Skip to content

Commit fa9b26d

Browse files
committed
rv: Cleanup da_monitor after refactor
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. Reviewed-by: Nam Cao <namcao@linutronix.de> Link: https://lore.kernel.org/r/20251126104241.291258-3-gmonaco@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
1 parent 30984cc commit fa9b26d

2 files changed

Lines changed: 50 additions & 81 deletions

File tree

include/rv/automata.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,19 @@
66
* models in C generated by the dot2k tool.
77
*/
88

9+
#ifndef _RV_AUTOMATA_H
10+
#define _RV_AUTOMATA_H
11+
912
#ifndef MONITOR_NAME
1013
#error "MONITOR_NAME macro is not defined. Did you include $(MODEL_NAME).h generated by rvgen?"
1114
#endif
1215

13-
#ifndef type
14-
#define type unsigned char
15-
#endif
16-
1716
#define RV_AUTOMATON_NAME CONCATENATE(automaton_, MONITOR_NAME)
1817
#define EVENT_MAX CONCATENATE(event_max_, MONITOR_NAME)
1918
#define STATE_MAX CONCATENATE(state_max_, MONITOR_NAME)
2019
#define events CONCATENATE(events_, MONITOR_NAME)
2120
#define states CONCATENATE(states_, MONITOR_NAME)
2221

23-
/*
24-
* DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata
25-
*
26-
* Define a set of helper functions for automata. The 'name' argument is used
27-
* as suffix for the functions and data. These functions will handle automaton
28-
* with data type 'type'.
29-
*/
30-
#define DECLARE_AUTOMATA_HELPERS(name, type)
31-
3222
/*
3323
* model_get_state_name - return the (string) name of the given state
3424
*/
@@ -54,7 +44,7 @@ static char *model_get_event_name(enum events event)
5444
/*
5545
* model_get_initial_state - return the automaton's initial state
5646
*/
57-
static inline type model_get_initial_state(void)
47+
static inline enum states model_get_initial_state(void)
5848
{
5949
return RV_AUTOMATON_NAME.initial_state;
6050
}
@@ -65,8 +55,8 @@ static inline type model_get_initial_state(void)
6555
* Given the current state (curr_state) and the event (event), returns
6656
* the next state, or INVALID_STATE in case of error.
6757
*/
68-
static inline type model_get_next_state(enum states curr_state,
69-
enum events event)
58+
static inline enum states model_get_next_state(enum states curr_state,
59+
enum events event)
7060
{
7161
if ((curr_state < 0) || (curr_state >= STATE_MAX))
7262
return INVALID_STATE;
@@ -87,3 +77,5 @@ static inline bool model_is_final_state(enum states state)
8777

8878
return RV_AUTOMATON_NAME.final_states[state];
8979
}
80+
81+
#endif

include/rv/da_monitor.h

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* Documentation/trace/rv/da_monitor_synthesis.rst
1212
*/
1313

14+
#ifndef _RV_DA_MONITOR_H
15+
#define _RV_DA_MONITOR_H
16+
1417
#include <rv/automata.h>
1518
#include <linux/rv.h>
1619
#include <linux/stringify.h>
@@ -19,12 +22,7 @@
1922

2023
static struct rv_monitor rv_this;
2124

