reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
scheduler_GEDF_NP.c File Reference

Global Earliest Deadline First (GEDF) non-preemptive scheduler for the threaded runtime of the C target of Lingua Franca. More...

#include "lf_types.h"
#include <assert.h>
#include "low_level_platform.h"
#include "environment.h"
#include "pqueue.h"
#include "reactor_threaded.h"
#include "scheduler_instance.h"
#include "scheduler_sync_tag_advance.h"
#include "scheduler.h"
#include "tracepoint.h"
#include "util.h"

Data Structures

struct  custom_scheduler_data_t
 

Macros

#define NUMBER_OF_WORKERS   1
 

Typedefs

typedef struct custom_scheduler_data_t custom_scheduler_data_t
 

Functions

void lf_sched_init (environment_t *env, size_t number_of_workers, sched_params_t *params)
 Initialize the scheduler.
 
void lf_sched_free (lf_scheduler_t *scheduler)
 Free the memory used by the scheduler.
 
reaction_tlf_sched_get_ready_reaction (lf_scheduler_t *scheduler, int worker_number)
 Ask the scheduler for one more reaction.
 
void lf_sched_done_with_reaction (size_t worker_number, reaction_t *done_reaction)
 Inform the scheduler that worker thread 'worker_number' is done executing the 'done_reaction'.
 
void lf_scheduler_trigger_reaction (lf_scheduler_t *scheduler, reaction_t *reaction, int worker_number)
 Inform the scheduler that worker thread 'worker_number' would like to trigger 'reaction' at the current tag.
 

Detailed Description

Global Earliest Deadline First (GEDF) non-preemptive scheduler for the threaded runtime of the C target of Lingua Franca.

Author
Soroush Bateni
Edward A. Lee
Marten Lohstroh

At each tag, this scheduler prioritizes reactions with the smallest (inferred) deadline. An inferred deadline for reaction R is either an explicitly declared deadline or the declared deadline of a reaction that depends on R. This scheduler is non-preemptive, meaning that once a worker thread starts executing a reaction, it will execute that reaction to completion. The underlying thread scheduler, of course, could preempt the execution in favor of some other worker thread. This scheduler does not take into account execution times of reactions. Moreover, it does not prioritize reactions across distinct tags.

Macro Definition Documentation

◆ NUMBER_OF_WORKERS

#define NUMBER_OF_WORKERS   1

Typedef Documentation

◆ custom_scheduler_data_t

typedef struct custom_scheduler_data_t custom_scheduler_data_t

Function Documentation

◆ lf_sched_done_with_reaction()

void lf_sched_done_with_reaction ( size_t worker_number,
reaction_t * done_reaction )

Inform the scheduler that worker thread 'worker_number' is done executing the 'done_reaction'.

Parameters
schedulerThe scheduler
worker_numberThe worker number for the worker thread that has finished executing 'done_reaction'.
done_reactionThe reaction that is done.

◆ lf_sched_free()

void lf_sched_free ( lf_scheduler_t * scheduler)

Free the memory used by the scheduler.

This must be called when the scheduler is no longer needed.

◆ lf_sched_get_ready_reaction()

reaction_t * lf_sched_get_ready_reaction ( lf_scheduler_t * scheduler,
int worker_number )

Ask the scheduler for one more reaction.

This function blocks until it can return a ready reaction for worker thread 'worker_number' or it is time for the worker thread to stop and exit (where a NULL value would be returned). This function assumes that the environment mutex is not locked.

Parameters
schedulerThe scheduler
worker_numberFor the calling worker thread.
Returns
reaction_t* A reaction for the worker to execute. NULL if the calling worker thread should exit.

◆ lf_sched_init()

void lf_sched_init ( environment_t * env,
size_t number_of_workers,
sched_params_t * params )

Initialize the scheduler.

This has to be called before other functions of the scheduler can be used. If the scheduler is already initialized, this will be a no-op.

Parameters
envEnvironment within which we are executing.
number_of_workersIndicate how many workers this scheduler will be managing.
optionPointer to a sched_params_t struct containing additional scheduler parameters.

◆ lf_scheduler_trigger_reaction()

void lf_scheduler_trigger_reaction ( lf_scheduler_t * scheduler,
reaction_t * reaction,
int worker_number )

Inform the scheduler that worker thread 'worker_number' would like to trigger 'reaction' at the current tag.

If a worker number is not available (e.g., this function is not called by a worker thread), -1 should be passed as the 'worker_number'.

The scheduler will ensure that the same reaction is not triggered twice in the same tag.

Parameters
schedulerThe scheduler
reactionThe reaction to trigger at the current tag.
worker_numberThe ID of the worker that is making this call. 0 should be used if there is only one worker (e.g., when the program is using the single-threaded C runtime). -1 is used for an anonymous call in a context where a worker number does not make sense (e.g., the caller is not a worker thread).