From e4d724d14a8dae4e5bc39c39f9df1ad036e60fef Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 25 Jun 2024 10:34:56 -0700 Subject: [PATCH 1/4] Record reaction start/end when calling violation handler --- core/reactor.c | 2 ++ core/reactor_common.c | 2 ++ core/threaded/reactor_threaded.c | 2 ++ include/api/schedule.h | 20 -------------------- include/core/tracepoint.h | 2 +- lib/schedule.c | 22 ---------------------- 6 files changed, 7 insertions(+), 43 deletions(-) diff --git a/core/reactor.c b/core/reactor.c index abc4f41d1..6e2fd24a1 100644 --- a/core/reactor.c +++ b/core/reactor.c @@ -164,6 +164,7 @@ int _lf_do_step(environment_t* env) { // Deadline violation has occurred. violation = true; // Invoke the local handler, if there is one. + tracepoint_reaction_starts(env, reaction, 0); reaction_function_t handler = reaction->deadline_violation_handler; if (handler != NULL) { (*handler)(reaction->self); @@ -171,6 +172,7 @@ int _lf_do_step(environment_t* env) { // triggered reactions into the queue. schedule_output_reactions(env, reaction, 0); } + tracepoint_reaction_ends(env, reaction, 0); } } diff --git a/core/reactor_common.c b/core/reactor_common.c index 26a489bec..83922735e 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -824,6 +824,7 @@ void schedule_output_reactions(environment_t* env, reaction_t* reaction, int wor violation = true; // Invoke the local handler, if there is one. reaction_function_t handler = downstream_to_execute_now->deadline_violation_handler; + tracepoint_reaction_starts(env, downstream_to_execute_now, worker); if (handler != NULL) { // Assume the mutex is still not held. (*handler)(downstream_to_execute_now->self); @@ -832,6 +833,7 @@ void schedule_output_reactions(environment_t* env, reaction_t* reaction, int wor // triggered reactions into the queue or execute them directly if possible. schedule_output_reactions(env, downstream_to_execute_now, worker); } + tracepoint_reaction_ends(env, downstream_to_execute_now, worker); } } if (!violation) { diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 14d84fd14..93dede985 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -729,6 +729,7 @@ bool _lf_worker_handle_deadline_violation_for_reaction(environment_t* env, int w tracepoint_reaction_deadline_missed(env, reaction, worker_number); violation_occurred = true; // Invoke the local handler, if there is one. + tracepoint_reaction_starts(env, reaction, worker_number); reaction_function_t handler = reaction->deadline_violation_handler; if (handler != NULL) { LF_PRINT_LOG("Worker %d: Deadline violation. Invoking deadline handler.", worker_number); @@ -739,6 +740,7 @@ bool _lf_worker_handle_deadline_violation_for_reaction(environment_t* env, int w schedule_output_reactions(env, reaction, worker_number); // Remove the reaction from the executing queue. } + tracepoint_reaction_ends(env, reaction, worker_number); } } return violation_occurred; diff --git a/include/api/schedule.h b/include/api/schedule.h index 8021814fd..96f3613d8 100644 --- a/include/api/schedule.h +++ b/include/api/schedule.h @@ -195,24 +195,4 @@ trigger_handle_t lf_schedule_value(void* action, interval_t extra_delay, void* v */ trigger_handle_t lf_schedule_trigger(environment_t* env, trigger_t* trigger, interval_t delay, lf_token_t* token); -/** - * @brief Check the deadline of the currently executing reaction against the - * current physical time. - * - * If the deadline has passed, invoke the deadline - * handler (if invoke_deadline_handler parameter is set true) and return true. - * Otherwise, return false. - * - * This function is intended to be used within a reaction that has been invoked without a deadline - * violation, but that wishes to check whether the deadline gets violated _during_ the execution of - * the reaction. This can be used, for example, to implement a timeout mechanism that bounds the - * execution time of a reaction, for example to realize an "anytime" computation. - * - * @param self The self struct of the reactor. - * @param invoke_deadline_handler When this is set true, also invoke deadline - * handler if the deadline has passed. - * @return True if the specified deadline has passed and false otherwise. - */ -bool lf_check_deadline(void* self, bool invoke_deadline_handler); - #endif // API_H diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index cfa1fb956..b2eca5dba 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -103,7 +103,7 @@ int register_user_trace_event(void* self, char* description); * @param worker The thread number of the worker thread or 0 for single-threaded execution. */ #define tracepoint_reaction_starts(env, reaction, worker) \ - call_tracepoint(reaction_starts, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, 0) + call_tracepoint(reaction_starts, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, reaction->deadline) /** * Trace the end of a reaction execution. diff --git a/lib/schedule.c b/lib/schedule.c index 5aa9fd528..46d5c58b3 100644 --- a/lib/schedule.c +++ b/lib/schedule.c @@ -85,28 +85,6 @@ trigger_handle_t lf_schedule_value(void* action, interval_t extra_delay, void* v return return_value; } -/** - * Check the deadline of the currently executing reaction against the - * current physical time. If the deadline has passed, invoke the deadline - * handler (if invoke_deadline_handler parameter is set true) and return true. - * Otherwise, return false. - * - * @param self The self struct of the reactor. - * @param invoke_deadline_handler When this is set true, also invoke deadline - * handler if the deadline has passed. - * @return True if the specified deadline has passed and false otherwise. - */ -bool lf_check_deadline(void* self, bool invoke_deadline_handler) { - reaction_t* reaction = ((self_base_t*)self)->executing_reaction; - if (lf_time_physical() > (lf_time_logical(((self_base_t*)self)->environment) + reaction->deadline)) { - if (invoke_deadline_handler) { - reaction->deadline_violation_handler(self); - } - return true; - } - return false; -} - trigger_handle_t lf_schedule_trigger(environment_t* env, trigger_t* trigger, interval_t extra_delay, lf_token_t* token) { assert(env != GLOBAL_ENVIRONMENT); From 001710c5abdd3c209592fd27b9bb880bbcfc2fe4 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 25 Jun 2024 14:31:02 -0700 Subject: [PATCH 2/4] Update tracepoint macro --- include/core/tracepoint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index b2eca5dba..fd5275d12 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -112,7 +112,7 @@ int register_user_trace_event(void* self, char* description); * @param worker The thread number of the worker thread or 0 for single-threaded execution. */ #define tracepoint_reaction_ends(env, reaction, worker) \ - call_tracepoint(reaction_ends, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, 0) + call_tracepoint(reaction_ends, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, reaction->deadline) /** * Trace a call to schedule. From 0db4cf581a9aba25c85d6b58d962a38da3ce8753 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 28 Jun 2024 12:38:53 -0700 Subject: [PATCH 3/4] Do not delete check_deadline API function --- include/api/schedule.h | 20 ++++++++++++++++++++ lib/schedule.c | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/api/schedule.h b/include/api/schedule.h index 96f3613d8..8021814fd 100644 --- a/include/api/schedule.h +++ b/include/api/schedule.h @@ -195,4 +195,24 @@ trigger_handle_t lf_schedule_value(void* action, interval_t extra_delay, void* v */ trigger_handle_t lf_schedule_trigger(environment_t* env, trigger_t* trigger, interval_t delay, lf_token_t* token); +/** + * @brief Check the deadline of the currently executing reaction against the + * current physical time. + * + * If the deadline has passed, invoke the deadline + * handler (if invoke_deadline_handler parameter is set true) and return true. + * Otherwise, return false. + * + * This function is intended to be used within a reaction that has been invoked without a deadline + * violation, but that wishes to check whether the deadline gets violated _during_ the execution of + * the reaction. This can be used, for example, to implement a timeout mechanism that bounds the + * execution time of a reaction, for example to realize an "anytime" computation. + * + * @param self The self struct of the reactor. + * @param invoke_deadline_handler When this is set true, also invoke deadline + * handler if the deadline has passed. + * @return True if the specified deadline has passed and false otherwise. + */ +bool lf_check_deadline(void* self, bool invoke_deadline_handler); + #endif // API_H diff --git a/lib/schedule.c b/lib/schedule.c index 46d5c58b3..5aa9fd528 100644 --- a/lib/schedule.c +++ b/lib/schedule.c @@ -85,6 +85,28 @@ trigger_handle_t lf_schedule_value(void* action, interval_t extra_delay, void* v return return_value; } +/** + * Check the deadline of the currently executing reaction against the + * current physical time. If the deadline has passed, invoke the deadline + * handler (if invoke_deadline_handler parameter is set true) and return true. + * Otherwise, return false. + * + * @param self The self struct of the reactor. + * @param invoke_deadline_handler When this is set true, also invoke deadline + * handler if the deadline has passed. + * @return True if the specified deadline has passed and false otherwise. + */ +bool lf_check_deadline(void* self, bool invoke_deadline_handler) { + reaction_t* reaction = ((self_base_t*)self)->executing_reaction; + if (lf_time_physical() > (lf_time_logical(((self_base_t*)self)->environment) + reaction->deadline)) { + if (invoke_deadline_handler) { + reaction->deadline_violation_handler(self); + } + return true; + } + return false; +} + trigger_handle_t lf_schedule_trigger(environment_t* env, trigger_t* trigger, interval_t extra_delay, lf_token_t* token) { assert(env != GLOBAL_ENVIRONMENT); From 4729ee0a4495c7b27e1074e8cf23db1f6a4fd505 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 30 Jun 2024 22:16:42 -0700 Subject: [PATCH 4/4] Format --- include/core/tracepoint.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index fd5275d12..4a8a5bc79 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -103,7 +103,8 @@ int register_user_trace_event(void* self, char* description); * @param worker The thread number of the worker thread or 0 for single-threaded execution. */ #define tracepoint_reaction_starts(env, reaction, worker) \ - call_tracepoint(reaction_starts, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, reaction->deadline) + call_tracepoint(reaction_starts, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, \ + reaction->deadline) /** * Trace the end of a reaction execution. @@ -112,7 +113,8 @@ int register_user_trace_event(void* self, char* description); * @param worker The thread number of the worker thread or 0 for single-threaded execution. */ #define tracepoint_reaction_ends(env, reaction, worker) \ - call_tracepoint(reaction_ends, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, reaction->deadline) + call_tracepoint(reaction_ends, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, \ + reaction->deadline) /** * Trace a call to schedule.