Skip to content

Commit

Permalink
Merge pull request #433 from lf-lang/gedf
Browse files Browse the repository at this point in the history
Redesign of GEDF scheduler
  • Loading branch information
lhstrh authored May 28, 2024
2 parents d9f86a0 + d577ea9 commit d54dbd6
Show file tree
Hide file tree
Showing 19 changed files with 352 additions and 553 deletions.
31 changes: 5 additions & 26 deletions core/environment.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
/**
* @file
* @author Erling R. Jellum ([email protected])
* @author Erling R. Jellum
* @copyright (c) 2023-2024, The Norwegian University of Science and Technology.
* License: <a href="https://github.com/lf-lang/reactor-c/blob/main/LICENSE.md">BSD 2-clause</a>
*
* @section LICENSE
* Copyright (c) 2023, The Norwegian University of Science and Technology.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @section DESCRIPTION Functions intitializing and freeing memory for environments.
* See environment.h for docs.
* This file defines functions intitializing and freeing memory for environments.
* See environment.h for docs.
*/

#include "environment.h"
Expand Down
14 changes: 9 additions & 5 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2611,14 +2611,18 @@ void lf_set_federation_id(const char* fid) { federation_metadata.federation_id =
void lf_spawn_staa_thread() { lf_thread_create(&_fed.staaSetter, update_ports_from_staa_offsets, NULL); }
#endif // FEDERATED_DECENTRALIZED

void lf_stall_advance_level_federation(environment_t* env, size_t level) {
LF_PRINT_DEBUG("Acquiring the environment mutex.");
LF_MUTEX_LOCK(&env->mutex);
LF_PRINT_DEBUG("Waiting on MLAA with next_reaction_level %zu and MLAA %d.", level, max_level_allowed_to_advance);
void lf_stall_advance_level_federation_locked(size_t level) {
LF_PRINT_DEBUG("Waiting for MLAA %d to exceed level %zu.", max_level_allowed_to_advance, level);
while (((int)level) >= max_level_allowed_to_advance) {
lf_cond_wait(&lf_port_status_changed);
};
LF_PRINT_DEBUG("Exiting wait with MLAA %d and next_reaction_level %zu.", max_level_allowed_to_advance, level);
LF_PRINT_DEBUG("Exiting wait with MLAA %d and level %zu.", max_level_allowed_to_advance, level);
}

void lf_stall_advance_level_federation(environment_t* env, size_t level) {
LF_PRINT_DEBUG("Acquiring the environment mutex.");
LF_MUTEX_LOCK(&env->mutex);
lf_stall_advance_level_federation_locked(level);
LF_MUTEX_UNLOCK(&env->mutex);
}

Expand Down
6 changes: 0 additions & 6 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,6 @@ void lf_request_stop(void) {
lf_set_stop_tag(env, new_stop_tag);
}

/**
* Return false.
* @param reaction The reaction.
*/
bool _lf_is_blocked_by_executing_reaction(void) { return false; }

/**
* The main loop of the LF program.
*
Expand Down
29 changes: 11 additions & 18 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @file
* @author Edward A. Lee ([email protected])
* @author{Marten Lohstroh <[email protected]>}
* @author{Soroush Bateni <[email protected]>}
* @author Edward A. Lee
* @author Marten Lohstroh
* @author Soroush Bateni
* @copyright (c) 2020-2024, The University of California at Berkeley.
* License: <a href="https://github.com/lf-lang/reactor-c/blob/main/LICENSE.md">BSD 2-clause</a>
* @brief Runtime infrastructure for the threaded version of the C target of Lingua Franca.
Expand Down Expand Up @@ -850,19 +850,13 @@ void _lf_worker_invoke_reaction(environment_t* env, int worker_number, reaction_
reaction->is_STP_violated = false;
}

void try_advance_level(environment_t* env, volatile size_t* next_reaction_level) {
#ifdef FEDERATED
lf_stall_advance_level_federation(env, *next_reaction_level);
#else
(void)env;
#endif
if (*next_reaction_level < SIZE_MAX)
*next_reaction_level += 1;
}

/**
* The main looping logic of each LF worker thread.
* This function assumes the caller holds the mutex lock.
* @brief The main looping logic of each LF worker thread.
*
* This function returns when the scheduler's lf_sched_get_ready_reaction()
* implementation returns NULL, indicating that there are no more reactions to execute.
*
* This function assumes the caller does not hold the mutex lock on the environment.
*
* @param env Environment within which we are executing.
* @param worker_number The number assigned to this worker thread
Expand All @@ -882,10 +876,9 @@ void _lf_worker_do_work(environment_t* env, int worker_number) {
while ((current_reaction_to_execute = lf_sched_get_ready_reaction(env->scheduler, worker_number)) != NULL) {
// Got a reaction that is ready to run.
LF_PRINT_DEBUG("Worker %d: Got from scheduler reaction %s: "
"level: %lld, is input reaction: %d, chain ID: %llu, and deadline " PRINTF_TIME ".",
"level: %lld, is input reaction: %d, and deadline " PRINTF_TIME ".",
worker_number, current_reaction_to_execute->name, LF_LEVEL(current_reaction_to_execute->index),
current_reaction_to_execute->is_an_input_reaction, current_reaction_to_execute->chain_id,
current_reaction_to_execute->deadline);
current_reaction_to_execute->is_an_input_reaction, current_reaction_to_execute->deadline);

bool violation = _lf_worker_handle_violations(env, worker_number, current_reaction_to_execute);

Expand Down
Loading

0 comments on commit d54dbd6

Please sign in to comment.