Add Hybrid Automata monitor type, per-object and deadline monitors
Subsystems (4)
Gabriele Monaco
maintainerv7 cover Add Hybrid Automata monitor type, per-object and deadline monitors
This series contains several related changes, the main areas are:
* hybrid automata
Hybrid automata are an extension of deterministic automata where each state transition is validating a constraint on a finite number of environment variables.
Hybrid automata can be used to implement timed automata, where the environment variables are clocks.
* per-object monitors
Define the generic per-object monitor allow RV monitors on any kind of object where the user can specify how to get an id (e.g. pid for tasks) and the data type for the monitor_target (e.g. struct task_struct * for tasks).
The monitor storage (e.g. the rv monitor, pointer to the target, etc.) is stored in a hash table indexed by id.
* deadline monitors collection
Add the throttle and nomiss monitors to validate timing aspects of the deadline scheduler, as they work for tasks and servers, their inclusion requires also per-object monitors (for dl entities). Also add the boost and laxity monitors specific to servers.
The entire series can also be found on:
git.kernel.org/pub/scm/linux/kernel/git/gmonaco/linux.git rv_hybrid_automata
Changes since V6 [1]:
* Drop general task_is_scx_enabled() to use the kallsyms-based version
* Search for task and lock RCU in extract_params() callers
* Use offsetofend when copying sched_attr for better clarity
* Export sched_dl_update to modules and fix style
* Use consistent events in examples in docs
* Use cpu_of(rq) helper in tracepoint calls
Changes since V5 [2]:
* Export task_is_scx_enabled() for monitors code to determine if tasks are ext
* tracepoints:
- Add dl_se type to differentiate between fair and ext servers
- Add event to track dl_update_curr not firing other events
* monitors:
- Add support for ext server
- Remove mostly unused dl_server_start from nomiss
- Allow to skip runtime constraint on throttle monitor
- Consider also BATCH and IDLE as fair policies
- Handle events only for supported deadline entities (future proof)
- Add missing transition running -> zero_laxity_wait
- Handle dl_update event in laxity to cover missing update without enqueue nor replenish when multiple server types are active
- Cleanup and sort constraints as generated
* rvgen:
- Use f-strings in newly added code and cleanup
- Sort constraints for predictable generated code
Changes since V4 [3]:
* Do not fire enqueue tracepoint for delayed enqueues
* Do not use boosted dl_se in monitors
* Add enqueue/dequeue validation on snroc model
* Do not export pi_of to deadline.h
* Remove useless variable reset when resetting Hybrid Automata
Changes since V3 [4]:
* Improve ns to jiffy rounding in HA timers
* Use da_handle_start_run_event not to lose the first event in opid
* Sort self_loop_reset_events in rvgen to avoid unpredictable order
* Add enqueue/dequeue tracepoints (Nam Cao)
* Rename handle_syscall as it collides with some UM function
* Simplify idle handling on nomiss and throttle from sleeping
* Improve switch_out for servers in throttle
* Rely on enqueue/dequeue tracepoints instead of syscalls
* Improve timing conditions in laxity and handle resume action
* Remove fragile Stopping state from boost
[1] - https://lore.kernel.org/lkml/[email protected]
[2] - https://lore.kernel.org/lkml/[email protected]
[3] - https://lore.kernel.org/lkml/[email protected]
[4] - https://lore.kernel.org/lkml/[email protected]
To: Steven Rostedt <[email protected]>
To: Nam Cao <[email protected]>
To: Juri Lelli <[email protected]>
Cc: Tomas Glozar <[email protected]>
Cc: Clark Williams <[email protected]>
Cc: John Kacur <[email protected]>
Cc: [email protected]
Gabriele Monaco (14):
rv: Unify DA event handling functions across monitor types
rv: Add Hybrid Automata monitor type verification/rvgen: Allow spaces in and events strings verification/rvgen: Add support for Hybrid Automata Documentation/rv: Add documentation about hybrid automata
rv: Add sample hybrid monitors stall
rv: Convert the opid monitor to a hybrid automaton
rv: Add enqueue/dequeue to snroc monitor
rv: Add support for per-object monitors in DA/HA verification/rvgen: Add support for per-obj monitors
sched: Add deadline tracepoints
sched/deadline: Move some utility functions to deadline.h
rv: Add deadline monitors
rv: Add dl_server specific monitors
Nam Cao (1):
sched: Add task enqueue/dequeue trace points
Documentation/tools/rv/index.rst | 1 + Documentation/tools/rv/rv-mon-stall.rst | 44 ++ .../trace/rv/deterministic_automata.rst | 2 +- Documentation/trace/rv/hybrid_automata.rst | 341 ++++++++++ Documentation/trace/rv/index.rst | 3 + Documentation/trace/rv/monitor_deadline.rst | 278 ++++++++ Documentation/trace/rv/monitor_sched.rst | 101 ++- Documentation/trace/rv/monitor_stall.rst | 43 ++ Documentation/trace/rv/monitor_synthesis.rst | 117 +++- include/linux/rv.h | 39 ++ include/linux/sched/deadline.h | 27 + include/rv/da_monitor.h | 644 +++++++++++++----- include/rv/ha_monitor.h | 478 +++++++++++++ include/trace/events/sched.h | 34 + kernel/sched/core.c | 17 +- kernel/sched/deadline.c | 52 +- kernel/sched/sched.h | 2 + kernel/trace/rv/Kconfig | 21 + kernel/trace/rv/Makefile | 6 + kernel/trace/rv/monitors/boost/Kconfig | 15 + kernel/trace/rv/monitors/boost/boost.c | 258 +++++++ kernel/trace/rv/monitors/boost/boost.h | 146 ++++ kernel/trace/rv/monitors/boost/boost_trace.h | 19 + kernel/trace/rv/monitors/deadline/Kconfig | 10 + kernel/trace/rv/monitors/deadline/deadline.c | 41 ++ kernel/trace/rv/monitors/deadline/deadline.h | 202 ++++++ kernel/trace/rv/monitors/laxity/Kconfig | 14 + kernel/trace/rv/monitors/laxity/laxity.c | 279 ++++++++ kernel/trace/rv/monitors/laxity/laxity.h | 140 ++++ .../trace/rv/monitors/laxity/laxity_trace.h | 19 + kernel/trace/rv/monitors/nomiss/Kconfig | 15 + kernel/trace/rv/monitors/nomiss/nomiss.c | 293 ++++++++ kernel/trace/rv/monitors/nomiss/nomiss.h | 123 ++++ .../trace/rv/monitors/nomiss/nomiss_trace.h | 19 + kernel/trace/rv/monitors/opid/Kconfig | 11 +- kernel/trace/rv/monitors/opid/opid.c | 111 +-- kernel/trace/rv/monitors/opid/opid.h | 86 +-- kernel/trace/rv/monitors/opid/opid_trace.h | 4 + kernel/trace/rv/monitors/snroc/snroc.c | 18 +- kernel/trace/rv/monitors/snroc/snroc.h | 46 +- kernel/trace/rv/monitors/stall/Kconfig | 13 + kernel/trace/rv/monitors/stall/stall.c | 150 ++++ kernel/trace/rv/monitors/stall/stall.h | 81 +++ kernel/trace/rv/monitors/stall/stall_trace.h | 19 + kernel/trace/rv/monitors/throttle/Kconfig | 15 + kernel/trace/rv/monitors/throttle/throttle.c | 285 ++++++++ kernel/trace/rv/monitors/throttle/throttle.h | 116 ++++ .../rv/monitors/throttle/throttle_trace.h | 19 + kernel/trace/rv/rv_trace.h | 70 +- tools/verification/models/deadline/boost.dot | 48 ++ tools/verification/models/deadline/laxity.dot | 37 + tools/verification/models/deadline/nomiss.dot | 41 ++ .../verification/models/deadline/throttle.dot | 44 ++ tools/verification/models/sched/opid.dot | 36 +- tools/verification/models/sched/snroc.dot | 30 +- tools/verification/models/stall.dot | 22 + tools/verification/rvgen/__main__.py | 8 +- tools/verification/rvgen/rvgen/automata.py | 151 +++- tools/verification/rvgen/rvgen/dot2c.py | 47 ++ tools/verification/rvgen/rvgen/dot2k.py | 489 ++++++++++++- tools/verification/rvgen/rvgen/generator.py | 4 +- .../rvgen/rvgen/templates/dot2k/main.c | 2 +- .../rvgen/templates/dot2k/trace_hybrid.h | 16 + 63 files changed, 5382 insertions(+), 480 deletions(-) create mode 100644 Documentation/tools/rv/rv-mon-stall.rst create mode 100644 Documentation/trace/rv/hybrid_automata.rst create mode 100644 Documentation/trace/rv/monitor_deadline.rst create mode 100644 Documentation/trace/rv/monitor_stall.rst create mode 100644 include/rv/ha_monitor.h create mode 100644 kernel/trace/rv/monitors/boost/Kconfig create mode 100644 kernel/trace/rv/monitors/boost/boost.c create mode 100644 kernel/trace/rv/monitors/boost/boost.h create mode 100644 kernel/trace/rv/monitors/boost/boost_trace.h create mode 100644 kernel/trace/rv/monitors/deadline/Kconfig create mode 100644 kernel/trace/rv/monitors/deadline/deadline.c create mode 100644 kernel/trace/rv/monitors/deadline/deadline.h create mode 100644 kernel/trace/rv/monitors/laxity/Kconfig create mode 100644 kernel/trace/rv/monitors/laxity/laxity.c create mode 100644 kernel/trace/rv/monitors/laxity/laxity.h create mode 100644 kernel/trace/rv/monitors/laxity/laxity_trace.h create mode 100644 kernel/trace/rv/monitors/nomiss/Kconfig create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss.c create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss.h create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss_trace.h create mode 100644 kernel/trace/rv/monitors/stall/Kconfig create mode 100644 kernel/trace/rv/monitors/stall/stall.c create mode 100644 kernel/trace/rv/monitors/stall/stall.h create mode 100644 kernel/trace/rv/monitors/stall/stall_trace.h create mode 100644 kernel/trace/rv/monitors/throttle/Kconfig create mode 100644 kernel/trace/rv/monitors/throttle/throttle.c create mode 100644 kernel/trace/rv/monitors/throttle/throttle.h create mode 100644 kernel/trace/rv/monitors/throttle/throttle_trace.h create mode 100644 tools/verification/models/deadline/boost.dot create mode 100644 tools/verification/models/deadline/laxity.dot create mode 100644 tools/verification/models/deadline/nomiss.dot create mode 100644 tools/verification/models/deadline/throttle.dot create mode 100644 tools/verification/models/stall.dot create mode 100644 tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 1/15 Unify DA event handling functions across monitor types
The DA event handling functions are mostly duplicated because the per-task monitors need to propagate the task struct while others do not.
Unify the functions, handle the difference by always passing an identifier which is the task's pid for per-task monitors but is ignored for the other types. Only keep the actual tracepoint calling separated.
---
Notes:
V3:
* Rearrange start/handle helpers to share more code
include/rv/da_monitor.h | 303 +++++++++++++++++----------------------- 1 file changed, 132 insertions(+), 171 deletions(-)
include/rv/da_monitor.h +132 -171
@@ -28,6 +28,13 @@static struct rv_monitor rv_this; +/* +* Type for the target id, default to int but can be overridden. +*/ +#ifndef da_id_type +#define da_id_type int +#endif +static void react (enum states curr_state,enum events event) { rv_react(&rv_this,
@@ -97,90 +104,6 @@ static inline bool da_monitor_handling_event(struct da_monitor *da_mon)return 1 ; } -#if RV_MON_TYPE ==RV_MON_GLOBAL ||RV_MON_TYPE ==RV_MON_PER_CPU -/* -* Event handler for implicit monitors. Implicit monitor is the one which the -* handler does not need to specify which da_monitor to manipulate. Examples -* of implicit monitor are the per_cpu or the global ones. -* -* Retry in case there is a race between getting and setting the next state, -* warn and reset the monitor if it runs out of retries. The monitor should be -* able to handle various orders. -*/ - -static inline bool da_event (struct da_monitor *da_mon,enum events event) -{ -enum states curr_state, next_state; - - curr_state =READ_ONCE (da_mon->curr_state); -for (int i =0 ; i <MAX_DA_RETRY_RACING_EVENTS ; i++) { - next_state =model_get_next_state (curr_state, event); -if (next_state ==INVALID_STATE ) { -react (curr_state, event); -CONCATENATE (trace_error_,MONITOR_NAME )( -model_get_state_name (curr_state), -model_get_event_name (event)); -return false; - } -if (likely (try_cmpxchg (&da_mon->curr_state, &curr_state, next_state))) { -CONCATENATE (trace_event_,MONITOR_NAME )( -model_get_state_name (curr_state), -model_get_event_name (event), -model_get_state_name (next_state), -model_is_final_state (next_state)); -return true; - } - } - -trace_rv_retries_error (__stringify (MONITOR_NAME ),model_get_event_name (event)); - pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) -" retries reached for event %s, resetting monitor %s" , -model_get_event_name (event),__stringify (MONITOR_NAME )); -return false; -} - -#elif RV_MON_TYPE ==RV_MON_PER_TASK -/* -* Event handler for per_task monitors. -* -* Retry in case there is a race between getting and setting the next state, -* warn and reset the monitor if it runs out of retries. The monitor should be -* able to handle various orders. -*/ - -static inline bool da_event (struct da_monitor *da_mon,struct task_struct *tsk, -enum events event) -{ -enum states curr_state, next_state; - - curr_state =READ_ONCE (da_mon->curr_state); -for (int i =0 ; i <MAX_DA_RETRY_RACING_EVENTS ; i++) { - next_state =model_get_next_state (curr_state, event); -if (next_state ==INVALID_STATE ) { -react (curr_state, event); -CONCATENATE (trace_error_,MONITOR_NAME )(tsk->pid, -model_get_state_name (curr_state), -model_get_event_name (event)); -return false; - } -if (likely (try_cmpxchg (&da_mon->curr_state, &curr_state, next_state))) { -CONCATENATE (trace_event_,MONITOR_NAME )(tsk->pid, -model_get_state_name (curr_state), -model_get_event_name (event), -model_get_state_name (next_state), -model_is_final_state (next_state)); -return true; - } - } - -trace_rv_retries_error (__stringify (MONITOR_NAME ),model_get_event_name (event)); - pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) -" retries reached for event %s, resetting monitor %s" , -model_get_event_name (event),__stringify (MONITOR_NAME )); -return false; -} -#endif /* RV_MON_TYPE */ -#if RV_MON_TYPE ==RV_MON_GLOBAL /* * Functions to define, init and get a global monitor.
@@ -335,115 +258,179 @@ static inline void da_monitor_destroy(void)#if RV_MON_TYPE ==RV_MON_GLOBAL ||RV_MON_TYPE ==RV_MON_PER_CPU /* -* Handle event for implicit monitor: da_get_monitor() will figure out -* the monitor. +* Trace events for implicit monitors. Implicit monitor is the one which the +* handler does not need to specify which da_monitor to manipulate. Examples +* of implicit monitor are the per_cpu or the global ones. */ -static inline void __da_handle_event (struct da_monitor *da_mon, -enum events event) +static inline void da_trace_event (struct da_monitor *da_mon, +char *curr_state,char *event, +char *next_state,bool is_final, +da_id_type id) { -bool retval; +CONCATENATE (trace_event_,MONITOR_NAME )(curr_state, event, next_state, + is_final); +} - retval =da_event (da_mon, event); -if (!retval) -da_monitor_reset (da_mon); +static inline void da_trace_error (struct da_monitor *da_mon, +char *curr_state,char *event, +da_id_type id) +{ +CONCATENATE (trace_error_,MONITOR_NAME )(curr_state, event); } +#elif RV_MON_TYPE ==RV_MON_PER_TASK /* -* da_handle_event - handle an event +* Trace events for per_task monitors, report the PID of the task. */ -static inline void da_handle_event (enum events event) -{ -struct da_monitor *da_mon =da_get_monitor (); -bool retval; - retval =da_monitor_handling_event (da_mon); -if (!retval) -return ; +static inline void da_trace_event (struct da_monitor *da_mon, +char *curr_state,char *event, +char *next_state,bool is_final, +da_id_type id) +{ +CONCATENATE (trace_event_,MONITOR_NAME )(id, curr_state, event, + next_state, is_final); +} -__da_handle_event (da_mon, event); +static inline void da_trace_error (struct da_monitor *da_mon, +char *curr_state,char *event, +da_id_type id) +{ +CONCATENATE (trace_error_,MONITOR_NAME )(id, curr_state, event); } +#endif /* RV_MON_TYPE */ /* -* da_handle_start_event - start monitoring or handle event -* -* This function is used to notify the monitor that the system is returning -* to the initial state, so the monitor can start monitoring in the next event. -* Thus: +* da_event - handle an event for the da_mon * -* If the monitor already started, handle the event. -* If the monitor did not start yet, start the monitor but skip the event. +* This function is valid for both implicit and id monitors. +* Retry in case there is a race between getting and setting the next state, +* warn and reset the monitor if it runs out of retries. The monitor should be +* able to handle various orders. */ -static inline bool da_handle_start_event (enum events event) +static inline bool da_event (struct da_monitor *da_mon,enum events event,da_id_type id) { -struct da_monitor *da_mon; +enum states curr_state, next_state; -if (!da_monitor_enabled ()) -return 0 ; + curr_state =READ_ONCE (da_mon->curr_state); +for (int i =0 ; i <MAX_DA_RETRY_RACING_EVENTS ; i++) { + next_state =model_get_next_state (curr_state, event); +if (next_state ==INVALID_STATE ) { +react (curr_state, event); +da_trace_error (da_mon,model_get_state_name (curr_state), +model_get_event_name (event), id); +return false; + } +if (likely (try_cmpxchg (&da_mon->curr_state, &curr_state, next_state))) { +da_trace_event (da_mon,model_get_state_name (curr_state), +model_get_event_name (event), +model_get_state_name (next_state), +model_is_final_state (next_state), id); +return true; + } + } + +trace_rv_retries_error (__stringify (MONITOR_NAME ),model_get_event_name (event)); + pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) +" retries reached for event %s, resetting monitor %s" , +model_get_event_name (event),__stringify (MONITOR_NAME )); +return false; +} - da_mon =da_get_monitor (); +static inline void __da_handle_event_common (struct da_monitor *da_mon, +enum events event,da_id_type id) +{ +if (!da_event (da_mon, event, id)) +da_monitor_reset (da_mon); +} +static inline void __da_handle_event (struct da_monitor *da_mon, +enum events event,da_id_type id) +{ +if (da_monitor_handling_event (da_mon)) +__da_handle_event_common (da_mon, event, id); +} + +static inline bool __da_handle_start_event (struct da_monitor *da_mon, +enum events event,da_id_type id) +{ +if (!da_monitor_enabled ()) +return 0 ;if (unlikely (!da_monitoring (da_mon))) {da_monitor_start (da_mon);return 0 ; } -__da_handle_event (da_mon, event); +__da_handle_event_common (da_mon, event, id);return 1 ; } -/* -* da_handle_start_run_event - start monitoring and handle event -* -* This function is used to notify the monitor that the system is in the -* initial state, so the monitor can start monitoring and handling event. -*/ -static inline bool da_handle_start_run_event (enum events event) +static inline bool __da_handle_start_run_event (struct da_monitor *da_mon, +enum events event,da_id_type id) { -struct da_monitor *da_mon; -if (!da_monitor_enabled ())return 0 ; - - da_mon =da_get_monitor (); -if (unlikely (!da_monitoring (da_mon)))da_monitor_start (da_mon); -__da_handle_event (da_mon, event); +__da_handle_event_common (da_mon, event, id);return 1 ; } -#elif RV_MON_TYPE ==RV_MON_PER_TASK +#if RV_MON_TYPE ==RV_MON_GLOBAL ||RV_MON_TYPE ==RV_MON_PER_CPU /* -* Handle event for per task. +* Handle event for implicit monitor: da_get_monitor() will figure out +* the monitor. */ -static inline void __da_handle_event (struct da_monitor *da_mon, -struct task_struct *tsk,enum events event) +/* +* da_handle_event - handle an event +*/ +static inline void da_handle_event (enum events event) { -bool retval; +__da_handle_event (da_get_monitor (), event,0 ); +} - retval =da_event (da_mon, tsk, event); -if (!retval) -da_monitor_reset (da_mon); +/* +* da_handle_start_event - start monitoring or handle event +* +* This function is used to notify the monitor that the system is returning +* to the initial state, so the monitor can start monitoring in the next event. +* Thus: +* +* If the monitor already started, handle the event. +* If the monitor did not start yet, start the monitor but skip the event. +*/ +static inline bool da_handle_start_event (enum events event) +{ +return __da_handle_start_event (da_get_monitor (), event,0 ); }/* -* da_handle_event - handle an event +* da_handle_start_run_event - start monitoring and handle event +* +* This function is used to notify the monitor that the system is in the +* initial state, so the monitor can start monitoring and handling event. */ -static inline void da_handle_event (struct task_struct *tsk,enum events event) +static inline bool da_handle_start_run_event (enum events event) { -struct da_monitor *da_mon =da_get_monitor (tsk); -bool retval; +return __da_handle_start_run_event (da_get_monitor (), event,0 ); +} - retval =da_monitor_handling_event (da_mon); -if (!retval) -return ; +#elif RV_MON_TYPE ==RV_MON_PER_TASK +/* +* Handle event for per task. +*/ -__da_handle_event (da_mon, tsk, event); +/* +* da_handle_event - handle an event +*/ +static inline void da_handle_event (struct task_struct *tsk,enum events event) +{ +__da_handle_event (da_get_monitor (tsk), event, tsk->pid); }/*
@@ -459,21 +446,7 @@ static inline void da_handle_event(struct task_struct *tsk, enum events event)static inline bool da_handle_start_event (struct task_struct *tsk,enum events event) { -struct da_monitor *da_mon; - -if (!da_monitor_enabled ()) -return 0 ; - - da_mon =da_get_monitor (tsk); - -if (unlikely (!da_monitoring (da_mon))) { -da_monitor_start (da_mon); -return 0 ; - } - -__da_handle_event (da_mon, tsk, event); - -return 1 ; +return __da_handle_start_event (da_get_monitor (tsk), event, tsk->pid); }/*
@@ -485,19 +458,7 @@ static inline bool da_handle_start_event(struct task_struct *tsk,static inline bool da_handle_start_run_event (struct task_struct *tsk,enum events event) { -struct da_monitor *da_mon; - -if (!da_monitor_enabled ()) -return 0 ; - - da_mon =da_get_monitor (tsk); - -if (unlikely (!da_monitoring (da_mon))) -da_monitor_start (da_mon); - -__da_handle_event (da_mon, tsk, event); - -return 1 ; +return __da_handle_start_run_event (da_get_monitor (tsk), event, tsk->pid); }#endif /* RV_MON_TYPE */
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 2/15 Add Hybrid Automata monitor type
In reply to Gabriele MonacoDeterministic automata define which events are allowed in every state, but cannot define more sophisticated constraint taking into account the system's environment (e.g. time or other states not producing events).
Add the Hybrid Automata monitor type as an extension of Deterministic automata where each state transition is validating a constraint on a finite number of environment variables.
Hybrid automata can be used to implement timed automata, where the environment variables are clocks.
Also implement the necessary functionality to handle clock constraints (ns or jiffy granularity) on state and events.
---
Notes:
V5:
* Remove useless variable reset when resetting Hybrid Automata V4:
* Improve ns to jiffy rounding in HA timers
V3:
* Improve functions naming for HA helpers
include/linux/rv.h | 38 +++ include/rv/da_monitor.h | 73 +++++- include/rv/ha_monitor.h | 475 +++++++++++++++++++++++++++++++++++++ kernel/trace/rv/Kconfig | 13 + kernel/trace/rv/rv_trace.h | 63 +++++ 5 files changed, 658 insertions(+), 4 deletions(-) create mode 100644 include/rv/ha_monitor.h
include/linux/rv.h +38 -0
@@ -81,11 +81,49 @@ struct ltl_monitor {};#endif /* CONFIG_RV_LTL_MONITOR */ +#ifdef CONFIG_RV_HA_MONITOR +/* +* In the future, hybrid automata may rely on multiple +* environment variables, e.g. different clocks started at +* different times or running at different speed. +* For now we support only 1 variable. +*/ +#define MAX_HA_ENV_LEN 1 + +/* +* Monitors can pick the preferred timer implementation: +* No timer: if monitors don't have state invariants. +* Timer wheel: lightweight invariants check but far less precise. +* Hrtimer: accurate invariants check with higher overhead. +*/ +#define HA_TIMER_NONE 0 +#define HA_TIMER_WHEEL 1 +#define HA_TIMER_HRTIMER 2 + +/* +* Hybrid automaton per-object variables. +*/ +struct ha_monitor { +struct da_monitor da_mon; +u64 env_store[MAX_HA_ENV_LEN ]; +union { +struct hrtimer hrtimer; +struct timer_list timer; + }; +}; + +#else + +struct ha_monitor { }; + +#endif /* CONFIG_RV_HA_MONITOR */ +#define RV_PER_TASK_MONITOR_INIT (CONFIG_RV_PER_TASK_MONITORS)union rv_task_monitor {struct da_monitor da_mon;struct ltl_monitor ltl_mon; +struct ha_monitor ha_mon; };#ifdef CONFIG_RV_REACTORS
include/rv/da_monitor.h +69 -4
134 lines not on this page · raw message
include/rv/ha_monitor.h new file +475 -0
475 lines not on this page · raw message
kernel/trace/rv/Kconfig +13 -0
@@ -23,6 +23,19 @@ config LTL_MON_EVENTS_ID config RV_LTL_MONITOR bool +config RV_HA_MONITOR + bool + +config HA_MON_EVENTS_IMPLICIT + select DA_MON_EVENTS_IMPLICIT + select RV_HA_MONITOR + bool + +config HA_MON_EVENTS_ID + select DA_MON_EVENTS_ID + select RV_HA_MONITOR + bool + menuconfig RV bool "Runtime Verification" select TRACING
kernel/trace/rv/rv_trace.h +63 -0
75 lines not on this page · raw message
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 3/15 verification/rvgen: Allow spaces in and events strings
In reply to Gabriele MonacoCurrently the automata parser assumes event strings don't have any space, this stands true for event names, but can be a wrong assumption if we want to store other information in the event strings (e.g. constraints for hybrid automata).
Adapt the parser logic to allow spaces in the event strings.
---
Notes:
V6:
* Use f-strings in newly added code and cleanup
tools/verification/rvgen/rvgen/automata.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/verification/rvgen/rvgen/automata.py +4 -5
@@ -127,14 +127,13 @@ class Automata: # ------------ event is here ------------^^^^^ if self.__dot_lines[cursor].split()[1] == "->": line = self.__dot_lines[cursor].split() - event = line[-2].replace('"','') + event = "".join(line[line.index("label")+2:-1]).replace('"', '') # when a transition has more than one lables, they are like this # "local_irq_enable\nhw_local_irq_enable_n" # so split them. - event = event.replace("\\n", " ") - for i in event.split(): + for i in event.split("\\n"): events.append(i) cursor += 1
@@ -167,8 +166,8 @@ class Automata: line = self.__dot_lines[cursor].split() origin_state = line[0].replace('"','').replace(',','_') dest_state = line[2].replace('"','').replace(',','_') - possible_events = line[-2].replace('"','').replace("\\n", " ") - for event in possible_events.split(): + possible_events = "".join(line[line.index("label")+2:-1]).replace('"', '') + for event in possible_events.split("\\n"): matrix[states_dict[origin_state]][events_dict[event]] = dest_state cursor += 1
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 4/15 verification/rvgen: Add support for Hybrid Automata
In reply to Gabriele MonacoAdd the possibility to parse dot files as hybrid automata and generate the necessary code from rvgen.
Hybrid automata are very similar to deterministic ones and most functionality is shared, the dot files include also constraints together with event names (separated by ;) and state names (separated by \n).
The tool can now generate the appropriate code to validate constraints at runtime according to the dot specification.
---
Notes:
V6:
* Use f-strings in newly added code and cleanup
* Sort constraints for predictable generated code V4:
* Sort self_loop_reset_events to avoid unpredictable order
tools/verification/rvgen/__main__.py | 8 +- tools/verification/rvgen/rvgen/automata.py | 146 +++++- tools/verification/rvgen/rvgen/dot2c.py | 47 ++ tools/verification/rvgen/rvgen/dot2k.py | 474 +++++++++++++++++- tools/verification/rvgen/rvgen/generator.py | 2 + .../rvgen/rvgen/templates/dot2k/main.c | 2 +- .../rvgen/templates/dot2k/trace_hybrid.h | 16 + 7 files changed, 679 insertions(+), 16 deletions(-) create mode 100644 tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h
tools/verification/rvgen/__main__.py +5 -3
@@ -9,7 +9,7 @@ # Documentation/trace/rv/da_monitor_synthesis.rst if __name__ == '__main__': - from rvgen.dot2k import dot2k + from rvgen.dot2k import da2k, ha2k from rvgen.generator import Monitor from rvgen.container import Container from rvgen.ltl2k import ltl2k
@@ -29,7 +29,7 @@ if __name__ == '__main__': monitor_parser.add_argument("-p", "--parent", dest="parent", required=False, help="Create a monitor nested to parent") monitor_parser.add_argument('-c', "--class", dest="monitor_class", - help="Monitor class, either \"da\" or \"ltl\"") + help="Monitor class, either \"da\", \"ha\" or \"ltl\"") monitor_parser.add_argument('-s', "--spec", dest="spec", help="Monitor specification file") monitor_parser.add_argument('-t', "--monitor_type", dest="monitor_type", help=f"Available options: {', '.join(Monitor.monitor_types.keys())}")
@@ -43,7 +43,9 @@ if __name__ == '__main__': if params.subcmd == "monitor": print("Opening and parsing the specification file %s" % params.spec) if params.monitor_class == "da": - monitor = dot2k(params.spec, params.monitor_type, vars(params)) + monitor = da2k(params.spec, params.monitor_type, vars(params)) + elif params.monitor_class == "ha": + monitor = ha2k(params.spec, params.monitor_type, vars(params)) elif params.monitor_class == "ltl": monitor = ltl2k(params.spec, params.monitor_type, vars(params)) else:
tools/verification/rvgen/rvgen/automata.py +136 -10
211 lines not on this page · raw message
tools/verification/rvgen/rvgen/dot2c.py +47 -0
81 lines not on this page · raw message
tools/verification/rvgen/rvgen/dot2k.py +472 -2
517 lines not on this page · raw message
tools/verification/rvgen/rvgen/generator.py +2 -0
@@ -255,12 +255,14 @@ class Monitor(RVGenerator): monitor_class_type = self.fill_monitor_class_type() tracepoint_args_skel_event = self.fill_tracepoint_args_skel("event") tracepoint_args_skel_error = self.fill_tracepoint_args_skel("error") + tracepoint_args_skel_error_env = self.fill_tracepoint_args_skel("error_env") trace_h = trace_h.replace("%%MODEL_NAME%%", self.name) trace_h = trace_h.replace("%%MODEL_NAME_UP%%", self.name.upper()) trace_h = trace_h.replace("%%MONITOR_CLASS%%", monitor_class) trace_h = trace_h.replace("%%MONITOR_CLASS_TYPE%%", monitor_class_type) trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_EVENT%%", tracepoint_args_skel_event) trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_ERROR%%", tracepoint_args_skel_error) + trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_ERROR_ENV%%", tracepoint_args_skel_error_env) return trace_h def print_files(self):
tools/verification/rvgen/rvgen/templates/dot2k/main.c +1 -1
@@ -21,7 +21,7 @@*/ #define RV_MON_TYPE RV_MON_%%MONITOR_TYPE%%#include "%%MODEL_NAME%%.h" -#include <rv/da_monitor.h> +#include <rv/%%MONITOR_CLASS%%_monitor.h> /* * This is the instrumentation part of the monitor.
tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Snippet to be included in rv_trace.h +*/ + +#ifdef CONFIG_RV_MON_%%MODEL_NAME_UP%% +DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%, +%%TRACEPOINT_ARGS_SKEL_EVENT%%); + +DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%, +%%TRACEPOINT_ARGS_SKEL_ERROR%%); + +DEFINE_EVENT(error_env_%%MONITOR_CLASS%%, error_env_%%MODEL_NAME%%, +%%TRACEPOINT_ARGS_SKEL_ERROR_ENV%%); +#endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 5/15 Documentation/rv: Add documentation about hybrid automata
In reply to Gabriele MonacoDescribe theory and implementation of hybrid automata in the dedicated page hybrid_automata.rst
Include a section on how to integrate a hybrid automaton in monitor_synthesis.rst
Also remove a hanging $ in deterministic_automata.rst
---
Notes:
V7:
* Use consistent events in examples
V3:
* Improve documentation clarity after review
.../trace/rv/deterministic_automata.rst | 2 +- Documentation/trace/rv/hybrid_automata.rst | 341 ++++++++++++++++++ Documentation/trace/rv/index.rst | 1 + Documentation/trace/rv/monitor_synthesis.rst | 117 +++++- 4 files changed, 458 insertions(+), 3 deletions(-) create mode 100644 Documentation/trace/rv/hybrid_automata.rst
Documentation/trace/rv/deterministic_automata.rst +1 -1
@@ -11,7 +11,7 @@ where: - *E* is the finite set of events; - x\ :subscript:`0` is the initial state; - X\ :subscript:`m` (subset of *X*) is the set of marked (or final) states. -- *f* : *X* x *E* -> *X* $ is the transition function. It defines the state +- *f* : *X* x *E* -> *X* is the transition function. It defines the state transition in the occurrence of an event from *E* in the state *X*. In the special case of deterministic automata, the occurrence of the event in *E* in a state in *X* has a deterministic next state from *X*.
Documentation/trace/rv/hybrid_automata.rst new file +341 -0
341 lines not on this page · raw message
Documentation/trace/rv/index.rst +1 -0
@@ -9,6 +9,7 @@ Runtime Verification runtime-verification.rst deterministic_automata.rst linear_temporal_logic.rst + hybrid_automata.rst monitor_synthesis.rst da_monitor_instrumentation.rst monitor_wip.rst
Documentation/trace/rv/monitor_synthesis.rst +115 -2
135 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v7 05/15] Documentation/rv: Add documentation about hybrid automata
Hello,
On 10/03/26 11:56, Gabriele Monaco wrote:
...
Quoted 22 lines
Documentation/trace/rv/hybrid_automata.rst new file +16
-0@@ -0,0 +1,341 @@ +Hybrid Automata +=============== + +Hybrid automata are an extension of deterministic automata, there are several +definitions of hybrid automata in the literature. The adaptation implemented +here is formally denoted by G and defined as a 7-tuple: + + *G* = { *X*, *E*, *V*, *f*, x\ :subscript:`0`, X\ :subscript:`m`, *i* } + +- *X* is the set of states; +- *E* is the finite set of events; +- *V* is the finite set of environment variables; +- x\ :subscript:`0` is the initial state; +- X\ :subscript:`m` (subset of *X*) is the set of marked (or final) states. +- *f* : *X* x *E* x *C(V)* -> *X* is the transition function. + It defines the state transition in the occurrence of an event from *E* in the
Documentation/trace/rv/hybrid_automata.rst line 26
Quoted 10 lines
Documentation/trace/rv/hybrid_automata.rst new file +10
-0+ state *X*. Unlike deterministic automata, the transition function also + includes guards from the set of all possible constraints (defined as *C(V)*). + Guards can be true or false with the valuation of *V* when the event occurs, + and the transition is possible only when constraints are true. Similarly to + deterministic automata, the occurrence of the event in *E* in a state in *X* + has a deterministic next state from *X*, if the guard is true. +- *i* : *X* -> *C'(V)* is the invariant assignment function, this is a + constraint assigned to each state in *X*, every state in *X* must be left + before the invariant turns to false. We can omit the representation of + invariants whose value is true regardless of the valuation of *V*.
Very minor nit, feel free to ignore, but ...
The formal 7-tuple definition includes 'i' (invariant function), but unlike other elements, 'i' isn't stored in the automaton struct - it's implemented as generated code in ha_verify_constraint(), IIUC. Worth a brief note clarifying this design choice so readers don't expect to find an invariants[] member in the struct? Here or below in the example C code section.
In any case,
Thanks,
Juri
[email protected]
maintainerRe: [PATCH v7 05/15] Documentation/rv: Add documentation about hybrid automata
Hello,
Quoted 8 lines · Juri Lelli
Very minor nit, feel free to ignore, but ...
The formal 7-tuple definition includes 'i' (invariant function), but unlike other elements, 'i' isn't stored in the automaton struct - it's implemented as generated code in
ha_verify_constraint(), IIUC. Worth a brief note clarifying this design choice so readers don't expect to find an invariants[] member in the struct? Here or below in the example C code section.
Thanks for the review! I haven't really thought of that. At this stage we are not mentioning any struct element (it's purely theoretical), so there shouldn't be any expectation from the reader.
Later I mention "The function verify_constraint checks guards, performs resets and starts timers to validate invariants according to specification".
In fact, also guards are not represented as part of 'function', I may mention after that sentence something like: "those cannot easily be represented in the automaton struct".
Not sure if saying more wouldn't make it even more confusing than it already is.
Thanks,
Gabriele
Juri Lelli
maintainerRe: [PATCH v7 05/15] Documentation/rv: Add documentation about hybrid automata
Quoted 23 lines · On 13/03/26 14:05, [email protected] wrote:
Hello,
Quoted 8 lines · Juri Lelli
Very minor nit, feel free to ignore, but ...
The formal 7-tuple definition includes 'i' (invariant function), but unlike other elements, 'i' isn't stored in the automaton struct - it's implemented as generated code in
ha_verify_constraint(), IIUC. Worth a brief note clarifying this design choice so readers don't expect to find an invariants[] member in the struct? Here or below in the example C code section.Thanks for the review! I haven't really thought of that. At this stage we are not mentioning any struct element (it's purely theoretical), so there shouldn't be any expectation from the reader.
Later I mention "The function
verify_constraintchecks guards, performs resets and starts timers to validate invariants according to specification".
In fact, also guards are not represented as part of 'function', I may mention after that sentence something like: "those cannot easily be represented in the automaton struct".
Quoted 2 lines
Not sure if saying more wouldn't make it even more confusing than it already is.
Yeah, probably. As mentioned, feel free to ignore, it was just a thought. :)
Gabriele Monaco
maintainerPATCH v7 6/15 Add sample hybrid monitors stall
In reply to Gabriele MonacoAdd a sample monitor to showcase hybrid/timed automata.
The stall monitor identifies tasks stalled for longer than a threshold and reacts when that happens.
---
Notes:
V3:
* Extend stall model to handle preemption
Documentation/tools/rv/index.rst | 1 + Documentation/tools/rv/rv-mon-stall.rst | 44 ++++++ Documentation/trace/rv/index.rst | 1 + Documentation/trace/rv/monitor_stall.rst | 43 ++++++ kernel/trace/rv/Kconfig | 1 + kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitors/stall/Kconfig | 13 ++ kernel/trace/rv/monitors/stall/stall.c | 150 +++++++++++++++++++ kernel/trace/rv/monitors/stall/stall.h | 81 ++++++++++ kernel/trace/rv/monitors/stall/stall_trace.h | 19 +++ kernel/trace/rv/rv_trace.h | 1 + tools/verification/models/stall.dot | 22 +++ 12 files changed, 377 insertions(+) create mode 100644 Documentation/tools/rv/rv-mon-stall.rst create mode 100644 Documentation/trace/rv/monitor_stall.rst create mode 100644 kernel/trace/rv/monitors/stall/Kconfig create mode 100644 kernel/trace/rv/monitors/stall/stall.c create mode 100644 kernel/trace/rv/monitors/stall/stall.h create mode 100644 kernel/trace/rv/monitors/stall/stall_trace.h create mode 100644 tools/verification/models/stall.dot
Documentation/tools/rv/index.rst +1 -0
@@ -16,3 +16,4 @@ Runtime verification (rv) tool rv-mon-wip rv-mon-wwnr rv-mon-sched + rv-mon-stall
Documentation/tools/rv/rv-mon-stall.rst new file +44 -0
44 lines not on this page · raw message
Documentation/trace/rv/index.rst +1 -0
@@ -16,3 +16,4 @@ Runtime Verification monitor_wwnr.rst monitor_sched.rst monitor_rtapp.rst + monitor_stall.rst
Documentation/trace/rv/monitor_stall.rst new file +43 -0
43 lines not on this page · raw message
kernel/trace/rv/Kconfig +1 -0
@@ -78,6 +78,7 @@ source "kernel/trace/rv/monitors/pagefault/Kconfig" source "kernel/trace/rv/monitors/sleep/Kconfig" # Add new rtapp monitors here +source "kernel/trace/rv/monitors/stall/Kconfig" # Add new monitors here config RV_REACTORS
kernel/trace/rv/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_RV_MON_STS) += monitors/sts/sts.o obj-$(CONFIG_RV_MON_NRP) += monitors/nrp/nrp.o obj-$(CONFIG_RV_MON_SSSW) += monitors/sssw/sssw.o obj-$(CONFIG_RV_MON_OPID) += monitors/opid/opid.o +obj-$(CONFIG_RV_MON_STALL) += monitors/stall/stall.o # Add new monitors here obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
kernel/trace/rv/monitors/stall/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_STALL + depends on RV + select HA_MON_EVENTS_ID + bool "stall monitor" + help + Enable the stall sample monitor that illustrates the usage of hybrid + automata monitors. It can be used to identify tasks stalled for + longer than a threshold. + + For further information, see: + Documentation/trace/rv/monitor_stall.rst
kernel/trace/rv/monitors/stall/stall.c new file +150 -0
150 lines not on this page · raw message
kernel/trace/rv/monitors/stall/stall.h new file +81 -0
81 lines not on this page · raw message
kernel/trace/rv/monitors/stall/stall_trace.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Snippet to be included in rv_trace.h +*/ + +#ifdef CONFIG_RV_MON_STALL +DEFINE_EVENT (event_da_monitor_id, event_stall, + TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state), +TP_ARGS (id, state, event, next_state, final_state)); + +DEFINE_EVENT (error_da_monitor_id, error_stall, + TP_PROTO(int id, char *state, char *event), +TP_ARGS (id, state, event)); + +DEFINE_EVENT (error_env_da_monitor_id, error_env_stall, + TP_PROTO(int id, char *state, char *event, char *env), +TP_ARGS (id, state, event, env)); +#endif /* CONFIG_RV_MON_STALL */
kernel/trace/rv/rv_trace.h +1 -0
@@ -187,6 +187,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id, __get_str(env)) ); +#include <monitors/stall/stall_trace.h> // Add new monitors based on CONFIG_HA_MON_EVENTS_ID here #endif
tools/verification/models/stall.dot new file +22 -0
@@ -0,0 +1,22 @@ +digraph state_automaton { + center = true; + size = "7,11"; + {node [shape = circle] "enqueued"}; + {node [shape = plaintext, style=invis, label=""] "__init_dequeued"}; + {node [shape = doublecircle] "dequeued"}; + {node [shape = circle] "running"}; + "__init_dequeued" -> "dequeued"; + "enqueued" [label = "enqueued\nclk < threshold_jiffies"]; + "running" [label = "running"]; + "dequeued" [label = "dequeued", color = green3]; + "running" -> "running" [ label = "sched_switch_in\nsched_wakeup" ]; + "enqueued" -> "enqueued" [ label = "sched_wakeup" ]; + "enqueued" -> "running" [ label = "sched_switch_in" ]; + "running" -> "dequeued" [ label = "sched_switch_wait" ]; + "dequeued" -> "enqueued" [ label = "sched_wakeup;reset(clk)" ]; + "running" -> "enqueued" [ label = "sched_switch_preempt;reset(clk)" ]; + { rank = min ; + "__init_dequeued"; + "dequeued"; + } +}
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 7/15 Convert the opid monitor to a hybrid automaton
In reply to Gabriele MonacoThe opid monitor validates that wakeup and need_resched events only occur with interrupts and preemption disabled by following the preemptirq tracepoints.
As reported in [1], those tracepoints might be inaccurate in some situations (e.g. NMIs).
Since the monitor doesn't validate other ordering properties, remove the dependency on preemptirq tracepoints and convert the monitor to a hybrid automaton to validate the constraint during event handling. This makes the monitor more robust by also removing the workaround for interrupts missing the preemption tracepoints, which was working on PREEMPT_RT only and allows the monitor to be built on kernels without the preemptirqs tracepoints.
[1] - https://lore.kernel.org/lkml/[email protected]
---
Notes:
V4:
Use da_handle_start_run_event not to lose the first event
Documentation/trace/rv/monitor_sched.rst | 62 +++--------- kernel/trace/rv/monitors/opid/Kconfig | 11 +- kernel/trace/rv/monitors/opid/opid.c | 111 +++++++-------------- kernel/trace/rv/monitors/opid/opid.h | 86 ++++------------ kernel/trace/rv/monitors/opid/opid_trace.h | 4 + kernel/trace/rv/rv_trace.h | 2 +- tools/verification/models/sched/opid.dot | 36 ++----- 7 files changed, 82 insertions(+), 230 deletions(-)
Documentation/trace/rv/monitor_sched.rst +14 -48
@@ -346,55 +346,21 @@ Monitor opid The operations with preemption and irq disabled (opid) monitor ensures operations like ``wakeup`` and ``need_resched`` occur with interrupts and -preemption disabled or during interrupt context, in such case preemption may -not be disabled explicitly. +preemption disabled. ``need_resched`` can be set by some RCU internals functions, in which case it -doesn't match a task wakeup and might occur with only interrupts disabled:: - - | sched_need_resched - | sched_waking - | irq_entry - | +--------------------+ - v v | - +------------------------------------------------------+ - +----------- | disabled | <+ - | +------------------------------------------------------+ | - | | ^ | - | | preempt_disable sched_need_resched | - | preempt_enable | +--------------------+ | - | v | v | | - | +------------------------------------------------------+ | - | | irq_disabled | | - | +------------------------------------------------------+ | - | | | ^ | - | irq_entry irq_entry | | | - | sched_need_resched v | irq_disable | - | sched_waking +--------------+ | | | - | +----- | | irq_enable | | - | | | in_irq | | | | - | +----> | | | | | - | +--------------+ | | irq_disable - | | | | | - | irq_enable | irq_enable | | | - | v v | | - | #======================================================# | - | H enabled H | - | #======================================================# | - | | ^ ^ preempt_enable | | - | preempt_disable preempt_enable +--------------------+ | - | v | | - | +------------------+ | | - +----------> | preempt_disabled | -+ | - +------------------+ | - | | - +-------------------------------------------------------+ - -This monitor is designed to work on ``PREEMPT_RT`` kernels, the special case of -events occurring in interrupt context is a shortcut to identify valid scenarios -where the preemption tracepoints might not be visible, during interrupts -preemption is always disabled. On non- ``PREEMPT_RT`` kernels, the interrupts -might invoke a softirq to set ``need_resched`` and wake up a task. This is -another special case that is currently not supported by the monitor. +doesn't match a task wakeup and might occur with only interrupts disabled. +The interrupt and preemption status are validated by the hybrid automaton +constraints when processing the events:: + + | + | + v + #=========# sched_need_resched;irq_off == 1 + H H sched_waking;irq_off == 1 && preempt_off == 1 + H any H ------------------------------------------------+ + H H | + H H <-----------------------------------------------+ + #=========# References ----------
kernel/trace/rv/monitors/opid/Kconfig +3 -8
@@ -2,18 +2,13 @@ # config RV_MON_OPID depends on RV - depends on TRACE_IRQFLAGS - depends on TRACE_PREEMPT_TOGGLE depends on RV_MON_SCHED - default y if PREEMPT_RT - select DA_MON_EVENTS_IMPLICIT + default y + select HA_MON_EVENTS_IMPLICIT bool "opid monitor" help Monitor to ensure operations like wakeup and need resched occur with - interrupts and preemption disabled or during IRQs, where preemption - may not be disabled explicitly. - - This monitor is unstable on !PREEMPT_RT, say N unless you are testing it. + interrupts and preemption disabled. For further information, see: Documentation/trace/rv/monitor_sched.rst
kernel/trace/rv/monitors/opid/opid.c +34 -77
156 lines not on this page · raw message
kernel/trace/rv/monitors/opid/opid.h +19 -67
117 lines not on this page · raw message
kernel/trace/rv/monitors/opid/opid_trace.h +4 -0
@@ -12,4 +12,8 @@ DEFINE_EVENT(event_da_monitor, event_opid,DEFINE_EVENT (error_da_monitor, error_opid,TP_PROTO (char *state, char *event),TP_ARGS (state, event)); + +DEFINE_EVENT (error_env_da_monitor, error_env_opid, +TP_PROTO (char *state, char *event, char *env), +TP_ARGS (state, event, env));#endif /* CONFIG_RV_MON_OPID */
kernel/trace/rv/rv_trace.h +1 -1
@@ -62,7 +62,6 @@ DECLARE_EVENT_CLASS(error_da_monitor,#include <monitors/scpd/scpd_trace.h> #include <monitors/snep/snep_trace.h> #include <monitors/sts/sts_trace.h> -#include <monitors/opid/opid_trace.h> // Add new monitors based on CONFIG_DA_MON_EVENTS_IMPLICIT here #ifdef CONFIG_HA_MON_EVENTS_IMPLICIT
@@ -91,6 +90,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor, __get_str(env)) ); +#include <monitors/opid/opid_trace.h> // Add new monitors based on CONFIG_HA_MON_EVENTS_IMPLICIT here #endif
tools/verification/models/sched/opid.dot +7 -29
@@ -1,35 +1,13 @@ digraph state_automaton { center = true; size = "7,11"; - {node [shape = plaintext, style=invis, label=""] "__init_disabled"}; - {node [shape = circle] "disabled"}; - {node [shape = doublecircle] "enabled"}; - {node [shape = circle] "enabled"}; - {node [shape = circle] "in_irq"}; - {node [shape = circle] "irq_disabled"}; - {node [shape = circle] "preempt_disabled"}; - "__init_disabled" -> "disabled"; - "disabled" [label = "disabled"]; - "disabled" -> "disabled" [ label = "sched_need_resched\nsched_waking\nirq_entry" ]; - "disabled" -> "irq_disabled" [ label = "preempt_enable" ]; - "disabled" -> "preempt_disabled" [ label = "irq_enable" ]; - "enabled" [label = "enabled", color = green3]; - "enabled" -> "enabled" [ label = "preempt_enable" ]; - "enabled" -> "irq_disabled" [ label = "irq_disable" ]; - "enabled" -> "preempt_disabled" [ label = "preempt_disable" ]; - "in_irq" [label = "in_irq"]; - "in_irq" -> "enabled" [ label = "irq_enable" ]; - "in_irq" -> "in_irq" [ label = "sched_need_resched\nsched_waking\nirq_entry" ]; - "irq_disabled" [label = "irq_disabled"]; - "irq_disabled" -> "disabled" [ label = "preempt_disable" ]; - "irq_disabled" -> "enabled" [ label = "irq_enable" ]; - "irq_disabled" -> "in_irq" [ label = "irq_entry" ]; - "irq_disabled" -> "irq_disabled" [ label = "sched_need_resched" ]; - "preempt_disabled" [label = "preempt_disabled"]; - "preempt_disabled" -> "disabled" [ label = "irq_disable" ]; - "preempt_disabled" -> "enabled" [ label = "preempt_enable" ]; + {node [shape = plaintext, style=invis, label=""] "__init_any"}; + {node [shape = doublecircle] "any"}; + "__init_any" -> "any"; + "any" [label = "any", color = green3]; + "any" -> "any" [ label = "sched_need_resched;irq_off == 1\nsched_waking;irq_off == 1 && preempt_off == 1" ]; { rank = min ; - "__init_disabled"; - "disabled"; + "__init_any"; + "any"; } }
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 8/15 sched: Add task enqueue/dequeue trace points
In reply to Gabriele MonacoFrom: Nam Cao <[email protected]>
Add trace points into enqueue_task() and dequeue_task().
---
Notes:
V7:
* Use cpu_of(rq) helper in tracepoint calls V5:
* Do not fire enqueue tracepoint for delayed enqueues
include/trace/events/sched.h | 8 ++++++++ kernel/sched/core.c | 12 +++++++++++- kernel/sched/sched.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-)
include/trace/events/sched.h +8 -0
@@ -896,6 +896,14 @@ DECLARE_TRACE(sched_set_need_resched, TP_PROTO(struct task_struct *tsk, int cpu, int tif), TP_ARGS(tsk, cpu, tif)); +DECLARE_TRACE (sched_enqueue, + TP_PROTO(struct task_struct *tsk, int cpu), +TP_ARGS (tsk, cpu)); + +DECLARE_TRACE (sched_dequeue, + TP_PROTO(struct task_struct *tsk, int cpu), +TP_ARGS (tsk, cpu)); +#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */
kernel/sched/core.c +11 -1
@@ -122,6 +122,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_compute_energy_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_entry_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_exit_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_set_need_resched_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_enqueue_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dequeue_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); DEFINE_PER_CPU(struct rnd_state, sched_rnd_state);
@@ -2094,6 +2096,9 @@ unsigned long get_wchan(struct task_struct *p)void enqueue_task (struct rq *rq,struct task_struct *p,int flags) { +if (trace_sched_enqueue_tp_enabled () && !(flags &ENQUEUE_DELAYED )) +trace_sched_enqueue_tp (p,cpu_of (rq)); +if (!(flags &ENQUEUE_NOCLOCK ))update_rq_clock (rq);
@@ -2120,6 +2125,8 @@ void enqueue_task(struct rq *rq, struct task_struct *p, int flags)*/ inline bool dequeue_task (struct rq *rq,struct task_struct *p,int flags) { +bool ret; +if (sched_core_enabled (rq))sched_core_dequeue (rq, p, flags);
@@ -2136,7 +2143,10 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)* and mark the task ->sched_delayed. */ uclamp_rq_dec (rq, p); -return p->sched_class->dequeue_task (rq, p, flags); + ret = p->sched_class->dequeue_task (rq, p, flags); +if (trace_sched_dequeue_tp_enabled () && !(flags &DEQUEUE_SLEEP )) +trace_sched_dequeue_tp (p,cpu_of (rq)); +return ret; }void activate_task (struct rq *rq,struct task_struct *p,int flags)
kernel/sched/sched.h +2 -0
@@ -2955,6 +2955,8 @@ static inline void sub_nr_running(struct rq *rq, unsigned count)static inline void __block_task (struct rq *rq,struct task_struct *p) { +trace_sched_dequeue_tp (p,cpu_of (rq)); +if (p->sched_contributes_to_load) rq->nr_uninterruptible++;
Signature · 1 line
2.53.0
[email protected]
maintainerRe: [PATCH v7 08/15] sched: Add task enqueue/dequeue trace points
Hi Peter,
Quoted 10 lines · Gabriele Monaco
From: Nam Cao <[email protected]>
Add trace points into
enqueue_task()anddequeue_task().Signed-off-by Nam Cao <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Reviewed-by K Prateek Nayak <[email protected]>Co-developed-by Gabriele Monaco <[email protected]>Signed-off-by Gabriele Monaco <[email protected]>---
Could I get an Ack for this?
Thanks,
Gabriele
Quoted 97 lines
Notes:
V7:
* Usecpu_of(rq)helper in tracepoint calls V5:
* Do not fire enqueue tracepoint for delayed enqueuesinclude/trace/events/sched.h | 8 ++++++++ kernel/sched/core.c | 12 +++++++++++- kernel/sched/sched.h | 2 ++
3 files changed, 21 insertions(+), 1 deletion(-)include/trace/events/sched.h +0
-0@@ -896,6 +896,14 @@ DECLARE_TRACE(sched_set_need_resched, TP_PROTO(struct task_struct *tsk, int cpu, int tif), TP_ARGS(tsk, cpu, tif));include/trace/events/sched.h +8
-0+DECLARE_TRACE (sched_enqueue, + TP_PROTO(struct task_struct *tsk, int cpu), +TP_ARGS (tsk, cpu)); + +DECLARE_TRACE (sched_dequeue, + TP_PROTO(struct task_struct *tsk, int cpu), +TP_ARGS (tsk, cpu)); +#endif /*
_TRACE_SCHED_H*/
/* This part must be outside protection */kernel/sched/core.c +2
-0@@ -122,6 +122,8 @@EXPORT_TRACEPOINT_SYMBOL_GPL (sched_compute_energy_tp); EXPORT_TRACEPOINT_SYMBOL_GPL(sched_entry_tp); EXPORT_TRACEPOINT_SYMBOL_GPL(sched_exit_tp); EXPORT_TRACEPOINT_SYMBOL_GPL(sched_set_need_resched_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_enqueue_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dequeue_tp);
DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);DEFINE_PER_CPU(struct rnd_state, sched_rnd_state);kernel/sched/core.c +0
-0@@ -2094,6 +2096,9 @@ unsigned long get_wchan(struct task_struct *p)
voidenqueue_task(struct rq *rq, struct task_struct *p, int flags){kernel/sched/core.c +1
-0+ if (trace_sched_enqueue_tp_enabled() && !(flags &
ENQUEUE_DELAYED))kernel/sched/core.c +2
-0+trace_sched_enqueue_tp (p,cpu_of (rq)); +if (!(flags &
ENQUEUE_NOCLOCK))
update_rq_clock(rq);kernel/sched/core.c +0
-0@@ -2120,6 +2125,8 @@ void enqueue_task(struct rq *rq, structtask_struct *p, int flags) */ inline bool
dequeue_task(struct rq *rq, struct task_struct *p, int flags)
{kernel/sched/core.c +2
-0+bool ret; +if (
sched_core_enabled(rq))sched_core_dequeue(rq, p, flags);kernel/sched/core.c +4
-1@@ -2136,7 +2143,10 @@ inline bool dequeue_task(struct rq *rq, structtask_struct *p, int flags) * and mark the task ->sched_delayed. */ uclamp_rq_dec(rq, p); -return p->sched_class->dequeue_task (rq, p, flags); + ret = p->sched_class->dequeue_task (rq, p, flags); +if (trace_sched_dequeue_tp_enabled () && !(flags &DEQUEUE_SLEEP )) +trace_sched_dequeue_tp (p,cpu_of (rq)); +return ret; }
voidactivate_task(struct rq *rq, struct task_struct *p, int flags)kernel/sched/sched.h +0
-0@@ -2955,6 +2955,8 @@ static inline void sub_nr_running(struct rq *rq, unsigned count)
static inline void__block_task(struct rq *rq, struct task_struct *p)
{kernel/sched/sched.h +2
-0+trace_sched_dequeue_tp (p,cpu_of (rq)); +if (
p->sched_contributes_to_load) rq->nr_uninterruptible++;
Gabriele Monaco
maintainerPATCH v7 9/15 Add enqueue/dequeue to snroc monitor
In reply to Gabriele MonacoThe snroc monitor is a simple monitor that validates set_state occurs only when a task is running. This implicitly validates switch in and out follow one another.
Add enqueue/dequeue to validate they also follow one another without duplicated events. Although they are not necessary to define the task context, adding the check here saves from adding another simple per-task monitor, which would require another slot in the task struct.
--- Documentation/trace/rv/monitor_sched.rst | 39 ++++++++++++------- kernel/trace/rv/monitors/snroc/snroc.c | 18 ++++++++- kernel/trace/rv/monitors/snroc/snroc.h | 46 ++++++++++++++++++++--- tools/verification/models/sched/snroc.dot | 30 ++++++++++----- 4 files changed, 101 insertions(+), 32 deletions(-)
Documentation/trace/rv/monitor_sched.rst +25 -14
@@ -66,21 +66,32 @@ Monitor snroc The set non runnable on its own context (snroc) monitor ensures changes in a task state happens only in the respective task's context. This is a per-task -monitor:: +monitor. +The monitor also includes enqueue/dequeue events to validate they alternate +each other without duplication. Although they are not necessary to define the +context, adding the check here saves from adding another simple per-task monitor:: + + | + | + v + #===============================================================# + +------ H enqueued H <--+ + | #===============================================================# | + | | ^ sched_set_state | + | sched_switch_in sched_switch_out +--------------+ | + | v | v | | + | +-----------------------+ sched_dequeue +-------------------+ | + | | | -----------------> | | | + | | own_context | | dequeued_running | | + | | | <----------------- | | | + | +-----------------------+ sched_enqueue +-------------------+ | + | ^ | | | + | +---+ | sched_switch_out | + | sched_set_state v | + | +-------------------------------------+ | + +--------------------> | dequeued | --------------+ + sched_dequeue +-------------------------------------+ sched_enqueue - | - | - v - +------------------+ - | other_context | <+ - +------------------+ | - | | - | sched_switch_in | sched_switch_out - v | - sched_set_state | - +------------------ | - | own_context | - +-----------------> -+ Monitor scpd ~~~~~~~~~~~~
kernel/trace/rv/monitors/snroc/snroc.c +16 -2
@@ -17,6 +17,16 @@#include "snroc.h" #include <rv/da_monitor.h> +static void handle_sched_dequeue (void *data,struct task_struct *tsk,int cpu) +{ +da_handle_event (tsk, sched_dequeue_snroc); +} + +static void handle_sched_enqueue (void *data,struct task_struct *tsk,int cpu) +{ +da_handle_event (tsk, sched_enqueue_snroc); +} +static void handle_sched_set_state (void *data,struct task_struct *tsk,int state) {da_handle_event (tsk, sched_set_state_snroc);
@@ -27,8 +37,8 @@ static void handle_sched_switch(void *data, bool preempt,struct task_struct *next, unsigned int prev_state) { -da_handle_start_event (prev ,sched_switch_out_snroc ); -da_handle_event (next, sched_switch_in_snroc); +da_handle_event (prev ,sched_switch_out_snroc ); +da_handle_start_run_event (next, sched_switch_in_snroc); }static int enable_snroc (void )
@@ -39,6 +49,8 @@ static int enable_snroc(void)if (retval)return retval; +rv_attach_trace_probe ("snroc" , sched_dequeue_tp, handle_sched_dequeue); +rv_attach_trace_probe ("snroc" , sched_enqueue_tp, handle_sched_enqueue);rv_attach_trace_probe ("snroc" , sched_set_state_tp, handle_sched_set_state);rv_attach_trace_probe ("snroc" , sched_switch, handle_sched_switch);
@@ -49,6 +61,8 @@ static void disable_snroc(void) { rv_this.enabled =0 ; +rv_detach_trace_probe ("snroc" , sched_dequeue_tp, handle_sched_dequeue); +rv_detach_trace_probe ("snroc" , sched_enqueue_tp, handle_sched_enqueue);rv_detach_trace_probe ("snroc" , sched_set_state_tp, handle_sched_set_state);rv_detach_trace_probe ("snroc" , sched_switch, handle_sched_switch);
kernel/trace/rv/monitors/snroc/snroc.h +40 -6
71 lines not on this page · raw message
tools/verification/models/sched/snroc.dot +20 -10
@@ -1,18 +1,28 @@ digraph state_automaton { center = true; size = "7,11"; - {node [shape = plaintext, style=invis, label=""] "__init_other_context"}; - {node [shape = ellipse] "other_context"}; - {node [shape = plaintext] "other_context"}; - {node [shape = plaintext] "own_context"}; - "__init_other_context" -> "other_context"; - "other_context" [label = "other_context", color = green3]; - "other_context" -> "own_context" [ label = "sched_switch_in" ]; + {node [shape = circle] "dequeued"}; + {node [shape = circle] "dequeued_running"}; + {node [shape = plaintext, style=invis, label=""] "__init_enqueued"}; + {node [shape = doublecircle] "enqueued"}; + {node [shape = circle] "enqueued"}; + {node [shape = circle] "own_context"}; + "__init_enqueued" -> "enqueued"; + "dequeued" [label = "dequeued"]; + "dequeued" -> "enqueued" [ label = "sched_enqueue" ]; + "dequeued_running" [label = "dequeued_running"]; + "dequeued_running" -> "dequeued" [ label = "sched_switch_out" ]; + "dequeued_running" -> "dequeued_running" [ label = "sched_set_state" ]; + "dequeued_running" -> "own_context" [ label = "sched_enqueue" ]; + "enqueued" [label = "enqueued", color = green3]; + "enqueued" -> "dequeued" [ label = "sched_dequeue" ]; + "enqueued" -> "own_context" [ label = "sched_switch_in" ]; "own_context" [label = "own_context"]; - "own_context" -> "other_context" [ label = "sched_switch_out" ]; + "own_context" -> "dequeued_running" [ label = "sched_dequeue" ]; + "own_context" -> "enqueued" [ label = "sched_switch_out" ]; "own_context" -> "own_context" [ label = "sched_set_state" ]; { rank = min ; - "__init_other_context"; - "other_context"; + "__init_enqueued"; + "enqueued"; } }
Signature · 1 line
2.53.0
Re: [PATCH v7 09/15] rv: Add enqueue/dequeue to snroc monitor
Quoted 10 lines · Gabriele Monaco
The snroc monitor is a simple monitor that validates
set_stateoccurs only when a task is running. This implicitly validates switch in and out follow one another.Add enqueue/dequeue to validate they also follow one another without duplicated events. Although they are not necessary to define the task context, adding the check here saves from adding another simple per-task monitor, which would require another slot in the task struct.
Signed-off-by Gabriele Monaco <[email protected]>
Gabriele Monaco
maintainerPATCH v7 10/15 Add support for per-object monitors in DA/HA
In reply to Gabriele MonacoRV deterministic and hybrid automata currently only support global, per-cpu and per-task monitors. It isn't possible to write a model that would follow some different type of object, like a deadline entity or a lock.
Define the generic per-object monitor implementation which shares part of the implementation with the per-task monitors.
The user needs to provide an id for the object (e.g. pid for tasks) and define the data type for the monitor_target (e.g. struct task_struct * for tasks). Both are supplied to the event handlers, as the id may not be easily available in the target.
The monitor storage (e.g. the rv monitor, pointer to the target, etc.) is stored in a hash table indexed by id. Monitor storage objects are automatically allocated unless specified otherwise (e.g. if the creation context is unsafe for allocation).
---
Notes:
V3:
* Use kmalloc_nolock for per-obj storage allocation
* Improve function name consistency
include/linux/rv.h | 1 + include/rv/da_monitor.h | 300 +++++++++++++++++++++++++++++++++++++++- include/rv/ha_monitor.h | 5 +- 3 files changed, 300 insertions(+), 6 deletions(-)
include/linux/rv.h +1 -0
@@ -13,6 +13,7 @@#define RV_MON_GLOBAL 0#define RV_MON_PER_CPU 1#define RV_MON_PER_TASK 2 +#define RV_MON_PER_OBJ 3#ifdef CONFIG_RV #include <linux/array_size.h>
include/rv/da_monitor.h +295 -5
344 lines not on this page · raw message
include/rv/ha_monitor.h +4 -1
@@ -190,7 +190,10 @@ static inline void ha_trace_error_env(struct ha_monitor *ha_mon, {CONCATENATE (trace_error_env_,MONITOR_NAME )(curr_state, event, env); } -#elif RV_MON_TYPE ==RV_MON_PER_TASK +#elif RV_MON_TYPE ==RV_MON_PER_TASK ||RV_MON_TYPE ==RV_MON_PER_OBJ + +#define ha_get_target (ha_mon) da_get_target(&ha_mon->da_mon) +static inline void ha_trace_error_env (struct ha_monitor *ha_mon,char *curr_state,char *event,char *env,da_id_type id)
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 11/15 verification/rvgen: Add support for per-obj monitors
In reply to Gabriele MonacoThe special per-object monitor type was just introduced in RV, this requires the user to define some functions and type specific to the object.
Adapt rvgen to add stub definitions for the monitor_target type and other modifications required to create per-object monitors.
---
Notes:
V6:
* Use f-strings in newly added code and cleanup
V3:
* Add _is_id_monitor() in dot2k to handle per-obj together with per-task
tools/verification/rvgen/rvgen/dot2k.py | 17 +++++++++++++---- tools/verification/rvgen/rvgen/generator.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
tools/verification/rvgen/rvgen/dot2k.py +13 -4
@@ -27,6 +27,8 @@ class dot2k(Monitor, Dot2c): def fill_monitor_type(self) -> str: buff = [ self.monitor_type.upper() ] buff += self._fill_timer_type() + if self.monitor_type == "per_obj": + buff.append("typedef /* XXX: define the target type */ *monitor_target;") return "\n".join(buff) def fill_tracepoint_handlers_skel(self) -> str:
@@ -45,6 +47,10 @@ class dot2k(Monitor, Dot2c): if self.monitor_type == "per_task": buff.append("\tstruct task_struct *p = /* XXX: how do I get p? */;"); buff.append("\tda_%s(p, %s%s);" % (handle, event, self.enum_suffix)); + elif self.monitor_type == "per_obj": + buff.append("\tint id = /* XXX: how do I get the id? */;") + buff.append("\tmonitor_target t = /* XXX: how do I get t? */;") + buff.append(f"\tda_{handle}(id, t, {event}{self.enum_suffix});") else: buff.append("\tda_%s(%s%s);" % (handle, event, self.enum_suffix)); buff.append("}")
@@ -92,13 +98,16 @@ class dot2k(Monitor, Dot2c): return '\n'.join(buff) + def _is_id_monitor(self) -> bool: + return self.monitor_type in ("per_task", "per_obj") + def fill_monitor_class_type(self) -> str: - if self.monitor_type == "per_task": + if self._is_id_monitor(): return "DA_MON_EVENTS_ID" return "DA_MON_EVENTS_IMPLICIT" def fill_monitor_class(self) -> str: - if self.monitor_type == "per_task": + if self._is_id_monitor(): return "da_monitor_id" return "da_monitor"
@@ -122,7 +131,7 @@ class dot2k(Monitor, Dot2c): } tp_args_id = ("int ", "id") tp_args = tp_args_dict[tp_type] - if self.monitor_type == "per_task": + if self._is_id_monitor(): tp_args.insert(0, tp_args_id) tp_proto_c = ", ".join([a+b for a,b in tp_args]) tp_args_c = ", ".join([b for a,b in tp_args])
@@ -169,7 +178,7 @@ class ha2k(dot2k): self.__parse_constraints() def fill_monitor_class_type(self) -> str: - if self.monitor_type == "per_task": + if self._is_id_monitor(): return "HA_MON_EVENTS_ID" return "HA_MON_EVENTS_IMPLICIT"
tools/verification/rvgen/rvgen/generator.py +1 -1
@@ -243,7 +243,7 @@ obj-$(CONFIG_RV_MON_%s) += monitors/%s/%s.o class Monitor(RVGenerator): - monitor_types = { "global" : 1, "per_cpu" : 2, "per_task" : 3 } + monitor_types = { "global" : 1, "per_cpu" : 2, "per_task" : 3, "per_obj" : 4 } def __init__(self, extra_params={}): super().__init__(extra_params)
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 12/15 sched: Add deadline tracepoints
In reply to Gabriele MonacoAdd the following tracepoints:
* sched_dl_throttle(dl_se, cpu, type):
Called when a deadline entity is throttled
* sched_dl_replenish(dl_se, cpu, type):
Called when a deadline entity's runtime is replenished
* sched_dl_update(dl_se, cpu, type):
Called when a deadline entity updates without throttle or replenish
* sched_dl_server_start(dl_se, cpu, type):
Called when a deadline server is started
* sched_dl_server_stop(dl_se, cpu, type):
Called when a deadline server is stopped
Those tracepoints can be useful to validate the deadline scheduler with RV and are not exported to tracefs.
---
Notes:
V7:
* Export sched_dl_update to modules and fix style V6:
* Add dl_se type to differentiate between fair and ext servers
* Add event to track dl_update_curr not firing other events V3:
* Rename dl argument to dl_se in tracepoints
include/trace/events/sched.h | 26 ++++++++++++++++++++++++++ kernel/sched/core.c | 5 +++++ kernel/sched/deadline.c | 24 ++++++++++++++++++++++++ 3 files changed, 55 insertions(+)
include/trace/events/sched.h +26 -0
@@ -904,6 +904,32 @@ DECLARE_TRACE(sched_dequeue, TP_PROTO(struct task_struct *tsk, int cpu), TP_ARGS(tsk, cpu)); +#define DL_OTHER 0 +#define DL_TASK 1 +#define DL_SERVER_FAIR 2 +#define DL_SERVER_EXT 3 + +DECLARE_TRACE (sched_dl_throttle, + TP_PROTO(struct sched_dl_entity *dl_se, int cpu, uint8_t type), +TP_ARGS (dl_se, cpu, type)); + +DECLARE_TRACE (sched_dl_replenish, + TP_PROTO(struct sched_dl_entity *dl_se, int cpu, uint8_t type), +TP_ARGS (dl_se, cpu, type)); + +/* Call to update_curr_dl_se not involving throttle or replenish */ +DECLARE_TRACE (sched_dl_update, + TP_PROTO(struct sched_dl_entity *dl_se, int cpu, uint8_t type), +TP_ARGS (dl_se, cpu, type)); + +DECLARE_TRACE (sched_dl_server_start, + TP_PROTO(struct sched_dl_entity *dl_se, int cpu, uint8_t type), +TP_ARGS (dl_se, cpu, type)); + +DECLARE_TRACE (sched_dl_server_stop, + TP_PROTO(struct sched_dl_entity *dl_se, int cpu, uint8_t type), +TP_ARGS (dl_se, cpu, type)); +#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */
kernel/sched/core.c +5 -0
@@ -124,6 +124,11 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_exit_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_set_need_resched_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_enqueue_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dequeue_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dl_throttle_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dl_replenish_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dl_update_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dl_server_start_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dl_server_stop_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); DEFINE_PER_CPU(struct rnd_state, sched_rnd_state);
kernel/sched/deadline.c +24 -0
@@ -115,6 +115,20 @@ static inline bool is_dl_boosted(struct sched_dl_entity *dl_se) }#endif /* !CONFIG_RT_MUTEXES */ +static inline uint8_t dl_get_type (struct sched_dl_entity *dl_se, +struct rq *rq) +{ +if (!dl_server (dl_se)) +return DL_TASK ; +if (dl_se == &rq->fair_server) +return DL_SERVER_FAIR ; +#ifdef CONFIG_SCHED_CLASS_EXT +if (dl_se == &rq->ext_server) +return DL_SERVER_EXT ; +#endif +return DL_OTHER ; +} +static inline struct dl_bw *dl_bw_of (int i) { RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held(),
@@ -733,6 +747,7 @@ static inline void replenish_dl_new_period(struct sched_dl_entity *dl_se, dl_se->dl_throttled =1 ; dl_se->dl_defer_armed =1 ; } +trace_sched_dl_replenish_tp (dl_se,cpu_of (rq),dl_get_type (dl_se, rq)); }/*
@@ -848,6 +863,8 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)if (dl_se->dl_throttled) dl_se->dl_throttled =0 ; +trace_sched_dl_replenish_tp (dl_se,cpu_of (rq),dl_get_type (dl_se, rq)); +/* * If this is the replenishment of a deferred reservation, * clear the flag and return.
@@ -1345,6 +1362,7 @@ static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se) dl_time_before(rq_clock(rq), dl_next_period(dl_se))) {if (unlikely (is_dl_boosted (dl_se) || !start_dl_timer (dl_se)))return ; +trace_sched_dl_throttle_tp (dl_se,cpu_of (rq),dl_get_type (dl_se, rq)); dl_se->dl_throttled =1 ;if (dl_se->runtime >0 ) dl_se->runtime =0 ;
@@ -1508,6 +1526,7 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64 throttle:if (dl_runtime_exceeded (dl_se) || dl_se->dl_yielded) { +trace_sched_dl_throttle_tp (dl_se,cpu_of (rq),dl_get_type (dl_se, rq)); dl_se->dl_throttled =1 ;/* If requested, inform the user about runtime overruns. */
@@ -1532,6 +1551,8 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64if (!is_leftmost (dl_se, &rq->dl))resched_curr (rq); + }else { +trace_sched_dl_update_tp (dl_se,cpu_of (rq),dl_get_type (dl_se, rq)); }/*
@@ -1810,6 +1831,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)if (WARN_ON_ONCE (!cpu_online (cpu_of (rq))))return ; +trace_sched_dl_server_start_tp (dl_se,cpu_of (rq),dl_get_type (dl_se, rq)); dl_se->dl_server_active =1 ;enqueue_dl_entity (dl_se,ENQUEUE_WAKEUP );if (!dl_task (dl_se->rq->curr) ||dl_entity_preempt (dl_se, &rq->curr->dl))
@@ -1821,6 +1843,8 @@ void dl_server_stop(struct sched_dl_entity *dl_se)if (!dl_server (dl_se) || !dl_server_active (dl_se))return ; +trace_sched_dl_server_stop_tp (dl_se,cpu_of (dl_se->rq), +dl_get_type (dl_se, dl_se->rq));dequeue_dl_entity (dl_se,DEQUEUE_SLEEP );hrtimer_try_to_cancel (&dl_se->dl_timer); dl_se->dl_defer_armed =0 ;
Signature · 1 line
2.53.0
Re: [PATCH v7 12/15] sched: Add deadline tracepoints
Hello,
Quoted 13 lines · Gabriele Monaco
Add the following tracepoints:
*
sched_dl_throttle(dl_se, cpu, type):
Called when a deadline entity is throttled
*sched_dl_replenish(dl_se, cpu, type):
Called when a deadline entity's runtime is replenished
*sched_dl_update(dl_se, cpu, type):
Called when a deadline entity updates without throttle or replenish
*sched_dl_server_start(dl_se, cpu, type):
Called when a deadline server is started
*sched_dl_server_stop(dl_se, cpu, type):
Called when a deadline server is stopped
Quoted 5 lines
Those tracepoints can be useful to validate the deadline scheduler with RV and are not exported to tracefs.
Reviewed-by Phil Auld <[email protected]>Signed-off-by Gabriele Monaco <[email protected]>
Looks good to me.
Best,
Juri
Gabriele Monaco
maintainerPATCH v7 13/15 sched/deadline: Move some utility functions to deadline.h
In reply to Gabriele MonacoSome utility functions on sched_dl_entity can be useful outside of deadline.c , for instance for modelling, without relying on raw structure fields.
Move functions like dl_task_of and dl_is_implicit to deadline.h to make them available outside.
---
Notes:
V5:
* Do not export pi_of to deadline.h
* Explicitly inline dl_server()
include/linux/sched/deadline.h | 27 +++++++++++++++++++++++++++ kernel/sched/deadline.c | 28 +--------------------------- 2 files changed, 28 insertions(+), 27 deletions(-)
include/linux/sched/deadline.h +27 -0
@@ -37,4 +37,31 @@ extern void dl_clear_root_domain_cpu(int cpu);extern u64 dl_cookie;extern bool dl_bw_visited (int cpu,u64 cookie); +static inline bool dl_server (struct sched_dl_entity *dl_se) +{ +return dl_se->dl_server; +} + +static inline struct task_struct *dl_task_of (struct sched_dl_entity *dl_se) +{ +BUG_ON (dl_server (dl_se)); + return container_of(dl_se, struct task_struct, dl); +} + +/* +* Regarding the deadline, a task with implicit deadline has a relative +* deadline == relative period. A task with constrained deadline has a +* relative deadline <= relative period. +* +* We support constrained deadline tasks. However, there are some restrictions +* applied only for tasks which do not have an implicit deadline. See +* update_dl_entity() to know more about such restrictions. +* +* The dl_is_implicit() returns true if the task has an implicit deadline. +*/ +static inline bool dl_is_implicit (struct sched_dl_entity *dl_se) +{ +return dl_se->dl_deadline == dl_se->dl_period; +} +#endif /* _LINUX_SCHED_DEADLINE_H */
kernel/sched/deadline.c +1 -27
@@ -18,6 +18,7 @@#include <linux/cpuset.h> #include <linux/sched/clock.h> +#include <linux/sched/deadline.h> #include <uapi/linux/sched/types.h> #include "sched.h" #include "pelt.h"
@@ -57,17 +58,6 @@ static int __init sched_dl_sysctl_init(void)late_initcall (sched_dl_sysctl_init);#endif /* CONFIG_SYSCTL */ -static bool dl_server (struct sched_dl_entity *dl_se) -{ -return dl_se->dl_server; -} - -static inline struct task_struct *dl_task_of (struct sched_dl_entity *dl_se) -{ -BUG_ON (dl_server (dl_se)); - return container_of(dl_se, struct task_struct, dl); -} -static inline struct rq *rq_of_dl_rq (struct dl_rq *dl_rq) { return container_of(dl_rq, struct rq, dl);
@@ -991,22 +981,6 @@ update_dl_revised_wakeup(struct sched_dl_entity *dl_se, struct rq *rq) dl_se->runtime = (dl_se->dl_density * laxity) >>BW_SHIFT ; } -/* -* Regarding the deadline, a task with implicit deadline has a relative -* deadline == relative period. A task with constrained deadline has a -* relative deadline <= relative period. -* -* We support constrained deadline tasks. However, there are some restrictions -* applied only for tasks which do not have an implicit deadline. See -* update_dl_entity() to know more about such restrictions. -* -* The dl_is_implicit() returns true if the task has an implicit deadline. -*/ -static inline bool dl_is_implicit (struct sched_dl_entity *dl_se) -{ -return dl_se->dl_deadline == dl_se->dl_period; -} -/* * When a deadline entity is placed in the runqueue, its runtime and deadline * might need to be updated. This is done by a CBS wake up rule. There are two
Signature · 1 line
2.53.0
Gabriele Monaco
maintainerPATCH v7 14/15 Add deadline monitors
In reply to Gabriele MonacoAdd the deadline monitors collection to validate the deadline scheduler, both for deadline tasks and servers.
The currently implemented monitors are:
* throttle:
validate dl entities are throttled when they use up their runtime
* nomiss:
validate dl entities run to completion before their deadiline
---
Notes:
V7:
* Determine ext tasks using a sched_class pointer via kallsyms
* Search for task and lock RCU in extract_params() callers
* Explicit sched_attr * cast in extract_params()
* Use offsetofend when copying sched_attr for better clarity V6:
* Add support for ext server in monitors
* Handle events only for supported deadline entities (future proof)
* Remove mostly unused dl_server_start from nomiss monitor
* Allow to skip runtime constraint on throttle monitor
* Consider also BATCH and IDLE as fair policies
* Cleanup and sort constraints as generated
V5:
* Do not use boosted dl_se in monitors
V4:
* Rename handle_syscall as it collides with some UM function
* Simplify idle handling on nomiss and throttle from sleeping
* Improve switch_out for servers in throttle
V3:
* Adapt models to new dl server behaviour
* Rename dl argument to dl_se in tracepoints
* Use __COUNTER__ in dl monitor syscall helpers
Documentation/trace/rv/index.rst | 1 + Documentation/trace/rv/monitor_deadline.rst | 158 ++++++++++ kernel/trace/rv/Kconfig | 5 + kernel/trace/rv/Makefile | 3 + kernel/trace/rv/monitors/deadline/Kconfig | 10 + kernel/trace/rv/monitors/deadline/deadline.c | 41 +++ kernel/trace/rv/monitors/deadline/deadline.h | 202 ++++++++++++ kernel/trace/rv/monitors/nomiss/Kconfig | 15 + kernel/trace/rv/monitors/nomiss/nomiss.c | 293 ++++++++++++++++++ kernel/trace/rv/monitors/nomiss/nomiss.h | 123 ++++++++ .../trace/rv/monitors/nomiss/nomiss_trace.h | 19 ++ kernel/trace/rv/monitors/throttle/Kconfig | 15 + kernel/trace/rv/monitors/throttle/throttle.c | 285 +++++++++++++++++ kernel/trace/rv/monitors/throttle/throttle.h | 116 +++++++ .../rv/monitors/throttle/throttle_trace.h | 19 ++ kernel/trace/rv/rv_trace.h | 2 + tools/verification/models/deadline/nomiss.dot | 41 +++ .../verification/models/deadline/throttle.dot | 44 +++ 18 files changed, 1392 insertions(+) create mode 100644 Documentation/trace/rv/monitor_deadline.rst create mode 100644 kernel/trace/rv/monitors/deadline/Kconfig create mode 100644 kernel/trace/rv/monitors/deadline/deadline.c create mode 100644 kernel/trace/rv/monitors/deadline/deadline.h create mode 100644 kernel/trace/rv/monitors/nomiss/Kconfig create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss.c create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss.h create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss_trace.h create mode 100644 kernel/trace/rv/monitors/throttle/Kconfig create mode 100644 kernel/trace/rv/monitors/throttle/throttle.c create mode 100644 kernel/trace/rv/monitors/throttle/throttle.h create mode 100644 kernel/trace/rv/monitors/throttle/throttle_trace.h create mode 100644 tools/verification/models/deadline/nomiss.dot create mode 100644 tools/verification/models/deadline/throttle.dot
Documentation/trace/rv/index.rst +1 -0
@@ -17,3 +17,4 @@ Runtime Verification monitor_sched.rst monitor_rtapp.rst monitor_stall.rst + monitor_deadline.rst
Documentation/trace/rv/monitor_deadline.rst new file +158 -0
158 lines not on this page · raw message
kernel/trace/rv/Kconfig +5 -0
@@ -79,6 +79,11 @@ source "kernel/trace/rv/monitors/sleep/Kconfig" # Add new rtapp monitors here source "kernel/trace/rv/monitors/stall/Kconfig" +source "kernel/trace/rv/monitors/deadline/Kconfig" +source "kernel/trace/rv/monitors/nomiss/Kconfig" +source "kernel/trace/rv/monitors/throttle/Kconfig" +# Add new deadline monitors here + # Add new monitors here config RV_REACTORS
kernel/trace/rv/Makefile +3 -0
@@ -18,6 +18,9 @@ obj-$(CONFIG_RV_MON_NRP) += monitors/nrp/nrp.o obj-$(CONFIG_RV_MON_SSSW) += monitors/sssw/sssw.o obj-$(CONFIG_RV_MON_OPID) += monitors/opid/opid.o obj-$(CONFIG_RV_MON_STALL) += monitors/stall/stall.o +obj-$(CONFIG_RV_MON_DEADLINE) += monitors/deadline/deadline.o +obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o +obj-$(CONFIG_RV_MON_THROTTLE) += monitors/throttle/throttle.o # Add new monitors here obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
kernel/trace/rv/monitors/deadline/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config RV_MON_DEADLINE + depends on RV + bool "deadline monitor" + help + Collection of monitors to check the deadline scheduler and server + behave according to specifications. Enable this to enable all + scheduler specification supported by the current kernel. + + For further information, see: + Documentation/trace/rv/monitor_deadline.rst
kernel/trace/rv/monitors/deadline/deadline.c new file +41 -0
41 lines not on this page · raw message
kernel/trace/rv/monitors/deadline/deadline.h new file +202 -0
202 lines not on this page · raw message
kernel/trace/rv/monitors/nomiss/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_NOMISS + depends on RV + depends on HAVE_SYSCALL_TRACEPOINTS + depends on RV_MON_DEADLINE + default y + select HA_MON_EVENTS_ID + bool "nomiss monitor" + help + Monitor to ensure dl entities run to completion before their deadiline. + This monitor is part of the deadline monitors collection. + + For further information, see: + Documentation/trace/rv/monitor_deadline.rst
kernel/trace/rv/monitors/nomiss/nomiss.c new file +293 -0
293 lines not on this page · raw message
kernel/trace/rv/monitors/nomiss/nomiss.h new file +123 -0
123 lines not on this page · raw message
kernel/trace/rv/monitors/nomiss/nomiss_trace.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Snippet to be included in rv_trace.h +*/ + +#ifdef CONFIG_RV_MON_NOMISS +DEFINE_EVENT (event_da_monitor_id, event_nomiss, + TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state), +TP_ARGS (id, state, event, next_state, final_state)); + +DEFINE_EVENT (error_da_monitor_id, error_nomiss, + TP_PROTO(int id, char *state, char *event), +TP_ARGS (id, state, event)); + +DEFINE_EVENT (error_env_da_monitor_id, error_env_nomiss, + TP_PROTO(int id, char *state, char *event, char *env), +TP_ARGS (id, state, event, env)); +#endif /* CONFIG_RV_MON_NOMISS */
kernel/trace/rv/monitors/throttle/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_THROTTLE + depends on RV + depends on HAVE_SYSCALL_TRACEPOINTS + depends on RV_MON_DEADLINE + default y + select HA_MON_EVENTS_ID + bool "throttle monitor" + help + Monitor to ensure dl entities are throttled when they use up their runtime. + This monitor is part of the deadline monitors collection. + + For further information, see: + Documentation/trace/rv/monitor_deadline.rst
kernel/trace/rv/monitors/throttle/throttle.c new file +285 -0
285 lines not on this page · raw message
kernel/trace/rv/monitors/throttle/throttle.h new file +116 -0
116 lines not on this page · raw message
kernel/trace/rv/monitors/throttle/throttle_trace.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Snippet to be included in rv_trace.h +*/ + +#ifdef CONFIG_RV_MON_THROTTLE +DEFINE_EVENT (event_da_monitor_id, event_throttle, + TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state), +TP_ARGS (id, state, event, next_state, final_state)); + +DEFINE_EVENT (error_da_monitor_id, error_throttle, + TP_PROTO(int id, char *state, char *event), +TP_ARGS (id, state, event)); + +DEFINE_EVENT (error_env_da_monitor_id, error_env_throttle, + TP_PROTO(int id, char *state, char *event, char *env), +TP_ARGS (id, state, event, env)); +#endif /* CONFIG_RV_MON_THROTTLE */
kernel/trace/rv/rv_trace.h +2 -0
@@ -188,6 +188,8 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id, );#include <monitors/stall/stall_trace.h> +#include <monitors/nomiss/nomiss_trace.h> +#include <monitors/throttle/throttle_trace.h> // Add new monitors based on CONFIG_HA_MON_EVENTS_ID here #endif
tools/verification/models/deadline/nomiss.dot new file +41 -0
41 lines not on this page · raw message
tools/verification/models/deadline/throttle.dot new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.53.0
Juri Lelli
maintainerRe: [PATCH v7 14/15] rv: Add deadline monitors
Hello,
On 10/03/26 11:56, Gabriele Monaco wrote:
...
kernel/trace/rv/monitors/deadline/deadline.c line 27
Quoted 7 lines
kernel/trace/rv/monitors/deadline/deadline.c new file +7
-0+/* Used by other monitors */ +struct sched_class *rv_ext_sched_class; + +static int __init register_deadline (void ) +{ +if (IS_ENABLED (CONFIG_SCHED_CLASS_EXT )) + rv_ext_sched_class = (void *)kallsyms_lookup_name ("ext_sched_class" );
Looks like the above look up can fail. I don't actually see how/why if would fail if things build correctly and EXT tasks are around. But, theoretically, we could end up with rv_ext_sched_class = NULL ?
...
Quoted 7 lines
kernel/trace/rv/monitors/deadline/deadline.h new file +7
-0+static inline bool task_is_scx_enabled (struct task_struct *tsk) +{ +return IS_ENABLED (CONFIG_SCHED_CLASS_EXT ) && + tsk->sched_class == rv_ext_sched_class; +} + +/* Expand id and target as arguments for da functions */
kernel/trace/rv/monitors/deadline/deadline.h line 93
Quoted 10 lines
kernel/trace/rv/monitors/deadline/deadline.h new file +10
-0+#define EXPAND_ID (dl_se, cpu, type) get_entity_id(dl_se, cpu, type), dl_se +#define EXPAND_ID_TASK (tsk) get_entity_id(&tsk->dl, task_cpu(tsk), DL_TASK), &tsk->dl + +static inline uint8_t get_server_type (struct task_struct *tsk) +{ +if (tsk->policy ==SCHED_NORMAL || tsk->policy ==SCHED_EXT || + tsk->policy ==SCHED_BATCH || tsk->policy ==SCHED_IDLE ) +return task_is_scx_enabled (tsk) ?DL_SERVER_EXT :DL_SERVER_FAIR ; +return DL_OTHER ; +}
Considering that, if that happens, get_server_type() will return DL_SERVER_FAIR for scx tasks as well (possibly confusing monitors?), shall we add a warn or something just in case. A 'no we don't need that because it can't happen' works for me, just thought I should still mention this. :)
Thanks,
Juri
[email protected]
maintainerRe: [PATCH v7 14/15] rv: Add deadline monitors
Hello,
Quoted 34 lines · Juri Lelli
Quoted 8 lines
kernel/trace/rv/monitors/deadline/deadline.c new file +7
-0+/* Used by other monitors */ +struct sched_class *rv_ext_sched_class; + +static int __init register_deadline (void ) +{ +if (IS_ENABLED (CONFIG_SCHED_CLASS_EXT )) + rv_ext_sched_class = (void*)kallsyms_lookup_name("ext_sched_class");
Looks like the above look up can fail. I don't actually see how/why if would fail if things build correctly and EXT tasks are around. But, theoretically, we could end up with
rv_ext_sched_class= NULL ?Quoted 21 lines
kernel/trace/rv/monitors/deadline/deadline.h new file +8
-0+static inline bool task_is_scx_enabled (struct task_struct *tsk) +{ +return IS_ENABLED (CONFIG_SCHED_CLASS_EXT ) && + tsk->sched_class == rv_ext_sched_class; +} + +/* Expand id and target as arguments for da functions */ +#define EXPAND_ID (dl_se, cpu, type) get_entity_id(dl_se, cpu,type),
dl_se
+#defineEXPAND_ID_TASK(tsk)get_entity_id(&tsk->dl, task_cpu(tsk), DL_TASK),&tsk->dlkernel/trace/rv/monitors/deadline/deadline.h new file +4
-0+ +static inline uint8_t get_server_type(struct task_struct *tsk) +{ + if (tsk->policy == SCHED_NORMAL || tsk->policy ==
SCHED_EXT||(quoted diff) +1
-0+ tsk->policy == SCHED_BATCH || tsk->policy ==
SCHED_IDLE)(quoted diff) +1
-0+ return task_is_scx_enabled(tsk) ? DL_SERVER_EXT :
DL_SERVER_FAIR;kernel/trace/rv/monitors/deadline/deadline.h new file +1
-0+return DL_OTHER ;
Quoted 8 lines
Quoted 1 line
+}
Considering that, if that happens,
get_server_type()will returnDL_SERVER_FAIRfor scx tasks as well (possibly confusing monitors?), shall we add a warn or something just in case. A 'no we don't need that
because it can't happen' works for me, just thought I should still mention this. :)
I forgot answering..
Well, technically yes, this all can fail.
I figured a silent degradation in this remote case would be alright, but probably just print it during initialisation wouldn't hurt.
We cannot do much if it really happened and, yes, monitors would likely fail if both SCX and fair servers coexist.
I'd assume it /should/ never happen, but it costs nothing adding:
pr_warn("Error detecting the ext class, monitors may report wrong
results.\n");
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v7 15/15 Add dl_server specific monitors
In reply to Gabriele MonacoAdd monitors to validate the behaviour of the deadline server.
The currently implemented monitors are:
* boost
fair tasks run either independently or boosted
* laxity
deferrable servers wait for zero-laxity and run
---
Notes:
V6:
* Add support for ext server in monitors
* Add missing transition running -> zero_laxity_wait
* Handle dl_update event in laxity to cover missing update without enqueue nor replenish when multiple server types are active
* Handle events only for supported deadline servers (future proof)
* Cleanup and sort constraints as generated
V4
* Rely on enqueue/dequeue tracepoints instead of syscalls
* Improve timing conditions in laxity and handle resume action
* Remove fragile Stopping state from boost
Documentation/trace/rv/monitor_deadline.rst | 120 ++++++++ kernel/trace/rv/Kconfig | 2 + kernel/trace/rv/Makefile | 2 + kernel/trace/rv/monitors/boost/Kconfig | 15 + kernel/trace/rv/monitors/boost/boost.c | 258 ++++++++++++++++ kernel/trace/rv/monitors/boost/boost.h | 146 +++++++++ kernel/trace/rv/monitors/boost/boost_trace.h | 19 ++ kernel/trace/rv/monitors/laxity/Kconfig | 14 + kernel/trace/rv/monitors/laxity/laxity.c | 279 ++++++++++++++++++ kernel/trace/rv/monitors/laxity/laxity.h | 140 +++++++++ .../trace/rv/monitors/laxity/laxity_trace.h | 19 ++ kernel/trace/rv/rv_trace.h | 2 + tools/verification/models/deadline/boost.dot | 48 +++ tools/verification/models/deadline/laxity.dot | 37 +++ 14 files changed, 1101 insertions(+) create mode 100644 kernel/trace/rv/monitors/boost/Kconfig create mode 100644 kernel/trace/rv/monitors/boost/boost.c create mode 100644 kernel/trace/rv/monitors/boost/boost.h create mode 100644 kernel/trace/rv/monitors/boost/boost_trace.h create mode 100644 kernel/trace/rv/monitors/laxity/Kconfig create mode 100644 kernel/trace/rv/monitors/laxity/laxity.c create mode 100644 kernel/trace/rv/monitors/laxity/laxity.h create mode 100644 kernel/trace/rv/monitors/laxity/laxity_trace.h create mode 100644 tools/verification/models/deadline/boost.dot create mode 100644 tools/verification/models/deadline/laxity.dot
Documentation/trace/rv/monitor_deadline.rst +120 -0
@@ -156,3 +156,123 @@ server can run from sleeping without being ready:: +--------------+ <---------+ ^ | | +------ dl_throttle;is_constr_dl == 1 || is_defer == 1 ------+ + +Monitor boost +~~~~~~~~~~~~~ + +The boost monitor ensures tasks associated to a server (e.g. fair tasks) run +either independently or boosted in a timely manner. +Unlike other models, the ``running`` state (and the ``switch_in/out`` events) +indicates that any fair task is running, this needs to happen within a +threshold that depends on server deadline and remaining runtime, whenever a +task is ready. + +The following chart is simplified to avoid confusion, several less important +self-loops on states have been removed and event names have been simplified: + +* ``idle`` (``dl_server_idle``) occurs when the CPU runs the idle task. +* ``start/stop`` (``dl_server_start/stop``) start and stop the server. +* ``switch`` (``sched_switch_in/out``) represented as a double arrow to + indicate both edges are present: ``ready -- switch_in -> running`` and + ``running -- switch_out -> ready``. As stated above this fires when any fair + task starts or stops to running. +* ``resume/resume_throttle``: a fair task woke up, potentially when the server + is throttled (no runtime left), this event is especially frequent on self + loops (no state change during a wakeup) but is removed here for clarity. +* arrows merge with an ``x`` sign to indicate they are the same event going to + the same state (but with different origins, e.g. ``{idle/throttled} -- stop + -> stopped``). The ``+`` sign indicates standard crossings or corners. + +Refer to the dot file for the full specification:: + + | + v + #===============# stop;reset(clk) + H H <---------------+ + +------------>H stopped H | + | H H | + | #===============# | + | ^ | | + | | | | replenish;reset(clk) + | stop | | +--+ + | | start;reset(clk) +-----------------+ | | + | | v | | v + | +---------------+ <---------- switch --------> +---------+ + | +- resume -> | ready | | | + | | | | -replenish;reset(clk) | running | + | | +- idle - | clk < thesh() | | | | + | | | +---------------+ <-+ +---------------- +---------+ + | | | | ^ | ^ | + | | | | | throttle | | + | | | | |replenish;reset(clk) | | | + | | | throttle | | replenish;reset(clk) | + | | | | | | | | + | | | v | v | | + | | | +---------+ switch +-------------------+ | | + x---+--+-- | | <----------> | throttled_running | --------+ | + | | | |throttled| +-------------------+ | + | | | | | -----+ | | + | | | +---------+ | | | + | | | ^ | | | + | | | resume_throttle | | | + stop | | | | | | + | | v | | | | + | +---------+ <-----------x--- idle ---x-----------------------------+ + | | | + +-- | idle | <--+ + | | | replenish;reset(clk) + +---------+ ---+ + +Monitor laxity +~~~~~~~~~~~~~~ + +The laxity monitor ensure deferrable servers go to a zero-laxity wait unless +already running and run in starvation cases. The model can stay in the +zero-laxity wait only for up to a period, then the server either prepares to +stop (after ``idle_wait``) or prepares to boost a task (``running``). Boosting +(``sched_switch_in``) is only allowed in the ``running`` state. +``dl_replenish_running`` should not be allowed in ``running``, but can happen +as soon as the server started, the model allows this only within a short +threshold:: + + | + +---- dl_server_stop -----+ | + | v v + | #=======================================# + | +------- H stopped H + | | #=======================================# + | | | ^ + | | dl_server_start_running; dl_server_stop + | | reset(clk) | + | | v | dl_replenish_running; + | | +-------------------------------------+ -----------clk < REPLENISH_NS + | | | | | + | | | running | <------------+ + | | | | + | | +-------------------------------------+ ------------------+ + | | | ^ ^ | + | | dl_throttle dl_replenish_running | dl_update + | | v | | dl_replenish;reset(clk) + | | +-------------------+ | dl_replenish_idle;reset(clk) + | | | replenish_wait | | | + | | | clk < period_ns() | ----------------+---------------------+--------+ + | | +-------------------+ | | | + | | | | | | + | | dl_update | | | + | | dl_replenish;reset(clk) dl_replenish_running | | + | | v | | | + | | +--------------------------+ | | + | dl_server_start; | | <----------------+ | + | reset(clk) | zero_laxity_wait | | + | | | clk < period_ns() | ------+ dl_replenish; | + | +---------------> | | | reset(clk) | + | +--------------------------+ <-----+ dl_update | + | | ^ | + | dl_replenish_idle;reset(clk) | dl_replenish;reset(clk) | + | v dl_update | + | +------------------------+ | | + +----------------- | idle_wait | -+ | + | clk < period_ns() | | + +------------------------+ <-- dl_replenish_idle;reset(clk) + ^ | + +------dl_replenish_idle;reset(clk)
kernel/trace/rv/Kconfig +2 -0
@@ -82,6 +82,8 @@ source "kernel/trace/rv/monitors/stall/Kconfig" source "kernel/trace/rv/monitors/deadline/Kconfig" source "kernel/trace/rv/monitors/nomiss/Kconfig" source "kernel/trace/rv/monitors/throttle/Kconfig" +source "kernel/trace/rv/monitors/boost/Kconfig" +source "kernel/trace/rv/monitors/laxity/Kconfig" # Add new deadline monitors here # Add new monitors here
kernel/trace/rv/Makefile +2 -0
@@ -21,6 +21,8 @@ obj-$(CONFIG_RV_MON_STALL) += monitors/stall/stall.o obj-$(CONFIG_RV_MON_DEADLINE) += monitors/deadline/deadline.o obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o obj-$(CONFIG_RV_MON_THROTTLE) += monitors/throttle/throttle.o +obj-$(CONFIG_RV_MON_BOOST) += monitors/boost/boost.o +obj-$(CONFIG_RV_MON_LAXITY) += monitors/laxity/laxity.o # Add new monitors here obj-$(CONFIG_RV_REACTORS) += rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
kernel/trace/rv/monitors/boost/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_BOOST + depends on RV + depends on RV_MON_DEADLINE + default y + select HA_MON_EVENTS_ID + bool "boost monitor" + help + Monitor to ensure tasks associated to a server (e.g. fair tasks) run + either independently or boosted in a timely manner. + This monitor is part of the deadline monitors collection. + + For further information, see: + Documentation/trace/rv/monitor_deadline.rst
kernel/trace/rv/monitors/boost/boost.c new file +258 -0
258 lines not on this page · raw message
kernel/trace/rv/monitors/boost/boost.h new file +146 -0
146 lines not on this page · raw message
kernel/trace/rv/monitors/boost/boost_trace.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Snippet to be included in rv_trace.h +*/ + +#ifdef CONFIG_RV_MON_BOOST +DEFINE_EVENT (event_da_monitor_id, event_boost, + TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state), +TP_ARGS (id, state, event, next_state, final_state)); + +DEFINE_EVENT (error_da_monitor_id, error_boost, + TP_PROTO(int id, char *state, char *event), +TP_ARGS (id, state, event)); + +DEFINE_EVENT (error_env_da_monitor_id, error_env_boost, + TP_PROTO(int id, char *state, char *event, char *env), +TP_ARGS (id, state, event, env)); +#endif /* CONFIG_RV_MON_BOOST */
kernel/trace/rv/monitors/laxity/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_LAXITY + depends on RV + depends on RV_MON_DEADLINE + default y + select HA_MON_EVENTS_ID + bool "laxity monitor" + help + Monitor to ensure deferrable servers go to a zero-laxity wait unless + already running and run in starvation cases. + + For further information, see: + Documentation/trace/rv/monitor_deadline.rst
kernel/trace/rv/monitors/laxity/laxity.c new file +279 -0
279 lines not on this page · raw message
kernel/trace/rv/monitors/laxity/laxity.h new file +140 -0
140 lines not on this page · raw message
kernel/trace/rv/monitors/laxity/laxity_trace.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Snippet to be included in rv_trace.h +*/ + +#ifdef CONFIG_RV_MON_LAXITY +DEFINE_EVENT (event_da_monitor_id, event_laxity, + TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state), +TP_ARGS (id, state, event, next_state, final_state)); + +DEFINE_EVENT (error_da_monitor_id, error_laxity, + TP_PROTO(int id, char *state, char *event), +TP_ARGS (id, state, event)); + +DEFINE_EVENT (error_env_da_monitor_id, error_env_laxity, + TP_PROTO(int id, char *state, char *event, char *env), +TP_ARGS (id, state, event, env)); +#endif /* CONFIG_RV_MON_LAXITY */
kernel/trace/rv/rv_trace.h +2 -0
@@ -190,6 +190,8 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id,#include <monitors/stall/stall_trace.h> #include <monitors/nomiss/nomiss_trace.h> #include <monitors/throttle/throttle_trace.h> +#include <monitors/boost/boost_trace.h> +#include <monitors/laxity/laxity_trace.h> // Add new monitors based on CONFIG_HA_MON_EVENTS_ID here #endif
tools/verification/models/deadline/boost.dot new file +48 -0
48 lines not on this page · raw message
tools/verification/models/deadline/laxity.dot new file +37 -0
@@ -0,0 +1,37 @@ +digraph state_automaton { + center = true; + size = "7,11"; + {node [shape = circle] "idle_wait"}; + {node [shape = circle] "replenish_wait"}; + {node [shape = circle] "running"}; + {node [shape = plaintext, style=invis, label=""] "__init_stopped"}; + {node [shape = doublecircle] "stopped"}; + {node [shape = circle] "stopped"}; + {node [shape = circle] "zero_laxity_wait"}; + "__init_stopped" -> "stopped"; + "idle_wait" [label = "idle_wait\nclk < period_ns()"]; + "idle_wait" -> "idle_wait" [ label = "dl_replenish_idle;reset(clk)" ]; + "idle_wait" -> "stopped" [ label = "dl_server_stop" ]; + "idle_wait" -> "zero_laxity_wait" [ label = "dl_replenish;reset(clk)\ndl_server_resume" ]; + "replenish_wait" [label = "replenish_wait\nclk < period_ns()"]; + "replenish_wait" -> "idle_wait" [ label = "dl_replenish_idle;reset(clk)" ]; + "replenish_wait" -> "replenish_wait" [ label = "dl_server_resume" ]; + "replenish_wait" -> "running" [ label = "dl_replenish_running;reset(clk)" ]; + "replenish_wait" -> "zero_laxity_wait" [ label = "dl_replenish;reset(clk)" ]; + "running" [label = "running"]; + "running" -> "replenish_wait" [ label = "dl_throttle;reset(clk)" ]; + "running" -> "running" [ label = "sched_switch_in\ndl_server_resume\ndl_replenish_running;clk < REPLENISH_NS" ]; + "running" -> "stopped" [ label = "dl_server_stop" ]; + "stopped" [label = "stopped", color = green3]; + "stopped" -> "running" [ label = "dl_server_start_running;reset(clk)" ]; + "stopped" -> "stopped" [ label = "dl_server_resume" ]; + "stopped" -> "zero_laxity_wait" [ label = "dl_server_start;reset(clk)" ]; + "zero_laxity_wait" [label = "zero_laxity_wait\nclk < period_ns()"]; + "zero_laxity_wait" -> "idle_wait" [ label = "dl_replenish_idle;reset(clk)" ]; + "zero_laxity_wait" -> "running" [ label = "dl_replenish_running;reset(clk)" ]; + "zero_laxity_wait" -> "zero_laxity_wait" [ label = "dl_replenish;reset(clk)\ndl_server_resume" ]; + { rank = min ; + "__init_stopped"; + "stopped"; + } +}
Signature · 1 line
2.53.0
Re: [PATCH v7 15/15] rv: Add dl_server specific monitors
Hello,
Quoted 11 lines · Gabriele Monaco
Add monitors to validate the behaviour of the deadline server.
The currently implemented monitors are:
* boost
fair tasks run either independently or boosted
* laxity
deferrable servers wait for zero-laxity and runCc Peter Zijlstra <[email protected]>Reviewed-by Nam Cao <[email protected]>Signed-off-by Gabriele Monaco <[email protected]>
Best,
Juri