Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+50 -81
+8 -16
include/rv/automata.h
··· 6 6 * models in C generated by the dot2k tool. 7 7 */ 8 8 9 + #ifndef _RV_AUTOMATA_H 10 + #define _RV_AUTOMATA_H 11 + 9 12 #ifndef MONITOR_NAME 10 13 #error "MONITOR_NAME macro is not defined. Did you include $(MODEL_NAME).h generated by rvgen?" 11 - #endif 12 - 13 - #ifndef type 14 - #define type unsigned char 15 14 #endif 16 15 17 16 #define RV_AUTOMATON_NAME CONCATENATE(automaton_, MONITOR_NAME) ··· 18 19 #define STATE_MAX CONCATENATE(state_max_, MONITOR_NAME) 19 20 #define events CONCATENATE(events_, MONITOR_NAME) 20 21 #define states CONCATENATE(states_, MONITOR_NAME) 21 - 22 - /* 23 - * DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata 24 - * 25 - * Define a set of helper functions for automata. The 'name' argument is used 26 - * as suffix for the functions and data. These functions will handle automaton 27 - * with data type 'type'. 28 - */ 29 - #define DECLARE_AUTOMATA_HELPERS(name, type) 30 22 31 23 /* 32 24 * model_get_state_name - return the (string) name of the given state ··· 44 54 /* 45 55 * model_get_initial_state - return the automaton's initial state 46 56 */ 47 - static inline type model_get_initial_state(void) 57 + static inline enum states model_get_initial_state(void) 48 58 { 49 59 return RV_AUTOMATON_NAME.initial_state; 50 60 } ··· 55 65 * Given the current state (curr_state) and the event (event), returns 56 66 * the next state, or INVALID_STATE in case of error. 57 67 */ 58 - static inline type model_get_next_state(enum states curr_state, 59 - enum events event) 68 + static inline enum states model_get_next_state(enum states curr_state, 69 + enum events event) 60 70 { 61 71 if ((curr_state < 0) || (curr_state >= STATE_MAX)) 62 72 return INVALID_STATE; ··· 77 87 78 88 return RV_AUTOMATON_NAME.final_states[state]; 79 89 } 90 + 91 + #endif
+42 -65
include/rv/da_monitor.h
··· 11 11 * Documentation/trace/rv/da_monitor_synthesis.rst 12 12 */ 13 13 14 + #ifndef _RV_DA_MONITOR_H 15 + #define _RV_DA_MONITOR_H 16 + 14 17 #include <rv/automata.h> 15 18 #include <linux/rv.h> 16 19 #include <linux/stringify.h> ··· 22 19 23 20 static struct rv_monitor rv_this; 24 21 25 - /* 26 - * Generic helpers for all types of deterministic automata monitors. 27 - */ 28 - #define DECLARE_DA_MON_GENERIC_HELPERS(name, type) 29 - 30 - static void react(type curr_state, type event) 22 + static void react(enum states curr_state, enum events event) 31 23 { 32 24 rv_react(&rv_this, 33 25 "rv: monitor %s does not allow event %s on state %s\n", ··· 81 83 */ 82 84 static inline bool da_monitor_handling_event(struct da_monitor *da_mon) 83 85 { 84 - 85 86 if (!da_monitor_enabled()) 86 87 return 0; 87 88 ··· 91 94 return 1; 92 95 } 93 96 97 + #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 94 98 /* 95 99 * Event handler for implicit monitors. Implicit monitor is the one which the 96 100 * handler does not need to specify which da_monitor to manipulate. Examples ··· 101 103 * warn and reset the monitor if it runs out of retries. The monitor should be 102 104 * able to handle various orders. 103 105 */ 104 - #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 105 106 106 - static inline bool 107 - da_event(struct da_monitor *da_mon, enum events event) 107 + static inline bool da_event(struct da_monitor *da_mon, enum events event) 108 108 { 109 109 enum states curr_state, next_state; 110 110 ··· 111 115 next_state = model_get_next_state(curr_state, event); 112 116 if (next_state == INVALID_STATE) { 113 117 react(curr_state, event); 114 - CONCATENATE(trace_error_, MONITOR_NAME)(model_get_state_name(curr_state), 115 - model_get_event_name(event)); 118 + CONCATENATE(trace_error_, MONITOR_NAME)( 119 + model_get_state_name(curr_state), 120 + model_get_event_name(event)); 116 121 return false; 117 122 } 118 123 if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { 119 - CONCATENATE(trace_event_, MONITOR_NAME)(model_get_state_name(curr_state), 120 - model_get_event_name(event), 121 - model_get_state_name(next_state), 122 - model_is_final_state(next_state)); 124 + CONCATENATE(trace_event_, MONITOR_NAME)( 125 + model_get_state_name(curr_state), 126 + model_get_event_name(event), 127 + model_get_state_name(next_state), 128 + model_is_final_state(next_state)); 123 129 return true; 124 130 } 125 131 } ··· 133 135 return false; 134 136 } 135 137 138 + #elif RV_MON_TYPE == RV_MON_PER_TASK 136 139 /* 137 140 * Event handler for per_task monitors. 138 141 * ··· 141 142 * warn and reset the monitor if it runs out of retries. The monitor should be 142 143 * able to handle various orders. 143 144 */ 144 - #elif RV_MON_TYPE == RV_MON_PER_TASK 145 145 146 146 static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk, 147 - enum events event) 147 + enum events event) 148 148 { 149 149 enum states curr_state, next_state; 150 150 ··· 153 155 if (next_state == INVALID_STATE) { 154 156 react(curr_state, event); 155 157 CONCATENATE(trace_error_, MONITOR_NAME)(tsk->pid, 156 - model_get_state_name(curr_state), 157 - model_get_event_name(event)); 158 + model_get_state_name(curr_state), 159 + model_get_event_name(event)); 158 160 return false; 159 161 } 160 162 if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { 161 163 CONCATENATE(trace_event_, MONITOR_NAME)(tsk->pid, 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)); 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)); 166 168 return true; 167 169 } 168 170 } ··· 173 175 model_get_event_name(event), __stringify(MONITOR_NAME)); 174 176 return false; 175 177 } 176 - #endif 178 + #endif /* RV_MON_TYPE */ 177 179 180 + #if RV_MON_TYPE == RV_MON_GLOBAL 178 181 /* 179 182 * Functions to define, init and get a global monitor. 180 183 */ 181 - #if RV_MON_TYPE == RV_MON_GLOBAL 182 184 183 185 /* 184 186 * global monitor (a single variable) ··· 213 215 /* 214 216 * da_monitor_destroy - destroy the monitor 215 217 */ 216 - static inline void da_monitor_destroy(void) 217 - { 218 - return; 219 - } 218 + static inline void da_monitor_destroy(void) { } 220 219 220 + #elif RV_MON_TYPE == RV_MON_PER_CPU 221 221 /* 222 222 * Functions to define, init and get a per-cpu monitor. 223 223 */ 224 - #elif RV_MON_TYPE == RV_MON_PER_CPU 225 224 226 225 /* 227 226 * per-cpu monitor variables ··· 240 245 { 241 246 struct da_monitor *da_mon; 242 247 int cpu; 248 + 243 249 for_each_cpu(cpu, cpu_online_mask) { 244 250 da_mon = per_cpu_ptr(&da_mon_this, cpu); 245 251 da_monitor_reset(da_mon); ··· 259 263 /* 260 264 * da_monitor_destroy - destroy the monitor 261 265 */ 262 - static inline void da_monitor_destroy(void) 263 - { 264 - return; 265 - } 266 + static inline void da_monitor_destroy(void) { } 266 267 268 + #elif RV_MON_TYPE == RV_MON_PER_TASK 267 269 /* 268 270 * Functions to define, init and get a per-task monitor. 269 271 */ 270 - #elif RV_MON_TYPE == RV_MON_PER_TASK 271 272 272 273 /* 273 274 * The per-task monitor is stored a vector in the task struct. This variable ··· 324 331 } 325 332 rv_put_task_monitor_slot(task_mon_slot); 326 333 task_mon_slot = RV_PER_TASK_MONITOR_INIT; 327 - return; 328 334 } 329 - #endif 335 + #endif /* RV_MON_TYPE */ 330 336 337 + #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 331 338 /* 332 339 * Handle event for implicit monitor: da_get_monitor() will figure out 333 340 * the monitor. 334 341 */ 335 - #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 336 342 337 343 static inline void __da_handle_event(struct da_monitor *da_mon, 338 - enum events event) 344 + enum events event) 339 345 { 340 346 bool retval; 341 347 ··· 410 418 return 1; 411 419 } 412 420 421 + #elif RV_MON_TYPE == RV_MON_PER_TASK 413 422 /* 414 423 * Handle event for per task. 415 424 */ 416 - #elif RV_MON_TYPE == RV_MON_PER_TASK 417 425 418 - static inline void 419 - __da_handle_event(struct da_monitor *da_mon, struct task_struct *tsk, 420 - enum events event) 426 + static inline void __da_handle_event(struct da_monitor *da_mon, 427 + struct task_struct *tsk, enum events event) 421 428 { 422 429 bool retval; 423 430 ··· 428 437 /* 429 438 * da_handle_event - handle an event 430 439 */ 431 - static inline void 432 - da_handle_event(struct task_struct *tsk, enum events event) 440 + static inline void da_handle_event(struct task_struct *tsk, enum events event) 433 441 { 434 442 struct da_monitor *da_mon = da_get_monitor(tsk); 435 443 bool retval; ··· 450 460 * If the monitor already started, handle the event. 451 461 * If the monitor did not start yet, start the monitor but skip the event. 452 462 */ 453 - static inline bool 454 - da_handle_start_event(struct task_struct *tsk, enum events event) 463 + static inline bool da_handle_start_event(struct task_struct *tsk, 464 + enum events event) 455 465 { 456 466 struct da_monitor *da_mon; 457 467 ··· 476 486 * This function is used to notify the monitor that the system is in the 477 487 * initial state, so the monitor can start monitoring and handling event. 478 488 */ 479 - static inline bool 480 - da_handle_start_run_event(struct task_struct *tsk, enum events event) 489 + static inline bool da_handle_start_run_event(struct task_struct *tsk, 490 + enum events event) 481 491 { 482 492 struct da_monitor *da_mon; 483 493 ··· 493 503 494 504 return 1; 495 505 } 506 + #endif /* RV_MON_TYPE */ 507 + 496 508 #endif 497 - 498 - /* 499 - * Entry point for the global monitor. 500 - */ 501 - #define DECLARE_DA_MON_GLOBAL(name, type) 502 - 503 - /* 504 - * Entry point for the per-cpu monitor. 505 - */ 506 - #define DECLARE_DA_MON_PER_CPU(name, type) 507 - 508 - /* 509 - * Entry point for the per-task monitor. 510 - */ 511 - #define DECLARE_DA_MON_PER_TASK(name, type)