Skip to content

Commit cb00bef

Browse files
Eric Holkgraydon
authored andcommitted
Added an environment variable to control how many threads to use.
1 parent 4bc7734 commit cb00bef

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/rt/rust.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ command_line_args : public dom_owned<command_line_args>
7171
}
7272
};
7373

74+
int get_num_threads()
75+
{
76+
char *env = getenv("RUST_THREADS");
77+
if(env) {
78+
int num = atoi(env);
79+
if(num > 0)
80+
return num;
81+
}
82+
// TODO: in this case, determine the number of CPUs present on the
83+
// machine.
84+
return 1;
85+
}
86+
7487
/**
7588
* Main entry point into the Rust runtime. Here we create a Rust service,
7689
* initialize the kernel, create the root domain and run it.
@@ -95,7 +108,11 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
95108

96109
dom->root_task->start(main_fn, (uintptr_t)args->args);
97110

98-
int ret = dom->start_main_loops(8);
111+
int num_threads = get_num_threads();
112+
113+
DLOG(dom, dom, "Using %d worker threads.", num_threads);
114+
115+
int ret = dom->start_main_loops(num_threads);
99116
delete args;
100117
kernel->destroy_domain(dom);
101118
kernel->join_all_domains();

0 commit comments

Comments
 (0)