Skip to content

Rewrite of task switching mechanism #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ fi
step_msg "making directories"
for i in \
doc \
rt rt/isaac rt/bigint rt/sync rt/test \
rt rt/isaac rt/bigint rt/sync rt/test rt/arch/i386 \
rustllvm \
dl stage0 stage1 stage2 stage3 \
test/run-pass test/run-fail test/compile-fail \
test/bench/99-bottles test/bench/shootout
test/bench/99-bottles test/bench/shootout
do
make_dir $i
done
Expand Down
13 changes: 8 additions & 5 deletions mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ RUNTIME_CS := rt/sync/timer.cpp \
rt/memory_region.cpp \
rt/test/rust_test_harness.cpp \
rt/test/rust_test_runtime.cpp \
rt/test/rust_test_util.cpp
rt/test/rust_test_util.cpp \
rt/arch/i386/context.cpp \

RUNTIME_LL := rt/new_exit.ll rt/vec_append.ll
RUNTIME_LL := rt/vec_append.ll

RUNTIME_S := rt/activate_glue.s rt/yield_glue.s
RUNTIME_S := rt/arch/i386/_context.s

RUNTIME_HDR := rt/globals.h \
rt/rust.h \
Expand Down Expand Up @@ -60,10 +61,12 @@ RUNTIME_HDR := rt/globals.h \
rt/memory.h \
rt/test/rust_test_harness.h \
rt/test/rust_test_runtime.h \
rt/test/rust_test_util.h
rt/test/rust_test_util.h \
rt/arch/i386/context.h \

RUNTIME_DEF := rt/rustrt$(CFG_DEF_SUFFIX)
RUNTIME_INCS := -I $(S)src/rt/isaac -I $(S)src/rt/uthash
RUNTIME_INCS := -I $(S)src/rt/isaac -I $(S)src/rt/uthash \
-I $(S)src/rt/arch/i386
RUNTIME_OBJS := $(RUNTIME_CS:.cpp=.o) $(RUNTIME_LL:.ll=.o) $(RUNTIME_S:.s=.o)
RUNTIME_LIBS := $(CFG_GCCISH_POST_LIB_FLAGS)

Expand Down
4 changes: 0 additions & 4 deletions src/comp/back/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ fn vec_append_glue_name() -> str {
ret "rust_vec_append_glue";
}

fn yield_glue_name() -> str {
ret "rust_yield_glue";
}

