Removing most of the locks in rust_upcall.cpp and elsewhere.

This commit is contained in:
Eric Holk
2011-07-06 12:48:43 -07:00
parent e7111fe147
commit a0f45f4456
4 changed files with 46 additions and 75 deletions

View File

@@ -392,17 +392,12 @@ task_yield(rust_task *task) {
extern "C" CDECL void extern "C" CDECL void
task_join(rust_task *task, rust_task *join_task) { task_join(rust_task *task, rust_task *join_task) {
task->kernel->scheduler_lock.lock();
// If the other task is already dying, we don't have to wait for it. // If the other task is already dying, we don't have to wait for it.
if (join_task->dead() == false) { if (join_task->dead() == false) {
join_task->tasks_waiting_to_join.push(task); join_task->tasks_waiting_to_join.push(task);
task->block(join_task, "joining local task"); task->block(join_task, "joining local task");
task->kernel->scheduler_lock.unlock();
task->yield(2); task->yield(2);
} }
else {
task->kernel->scheduler_lock.unlock();
}
} }
/* Debug builtins for std.dbg. */ /* Debug builtins for std.dbg. */

View File

@@ -54,7 +54,7 @@ rust_srv::fatal(const char *expression,
"fatal, '%s' failed, %s:%d %s", "fatal, '%s' failed, %s:%d %s",
expression, file, (int)line, buf); expression, file, (int)line, buf);
log(msg); log(msg);
exit(1); abort();
} }
void void

View File

