From: Gabriele Monaco <gmonaco@redhat.com>
To: linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
linux-trace-kernel@vger.kernel.org
Cc: Gabriele Monaco <gmonaco@redhat.com>,
Nam Cao <namcao@linutronix.de>, Tomas Glozar <tglozar@redhat.com>,
Juri Lelli <jlelli@redhat.com>,
Clark Williams <williams@redhat.com>,
John Kacur <jkacur@redhat.com>
Subject: [PATCH v2 02/20] rv: Cleanup da_monitor after refactor
Date: Fri, 19 Sep 2025 16:09:36 +0200 [thread overview]
Message-ID: <20250919140954.104920-3-gmonaco@redhat.com> (raw)
In-Reply-To: <20250919140954.104920-1-gmonaco@redhat.com>
Previous 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.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
include/rv/automata.h | 24 +++-----
include/rv/da_monitor.h | 121 +++++++++++++++-------------------------
2 files changed, 53 insertions(+), 92 deletions(-)
diff --git a/include/rv/automata.h b/include/rv/automata.h
index 5b5d2e94c034..4a4eb40cf09a 100644
--- a/include/rv/automata.h
+++ b/include/rv/automata.h
@@ -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
diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h
index c2bc1350bb40..7c3540d0f64e 100644
--- a/include/rv/da_monitor.h
+++ b/include/rv/da_monitor.h
@@ -11,6 +11,9 @@
* Documentation/trace/rv/da_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>
@@ -22,33 +25,20 @@ static struct rv_monitor rv_this;
#ifdef CONFIG_RV_REACTORS
-#define DECLARE_RV_REACTING_HELPERS(name, type)
-static void cond_react(type curr_state, type event)
+static void cond_react(enum states curr_state, enum events event)
{
if (!rv_reacting_on() || !rv_this.react)
return;
rv_this.react("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));
+ __stringify(MONITOR_NAME), model_get_event_name(event),
+ model_get_state_name(curr_state));
}
#else /* CONFIG_RV_REACTOR */
-#define DECLARE_RV_REACTING_HELPERS(name, type)
-static void cond_react(type curr_state, type event)
-{
- return;
-}
+static void cond_react(enum states curr_state, enum events event) { }
#endif
-/*
- * Generic helpers for all types of deterministic automata monitors.
- */
-#define DECLARE_DA_MON_GENERIC_HELPERS(name, type)
-
-DECLARE_RV_REACTING_HELPERS(name, type)
-
/*
* da_monitor_reset - reset a monitor and setting it to init state
*/
@@ -99,7 +89,6 @@ static inline bool da_monitor_enabled(void)
*/
static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
{
-
if (!da_monitor_enabled())
return 0;
@@ -110,6 +99,7 @@ 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
@@ -119,10 +109,8 @@ static inline bool da_monitor_handling_event(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.
*/
-#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
-static inline bool
-da_event(struct da_monitor *da_mon, enum events event)
+static inline bool da_event(struct da_monitor *da_mon, enum events event)
{
enum states curr_state, next_state;
@@ -131,15 +119,17 @@ da_event(struct da_monitor *da_mon, enum events event)
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));
+ 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));
+ 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;
}
}
@@ -151,6 +141,7 @@ da_event(struct da_monitor *da_mon, enum events event)
return false;
}
+#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* Event handler for per_task monitors.
*
@@ -158,10 +149,9 @@ da_event(struct da_monitor *da_mon, enum events event)
* warn and reset the monitor if it runs out of retries. The monitor should be
* able to handle various orders.
*/
-#elif RV_MON_TYPE == RV_MON_PER_TASK
static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
- enum events event)
+ enum events event)
{
enum states curr_state, next_state;
@@ -171,16 +161,16 @@ static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
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));
+ 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));
+ 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;
}
}
@@ -191,12 +181,12 @@ static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
model_get_event_name(event), __stringify(MONITOR_NAME));
return false;
}
-#endif
+#endif /* RV_MON_TYPE */
+#if RV_MON_TYPE == RV_MON_GLOBAL
/*
* Functions to define, init and get a global monitor.
*/
-#if RV_MON_TYPE == RV_MON_GLOBAL
/*
* global monitor (a single variable)
@@ -231,15 +221,12 @@ static inline int da_monitor_init(void)
/*
* da_monitor_destroy - destroy the monitor
*/
-static inline void da_monitor_destroy(void)
-{
- return;
-}
+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.
*/
-#elif RV_MON_TYPE == RV_MON_PER_CPU
/*
* per-cpu monitor variables
@@ -261,6 +248,7 @@ 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(&RV_DA_MON_NAME, cpu);
da_monitor_reset(da_mon);
@@ -279,15 +267,12 @@ static inline int da_monitor_init(void)
/*
* da_monitor_destroy - destroy the monitor
*/
-static inline void da_monitor_destroy(void)
-{
- return;
-}
+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.
*/
-#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* The per-task monitor is stored a vector in the task struct. This variable
@@ -347,18 +332,17 @@ static inline void da_monitor_destroy(void)
}
rv_put_task_monitor_slot(task_mon_slot);
task_mon_slot = RV_PER_TASK_MONITOR_INIT;
- return;
}
-#endif
+#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.
*/
-#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
static inline void __da_handle_event(struct da_monitor *da_mon,
- enum events event)
+ enum events event)
{
bool retval;
@@ -434,14 +418,13 @@ static inline bool da_handle_start_run_event(enum events event)
return 1;
}
+#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* Handle event for per task.
*/
-#elif RV_MON_TYPE == RV_MON_PER_TASK
-static inline void
-__da_handle_event(struct da_monitor *da_mon, struct task_struct *tsk,
- enum events event)
+static inline void __da_handle_event(struct da_monitor *da_mon,
+ struct task_struct *tsk, enum events event)
{
bool retval;
@@ -453,8 +436,7 @@ __da_handle_event(struct da_monitor *da_mon, struct task_struct *tsk,
/*
* da_handle_event - handle an event
*/
-static inline void
-da_handle_event(struct task_struct *tsk, enum events 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;
@@ -476,8 +458,8 @@ da_handle_event(struct task_struct *tsk, enum events event)
* 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(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;
@@ -502,8 +484,8 @@ da_handle_start_event(struct task_struct *tsk, enum events 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(struct task_struct *tsk, enum events event)
+static inline bool da_handle_start_run_event(struct task_struct *tsk,
+ enum events event)
{
struct da_monitor *da_mon;
@@ -519,19 +501,6 @@ da_handle_start_run_event(struct task_struct *tsk, enum events event)
return 1;
}
-#endif
-
-/*
- * Entry point for the global monitor.
- */
-#define DECLARE_DA_MON_GLOBAL(name, type)
-
-/*
- * Entry point for the per-cpu monitor.
- */
-#define DECLARE_DA_MON_PER_CPU(name, type)
+#endif /* RV_MON_TYPE */
-/*
- * Entry point for the per-task monitor.
- */
-#define DECLARE_DA_MON_PER_TASK(name, type)
+#endif
--
2.51.0
next prev parent reply other threads:[~2025-09-19 14:10 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-19 14:09 [PATCH v2 00/20] rv: Add Hybrid Automata monitor type, per-object and deadline monitors Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 01/20] rv: Refactor da_monitor to minimise macros Gabriele Monaco
2025-10-02 8:45 ` Nam Cao
2025-09-19 14:09 ` Gabriele Monaco [this message]
2025-10-02 8:49 ` [PATCH v2 02/20] rv: Cleanup da_monitor after refactor Nam Cao
2025-09-19 14:09 ` [PATCH v2 03/20] rv: Unify DA event handling functions across monitor types Gabriele Monaco
2025-10-02 9:14 ` Nam Cao
2025-10-02 11:30 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 04/20] Documentation/rv: Adapt documentation after da_monitor refactoring Gabriele Monaco
2025-10-02 9:26 ` Nam Cao
2025-09-19 14:09 ` [PATCH v2 05/20] verification/rvgen: Adapt dot2k and templates after refactoring da_monitor.h Gabriele Monaco
2025-10-02 9:34 ` Nam Cao
2025-09-19 14:09 ` [PATCH v2 06/20] verification/rvgen: Annotate DA functions with types Gabriele Monaco
2025-10-02 9:39 ` Nam Cao
2025-09-19 14:09 ` [PATCH v2 07/20] verification/dot2c: Remove __buff_to_string() and cleanup Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 08/20] verification/dot2c: Remove superfluous enum assignment and add last comma Gabriele Monaco
2025-10-02 9:40 ` Nam Cao
2025-09-19 14:09 ` [PATCH v2 09/20] verification/rvgen: Remove unused variable declaration from containers Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 10/20] rv: Add Hybrid Automata monitor type Gabriele Monaco
2025-10-17 8:44 ` Nam Cao
2025-10-17 9:48 ` Gabriele Monaco
2025-10-17 13:05 ` Nam Cao
2025-10-17 15:22 ` Gabriele Monaco
2025-10-20 13:43 ` Nam Cao
2025-09-19 14:09 ` [PATCH v2 11/20] verification/rvgen: Allow spaces in and events strings Gabriele Monaco
2025-10-02 11:03 ` Nam Cao
2025-10-02 11:17 ` Gabriele Monaco
2025-10-06 13:20 ` Nam Cao
2025-10-06 15:22 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 12/20] verification/rvgen: Add support for Hybrid Automata Gabriele Monaco
2025-10-17 9:37 ` Nam Cao
2025-10-17 9:53 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 13/20] Documentation/rv: Add documentation about hybrid automata Gabriele Monaco
2025-10-10 13:46 ` Nam Cao
2025-10-13 8:33 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 14/20] rv: Add sample hybrid monitors stall Gabriele Monaco
2025-10-10 14:23 ` Nam Cao
2025-10-13 9:01 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 15/20] rv: Convert the opid monitor to a hybrid automaton Gabriele Monaco
2025-10-10 14:29 ` Nam Cao
2025-10-13 14:14 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 16/20] sched: Export hidden tracepoints to modules Gabriele Monaco
2025-09-19 15:37 ` Steven Rostedt
2025-09-19 17:07 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 17/20] sched: Add deadline tracepoints Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 18/20] rv: Add support for per-object monitors in DA/HA Gabriele Monaco
2025-10-21 11:55 ` Nam Cao
2025-10-21 15:54 ` Gabriele Monaco
2025-10-23 12:36 ` Nam Cao
2025-10-24 9:20 ` Gabriele Monaco
2025-09-19 14:09 ` [PATCH v2 19/20] verification/rvgen: Add support for per-obj monitors Gabriele Monaco
2025-10-21 12:00 ` Nam Cao
2025-09-19 14:09 ` [PATCH v2 20/20] rv: Add deadline monitors Gabriele Monaco
2025-10-10 15:04 ` Nam Cao
2025-10-13 7:30 ` Gabriele Monaco
2025-10-21 12:05 ` [PATCH v2 00/20] rv: Add Hybrid Automata monitor type, per-object and " Nam Cao
2025-10-21 15:45 ` Gabriele Monaco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250919140954.104920-3-gmonaco@redhat.com \
--to=gmonaco@redhat.com \
--cc=jkacur@redhat.com \
--cc=jlelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=rostedt@goodmis.org \
--cc=tglozar@redhat.com \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).