Skip to content

Commit

Permalink
adding scheduler interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Nov 19, 2024
1 parent 27a5ec5 commit b1c57ed
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 200 deletions.
8 changes: 4 additions & 4 deletions include/reactor-uc/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
typedef struct Environment Environment;

struct Environment {
Reactor *main; // The top-level reactor of the program.
Scheduler* scheduler; // The scheduler in charge of executing the reactions.
Platform *platform; // The platform that provides the physical time and sleep functions.
Reactor *main; // The top-level reactor of the program.
Scheduler *scheduler; // The scheduler in charge of executing the reactions.
Platform *platform; // The platform that provides the physical time and sleep functions.
bool has_async_events;
BuiltinTrigger *startup; // A pointer to a startup trigger, if the program has one.
BuiltinTrigger *shutdown; // A pointer to a chain of shutdown triggers, if the program has one.
Expand Down Expand Up @@ -59,7 +59,7 @@ struct Environment {
void (*request_shutdown)(Environment *self);
};

void Environment_ctor(Environment *self, Scheduler* scheduler, Reactor *main);
void Environment_ctor(Environment *self, Scheduler *scheduler, Reactor *main);
void Environment_free(Environment *self);

#endif
21 changes: 13 additions & 8 deletions include/reactor-uc/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if (ret == LF_FATAL) { \
LF_ERR(TRIG, "Scheduling an value, that doesn't have value!"); \
Scheduler *sched = &(action)->super.super.parent->env->scheduler; \
sched->do_shutdown(sched, sched->current_tag(sched)); \
sched->do_shutdown(sched, sched->current_tag(sched)); \
throw("Tried to schedule a value onto an action without a type!"); \
} \
} while (0)
Expand Down Expand Up @@ -455,12 +455,14 @@ typedef struct FederatedInputConnection FederatedInputConnection;
#define ENTRY_POINT(MainReactorName, Timeout, KeepAlive) \
MainReactorName main_reactor; \
Environment env; \
DynamicScheduler scheduler; \
void lf_exit(void) { Environment_free(&env); } \
void lf_start() { \
Environment_ctor(&env, (Reactor *)&main_reactor); \
DynamicScheduler_ctor(&scheduler, &env); \
Environment_ctor(&env, &scheduler.scheduler, (Reactor *)&main_reactor); \
MainReactorName##_ctor(&main_reactor, NULL, &env); \
env.scheduler.duration = Timeout; \
env.scheduler.keep_alive = KeepAlive; \
env.scheduler->set_duration(env.scheduler, Timeout); \
env.scheduler->keep_alive = KeepAlive; \
env.assemble(&env); \
env.start(&env); \
lf_exit(); \
Expand All @@ -469,13 +471,16 @@ typedef struct FederatedInputConnection FederatedInputConnection;
#define ENTRY_POINT_FEDERATED(FederateName, Timeout, KeepAlive, HasInputs, NumBundles, IsLeader) \
FederateName main_reactor; \
Environment env; \
DynamicScheduler scheduler; \
void lf_exit(void) { Environment_free(&env); } \
void lf_start() { \
Environment_ctor(&env, (Reactor *)&main_reactor); \
env.scheduler.duration = Timeout; \
env.scheduler.keep_alive = KeepAlive; \
env.scheduler.leader = IsLeader; \
DynamicScheduler_ctor(&scheduler, &env); \
Environment_ctor(&env, &scheduler.scheduler, (Reactor *)&main_reactor); \
env.scheduler->duration = Timeout; \
env.scheduler->keep_alive = KeepAlive; \
scheduler.leader = IsLeader; \
env.has_async_events = HasInputs; \
\
env.enter_critical_section(&env); \
FederateName##_ctor(&main_reactor, NULL, &env); \
env.net_bundles_size = NumBundles; \
Expand Down
20 changes: 15 additions & 5 deletions include/reactor-uc/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ typedef struct Scheduler Scheduler;
typedef struct Environment Environment;

struct Scheduler {
long int start_time;
long int start_time;
interval_t duration; // The duration after which the program should stop.
bool keep_alive; // Whether the program should keep running even if there are no more events to process.

/**
* @brief Schedules an event on trigger at a specified tag. This function will
Expand Down Expand Up @@ -62,13 +64,21 @@ struct Scheduler {

void (*acquire_and_schedule_start_tag)(Scheduler *self);

void (*set_duration)(Scheduler* self, interval_t duration);
void (*set_duration)(Scheduler *self, interval_t duration);

lf_ret_t (*add_to_reaction_queue)(Scheduler *self, Reaction* reaction);
lf_ret_t (*add_to_reaction_queue)(Scheduler *self, Reaction *reaction);

tag_t (*current_tag)(Scheduler* self);
tag_t (*current_tag)(Scheduler *self);
};

void Scheduler_ctor(Scheduler* self);
void Scheduler_ctor(Scheduler *self);

#define SCHEDULER_DYNAMIC

#if defined(SCHEDULER_DYNAMIC)
#include "schedulers/dynamic/scheduler.h"
#else
#include "schedulers/static/scheduler.h"
#endif

#endif
12 changes: 5 additions & 7 deletions include/reactor-uc/schedulers/dynamic/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ struct DynamicScheduler {
// that are registered for cleanup at the end of the current tag.
Trigger *cleanup_ll_head;
Trigger *cleanup_ll_tail;
bool leader; // Whether this scheduler is the leader in a federated program and selects the start tag.
instant_t start_time; // The physical time at which the program started.
interval_t duration; // The duration after which the program should stop.
tag_t stop_tag; // The tag at which the program should stop. This is set by the user or by the scheduler.
tag_t current_tag; // The current logical tag. Set by the scheduler and read by user in the reaction bodies.
bool keep_alive; // Whether the program should keep running even if there are no more events to process.
bool leader; // Whether this scheduler is the leader in a federated program and selects the start tag.
// instant_t start_time; // The physical time at which the program started.
tag_t stop_tag; // The tag at which the program should stop. This is set by the user or by the scheduler.
tag_t current_tag; // The current logical tag. Set by the scheduler and read by user in the reaction bodies.
};

void DynamicScheduler_ctor(DynamicScheduler *self, Environment *env);

#endif //SCHEDULER_H
#endif // SCHEDULER_H
65 changes: 26 additions & 39 deletions include/reactor-uc/schedulers/static/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,31 @@
*/
void push_pop_peek_pqueue(void *self);

void execute_inst_ADD(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_ADDI(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BEQ(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BGE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BNE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_DU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_EXE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JAL(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JALR(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_STP(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_ADD(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_ADDI(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3,
bool debug, size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BEQ(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BGE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BNE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_DU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_EXE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JAL(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JALR(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3,
bool debug, size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_STP(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *program_counter, Reaction **returned_reaction, bool *exit_loop);

#endif
8 changes: 4 additions & 4 deletions include/reactor-uc/schedulers/static/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ typedef struct StaticScheduler StaticScheduler;
typedef struct Environment Environment;

struct StaticScheduler {
Scheduler* scheduler;
Scheduler *scheduler;
Environment *env;
const inst_t** static_schedule;
size_t* pc;
const inst_t **static_schedule;
size_t *pc;
};

void StaticScheduler_ctor(StaticScheduler *self, Environment *env);

#endif //STATIC_SCHEDULER_H
#endif // STATIC_SCHEDULER_H
6 changes: 3 additions & 3 deletions include/reactor-uc/schedulers/static/scheduler_instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ typedef union {
/**
* @brief Virtual instruction function pointer
*/
typedef void (*function_virtual_instruction_t)(
Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3,
bool debug, size_t *pc, Reaction **returned_reaction, bool *exit_loop);
typedef void (*function_virtual_instruction_t)(Platform *platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *program_counter,
Reaction **returned_reaction, bool *exit_loop);

/**
* @brief This struct represents a PRET VM instruction for C platforms.
Expand Down
6 changes: 4 additions & 2 deletions src/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ lf_ret_t Environment_wait_until(Environment *self, instant_t wakeup_time) {
}
}

interval_t Environment_get_logical_time(Environment *self) { return self->scheduler->current_tag(self->scheduler).time; }
interval_t Environment_get_logical_time(Environment *self) {
return self->scheduler->current_tag(self->scheduler).time;
}
interval_t Environment_get_elapsed_logical_time(Environment *self) {
return self->scheduler->current_tag(self->scheduler).time - self->scheduler->start_time;
}
Expand All @@ -63,7 +65,7 @@ void Environment_leave_critical_section(Environment *self) {

void Environment_request_shutdown(Environment *self) { self->scheduler->request_shutdown(self->scheduler); }

void Environment_ctor(Environment *self, Scheduler* scheduler, Reactor *main) {
void Environment_ctor(Environment *self, Scheduler *scheduler, Reactor *main) {
self->main = main;
self->scheduler = scheduler;
self->platform = Platform_new();
Expand Down
4 changes: 1 addition & 3 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
#include "schedulers/dynamic/dynamic.c"
#include "schedulers/static/scheduler.c"

void Scheduler_ctor(Scheduler* self) {
(void)self;
}
void Scheduler_ctor(Scheduler *self) { (void)self; }
Loading

0 comments on commit b1c57ed

Please sign in to comment.