Skip to content

Commit

Permalink
Begin to support the static scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Feb 4, 2025
1 parent f5cd92b commit 081becc
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 18 deletions.
9 changes: 9 additions & 0 deletions examples/posix/static/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.20.0)
project(reactor-uc-posix-hello)

set(PLATFORM "POSIX" CACHE STRING "Platform to target")
set(SCHEDULER "STATIC" CACHE STRING "Scheduler to use")
add_subdirectory(reactor-uc)

add_executable(app timer_test.c)
target_link_libraries(app PRIVATE reactor-uc)
Empty file.
48 changes: 48 additions & 0 deletions examples/posix/static/timer_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/schedulers/static/scheduler.h"
#include "static_schedule.c"

LF_DEFINE_TIMER_STRUCT(TimerTest, t, 1, 0)
LF_DEFINE_TIMER_CTOR(TimerTest, t, 1, 0)
LF_DEFINE_REACTION_STRUCT(TimerTest, reaction, 0)
LF_DEFINE_REACTION_CTOR(TimerTest, reaction, 0)

typedef struct {
Reactor super;
LF_REACTION_INSTANCE(TimerTest, reaction);
LF_TIMER_INSTANCE(TimerTest, t);
LF_REACTOR_BOOKKEEPING_INSTANCES(1,1,0);
int cnt;
} TimerTest;

LF_DEFINE_REACTION_BODY(TimerTest, reaction) {
LF_SCOPE_SELF(TimerTest);
LF_SCOPE_ENV();
printf("Hello World @ %lld\n", env->get_elapsed_logical_time(env));
self->cnt++;
}

LF_REACTOR_CTOR_SIGNATURE(TimerTest) {
LF_REACTOR_CTOR_PREAMBLE();
LF_REACTOR_CTOR(TimerTest);
LF_INITIALIZE_REACTION(TimerTest, reaction);
LF_INITIALIZE_TIMER(TimerTest, t, MSEC(0), MSEC(1));
LF_TIMER_REGISTER_EFFECT(self->t, self->reaction);
}

TimerTest my_reactor;
Environment env;
void test_simple() {
Environment_ctor(&env, (Reactor *)&my_reactor);
env.scheduler->duration = MSEC(100);
((StaticScheduler*)env.scheduler)->static_schedule = NULL; // FIXME: register schedule here.
TimerTest_ctor(&my_reactor, NULL, &env);
env.assemble(&env);
env.start(&env);
Environment_free(&env);
}

int main() {
test_simple();
return 0;
}
1 change: 1 addition & 0 deletions include/reactor-uc/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

typedef struct Environment Environment;
extern Environment *_lf_environment; // NOLINT
typedef struct Scheduler Scheduler;

struct Environment {
Reactor *main; // The top-level reactor of the program.
Expand Down
8 changes: 0 additions & 8 deletions include/reactor-uc/reactor-uc.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#ifndef REACTOR_UC_REACTOR_UC_H
#define REACTOR_UC_REACTOR_UC_H

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

#include "reactor-uc/action.h"
#include "reactor-uc/builtin_triggers.h"
#include "reactor-uc/connection.h"
Expand Down
2 changes: 2 additions & 0 deletions include/reactor-uc/scheduler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef REACTOR_UC_SCHEDULER_H
#define REACTOR_UC_SCHEDULER_H

#include "reactor-uc/reactor-uc.h"

typedef struct Scheduler Scheduler;
typedef struct Environment Environment;

Expand Down
3 changes: 2 additions & 1 deletion include/reactor-uc/schedulers/static/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#include "reactor-uc/error.h"
#include "reactor-uc/queues.h"
#include "reactor-uc/scheduler.h"
#include "reactor-uc/schedulers/static/scheduler_instructions.h"

typedef struct StaticScheduler StaticScheduler;
typedef struct Environment Environment;

struct StaticScheduler {
Scheduler *super;
Scheduler super;
Environment *env;
const inst_t **static_schedule;
size_t *pc;
Expand Down
1 change: 1 addition & 0 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#include "schedulers/static/scheduler.c"
#include "schedulers/static/instructions.c"
#else
#error "Unsupported scheduler macro"
#endif
36 changes: 27 additions & 9 deletions src/schedulers/static/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

static StaticScheduler scheduler;

Reaction *lf_sched_get_ready_reaction(StaticScheduler *scheduler, int worker_number) {
void *interpret(StaticScheduler *scheduler, int worker_number) {
LF_PRINT_DEBUG("Worker %d inside lf_sched_get_ready_reaction", worker_number);

const inst_t *current_schedule = scheduler->static_schedule[worker_number];
Expand Down Expand Up @@ -37,17 +37,35 @@ Reaction *lf_sched_get_ready_reaction(StaticScheduler *scheduler, int worker_num
return returned_reaction;
}

void StaticScheduler_run(Scheduler *untyped_self) {
StaticScheduler *self = (StaticScheduler *)untyped_self;
(void)self;
// Environment *env = self->env;
// lf_ret_t res;
printf("Hello from the static scheduler\n");
}

void StaticScheduler_acquire_and_schedule_start_tag(Scheduler *untyped_self) {
StaticScheduler *self = (StaticScheduler *)untyped_self;
(void)self;
// Environment *env = self->env;
// lf_ret_t res;
}

void StaticScheduler_ctor(StaticScheduler *self, Environment *env, const inst_t **static_schedule) {
self->env = env;
self->static_schedule = static_schedule;

self->super->run = Scheduler_run;
self->super->do_shutdown = Scheduler_do_shutdown;
self->super->schedule_at = Scheduler_schedule_at;
self->super->schedule_at_locked = Scheduler_schedule_at_locked;
self->super->register_for_cleanup = Scheduler_register_for_cleanup;
self->super->request_shutdown = Scheduler_request_shutdown;
self->super->acquire_and_schedule_start_tag = Scheduler_acquire_and_schedule_start_tag;
self->super.run = StaticScheduler_run;
self->super.do_shutdown = NULL;
self->super.schedule_at = NULL; // FIXME: Expect runtime exception.
self->super.schedule_at_locked = NULL;
self->super.register_for_cleanup = NULL;
self->super.request_shutdown = NULL;
self->super.acquire_and_schedule_start_tag = StaticScheduler_acquire_and_schedule_start_tag;
}

Scheduler *Scheduler_new(void) { return (Scheduler *)&scheduler; }
Scheduler *Scheduler_new(Environment *env) {
StaticScheduler_ctor(&scheduler, env, NULL); // FIXME: Supply scheduler pointer.
return (Scheduler *)&scheduler;
}

0 comments on commit 081becc

Please sign in to comment.