@@ -120,21 +120,12 @@ void task_start_wrapper(spawn_args *a)
LOG(task, task, "task exited with value %d", rval); LOG(task, task, "task exited with value %d", rval);
{
scoped_lock with(task->kernel->scheduler_lock);
// FIXME: the old exit glue does some magical argument copying
// stuff. This is probably still needed.
// This is duplicated from upcall_exit, which is probably dead code by
// now.
LOG(task, task, "task ref_count: %d", task->ref_count); LOG(task, task, "task ref_count: %d", task->ref_count);
A(task->sched, task->ref_count >= 0, A(task->sched, task->ref_count >= 0,
"Task ref_count should not be negative on exit!"); "Task ref_count should not be negative on exit!");
task->die(); task->die();
task->notify_tasks_waiting_to_join(); task->notify_tasks_waiting_to_join();
}
task->yield(1); task->yield(1);
} }
@@ -145,9 +136,6 @@ rust_task::start(uintptr_t spawnee_fn,
LOGPTR(sched, "from spawnee", spawnee_fn); LOGPTR(sched, "from spawnee", spawnee_fn);
I(sched, stk->data != NULL); I(sched, stk->data != NULL);
I(sched, !kernel->scheduler_lock.lock_held_by_current_thread());
scoped_lock with(kernel->scheduler_lock);
char *sp = (char *)rust_sp; char *sp = (char *)rust_sp;
@@ -399,7 +387,8 @@ rust_task::free(void *p, bool is_gc)
void void
rust_task::transition(rust_task_list *src, rust_task_list *dst) { rust_task::transition(rust_task_list *src, rust_task_list *dst) {
I(sched, kernel->scheduler_lock.lock_held_by_current_thread()); I(sched, !kernel->scheduler_lock.lock_held_by_current_thread());
scoped_lock with(kernel->scheduler_lock);
DLOG(sched, task, DLOG(sched, task,
"task %s " PTR " state change '%s' -> '%s' while in '%s'", "task %s " PTR " state change '%s' -> '%s' while in '%s'",
name, (uintptr_t)this, src->name, dst->name, state->name); name, (uintptr_t)this, src->name, dst->name, state->name);

View File

@@ -90,7 +90,6 @@ upcall_trace_str(rust_task *task, char const *c) {
extern "C" CDECL rust_port* extern "C" CDECL rust_port*
upcall_new_port(rust_task *task, size_t unit_sz) { upcall_new_port(rust_task *task, size_t unit_sz) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, comm, "upcall_new_port(task=0x%" PRIxPTR " (%s), unit_sz=%d)", LOG(task, comm, "upcall_new_port(task=0x%" PRIxPTR " (%s), unit_sz=%d)",
(uintptr_t) task, task->name, unit_sz); (uintptr_t) task, task->name, unit_sz);
return new (task) rust_port(task, unit_sz); return new (task) rust_port(task, unit_sz);
@@ -99,7 +98,6 @@ upcall_new_port(rust_task *task, size_t unit_sz) {
extern "C" CDECL void extern "C" CDECL void
upcall_del_port(rust_task *task, rust_port *port) { upcall_del_port(rust_task *task, rust_port *port) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, comm, "upcall del_port(0x%" PRIxPTR ")", (uintptr_t) port); LOG(task, comm, "upcall del_port(0x%" PRIxPTR ")", (uintptr_t) port);
I(task->sched, !port->ref_count); I(task->sched, !port->ref_count);
delete port; delete port;
@@ -139,7 +137,6 @@ upcall_flush_chan(rust_task *task, rust_chan *chan) {
extern "C" CDECL extern "C" CDECL
void upcall_del_chan(rust_task *task, rust_chan *chan) { void upcall_del_chan(rust_task *task, rust_chan *chan) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, comm, "upcall del_chan(0x%" PRIxPTR ")", (uintptr_t) chan); LOG(task, comm, "upcall del_chan(0x%" PRIxPTR ")", (uintptr_t) chan);
chan->destroy(); chan->destroy();
@@ -153,7 +150,6 @@ extern "C" CDECL rust_chan *
upcall_clone_chan(rust_task *task, maybe_proxy<rust_task> *target, upcall_clone_chan(rust_task *task, maybe_proxy<rust_task> *target,
rust_chan *chan) { rust_chan *chan) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
return chan->clone(target); return chan->clone(target);
} }
@@ -181,16 +177,13 @@ upcall_sleep(rust_task *task, size_t time_in_us) {
extern "C" CDECL void extern "C" CDECL void
upcall_send(rust_task *task, rust_chan *chan, void *sptr) { upcall_send(rust_task *task, rust_chan *chan, void *sptr) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
chan->send(sptr); chan->send(sptr);
LOG(task, comm, "=== sent data ===>"); LOG(task, comm, "=== sent data ===>");
} }
extern "C" CDECL void extern "C" CDECL void
upcall_recv(rust_task *task, uintptr_t *dptr, rust_port *port) { upcall_recv(rust_task *task, uintptr_t *dptr, rust_port *port) {
{
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, comm, "port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR LOG(task, comm, "port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR
", size: 0x%" PRIxPTR ", chan_no: %d", ", size: 0x%" PRIxPTR ", chan_no: %d",
@@ -201,14 +194,14 @@ upcall_recv(rust_task *task, uintptr_t *dptr, rust_port *port) {
return; return;
} }
// No data was buffered on any incoming channel, so block this task // No data was buffered on any incoming channel, so block this task on the
// on the port. Remember the rendezvous location so that any sender // port. Remember the rendezvous location so that any sender task can
// task can write to it before waking up this task. // write to it before waking up this task.
LOG(task, comm, "<=== waiting for rendezvous data ==="); LOG(task, comm, "<=== waiting for rendezvous data ===");
task->rendezvous_ptr = dptr; task->rendezvous_ptr = dptr;
task->block(port, "waiting for rendezvous data"); task->block(port, "waiting for rendezvous data");
}
task->yield(3); task->yield(3);
} }
@@ -228,7 +221,7 @@ upcall_fail(rust_task *task,
extern "C" CDECL void extern "C" CDECL void
upcall_kill(rust_task *task, maybe_proxy<rust_task> *target) { upcall_kill(rust_task *task, maybe_proxy<rust_task> *target) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
if (target->is_proxy()) { if (target->is_proxy()) {
notify_message:: notify_message::
send(notify_message::KILL, "kill", task->get_handle(), send(notify_message::KILL, "kill", task->get_handle(),
@@ -245,28 +238,26 @@ upcall_kill(rust_task *task, maybe_proxy<rust_task> *target) {
*/ */
extern "C" CDECL void extern "C" CDECL void
upcall_exit(rust_task *task) { upcall_exit(rust_task *task) {
{
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, task, "task ref_count: %d", task->ref_count); LOG(task, task, "task ref_count: %d", task->ref_count);
A(task->sched, task->ref_count >= 0, A(task->sched, task->ref_count >= 0,
"Task ref_count should not be negative on exit!"); "Task ref_count should not be negative on exit!");
task->die(); task->die();
task->notify_tasks_waiting_to_join(); task->notify_tasks_waiting_to_join();
}
task->yield(1); task->yield(1);
} }
extern "C" CDECL uintptr_t extern "C" CDECL uintptr_t
upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) { upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, mem, LOG(task, mem,
"upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR ")" "upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR ")"
" with gc-chain head = 0x%" PRIxPTR, " with gc-chain head = 0x%" PRIxPTR,
nbytes, td, task->gc_alloc_chain); nbytes, td, task->gc_alloc_chain);
void *p = task->malloc(nbytes, td); void *p = task->malloc(nbytes, td);
LOG(task, mem, LOG(task, mem,
"upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR "upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR
") = 0x%" PRIxPTR ") = 0x%" PRIxPTR
@@ -281,7 +272,7 @@ upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
extern "C" CDECL void extern "C" CDECL void
upcall_free(rust_task *task, void* ptr, uintptr_t is_gc) { upcall_free(rust_task *task, void* ptr, uintptr_t is_gc) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
rust_scheduler *sched = task->sched; rust_scheduler *sched = task->sched;
DLOG(sched, mem, DLOG(sched, mem,
"upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")", "upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")",
@@ -322,7 +313,6 @@ upcall_shared_free(rust_task *task, void* ptr) {
extern "C" CDECL uintptr_t extern "C" CDECL uintptr_t
upcall_mark(rust_task *task, void* ptr) { upcall_mark(rust_task *task, void* ptr) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
rust_scheduler *sched = task->sched; rust_scheduler *sched = task->sched;
if (ptr) { if (ptr) {
@@ -354,7 +344,6 @@ rust_str *make_str(rust_task *task, char const *s, size_t fill) {
extern "C" CDECL rust_str * extern "C" CDECL rust_str *
upcall_new_str(rust_task *task, char const *s, size_t fill) { upcall_new_str(rust_task *task, char const *s, size_t fill) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
return make_str(task, s, fill); return make_str(task, s, fill);
} }
@@ -362,7 +351,6 @@ upcall_new_str(rust_task *task, char const *s, size_t fill) {
extern "C" CDECL rust_str * extern "C" CDECL rust_str *
upcall_dup_str(rust_task *task, rust_task *target, rust_str *str) { upcall_dup_str(rust_task *task, rust_task *target, rust_str *str) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
return make_str(target, (char const *)str->data, str->fill); return make_str(target, (char const *)str->data, str->fill);
} }
@@ -370,7 +358,7 @@ upcall_dup_str(rust_task *task, rust_task *target, rust_str *str) {
extern "C" CDECL rust_vec * extern "C" CDECL rust_vec *
upcall_new_vec(rust_task *task, size_t fill, type_desc *td) { upcall_new_vec(rust_task *task, size_t fill, type_desc *td) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
rust_scheduler *sched = task->sched; rust_scheduler *sched = task->sched;
DLOG(sched, mem, "upcall new_vec(%" PRIdPTR ")", fill); DLOG(sched, mem, "upcall new_vec(%" PRIdPTR ")", fill);
size_t alloc = next_power_of_two(sizeof(rust_vec) + fill); size_t alloc = next_power_of_two(sizeof(rust_vec) + fill);
@@ -511,7 +499,7 @@ upcall_get_type_desc(rust_task *task,
type_desc const **descs) { type_desc const **descs) {
check_stack(task); check_stack(task);
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
LOG(task, cache, "upcall get_type_desc with size=%" PRIdPTR LOG(task, cache, "upcall get_type_desc with size=%" PRIdPTR
", align=%" PRIdPTR ", %" PRIdPTR " descs", size, align, ", align=%" PRIdPTR ", %" PRIdPTR " descs", size, align,
n_descs); n_descs);
@@ -568,7 +556,7 @@ upcall_ivec_resize(rust_task *task,
rust_ivec *v, rust_ivec *v,
size_t newsz) { size_t newsz) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
I(task->sched, !v->fill); I(task->sched, !v->fill);
size_t new_alloc = next_power_of_two(newsz); size_t new_alloc = next_power_of_two(newsz);
@@ -588,7 +576,6 @@ upcall_ivec_spill(rust_task *task,
rust_ivec *v, rust_ivec *v,
size_t newsz) { size_t newsz) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
scoped_lock with(task->kernel->scheduler_lock);
size_t new_alloc = next_power_of_two(newsz); size_t new_alloc = next_power_of_two(newsz);
rust_ivec_heap *heap_part = (rust_ivec_heap *) rust_ivec_heap *heap_part = (rust_ivec_heap *)