Add Hybrid Automata monitor type, per-object and deadline monitors
Subsystems (4)
Gabriele Monaco
maintainerv2 cover Add Hybrid Automata monitor type, per-object and deadline monitors
This RFC contains several related changes, I'm sending them together to give the full picture and get early feedback but I'm probably going to submit some of them separately.
The main areas are:
* DA monitor cleanup to remove macros
* 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).
Note: this series is NOT based on the changes in [1], the next version will integrate that and likely adapt models.
Changes since V1 [2]:
* Cleanup unused trace events definitions
* Improve hybrid automata description about use of timers
* Unify event handler internals across DA monitor types
* Implement timer wheel alternative for invariants
* Extend models to consider timing of task switches (in before deadline, out after throttle)
* Refactor tracepoints and per-object monitors to allow server events from remote CPUs
* Changed clock representation in case of invariants (time to expire vs time since reset) and allow conversion without reset
* Extend dot2k to understand the graph relations and suggest where invariant conversions are needed
* General cleanup of rvgen scripts
[1] - https://lore.kernel.org/lkml/175817861437.709179.10913499403372809816.tip-bot2@tip-bot2
[2] - https://lore.kernel.org/lkml/[email protected]
To: Steven Rostedt <[email protected]>
To: Nam Cao <[email protected]>
Cc: Tomas Glozar <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Clark Williams <[email protected]>
Cc: John Kacur <[email protected]>
Cc: [email protected]
Gabriele Monaco (20):
rv: Refactor da_monitor to minimise macros
rv: Cleanup da_monitor after refactor
rv: Unify DA event handling functions across monitor types Documentation/rv: Adapt documentation after da_monitor refactoring verification/rvgen: Adapt dot2k and templates after refactoring
da_monitor.h
verification/rvgen: Annotate DA functions with types verification/dot2c: Remove __buff_to_string() and cleanup verification/dot2c: Remove superfluous enum assignment and add last
comma
verification/rvgen: Remove unused variable declaration from containers
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
sched: Export hidden tracepoints to modules
sched: Add deadline tracepoints
rv: Add support for per-object monitors in DA/HA verification/rvgen: Add support for per-obj monitors
rv: Add deadline monitors
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 | 340 +++++ Documentation/trace/rv/index.rst | 3 + Documentation/trace/rv/monitor_deadline.rst | 151 ++ Documentation/trace/rv/monitor_sched.rst | 62 +- Documentation/trace/rv/monitor_stall.rst | 43 + Documentation/trace/rv/monitor_synthesis.rst | 151 +- include/linux/rv.h | 43 + include/rv/automata.h | 132 +- include/rv/da_monitor.h | 1289 ++++++++++------- include/rv/ha_monitor.h | 472 ++++++ include/trace/events/sched.h | 16 + kernel/sched/core.c | 7 + kernel/sched/deadline.c | 9 + kernel/trace/rv/Kconfig | 19 + kernel/trace/rv/Makefile | 4 + kernel/trace/rv/monitors/deadline/Kconfig | 10 + kernel/trace/rv/monitors/deadline/deadline.c | 35 + kernel/trace/rv/monitors/deadline/deadline.h | 200 +++ kernel/trace/rv/monitors/nomiss/Kconfig | 15 + kernel/trace/rv/monitors/nomiss/nomiss.c | 283 ++++ kernel/trace/rv/monitors/nomiss/nomiss.h | 130 ++ .../trace/rv/monitors/nomiss/nomiss_trace.h | 19 + kernel/trace/rv/monitors/nrp/nrp.c | 30 +- kernel/trace/rv/monitors/nrp/nrp.h | 22 +- kernel/trace/rv/monitors/opid/Kconfig | 11 +- kernel/trace/rv/monitors/opid/opid.c | 129 +- kernel/trace/rv/monitors/opid/opid.h | 94 +- kernel/trace/rv/monitors/opid/opid_trace.h | 4 + kernel/trace/rv/monitors/rtapp/rtapp.c | 2 - kernel/trace/rv/monitors/sched/sched.c | 2 - kernel/trace/rv/monitors/sco/sco.c | 26 +- kernel/trace/rv/monitors/sco/sco.h | 14 +- kernel/trace/rv/monitors/scpd/scpd.c | 28 +- kernel/trace/rv/monitors/scpd/scpd.h | 14 +- kernel/trace/rv/monitors/snep/snep.c | 28 +- kernel/trace/rv/monitors/snep/snep.h | 18 +- kernel/trace/rv/monitors/snroc/snroc.c | 26 +- kernel/trace/rv/monitors/snroc/snroc.h | 14 +- kernel/trace/rv/monitors/sssw/sssw.c | 38 +- kernel/trace/rv/monitors/sssw/sssw.h | 22 +- kernel/trace/rv/monitors/stall/Kconfig | 13 + kernel/trace/rv/monitors/stall/stall.c | 146 ++ kernel/trace/rv/monitors/stall/stall.h | 64 + kernel/trace/rv/monitors/stall/stall_trace.h | 19 + kernel/trace/rv/monitors/sts/sts.c | 34 +- kernel/trace/rv/monitors/sts/sts.h | 28 +- kernel/trace/rv/monitors/throttle/Kconfig | 15 + kernel/trace/rv/monitors/throttle/throttle.c | 253 ++++ kernel/trace/rv/monitors/throttle/throttle.h | 118 ++ .../rv/monitors/throttle/throttle_trace.h | 19 + kernel/trace/rv/monitors/wip/wip.c | 26 +- kernel/trace/rv/monitors/wip/wip.h | 14 +- kernel/trace/rv/monitors/wwnr/wwnr.c | 28 +- kernel/trace/rv/monitors/wwnr/wwnr.h | 14 +- kernel/trace/rv/rv_trace.h | 68 +- tools/verification/models/deadline/nomiss.dot | 39 + .../verification/models/deadline/throttle.dot | 44 + tools/verification/models/sched/opid.dot | 36 +- tools/verification/models/stall.dot | 20 + tools/verification/rvgen/__main__.py | 8 +- tools/verification/rvgen/rvgen/automata.py | 166 ++- tools/verification/rvgen/rvgen/dot2c.py | 160 +- tools/verification/rvgen/rvgen/dot2k.py | 506 ++++++- tools/verification/rvgen/rvgen/generator.py | 4 +- .../rvgen/rvgen/templates/container/main.c | 2 - .../rvgen/rvgen/templates/dot2k/main.c | 25 +- .../rvgen/templates/dot2k/trace_hybrid.h | 16 + 70 files changed, 4717 insertions(+), 1170 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/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/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/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: 8b789f2b7602a818e7c7488c74414fae21392b63
Signature · 1 line
2.51.0
Gabriele Monaco
maintainerPATCH v2 1/20 Refactor da_monitor to minimise macros
The da_monitor helper functions are generated from macros of the type:
DECLARE_DA_FUNCTION(name, type) \
static void da_func_x_##name(type arg) {} \
static void da_func_y_##name(type arg) {} \
This is good to minimise code duplication but the long macros made of skipped end of lines is rather hard to parse. Since functions are static, the advantage of naming them differently for each monitor is minimal.
Refactor the da_monitor.h file to minimise macros, instead of declaring functions from macros, we simply declare them with the same name for all monitors (e.g. da_func_x) and for any remaining reference to the monitor name (e.g. tracepoints, enums, global variables) we use the CONCATENATE macro.
In this way the file is much easier to maintain while keeping the same generality.
Functions depending on the monitor types are now conditionally compiled according to the value of RV_MON_TYPE, which must be defined in the monitor source.
The monitor type can be specified as in the original implementation, although it's best to keep the default implementation (unsigned char) as not all parts of code support larger data types, and likely there's no need.
We keep the empty macro definitions to ease review of this change with diff tools, but cleanup is required.
Also adapt existing monitors to keep the build working.
--- include/linux/rv.h | 4 + include/rv/automata.h | 132 ++-- include/rv/da_monitor.h | 911 ++++++++++++------------- kernel/trace/rv/monitors/nrp/nrp.c | 30 +- kernel/trace/rv/monitors/nrp/nrp.h | 2 + kernel/trace/rv/monitors/opid/opid.c | 40 +- kernel/trace/rv/monitors/opid/opid.h | 2 + kernel/trace/rv/monitors/sco/sco.c | 26 +- kernel/trace/rv/monitors/sco/sco.h | 2 + kernel/trace/rv/monitors/scpd/scpd.c | 28 +- kernel/trace/rv/monitors/scpd/scpd.h | 2 + kernel/trace/rv/monitors/snep/snep.c | 28 +- kernel/trace/rv/monitors/snep/snep.h | 2 + kernel/trace/rv/monitors/snroc/snroc.c | 26 +- kernel/trace/rv/monitors/snroc/snroc.h | 2 + kernel/trace/rv/monitors/sssw/sssw.c | 38 +- kernel/trace/rv/monitors/sssw/sssw.h | 2 + kernel/trace/rv/monitors/sts/sts.c | 34 +- kernel/trace/rv/monitors/sts/sts.h | 2 + kernel/trace/rv/monitors/wip/wip.c | 26 +- kernel/trace/rv/monitors/wip/wip.h | 2 + kernel/trace/rv/monitors/wwnr/wwnr.c | 28 +- kernel/trace/rv/monitors/wwnr/wwnr.h | 2 + 23 files changed, 689 insertions(+), 682 deletions(-)
include/linux/rv.h +4 -0
@@ -13,6 +13,10 @@#define MAX_DA_NAME_LEN 32#define MAX_DA_RETRY_RACING_EVENTS 3 +#define RV_MON_GLOBAL 0 +#define RV_MON_PER_CPU 1 +#define RV_MON_PER_TASK 2 +#ifdef CONFIG_RV #include <linux/bitops.h> #include <linux/types.h>
include/rv/automata.h +73 -59
142 lines not on this page · raw message
include/rv/da_monitor.h +450 -461
979 lines not on this page · raw message
kernel/trace/rv/monitors/nrp/nrp.c +14 -16
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "nrp"
@@ -15,17 +14,16 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_TASK#include "nrp.h" - -static struct rv_monitor rv_nrp; -DECLARE_DA_MON_PER_TASK(nrp, unsigned char); +#include <rv/da_monitor.h> #ifdef CONFIG_X86_LOCAL_APIC #include <asm/trace/irq_vectors.h> static void handle_vector_irq_entry (void *data,int vector) { -da_handle_event_nrp (current, irq_entry_nrp); +da_handle_event (current, irq_entry_nrp); }static void attach_vector_irq (void )
@@ -60,7 +58,7 @@ static void detach_vector_irq(void) { }static void handle_irq_entry (void *data,int irq,struct irqaction *action) { -da_handle_event_nrp (current, irq_entry_nrp); +da_handle_event (current, irq_entry_nrp); } static void handle_sched_need_resched(void *data, struct task_struct *tsk,
@@ -72,22 +70,22 @@ static void handle_sched_need_resched(void *data, struct task_struct *tsk,* which may not mirror the system state but makes the monitor simpler, */ if (tif ==TIF_NEED_RESCHED ) -da_handle_start_event_nrp (tsk, sched_need_resched_nrp); +da_handle_start_event (tsk, sched_need_resched_nrp); }static void handle_schedule_entry (void *data,bool preempt) {if (preempt) -da_handle_event_nrp (current, schedule_entry_preempt_nrp); +da_handle_event (current, schedule_entry_preempt_nrp);else -da_handle_event_nrp (current, schedule_entry_nrp); +da_handle_event (current, schedule_entry_nrp); }static int enable_nrp (void ) {int retval; - retval =da_monitor_init_nrp (); + retval =da_monitor_init ();if (retval)return retval;
@@ -101,33 +99,33 @@ static int enable_nrp(void)static void disable_nrp (void ) { - rv_nrp.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("nrp" , irq_handler_entry, handle_irq_entry);rv_detach_trace_probe ("nrp" , sched_set_need_resched_tp, handle_sched_need_resched);rv_detach_trace_probe ("nrp" , sched_entry_tp, handle_schedule_entry);detach_vector_irq (); -da_monitor_destroy_nrp (); +da_monitor_destroy (); } -static struct rv_monitor rv_nrp = { +static struct rv_monitor rv_this = { .name ="nrp" , .description ="need resched preempts." , .enable = enable_nrp, .disable = disable_nrp, - .reset = da_monitor_reset_all_nrp, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_nrp (void ) { -return rv_register_monitor (&rv_nrp, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_nrp(void) { -rv_unregister_monitor (&rv_nrp); +rv_unregister_monitor (&rv_this); }module_init (register_nrp);
kernel/trace/rv/monitors/nrp/nrp.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME nrp +enum states_nrp { preempt_irq_nrp =0 , any_thread_running_nrp,
kernel/trace/rv/monitors/opid/opid.c +19 -21
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "opid"
@@ -16,17 +15,16 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_CPU#include "opid.h" - -static struct rv_monitor rv_opid; -DECLARE_DA_MON_PER_CPU(opid, unsigned char); +#include <rv/da_monitor.h> #ifdef CONFIG_X86_LOCAL_APIC #include <asm/trace/irq_vectors.h> static void handle_vector_irq_entry (void *data,int vector) { -da_handle_event_opid (irq_entry_opid); +da_handle_event (irq_entry_opid); }static void attach_vector_irq (void )
@@ -61,52 +59,52 @@ static void detach_vector_irq(void) { }static void handle_irq_disable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_opid (irq_disable_opid); +da_handle_event (irq_disable_opid); }static void handle_irq_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_opid (irq_enable_opid); +da_handle_event (irq_enable_opid); }static void handle_irq_entry (void *data,int irq,struct irqaction *action) { -da_handle_event_opid (irq_entry_opid); +da_handle_event (irq_entry_opid); }static void handle_preempt_disable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_opid (preempt_disable_opid); +da_handle_event (preempt_disable_opid); }static void handle_preempt_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_opid (preempt_enable_opid); +da_handle_event (preempt_enable_opid); }static void handle_sched_need_resched (void *data,struct task_struct *tsk,int cpu,int tif) {/* The monitor's intitial state is not in_irq */ if (this_cpu_read (hardirq_context)) -da_handle_event_opid (sched_need_resched_opid); +da_handle_event (sched_need_resched_opid);else -da_handle_start_event_opid (sched_need_resched_opid); +da_handle_start_event (sched_need_resched_opid); }static void handle_sched_waking (void *data,struct task_struct *p) {/* The monitor's intitial state is not in_irq */ if (this_cpu_read (hardirq_context)) -da_handle_event_opid (sched_waking_opid); +da_handle_event (sched_waking_opid);else -da_handle_start_event_opid (sched_waking_opid); +da_handle_start_event (sched_waking_opid); }static int enable_opid (void ) {int retval; - retval =da_monitor_init_opid (); + retval =da_monitor_init ();if (retval)return retval;
@@ -124,7 +122,7 @@ static int enable_opid(void)static void disable_opid (void ) { - rv_opid.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("opid" , irq_disable, handle_irq_disable);rv_detach_trace_probe ("opid" , irq_enable, handle_irq_enable);
@@ -135,29 +133,29 @@ static void disable_opid(void)rv_detach_trace_probe ("opid" , sched_waking, handle_sched_waking);detach_vector_irq (); -da_monitor_destroy_opid (); +da_monitor_destroy (); }/* * This is the monitor register section. */ -static struct rv_monitor rv_opid = { +static struct rv_monitor rv_this = { .name ="opid" , .description ="operations with preemption and irq disabled." , .enable = enable_opid, .disable = disable_opid, - .reset = da_monitor_reset_all_opid, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_opid (void ) { -return rv_register_monitor (&rv_opid, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_opid(void) { -rv_unregister_monitor (&rv_opid); +rv_unregister_monitor (&rv_this); }module_init (register_opid);
kernel/trace/rv/monitors/opid/opid.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME opid +enum states_opid { disabled_opid =0 , enabled_opid,
kernel/trace/rv/monitors/sco/sco.c +12 -14
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "sco"
@@ -14,31 +13,30 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_CPU#include "sco.h" - -static struct rv_monitor rv_sco; -DECLARE_DA_MON_PER_CPU(sco, unsigned char); +#include <rv/da_monitor.h> static void handle_sched_set_state (void *data,struct task_struct *tsk,int state) { -da_handle_start_event_sco (sched_set_state_sco); +da_handle_start_event (sched_set_state_sco); }static void handle_schedule_entry (void *data,bool preempt) { -da_handle_event_sco (schedule_entry_sco); +da_handle_event (schedule_entry_sco); }static void handle_schedule_exit (void *data,bool is_switch) { -da_handle_start_event_sco (schedule_exit_sco); +da_handle_start_event (schedule_exit_sco); }static int enable_sco (void ) {int retval; - retval =da_monitor_init_sco (); + retval =da_monitor_init ();if (retval)return retval;
@@ -51,32 +49,32 @@ static int enable_sco(void)static void disable_sco (void ) { - rv_sco.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("sco" , sched_set_state_tp, handle_sched_set_state);rv_detach_trace_probe ("sco" , sched_entry_tp, handle_schedule_entry);rv_detach_trace_probe ("sco" , sched_exit_tp, handle_schedule_exit); -da_monitor_destroy_sco (); +da_monitor_destroy (); } -static struct rv_monitor rv_sco = { +static struct rv_monitor rv_this = { .name ="sco" , .description ="scheduling context operations." , .enable = enable_sco, .disable = disable_sco, - .reset = da_monitor_reset_all_sco, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_sco (void ) { -return rv_register_monitor (&rv_sco, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_sco(void) { -rv_unregister_monitor (&rv_sco); +rv_unregister_monitor (&rv_this); }module_init (register_sco);
kernel/trace/rv/monitors/sco/sco.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME sco +enum states_sco { thread_context_sco =0 , scheduling_context_sco,
kernel/trace/rv/monitors/scpd/scpd.c +13 -15
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "scpd"
@@ -15,36 +14,35 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_CPU#include "scpd.h" - -static struct rv_monitor rv_scpd; -DECLARE_DA_MON_PER_CPU(scpd, unsigned char); +#include <rv/da_monitor.h> static void handle_preempt_disable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_scpd (preempt_disable_scpd); +da_handle_event (preempt_disable_scpd); }static void handle_preempt_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_start_event_scpd (preempt_enable_scpd); +da_handle_start_event (preempt_enable_scpd); }static void handle_schedule_entry (void *data,bool preempt) { -da_handle_event_scpd (schedule_entry_scpd); +da_handle_event (schedule_entry_scpd); }static void handle_schedule_exit (void *data,bool is_switch) { -da_handle_event_scpd (schedule_exit_scpd); +da_handle_event (schedule_exit_scpd); }static int enable_scpd (void ) {int retval; - retval =da_monitor_init_scpd (); + retval =da_monitor_init ();if (retval)return retval;
@@ -58,33 +56,33 @@ static int enable_scpd(void)static void disable_scpd (void ) { - rv_scpd.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("scpd" , preempt_disable, handle_preempt_disable);rv_detach_trace_probe ("scpd" , preempt_enable, handle_preempt_enable);rv_detach_trace_probe ("scpd" , sched_entry_tp, handle_schedule_entry);rv_detach_trace_probe ("scpd" , sched_exit_tp, handle_schedule_exit); -da_monitor_destroy_scpd (); +da_monitor_destroy (); } -static struct rv_monitor rv_scpd = { +static struct rv_monitor rv_this = { .name ="scpd" , .description ="schedule called with preemption disabled." , .enable = enable_scpd, .disable = disable_scpd, - .reset = da_monitor_reset_all_scpd, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_scpd (void ) { -return rv_register_monitor (&rv_scpd, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_scpd(void) { -rv_unregister_monitor (&rv_scpd); +rv_unregister_monitor (&rv_this); }module_init (register_scpd);
kernel/trace/rv/monitors/scpd/scpd.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME scpd +enum states_scpd { cant_sched_scpd =0 , can_sched_scpd,
kernel/trace/rv/monitors/snep/snep.c +13 -15
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "snep"
@@ -15,36 +14,35 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_CPU#include "snep.h" - -static struct rv_monitor rv_snep; -DECLARE_DA_MON_PER_CPU(snep, unsigned char); +#include <rv/da_monitor.h> static void handle_preempt_disable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_start_event_snep (preempt_disable_snep); +da_handle_start_event (preempt_disable_snep); }static void handle_preempt_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_start_event_snep (preempt_enable_snep); +da_handle_start_event (preempt_enable_snep); }static void handle_schedule_entry (void *data,bool preempt) { -da_handle_event_snep (schedule_entry_snep); +da_handle_event (schedule_entry_snep); }static void handle_schedule_exit (void *data,bool is_switch) { -da_handle_start_event_snep (schedule_exit_snep); +da_handle_start_event (schedule_exit_snep); }static int enable_snep (void ) {int retval; - retval =da_monitor_init_snep (); + retval =da_monitor_init ();if (retval)return retval;
@@ -58,33 +56,33 @@ static int enable_snep(void)static void disable_snep (void ) { - rv_snep.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("snep" , preempt_disable, handle_preempt_disable);rv_detach_trace_probe ("snep" , preempt_enable, handle_preempt_enable);rv_detach_trace_probe ("snep" , sched_entry_tp, handle_schedule_entry);rv_detach_trace_probe ("snep" , sched_exit_tp, handle_schedule_exit); -da_monitor_destroy_snep (); +da_monitor_destroy (); } -static struct rv_monitor rv_snep = { +static struct rv_monitor rv_this = { .name ="snep" , .description ="schedule does not enable preempt." , .enable = enable_snep, .disable = disable_snep, - .reset = da_monitor_reset_all_snep, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_snep (void ) { -return rv_register_monitor (&rv_snep, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_snep(void) { -rv_unregister_monitor (&rv_snep); +rv_unregister_monitor (&rv_this); }module_init (register_snep);
kernel/trace/rv/monitors/snep/snep.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME snep +enum states_snep { non_scheduling_context_snep =0 , scheduling_contex_snep,
kernel/trace/rv/monitors/snroc/snroc.c +12 -14
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "snroc"
@@ -14,14 +13,13 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_TASK#include "snroc.h" - -static struct rv_monitor rv_snroc; -DECLARE_DA_MON_PER_TASK(snroc, unsigned char); +#include <rv/da_monitor.h> static void handle_sched_set_state (void *data,struct task_struct *tsk,int state) { -da_handle_event_snroc (tsk, sched_set_state_snroc); +da_handle_event (tsk, sched_set_state_snroc); } static void handle_sched_switch(void *data, bool preempt,
@@ -29,15 +27,15 @@ static void handle_sched_switch(void *data, bool preempt,struct task_struct *next, unsigned int prev_state) { -da_handle_start_event_snroc (prev ,sched_switch_out_snroc ); -da_handle_event_snroc (next, sched_switch_in_snroc); +da_handle_start_event (prev ,sched_switch_out_snroc ); +da_handle_event (next, sched_switch_in_snroc); }static int enable_snroc (void ) {int retval; - retval =da_monitor_init_snroc (); + retval =da_monitor_init ();if (retval)return retval;
@@ -49,31 +47,31 @@ static int enable_snroc(void)static void disable_snroc (void ) { - rv_snroc.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("snroc" , sched_set_state_tp, handle_sched_set_state);rv_detach_trace_probe ("snroc" , sched_switch, handle_sched_switch); -da_monitor_destroy_snroc (); +da_monitor_destroy (); } -static struct rv_monitor rv_snroc = { +static struct rv_monitor rv_this = { .name ="snroc" , .description ="set non runnable on its own context." , .enable = enable_snroc, .disable = disable_snroc, - .reset = da_monitor_reset_all_snroc, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_snroc (void ) { -return rv_register_monitor (&rv_snroc, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_snroc(void) { -rv_unregister_monitor (&rv_snroc); +rv_unregister_monitor (&rv_this); }module_init (register_snroc);
kernel/trace/rv/monitors/snroc/snroc.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME snroc +enum states_snroc { other_context_snroc =0 , own_context_snroc,
kernel/trace/rv/monitors/sssw/sssw.c +18 -20
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "sssw"
@@ -15,17 +14,16 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_TASK#include "sssw.h" - -static struct rv_monitor rv_sssw; -DECLARE_DA_MON_PER_TASK(sssw, unsigned char); +#include <rv/da_monitor.h> static void handle_sched_set_state (void *data,struct task_struct *tsk,int state) {if (state ==TASK_RUNNING ) -da_handle_start_event_sssw (tsk, sched_set_state_runnable_sssw); +da_handle_start_event (tsk, sched_set_state_runnable_sssw);else -da_handle_event_sssw (tsk, sched_set_state_sleepable_sssw); +da_handle_event (tsk, sched_set_state_sleepable_sssw); } static void handle_sched_switch(void *data, bool preempt,
@@ -34,15 +32,15 @@ static void handle_sched_switch(void *data, bool preempt, unsigned int prev_state) {if (preempt) -da_handle_event_sssw (prev, sched_switch_preempt_sssw); +da_handle_event (prev, sched_switch_preempt_sssw);else if (prev_state ==TASK_RUNNING ) -da_handle_event_sssw (prev, sched_switch_yield_sssw); +da_handle_event (prev, sched_switch_yield_sssw);else if (prev_state ==TASK_RTLOCK_WAIT )/* special case of sleeping task with racy conditions */ -da_handle_event_sssw (prev, sched_switch_blocking_sssw); +da_handle_event (prev, sched_switch_blocking_sssw);else -da_handle_event_sssw (prev, sched_switch_suspend_sssw); -da_handle_event_sssw (next, sched_switch_in_sssw); +da_handle_event (prev, sched_switch_suspend_sssw); +da_handle_event (next, sched_switch_in_sssw); }static void handle_sched_wakeup (void *data,struct task_struct *p)
@@ -51,21 +49,21 @@ static void handle_sched_wakeup(void *data, struct task_struct *p)* Wakeup can also lead to signal_wakeup although the system is * actually runnable. The monitor can safely start with this event. */ -da_handle_start_event_sssw (p, sched_wakeup_sssw); +da_handle_start_event (p, sched_wakeup_sssw); }static void handle_signal_deliver (void *data,int sig,struct kernel_siginfo *info,struct k_sigaction *ka) { -da_handle_event_sssw (current, signal_deliver_sssw); +da_handle_event (current, signal_deliver_sssw); }static int enable_sssw (void ) {int retval; - retval =da_monitor_init_sssw (); + retval =da_monitor_init ();if (retval)return retval;
@@ -79,33 +77,33 @@ static int enable_sssw(void)static void disable_sssw (void ) { - rv_sssw.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("sssw" , sched_set_state_tp, handle_sched_set_state);rv_detach_trace_probe ("sssw" , sched_switch, handle_sched_switch);rv_detach_trace_probe ("sssw" , sched_wakeup, handle_sched_wakeup);rv_detach_trace_probe ("sssw" , signal_deliver, handle_signal_deliver); -da_monitor_destroy_sssw (); +da_monitor_destroy (); } -static struct rv_monitor rv_sssw = { +static struct rv_monitor rv_this = { .name ="sssw" , .description ="set state sleep and wakeup." , .enable = enable_sssw, .disable = disable_sssw, - .reset = da_monitor_reset_all_sssw, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_sssw (void ) { -return rv_register_monitor (&rv_sssw, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_sssw(void) { -rv_unregister_monitor (&rv_sssw); +rv_unregister_monitor (&rv_this); }module_init (register_sssw);
kernel/trace/rv/monitors/sssw/sssw.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME sssw +enum states_sssw { runnable_sssw =0 , signal_wakeup_sssw,
kernel/trace/rv/monitors/sts/sts.c +16 -18
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "sts"
@@ -16,17 +15,16 @@#include <rv_trace.h> #include <monitors/sched/sched.h> +#define RV_MON_TYPE RV_MON_PER_CPU#include "sts.h" - -static struct rv_monitor rv_sts; -DECLARE_DA_MON_PER_CPU(sts, unsigned char); +#include <rv/da_monitor.h> #ifdef CONFIG_X86_LOCAL_APIC #include <asm/trace/irq_vectors.h> static void handle_vector_irq_entry (void *data,int vector) { -da_handle_event_sts (irq_entry_sts); +da_handle_event (irq_entry_sts); }static void attach_vector_irq (void )
@@ -61,17 +59,17 @@ static void detach_vector_irq(void) { }static void handle_irq_disable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_sts (irq_disable_sts); +da_handle_event (irq_disable_sts); }static void handle_irq_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_sts (irq_enable_sts); +da_handle_event (irq_enable_sts); }static void handle_irq_entry (void *data,int irq,struct irqaction *action) { -da_handle_event_sts (irq_entry_sts); +da_handle_event (irq_entry_sts); } static void handle_sched_switch(void *data, bool preempt,
@@ -79,24 +77,24 @@ static void handle_sched_switch(void *data, bool preempt,struct task_struct *next, unsigned int prev_state) { -da_handle_event_sts (sched_switch_sts ); +da_handle_event (sched_switch_sts ); }static void handle_schedule_entry (void *data,bool preempt) { -da_handle_event_sts (schedule_entry_sts); +da_handle_event (schedule_entry_sts); }static void handle_schedule_exit (void *data,bool is_switch) { -da_handle_start_event_sts (schedule_exit_sts); +da_handle_start_event (schedule_exit_sts); }static int enable_sts (void ) {int retval; - retval =da_monitor_init_sts (); + retval =da_monitor_init ();if (retval)return retval;
@@ -113,7 +111,7 @@ static int enable_sts(void)static void disable_sts (void ) { - rv_sts.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("sts" , irq_disable, handle_irq_disable);rv_detach_trace_probe ("sts" , irq_enable, handle_irq_enable);
@@ -123,29 +121,29 @@ static void disable_sts(void)rv_detach_trace_probe ("sts" , sched_exit_tp, handle_schedule_exit);detach_vector_irq (); -da_monitor_destroy_sts (); +da_monitor_destroy (); }/* * This is the monitor register section. */ -static struct rv_monitor rv_sts = { +static struct rv_monitor rv_this = { .name ="sts" , .description ="schedule implies task switch." , .enable = enable_sts, .disable = disable_sts, - .reset = da_monitor_reset_all_sts, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_sts (void ) { -return rv_register_monitor (&rv_sts, &rv_sched); +return rv_register_monitor (&rv_this, &rv_sched); } static void __exit unregister_sts(void) { -rv_unregister_monitor (&rv_sts); +rv_unregister_monitor (&rv_this); }module_init (register_sts);
kernel/trace/rv/monitors/sts/sts.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME sts +enum states_sts { can_sched_sts =0 , cant_sched_sts,
kernel/trace/rv/monitors/wip/wip.c +12 -14
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "wip"
@@ -14,31 +13,30 @@#include <trace/events/sched.h> #include <trace/events/preemptirq.h> +#define RV_MON_TYPE RV_MON_PER_CPU#include "wip.h" - -static struct rv_monitor rv_wip; -DECLARE_DA_MON_PER_CPU(wip, unsigned char); +#include <rv/da_monitor.h> static void handle_preempt_disable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_event_wip (preempt_disable_wip); +da_handle_event (preempt_disable_wip); }static void handle_preempt_enable (void *data,unsigned long ip,unsigned long parent_ip) { -da_handle_start_event_wip (preempt_enable_wip); +da_handle_start_event (preempt_enable_wip); }static void handle_sched_waking (void *data,struct task_struct *task) { -da_handle_event_wip (sched_waking_wip); +da_handle_event (sched_waking_wip); }static int enable_wip (void ) {int retval; - retval =da_monitor_init_wip (); + retval =da_monitor_init ();if (retval)return retval;
@@ -51,32 +49,32 @@ static int enable_wip(void)static void disable_wip (void ) { - rv_wip.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("wip" , preempt_disable, handle_preempt_disable);rv_detach_trace_probe ("wip" , preempt_enable, handle_preempt_enable);rv_detach_trace_probe ("wip" , sched_waking, handle_sched_waking); -da_monitor_destroy_wip (); +da_monitor_destroy (); } -static struct rv_monitor rv_wip = { +static struct rv_monitor rv_this = { .name ="wip" , .description ="wakeup in preemptive per-cpu testing monitor." , .enable = enable_wip, .disable = disable_wip, - .reset = da_monitor_reset_all_wip, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_wip (void ) { -return rv_register_monitor (&rv_wip,NULL ); +return rv_register_monitor (&rv_this,NULL ); } static void __exit unregister_wip(void) { -rv_unregister_monitor (&rv_wip); +rv_unregister_monitor (&rv_this); }module_init (register_wip);
kernel/trace/rv/monitors/wip/wip.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME wip +enum states_wip { preemptive_wip =0 , non_preemptive_wip,
kernel/trace/rv/monitors/wwnr/wwnr.c +13 -15
@@ -6,40 +6,38 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "wwnr"#include <rv_trace.h> #include <trace/events/sched.h> +#define RV_MON_TYPE RV_MON_PER_TASK#include "wwnr.h" - -static struct rv_monitor rv_wwnr; -DECLARE_DA_MON_PER_TASK(wwnr, unsigned char); +#include <rv/da_monitor.h> static void handle_switch (void *data,bool preempt,struct task_struct *p,struct task_struct *n,unsigned int prev_state) {/* start monitoring only after the first suspension */ if (prev_state ==TASK_INTERRUPTIBLE ) -da_handle_start_event_wwnr (p, switch_out_wwnr); +da_handle_start_event (p, switch_out_wwnr);else -da_handle_event_wwnr (p, switch_out_wwnr); +da_handle_event (p, switch_out_wwnr); -da_handle_event_wwnr (n, switch_in_wwnr); +da_handle_event (n, switch_in_wwnr); }static void handle_wakeup (void *data,struct task_struct *p) { -da_handle_event_wwnr (p, wakeup_wwnr); +da_handle_event (p, wakeup_wwnr); }static int enable_wwnr (void ) {int retval; - retval =da_monitor_init_wwnr (); + retval =da_monitor_init ();if (retval)return retval;
@@ -51,31 +49,31 @@ static int enable_wwnr(void)static void disable_wwnr (void ) { - rv_wwnr.enabled =0 ; + rv_this.enabled =0 ;rv_detach_trace_probe ("wwnr" , sched_switch, handle_switch);rv_detach_trace_probe ("wwnr" , sched_wakeup, handle_wakeup); -da_monitor_destroy_wwnr (); +da_monitor_destroy (); } -static struct rv_monitor rv_wwnr = { +static struct rv_monitor rv_this = { .name ="wwnr" , .description ="wakeup while not running per-task testing model." , .enable = enable_wwnr, .disable = disable_wwnr, - .reset = da_monitor_reset_all_wwnr, + .reset = da_monitor_reset_all, .enabled =0 , };static int __init register_wwnr (void ) { -return rv_register_monitor (&rv_wwnr,NULL ); +return rv_register_monitor (&rv_this,NULL ); } static void __exit unregister_wwnr(void) { -rv_unregister_monitor (&rv_wwnr); +rv_unregister_monitor (&rv_this); }module_init (register_wwnr);
kernel/trace/rv/monitors/wwnr/wwnr.h +2 -0
@@ -5,6 +5,8 @@* Documentation/trace/rv/deterministic_automata.rst */ +#define MONITOR_NAME wwnr +enum states_wwnr { not_running_wwnr =0 , running_wwnr,
Signature · 1 line
2.51.0
Re: [PATCH v2 01/20] rv: Refactor da_monitor to minimise macros
Quoted 26 lines · Gabriele Monaco
The
da_monitorhelper functions are generated from macros of the type:
DECLARE_DA_FUNCTION(name, type)\
static void da_func_x_##name(type arg) {} \
static void da_func_y_##name(type arg) {} \This is good to minimise code duplication but the long macros made of skipped end of lines is rather hard to parse. Since functions are static, the advantage of naming them differently for each monitor is minimal.
Refactor the
da_monitor.hfile to minimise macros, instead of declaring functions from macros, we simply declare them with the same name for all monitors (e.g.da_func_x) and for any remaining reference to the monitor name (e.g. tracepoints, enums, global variables) we use the CONCATENATE macro.
In this way the file is much easier to maintain while keeping the same generality.
Functions depending on the monitor types are now conditionally compiled according to the value ofRV_MON_TYPE, which must be defined in the monitor source.
The monitor type can be specified as in the original implementation, although it's best to keep the default implementation (unsigned char) as not all parts of code support larger data types, and likely there's no need.
Quoted 6 lines
We keep the empty macro definitions to ease review of this change with diff tools, but cleanup is required.
Also adapt existing monitors to keep the build working.
Signed-off-by Gabriele Monaco <[email protected]>
Farewell, macros. You won't be missed.
Gabriele Monaco
maintainerPATCH v2 2/20 Cleanup da_monitor after refactor
In reply to Gabriele MonacoPrevious changes refactored the da_monitor header file to avoid using macros, however empty macros (e.g. DECLARE_DA_FUNCTION) were left to ease review with diff tools.
Most macros also get the argument type which doesn't really have a purpose since states have their own enum and the storage in struct da_monitor is fixed to unsigned int.
Remove empty and no longer required macros and substitute the type parameter with the appropriate enum.
Additionally break long line and adjust the format overall.
--- include/rv/automata.h | 24 +++----- include/rv/da_monitor.h | 121 +++++++++++++++------------------------- 2 files changed, 53 insertions(+), 92 deletions(-)
include/rv/automata.h +8 -16
@@ -6,29 +6,19 @@* models in C generated by the dot2k tool. */ +#ifndef _RV_AUTOMATA_H +#define _RV_AUTOMATA_H +#ifndef MONITOR_NAME #error "MONITOR_NAME macro is not defined. Did you include $(MODEL_NAME).h generated by rvgen?"#endif -#ifndef type -#define type unsigned char -#endif -#define RV_AUTOMATON_NAME CONCATENATE(automaton_, MONITOR_NAME)#define EVENT_MAX CONCATENATE(event_max_, MONITOR_NAME)#define STATE_MAX CONCATENATE(state_max_, MONITOR_NAME)#define events CONCATENATE(events_, MONITOR_NAME)#define states CONCATENATE(states_, MONITOR_NAME) -/* -* DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata -* -* Define a set of helper functions for automata. The 'name' argument is used -* as suffix for the functions and data. These functions will handle automaton -* with data type 'type'. -*/ -#define DECLARE_AUTOMATA_HELPERS (name, type) -/* * model_get_state_name - return the (string) name of the given state */
@@ -54,7 +44,7 @@ static char *model_get_event_name(enum events event)/* * model_get_initial_state - return the automaton's initial state */ -static inline type model_get_initial_state (void ) +static inline enum states model_get_initial_state (void ) {return RV_AUTOMATON_NAME .initial_state; }
@@ -65,8 +55,8 @@ static inline type model_get_initial_state(void)* Given the current state (curr_state) and the event (event), returns * the next state, or INVALID_STATE in case of error. */ -static inline type model_get_next_state (enum states curr_state, -enum events event) +static inline enum states model_get_next_state (enum states curr_state, +enum events event) {if ((curr_state <0 ) || (curr_state >=STATE_MAX ))return INVALID_STATE ;
@@ -87,3 +77,5 @@ static inline bool model_is_final_state(enum states state) return RV_AUTOMATON_NAME.final_states[state]; } + +#endif
include/rv/da_monitor.h +45 -76
277 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v2 02/20] rv: Cleanup da_monitor after refactor
Quoted 7 lines · Gabriele Monaco
Previous changes refactored the
da_monitorheader file to avoid using macros, however empty macros (e.g.DECLARE_DA_FUNCTION) were left to ease review with diff tools.
Most macros also get the argument type which doesn't really have a purpose since states have their own enum and the storage in structda_monitoris fixed to unsigned int.
Quoted 5 lines
Remove empty and no longer required macros and substitute the type parameter with the appropriate enum.
Additionally break long line and adjust the format overall.Signed-off-by Gabriele Monaco <[email protected]>
Gabriele Monaco
maintainerPATCH v2 3/20 Unify DA event handling functions across monitor types
In reply to Gabriele MonacoThe DA event handling functions are mostly duplicated because the per-task monitors need to propagate the task to use the pid in the trace events. This is a maintenance burden for a little advantage. The task can be obtained with some pointer arithmetic from the da_mon, hence only the function tracing events really need to differ.
Unify all code handling the events, create da_trace_event() and da_trace_error() that only call the tracepoint function. Propagate the monitor id through the calls, the do_trace_ functions use the id (pid) in case of per-task monitors but ignore it for implicit monitors.
--- include/rv/da_monitor.h | 303 +++++++++++++++++++--------------------- 1 file changed, 142 insertions(+), 161 deletions(-)
include/rv/da_monitor.h +142 -161
@@ -23,6 +23,13 @@#define RV_DA_MON_NAME CONCATENATE(da_mon_, MONITOR_NAME)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 +#ifdef CONFIG_RV_REACTORS static void cond_react (enum states curr_state,enum events event)
@@ -99,90 +106,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 ) { -cond_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 ) { -cond_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.
@@ -288,6 +211,14 @@ static inline struct da_monitor *da_get_monitor(struct task_struct *tsk)return &tsk->rv[task_mon_slot].da_mon; } +/* +* da_get_task - return the task associated to the monitor +*/ +static inline struct task_struct *da_get_task (struct da_monitor *da_mon) +{ + return container_of(da_mon, struct task_struct, rv[task_mon_slot].da_mon); +} +static void da_monitor_reset_all (void ) {struct task_struct *g, *p;
@@ -337,33 +268,144 @@ 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) +{ +CONCATENATE (trace_event_,MONITOR_NAME )(curr_state, event, next_state, + is_final); +} + +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 +/* +* Trace events for per_task monitors, report the PID of the task. +*/ + +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); +} + +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_event - handle an event for the da_mon +* +* 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_event (struct da_monitor *da_mon,enum events event,da_id_type id) +{ +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 ) { +cond_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; +} + +static inline void __da_handle_event_common (struct da_monitor *da_mon, +enum events event,da_id_type id) {bool retval; - retval =da_event (da_mon, event); + retval =da_event (da_mon, event, id);if (!retval)da_monitor_reset (da_mon); } -/* -* da_handle_event - handle an event -*/ -static inline void da_handle_event (enum events event) +static inline void __da_handle_event (struct da_monitor *da_mon, +enum events event,da_id_type id) { -struct da_monitor *da_mon =da_get_monitor ();bool retval; retval =da_monitor_handling_event (da_mon);if (!retval)return ; -__da_handle_event (da_mon, event); +__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 (unlikely (!da_monitoring (da_mon))) { +da_monitor_start (da_mon); +return 0 ; + } + +__da_handle_event_common (da_mon, event, id); + +return 1 ; +} + +static inline bool __da_handle_start_run_event (struct da_monitor *da_mon, +enum events event,da_id_type id) +{ +if (unlikely (!da_monitoring (da_mon))) +da_monitor_start (da_mon); + +__da_handle_event_common (da_mon, event, id); + +return 1 ; +} + +#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. +*/ + +/* +* da_handle_event - handle an event +*/ +static inline void da_handle_event (enum events event) +{ +__da_handle_event (da_get_monitor (), event,0 ); }/*
@@ -378,21 +420,9 @@ static inline void da_handle_event(enum events event)*/ static inline bool da_handle_start_event (enum events event) { -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); -return 0 ; - } - -__da_handle_event (da_mon, event); - -return 1 ; +return __da_handle_start_event (da_get_monitor (), event,0 ); }/*
@@ -403,19 +433,9 @@ static inline bool da_handle_start_event(enum events event)*/ static inline bool da_handle_start_run_event (enum events event) { -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); - -return 1 ; +return __da_handle_start_run_event (da_get_monitor (), event,0 ); }#elif RV_MON_TYPE ==RV_MON_PER_TASK
@@ -423,29 +443,12 @@ static inline bool da_handle_start_run_event(enum events event)* Handle event for per task. */ -static inline void __da_handle_event (struct da_monitor *da_mon, -struct task_struct *tsk,enum events event) -{ -bool retval; - - retval =da_event (da_mon, tsk, event); -if (!retval) -da_monitor_reset (da_mon); -} -/* * da_handle_event - handle an event */ static inline void da_handle_event (struct task_struct *tsk,enum events event) { -struct da_monitor *da_mon =da_get_monitor (tsk); -bool retval; - - retval =da_monitor_handling_event (da_mon); -if (!retval) -return ; - -__da_handle_event (da_mon, tsk, event); +__da_handle_event (da_get_monitor (tsk), event, tsk->pid); }/*
@@ -461,21 +464,9 @@ 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); }/*
@@ -487,19 +478,9 @@ 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.51.0
Re: [PATCH v2 03/20] rv: Unify DA event handling functions across monitor types
include/rv/da_monitor.h static inline struct da_monitor *da_get_monitor(struct task_struct *tsk) · line 220
Quoted 7 lines · Gabriele Monaco
include/rv/da_monitor.h +7
-0+/* +* da_get_task - return the task associated to the monitor +*/ +static inline struct task_struct *da_get_task (struct da_monitor *da_mon) +{ + return container_of(da_mon, struct task_struct, rv[task_mon_slot].da_mon); +}
This function is not used? Maybe later in the series, let me keep looking..
include/rv/da_monitor.h static inline void da_handle_event(enum events event) · line 424
Quoted 6 lines
static inline bool
da_handle_start_event(enum events event){include/rv/da_monitor.h +0
-2-struct da_monitor *da_mon; -if (!da_monitor_enabled ())return 0 ;
Can't this part be shared between different monitor types?
Same for the other handle functions.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 03/20] rv: Unify DA event handling functions across monitor types
Quoted 11 lines · Nam Cao
Quoted 8 lines · Gabriele Monaco
include/rv/da_monitor.h +6
-0+/* +* da_get_task - return the task associated to the monitor +*/ +static inline struct task_struct *da_get_task (struct da_monitor *da_mon) +{ + return container_of(da_mon, struct task_struct,rv[task_mon_slot].da_mon);
+}This function is not used? Maybe later in the series, let me keep looking..
Right, this doesn't belong here, I should add it later..
Quoted 11 lines
Quoted 7 lines
static inline bool
da_handle_start_event(enum events event){(quoted diff) +0
-2- struct da_monitor *da_mon; -if (!da_monitor_enabled())
return 0;Can't this part be shared between different monitor types?
Same for the other handle functions.
Mmh good point, I left it separate because the per-object monitors (later in the series) do a bit more before calling the __da_handle_* functions (like some potential allocation).
But it's probably not a big deal to let them do that in any case, considering da_monitor_enabled() is false only during teardown or with monitoring off, and in neither case a superfluous allocation should cause problems.
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v2 4/20 Documentation/rv: Adapt documentation after da_monitor refactoring
In reply to Gabriele MonacoPrevious changes refactored the da_monitor header file to avoid using macros. This implies a few changes in how to import and use da_monitor helpers:
DECLARE_DA_MON_<TYPE>(name, type) is substituted by #define RV_MON_TYPE RV_MON_<TYPE>
da_handle_event_<name>() is substituted by
da_handle_event()
Update the documentation to reflect the changes.
--- Documentation/trace/rv/monitor_synthesis.rst | 44 ++++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-)
Documentation/trace/rv/monitor_synthesis.rst +21 -23
@@ -100,54 +100,52 @@ rv/da_monitor.h This initial implementation presents three different types of monitor instances: -- ``#define DECLARE_DA_MON_GLOBAL(name, type)`` -- ``#define DECLARE_DA_MON_PER_CPU(name, type)`` -- ``#define DECLARE_DA_MON_PER_TASK(name, type)`` +- ``#define RV_MON_TYPE RV_MON_GLOBAL`` +- ``#define RV_MON_TYPE RV_MON_PER_CPU`` +- ``#define RV_MON_TYPE RV_MON_PER_TASK`` -The first declares the functions for a global deterministic automata monitor, -the second for monitors with per-cpu instances, and the third with per-task -instances. +The first sets up functions declaration for a global deterministic automata +monitor, the second for monitors with per-cpu instances, and the third with +per-task instances. -In all cases, the 'name' argument is a string that identifies the monitor, and -the 'type' argument is the data type used by rvgen on the representation of -the model in C. +In all cases, the C file must include the $(MODEL_NAME).h file (generated by +`rvgen`), for example, to define the per-cpu 'wip' monitor, the `wip.c` source +file must include:: -For example, the wip model with two states and three events can be -stored in an 'unsigned char' type. Considering that the preemption control -is a per-cpu behavior, the monitor declaration in the 'wip.c' file is:: - - DECLARE_DA_MON_PER_CPU(wip, unsigned char); + #define RV_MON_TYPE RV_MON_PER_CPU + #include "wip.h" + #include <rv/da_monitor.h> The monitor is executed by sending events to be processed via the functions presented below:: - da_handle_event_$(MONITOR_NAME)($(event from event enum)); - da_handle_start_event_$(MONITOR_NAME)($(event from event enum)); - da_handle_start_run_event_$(MONITOR_NAME)($(event from event enum)); + da_handle_event($(event from event enum)); + da_handle_start_event($(event from event enum)); + da_handle_start_run_event($(event from event enum)); -The function ``da_handle_event_$(MONITOR_NAME)()`` is the regular case where +The function ``da_handle_event()`` is the regular case where the event will be processed if the monitor is processing events. When a monitor is enabled, it is placed in the initial state of the automata. However, the monitor does not know if the system is in the *initial state*. -The ``da_handle_start_event_$(MONITOR_NAME)()`` function is used to notify the +The ``da_handle_start_event()`` function is used to notify the monitor that the system is returning to the initial state, so the monitor can start monitoring the next event. -The ``da_handle_start_run_event_$(MONITOR_NAME)()`` function is used to notify +The ``da_handle_start_run_event()`` function is used to notify the monitor that the system is known to be in the initial state, so the monitor can start monitoring and monitor the current event. Using the wip model as example, the events "preempt_disable" and "sched_waking" should be sent to monitor, respectively, via [2]:: - da_handle_event_wip(preempt_disable_wip); - da_handle_event_wip(sched_waking_wip); + da_handle_event(preempt_disable_wip); + da_handle_event(sched_waking_wip); While the event "preempt_enabled" will use:: - da_handle_start_event_wip(preempt_enable_wip); + da_handle_start_event(preempt_enable_wip); To notify the monitor that the system will be returning to the initial state, so the system and the monitor should be in sync.
Signature · 1 line
2.51.0
Re: [PATCH v2 04/20] Documentation/rv: Adapt documentation after da_monitor refactoring
Quoted 7 lines · Gabriele Monaco
Previous changes refactored the
da_monitorheader file to avoid using macros. This implies a few changes in how to import and useda_monitorhelpers:DECLARE_DA_MON_<TYPE>(name, type) is substituted by #define
RV_MON_TYPERV_MON_<TYPE>
Quoted 6 lines
da_handle_event_<name>() is substituted by
da_handle_event()Update the documentation to reflect the changes.
Signed-off-by Gabriele Monaco <[email protected]>
This is probably best reviewed by someone without much RV background. As I already know these information, I'm not sure whether the doc is confusing to outsiders.
But from my point of view:
Gabriele Monaco
maintainerPATCH v2 5/20 verification/rvgen: Adapt dot2k and templates after refactoring da_monitor.h
In reply to Gabriele MonacoPrevious changes refactored the da_monitor header file to avoid using macros. This implies a few changes in how to import and use da_monitor helpers:
DECLARE_DA_MON_<TYPE>(name, type) is substituted by #define RV_MON_TYPE RV_MON_<TYPE>
Update the rvgen templates to reflect the changes.
--- tools/verification/rvgen/rvgen/dot2k.py | 6 +++-- .../rvgen/rvgen/templates/dot2k/main.c | 25 +++++++------------ 2 files changed, 13 insertions(+), 18 deletions(-)
tools/verification/rvgen/rvgen/dot2k.py +4 -2
@@ -38,9 +38,9 @@ class dot2k(Monitor, Dot2c): handle = "handle_start_run_event" if self.monitor_type == "per_task": buff.append("\tstruct task_struct *p = /* XXX: how do I get p? */;"); - buff.append("\tda_%s_%s(p, %s%s);" % (handle, self.name, event, self.enum_suffix)); + buff.append("\tda_%s(p, %s%s);" % (handle, event, self.enum_suffix)); else: - buff.append("\tda_%s_%s(%s%s);" % (handle, self.name, event, self.enum_suffix)); + buff.append("\tda_%s(%s%s);" % (handle, event, self.enum_suffix)); buff.append("}") buff.append("") return '\n'.join(buff)
@@ -66,6 +66,8 @@ class dot2k(Monitor, Dot2c): buff.append(" * Documentation/trace/rv/deterministic_automata.rst") buff.append(" */") buff.append("") + buff.append("#define MONITOR_NAME %s" % (self.name)) + buff.append("") return buff
tools/verification/rvgen/rvgen/templates/dot2k/main.c +9 -16
@@ -6,7 +6,6 @@#include <linux/init.h> #include <linux/rv.h> #include <rv/instrumentation.h> -#include <rv/da_monitor.h> #define MODULE_NAME "%%MODEL_NAME%%"
@@ -20,15 +19,9 @@* This is the self-generated part of the monitor. Generally, there is no need * to touch this section. */ +#define RV_MON_TYPE RV_MON_%%MONITOR_TYPE%%#include "%%MODEL_NAME%%.h" - -/* -* Declare the deterministic automata monitor. -* -* The rv monitor reference is needed for the monitor declaration. -*/ -static struct rv_monitor rv_%%MODEL_NAME%%; -DECLARE_DA_MON_%%MONITOR_TYPE%%(%%MODEL_NAME%%, %%MIN_TYPE%%); +#include <rv/da_monitor.h> /* * This is the instrumentation part of the monitor.
@@ -42,7 +35,7 @@ static int enable_%%MODEL_NAME%%(void) {int retval; - retval = da_monitor_init_%%MODEL_NAME%%(); + retval =da_monitor_init ();if (retval)return retval;
@@ -53,33 +46,33 @@ static int enable_%%MODEL_NAME%%(void) static void disable_%%MODEL_NAME%%(void) { - rv_%%MODEL_NAME%%.enabled = 0; + rv_this.enabled =0 ; %%TRACEPOINT_DETACH%% - da_monitor_destroy_%%MODEL_NAME%%(); +da_monitor_destroy (); }/* * This is the monitor register section. */ -static struct rv_monitor rv_%%MODEL_NAME%% = { +static struct rv_monitor rv_this = { .name ="%%MODEL_NAME%%" , .description ="%%DESCRIPTION%%" , .enable = enable_%%MODEL_NAME%%, .disable = disable_%%MODEL_NAME%%, - .reset = da_monitor_reset_all_%%MODEL_NAME%%, + .reset = da_monitor_reset_all, .enabled =0 , }; static int __init register_%%MODEL_NAME%%(void) { - return rv_register_monitor(&rv_%%MODEL_NAME%%, %%PARENT%%); + return rv_register_monitor(&rv_this, %%PARENT%%); } static void __exit unregister_%%MODEL_NAME%%(void) { - rv_unregister_monitor(&rv_%%MODEL_NAME%%); + rv_unregister_monitor(&rv_this); } module_init(register_%%MODEL_NAME%%);
Signature · 1 line
2.51.0
Re: [PATCH v2 05/20] verification/rvgen: Adapt dot2k and templates after refactoring da_monitor.h
Quoted 10 lines · Gabriele Monaco
Previous changes refactored the
da_monitorheader file to avoid using macros. This implies a few changes in how to import and useda_monitorhelpers:DECLARE_DA_MON_<TYPE>(name, type) is substituted by #define
RV_MON_TYPERV_MON_<TYPE>Update the rvgen templates to reflect the changes.
Signed-off-by Gabriele Monaco <[email protected]>
Gabriele Monaco
maintainerPATCH v2 6/20 verification/rvgen: Annotate DA functions with types
In reply to Gabriele MonacoFunctions in automata.py, dot2c.py and dot2k.py don't have type annotations and it can get complicated to remember how to use them.
Add minimal type annotations.
--- tools/verification/rvgen/rvgen/automata.py | 20 +++++------ tools/verification/rvgen/rvgen/dot2c.py | 42 +++++++++++----------- tools/verification/rvgen/rvgen/dot2k.py | 20 +++++------ 3 files changed, 41 insertions(+), 41 deletions(-)
tools/verification/rvgen/rvgen/automata.py +10 -10
@@ -28,7 +28,7 @@ class Automata: self.function = self.__create_matrix() self.events_start, self.events_start_run = self.__store_init_events() - def __get_model_name(self): + def __get_model_name(self) -> str: basename = ntpath.basename(self.__dot_path) if not basename.endswith(".dot") and not basename.endswith(".gv"): print("not a dot file")
@@ -40,7 +40,7 @@ class Automata: return model_name - def __open_dot(self): + def __open_dot(self) -> list[str]: cursor = 0 dot_lines = [] try:
@@ -60,13 +60,13 @@ class Automata: cursor += 1 return dot_lines - def __get_cursor_begin_states(self): + def __get_cursor_begin_states(self) -> int: cursor = 0 while self.__dot_lines[cursor].split()[0] != "{node": cursor += 1 return cursor - def __get_cursor_begin_events(self): + def __get_cursor_begin_events(self) -> int: cursor = 0 while self.__dot_lines[cursor].split()[0] != "{node": cursor += 1
@@ -76,7 +76,7 @@ class Automata: cursor += 1 return cursor - def __get_state_variables(self): + def __get_state_variables(self) -> tuple[list[str], str, list[str]]: # wait for node declaration states = [] final_states = []
@@ -116,7 +116,7 @@ class Automata: return states, initial_state, final_states - def __get_event_variables(self): + def __get_event_variables(self) -> list[str]: # here we are at the begin of transitions, take a note, we will return later. cursor = self.__get_cursor_begin_events()
@@ -140,7 +140,7 @@ class Automata: return sorted(set(events)) - def __create_matrix(self): + def __create_matrix(self) -> list[list[str]]: # transform the array into a dictionary events = self.events states = self.states
@@ -174,7 +174,7 @@ class Automata: return matrix - def __store_init_events(self): + def __store_init_events(self) -> tuple[list[bool], list[bool]]: events_start = [False] * len(self.events) events_start_run = [False] * len(self.events) for i, _ in enumerate(self.events):
@@ -196,10 +196,10 @@ class Automata: events_start_run[i] = True return events_start, events_start_run - def is_start_event(self, event): + def is_start_event(self, event: str) -> bool: return self.events_start[self.events.index(event)] - def is_start_run_event(self, event): + def is_start_run_event(self, event: str) -> bool: # prefer handle_start_event if there if any(self.events_start): return False
tools/verification/rvgen/rvgen/dot2c.py +21 -21
153 lines not on this page · raw message
tools/verification/rvgen/rvgen/dot2k.py +10 -10
@@ -21,10 +21,10 @@ class dot2k(Monitor, Dot2c): Dot2c.__init__(self, file_path, extra_params.get("model_name")) self.enum_suffix = "_%s" % self.name - def fill_monitor_type(self): + def fill_monitor_type(self) -> str: return self.monitor_type.upper() - def fill_tracepoint_handlers_skel(self): + def fill_tracepoint_handlers_skel(self) -> str: buff = [] for event in self.events: buff.append("static void handle_%s(void *data, /* XXX: fill header */)" % event)
@@ -45,19 +45,19 @@ class dot2k(Monitor, Dot2c): buff.append("") return '\n'.join(buff) - def fill_tracepoint_attach_probe(self): + def fill_tracepoint_attach_probe(self) -> str: buff = [] for event in self.events: buff.append("\trv_attach_trace_probe(\"%s\", /* XXX: tracepoint */, handle_%s);" % (self.name, event)) return '\n'.join(buff) - def fill_tracepoint_detach_helper(self): + def fill_tracepoint_detach_helper(self) -> str: buff = [] for event in self.events: buff.append("\trv_detach_trace_probe(\"%s\", /* XXX: tracepoint */, handle_%s);" % (self.name, event)) return '\n'.join(buff) - def fill_model_h_header(self): + def fill_model_h_header(self) -> list[str]: buff = [] buff.append("/* SPDX-License-Identifier: GPL-2.0 */") buff.append("/*")
@@ -71,7 +71,7 @@ class dot2k(Monitor, Dot2c): return buff - def fill_model_h(self): + def fill_model_h(self) -> str: # # Adjust the definition names #
@@ -85,17 +85,17 @@ class dot2k(Monitor, Dot2c): return '\n'.join(buff) - def fill_monitor_class_type(self): + def fill_monitor_class_type(self) -> str: if self.monitor_type == "per_task": return "DA_MON_EVENTS_ID" return "DA_MON_EVENTS_IMPLICIT" - def fill_monitor_class(self): + def fill_monitor_class(self) -> str: if self.monitor_type == "per_task": return "da_monitor_id" return "da_monitor" - def fill_tracepoint_args_skel(self, tp_type): + def fill_tracepoint_args_skel(self, tp_type: str) -> str: buff = [] tp_args_event = [ ("char *", "state"),
@@ -117,7 +117,7 @@ class dot2k(Monitor, Dot2c): buff.append(" TP_ARGS(%s)" % tp_args_c) return '\n'.join(buff) - def fill_main_c(self): + def fill_main_c(self) -> str: main_c = super().fill_main_c() min_type = self.get_minimun_type()
Signature · 1 line
2.51.0
Re: [PATCH v2 06/20] verification/rvgen: Annotate DA functions with types
Quoted 6 lines · Gabriele Monaco
Functions in
automata.py,dot2c.pyanddot2k.pydon't have type annotations and it can get complicated to remember how to use them.Add minimal type annotations.
Signed-off-by Gabriele Monaco <[email protected]>
Gabriele Monaco
maintainerPATCH v2 7/20 verification/dot2c: Remove __buff_to_string() and cleanup
In reply to Gabriele Monacostr.join() can do what __buff_to_string() does. Therefore replace __buff_to_string() to make the scripts more pythonic.
Also clean and remove some intermediate functions.
--- tools/verification/rvgen/rvgen/dot2c.py | 35 +++++-------------------- 1 file changed, 6 insertions(+), 29 deletions(-)
tools/verification/rvgen/rvgen/dot2c.py +6 -29
@@ -26,15 +26,6 @@ class Dot2c(Automata): super().__init__(file_path, model_name) self.line_length = 100 - def __buff_to_string(self, buff): - string = "" - - for line in buff: - string = string + line + "\n" - - # cut off the last \n - return string[:-1] - def __get_enum_states_content(self) -> list[str]: buff = [] buff.append("\t%s%s = 0," % (self.initial_state, self.enum_suffix))
@@ -45,14 +36,10 @@ class Dot2c(Automata): return buff - def get_enum_states_string(self): - buff = self.__get_enum_states_content() - return self.__buff_to_string(buff) - def format_states_enum(self) -> list[str]: buff = [] buff.append("enum %s {" % self.enum_states_def) - buff.append(self.get_enum_states_string()) + buff += self.__get_enum_states_content() buff.append("};\n") return buff
@@ -71,14 +58,10 @@ class Dot2c(Automata): return buff - def get_enum_events_string(self): - buff = self.__get_enum_events_content() - return self.__buff_to_string(buff) - def format_events_enum(self) -> list[str]: buff = [] buff.append("enum %s {" % self.enum_events_def) - buff.append(self.get_enum_events_string()) + buff += self.__get_enum_events_content() buff.append("};\n") return buff
@@ -127,23 +110,17 @@ class Dot2c(Automata): return string - def get_aut_init_events_string(self): - return self.__get_string_vector_per_line_content(self.events) - - def get_aut_init_states_string(self): - return self.__get_string_vector_per_line_content(self.states) - def format_aut_init_events_string(self) -> list[str]: buff = [] buff.append("\t.event_names = {") - buff.append(self.get_aut_init_events_string()) + buff.append(self.__get_string_vector_per_line_content(self.events)) buff.append("\t},") return buff def format_aut_init_states_string(self) -> list[str]: buff = [] buff.append("\t.state_names = {") - buff.append(self.get_aut_init_states_string()) + buff.append(self.__get_string_vector_per_line_content(self.states)) buff.append("\t},") return buff
@@ -178,7 +155,7 @@ class Dot2c(Automata): line += "\n\t\t}," if linetoolong else " }," buff.append(line) - return self.__buff_to_string(buff) + return '\n'.join(buff) def format_aut_init_function(self) -> list[str]: buff = []
@@ -253,4 +230,4 @@ class Dot2c(Automata): def print_model_classic(self): buff = self.format_model() - print(self.__buff_to_string(buff)) + print('\n'.join(buff))
Signature · 1 line
2.51.0
Gabriele Monaco
maintainerPATCH v2 8/20 verification/dot2c: Remove superfluous enum assignment and add last comma
In reply to Gabriele MonacoThe header files generated by dot2c currently create enums for states and events assigning the first element to 0. This is superfluous as it happens automatically if no value is specified.
Also it doesn't add a comma to the last enum elements, which slightly complicates the diff if states or events are added.
Remove the assignment to 0 and add a comma to last elements, this simplifies the logic for the code generator.
--- kernel/trace/rv/monitors/nrp/nrp.h | 20 +++++++------- kernel/trace/rv/monitors/opid/opid.h | 22 +++++++-------- kernel/trace/rv/monitors/sco/sco.h | 12 ++++----- kernel/trace/rv/monitors/scpd/scpd.h | 12 ++++----- kernel/trace/rv/monitors/snep/snep.h | 16 +++++------ kernel/trace/rv/monitors/snroc/snroc.h | 12 ++++----- kernel/trace/rv/monitors/sssw/sssw.h | 20 +++++++------- kernel/trace/rv/monitors/sts/sts.h | 26 +++++++++--------- kernel/trace/rv/monitors/wip/wip.h | 12 ++++----- kernel/trace/rv/monitors/wwnr/wwnr.h | 12 ++++----- tools/verification/rvgen/rvgen/dot2c.py | 36 +++++++++---------------- 11 files changed, 94 insertions(+), 106 deletions(-)
kernel/trace/rv/monitors/nrp/nrp.h +10 -10
@@ -8,21 +8,21 @@#define MONITOR_NAME nrpenum states_nrp { - preempt_irq_nrp =0 , + preempt_irq_nrp, any_thread_running_nrp, nested_preempt_nrp, rescheduling_nrp, - state_max_nrp + state_max_nrp, };#define INVALID_STATE state_max_nrpenum events_nrp { - irq_entry_nrp =0 , + irq_entry_nrp, sched_need_resched_nrp, schedule_entry_nrp, schedule_entry_preempt_nrp, - event_max_nrp + event_max_nrp, };struct automaton_nrp {
@@ -38,38 +38,38 @@ static const struct automaton_nrp automaton_nrp = {"preempt_irq" ,"any_thread_running" ,"nested_preempt" , -"rescheduling" + "rescheduling", }, .event_names = {"irq_entry" ,"sched_need_resched" ,"schedule_entry" , -"schedule_entry_preempt" + "schedule_entry_preempt", }, .function = { { preempt_irq_nrp, preempt_irq_nrp, nested_preempt_nrp, - nested_preempt_nrp + nested_preempt_nrp, }, { any_thread_running_nrp, rescheduling_nrp, any_thread_running_nrp, -INVALID_STATE +INVALID_STATE , }, { nested_preempt_nrp, preempt_irq_nrp, any_thread_running_nrp, - any_thread_running_nrp + any_thread_running_nrp, }, { preempt_irq_nrp, rescheduling_nrp, any_thread_running_nrp, - any_thread_running_nrp + any_thread_running_nrp, }, }, .initial_state = preempt_irq_nrp,
kernel/trace/rv/monitors/opid/opid.h +11 -11
@@ -8,25 +8,25 @@#define MONITOR_NAME opidenum states_opid { - disabled_opid =0 , + disabled_opid, enabled_opid, in_irq_opid, irq_disabled_opid, preempt_disabled_opid, - state_max_opid + state_max_opid, };#define INVALID_STATE state_max_opidenum events_opid { - irq_disable_opid =0 , + irq_disable_opid, irq_enable_opid, irq_entry_opid, preempt_disable_opid, preempt_enable_opid, sched_need_resched_opid, sched_waking_opid, - event_max_opid + event_max_opid, };struct automaton_opid {
@@ -43,7 +43,7 @@ static const struct automaton_opid automaton_opid = {"enabled" ,"in_irq" ,"irq_disabled" , -"preempt_disabled" + "preempt_disabled", }, .event_names = { "irq_disable",
@@ -52,7 +52,7 @@ static const struct automaton_opid automaton_opid = {"preempt_disable" ,"preempt_enable" ,"sched_need_resched" , -"sched_waking" + "sched_waking", }, .function = { {
@@ -62,7 +62,7 @@ static const struct automaton_opid automaton_opid = {INVALID_STATE , irq_disabled_opid, disabled_opid, - disabled_opid + disabled_opid, }, { irq_disabled_opid,
@@ -71,7 +71,7 @@ static const struct automaton_opid automaton_opid = { preempt_disabled_opid, enabled_opid,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, { INVALID_STATE,
@@ -80,7 +80,7 @@ static const struct automaton_opid automaton_opid = {INVALID_STATE ,INVALID_STATE , in_irq_opid, - in_irq_opid + in_irq_opid, }, { INVALID_STATE,
@@ -89,7 +89,7 @@ static const struct automaton_opid automaton_opid = { disabled_opid,INVALID_STATE , irq_disabled_opid, -INVALID_STATE +INVALID_STATE , }, { disabled_opid,
@@ -98,7 +98,7 @@ static const struct automaton_opid automaton_opid = { INVALID_STATE, enabled_opid,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, }, .initial_state = disabled_opid,
kernel/trace/rv/monitors/sco/sco.h +6 -6
@@ -8,18 +8,18 @@#define MONITOR_NAME scoenum states_sco { - thread_context_sco =0 , + thread_context_sco, scheduling_context_sco, - state_max_sco + state_max_sco, };#define INVALID_STATE state_max_scoenum events_sco { - sched_set_state_sco =0 , + sched_set_state_sco, schedule_entry_sco, schedule_exit_sco, - event_max_sco + event_max_sco, };struct automaton_sco {
@@ -33,12 +33,12 @@ struct automaton_sco {static const struct automaton_sco automaton_sco = { .state_names = {"thread_context" , -"scheduling_context" +"scheduling_context" , }, .event_names = {"sched_set_state" ,"schedule_entry" , -"schedule_exit" +"schedule_exit" , }, .function = { { thread_context_sco, scheduling_context_sco,INVALID_STATE },
kernel/trace/rv/monitors/scpd/scpd.h +6 -6
@@ -8,19 +8,19 @@#define MONITOR_NAME scpdenum states_scpd { - cant_sched_scpd =0 , + cant_sched_scpd, can_sched_scpd, - state_max_scpd + state_max_scpd, };#define INVALID_STATE state_max_scpdenum events_scpd { - preempt_disable_scpd =0 , + preempt_disable_scpd, preempt_enable_scpd, schedule_entry_scpd, schedule_exit_scpd, - event_max_scpd + event_max_scpd, };struct automaton_scpd {
@@ -34,13 +34,13 @@ struct automaton_scpd {static const struct automaton_scpd automaton_scpd = { .state_names = {"cant_sched" , -"can_sched" +"can_sched" , }, .event_names = {"preempt_disable" ,"preempt_enable" ,"schedule_entry" , -"schedule_exit" +"schedule_exit" , }, .function = { { can_sched_scpd,INVALID_STATE ,INVALID_STATE ,INVALID_STATE },
kernel/trace/rv/monitors/snep/snep.h +8 -8
@@ -8,19 +8,19 @@#define MONITOR_NAME snepenum states_snep { - non_scheduling_context_snep =0 , + non_scheduling_context_snep, scheduling_contex_snep, - state_max_snep + state_max_snep, };#define INVALID_STATE state_max_snepenum events_snep { - preempt_disable_snep =0 , + preempt_disable_snep, preempt_enable_snep, schedule_entry_snep, schedule_exit_snep, - event_max_snep + event_max_snep, };struct automaton_snep {
@@ -34,26 +34,26 @@ struct automaton_snep {static const struct automaton_snep automaton_snep = { .state_names = {"non_scheduling_context" , -"scheduling_contex" +"scheduling_contex" , }, .event_names = {"preempt_disable" ,"preempt_enable" ,"schedule_entry" , -"schedule_exit" +"schedule_exit" , }, .function = { { non_scheduling_context_snep, non_scheduling_context_snep, scheduling_contex_snep, -INVALID_STATE +INVALID_STATE , }, {INVALID_STATE ,INVALID_STATE ,INVALID_STATE , - non_scheduling_context_snep + non_scheduling_context_snep, }, }, .initial_state = non_scheduling_context_snep,
kernel/trace/rv/monitors/snroc/snroc.h +6 -6
@@ -8,18 +8,18 @@#define MONITOR_NAME snrocenum states_snroc { - other_context_snroc =0 , + other_context_snroc, own_context_snroc, - state_max_snroc + state_max_snroc, };#define INVALID_STATE state_max_snrocenum events_snroc { - sched_set_state_snroc =0 , + sched_set_state_snroc, sched_switch_in_snroc, sched_switch_out_snroc, - event_max_snroc + event_max_snroc, };struct automaton_snroc {
@@ -33,12 +33,12 @@ struct automaton_snroc {static const struct automaton_snroc automaton_snroc = { .state_names = {"other_context" , -"own_context" +"own_context" , }, .event_names = {"sched_set_state" ,"sched_switch_in" , -"sched_switch_out" +"sched_switch_out" , }, .function = { {INVALID_STATE , own_context_snroc,INVALID_STATE },
kernel/trace/rv/monitors/sssw/sssw.h +10 -10
@@ -8,17 +8,17 @@#define MONITOR_NAME ssswenum states_sssw { - runnable_sssw =0 , + runnable_sssw, signal_wakeup_sssw, sleepable_sssw, sleeping_sssw, - state_max_sssw + state_max_sssw, };#define INVALID_STATE state_max_ssswenum events_sssw { - sched_set_state_runnable_sssw =0 , + sched_set_state_runnable_sssw, sched_set_state_sleepable_sssw, sched_switch_blocking_sssw, sched_switch_in_sssw,
@@ -27,7 +27,7 @@ enum events_sssw { sched_switch_yield_sssw, sched_wakeup_sssw, signal_deliver_sssw, - event_max_sssw + event_max_sssw, }; struct automaton_sssw {
@@ -43,7 +43,7 @@ static const struct automaton_sssw automaton_sssw = {"runnable" ,"signal_wakeup" ,"sleepable" , -"sleeping" + "sleeping", }, .event_names = { "sched_set_state_runnable",
@@ -54,7 +54,7 @@ static const struct automaton_sssw automaton_sssw = {"sched_switch_suspend" ,"sched_switch_yield" ,"sched_wakeup" , -"signal_deliver" + "signal_deliver", }, .function = { {
@@ -66,7 +66,7 @@ static const struct automaton_sssw automaton_sssw = {INVALID_STATE , runnable_sssw, runnable_sssw, - runnable_sssw + runnable_sssw, }, { INVALID_STATE,
@@ -77,7 +77,7 @@ static const struct automaton_sssw automaton_sssw = {INVALID_STATE , signal_wakeup_sssw, signal_wakeup_sssw, - runnable_sssw + runnable_sssw, }, { runnable_sssw,
@@ -88,7 +88,7 @@ static const struct automaton_sssw automaton_sssw = { sleeping_sssw, signal_wakeup_sssw, runnable_sssw, - sleepable_sssw + sleepable_sssw, }, { INVALID_STATE,
@@ -99,7 +99,7 @@ static const struct automaton_sssw automaton_sssw = { INVALID_STATE,INVALID_STATE , runnable_sssw, -INVALID_STATE +INVALID_STATE , }, }, .initial_state = runnable_sssw,
kernel/trace/rv/monitors/sts/sts.h +13 -13
@@ -8,26 +8,26 @@#define MONITOR_NAME stsenum states_sts { - can_sched_sts =0 , + can_sched_sts, cant_sched_sts, disable_to_switch_sts, enable_to_exit_sts, in_irq_sts, scheduling_sts, switching_sts, - state_max_sts + state_max_sts, };#define INVALID_STATE state_max_stsenum events_sts { - irq_disable_sts =0 , + irq_disable_sts, irq_enable_sts, irq_entry_sts, sched_switch_sts, schedule_entry_sts, schedule_exit_sts, - event_max_sts + event_max_sts, };struct automaton_sts {
@@ -46,7 +46,7 @@ static const struct automaton_sts automaton_sts = {"enable_to_exit" ,"in_irq" ,"scheduling" , -"switching" + "switching", }, .event_names = { "irq_disable",
@@ -54,7 +54,7 @@ static const struct automaton_sts automaton_sts = {"irq_entry" ,"sched_switch" ,"schedule_entry" , -"schedule_exit" + "schedule_exit", }, .function = { {
@@ -63,7 +63,7 @@ static const struct automaton_sts automaton_sts = {INVALID_STATE ,INVALID_STATE , scheduling_sts, -INVALID_STATE +INVALID_STATE , }, { INVALID_STATE,
@@ -71,7 +71,7 @@ static const struct automaton_sts automaton_sts = { cant_sched_sts,INVALID_STATE ,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, { INVALID_STATE,
@@ -79,7 +79,7 @@ static const struct automaton_sts automaton_sts = { in_irq_sts, switching_sts,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, { enable_to_exit_sts,
@@ -87,7 +87,7 @@ static const struct automaton_sts automaton_sts = { enable_to_exit_sts,INVALID_STATE ,INVALID_STATE , - can_sched_sts + can_sched_sts, }, { INVALID_STATE,
@@ -95,7 +95,7 @@ static const struct automaton_sts automaton_sts = { in_irq_sts,INVALID_STATE ,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, { disable_to_switch_sts,
@@ -103,7 +103,7 @@ static const struct automaton_sts automaton_sts = {INVALID_STATE ,INVALID_STATE ,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, { INVALID_STATE,
@@ -111,7 +111,7 @@ static const struct automaton_sts automaton_sts = { INVALID_STATE,INVALID_STATE ,INVALID_STATE , -INVALID_STATE +INVALID_STATE , }, }, .initial_state = can_sched_sts,
kernel/trace/rv/monitors/wip/wip.h +6 -6
@@ -8,18 +8,18 @@#define MONITOR_NAME wipenum states_wip { - preemptive_wip =0 , + preemptive_wip, non_preemptive_wip, - state_max_wip + state_max_wip, };#define INVALID_STATE state_max_wipenum events_wip { - preempt_disable_wip =0 , + preempt_disable_wip, preempt_enable_wip, sched_waking_wip, - event_max_wip + event_max_wip, };struct automaton_wip {
@@ -33,12 +33,12 @@ struct automaton_wip {static const struct automaton_wip automaton_wip = { .state_names = {"preemptive" , -"non_preemptive" +"non_preemptive" , }, .event_names = {"preempt_disable" ,"preempt_enable" , -"sched_waking" +"sched_waking" , }, .function = { { non_preemptive_wip,INVALID_STATE ,INVALID_STATE },
kernel/trace/rv/monitors/wwnr/wwnr.h +6 -6
@@ -8,18 +8,18 @@#define MONITOR_NAME wwnrenum states_wwnr { - not_running_wwnr =0 , + not_running_wwnr, running_wwnr, - state_max_wwnr + state_max_wwnr, };#define INVALID_STATE state_max_wwnrenum events_wwnr { - switch_in_wwnr =0 , + switch_in_wwnr, switch_out_wwnr, wakeup_wwnr, - event_max_wwnr + event_max_wwnr, };struct automaton_wwnr {
@@ -33,12 +33,12 @@ struct automaton_wwnr {static const struct automaton_wwnr automaton_wwnr = { .state_names = {"not_running" , -"running" +"running" , }, .event_names = {"switch_in" ,"switch_out" , -"wakeup" +"wakeup" , }, .function = { { running_wwnr,INVALID_STATE , not_running_wwnr },
tools/verification/rvgen/rvgen/dot2c.py +12 -24
@@ -28,11 +28,11 @@ class Dot2c(Automata): def __get_enum_states_content(self) -> list[str]: buff = [] - buff.append("\t%s%s = 0," % (self.initial_state, self.enum_suffix)) + buff.append("\t%s%s," % (self.initial_state, self.enum_suffix)) for state in self.states: if state != self.initial_state: buff.append("\t%s%s," % (state, self.enum_suffix)) - buff.append("\tstate_max%s" % (self.enum_suffix)) + buff.append("\tstate_max%s," % (self.enum_suffix)) return buff
@@ -46,15 +46,10 @@ class Dot2c(Automata): def __get_enum_events_content(self) -> list[str]: buff = [] - first = True for event in self.events: - if first: - buff.append("\t%s%s = 0," % (event, self.enum_suffix)) - first = False - else: - buff.append("\t%s%s," % (event, self.enum_suffix)) + buff.append("\t%s%s," % (event, self.enum_suffix)) - buff.append("\tevent_max%s" % self.enum_suffix) + buff.append("\tevent_max%s," % self.enum_suffix) return buff
@@ -97,18 +92,11 @@ class Dot2c(Automata): buff.append("static const struct %s %s = {" % (self.struct_automaton_def, self.var_automaton_def)) return buff - def __get_string_vector_per_line_content(self, buff: list[str]) -> str: - first = True - string = "" - for entry in buff: - if first: - string = string + "\t\t\"" + entry - first = False; - else: - string = string + "\",\n\t\t\"" + entry - string = string + "\"" - - return string + def __get_string_vector_per_line_content(self, entries: list[str]) -> str: + buff = [] + for entry in entries: + buff.append(f"\t\t\"{entry}\",") + return "\n".join(buff) def format_aut_init_events_string(self) -> list[str]: buff = []
@@ -152,7 +140,7 @@ class Dot2c(Automata): if y != nr_events-1: line += ",\n" if linetoolong else ", " else: - line += "\n\t\t}," if linetoolong else " }," + line += ",\n\t\t}," if linetoolong else " }," buff.append(line) return '\n'.join(buff)
@@ -179,12 +167,12 @@ class Dot2c(Automata): line = "" first = True for state in self.states: - if first == False: + if not first: line = line + ', ' else: first = False - if self.final_states.__contains__(state): + if state in self.final_states: line = line + '1' else: line = line + '0'
Signature · 1 line
2.51.0
Re: [PATCH v2 08/20] verification/dot2c: Remove superfluous enum assignment and add last comma
Quoted 10 lines · Gabriele Monaco
The header files generated by dot2c currently create enums for states and events assigning the first element to 0. This is superfluous as it happens automatically if no value is specified.
Also it doesn't add a comma to the last enum elements, which slightly complicates the diff if states or events are added.Remove the assignment to 0 and add a comma to last elements, this simplifies the logic for the code generator.
Signed-off-by Gabriele Monaco <[email protected]>
There are some minor changes which are not mentioned, but not a big deal:
Gabriele Monaco
maintainerPATCH v2 9/20 verification/rvgen: Remove unused variable declaration from containers
In reply to Gabriele MonacoThe monitor container source files contained a declaration and a definition for the rv_monitor variable. The former is superfluous and can be removed.
Remove the variable declaration from the template as well as the existing monitor containers.
--- kernel/trace/rv/monitors/rtapp/rtapp.c | 2 -- kernel/trace/rv/monitors/sched/sched.c | 2 -- tools/verification/rvgen/rvgen/templates/container/main.c | 2 -- 3 files changed, 6 deletions(-)
kernel/trace/rv/monitors/rtapp/rtapp.c +0 -2
@@ -8,8 +8,6 @@#include "rtapp.h" -struct rv_monitor rv_rtapp; -struct rv_monitor rv_rtapp = { .name ="rtapp" , .description ="Collection of monitors for detecting problems with real-time applications" ,
kernel/trace/rv/monitors/sched/sched.c +0 -2
@@ -8,8 +8,6 @@#include "sched.h" -struct rv_monitor rv_sched; -struct rv_monitor rv_sched = { .name ="sched" , .description ="container for several scheduler monitor specifications." ,
tools/verification/rvgen/rvgen/templates/container/main.c +0 -2
@@ -8,8 +8,6 @@#include "%%MODEL_NAME%%.h" -struct rv_monitor rv_%%MODEL_NAME%%; - struct rv_monitor rv_%%MODEL_NAME%% = { .name ="%%MODEL_NAME%%" , .description ="%%DESCRIPTION%%" ,
Signature · 1 line
2.51.0
Gabriele Monaco
maintainerPATCH v2 10/20 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.
--- include/linux/rv.h | 38 +++ include/rv/da_monitor.h | 59 ++++- include/rv/ha_monitor.h | 469 +++++++++++++++++++++++++++++++++++++ kernel/trace/rv/Kconfig | 13 + kernel/trace/rv/rv_trace.h | 63 +++++ 5 files changed, 637 insertions(+), 5 deletions(-) create mode 100644 include/rv/ha_monitor.h
include/linux/rv.h +38 -0
@@ -83,11 +83,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 +54 -5
125 lines not on this page · raw message
include/rv/ha_monitor.h new file +469 -0
469 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.51.0
Re: [PATCH v2 10/20] rv: Add Hybrid Automata monitor type
Quoted 8 lines · Gabriele Monaco
include/rv/ha_monitor.h new file +2
-0@@ -0,0 +1,469 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/*
include/rv/ha_monitor.h line 12
Quoted 10 lines
include/rv/ha_monitor.h new file +10
-0+* Copyright (C) 2025-2028 Red Hat, Inc. Gabriele Monaco <[email protected]> +* +* Hybrid automata (HA) monitor functions, to be used together +* with automata models in C generated by the dot2k tool. +* +* This type of monitors extends the Deterministic automata (DA) class by +* adding a set of environment variables (e.g. clocks) that can be used to +* constraint the valid transitions. +* +* The dot2k tool is available at tools/verification/dot2k/
^^^^^^^^^^^^^^^^^^^^^^^^^
non-existentinclude/rv/ha_monitor.h line 115
Quoted 11 lines
include/rv/ha_monitor.h new file +11
-0+/* +* ktime_get_ns is expensive, since we usually don't require precise accounting +* of changes within the same event, cache the current time at the beginning of +* the constraint handler and use the cache for subsequent calls. +* Monitors without ns clocks automatically skip this. +*/ +#ifdef HA_CLK_NS +#define ha_update_ns_cache () ktime_get_ns() +#else +#define ha_update_ns_cache () 0 +#endif /* HA_CLK_NS */
ha_update_ns_cache() itself does not cache, its caller does. So I think it is misleading to name this "cache".
Why is "update" in the name? Isn't something like ha_get_ns() betters describe this macro?
include/rv/ha_monitor.h line 255
Quoted 4 lines
include/rv/ha_monitor.h new file +4
-0+/* +* The clock variables have 2 different representations in the env_store: +* - The guard representation is the timestamp of the last reset +* - The invariant representation is the timestamp when the invariant expires
Why does guard representation store the last reset?
For example, what if I specifiy the guard as "clk > 500ns". Shouldn't the guard representation be "500ns"?
include/rv/ha_monitor.h line 299
Quoted 11 lines
include/rv/ha_monitor.h new file +11
-0+static inline u64 ha_get_passed_ns (struct ha_monitor *ha_mon,enum envs env, +u64 expire,u64 time_ns) +{ +u64 passed =0 ; + +if (env <0 || env >=ENV_MAX_STORED ) +return 0 ; +if (ha_monitor_env_invalid (ha_mon, env)) +return 0 ; + passed =ha_get_env (ha_mon, env, time_ns); +ha_set_invariant_ns (ha_mon, env, expire - passed, time_ns);
The function is named *get*() which indicates that it only reads. But it also writes.
include/rv/ha_monitor.h line 348
Quoted 10 lines
include/rv/ha_monitor.h new file +10
-0+/* +* Retrieve the last reset time (guard representation) from the invariant +* representation (expiration). +* It the caller's responsibility to make sure the storage was actually in the +* invariant representation (e.g. the current state has an invariant). +* The provided value must be the same used when starting the invariant. +* +* This function's access to the storage is NOT atomic, due to the rarity when +* this is used. If a monitor allows writes concurrent to this, likely +* other things are broken and need rethinking the model or additional locking.
Does atomic_sub() solves your "NOT atomic" problem?
include/rv/ha_monitor.h line 386
Quoted 7 lines
include/rv/ha_monitor.h new file +7
-0+static inline void ha_start_timer_jiffy (struct ha_monitor *ha_mon,enum envs env, +u64 expire,u64 time_ns) +{ +u64 passed =ha_get_passed_jiffy (ha_mon, env, expire, time_ns); + +mod_timer (&ha_mon->timer,get_jiffies_64 () + expire - passed); +}
I don't understand this "passed" thing. I see this function being called in ha_setup_invariants() of stall monitor. Stall monitor is validating that the task does not stay in "enqueued" state for more than "threshold_jiffies". If so, what is the purpose of "passed"? From my understanding, it should be just
static inline void ha_start_timer_jiffy(struct ha_monitor *ha_mon, enum envs env,
u64 expire, u64 time_ns)
{
mod_timer(&ha_mon->timer, get_jiffies_64() + expire);
}what do I miss?
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 10/20] rv: Add Hybrid Automata monitor type
Quoted 14 lines · Nam Cao
Quoted 13 lines · Gabriele Monaco
include/rv/ha_monitor.h new file +3
-0@@ -0,0 +1,469 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2025-2028 Red Hat, Inc. Gabriele Monaco <[email protected]>
+ *
+ * Hybrid automata (HA) monitor functions, to be used together
+ * with automata models in C generated by the dot2k tool.
Quoted 8 lines
Quoted 6 lines
+ *
+ * This type of monitors extends the Deterministic automata (DA) class by
+ * adding a set of environment variables (e.g. clocks) that can be used to
+ * constraint the valid transitions.
+ *
+ * The dot2k tool is available attools/verification/dot2k/^^^^^^^^^^^^^^^^^^^^^^^^^ non-existent
Right, need to update also in DA.
Quoted 17 lines
include/rv/ha_monitor.h line 115
Quoted 13 lines
+/*
+ *ktime_get_nsis expensive, since we usually don't require precise accounting
+ * of changes within the same event, cache the current time at the beginning of
+ * the constraint handler and use the cache for subsequent calls.
+ * Monitors without ns clocks automatically skip this.
+ */include/rv/ha_monitor.h new file +5
-0+#ifdef HA_CLK_NS +#define ha_update_ns_cache () ktime_get_ns() +#else +#define ha_update_ns_cache () 0 +#endif /* HA_CLK_NS */
ha_update_ns_cache()itself does not cache, its caller does. So I think it is misleading to name this "cache".
Quoted 3 lines
Why is "update" in the name? Isn't something like
ha_get_ns()betters describe this macro?
Good point.
Quoted 10 lines
Quoted 5 lines
+/*
+ * The clock variables have 2 different representations in theenv_store:
+ * - The guard representation is the timestamp of the last reset
+ * - The invariant representation is the timestamp when the invariant expiresWhy does guard representation store the last reset?
For example, what if I specifiy the guard as "clk > 500ns". Shouldn't the guard representation be "500ns"?
Alright, this is the simplest way I could think to represent clocks, still it seems confusing.
Let's start from guards (invariants are not special but I'm trying to do something to keep precision), the value of a clock is the time that passed since the last reset, as that's when the value is set to 0. Storing that timestamp and just comparing the difference whenever you need to know the valuation of said clock seemed the most straightforward thing to me. The clock representation doesn't include the guard constraint, that is validated during the event using the current valuation (i.e. now - reset_time).
What is important to note is that, at time of reset, you don't know what guard is going to fire, you may as well have a state with event A asking for clk<10 and event B requiring clk<20, also the guard may be in a later state and may depend on the path.
Invariants are bound to the form clk < N, and get "armed" when we reach the state, from there we know exactly when the invariant is going to expire, so we can save that (very important when using the timer wheel). Note here that the expiration isn't exactly N from now, but it's the valuation of the clock (reset might have occurred a few states earlier, see the nomiss case) subtracted by N, this is what the "passed" means later.
That said, I couldn't think of a simpler implementation but any suggestion is welcome, of course.
Quoted 7 lines
Quoted 7 lines
+static inline u64 ha_get_passed_ns(struct
ha_monitor*ha_mon, enum envs env,include/rv/ha_monitor.h new file +5
-0+ u64 expire, u64 time_ns) +{ +u64 passed =0 ; + +if (env <0 || env >=ENV_MAX_STORED )
Quoted 8 lines
include/rv/ha_monitor.h line 299
Quoted 5 lines
include/rv/ha_monitor.h new file +5
-0+return 0 ; +if (ha_monitor_env_invalid (ha_mon, env)) +return 0 ; + passed =ha_get_env (ha_mon, env, time_ns); +ha_set_invariant_ns (ha_mon, env, expire - passed, time_ns);The function is named *get*() which indicates that it only reads. But it also writes.
Right.
Quoted 15 lines
Quoted 14 lines
+/*
+ * Retrieve the last reset time (guard representation) from the invariant
+ * representation (expiration).
+ * It the caller's responsibility to make sure the storage was actually in the
+ * invariant representation (e.g. the current state has an invariant).
+ * The provided value must be the same used when starting the invariant.
+ *
+ * This function's access to the storage is NOT atomic, due to the rarity when
+ * this is used. If a monitor allows writes concurrent to this, likely
+ * other things are broken and need rethinking the model or additional locking.
Quoted 1 line
Does
atomic_sub()solves your "NOT atomic" problem?
Kinda, it would solve the problem for this specific subtraction, but racing handlers could still lead to problems although the subtraction is "correct".
Since this is the only time the env storage needs to be an atomic_t and it's fairly rare (only complicated models require calling this function at all, others are happy with READ_ONCE/WRITE_ONCE) I didn't want to change the storage implementation for some perceived safety.
I wrote that comment exactly to motivate why we aren't using atomic_t, but I should probably reword that. Does this make sense to you?
Quoted 16 lines
include/rv/ha_monitor.h line 386
Quoted 9 lines
+static inline void ha_start_timer_jiffy(struct
ha_monitor*ha_mon, enum envs env,include/rv/ha_monitor.h new file +6
-0+ u64 expire, u64 time_ns) +{ +u64 passed =ha_get_passed_jiffy (ha_mon, env, expire, time_ns); + +mod_timer (&ha_mon->timer,get_jiffies_64 () + expire - passed); +}I don't understand this "passed" thing. I see this function being called in
ha_setup_invariants()of stall monitor. Stall monitor is validating that the task does not stay in "enqueued" state for more than "threshold_jiffies". If so, what is the purpose of "passed"? From my understanding, it should be just
Quoted 8 lines
static inline void ha_start_timer_jiffy(struct
ha_monitor*ha_mon, enum envs env,u64 expire, u64 time_ns) { mod_timer(&ha_mon->timer, get_jiffies_64() + expire); }what do I miss?
As mentioned before, this is true for the stall case, where the reset occurred when reaching the state with the invariant (passed is close to 0), if you look at the nomiss case, reset happens before being ready (its invariant would have passed close to 0), but the same invariant is enforced in running, here we will see a passed far from 0 and need to take that into account when setting the invariant.
This is by the way what made necessary caching the ns time, otherwise we'd end up reading the ktime multiple times in the same handler for fairly no reason.
I've been stuck on this implementation for a while so I definitely need an outsider perspective to see if things make sense!
Thanks,
Gabriele
Re: [PATCH v2 10/20] rv: Add Hybrid Automata monitor type
Quoted 23 lines · Gabriele Monaco
Alright, this is the simplest way I could think to represent clocks, still it seems confusing.
Let's start from guards (invariants are not special but I'm trying to do something to keep precision), the value of a clock is the time that passed since the last reset, as that's when the value is set to 0. Storing that timestamp and just comparing the difference whenever you need to know the valuation of said clock seemed the most straightforward thing to me. The clock representation doesn't include the guard constraint, that is validated during the event using the current valuation (i.e. now -
reset_time).What is important to note is that, at time of reset, you don't know what guard is going to fire, you may as well have a state with event A asking for clk<10 and event B requiring clk<20, also the guard may be in a later state and may depend on the path.
Invariants are bound to the form clk < N, and get "armed" when we reach the state, from there we know exactly when the invariant is going to expire, so we can save that (very important when using the timer wheel). Note here that the expiration isn't exactly N from now, but it's the valuation of the clock (reset might have occurred a few states earlier, see the nomiss case) subtracted by N, this is what the "passed" means later.
Quoted 2 lines
That said, I couldn't think of a simpler implementation but any suggestion is welcome, of course.
Ok, now things start to make sense. Thanks for the explanation.
At least to me, using the same variable to store different time values is a bit confusing.
Is it possible that we always store the timestamp of the last clock reset?
The invariant bound value (N) is fixed for each state, so we can have the bound value in ha_verify_invariants() instead. For example, the Python script can generate something like
static inline bool ha_verify_invariants(struct ha_monitor *ha_mon,
enum states curr_state, enum events event, enum states next_state, u64 time_ns)
{
if (curr_state == enqueued_stall)
return ha_check_invariant_jiffy(ha_mon, threshold_jiffies, time_ns);
return true;
}Is that possible?
Quoted 10 lines
Kinda, it would solve the problem for this specific subtraction, but racing handlers could still lead to problems although the subtraction is "correct".
Since this is the only time the env storage needs to be an
atomic_tand it's fairly rare (only complicated models require calling this function at all, others are happy with READ_ONCE/WRITE_ONCE) I didn't want to change the storage implementation for some perceived safety.I wrote that comment exactly to motivate why we aren't using
atomic_t, but I should probably reword that. Does this make sense to you?
I think if we always store the timestamp since last reset, we can get rid of this function. Let's see how that discussion go..
Quoted 6 lines
As mentioned before, this is true for the stall case, where the reset occurred when reaching the state with the invariant (passed is close to 0), if you look at the nomiss case, reset happens before being ready (its invariant would have passed close to 0), but the same invariant is enforced in running, here we will see a passed far from 0 and need to take that into account when setting the invariant.
Make sense, thanks!
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 10/20] rv: Add Hybrid Automata monitor type
Quoted 23 lines · Nam Cao
Ok, now things start to make sense. Thanks for the explanation.
At least to me, using the same variable to store different time values is a bit confusing.
Is it possible that we always store the timestamp of the last clock reset?
The invariant bound value (N) is fixed for each state, so we can have the bound value in
ha_verify_invariants()instead. For example, the Python script can generate something likestatic inline bool ha_verify_invariants(struct
ha_monitor*ha_mon, enum statescurr_state, enum events event,
enum statesnext_state, u64time_ns) {
if (curr_state==enqueued_stall)
returnha_check_invariant_jiffy(ha_mon, threshold_jiffies, time_ns);
return true;
}
Quoted 1 line
Is that possible?
Alright, that /should/ be possible, provided the value used to set invariants is constant or at least doesn't change until we leave the state.
This seems a fair assumption to make but doesn't stand for the throttle monitor, in that case I read the remaining runtime from the dl entity, that one is updated frequently, for instance when a task is throttled, it's negative, but this doesn't mean the invariant should expect time to be negative.
Runtime is consumed only when a task is running, so here I use an invariant set up on the /remaining/ runtime when reaching the running state, that's why also switch_in resets the clock (runtime is not replenished, but the runtime_left value doesn't need to be subtracted anything).
An alternative would be to have some sort of pause/resume operations on clocks, and a task would just pause the clock when preempted, but those operations are not backed up by theory and wouldn't really simplify the implementation (use 2 variables per clock or a single one and some hack to mark it as paused).
Again, there may be better ways, but I found this one the "simplest".
Does it makes sense or am I just crystallising to this implementation?
Thanks,
Gabriele
Quoted 16 lines
Quoted 4 lines
Kinda, it would solve the problem for this specific subtraction, but racing handlers could still lead to problems although the subtraction is "correct".
Quoted 8 lines
Since this is the only time the env storage needs to be an
atomic_tand it's fairly rare (only complicated models require calling this function at all, others are happy with READ_ONCE/WRITE_ONCE) I didn't want to change the storage
implementation for some perceived safety.I wrote that comment exactly to motivate why we aren't using
atomic_t, but I should probably reword that. Does this make sense to you?I think if we always store the timestamp since last reset, we can get rid of this function. Let's see how that discussion go..
Quoted 1 line
Re: [PATCH v2 10/20] rv: Add Hybrid Automata monitor type
Quoted 12 lines · Gabriele Monaco
Alright, that /should/ be possible, provided the value used to set invariants is constant or at least doesn't change until we leave the state.
This seems a fair assumption to make but doesn't stand for the throttle monitor, in that case I read the remaining runtime from the dl entity, that one is updated frequently, for instance when a task is throttled, it's negative, but this doesn't mean the invariant should expect time to be negative.Runtime is consumed only when a task is running, so here I use an invariant set up on the /remaining/ runtime when reaching the running state, that's why also
switch_inresets the clock (runtime is not replenished, but theruntime_leftvalue doesn't need to be subtracted anything).
Quoted 8 lines
An alternative would be to have some sort of pause/resume operations on clocks, and a task would just pause the clock when preempted, but those operations are not backed up by theory and wouldn't really simplify the implementation (use 2 variables per clock or a single one and some hack to mark it as paused).
Again, there may be better ways, but I found this one the "simplest".
Does it makes sense or am I just crystallising to this implementation?
Ok, now it makes sense.
I have been thinking about this in the past days, and didn't come up with anything better. Let's leave it be.
Nam
Gabriele Monaco
maintainerPATCH v2 11/20 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.
--- 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.51.0
Re: [PATCH v2 11/20] verification/rvgen: Allow spaces in and events strings
Quoted 6 lines · Gabriele Monaco
Currently 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.
I probably misunderstand something, but isn't the description misleading? After reading this description, I expect the patch to ignore spaces or something similar. But from my understanding, the script only allowed a single event, and this patch allows conditions as well.
Shouldn't this be squashed to the next patch?
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 11/20] verification/rvgen: Allow spaces in and events strings
Quoted 7 lines · Nam Cao
Quoted 5 lines · Gabriele Monaco
Currently 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).
Quoted 6 lines
Quoted 1 line
Adapt the parser logic to allow spaces in the event strings.
I probably misunderstand something, but isn't the description misleading? After reading this description, I expect the patch to ignore spaces or something similar. But from my understanding, the script only allowed a single event, and this patch allows conditions as well.
The script allows multiple events, all separated by \n, strictly speaking there is nothing saying spaces are not allowed in event names, but the parser breaks if there's any space.
This patch allows spaces in event names, conditions (separated by a ; ) are not supported yet.
Quoted 1 line
Shouldn't this be squashed to the next patch?
I kept it separated to avoid pushing too many changes in the next one, which mostly adds new functionality (and lines) instead of changing the current ones.
Apparently that didn't make it any clearer, and there isn't really any use case needing event names with spaces, so if it looks cleaner to you I can just squash it.
Thanks,
Gabriele
Nam Cao
Reviewed-byRe: [PATCH v2 11/20] verification/rvgen: Allow spaces in and events strings
Quoted 22 lines · Gabriele Monaco
Quoted 7 lines · Nam Cao
Quoted 5 lines · Gabriele Monaco
Currently 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).
Quoted 6 lines
Quoted 1 line
Adapt the parser logic to allow spaces in the event strings.
I probably misunderstand something, but isn't the description misleading? After reading this description, I expect the patch to ignore spaces or something similar. But from my understanding, the script only allowed a single event, and this patch allows conditions as well.
The script allows multiple events, all separated by \n, strictly speaking there is nothing saying spaces are not allowed in event names, but the parser breaks if there's any space.
This patch allows spaces in event names, conditions (separated by a ; ) are not supported yet.
Quoted 8 lines
Quoted 1 line
Shouldn't this be squashed to the next patch?
I kept it separated to avoid pushing too many changes in the next one, which mostly adds new functionality (and lines) instead of changing the current ones.
Apparently that didn't make it any clearer, and there isn't really any use case needing event names with spaces, so if it looks cleaner to you I can just squash it.
Nah, you can keep it. I was just confused. Now I looked again, it starts to make sense.
I am thinking about converting the entire thing to be ply-based (after we are done with this series). It should make things easier to follow. Would you object that?
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 11/20] verification/rvgen: Allow spaces in and events strings
Quoted 5 lines · Nam Cao
Nah, you can keep it. I was just confused. Now I looked again, it starts to make sense.
Reviewed-by Nam Cao <[email protected]>
Alright, thanks!
Quoted 3 lines
I am thinking about converting the entire thing to be ply-based (after we are done with this series). It should make things easier to follow. Would you object that?
I'm on board with that, I left out some other changes to the parser in light of a major refactoring. I'd just need to see how this thing works but it really seems the right thing to do.
Gabriele
Gabriele Monaco
maintainerPATCH v2 12/20 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.
--- tools/verification/rvgen/__main__.py | 8 +- tools/verification/rvgen/rvgen/automata.py | 141 +++++- tools/verification/rvgen/rvgen/dot2c.py | 49 ++ 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, 678 insertions(+), 14 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 +133 -8
199 lines not on this page · raw message
tools/verification/rvgen/rvgen/dot2c.py +49 -0
83 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.51.0
Re: [PATCH v2 12/20] verification/rvgen: Add support for Hybrid Automata
tools/verification/rvgen/rvgen/dot2c.py class Dot2c(Automata): · line 94
Quoted 2 lines · Gabriele Monaco
tools/verification/rvgen/rvgen/dot2c.py +2
-0+ if any(u in self.env_types.values() for u in ["ns", "us", "ms", "s"]): + buff.append("#define HA_CLK_NS")
That any() twisted my brain. Does the following work?
if not {"ns", "us", "ms", "s"}.isdisjoint(self.env_types.values())tools/verification/rvgen/rvgen/dot2k.py class dot2k(Monitor, Dot2c): · line 199
Quoted 7 lines
tools/verification/rvgen/rvgen/dot2k.py +7
-0+ match unit: + case "us": + value *= 1000 + case "ms": + value *= 1000000 + case "s": + value *= 1000000000
Use 10**9 instead, so that we don't have to count the zeroes.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 12/20] verification/rvgen: Add support for Hybrid Automata
Quoted 9 lines · Nam Cao
Quoted 3 lines · Gabriele Monaco
+ if any(u in
self.env_types.values()for u in ["ns", "us", "ms",
"s"]):
+buff.append("#define HA_CLK_NS")That
any()twisted my brain. Does the following work?if not {"ns", "us", "ms", "s"}.isdisjoint(self.env_types.values())
Yeah that should do, thanks for the suggestion!
Quoted 9 lines
tools/verification/rvgen/rvgen/dot2k.py class dot2k(Monitor, Dot2c): · line 199
Quoted 7 lines
tools/verification/rvgen/rvgen/dot2k.py +7
-0+ match unit: + case "us": + value *= 1000 + case "ms": + value *= 1000000 + case "s": + value *= 1000000000Use 10**9 instead, so that we don't have to count the zeroes.
Right, that's not C.. Will fix.
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v2 13/20 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
--- .../trace/rv/deterministic_automata.rst | 2 +- Documentation/trace/rv/hybrid_automata.rst | 340 ++++++++++++++++++ Documentation/trace/rv/index.rst | 1 + Documentation/trace/rv/monitor_synthesis.rst | 107 ++++++ 4 files changed, 449 insertions(+), 1 deletion(-) 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 +340 -0
340 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 +107 -0
119 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v2 13/20] Documentation/rv: Add documentation about hybrid automata
Quoted 50 lines · Gabriele Monaco
Describe theory and implementation of hybrid automata in the dedicated page
hybrid_automata.rst
Include a section on how to integrate a hybrid automaton inmonitor_synthesis.rst
Also remove a hanging $ indeterministic_automata.rstSigned-off-by Gabriele Monaco <[email protected]>--- .../trace/rv/deterministic_automata.rst | 2 +- Documentation/trace/rv/hybrid_automata.rst | 340 ++++++++++++++++++ Documentation/trace/rv/index.rst | 1 + Documentation/trace/rv/monitor_synthesis.rst | 107 ++++++ 4 files changed, 449 insertions(+), 1 deletion(-) create mode 100644 Documentation/trace/rv/hybrid_automata.rstDocumentation/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 +16
-0@@ -0,0 +1,340 @@ +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*.
This brings back bad memories from university..
Quoted 21 lines
Documentation/trace/rv/hybrid_automata.rst new file +21
-0+ +The set of all possible constraints *C(V)* is defined according to the +following grammar: + + g = v < c | v > c | v <= c | v >= c | v == c | v != c | g && g | true + +With v a variable in *V* and c a numerical value. + +We define the special case of hybrid automata whose variables grow with uniform +rates as timed automata. In this case, the variables are called clocks. +As the name implies, timed automata can be used to describe real time. +Additionally, clocks support another type of guard which always evaluates to true: + + reset(v) + +The reset constraint is used to set the value of a clock to 0. + +The set of invariant constraints *C'(V)* is a subset of *C(V)* including only +constraint of the form: + + g = v < c | true
Documentation/trace/rv/hybrid_automata.rst line 57
Quoted 10 lines
Documentation/trace/rv/hybrid_automata.rst new file +10
-0+ +This simplifies the implementation as a clock expiration is a necessary and +sufficient condition for the violation of invariants while still allowing more +complex constraints to be specified as guards. + +It is important to note that any valid hybrid automaton is a valid +deterministic automaton with additional guards and invariants. Those can only +further constrain what transitions are valid but it is not possible to define +transition functions starting from the same state in *X* and the same event in +*E* but ending up in different states in *X* based on the valuation of *V*.
Perhaps remove the double "valid". Usually people use the phrase "any valid A is a valid B" to say that B is a superset of A, but it is opposite here.
Quoted 128 lines
Documentation/trace/rv/hybrid_automata.rst new file +128
-0+ +Examples +-------- + +Wip as hybrid automaton +~~~~~~~~~~~~~~~~~~~~~~~ + +The 'wip' (wakeup in preemptive) example introduced as a deterministic automaton +can also be described as: + +- *X* = { ``any_thread_running`` } +- *E* = { ``sched_waking`` } +- *V* = { ``preemptive`` } +- x\ :subscript:`0` = ``any_thread_running`` +- X\ :subscript:`m` = {``any_thread_running``} +- *f* = + - *f*\ (``any_thread_running``, ``sched_waking``, ``preemptive==0``) = ``any_thread_running`` +- *i* = + - *i*\ (``any_thread_running``) = ``true`` + +Which can be represented graphically as:: + + | + | + v + #====================# sched_waking;preemptive==0 + H H ------------------------------+ + H any_thread_running H | + H H <-----------------------------+ + #====================# + +In this example, by using the preemptive state of the system as an environment +variable, we can assert this constraint on ``sched_waking`` without requiring +preemption events (as we would in a deterministic automaton), which can be +useful in case those events are not available or not reliable on the system. + +Since all the invariants in *i* are true, we can omit them from the representation. + +Stall model with guards (iteration 1) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +As a sample timed automaton we can define 'stall' as: + +- *X* = { ``dequeued``, ``enqueued``, ``running``} +- *E* = { ``enqueue``, ``dequeue``, ``switch_in``} +- *V* = { ``clk`` } +- x\ :subscript:`0` = ``dequeue`` +- X\ :subscript:`m` = {``dequeue``} +- *f* = + - *f*\ (``enqueued``, ``switch_in``, ``clk < threshold``) = ``running`` + - *f*\ (``running``, ``dequeue``) = ``dequeued`` + - *f*\ (``dequeued``, ``enqueue``, ``reset(clk)``) = ``enqueued`` +- *i* = *omitted as all true* + +Graphically represented as:: + + | + | + v + #============================# + H dequeued H <+ + #============================# | + | | + | enqueue; reset(clk) | + v | + +----------------------------+ | + | enqueued | | dequeue + +----------------------------+ | + | | + | switch_in; clk < threshold | + v | + +----------------------------+ | + | running | -+ + +----------------------------+ + +This model imposes that the time between when a task is enqueued (it becomes +runnable) and when the task gets to run must be lower than a certain threshold. +A failure in this model means that the task is starving. +One problem in using guards on the edges in this case is that the model will +not report a failure until the ``switch_in`` event occurs. This means that, +according to the model, it is valid for the task never to run. + +Stall model with invariants (iteration 2) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The first iteration isn't exactly what was intended, we can change the model as: + +- *X* = { ``dequeued``, ``enqueued``, ``running``} +- *E* = { ``enqueue``, ``dequeue``, ``switch_in``} +- *V* = { ``clk`` } +- x\ :subscript:`0` = ``dequeue`` +- X\ :subscript:`m` = {``dequeue``} +- *f* = + - *f*\ (``enqueued``, ``switch_in``) = ``running`` + - *f*\ (``running``, ``dequeue``) = ``dequeued`` + - *f*\ (``dequeued``, ``enqueue``, ``reset(clk)``) = ``enqueued`` +- *i* = + - *i*\ (``enqueued``) = ``clk < threshold`` + +Graphically:: + + | + | + v + #=========================# + H dequeued H <+ + #=========================# | + | | + | enqueue; reset(clk) | + v | + +-------------------------+ | + | enqueued | | + | clk < threshold | | dequeue + +-------------------------+ | + | | + | switch_in | + v | + +-------------------------+ | + | running | -+ + +-------------------------+ + +In this case, we moved the guard as an invariant to the ``enqueued`` state, +this means we not only forbid the occurrence of ``switch_in`` when ``clk`` is +past the threshold but also mark as invalid in case we are *still* in +``enqueued`` after the threshold. This model is effectively in an invalid state +as soon as a task is starving, rather than when the starving task finally runs. + +Hybrid Automaton in C
Documentation/trace/rv/hybrid_automata.rst line 195
Quoted 10 lines
Documentation/trace/rv/hybrid_automata.rst new file +10
-0+--------------------- + +The definition of hybrid automata in C is heavily based on the deterministic +automata one. Specifically, we add the set of environment variables and the +constraints (both guards on transitions and invariants on states) as follows. +This is a combination of both iterations of the stall example:: + + /* enum representation of X (set of states) to be used as index */ + enum states { + dequeued = 0,
I think you already removed this " = 0" in an earlier patch?
Quoted 57 lines
Documentation/trace/rv/hybrid_automata.rst new file +57
-0+ enqueued, + running, + state_max + }; + + #define INVALID_STATE state_max + + /* enum representation of E (set of events) to be used as index */ + enum events { + dequeue = 0, + enqueue, + switch_in, + event_max + }; + + /* enum representation of V (set of environment variables) to be used as index */ + enum envs { + clk = 0, + env_max, + env_max_stored = env_max + }; + + struct automaton { + char *state_names[state_max]; // X: the set of states + char *event_names[event_max]; // E: the finite set of events + char *env_names[env_max]; // V: the finite set of env vars + unsigned char function[state_max][event_max]; // f: transition function + unsigned char initial_state; // x_0: the initial state + bool final_states[state_max]; // X_m: the set of marked states + }; + + struct automaton aut = { + .state_names = { + "dequeued", + "enqueued", + "running" + }, + .event_names = { + "dequeue", + "enqueue", + "switch_in" + }, + .env_names = { + "clk" + }, + .function = { + { INVALID_STATE, enqueued, INVALID_STATE }, + { INVALID_STATE, INVALID_STATE, running }, + { dequeued, INVALID_STATE, INVALID_STATE }, + }, + .initial_state = dequeued, + .final_states = { 1, 0, 0 }, + }; + + static bool verify_constraint(enum states curr_state, enum events event, + enum states next_state) + {
Documentation/trace/rv/hybrid_automata.rst line 262
Quoted 10 lines
Documentation/trace/rv/hybrid_automata.rst new file +10
-0+ bool res = true; + + /* Validate guards as part of f */ + if (curr_state == enqueued && event == sched_switch_in) + res = get_env(clk) < threshold; + else if (curr_state == dequeued && event == sched_wakeup) + reset_env(clk); + + /* Validate invariants in i */ + if (next_state == curr_state || !res)
^^^^
indentation error ;)
Quoted 4 lines
Documentation/trace/rv/hybrid_automata.rst new file +4
-0+ return res; + if (next_state == enqueued) + ha_start_timer_jiffy(ha_mon, clk, threshold_jiffies); + else if (curr_state == enqueued)
Documentation/trace/rv/hybrid_automata.rst line 276
Quoted 10 lines
Documentation/trace/rv/hybrid_automata.rst new file +10
-0+ res = !ha_cancel_timer(ha_mon); + return res; + } + +The function ``verify_constraint``, here reported as simplified, checks guards, +performs resets and starts timers to validate invariants according to +specification. +Due to the complex nature of environment variables, the user needs to provide +functions to get and reset environment variables, although we provide some +helpers for common types (e.g. clocks with ns or jiffy granularity).
Is there theoretical reason that functions to get/set variables cannot be generated? Or you just do not have time for it yet?
Documentation/trace/rv/hybrid_automata.rst line 280
Quoted 4 lines
Documentation/trace/rv/hybrid_automata.rst new file +4
-0+Since invariants are only defined as clock expirations (e.g. *clk < +threshold*), the callback for timers armed when entering the state is in fact a +failure in the model and triggers a reaction. Leaving the state stops the timer +and checks for its expiration, in case the callback was late.
"callback for timers armed when entering the state is in fact a failure in the model and triggers a reaction." - I have problem parsing this sentence. How can "callback for timers" be armed? Or do you mean arming timers while entering a state is a failure in the model? What is it a failure?
Documentation/trace/rv/hybrid_automata.rst line 286
Quoted 5 lines
Documentation/trace/rv/hybrid_automata.rst new file +5
-0+It is important to note that timers introduce overhead, if the monitor has +several instances (e.g. all tasks) this can become an issue. +If the monitor is guaranteed to *eventually* leave the state and the incurred +delay to wait for the next event is acceptable, guards can be use to lower the +monitor's overhead.
How about having some sort of a "background task" which periodically verifies the invariants?
Quoted 30 lines
Documentation/trace/rv/hybrid_automata.rst new file +30
-0+For instance in the stall example, if we are only interested in reporting +stalled tasks, rather than reacting as soon as a task is stalled, and +``switch_in`` is eventually going to occur, we can use the first iteration. + +Graphviz .dot format +-------------------- + +Also the Graphviz representation of hybrid automata is an extension of the +deterministic automata one. Specifically, guards can be provided in the event +name separated by ``;``:: + + "state_start" -> "state_dest" [ label = "sched_waking;preemptible==0;reset(clk)" ]; + +Invariant can be specified in the state label (not the node name!) separated by ``\n``:: + + "enqueued" [label = "enqueued\nclk < threshold_jiffies"]; + +Constraints can be specified as valid C comparisons and allow spaces, the first +element of the comparison must be the clock while the second is a numerical or +parametrised value. Guards allow comparisons to be combined with boolean +operations (``&&`` and ``||``), resets must be separated from other constraints. + +This is the full example of the last version of the 'stall' model in DOT:: + + digraph state_automaton { + {node [shape = circle] "enqueued"}; + {node [shape = plaintext, style=invis, label=""] "__init_dequeued"}; + {node [shape = doublecircle] "dequeued"}; + {node [shape = circle] "running"}; + "__init_dequeued" -> "dequeued";
Documentation/trace/rv/hybrid_automata.rst line 326
Quoted 10 lines
Documentation/trace/rv/hybrid_automata.rst new file +10
-0+ "enqueued" [label = "enqueued\nclk < threshold_jiffies"]; + "running" [label = "running"]; + "dequeued" [label = "dequeued"]; + "enqueued" -> "running" [ label = "switch_in" ]; + "running" -> "dequeued" [ label = "dequeue" ]; + "dequeued" -> "enqueued" [ label = "enqueue;reset(clk)" ]; + { rank = min ; + "__init_dequeued"; + "dequeued"; + }
Btw, the last block (rank = min) doesn't seem to serve any purpose. But the last time I checked months ago, the parser explodes if it is removed, not sure if it still does now. But this is another reason that I would like a rewrite.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 13/20] Documentation/rv: Add documentation about hybrid automata
Quoted 10 lines · Nam Cao
Quoted 8 lines · Gabriele Monaco
Describe theory and implementation of hybrid automata in the dedicated page
hybrid_automata.rst
Include a section on how to integrate a hybrid automaton inmonitor_synthesis.rst
Also remove a hanging $ indeterministic_automata.rstSigned-off-by Gabriele Monaco <[email protected]>---
This brings back bad memories from university..
:')
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+It is important to note that any valid hybrid automaton is a valid +deterministic automatonPerhaps remove the double "valid". Usually people use the phrase "any valid A is a valid B" to say that B is a superset of A, but it is opposite here.
Alright, will do.
Quoted 7 lines
Documentation/trace/rv/hybrid_automata.rst line 195
Quoted 5 lines
Documentation/trace/rv/hybrid_automata.rst new file +5
-0+This is a combination of both iterations of the stall example:: + + /* enum representation of X (set of states) to be used as index */ + enum states { + dequeued = 0,I think you already removed this " = 0" in an earlier patch?
Right, missed that.
Quoted 4 lines
Documentation/trace/rv/hybrid_automata.rst line 262
Quoted 2 lines
Documentation/trace/rv/hybrid_automata.rst new file +2
-0+ /* Validate invariants in i */ + if (next_state == curr_state || !res)^^^^
indentation error ;)
Good catch.
Quoted 7 lines
Documentation/trace/rv/hybrid_automata.rst line 276
Quoted 4 lines
+Due to the complex nature of environment variables, the user needs to provide
Documentation/trace/rv/hybrid_automata.rst new file +2
-0+functions to get and reset environment variables, although we provide some +helpers for common types (e.g. clocks with ns or jiffy granularity).Is there theoretical reason that functions to get/set variables cannot be generated? Or you just do not have time for it yet?
Not theoretical but practical, the monitor cannot always define /what/ an environment variable is. In case of clocks (jiffy and ns) that's easy and the parser does in fact generate get and reset functions, the user only needs to specify the measure unit as explained somewhere else.
It is possible to add more exotic variables that don't follow common clock rules and need different get/reset definitions. Now, in practice, that may not happen with clocks (I cannot think of an alternative clock definition), but can happen for other variables. For instance if the variable describes the preempt count, the model cannot know in advance and the user will need to supply how to read that in the kernel (just like we do with tracepoints, although event names /might/ hint something).
As I get it, this isn't so clear so I should probably try and reword it.
I might just assume variables without unit but with a reset are, say, jiffy clocks and never expect manual definition of the reset function, but that might be misleading at times: e.g. if a user wants a ns clock but forgets the unit, the monitor would still build.
Quoted 12 lines
Quoted 7 lines
(quoted diff) +2
-0+Since invariants are only defined as clock expirations (e.g. *clk < +threshold*), the callback for timers armed when entering the state is infact a
+failure in the model and triggers a reaction. Leaving the state stops the timer
+and checks for its expiration, in case the callback was late."callback for timers armed when entering the state is in fact a failure in the model and triggers a reaction." - I have problem parsing this sentence. How can "callback for timers" be armed? Or do you mean arming timers while entering a state is a failure in the model? What is it a failure?
Right, that sentence doesn't make sense.
We arm a timer when entering the state, expiration of such timer is a failure. The timer is cancelled when leaving the state, so in fact leaving the state before the timer expiration is the only valid behaviour.
Quoted 10 lines
Quoted 7 lines
Documentation/trace/rv/hybrid_automata.rst new file +3
-0+It is important to note that timers introduce overhead, if the monitor has +several instances (e.g. all tasks) this can become an issue. +If the monitor is guaranteed to *eventually* leave the state and theincurred
+delay to wait for the next event is acceptable, guards can be use to lower the
+monitor's overhead.How about having some sort of a "background task" which periodically verifies the invariants?
I didn't update this part, but now timers can work also via timer wheel, which is cutting down costs by sacrificing some reactivity (not correctness though). I assume the background thread would be quite similar to what the timer wheel already does.
But I definitely need to mention this because the timer wheel is not as heavy as the hrtimers and its overhead is usually acceptable (unless proven otherwise for a specific monitor/workload, I'd say).
Quoted 15 lines
Quoted 15 lines
Documentation/trace/rv/hybrid_automata.rst new file +15
-0+This is the full example of the last version of the 'stall' model in DOT:: + + digraph state_automaton { + {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"]; + "enqueued" -> "running" [ label = "switch_in" ]; + "running" -> "dequeued" [ label = "dequeue" ]; + "dequeued" -> "enqueued" [ label = "enqueue;reset(clk)" ]; + { rank = min ;
Quoted 8 lines
Quoted 3 lines
+ "
__init_dequeued";
+ "dequeued";
+ }Btw, the last block (rank = min) doesn't seem to serve any purpose. But the last time I checked months ago, the parser explodes if it is removed, not sure if it still does now. But this is another reason that I would like a rewrite.
Mmh, that's automatically generated by Supremica and, I believe, in some models it's tuning a bit the position of nodes. Quite strange that the parser exploded, those lines should be completely ignored.. Still, we know the parser needs this big refactor.
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v2 14/20 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.
--- 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 | 146 +++++++++++++++++++ kernel/trace/rv/monitors/stall/stall.h | 64 ++++++++ kernel/trace/rv/monitors/stall/stall_trace.h | 19 +++ kernel/trace/rv/rv_trace.h | 1 + tools/verification/models/stall.dot | 20 +++ 12 files changed, 354 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,6 +16,7 @@ Runtime verification (rv) tool rv-mon-wip rv-mon-wwnr rv-mon-sched + rv-mon-stall .. only:: subproject and html
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 +146 -0
146 lines not on this page · raw message
kernel/trace/rv/monitors/stall/stall.h new file +64 -0
64 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 +20 -0
@@ -0,0 +1,20 @@ +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" -> "running" [ label = "sched_switch_in" ]; + "running" -> "dequeued" [ label = "sched_switch_wait" ]; + "dequeued" -> "enqueued" [ label = "sched_wakeup;reset(clk)" ]; + { rank = min ; + "__init_dequeued"; + "dequeued"; + } +}
Signature · 1 line
2.51.0
Re: [PATCH v2 14/20] rv: Add sample hybrid monitors stall
Quoted 1 line · Gabriele Monaco
+- Name: stall - wakeup in preemptive
^^^^^^^^^^^^^^^^^^^^
copy-paste mistake?Quoted 20 lines
+- Type: per-task hybrid automaton +- Author: Gabriele Monaco <[email protected]>Documentation/trace/rv/monitor_stall.rst new file +18
-0+ +Description +----------- + +The stalled task (stall) monitor is a sample per-task timed monitor that checks +if tasks are scheduled within a defined threshold after they are ready:: + + | + | + v + #==================================# + H dequeued H <+ + #==================================# | + | | + | sched_wakeup;reset(clk) | + v | + +----------------------------------+ | + | enqueued | |
Documentation/trace/rv/monitor_stall.rst line 34
Quoted 10 lines
Documentation/trace/rv/monitor_stall.rst new file +10
-0+ | clk < threshold_jiffies | | sched_switch_wait + +----------------------------------+ | + | | + | sched_switch_in | + sched_switch_in v | + sched_wakeup +----------------------------------+ | + +------------------ | | | + | | running | | + +-----------------> | | -+ + +----------------------------------+
I think this monitor does not detect if a task get preempted, but then never get scheduled again?
This sample monitor does not have to cover everything obviously, but I'm curious if I understand it correct.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 14/20] rv: Add sample hybrid monitors stall
Quoted 4 lines · Nam Cao
Quoted 1 line · Gabriele Monaco
+- Name: stall - wakeup in preemptive
^^^^^^^^^^^^^^^^^^^^
copy-paste mistake?
Damn, right..
Quoted 36 lines
Quoted 24 lines
+- Type: per-task hybrid automaton +- Author: Gabriele Monaco <[email protected]>Documentation/trace/rv/monitor_stall.rst new file +5
-0+ +Description +----------- + +The stalled task (stall) monitor is a sample per-task timed monitor thatchecks
Documentation/trace/rv/monitor_stall.rst new file +14
-0+if tasks are scheduled within a defined threshold after they are ready:: + + | + | + v + #==================================# + H dequeued H <+ + #==================================# | + | | + | sched_wakeup;reset(clk) | + v | + +----------------------------------+ | + | enqueued | | + | clk < threshold_jiffies | |
sched_switch_wait
+ +----------------------------------+ |Quoted 8 lines
+ | | + | sched_switch_in | + sched_switch_in v | + sched_wakeup +----------------------------------+ | + +------------------ | | | + | | running | | + +-----------------> | | -+ + +----------------------------------+
I think this monitor does not detect if a task get preempted, but then never get scheduled again?
Quoted 2 lines
This sample monitor does not have to cover everything obviously, but I'm curious if I understand it correct.
Yes, that's right. I think I could cover that scenario by just going back to enqueued and resetting when preempted. Since it's a simple change, it's probably something meaningful to do..
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v2 15/20 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]
--- 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
@@ -92,6 +91,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor, );// Add new monitors based on CONFIG_HA_MON_EVENTS_IMPLICIT here +#include <monitors/opid/opid_trace.h> #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.51.0
Re: [PATCH v2 15/20] rv: Convert the opid monitor to a hybrid automaton
Quoted 38 lines · Gabriele Monaco
Documentation/trace/rv/monitor_sched.rst +0
-38- | 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 | -+ | - +------------------+ | - | | - +-------------------------------------------------------+ -
Documentation/trace/rv/monitor_sched.rst Monitor opid · line 363
Quoted 10 lines
Documentation/trace/rv/monitor_sched.rst +10
-0+ + | + | + v + #=========# sched_need_resched;irq_off == 1 + H H sched_waking;irq_off == 1 && preempt_off == 1 + H any H ------------------------------------------------+ + H H | + H H <-----------------------------------------------+ + #=========#
Nice!
kernel/trace/rv/monitors/opid/opid.c line 32
Quoted 7 lines
kernel/trace/rv/monitors/opid/opid.c +7
-0+* If CONFIG_PREEMPTION is enabled, then the tracepoint itself disables +* preemption (adding one to the preempt_count). Since we are +* interested in the preempt_count at the time the tracepoint was +* hit, we consider 1 as still enabled. +*/ +if (IS_ENABLED (CONFIG_PREEMPTION )) +return (preempt_count () &PREEMPT_MASK ) >1 ;
FYI, there is plan to keep preemption enabled during tracepoint handling. So keep that in mind when this monitor breaks.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 15/20] rv: Convert the opid monitor to a hybrid automaton
Quoted 5 lines · Nam Cao
Quoted 5 lines
(quoted diff) +1
-0+ * If CONFIG_PREEMPTION is enabled, then the tracepointitself disables
(quoted diff) +1
-0+ * preemption (adding one to the preempt_count). Since weare
(quoted diff) +1
-0+ * interested in the preempt_count at the time the
Quoted 8 lines
kernel/trace/rv/monitors/opid/opid.c line 32
Quoted 5 lines
tracepoint was
kernel/trace/rv/monitors/opid/opid.c +4
-0+* hit, we consider 1 as still enabled. +*/ +if (IS_ENABLED (CONFIG_PREEMPTION )) +return (preempt_count () &PREEMPT_MASK ) >1 ;FYI, there is plan to keep preemption enabled during tracepoint handling. So keep that in mind when this monitor breaks.
Right, I've heard of it, thanks for the heads up. I'll adapt the monitors once that happens.
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v2 16/20 sched: Export hidden tracepoints to modules
In reply to Gabriele MonacoThe tracepoints sched_entry, sched_exit and sched_set_need_resched are not exported to tracefs as trace events, this allows only kernel code to access them. Helper modules like [1] can be used to still have the tracepoints available to ftrace for debugging purposes, but they do rely on the tracepoints being exported.
Export the 3 not exported tracepoints.
Note that sched_set_state is already exported as the macro is called from modules.
[1] - https://github.com/qais-yousef/sched_tp.git
--- kernel/sched/core.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/sched/core.c +3 -0
@@ -117,6 +117,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_util_est_cfs_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_util_est_se_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_update_nr_running_tp);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); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
Signature · 1 line
2.51.0
Steven Rostedt
maintainerRe: [PATCH v2 16/20] sched: Export hidden tracepoints to modules
Quoted 6 lines · On Fri, 19 Sep 2025 16:09:50 +0200 Gabriele Monaco <[email protected]> wrote:
The tracepoints
sched_entry,sched_exitandsched_set_need_reschedare not exported to tracefs as trace events, this allows only kernel code to access them. Helper modules like [1] can be used to still have the tracepoints available to ftrace for debugging purposes, but they do rely on the tracepoints being exported.
Quoted 7 lines
Export the 3 not exported tracepoints.
Note thatsched_set_stateis already exported as the macro is called from modules.[1] - https://github.com/qais-yousef/sched_tp.git
Signed-off-by Gabriele Monaco <[email protected]>
Note, for all the scheduler changes, we need an acked-by from the scheduler maintainers.
After you have acks and are satisfied with the code (hopefully someone else can review them), you can send me a pull request to be added into linux-next. I'll still run them through my own tests.
Which BTW, there should be a bunch of tests in:
tools/testing/selftests/verification/
(which doesn't yet exist).
-- Steve
Quoted 18 lines
--- kernel/sched/core.c | 3 +++ 1 file changed, 3 insertions(+)kernel/sched/core.c +3
-0@@ -117,6 +117,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_util_est_cfs_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_util_est_se_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_update_nr_running_tp);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); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
Gabriele Monaco
maintainerRe: [PATCH v2 16/20] sched: Export hidden tracepoints to modules
2025-09-19T15:36:50Z Steven Rostedt <[email protected]>:
Quoted 13 lines
Quoted 10 lines · On Fri, 19 Sep 2025 16:09:50 +0200 Gabriele Monaco <[email protected]> wrote:
The tracepoints
sched_entry,sched_exitandsched_set_need_reschedare not exported to tracefs as trace events, this allows only kernel code to access them. Helper modules like [1] can be used to still have the tracepoints available to ftrace for debugging purposes, but they do rely on the tracepoints being exported.Export the 3 not exported tracepoints.
Note thatsched_set_stateis already exported as the macro is called from modules.
Quoted 7 lines
Quoted 3 lines
[1] - https://github.com/qais-yousef/sched_tp.git
Signed-off-by Gabriele Monaco <[email protected]>Note, for all the scheduler changes, we need an acked-by from the scheduler maintainers.
Alright got it.
Quoted 2 lines
After you have acks and are satisfied with the code (hopefully someone else can review them), you can send me a pull request to be added into linux-next.
Usually Nam does a very good job reviewing them.
Quoted 7 lines
I'll still run them through my own tests.
Which BTW, there should be a bunch of tests in:
tools/testing/selftests/verification/(which doesn't yet exist).
Yeah that's the next thing in my imaginary list, or perhaps something inspired on what's done in rtla.
Thanks,
Gabriele
Quoted 22 lines
-- Steve
Quoted 18 lines
---
kernel/sched/core.c| 3 +++1 file changed, 3 insertions(+)kernel/sched/core.c +3
-0@@ -117,6 +117,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_util_est_cfs_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_util_est_se_tp);EXPORT_TRACEPOINT_SYMBOL_GPL (sched_update_nr_running_tp);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); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
Gabriele Monaco
maintainerPATCH v2 17/20 sched: Add deadline tracepoints
In reply to Gabriele MonacoAdd the following tracepoints:
* sched_dl_throttle(dl):
Called when a deadline entity is throttled
* sched_dl_replenish(dl):
Called when a deadline entity's runtime is replenished
* sched_dl_server_start(dl):
Called when a deadline server is started
* sched_dl_server_stop(dl, hard):
Called when a deadline server is stopped (hard) or put to idle waiting for the next period (!hard)
Those tracepoints can be useful to validate the deadline scheduler with RV and are not exported to tracefs.
--- include/trace/events/sched.h | 16 ++++++++++++++++ kernel/sched/core.c | 4 ++++ kernel/sched/deadline.c | 9 +++++++++ 3 files changed, 29 insertions(+)
include/trace/events/sched.h +16 -0
@@ -896,6 +896,22 @@ DECLARE_TRACE(sched_set_need_resched, TP_PROTO(struct task_struct *tsk, int cpu, int tif), TP_ARGS(tsk, cpu, tif)); +DECLARE_TRACE (sched_dl_throttle, + TP_PROTO(struct sched_dl_entity *dl, int cpu), +TP_ARGS (dl, cpu)); + +DECLARE_TRACE (sched_dl_replenish, + TP_PROTO(struct sched_dl_entity *dl, int cpu), +TP_ARGS (dl, cpu)); + +DECLARE_TRACE (sched_dl_server_start, + TP_PROTO(struct sched_dl_entity *dl, int cpu), +TP_ARGS (dl, cpu)); + +DECLARE_TRACE (sched_dl_server_stop, + TP_PROTO(struct sched_dl_entity *dl, int cpu, bool hard), +TP_ARGS (dl, cpu, hard)); +#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */
kernel/sched/core.c +4 -0
@@ -120,6 +120,10 @@ 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_dl_throttle_tp); +EXPORT_TRACEPOINT_SYMBOL_GPL (sched_dl_replenish_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);
kernel/sched/deadline.c +9 -0
@@ -742,6 +742,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)); }/*
@@ -852,6 +853,9 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)if (dl_time_before (dl_se->deadline,rq_clock (rq))) {printk_deferred_once ("sched: DL replenish lagged too much\n" );replenish_dl_new_period (dl_se, rq); + }else { +/* replenish_dl_new_period is also tracing */ +trace_sched_dl_replenish_tp (dl_se,cpu_of (rq)); }if (dl_se->dl_yielded)
@@ -1349,6 +1353,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_se->dl_throttled =1 ;if (dl_se->runtime >0 ) dl_se->runtime =0 ;
@@ -1482,6 +1487,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_se->dl_throttled =1 ;/* If requested, inform the user about runtime overruns. */
@@ -1592,6 +1598,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)if (!dl_server (dl_se) || dl_se->dl_server_active)return ; +trace_sched_dl_server_start_tp (dl_se,cpu_of (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))
@@ -1603,6 +1610,7 @@ 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), true);dequeue_dl_entity (dl_se,DEQUEUE_SLEEP );hrtimer_try_to_cancel (&dl_se->dl_timer); dl_se->dl_defer_armed =0 ;
@@ -1620,6 +1628,7 @@ static bool dl_server_stopped(struct sched_dl_entity *dl_se)return true; } +trace_sched_dl_server_stop_tp (dl_se,cpu_of (dl_se->rq), false); dl_se->dl_server_idle =1 ;return false; }
Signature · 1 line
2.51.0
Gabriele Monaco
maintainerPATCH v2 18/20 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).
--- include/linux/rv.h | 1 + include/rv/da_monitor.h | 323 +++++++++++++++++++++++++++++++++++++++- include/rv/ha_monitor.h | 5 +- 3 files changed, 323 insertions(+), 6 deletions(-)
include/linux/rv.h +1 -0
@@ -16,6 +16,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/bitops.h>
include/rv/da_monitor.h +318 -5
372 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.51.0
Re: [PATCH v2 18/20] rv: Add support for per-object monitors in DA/HA
include/rv/da_monitor.h static inline void da_monitor_destroy(void) · line 384
Quoted 9 lines · Gabriele Monaco
include/rv/da_monitor.h +9
-0+static inline struct da_monitor *da_create_storage (da_id_type id, +monitor_target target, +struct da_monitor *da_mon, +gfp_t flags) +{ +struct da_monitor_storage *mon_storage; + +if (da_mon) +return da_mon;
I think this 'if' should be moved to da_create_conditional() instead, because the "conditional" part should be implemented in the function whose name includes "conditional". I think that would make the code easier to follow, because one would already have a good guess what the function does without looking into the details.
include/rv/da_monitor.h static inline bool da_handle_start_run_event(struct task_struct *tsk, · line 811
Quoted 10 lines
include/rv/da_monitor.h +10
-0+static inline bool da_handle_start_event (da_id_type id,monitor_target target, +enum events event) +{ +struct da_monitor *da_mon; + +if (!da_monitor_enabled ()) +return 0 ; +guard (rcu)(); + da_mon =da_get_monitor (id, target); + da_mon =da_monitor_start_hook (id, target, da_mon);
Do you plan this da_monitor_start_hook() macro to do anything other than storage preparation? If not, perhaps it is better to name it da_monitor_prepare_storage() or something like that, so that this is easier to follow.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 18/20] rv: Add support for per-object monitors in DA/HA
Quoted 17 lines · Nam Cao
include/rv/da_monitor.h static inline void da_monitor_destroy(void) · line 384
Quoted 10 lines · Gabriele Monaco
include/rv/da_monitor.h +3
-0+static inline struct da_monitor *da_create_storage (da_id_type id, + monitor_target target, + struct da_monitor
*da_mon,include/rv/da_monitor.h +6
-0+ gfp_t flags) +{ +struct da_monitor_storage *mon_storage; + +if (da_mon) +return da_mon;I think this 'if' should be moved to
da_create_conditional()instead, because the "conditional" part should be implemented in the function whose name includes "conditional". I think that would make the code easier to follow, because one would already have a good guess what the function does without looking into the details.
I get this is confusing and poorly documented, also the _conditional function is not more conditional than the other, so I'd really need to rethink the name (if it really needs to stay).
The main purpose of the functions under da_monitor_start_hook is to return a (possibly new) storage, it's perfectly possible, even likely, that the da_mon is not null, in such case we don't do any further allocation.
Ignoring the vagueness of the name, the two implementations of this hook are to call an allocation (yes, always conditionally) or just assign the target to a pre-allocated storage.
Your suggestion of da_monitor_prepare_storage might fit both descriptions.
In fact, having something like kmalloc_nolock (if it works as I expect it would) might save this gymnastics as we may not even care about pre-allocating, I'm going to try it out and perhaps re-think this entire mess.
Quoted 8 lines
Quoted 8 lines
+static inline bool da_handle_start_event(da_id_type id,
monitor_targettarget,include/rv/da_monitor.h +6
-0+ enum events event) +{ +struct da_monitor *da_mon; + +if (!da_monitor_enabled ()) +return 0 ;
Quoted 8 lines
include/rv/da_monitor.h static inline bool da_handle_start_run_event(struct task_struct *tsk, · line 811
Quoted 3 lines
include/rv/da_monitor.h +3
-0+guard (rcu)(); + da_mon =da_get_monitor (id, target); + da_mon =da_monitor_start_hook (id, target, da_mon);Do you plan this
da_monitor_start_hook()macro to do anything other than storage preparation? If not, perhaps it is better to name itda_monitor_prepare_storage()or something like that, so that this is easier to follow.
That's a good point, this appears already only in per-object code, the general name is really just pointless.
Thanks,
Gabriele
Re: [PATCH v2 18/20] rv: Add support for per-object monitors in DA/HA
Quoted 4 lines · Gabriele Monaco
Ignoring the vagueness of the name, the two implementations of this hook are to call an allocation (yes, always conditionally) or just assign the target to a pre-allocated storage.
Your suggestion ofda_monitor_prepare_storagemight fit both descriptions.
Now that I have grasped (or at least I think so) the patches, it is not that important to me anymore. But still, having function names which precisely describe what they do would help new people understand the code.
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 18/20] rv: Add support for per-object monitors in DA/HA
Quoted 9 lines · Nam Cao
Quoted 4 lines · Gabriele Monaco
Ignoring the vagueness of the name, the two implementations of this hook are to call an allocation (yes, always conditionally) or just assign the target to a pre-allocated storage.
Your suggestion ofda_monitor_prepare_storagemight fit both descriptions.Now that I have grasped (or at least I think so) the patches, it is not that important to me anymore. But still, having function names which precisely describe what they do would help new people understand the code.
Agree, I'm going to use more meaningful function names. Apparently the kmalloc_nolock is still getting lockdep complain on RT kernels so I'm going to keep this skip-preallocation logic as it is, hopefully just clearer.
Thanks,
Gabriele
Gabriele Monaco
maintainerPATCH v2 19/20 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, the da_get_id() function and other modifications required to create per-object monitors.
--- tools/verification/rvgen/rvgen/dot2k.py | 6 ++++++ tools/verification/rvgen/rvgen/generator.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
tools/verification/rvgen/rvgen/dot2k.py +6 -0
@@ -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("\tda_%s(id, t, %s%s);" % (handle, event, self.enum_suffix)); else: buff.append("\tda_%s(%s%s);" % (handle, event, self.enum_suffix)); buff.append("}")
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.51.0
Re: [PATCH v2 19/20] verification/rvgen: Add support for per-obj monitors
Quoted 9 lines · Gabriele Monaco
The 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_targettype, theda_get_id()function and other modifications required to create per-object monitors.Signed-off-by Gabriele Monaco <[email protected]>
Gabriele Monaco
maintainerPATCH v2 20/20 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
--- Documentation/trace/rv/index.rst | 1 + Documentation/trace/rv/monitor_deadline.rst | 151 ++++++++++ kernel/trace/rv/Kconfig | 5 + kernel/trace/rv/Makefile | 3 + kernel/trace/rv/monitors/deadline/Kconfig | 10 + kernel/trace/rv/monitors/deadline/deadline.c | 35 +++ kernel/trace/rv/monitors/deadline/deadline.h | 200 +++++++++++++ kernel/trace/rv/monitors/nomiss/Kconfig | 15 + kernel/trace/rv/monitors/nomiss/nomiss.c | 283 ++++++++++++++++++ kernel/trace/rv/monitors/nomiss/nomiss.h | 130 ++++++++ .../trace/rv/monitors/nomiss/nomiss_trace.h | 19 ++ kernel/trace/rv/monitors/throttle/Kconfig | 15 + kernel/trace/rv/monitors/throttle/throttle.c | 253 ++++++++++++++++ kernel/trace/rv/monitors/throttle/throttle.h | 118 ++++++++ .../rv/monitors/throttle/throttle_trace.h | 19 ++ kernel/trace/rv/rv_trace.h | 2 + tools/verification/models/deadline/nomiss.dot | 39 +++ .../verification/models/deadline/throttle.dot | 44 +++ 18 files changed, 1342 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 +151 -0
151 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 +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/rv.h> + +#define MODULE_NAME "deadline" + +#include "deadline.h" + +struct rv_monitor rv_deadline = { + .name ="deadline" , + .description ="container for several deadline scheduler specifications." , + .enable =NULL , + .disable =NULL , + .reset =NULL , + .enabled =0 , +}; + +static int __init register_deadline (void ) +{ +return rv_register_monitor (&rv_deadline,NULL ); +} + +static void __exit unregister_deadline(void) +{ +rv_unregister_monitor (&rv_deadline); +} + +module_init (register_deadline); +module_exit (unregister_deadline); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Gabriele Monaco <[email protected]>" ); +MODULE_DESCRIPTION ("deadline: container for several deadline scheduler specifications." );
kernel/trace/rv/monitors/deadline/deadline.h new file +200 -0
200 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 +283 -0
283 lines not on this page · raw message
kernel/trace/rv/monitors/nomiss/nomiss.h new file +130 -0
130 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 +253 -0
253 lines not on this page · raw message
kernel/trace/rv/monitors/throttle/throttle.h new file +118 -0
118 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 +39 -0
@@ -0,0 +1,39 @@ +digraph state_automaton { + center = true; + size = "7,11"; + {node [shape = circle] "idle"}; + {node [shape = plaintext, style=invis, label=""] "__init_ready"}; + {node [shape = doublecircle] "ready"}; + {node [shape = circle] "ready"}; + {node [shape = circle] "running"}; + {node [shape = circle] "sleeping"}; + {node [shape = circle] "throttled"}; + "__init_ready" -> "ready"; + "idle" [label = "idle"]; + "idle" -> "idle" [ label = "dl_server_idle" ]; + "idle" -> "ready" [ label = "dl_replenish;reset(clk)" ]; + "idle" -> "running" [ label = "sched_switch_in" ]; + "idle" -> "throttled" [ label = "dl_throttle" ]; + "ready" [label = "ready\nclk < DEADLINE_NS()", color = green3]; + "ready" -> "idle" [ label = "dl_server_idle" ]; + "ready" -> "ready" [ label = "sched_wakeup\ndl_server_start\ndl_replenish;reset(clk)" ]; + "ready" -> "running" [ label = "sched_switch_in" ]; + "ready" -> "sleeping" [ label = "dl_server_stop" ]; + "ready" -> "throttled" [ label = "dl_throttle;is_defer == 1" ]; + "running" [label = "running\nclk < DEADLINE_NS()"]; + "running" -> "idle" [ label = "dl_server_idle" ]; + "running" -> "running" [ label = "dl_replenish;reset(clk)\nsched_switch_in\nsched_wakeup" ]; + "running" -> "sleeping" [ label = "sched_switch_suspend\ndl_server_stop" ]; + "running" -> "throttled" [ label = "dl_throttle" ]; + "sleeping" [label = "sleeping"]; + "sleeping" -> "ready" [ label = "sched_wakeup\ndl_replenish;reset(clk)" ]; + "sleeping" -> "sleeping" [ label = "dl_server_idle\ndl_server_start" ]; + "sleeping" -> "throttled" [ label = "dl_throttle;is_constr_dl == 1" ]; + "throttled" [label = "throttled"]; + "throttled" -> "ready" [ label = "dl_replenish;reset(clk)" ]; + "throttled" -> "throttled" [ label = "sched_switch_suspend\nsched_wakeup\ndl_server_start\ndl_server_idle\ndl_throttle" ]; + { rank = min ; + "__init_ready"; + "ready"; + } +}
tools/verification/models/deadline/throttle.dot new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v2 20/20] rv: Add deadline monitors
kernel/trace/rv/monitors/deadline/deadline.h line 15
Quoted 9 lines · Gabriele Monaco
kernel/trace/rv/monitors/deadline/deadline.h new file +9
-0+/* +* Dummy values if not available +*/ +#ifndef __NR_sched_setscheduler +#define __NR_sched_setscheduler -1 +#endif +#ifndef __NR_sched_setattr +#define __NR_sched_setattr -2 +#endif
You can use __COUNTER__ intead, would make it easier to add to or remove from this list later on.
kernel/trace/rv/monitors/nomiss/nomiss.c line 206
Quoted 13 lines
kernel/trace/rv/monitors/nomiss/nomiss.c new file +13
-0+static void handle_syscall (void *data,struct pt_regs *regs,long id) +{ +struct task_struct *p; +int new_policy =-1 ; + + new_policy =extract_params (regs, id, &p); +if (new_policy <0 || new_policy == p->policy) +return ; +if (p->policy ==SCHED_DEADLINE ) +da_reset (EXPAND_ID (&p->dl,DL_TASK )); +else if (new_policy ==SCHED_DEADLINE ) +da_create_conditional (EXPAND_ID (&p->dl,DL_TASK ),GFP_NOWAIT ); +}
What if the syscall fails for any reason? Wouldn't the monitor stores incorrect information?
Nam
Gabriele Monaco
maintainerRe: [PATCH v2 20/20] rv: Add deadline monitors
Quoted 13 lines · Nam Cao
kernel/trace/rv/monitors/deadline/deadline.h line 15
Quoted 9 lines · Gabriele Monaco
kernel/trace/rv/monitors/deadline/deadline.h new file +9
-0+/* +* Dummy values if not available +*/ +#ifndef __NR_sched_setscheduler +#define __NR_sched_setscheduler -1 +#endif +#ifndef __NR_sched_setattr +#define __NR_sched_setattr -2 +#endif You can use
__COUNTER__intead, would make it easier to add to or remove from this list later on.
Right, good point.
Quoted 9 lines
Quoted 9 lines
kernel/trace/rv/monitors/nomiss/nomiss.c new file +9
-0+static void handle_syscall (void *data,struct pt_regs *regs,long id) +{ +struct task_struct *p; +int new_policy =-1 ; + + new_policy =extract_params (regs, id, &p); +if (new_policy <0 || new_policy == p->policy) +return ; +if (p->policy ==SCHED_DEADLINE )
Quoted 8 lines
Quoted 5 lines
kernel/trace/rv/monitors/nomiss/nomiss.c new file +3
-0+da_reset (EXPAND_ID (&p->dl,DL_TASK )); + else if (new_policy == SCHED_DEADLINE) + da_create_conditional(EXPAND_ID(&p->dl, DL_TASK),
GFP_NOWAIT);
+}What if the syscall fails for any reason? Wouldn't the monitor stores incorrect information?
Yes, that could happen, this seems an issue only in the throttle monitor when failing a DEADLINE->NORMAL, other cases are at most resetting the monitor.
In this case, the monitor is really saying: a deadline task is no longer deadline, so its runtime should be counted as fair server. If the syscall does fail, we are assuming the fair server as armed (not running) for a bit more.
Here I couldn't find a nice way to handle this: if I attach only to the syscall return, I see if it succeeded but I lost the previous policy, attaching to both (and keep a per-cpu storage just for this process) seems a bit overcomplicated. I see this can potentially lead to errors in the monitor, but I'm not sure the extra complexity is worth it here, considering this failure might only happen if a user really makes wrong calls.
I tried to avoid creating a new tracepoint on a successful policy change.
What do you think?
Thanks,
Gabriele
Quoted 3 lines · Gabriele Monaco
This RFC contains several related changes, I'm sending them together to give the full picture and get early feedback but I'm probably going to submit some of them separately.
I'm done reviewing the series, sorry for taking forever (I have other urgent stuffs going on, and this series is not easy to digest).
Overall looks decent. Thank you for this work!
Nam
Gabriele Monaco
maintainerQuoted 9 lines · Nam Cao
Quoted 3 lines · Gabriele Monaco
This RFC contains several related changes, I'm sending them together to give the full picture and get early feedback but I'm probably going to submit some of them separately.
I'm done reviewing the series, sorry for taking forever (I have other urgent stuffs going on, and this series is not easy to digest).
Overall looks decent. Thank you for this work!
Thanks, that was really appreciated! This is quite a fat series to review, I am well aware of that!
Gabriele