summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-02-12 14:08:49 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2026-02-12 14:08:49 -0800
commitf75c03a761b737c4ee94c17f154967261f00ab4d (patch)
tree04d1708f029183a7656f8ef43d970ffadb1fb336 /include
parenta67594c977234b0ad6887202740e9e8b9821473a (diff)
parent403faa575738a7f92267b2ca2ee56cd1b9373078 (diff)
Merge tag 'trace-rv-v7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull runtime verifier updates from Steven Rostedt: - Refactor da_monitor to minimize macros Complete refactor of da_monitor.h to reduce reliance on macros generating functions. Use generic static functions and uses the preprocessor only when strictly necessary (e.g. for tracepoint handlers). The change essentially relies on functions with generic names (e.g. da_handle) instead of monitor-specific as well adding the need to define constant (e.g. MONITOR_NAME, MONITOR_TYPE) before including the header rather than calling macros that would define functions. Also adapt monitors and documentation accordingly. - Cleanup DA code generation scripts Clean up functions in dot2c removing reimplementations of trivial library functions (__buff_to_string) and removing some other unused intermediate steps. - Annotate functions with types in the rvgen python scripts - Remove superfluous assignments and cleanup generated code The rvgen scripts generate a superfluous assignment to 0 for enum variables and don't add commas to the last elements, which is against the kernel coding standards. Change the generation process for a better compliance and slightly simpler logic. - Remove superfluous declarations from generated code The monitor container source files contained a declaration and a definition for the rv_monitor variable. The former is superfluous and was removed. - Fix reference to outdated documentation s/da_monitor_synthesis.rst/monitor_synthesis.rst in comment in da_monitor.h * tag 'trace-rv-v7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: rv: Fix documentation reference in da_monitor.h verification/rvgen: Remove unused variable declaration from containers verification/dot2c: Remove superfluous enum assignment and add last comma verification/dot2c: Remove __buff_to_string() and cleanup verification/rvgen: Annotate DA functions with types verification/rvgen: Adapt dot2k and templates after refactoring da_monitor.h Documentation/rv: Adapt documentation after da_monitor refactoring rv: Cleanup da_monitor after refactor rv: Refactor da_monitor to minimise macros
Diffstat (limited to 'include')
-rw-r--r--include/linux/rv.h4
-rw-r--r--include/rv/automata.h132
-rw-r--r--include/rv/da_monitor.h887
3 files changed, 499 insertions, 524 deletions
diff --git a/include/linux/rv.h b/include/linux/rv.h
index 92fd467547e7..58774eb3aecf 100644
--- a/include/linux/rv.h
+++ b/include/linux/rv.h
@@ -10,6 +10,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/array_size.h>
#include <linux/bitops.h>
diff --git a/include/rv/automata.h b/include/rv/automata.h
index eb9e636809a0..4a4eb40cf09a 100644
--- a/include/rv/automata.h
+++ b/include/rv/automata.h
@@ -6,70 +6,76 @@
* 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
+
+#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)
+
+/*
+ * model_get_state_name - return the (string) name of the given state
+ */
+static char *model_get_state_name(enum states state)
+{
+ if ((state < 0) || (state >= STATE_MAX))
+ return "INVALID";
+
+ return RV_AUTOMATON_NAME.state_names[state];
+}
+
+/*
+ * model_get_event_name - return the (string) name of the given event
+ */
+static char *model_get_event_name(enum events event)
+{
+ if ((event < 0) || (event >= EVENT_MAX))
+ return "INVALID";
+
+ return RV_AUTOMATON_NAME.event_names[event];
+}
+
/*
- * DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata
+ * model_get_initial_state - return the automaton's initial state
+ */
+static inline enum states model_get_initial_state(void)
+{
+ return RV_AUTOMATON_NAME.initial_state;
+}
+
+/*
+ * model_get_next_state - process an automaton event occurrence
*
- * 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'.
+ * Given the current state (curr_state) and the event (event), returns
+ * the next state, or INVALID_STATE in case of error.
+ */
+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;
+
+ if ((event < 0) || (event >= EVENT_MAX))
+ return INVALID_STATE;
+
+ return RV_AUTOMATON_NAME.function[curr_state][event];
+}
+
+/*
+ * model_is_final_state - check if the given state is a final state
*/
-#define DECLARE_AUTOMATA_HELPERS(name, type) \
- \
-/* \
- * model_get_state_name_##name - return the (string) name of the given state \
- */ \
-static char *model_get_state_name_##name(enum states_##name state) \
-{ \
- if ((state < 0) || (state >= state_max_##name)) \
- return "INVALID"; \
- \
- return automaton_##name.state_names[state]; \
-} \
- \
-/* \
- * model_get_event_name_##name - return the (string) name of the given event \
- */ \
-static char *model_get_event_name_##name(enum events_##name event) \
-{ \
- if ((event < 0) || (event >= event_max_##name)) \
- return "INVALID"; \
- \
- return automaton_##name.event_names[event]; \
-} \
- \
-/* \
- * model_get_initial_state_##name - return the automaton's initial state \
- */ \
-static inline type model_get_initial_state_##name(void) \
-{ \
- return automaton_##name.initial_state; \
-} \
- \
-/* \
- * model_get_next_state_##name - process an automaton event occurrence \
- * \
- * 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_##name(enum states_##name curr_state, \
- enum events_##name event) \
-{ \
- if ((curr_state < 0) || (curr_state >= state_max_##name)) \
- return INVALID_STATE; \
- \
- if ((event < 0) || (event >= event_max_##name)) \
- return INVALID_STATE; \
- \
- return automaton_##name.function[curr_state][event]; \
-} \
- \
-/* \
- * model_is_final_state_##name - check if the given state is a final state \
- */ \
-static inline bool model_is_final_state_##name(enum states_##name state) \
-{ \
- if ((state < 0) || (state >= state_max_##name)) \
- return 0; \
- \
- return automaton_##name.final_states[state]; \
+static inline bool model_is_final_state(enum states state)
+{
+ if ((state < 0) || (state >= STATE_MAX))
+ return 0;
+
+ return RV_AUTOMATON_NAME.final_states[state];
}
+
+#endif
diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h
index 0cef64366538..db11d41bb438 100644
--- a/include/rv/da_monitor.h
+++ b/include/rv/da_monitor.h
@@ -8,90 +8,91 @@
* The dot2k tool is available at tools/verification/dot2k/
*
* For further information, see:
- * Documentation/trace/rv/da_monitor_synthesis.rst
+ * Documentation/trace/rv/monitor_synthesis.rst
*/
+#ifndef _RV_DA_MONITOR_H
+#define _RV_DA_MONITOR_H
+
#include <rv/automata.h>
#include <linux/rv.h>
+#include <linux/stringify.h>
#include <linux/bug.h>
#include <linux/sched.h>
+static struct rv_monitor rv_this;
+
+static void react(enum states curr_state, enum events event)
+{
+ rv_react(&rv_this,
+ "rv: monitor %s does not allow event %s on state %s\n",
+ __stringify(MONITOR_NAME),
+ model_get_event_name(event),
+ model_get_state_name(curr_state));
+}
+
+/*
+ * da_monitor_reset - reset a monitor and setting it to init state
+ */
+static inline void da_monitor_reset(struct da_monitor *da_mon)
+{
+ da_mon->monitoring = 0;
+ da_mon->curr_state = model_get_initial_state();
+}
+
+/*
+ * da_monitor_start - start monitoring
+ *
+ * The monitor will ignore all events until monitoring is set to true. This
+ * function needs to be called to tell the monitor to start monitoring.
+ */
+static inline void da_monitor_start(struct da_monitor *da_mon)
+{
+ da_mon->curr_state = model_get_initial_state();
+ da_mon->monitoring = 1;
+}
+
/*
- * Generic helpers for all types of deterministic automata monitors.
- */
-#define DECLARE_DA_MON_GENERIC_HELPERS(name, type) \
- \
-static void react_##name(type curr_state, type event) \
-{ \
- rv_react(&rv_##name, \
- "rv: monitor %s does not allow event %s on state %s\n", \
- #name, \
- model_get_event_name_##name(event), \
- model_get_state_name_##name(curr_state)); \
-} \
- \
-/* \
- * da_monitor_reset_##name - reset a monitor and setting it to init state \
- */ \
-static inline void da_monitor_reset_##name(struct da_monitor *da_mon) \
-{ \
- da_mon->monitoring = 0; \
- da_mon->curr_state = model_get_initial_state_##name(); \
-} \
- \
-/* \
- * da_monitor_start_##name - start monitoring \
- * \
- * The monitor will ignore all events until monitoring is set to true. This \
- * function needs to be called to tell the monitor to start monitoring. \
- */ \
-static inline void da_monitor_start_##name(struct da_monitor *da_mon) \
-{ \
- da_mon->curr_state = model_get_initial_state_##name(); \
- da_mon->monitoring = 1; \
-} \
- \
-/* \
- * da_monitoring_##name - returns true if the monitor is processing events \
- */ \
-static inline bool da_monitoring_##name(struct da_monitor *da_mon) \
-{ \
- return da_mon->monitoring; \
-} \
- \
-/* \
- * da_monitor_enabled_##name - checks if the monitor is enabled \
- */ \
-static inline bool da_monitor_enabled_##name(void) \
-{ \
- /* global switch */ \
- if (unlikely(!rv_monitoring_on())) \
- return 0; \
- \
- /* monitor enabled */ \
- if (unlikely(!rv_##name.enabled)) \
- return 0; \
- \
- return 1; \
-} \
- \
-/* \
- * da_monitor_handling_event_##name - checks if the monitor is ready to handle events \
- */ \
-static inline bool da_monitor_handling_event_##name(struct da_monitor *da_mon) \
-{ \
- \
- if (!da_monitor_enabled_##name()) \
- return 0; \
- \
- /* monitor is actually monitoring */ \
- if (unlikely(!da_monitoring_##name(da_mon))) \
- return 0; \
- \
- return 1; \
+ * da_monitoring - returns true if the monitor is processing events
+ */
+static inline bool da_monitoring(struct da_monitor *da_mon)
+{
+ return da_mon->monitoring;
}
/*
+ * da_monitor_enabled - checks if the monitor is enabled
+ */
+static inline bool da_monitor_enabled(void)
+{
+ /* global switch */
+ if (unlikely(!rv_monitoring_on()))
+ return 0;
+
+ /* monitor enabled */
+ if (unlikely(!rv_this.enabled))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * da_monitor_handling_event - checks if the monitor is ready to handle events
+ */
+static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
+{
+ if (!da_monitor_enabled())
+ return 0;
+
+ /* monitor is actually monitoring */
+ if (unlikely(!da_monitoring(da_mon)))
+ return 0;
+
+ 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.
@@ -100,38 +101,39 @@ static inline bool da_monitor_handling_event_##name(struct da_monitor *da_mon)
* warn and reset the monitor if it runs out of retries. The monitor should be
* able to handle various orders.
*/
-#define DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type) \
- \
-static inline bool \
-da_event_##name(struct da_monitor *da_mon, enum events_##name event) \
-{ \
- enum states_##name 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_##name(curr_state, event); \
- if (next_state == INVALID_STATE) { \
- react_##name(curr_state, event); \
- trace_error_##name(model_get_state_name_##name(curr_state), \
- model_get_event_name_##name(event)); \
- return false; \
- } \
- if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { \
- trace_event_##name(model_get_state_name_##name(curr_state), \
- model_get_event_name_##name(event), \
- model_get_state_name_##name(next_state), \
- model_is_final_state_##name(next_state)); \
- return true; \
- } \
- } \
- \
- trace_rv_retries_error(#name, model_get_event_name_##name(event)); \
- pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) \
- " retries reached for event %s, resetting monitor %s", \
- model_get_event_name_##name(event), #name); \
- return false; \
-} \
+static inline bool da_event(struct da_monitor *da_mon, enum events event)
+{
+ enum states curr_state, next_state;
+
+ curr_state = READ_ONCE(da_mon->curr_state);
+ for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) {
+ next_state = model_get_next_state(curr_state, event);
+ if (next_state == INVALID_STATE) {
+ react(curr_state, event);
+ CONCATENATE(trace_error_, MONITOR_NAME)(
+ model_get_state_name(curr_state),
+ model_get_event_name(event));
+ return false;
+ }
+ if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) {
+ CONCATENATE(trace_event_, MONITOR_NAME)(
+ model_get_state_name(curr_state),
+ model_get_event_name(event),
+ model_get_state_name(next_state),
+ model_is_final_state(next_state));
+ return true;
+ }
+ }
+
+ trace_rv_retries_error(__stringify(MONITOR_NAME), model_get_event_name(event));
+ pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS)
+ " retries reached for event %s, resetting monitor %s",
+ model_get_event_name(event), __stringify(MONITOR_NAME));
+ return false;
+}
+
+#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* Event handler for per_task monitors.
*
@@ -139,395 +141,358 @@ da_event_##name(struct da_monitor *da_mon, enum events_##name event) \
* warn and reset the monitor if it runs out of retries. The monitor should be
* able to handle various orders.
*/
-#define DECLARE_DA_MON_MODEL_HANDLER_PER_TASK(name, type) \
- \
-static inline bool da_event_##name(struct da_monitor *da_mon, struct task_struct *tsk, \
- enum events_##name event) \
-{ \
- enum states_##name 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_##name(curr_state, event); \
- if (next_state == INVALID_STATE) { \
- react_##name(curr_state, event); \
- trace_error_##name(tsk->pid, \
- model_get_state_name_##name(curr_state), \
- model_get_event_name_##name(event)); \
- return false; \
- } \
- if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { \
- trace_event_##name(tsk->pid, \
- model_get_state_name_##name(curr_state), \
- model_get_event_name_##name(event), \
- model_get_state_name_##name(next_state), \
- model_is_final_state_##name(next_state)); \
- return true; \
- } \
- } \
- \
- trace_rv_retries_error(#name, model_get_event_name_##name(event)); \
- pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) \
- " retries reached for event %s, resetting monitor %s", \
- model_get_event_name_##name(event), #name); \
- return false; \
+
+static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
+ enum events event)
+{
+ enum states curr_state, next_state;
+
+ curr_state = READ_ONCE(da_mon->curr_state);
+ for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) {
+ next_state = model_get_next_state(curr_state, event);
+ if (next_state == INVALID_STATE) {
+ react(curr_state, event);
+ CONCATENATE(trace_error_, MONITOR_NAME)(tsk->pid,
+ model_get_state_name(curr_state),
+ model_get_event_name(event));
+ return false;
+ }
+ if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) {
+ CONCATENATE(trace_event_, MONITOR_NAME)(tsk->pid,
+ model_get_state_name(curr_state),
+ model_get_event_name(event),
+ model_get_state_name(next_state),
+ model_is_final_state(next_state));
+ return true;
+ }
+ }
+
+ trace_rv_retries_error(__stringify(MONITOR_NAME), model_get_event_name(event));
+ pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS)
+ " retries reached for event %s, resetting monitor %s",
+ model_get_event_name(event), __stringify(MONITOR_NAME));
+ return false;
}
+#endif /* RV_MON_TYPE */
+#if RV_MON_TYPE == RV_MON_GLOBAL
/*
* Functions to define, init and get a global monitor.
*/
-#define DECLARE_DA_MON_INIT_GLOBAL(name, type) \
- \
-/* \
- * global monitor (a single variable) \
- */ \
-static struct da_monitor da_mon_##name; \
- \
-/* \
- * da_get_monitor_##name - return the global monitor address \
- */ \
-static struct da_monitor *da_get_monitor_##name(void) \
-{ \
- return &da_mon_##name; \
-} \
- \
-/* \
- * da_monitor_reset_all_##name - reset the single monitor \
- */ \
-static void da_monitor_reset_all_##name(void) \
-{ \
- da_monitor_reset_##name(da_get_monitor_##name()); \
-} \
- \
-/* \
- * da_monitor_init_##name - initialize a monitor \
- */ \
-static inline int da_monitor_init_##name(void) \
-{ \
- da_monitor_reset_all_##name(); \
- return 0; \
-} \
- \
-/* \
- * da_monitor_destroy_##name - destroy the monitor \
- */ \
-static inline void da_monitor_destroy_##name(void) \
-{ \
- return; \
+
+/*
+ * global monitor (a single variable)
+ */
+static struct da_monitor da_mon_this;
+
+/*
+ * da_get_monitor - return the global monitor address
+ */
+static struct da_monitor *da_get_monitor(void)
+{
+ return &da_mon_this;
+}
+
+/*
+ * da_monitor_reset_all - reset the single monitor
+ */
+static void da_monitor_reset_all(void)
+{
+ da_monitor_reset(da_get_monitor());
+}
+
+/*
+ * da_monitor_init - initialize a monitor
+ */
+static inline int da_monitor_init(void)
+{
+ da_monitor_reset_all();
+ return 0;
}
/*
+ * da_monitor_destroy - destroy the monitor
+ */
+static inline void da_monitor_destroy(void) { }
+
+#elif RV_MON_TYPE == RV_MON_PER_CPU
+/*
* Functions to define, init and get a per-cpu monitor.
*/
-#define DECLARE_DA_MON_INIT_PER_CPU(name, type) \
- \
-/* \
- * per-cpu monitor variables \
- */ \
-static DEFINE_PER_CPU(struct da_monitor, da_mon_##name); \
- \
-/* \
- * da_get_monitor_##name - return current CPU monitor address \
- */ \
-static struct da_monitor *da_get_monitor_##name(void) \
-{ \
- return this_cpu_ptr(&da_mon_##name); \
-} \
- \
-/* \
- * da_monitor_reset_all_##name - reset all CPUs' monitor \
- */ \
-static void da_monitor_reset_all_##name(void) \
-{ \
- struct da_monitor *da_mon; \
- int cpu; \
- for_each_cpu(cpu, cpu_online_mask) { \
- da_mon = per_cpu_ptr(&da_mon_##name, cpu); \
- da_monitor_reset_##name(da_mon); \
- } \
-} \
- \
-/* \
- * da_monitor_init_##name - initialize all CPUs' monitor \
- */ \
-static inline int da_monitor_init_##name(void) \
-{ \
- da_monitor_reset_all_##name(); \
- return 0; \
-} \
- \
-/* \
- * da_monitor_destroy_##name - destroy the monitor \
- */ \
-static inline void da_monitor_destroy_##name(void) \
-{ \
- return; \
+
+/*
+ * per-cpu monitor variables
+ */
+static DEFINE_PER_CPU(struct da_monitor, da_mon_this);
+
+/*
+ * da_get_monitor - return current CPU monitor address
+ */
+static struct da_monitor *da_get_monitor(void)
+{
+ return this_cpu_ptr(&da_mon_this);
}
/*
+ * da_monitor_reset_all - reset all CPUs' monitor
+ */
+static void da_monitor_reset_all(void)
+{
+ struct da_monitor *da_mon;
+ int cpu;
+
+ for_each_cpu(cpu, cpu_online_mask) {
+ da_mon = per_cpu_ptr(&da_mon_this, cpu);
+ da_monitor_reset(da_mon);
+ }
+}
+
+/*
+ * da_monitor_init - initialize all CPUs' monitor
+ */
+static inline int da_monitor_init(void)
+{
+ da_monitor_reset_all();
+ return 0;
+}
+
+/*
+ * da_monitor_destroy - destroy the monitor
+ */
+static inline void da_monitor_destroy(void) { }
+
+#elif RV_MON_TYPE == RV_MON_PER_TASK
+/*
* Functions to define, init and get a per-task monitor.
*/
-#define DECLARE_DA_MON_INIT_PER_TASK(name, type) \
- \
-/* \
- * The per-task monitor is stored a vector in the task struct. This variable \
- * stores the position on the vector reserved for this monitor. \
- */ \
-static int task_mon_slot_##name = RV_PER_TASK_MONITOR_INIT; \
- \
-/* \
- * da_get_monitor_##name - return the monitor in the allocated slot for tsk \
- */ \
-static inline struct da_monitor *da_get_monitor_##name(struct task_struct *tsk) \
-{ \
- return &tsk->rv[task_mon_slot_##name].da_mon; \
-} \
- \
-static void da_monitor_reset_all_##name(void) \
-{ \
- struct task_struct *g, *p; \
- int cpu; \
- \
- read_lock(&tasklist_lock); \
- for_each_process_thread(g, p) \
- da_monitor_reset_##name(da_get_monitor_##name(p)); \
- for_each_present_cpu(cpu) \
- da_monitor_reset_##name(da_get_monitor_##name(idle_task(cpu))); \
- read_unlock(&tasklist_lock); \
-} \
- \
-/* \
- * da_monitor_init_##name - initialize the per-task monitor \
- * \
- * Try to allocate a slot in the task's vector of monitors. If there \
- * is an available slot, use it and reset all task's monitor. \
- */ \
-static int da_monitor_init_##name(void) \
-{ \
- int slot; \
- \
- slot = rv_get_task_monitor_slot(); \
- if (slot < 0 || slot >= RV_PER_TASK_MONITOR_INIT) \
- return slot; \
- \
- task_mon_slot_##name = slot; \
- \
- da_monitor_reset_all_##name(); \
- return 0; \
-} \
- \
-/* \
- * da_monitor_destroy_##name - return the allocated slot \
- */ \
-static inline void da_monitor_destroy_##name(void) \
-{ \
- if (task_mon_slot_##name == RV_PER_TASK_MONITOR_INIT) { \
- WARN_ONCE(1, "Disabling a disabled monitor: " #name); \
- return; \
- } \
- rv_put_task_monitor_slot(task_mon_slot_##name); \
- task_mon_slot_##name = RV_PER_TASK_MONITOR_INIT; \
- return; \
+
+/*
+ * The per-task monitor is stored a vector in the task struct. This variable
+ * stores the position on the vector reserved for this monitor.
+ */
+static int task_mon_slot = RV_PER_TASK_MONITOR_INIT;
+
+/*
+ * da_get_monitor - return the monitor in the allocated slot for tsk
+ */
+static inline struct da_monitor *da_get_monitor(struct task_struct *tsk)
+{
+ return &tsk->rv[task_mon_slot].da_mon;
+}
+
+static void da_monitor_reset_all(void)
+{
+ struct task_struct *g, *p;
+ int cpu;
+
+ read_lock(&tasklist_lock);
+ for_each_process_thread(g, p)
+ da_monitor_reset(da_get_monitor(p));
+ for_each_present_cpu(cpu)
+ da_monitor_reset(da_get_monitor(idle_task(cpu)));
+ read_unlock(&tasklist_lock);
+}
+
+/*
+ * da_monitor_init - initialize the per-task monitor
+ *
+ * Try to allocate a slot in the task's vector of monitors. If there
+ * is an available slot, use it and reset all task's monitor.
+ */
+static int da_monitor_init(void)
+{
+ int slot;
+
+ slot = rv_get_task_monitor_slot();
+ if (slot < 0 || slot >= RV_PER_TASK_MONITOR_INIT)
+ return slot;
+
+ task_mon_slot = slot;
+
+ da_monitor_reset_all();
+ return 0;
}
/*
- * Handle event for implicit monitor: da_get_monitor_##name() will figure out
+ * da_monitor_destroy - return the allocated slot
+ */
+static inline void da_monitor_destroy(void)
+{
+ if (task_mon_slot == RV_PER_TASK_MONITOR_INIT) {
+ WARN_ONCE(1, "Disabling a disabled monitor: " __stringify(MONITOR_NAME));
+ return;
+ }
+ rv_put_task_monitor_slot(task_mon_slot);
+ task_mon_slot = RV_PER_TASK_MONITOR_INIT;
+}
+#endif /* RV_MON_TYPE */
+
+#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.
*/
-#define DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type) \
- \
-static inline void __da_handle_event_##name(struct da_monitor *da_mon, \
- enum events_##name event) \
-{ \
- bool retval; \
- \
- retval = da_event_##name(da_mon, event); \
- if (!retval) \
- da_monitor_reset_##name(da_mon); \
-} \
- \
-/* \
- * da_handle_event_##name - handle an event \
- */ \
-static inline void da_handle_event_##name(enum events_##name event) \
-{ \
- struct da_monitor *da_mon = da_get_monitor_##name(); \
- bool retval; \
- \
- retval = da_monitor_handling_event_##name(da_mon); \
- if (!retval) \
- return; \
- \
- __da_handle_event_##name(da_mon, event); \
-} \
- \
-/* \
- * da_handle_start_event_##name - start monitoring or handle event \
- * \
- * This function is used to notify the monitor that the system is returning \
- * to the initial state, so the monitor can start monitoring in the next event. \
- * Thus: \
- * \
- * If the monitor already started, handle the event. \
- * If the monitor did not start yet, start the monitor but skip the event. \
- */ \
-static inline bool da_handle_start_event_##name(enum events_##name event) \
-{ \
- struct da_monitor *da_mon; \
- \
- if (!da_monitor_enabled_##name()) \
- return 0; \
- \
- da_mon = da_get_monitor_##name(); \
- \
- if (unlikely(!da_monitoring_##name(da_mon))) { \
- da_monitor_start_##name(da_mon); \
- return 0; \
- } \
- \
- __da_handle_event_##name(da_mon, event); \
- \
- return 1; \
-} \
- \
-/* \
- * da_handle_start_run_event_##name - start monitoring and handle event \
- * \
- * This function is used to notify the monitor that the system is in the \
- * initial state, so the monitor can start monitoring and handling event. \
- */ \
-static inline bool da_handle_start_run_event_##name(enum events_##name event) \
-{ \
- struct da_monitor *da_mon; \
- \
- if (!da_monitor_enabled_##name()) \
- return 0; \
- \
- da_mon = da_get_monitor_##name(); \
- \
- if (unlikely(!da_monitoring_##name(da_mon))) \
- da_monitor_start_##name(da_mon); \
- \
- __da_handle_event_##name(da_mon, event); \
- \
- return 1; \
+
+static inline void __da_handle_event(struct da_monitor *da_mon,
+ enum events event)
+{
+ bool retval;
+
+ retval = da_event(da_mon, event);
+ if (!retval)
+ da_monitor_reset(da_mon);
+}
+
+/*
+ * da_handle_event - handle an event
+ */
+static inline void da_handle_event(enum events event)
+{
+ struct da_monitor *da_mon = da_get_monitor();
+ bool retval;
+
+ retval = da_monitor_handling_event(da_mon);
+ if (!retval)
+ return;
+
+ __da_handle_event(da_mon, event);
}
/*
+ * da_handle_start_event - start monitoring or handle event
+ *
+ * This function is used to notify the monitor that the system is returning
+ * to the initial state, so the monitor can start monitoring in the next event.
+ * Thus:
+ *
+ * If the monitor already started, handle the event.
+ * If the monitor did not start yet, start the monitor but skip the event.
+ */
+static inline bool da_handle_start_event(enum events event)
+{
+ 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;
+}
+
+/*
+ * da_handle_start_run_event - start monitoring and handle event
+ *
+ * This function is used to notify the monitor that the system is in the
+ * initial state, so the monitor can start monitoring and handling event.
+ */
+static inline bool da_handle_start_run_event(enum events event)
+{
+ 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;
+}
+
+#elif RV_MON_TYPE == RV_MON_PER_TASK
+/*
* Handle event for per task.
*/
-#define DECLARE_DA_MON_MONITOR_HANDLER_PER_TASK(name, type) \
- \
-static inline void \
-__da_handle_event_##name(struct da_monitor *da_mon, struct task_struct *tsk, \
- enum events_##name event) \
-{ \
- bool retval; \
- \
- retval = da_event_##name(da_mon, tsk, event); \
- if (!retval) \
- da_monitor_reset_##name(da_mon); \
-} \
- \
-/* \
- * da_handle_event_##name - handle an event \
- */ \
-static inline void \
-da_handle_event_##name(struct task_struct *tsk, enum events_##name event) \
-{ \
- struct da_monitor *da_mon = da_get_monitor_##name(tsk); \
- bool retval; \
- \
- retval = da_monitor_handling_event_##name(da_mon); \
- if (!retval) \
- return; \
- \
- __da_handle_event_##name(da_mon, tsk, event); \
-} \
- \
-/* \
- * da_handle_start_event_##name - start monitoring or handle event \
- * \
- * This function is used to notify the monitor that the system is returning \
- * to the initial state, so the monitor can start monitoring in the next event. \
- * Thus: \
- * \
- * If the monitor already started, handle the event. \
- * If the monitor did not start yet, start the monitor but skip the event. \
- */ \
-static inline bool \
-da_handle_start_event_##name(struct task_struct *tsk, enum events_##name event) \
-{ \
- struct da_monitor *da_mon; \
- \
- if (!da_monitor_enabled_##name()) \
- return 0; \
- \
- da_mon = da_get_monitor_##name(tsk); \
- \
- if (unlikely(!da_monitoring_##name(da_mon))) { \
- da_monitor_start_##name(da_mon); \
- return 0; \
- } \
- \
- __da_handle_event_##name(da_mon, tsk, event); \
- \
- return 1; \
-} \
- \
-/* \
- * da_handle_start_run_event_##name - start monitoring and handle event \
- * \
- * This function is used to notify the monitor that the system is in the \
- * initial state, so the monitor can start monitoring and handling event. \
- */ \
-static inline bool \
-da_handle_start_run_event_##name(struct task_struct *tsk, enum events_##name event) \
-{ \
- struct da_monitor *da_mon; \
- \
- if (!da_monitor_enabled_##name()) \
- return 0; \
- \
- da_mon = da_get_monitor_##name(tsk); \
- \
- if (unlikely(!da_monitoring_##name(da_mon))) \
- da_monitor_start_##name(da_mon); \
- \
- __da_handle_event_##name(da_mon, tsk, event); \
- \
- return 1; \
+
+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);
}
/*
- * Entry point for the global monitor.
+ * da_handle_event - handle an event
*/
-#define DECLARE_DA_MON_GLOBAL(name, type) \
- \
-DECLARE_AUTOMATA_HELPERS(name, type) \
-DECLARE_DA_MON_GENERIC_HELPERS(name, type) \
-DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type) \
-DECLARE_DA_MON_INIT_GLOBAL(name, type) \
-DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type)
+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);
+}
/*
- * Entry point for the per-cpu monitor.
+ * da_handle_start_event - start monitoring or handle event
+ *
+ * This function is used to notify the monitor that the system is returning
+ * to the initial state, so the monitor can start monitoring in the next event.
+ * Thus:
+ *
+ * If the monitor already started, handle the event.
+ * If the monitor did not start yet, start the monitor but skip the event.
*/
-#define DECLARE_DA_MON_PER_CPU(name, type) \
- \
-DECLARE_AUTOMATA_HELPERS(name, type) \
-DECLARE_DA_MON_GENERIC_HELPERS(name, type) \
-DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type) \
-DECLARE_DA_MON_INIT_PER_CPU(name, type) \
-DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type)
+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;
+}
/*
- * Entry point for the per-task monitor.
+ * da_handle_start_run_event - start monitoring and handle event
+ *
+ * This function is used to notify the monitor that the system is in the
+ * initial state, so the monitor can start monitoring and handling event.
*/
-#define DECLARE_DA_MON_PER_TASK(name, type) \
- \
-DECLARE_AUTOMATA_HELPERS(name, type) \
-DECLARE_DA_MON_GENERIC_HELPERS(name, type) \
-DECLARE_DA_MON_MODEL_HANDLER_PER_TASK(name, type) \
-DECLARE_DA_MON_INIT_PER_TASK(name, type) \
-DECLARE_DA_MON_MONITOR_HANDLER_PER_TASK(name, type)
+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;
+}
+#endif /* RV_MON_TYPE */
+
+#endif