22-
/*
23-
* Generic helpers for all types of deterministic automata monitors.
24-
*/
25-
#define DECLARE_DA_MON_GENERIC_HELPERS(name, type)
26-
27-
static void react(type curr_state, type event)
25+
static void react(enum states curr_state, enum events event)
2826
{
2927
rv_react(&rv_this,
3028
"rv: monitor %s does not allow event %s on state %s\n",
@@ -83,7 +81,6 @@ static inline bool da_monitor_enabled(void)
8381
*/
8482
static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
8583
{
86-
8784
if (!da_monitor_enabled())
8885
return 0;
8986

@@ -94,6 +91,7 @@ static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
9491
return 1;
9592
}
9693

94+
#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
9795
/*
9896
* Event handler for implicit monitors. Implicit monitor is the one which the
9997
* handler does not need to specify which da_monitor to manipulate. Examples
@@ -103,10 +101,8 @@ static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
103101
* warn and reset the monitor if it runs out of retries. The monitor should be
104102
* able to handle various orders.
105103
*/
106-
#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
107104

108-
static inline bool
109-
da_event(struct da_monitor *da_mon, enum events event)
105+
static inline bool da_event(struct da_monitor *da_mon, enum events event)
110106
{
111107
enum states curr_state, next_state;
112108

@@ -115,15 +111,17 @@ da_event(struct da_monitor *da_mon, enum events event)
115111
next_state = model_get_next_state(curr_state, event);
116112
if (next_state == INVALID_STATE) {
117113
react(curr_state, event);
118-
CONCATENATE(trace_error_, MONITOR_NAME)(model_get_state_name(curr_state),
119-
model_get_event_name(event));
114+
CONCATENATE(trace_error_, MONITOR_NAME)(
115+
model_get_state_name(curr_state),
116+
model_get_event_name(event));
120117
return false;
121118
}
122119
if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) {
123-
CONCATENATE(trace_event_, MONITOR_NAME)(model_get_state_name(curr_state),
124-
model_get_event_name(event),
125-
model_get_state_name(next_state),
126-
model_is_final_state(next_state));
120+
CONCATENATE(trace_event_, MONITOR_NAME)(
121+
model_get_state_name(curr_state),
122+
model_get_event_name(event),
123+
model_get_state_name(next_state),
124+
model_is_final_state(next_state));
127125
return true;
128126
}
129127
}
@@ -135,17 +133,17 @@ da_event(struct da_monitor *da_mon, enum events event)
135133
return false;
136134
}
137135

136+
#elif RV_MON_TYPE == RV_MON_PER_TASK
138137
/*
139138
* Event handler for per_task monitors.
140139
*
141140
* Retry in case there is a race between getting and setting the next state,
142141
* warn and reset the monitor if it runs out of retries. The monitor should be
143142
* able to handle various orders.
144143
*/
145-
#elif RV_MON_TYPE == RV_MON_PER_TASK
146144

147145
static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
148-
enum events event)
146+
enum events event)
149147
{
150148
enum states curr_state, next_state;
151149

@@ -155,16 +153,16 @@ static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
155153
if (next_state == INVALID_STATE) {
156154
react(curr_state, event);
157155
CONCATENATE(trace_error_, MONITOR_NAME)(tsk->pid,
158-
model_get_state_name(curr_state),
159-
model_get_event_name(event));
156+
model_get_state_name(curr_state),
157+
model_get_event_name(event));
160158
return false;
161159
}
162160
if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) {
163161
CONCATENATE(trace_event_, MONITOR_NAME)(tsk->pid,
164-
model_get_state_name(curr_state),
165-
model_get_event_name(event),
166-
model_get_state_name(next_state),
167-
model_is_final_state(next_state));
162+
model_get_state_name(curr_state),
163+
model_get_event_name(event),
164+
model_get_state_name(next_state),
165+
model_is_final_state(next_state));
168166
return true;
169167
}
170168
}
@@ -175,12 +173,12 @@ static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
175173
model_get_event_name(event), __stringify(MONITOR_NAME));
176174
return false;
177175
}
178-
#endif
176+
#endif /* RV_MON_TYPE */
179177

178+
#if RV_MON_TYPE == RV_MON_GLOBAL
180179
/*
181180
* Functions to define, init and get a global monitor.
182181
*/
183-
#if RV_MON_TYPE == RV_MON_GLOBAL
184182

185183
/*
186184
* global monitor (a single variable)
@@ -215,15 +213,12 @@ static inline int da_monitor_init(void)
215213
/*
216214
* da_monitor_destroy - destroy the monitor
217215
*/
218-
static inline void da_monitor_destroy(void)
219-
{
220-
return;
221-
}
216+
static inline void da_monitor_destroy(void) { }
222217

218+
#elif RV_MON_TYPE == RV_MON_PER_CPU
223219
/*
224220
* Functions to define, init and get a per-cpu monitor.
225221
*/
226-
#elif RV_MON_TYPE == RV_MON_PER_CPU
227222

