Skip to content

rt: Implement ThreadPerCore scheduling mode #3487

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

Merged
merged 1 commit into from
Sep 13, 2012
Merged
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
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