Skip to content

Commit

Permalink
Trace deadline violations (lf-lang#457)
Browse files Browse the repository at this point in the history
* Record reaction start/end when calling violation handler

* Update tracepoint macro

* Do not delete check_deadline API function

* Format

---------

Co-authored-by: Christian Menard <[email protected]>
  • Loading branch information
2 people authored and EhsanKhodadad committed Aug 1, 2024
1 parent fe7748c commit a90e03b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ 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);
// If the reaction produced outputs, put the resulting
// triggered reactions into the queue.
schedule_output_reactions(env, reaction, 0);
}
tracepoint_reaction_ends(env, reaction, 0);
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions include/core/tracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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.
Expand All @@ -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, 0)
call_tracepoint(reaction_ends, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, \
reaction->deadline)

/**
* Trace a call to schedule.
Expand Down

0 comments on commit a90e03b

Please sign in to comment.