228223
/*
229224
* per-cpu monitor variables
@@ -245,6 +240,7 @@ static void da_monitor_reset_all(void)
245240
{
246241
struct da_monitor *da_mon;
247242
int cpu;
243+
248244
for_each_cpu(cpu, cpu_online_mask) {
249245
da_mon = per_cpu_ptr(&da_mon_this, cpu);
250246
da_monitor_reset(da_mon);
@@ -263,15 +259,12 @@ static inline int da_monitor_init(void)
263259
/*
264260
* da_monitor_destroy - destroy the monitor
265261
*/
266-
static inline void da_monitor_destroy(void)
267-
{
268-
return;
269-
}
262+
static inline void da_monitor_destroy(void) { }
270263

264+
#elif RV_MON_TYPE == RV_MON_PER_TASK
271265
/*
272266
* Functions to define, init and get a per-task monitor.
273267
*/
274-
#elif RV_MON_TYPE == RV_MON_PER_TASK
275268

276269
/*
277270
* The per-task monitor is stored a vector in the task struct. This variable
@@ -331,18 +324,17 @@ static inline void da_monitor_destroy(void)
331324
}
332325
rv_put_task_monitor_slot(task_mon_slot);
333326
task_mon_slot = RV_PER_TASK_MONITOR_INIT;
334-
return;
335327
}
336-
#endif
328+
#endif /* RV_MON_TYPE */
337329

330+
#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
338331
/*
339332
* Handle event for implicit monitor: da_get_monitor() will figure out
340333
* the monitor.
341334
*/
342-
#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
343335

344336
static inline void __da_handle_event(struct da_monitor *da_mon,
345-
enum events event)
337+
enum events event)
346338
{
347339
bool retval;
348340

@@ -418,14 +410,13 @@ static inline bool da_handle_start_run_event(enum events event)
418410
return 1;
419411
}
420412

413+
#elif RV_MON_TYPE == RV_MON_PER_TASK
421414
/*
422415
* Handle event for per task.
423416
*/
424-
#elif RV_MON_TYPE == RV_MON_PER_TASK
425417

426-
static inline void
427-
__da_handle_event(struct da_monitor *da_mon, struct task_struct *tsk,
428-
enum events event)
418+
static inline void __da_handle_event(struct da_monitor *da_mon,
419+
struct task_struct *tsk, enum events event)
429420
{
430421
bool retval;
431422

@@ -437,8 +428,7 @@ __da_handle_event(struct da_monitor *da_mon, struct task_struct *tsk,
437428
/*
438429
* da_handle_event - handle an event
439430
*/
440-
static inline void
441-
da_handle_event(struct task_struct *tsk, enum events event)
431+
static inline void da_handle_event(struct task_struct *tsk, enum events event)
442432
{
443433
struct da_monitor *da_mon = da_get_monitor(tsk);
444434
bool retval;
@@ -460,8 +450,8 @@ da_handle_event(struct task_struct *tsk, enum events event)
460450
* If the monitor already started, handle the event.
461451
* If the monitor did not start yet, start the monitor but skip the event.
462452
*/
463-
static inline bool
464-
da_handle_start_event(struct task_struct *tsk, enum events event)
453+
static inline bool da_handle_start_event(struct task_struct *tsk,
454+
enum events event)
465455
{
466456
struct da_monitor *da_mon;
467457

@@ -486,8 +476,8 @@ da_handle_start_event(struct task_struct *tsk, enum events event)
486476
* This function is used to notify the monitor that the system is in the
487477
* initial state, so the monitor can start monitoring and handling event.
488478
*/
489-
static inline bool
490-
da_handle_start_run_event(struct task_struct *tsk, enum events event)
479+
static inline bool da_handle_start_run_event(struct task_struct *tsk,
480+
enum events event)
491481
{
492482
struct da_monitor *da_mon;
493483

@@ -503,19 +493,6 @@ da_handle_start_run_event(struct task_struct *tsk, enum events event)
503493

504494
return 1;
505495
}
506-
#endif
496+
#endif /* RV_MON_TYPE */
507497

508-
/*
509-
* Entry point for the global monitor.
510-
*/
511-
#define DECLARE_DA_MON_GLOBAL(name, type)
512-
513-
/*
514-
* Entry point for the per-cpu monitor.
515-
*/
516-
#define DECLARE_DA_MON_PER_CPU(name, type)
517-
518-
/*
519-
* Entry point for the per-task monitor.
520-
*/
521-
#define DECLARE_DA_MON_PER_TASK(name, type)
498+
#endif

0 commit comments

Comments
 (0)