From 45f8241ae2d928a340e7ab0eedd464311e6cfdfa Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Fri, 7 Jun 2024 09:41:18 +0200 Subject: [PATCH] Support for Patmos platform --- core/threaded/scheduler_static.c | 267 ++++++++++++++++++------------- 1 file changed, 158 insertions(+), 109 deletions(-) diff --git a/core/threaded/scheduler_static.c b/core/threaded/scheduler_static.c index 9dfef8044..cdfb7ec4e 100644 --- a/core/threaded/scheduler_static.c +++ b/core/threaded/scheduler_static.c @@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined SCHEDULER && SCHEDULER == SCHED_STATIC #ifndef NUMBER_OF_WORKERS #define NUMBER_OF_WORKERS 1 -#endif // NUMBER_OF_WORKERS +#endif // NUMBER_OF_WORKERS #include @@ -52,7 +52,7 @@ typedef struct lf_scheduler_t lf_scheduler_t; #include "scheduler_static_functions.h" #include "scheduler.h" -#include "semaphore.h" +// #include "semaphore.h" #include "tag.h" #include "trace.h" #include "util.h" @@ -65,7 +65,7 @@ typedef struct lf_scheduler_t lf_scheduler_t; extern instant_t start_time; // Global variables defined in schedule.c: -extern const inst_t* static_schedules[]; +extern const inst_t *static_schedules[]; extern reg_t timeout; extern const size_t num_counters; extern reg_t time_offset; @@ -80,9 +80,10 @@ extern volatile reg_t binary_sema[]; /** * @brief The implementation of the ADD instruction */ -void execute_inst_ADD(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { - int pc_orig = (int) *pc; +void execute_inst_ADD(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ + int pc_orig = (int)*pc; #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_ADD_starts(scheduler->env->trace, worker_number, pc_orig); #endif @@ -99,10 +100,11 @@ void execute_inst_ADD(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the ADDI instruction */ -void execute_inst_ADDI(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_ADDI(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_ADDI_starts(scheduler->env->trace, worker_number, pc_orig); #endif reg_t *dst = op1.reg; @@ -118,24 +120,26 @@ void execute_inst_ADDI(lf_scheduler_t* scheduler, size_t worker_number, operand_ /** * @brief The implementation of the ADV instruction */ -void execute_inst_ADV(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_ADV(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_ADV_starts(scheduler->env->trace, worker_number, pc_orig); #endif reg_t *base = op2.reg; - reg_t *inc = op3.reg; - self_base_t* reactor = + reg_t *inc = op3.reg; + self_base_t *reactor = scheduler->reactor_self_instances[op1.imm]; reactor->tag.time = *base + *inc; reactor->tag.microstep = 0; // Reset all "is_present" fields of the output ports of the reactor - // Doing this here has the major implication that ADV has to execute AFTER + // Doing this here has the major implication that ADV has to execute AFTER // all downstream reactions have finished, since it is modifying state that is // visible to those reactions. - for (int i = 0; i < reactor->num_output_ports; i++) { + for (int i = 0; i < reactor->num_output_ports; i++) + { reactor->output_ports[i]->is_present = false; } @@ -148,17 +152,18 @@ void execute_inst_ADV(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the ADVI instruction */ -void execute_inst_ADVI(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_ADVI(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_ADVI_starts(scheduler->env->trace, worker_number, pc_orig); #endif - self_base_t *reactor = (self_base_t*) op1.reg; + self_base_t *reactor = (self_base_t *)op1.reg; reg_t *base = op2.reg; reactor->tag.time = *base + op3.imm; reactor->tag.microstep = 0; - LF_PRINT_DEBUG("*** [Line %zu] Worker %zu advance reactor time (%p) from %lld to %lld by %lld", *pc, worker_number, &(reactor->tag.time), *base, reactor->tag.time, op3.imm); + lf_print("*** [Line %zu] Worker %zu advance reactor time (%p) from %lld to %lld by %lld", *pc, worker_number, &(reactor->tag.time), *base, reactor->tag.time, op3.imm); *pc += 1; // Increment pc. #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_ADVI_ends(scheduler->env->trace, worker_number, pc_orig); @@ -168,10 +173,11 @@ void execute_inst_ADVI(lf_scheduler_t* scheduler, size_t worker_number, operand_ /** * @brief The implementation of the BEQ instruction */ -void execute_inst_BEQ(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_BEQ(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_BEQ_starts(scheduler->env->trace, worker_number, pc_orig); #endif reg_t *_rs1 = op1.reg; @@ -179,13 +185,18 @@ void execute_inst_BEQ(lf_scheduler_t* scheduler, size_t worker_number, operand_t // These NULL checks allow _rs1 and _rs2 to be uninitialized in the static // schedule, which can save a few lines in the schedule. But it is debatable // whether this is good practice. - if (debug) { + if (debug) + { lf_print("DEBUG: _rs1 = %p, _rs2 = %p", _rs1, _rs2); - if (_rs1 != NULL) lf_print("DEBUG: *_rs1 = %lld", *_rs1); - if (_rs2 != NULL) lf_print("DEBUG: *_rs2 = %lld", *_rs2); + if (_rs1 != NULL) + lf_print("DEBUG: *_rs1 = %lld", *_rs1); + if (_rs2 != NULL) + lf_print("DEBUG: *_rs2 = %lld", *_rs2); } - if (_rs1 != NULL && _rs2 != NULL && *_rs1 == *_rs2) *pc = op3.imm; - else *pc += 1; + if (_rs1 != NULL && _rs2 != NULL && *_rs1 == *_rs2) + *pc = op3.imm; + else + *pc += 1; #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_BEQ_ends(scheduler->env->trace, worker_number, pc_orig); #endif @@ -194,17 +205,20 @@ void execute_inst_BEQ(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the BGE instruction */ -void execute_inst_BGE(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_BGE(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_BGE_starts(scheduler->env->trace, worker_number, pc_orig); #endif reg_t *_rs1 = op1.reg; reg_t *_rs2 = op2.reg; - LF_PRINT_DEBUG("Worker %zu: BGE : operand 1 = %lld, operand 2 = %lld", worker_number, *_rs1, *_rs2); - if (_rs1 != NULL && _rs2 != NULL && *_rs1 >= *_rs2) *pc = op3.imm; - else *pc += 1; + lf_print("Worker %zu: BGE : operand 1 = %lld, operand 2 = %lld", worker_number, *_rs1, *_rs2); + if (_rs1 != NULL && _rs2 != NULL && *_rs1 >= *_rs2) + *pc = op3.imm; + else + *pc += 1; #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_BGE_ends(scheduler->env->trace, worker_number, pc_orig); #endif @@ -213,16 +227,19 @@ void execute_inst_BGE(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the BLT instruction */ -void execute_inst_BLT(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_BLT(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_BLT_starts(scheduler->env->trace, worker_number, pc_orig); #endif reg_t *_rs1 = op1.reg; reg_t *_rs2 = op2.reg; - if (_rs1 != NULL && _rs2 != NULL && *_rs1 < *_rs2) *pc = op3.imm; - else *pc += 1; + if (_rs1 != NULL && _rs2 != NULL && *_rs1 < *_rs2) + *pc = op3.imm; + else + *pc += 1; #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_BLT_ends(scheduler->env->trace, worker_number, pc_orig); #endif @@ -231,16 +248,19 @@ void execute_inst_BLT(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the BNE instruction */ -void execute_inst_BNE(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_BNE(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_BNE_starts(scheduler->env->trace, worker_number, pc_orig); #endif reg_t *_rs1 = op1.reg; reg_t *_rs2 = op2.reg; - if (_rs1 != NULL && _rs2 != NULL && *_rs1 != *_rs2) *pc = op3.imm; - else *pc += 1; + if (_rs1 != NULL && _rs2 != NULL && *_rs1 != *_rs2) + *pc = op3.imm; + else + *pc += 1; #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_BNE_ends(scheduler->env->trace, worker_number, pc_orig); #endif @@ -249,10 +269,11 @@ void execute_inst_BNE(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the DU instruction */ -void execute_inst_DU(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_DU(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_DU_starts(scheduler->env->trace, worker_number, pc_orig); #endif // FIXME: There seems to be an overflow problem. @@ -263,8 +284,9 @@ void execute_inst_DU(lf_scheduler_t* scheduler, size_t worker_number, operand_t instant_t wakeup_time = *src + op2.imm; instant_t wait_interval = wakeup_time - current_time; // LF_PRINT_DEBUG("*** start_time: %lld, wakeup_time: %lld, op1: %lld, op2: %lld, current_physical_time: %lld\n", start_time, wakeup_time, *src, op2.imm, lf_time_physical()); - LF_PRINT_DEBUG("*** [Line %zu] Worker %zu delaying, current_physical_time: %lld, wakeup_time: %lld, wait_interval: %lld", *pc, worker_number, current_time, wakeup_time, wait_interval); - if (wait_interval > 0) { + lf_print("*** [Line %zu] Worker %zu delaying, current_physical_time: %lld, wakeup_time: %lld, wait_interval: %lld", *pc, worker_number, current_time, wakeup_time, wait_interval); + if (wait_interval > 0) + { // if (wait_interval < SPIN_WAIT_THRESHOLD) { // // Spin wait if the wait interval is less than 1 ms. // while (lf_time_physical() < wakeup_time); @@ -272,9 +294,10 @@ void execute_inst_DU(lf_scheduler_t* scheduler, size_t worker_number, operand_t // // Otherwise sleep. // _lf_interruptable_sleep_until_locked(scheduler->env, wakeup_time); // } - while (lf_time_physical() < wakeup_time); + while (lf_time_physical() < wakeup_time) + ; } - LF_PRINT_DEBUG("*** [Line %zu] Worker %zu done delaying", *pc, worker_number); + lf_print("*** [Line %zu] Worker %zu done delaying", *pc, worker_number); *pc += 1; // Increment pc. #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_DU_ends(scheduler->env->trace, worker_number, pc_orig); @@ -284,40 +307,54 @@ void execute_inst_DU(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the EXE instruction */ -void execute_inst_EXE(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { - int pc_orig = (int) *pc; - if (op3.imm != ULLONG_MAX) {tracepoint_static_scheduler_EXE_reaction_starts(scheduler->env->trace, (self_base_t *) op2.reg, worker_number, pc_orig, (int) op3.imm);} +void execute_inst_EXE(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ + int pc_orig = (int)*pc; + if (op3.imm != ULLONG_MAX) + { + tracepoint_static_scheduler_EXE_reaction_starts(scheduler->env->trace, (self_base_t *)op2.reg, worker_number, pc_orig, (int)op3.imm); + } #if TRACE_ALL_INSTRUCTIONS - else {tracepoint_static_scheduler_EXE_starts(scheduler->env->trace, (self_base_t *) op2.reg, worker_number, pc_orig);} + else + { + tracepoint_static_scheduler_EXE_starts(scheduler->env->trace, (self_base_t *)op2.reg, worker_number, pc_orig); + } #endif function_generic_t function = (function_generic_t)(uintptr_t)op1.reg; - void *args = (void*)op2.reg; + void *args = (void *)op2.reg; // Execute the function directly. - LF_PRINT_DEBUG("*** [Line %zu] Worker %zu executing reaction", *pc, worker_number); + lf_print("*** [Line %zu] Worker %zu executing reaction", *pc, worker_number); function(args); - LF_PRINT_DEBUG("*** [Line %zu] Worker %zu done executing reaction", *pc, worker_number); + lf_print("*** [Line %zu] Worker %zu done executing reaction", *pc, worker_number); *pc += 1; // Increment pc. - if (op3.imm != ULLONG_MAX) {tracepoint_static_scheduler_EXE_reaction_ends(scheduler->env->trace, (self_base_t *) op2.reg, worker_number, pc_orig, (int) op3.imm);} + if (op3.imm != ULLONG_MAX) + { + tracepoint_static_scheduler_EXE_reaction_ends(scheduler->env->trace, (self_base_t *)op2.reg, worker_number, pc_orig, (int)op3.imm); + } #if TRACE_ALL_INSTRUCTIONS - else {tracepoint_static_scheduler_EXE_ends(scheduler->env->trace, (self_base_t *) op2.reg, worker_number, pc_orig);} + else + { + tracepoint_static_scheduler_EXE_ends(scheduler->env->trace, (self_base_t *)op2.reg, worker_number, pc_orig); + } #endif } - /** * @brief The implementation of the WLT instruction */ -void execute_inst_WLT(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_WLT(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_WLT_starts(scheduler->env->trace, worker_number, pc_orig); #endif - LF_PRINT_DEBUG("*** Worker %zu waiting", worker_number); + lf_print("*** Worker %zu waiting", worker_number); reg_t *var = op1.reg; - while(*var >= op2.imm); - LF_PRINT_DEBUG("*** Worker %zu done waiting", worker_number); + while (*var >= op2.imm) + ; + lf_print("*** Worker %zu done waiting", worker_number); *pc += 1; // Increment pc. #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_WLT_ends(scheduler->env->trace, worker_number, pc_orig); @@ -327,16 +364,18 @@ void execute_inst_WLT(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the WU instruction */ -void execute_inst_WU(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_WU(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_WU_starts(scheduler->env->trace, worker_number, pc_orig); #endif - LF_PRINT_DEBUG("*** Worker %zu waiting", worker_number); + lf_print("*** Worker %zu waiting", worker_number); reg_t *var = op1.reg; - while(*var < op2.imm); - LF_PRINT_DEBUG("*** Worker %zu done waiting", worker_number); + while (*var < op2.imm) + ; + lf_print("*** Worker %zu done waiting", worker_number); *pc += 1; // Increment pc. #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_WU_ends(scheduler->env->trace, worker_number, pc_orig); @@ -346,16 +385,18 @@ void execute_inst_WU(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the JAL instruction */ -void execute_inst_JAL(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_JAL(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_JAL_starts(scheduler->env->trace, worker_number, pc_orig); #endif // Use the destination register as the return address and, if the // destination register is not the zero register, store pc+1 in it. reg_t *destReg = op1.reg; - if (destReg != &zero) *destReg = *pc + 1; + if (destReg != &zero) + *destReg = *pc + 1; *pc = op2.imm; #if TRACE_ALL_INSTRUCTIONS tracepoint_static_scheduler_JAL_ends(scheduler->env->trace, worker_number, pc_orig); @@ -365,16 +406,18 @@ void execute_inst_JAL(lf_scheduler_t* scheduler, size_t worker_number, operand_t /** * @brief The implementation of the JALR instruction */ -void execute_inst_JALR(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_JALR(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_JALR_starts(scheduler->env->trace, worker_number, pc_orig); #endif // Use the destination register as the return address and, if the // destination register is not the zero register, store pc+1 in it. reg_t *destReg = op1.reg; - if (destReg != &zero) *destReg = *pc + 1; + if (destReg != &zero) + *destReg = *pc + 1; // Set pc to base addr + immediate. reg_t *baseAddr = op2.reg; *pc = *baseAddr + op3.imm; @@ -386,10 +429,11 @@ void execute_inst_JALR(lf_scheduler_t* scheduler, size_t worker_number, operand_ /** * @brief The implementation of the STP instruction */ -void execute_inst_STP(lf_scheduler_t* scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t* pc, - reaction_t** returned_reaction, bool* exit_loop) { +void execute_inst_STP(lf_scheduler_t *scheduler, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, size_t *pc, + reaction_t **returned_reaction, bool *exit_loop) +{ #if TRACE_ALL_INSTRUCTIONS - int pc_orig = (int) *pc; + int pc_orig = (int)*pc; tracepoint_static_scheduler_STP_starts(scheduler->env->trace, worker_number, pc_orig); #endif *exit_loop = true; @@ -413,12 +457,13 @@ void execute_inst_STP(lf_scheduler_t* scheduler, size_t worker_number, operand_t void lf_sched_init( environment_t *env, size_t number_of_workers, - sched_params_t* params -) { + sched_params_t *params) +{ LF_PRINT_DEBUG("Scheduler: Initializing with %zu workers", number_of_workers); - + // Scheduler already initialized - if (!init_sched_instance(env, &env->scheduler, number_of_workers, params)) { + if (!init_sched_instance(env, &env->scheduler, number_of_workers, params)) + { // FIXME: This is not the best practice and seems to take advantage of a // bug in the runtime. // lf_sched_init() is for some reason called twice. @@ -431,7 +476,8 @@ void lf_sched_init( // called, start_time has not been set. // Initialize the local tags for the SCHED_STATIC scheduler. - for (int i = 0; i < env->scheduler->num_reactor_self_instances; i++) { + for (int i = 0; i < env->scheduler->num_reactor_self_instances; i++) + { env->scheduler->reactor_self_instances[i]->tag.time = start_time; env->scheduler->reactor_self_instances[i]->tag.microstep = 0; } @@ -452,7 +498,8 @@ void lf_sched_init( * * This must be called when the scheduler is no longer needed. */ -void lf_sched_free(lf_scheduler_t* scheduler) { +void lf_sched_free(lf_scheduler_t *scheduler) +{ LF_PRINT_DEBUG("Freeing the pointers in the scheduler struct."); free(scheduler->pc); free(scheduler->reactor_self_instances); @@ -471,22 +518,24 @@ void lf_sched_free(lf_scheduler_t* scheduler) { * @return reaction_t* A reaction for the worker to execute. NULL if the calling * worker thread should exit. */ -reaction_t* lf_sched_get_ready_reaction(lf_scheduler_t* scheduler, int worker_number) { +reaction_t *lf_sched_get_ready_reaction(lf_scheduler_t *scheduler, int worker_number) +{ LF_PRINT_DEBUG("Worker %d inside lf_sched_get_ready_reaction", worker_number); - - const inst_t* current_schedule = scheduler->static_schedules[worker_number]; - reaction_t* returned_reaction = NULL; - bool exit_loop = false; - size_t* pc = &scheduler->pc[worker_number]; - function_virtual_instruction_t func; - opcode_t opcode; - operand_t op1; - operand_t op2; - operand_t op3; - bool debug; + const inst_t *current_schedule = scheduler->static_schedules[worker_number]; + reaction_t *returned_reaction = NULL; + bool exit_loop = false; + size_t *pc = &scheduler->pc[worker_number]; - while (!exit_loop) { + function_virtual_instruction_t func; + opcode_t opcode; + operand_t op1; + operand_t op2; + operand_t op3; + bool debug; + + while (!exit_loop) + { func = current_schedule[*pc].func; // opcode = current_schedule[*pc].opcode; // FIXME: Opcode is unused. op1 = current_schedule[*pc].op1; @@ -496,10 +545,10 @@ reaction_t* lf_sched_get_ready_reaction(lf_scheduler_t* scheduler, int worker_nu // Execute the current instruction func(scheduler, worker_number, op1, op2, op3, debug, pc, - &returned_reaction, &exit_loop); + &returned_reaction, &exit_loop); } - LF_PRINT_DEBUG("Worker %d leaves lf_sched_get_ready_reaction", worker_number); + lf_print("Worker %d leaves lf_sched_get_ready_reaction", worker_number); return returned_reaction; } @@ -512,7 +561,7 @@ reaction_t* lf_sched_get_ready_reaction(lf_scheduler_t* scheduler, int worker_nu * @param done_reaction The reaction that is done. */ void lf_sched_done_with_reaction(size_t worker_number, - reaction_t* done_reaction) {} + reaction_t *done_reaction) {} /** * @brief Inform the scheduler that worker thread 'worker_number' would like to @@ -533,5 +582,5 @@ void lf_sched_done_with_reaction(size_t worker_number, * worker number does not make sense (e.g., the caller is not a worker thread). * */ -void lf_scheduler_trigger_reaction(lf_scheduler_t* scheduler, reaction_t* reaction, int worker_number) {} +void lf_scheduler_trigger_reaction(lf_scheduler_t *scheduler, reaction_t *reaction, int worker_number) {} #endif