Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal Models #6

Merged
merged 20 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f6306c1
modes: Migrated changes for modal models
a-sr Oct 20, 2021
0718169
modes: Added support for resetting state variables
a-sr Oct 20, 2021
2416c66
Added handling for suspended events with micro steps
a-sr Oct 29, 2021
4f5ead5
modes: Memory of suspended evens will be freed at termination
a-sr Nov 4, 2021
79c7af7
modes: Switched to using _lf_schedule_at_tag when for suspended events
a-sr Dec 3, 2021
4dc8f81
Merge branch 'main' into modal-models
a-sr Dec 8, 2021
9372810
Merge remote-tracking branch 'origin/main' into modal-models
a-sr Dec 8, 2021
9951906
modes: Fix bug in defragmentation of suspended events list
a-sr Dec 8, 2021
52ad31a
modes: Switched to a linked list structure to store suspended events
a-sr Dec 10, 2021
9f133ca
modes: Added experimental support for threaded execution for modes
a-sr Dec 15, 2021
19a9f59
modes: Improved allocation of array.
a-sr Dec 16, 2021
e1d381e
modes: Added explicit cast after malloc
a-sr Dec 16, 2021
e5b09f8
Merge remote-tracking branch 'origin/main' into modal-models
a-sr Feb 3, 2022
f027918
modes: Fixed bug in suspended events list and timer offset
a-sr Feb 4, 2022
b66703c
Merge remote-tracking branch 'origin/main' into modal-models
a-sr Feb 11, 2022
7e67964
Merge remote-tracking branch 'origin/main' into modal-models
a-sr Feb 17, 2022
9919e30
Merged main into modal-models and resolved conflicts (hopefully corre…
edwardalee Feb 25, 2022
cc0f07c
Small stylistic changes to lf_sched_trigger_reaction implementations …
edwardalee Feb 25, 2022
0d92a8f
Merge with main.
edwardalee Feb 27, 2022
76a055f
Specify to use master branch of lingua-franca when running CI tests
edwardalee Feb 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:

lf-gedf-np:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@c-new-scheduler
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
scheduler: GEDF_NP

lf-gedf-np-ci:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@c-new-scheduler
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
Expand Down
12 changes: 12 additions & 0 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ void print_snapshot() {
* worker number does not make sense (e.g., the caller is not a worker thread).
*/
void _lf_trigger_reaction(reaction_t* reaction, int worker_number) {
#ifdef MODAL_REACTORS
// Check if reaction is disabled by mode inactivity
if (!_lf_mode_is_active(reaction->mode)) {
DEBUG_PRINT("Suppressing downstream reaction %s due inactivity of mode %s.", reaction->name, reaction->mode->name);
return; // Suppress reaction by preventing entering reaction queue
}
#endif
// Do not enqueue this reaction twice.
if (reaction->status == inactive) {
DEBUG_PRINT("Enqueing downstream reaction %s, which has level %lld.",
Expand Down Expand Up @@ -233,6 +240,11 @@ int _lf_do_step() {
reaction->status = inactive;
}

#ifdef MODAL_REACTORS
// At the end of the step, perform mode transitions
_lf_handle_mode_changes();
#endif

// No more reactions should be blocked at this point.
//assert(pqueue_size(blocked_q) == 0);

Expand Down
65 changes: 65 additions & 0 deletions core/reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ do { \
#endif


/**
* Sets the next mode of a modal reactor. Same as SET for outputs, only
* the last value will have effect if invoked multiple times.
* Works only in reactions with the target mode declared as effect.
*
* @param mode The target mode to set for activation.
*/
#ifdef MODAL_REACTORS
#define _LF_SET_MODE(mode) \
do { \
self->_lf__mode_state.next_mode = mode; \
self->_lf__mode_state.mode_change = _lf_##mode##_change_type; \
} while(0)
#endif

/**
* Macro for extracting the deadline from the index of a reaction.
* The reaction queue is sorted according to this index, and the
Expand Down Expand Up @@ -442,6 +457,45 @@ typedef struct token_present_t {
bool reset_is_present; // True to set is_present to false after calling done_using().
} token_present_t;


#ifdef MODAL_REACTORS
/** Typedef for reactor_mode_t struct, used for representing a mode. */
typedef struct reactor_mode_t reactor_mode_t;
/** Typedef for reactor_mode_state_t struct, used for storing modal state of reactor and/or its relation to enclosing modes. */
typedef struct reactor_mode_state_t reactor_mode_state_t;
/** Typedef for mode_state_variable_reset_data_t struct, used for storing data for resetting state variables nested in modes. */
typedef struct mode_state_variable_reset_data_t mode_state_variable_reset_data_t;

/** A struct to represent a single mode instace in a reactor instance. */
struct reactor_mode_t {
reactor_mode_state_t* state; // Pointer to a struct with the reactor's mode state. INSTANCE.
string name; // Name of this mode.
instant_t deactivation_time; // Time when the mode was left.
};
/** A struct to store state of the modes in a reactor instance and/or its relation to enclosing modes. */
struct reactor_mode_state_t {
reactor_mode_t* parent_mode; // Pointer to the next enclosing mode (if exsits).
reactor_mode_t* initial_mode; // Pointer to the initial mode.
reactor_mode_t* active_mode; // Pointer to the currently active mode.
reactor_mode_t* next_mode; // Pointer to the next mode to activate at the end of this step (if set).
char mode_change; // A mode change type flag (0: no change, 1: reset, 2: history).
};
/** A struct to store data for resetting state variables nested in modes. */
struct mode_state_variable_reset_data_t {
reactor_mode_t* mode; // Pointer to the enclosing mode.
void* target; // Pointer to the target variable.
void* source; // Pointer to the data source.
size_t size; // The size of the variable.
};
#else
/*
* Reactions and triggers must have a mode pointer to set up connection to enclosing modes,
* also when they are precompiled without modal reactors in order to later work in modal reactors.
* Hence define mode type as void in the absence of modes to treat mode pointer as void pointers for that time being.
*/
typedef void reactor_mode_t;
#endif

/**
* Reaction activation record to push onto the reaction queue.
* Some of the information in this struct is common among all instances
Expand Down Expand Up @@ -487,6 +541,8 @@ struct reaction_t {
char* name; // If logging is set to LOG or higher, then this will
// point to the full name of the reactor followed by
// the reaction number.
reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
// If enclosed in multiple, this will point to the innermost mode.
};

/** Typedef for event_t struct, used for storing activation records. */
Expand Down Expand Up @@ -537,6 +593,8 @@ struct trigger_t {
// coordination.
// - Finally, if status is 'present', then this is an error since multiple
// downstream messages have been produced for the same port for the same logical time.
reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
// If enclosed in multiple, this will point to the innermost mode.
#ifdef FEDERATED
tag_t last_known_status_tag; // Last known status of the port, either via a timed message, a port absent, or a
// TAG from the RTI.
Expand Down Expand Up @@ -717,6 +775,13 @@ void terminate_execution(void);
*/
bool _lf_trigger_shutdown_reactions(void);

/**
* Function (to be code generated) to handle mode changes.
*/
#ifdef MODAL_REACTORS
void _lf_handle_mode_changes();
#endif

/**
* Create a new token and initialize it.
* The value pointer will be NULL and the length will be 0.
Expand Down
Loading