fn no_op_type_glue_name() -> str {
ret "rust_no_op_type_glue";
}
Expand Down
2 changes: 1 addition & 1 deletion src/comp/back/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
T_ptr(T_tydesc(tn))),
new_task=d("new_task", [T_ptr(T_str())], T_taskptr(tn)),
start_task=d("start_task", [T_taskptr(tn),
T_int(), T_int()],
T_int(), T_int(), T_size_t()],
T_taskptr(tn)),
new_thread=d("new_thread", [T_ptr(T_i8())], T_taskptr(tn)),
start_thread=d("start_thread", [T_taskptr(tn), T_int(), T_int(),
Expand Down
11 changes: 4 additions & 7 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ state obj namegen(mutable int i) {

type derived_tydesc_info = rec(ValueRef lltydesc, bool escapes);

type glue_fns = rec(ValueRef yield_glue,
ValueRef no_op_type_glue,
type glue_fns = rec(ValueRef no_op_type_glue,
ValueRef vec_append_glue);

type tydesc_info = rec(ty::t ty,
Expand Down Expand Up @@ -6470,13 +6469,12 @@ fn trans_spawn(&@block_ctxt cx,
auto wrapper = mk_spawn_wrapper(bcx, func, args_ty);
bcx = wrapper.bcx;
auto llfnptr_i = bcx.build.PointerCast(wrapper.val, T_int());
// TODO: this next line might be necessary...
//llfnptr_i = bcx.build.Load(llfnptr_i);

// And start the task
auto args_size = size_of(bcx, args_ty).val;
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.start_task,
[bcx.fcx.lltaskptr, new_task,
llfnptr_i, llargs_i]);
llfnptr_i, llargs_i, args_size]);

auto task_ty = node_ann_type(bcx.fcx.lcx.ccx, ann);
auto dropref = clean(bind drop_ty(_, new_task, task_ty));
Expand Down Expand Up @@ -8561,8 +8559,7 @@ fn vec_p0(&@block_ctxt bcx, ValueRef v) -> ValueRef {
}

fn make_glues(ModuleRef llmod, &type_names tn) -> @glue_fns {
ret @rec(yield_glue = decl_glue(llmod, tn, abi::yield_glue_name()),
no_op_type_glue = decl_no_op_type_glue(llmod, tn),
ret @rec(no_op_type_glue = decl_no_op_type_glue(llmod, tn),
vec_append_glue = make_vec_append_glue(llmod, tn));
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/std.rc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod str;

mod io;
mod sys;
mod _task;
mod task;

// Utility modules.

Expand All @@ -33,7 +33,7 @@ auth os_fs = unsafe;
auth run = unsafe;
auth str = unsafe;
auth vec = unsafe;
auth _task = unsafe;
auth task = unsafe;

auth dbg = unsafe;

Expand Down
10 changes: 10 additions & 0 deletions src/lib/_task.rs → src/lib/task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
native "rust" mod rustrt {
fn task_sleep(uint time_in_us);
fn task_yield();
}

/**
Expand All @@ -11,6 +12,15 @@ fn sleep(uint time_in_us) {
ret rustrt::task_sleep(time_in_us);
}

fn yield() {
ret rustrt::task_yield();
}

fn join(task t) {
// TODO: figure out how to pass tasks to the runtime and call the builtin
// join.
}

// Local Variables:
// mode: rust;
// fill-column: 78;
Expand Down
89 changes: 0 additions & 89 deletions src/rt/activate_glue.s

This file was deleted.

86 changes: 86 additions & 0 deletions src/rt/arch/i386/_context.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
.text

/*
Callee save registers:
ebp, ebx, esi, edi

Caller save registers:
eax, ecx, edx
*/

/*
Saves a set of registers. This is used by our implementation of
getcontext.

The registers_t variable is in (%esp)
*/

.globl get_registers
get_registers:
movl 4(%esp), %eax
movl %eax, 0(%eax)
movl %ebx, 4(%eax)
movl %ecx, 8(%eax)
movl %edx, 12(%eax)
movl %ebp, 16(%eax)
movl %esi, 20(%eax)
movl %edi, 24(%eax)
movl %esp, 28(%eax)
movw %cs, 32(%eax)
movw %ds, 34(%eax)
movw %ss, 36(%eax)
movw %es, 38(%eax)
movw %fs, 40(%eax)
movw %gs, 42(%eax)

// save the flags
pushf
popl %ecx
movl %ecx, 44(%eax)

// save the return address as the instruction pointer
movl 0(%esp), %ecx
movl %ecx, 48(%eax)

// return 0
xor %eax, %eax
ret

.globl set_registers
set_registers:
movl 4(%esp), %eax

movl 4(%eax), %ebx
// save ecx for later...
movl 12(%eax), %edx
movl 16(%eax), %ebp
movl 20(%eax), %esi
movl 24(%eax), %edi
movl 28(%eax), %esp
// We can't actually change this...
//movl 32(%eax), %cs
movw 34(%eax), %ds
movw 36(%eax), %ss
movw 38(%eax), %es
movw 40(%eax), %fs
movw 42(%eax), %gs

// restore the flags
movl 44(%eax), %ecx
push %ecx
popf

// get ready to return back to the old eip
// We could write this directly to 0(%esp), but Valgrind on OS X
// complains.
pop %ecx
mov 48(%eax), %ecx
push %ecx
//movl %ecx, 0(%esp)

// okay, now we can restore ecx.
movl 8(%eax), %ecx

// return 1 to the saved eip
movl $1, %eax
ret
Loading