Skip to content
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

Set worker thread scheduling policy and priority #424

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ define(FEDERATED_DECENTRALIZED)
define(FEDERATED)
define(FEDERATED_AUTHENTICATED)
define(FEDERATE_ID)
define(LF_NUMBER_OF_CORES)
define(LF_REACTION_GRAPH_BREADTH)
define(LF_THREAD_POLICY)
define(LF_TRACE)
define(LF_SINGLE_THREADED)
define(LOG_LEVEL)
Expand Down
15 changes: 12 additions & 3 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ bool wait_until(instant_t logical_time, lf_cond_t* condition) {
return true;
}

// setting the priority to the maximum to be sure to be
// woken up as soon as the sleep time terminates (because there
// might be other worker threads from different enclaves having
// higher priority than what the current thread has)
// FIXME: use the same constant defined for the GEDF scheduler
lf_thread_set_priority(lf_thread_self(), LF_SCHED_MAX_PRIORITY - 1);

// We do the sleep on the cond var so we can be awakened by the
// asynchronous scheduling of a physical action. lf_clock_cond_timedwait
// returns 0 if it is awakened before the timeout. Hence, we want to run
Expand Down Expand Up @@ -861,7 +868,7 @@ void _lf_worker_invoke_reaction(environment_t* env, int worker_number, reaction_
* @param env Environment within which we are executing.
* @param worker_number The number assigned to this worker thread
*/
void _lf_worker_do_work(environment_t* env, int worker_number) {
static void _lf_worker_do_work(environment_t* env, int worker_number) {
assert(env != GLOBAL_ENVIRONMENT);

// Keep track of whether we have decremented the idle thread count.
Expand Down Expand Up @@ -903,6 +910,8 @@ void _lf_worker_do_work(environment_t* env, int worker_number) {
*/
void* worker(void* arg) {
initialize_lf_thread_id();
lf_sched_configure_worker();

environment_t* env = (environment_t*)arg;
LF_MUTEX_LOCK(&env->mutex);

Expand Down Expand Up @@ -1013,7 +1022,6 @@ void determine_number_of_workers(void) {
* at compile time.
*/
int lf_reactor_c_main(int argc, const char* argv[]) {
initialize_lf_thread_id();
// Invoke the function that optionally provides default command-line options.
lf_set_default_command_line_options();

Expand Down Expand Up @@ -1104,14 +1112,15 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
lf_print("Environment %u: ---- Intializing start tag", env->id);
_lf_initialize_start_tag(env);

lf_print("Environment %u: ---- Spawning %d workers.", env->id, env->num_workers);
lf_print("Environment %u: ---- Spawning %d workers on %d cores.", env->id, env->num_workers, LF_NUMBER_OF_CORES);

for (int j = 0; j < env->num_workers; j++) {
if (i == 0 && j == 0) {
// The first worker thread of the first environment will be
// run on the main thread, rather than creating a new thread.
// This is important for bare-metal platforms, who can't
// afford to have the main thread sit idle.
env->thread_ids[0] = lf_thread_self();
continue;
}
if (lf_thread_create(&env->thread_ids[j], worker, env) != 0) {
Expand Down
Loading
Loading