From 5e2883524c30314fcf76ef4e83c3e8177c8a63d5 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 13:51:42 -0700 Subject: [PATCH 1/9] Add actions status field to the is_present_fields_abbreviated array --- core/reactor_common.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index 83a1592b9..6ca0c032d 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -303,8 +303,12 @@ void _lf_pop_events(environment_t* env) { } } - // Mark the trigger present. + // Mark the trigger present and store a pointer to it for marking it as absent later. event->trigger->status = present; + int ipfas = lf_atomic_fetch_add(&env->is_present_fields_abbreviated_size, 1); + if (ipfas < env->is_present_fields_size) { + env->is_present_fields_abbreviated[ipfas] = (bool*)&event->trigger->status; + } // If the trigger is a periodic timer, create a new event for its next execution. if (event->trigger->is_timer && event->trigger->period > 0LL) { @@ -323,9 +327,6 @@ void _lf_pop_events(environment_t* env) { // freed prematurely. _lf_done_using(token); - // Mark the trigger present. - event->trigger->status = present; - lf_recycle_event(env, event); // Peek at the next event in the event queue. @@ -603,8 +604,12 @@ trigger_handle_t _lf_insert_reactions_for_trigger(environment_t* env, trigger_t* // for which we decrement the reference count. _lf_replace_template_token((token_template_t*)trigger, token); - // Mark the trigger present. + // Mark the trigger present and store a pointer to it for marking it as absent later. trigger->status = present; + int ipfas = lf_atomic_fetch_add(&env->is_present_fields_abbreviated_size, 1); + if (ipfas < env->is_present_fields_size) { + env->is_present_fields_abbreviated[ipfas] = (bool*)&trigger->status; + } // Push the corresponding reactions for this trigger // onto the reaction queue. From fa5a7aee3b2e62e7439ed705148d355222ba57c9 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 14:33:23 -0700 Subject: [PATCH 2/9] Dont store status field of the timers in the is_present_fields array --- core/reactor_common.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index 6ca0c032d..d37600e8a 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -303,17 +303,19 @@ void _lf_pop_events(environment_t* env) { } } - // Mark the trigger present and store a pointer to it for marking it as absent later. + // Mark the trigger present event->trigger->status = present; - int ipfas = lf_atomic_fetch_add(&env->is_present_fields_abbreviated_size, 1); - if (ipfas < env->is_present_fields_size) { - env->is_present_fields_abbreviated[ipfas] = (bool*)&event->trigger->status; - } // If the trigger is a periodic timer, create a new event for its next execution. if (event->trigger->is_timer && event->trigger->period > 0LL) { // Reschedule the trigger. lf_schedule_trigger(env, event->trigger, event->trigger->period, NULL); + } else { + // For actions, store a pointer to status field so it is reset later. + int ipfas = lf_atomic_fetch_add(&env->is_present_fields_abbreviated_size, 1); + if (ipfas < env->is_present_fields_size) { + env->is_present_fields_abbreviated[ipfas] = (bool*)&event->trigger->status; + } } // Copy the token pointer into the trigger struct so that the From 1d79e1162f8f07b4f396b3b325a02567ed87cbef Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 16:12:37 -0700 Subject: [PATCH 3/9] Add a verification of environment which is called when we compile with debug flags. --- core/environment.c | 6 ++++++ core/reactor_common.c | 7 +++++++ include/core/environment.h | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/core/environment.c b/core/environment.c index af192c09b..eb012589b 100644 --- a/core/environment.c +++ b/core/environment.c @@ -284,3 +284,9 @@ int environment_init(environment_t* env, const char* name, int id, int num_worke env->initialized = true; return 0; } + +void environment_verify(environment_t* env) { + for (int i = 0; i < env->is_present_fields_size; i++) { + LF_ASSERT_NON_NULL(env->is_present_fields[i]); + } +} \ No newline at end of file diff --git a/core/reactor_common.c b/core/reactor_common.c index d37600e8a..731391ab5 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1103,6 +1103,13 @@ void initialize_global(void) { // Call the code-generated function to initialize all actions, timers, and ports // This is done for all environments/enclaves at the same time. _lf_initialize_trigger_objects(); + +#if !defined(NDBEUG) + // If we are testing, verify that environment with pointers is correctly set up. + for (int i = 0; i < num_envs; i++) { + environment_verify(&envs[i]); + } +#endif } /** diff --git a/include/core/environment.h b/include/core/environment.h index 8099eed26..9f3960a6f 100644 --- a/include/core/environment.h +++ b/include/core/environment.h @@ -112,6 +112,13 @@ int environment_init(environment_t* env, const char* name, int id, int num_worke int num_is_present_fields, int num_modes, int num_state_resets, int num_watchdogs, const char* trace_file_name); +/** + * @brief Verify that the environment is correctly set up. + * + * @param env + */ +void environment_verify(environment_t* env); + /** * @brief Free the dynamically allocated memory on the environment struct. * @param env The environment in which we are executing. From 988d25c8773d174c917d90f42663542b66155ad1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 16:15:38 -0700 Subject: [PATCH 4/9] Fix tiny mistake --- core/reactor_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index 731391ab5..a780c0e2f 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1104,7 +1104,7 @@ void initialize_global(void) { // This is done for all environments/enclaves at the same time. _lf_initialize_trigger_objects(); -#if !defined(NDBEUG) +#if defined(LF_SINGLE_THREADED) && !defined(NDBEUG) // If we are testing, verify that environment with pointers is correctly set up. for (int i = 0; i < num_envs; i++) { environment_verify(&envs[i]); From b17ed4fdf3fbf44391fd5ffb0b528cf420634ee1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 24 Sep 2024 16:19:55 -0700 Subject: [PATCH 5/9] Another typo --- core/reactor_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index a780c0e2f..adc0b71e0 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1104,7 +1104,7 @@ void initialize_global(void) { // This is done for all environments/enclaves at the same time. _lf_initialize_trigger_objects(); -#if defined(LF_SINGLE_THREADED) && !defined(NDBEUG) +#if !defined(LF_SINGLE_THREADED) && !defined(NDBEUG) // If we are testing, verify that environment with pointers is correctly set up. for (int i = 0; i < num_envs; i++) { environment_verify(&envs[i]); From 6650f3616dde885393d97f5732645e4a60da8596 Mon Sep 17 00:00:00 2001 From: erling Date: Tue, 24 Sep 2024 18:25:53 -0700 Subject: [PATCH 6/9] Update core/reactor_common.c Co-authored-by: Edward A. Lee --- core/reactor_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index adc0b71e0..455b3a065 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1104,7 +1104,7 @@ void initialize_global(void) { // This is done for all environments/enclaves at the same time. _lf_initialize_trigger_objects(); -#if !defined(LF_SINGLE_THREADED) && !defined(NDBEUG) +#if !defined(LF_SINGLE_THREADED) && !defined(NDEBUG) // If we are testing, verify that environment with pointers is correctly set up. for (int i = 0; i < num_envs; i++) { environment_verify(&envs[i]); From 12ba4ee56a70fc87b7e7b0a53dd5f9a425a9dc00 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Thu, 26 Sep 2024 22:38:51 -0700 Subject: [PATCH 7/9] Update lingua-franca-ref.txt --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 1f7391f92..8ac1011e3 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -master +fix-action-present-bug From 165f3fe1077eb98f3a888a70d61a710bfac59778 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sat, 28 Sep 2024 16:26:19 -0700 Subject: [PATCH 8/9] Point to lingua-franca/master --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 8ac1011e3..1f7391f92 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -fix-action-present-bug +master From 5a122ceb089c4f61c5fa5328533a03f3b4f26797 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 29 Sep 2024 07:30:08 -0700 Subject: [PATCH 9/9] Point to add-reaction branch --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 1f7391f92..5d6695559 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -master +add-reaction