Skip to content

Commit

Permalink
rt: Implement ThreadPerCore scheduling mode
Browse files Browse the repository at this point in the history
Fixes #3465.
  • Loading branch information
Blei committed Sep 13, 2012
1 parent 308ca06 commit 62b51d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/libcore/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1403,11 +1403,9 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {

let num_threads = match opts.mode {
SingleThreaded => 1u,
ThreadPerCore => {
fail ~"thread_per_core scheduling mode unimplemented"
}
ThreadPerCore => rustrt::rust_num_threads(),
ThreadPerTask => {
fail ~"thread_per_task scheduling mode unimplemented"
fail ~"ThreadPerTask scheduling mode unimplemented"
}
ManualThreads(threads) => {
if threads == 0u {
Expand Down Expand Up @@ -1657,6 +1655,8 @@ extern mod rustrt {

fn rust_get_sched_id() -> sched_id;
fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id;
fn sched_threads() -> libc::size_t;
fn rust_num_threads() -> libc::uintptr_t;

fn get_task_id() -> task_id;
#[rust_stack]
Expand Down Expand Up @@ -2422,3 +2422,13 @@ fn test_tls_cleanup_on_failure() unsafe {
local_data_set(int_key, @31337);
fail;
}

#[test]
fn test_sched_thread_per_core() {
let cores = rustrt::rust_num_threads();
let mut reported_threads = 0u;
do spawn_sched(ThreadPerCore) {
reported_threads = rustrt::sched_threads();
}
assert(cores == reported_threads);
}
8 changes: 7 additions & 1 deletion src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ rust_get_sched_id() {
return task->sched->get_id();
}

extern "C" CDECL uintptr_t
rust_num_threads() {
rust_task *task = rust_get_current_task();
return task->kernel->env->num_sched_threads;
}

extern "C" CDECL rust_sched_id
rust_new_sched(uintptr_t threads) {
rust_task *task = rust_get_current_task();
Expand Down Expand Up @@ -620,7 +626,7 @@ start_task(rust_task *target, fn_env_pair *f) {
target->start(f->f, f->env, NULL);
}

extern "C" CDECL int
extern "C" CDECL size_t
sched_threads() {
rust_task *task = rust_get_current_task();
return task->sched->number_of_threads();
Expand Down
1 change: 1 addition & 0 deletions src/rt/rustrt.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rand_seed
rust_get_sched_id
rust_new_sched
rust_new_task_in_sched
rust_num_threads
rust_path_is_dir
rust_path_exists
rust_getcwd
Expand Down

0 comments on commit 62b51d9

Please sign in to comment.