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.

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

+839 -912
+21 -23
Documentation/trace/rv/monitor_synthesis.rst
··· 100 100 101 101 This initial implementation presents three different types of monitor instances: 102 102 103 - - ``#define DECLARE_DA_MON_GLOBAL(name, type)`` 104 - - ``#define DECLARE_DA_MON_PER_CPU(name, type)`` 105 - - ``#define DECLARE_DA_MON_PER_TASK(name, type)`` 103 + - ``#define RV_MON_TYPE RV_MON_GLOBAL`` 104 + - ``#define RV_MON_TYPE RV_MON_PER_CPU`` 105 + - ``#define RV_MON_TYPE RV_MON_PER_TASK`` 106 106 107 - The first declares the functions for a global deterministic automata monitor, 108 - the second for monitors with per-cpu instances, and the third with per-task 109 - instances. 107 + The first sets up functions declaration for a global deterministic automata 108 + monitor, the second for monitors with per-cpu instances, and the third with 109 + per-task instances. 110 110 111 - In all cases, the 'name' argument is a string that identifies the monitor, and 112 - the 'type' argument is the data type used by rvgen on the representation of 113 - the model in C. 111 + In all cases, the C file must include the $(MODEL_NAME).h file (generated by 112 + `rvgen`), for example, to define the per-cpu 'wip' monitor, the `wip.c` source 113 + file must include:: 114 114 115 - For example, the wip model with two states and three events can be 116 - stored in an 'unsigned char' type. Considering that the preemption control 117 - is a per-cpu behavior, the monitor declaration in the 'wip.c' file is:: 118 - 119 - DECLARE_DA_MON_PER_CPU(wip, unsigned char); 115 + #define RV_MON_TYPE RV_MON_PER_CPU 116 + #include "wip.h" 117 + #include <rv/da_monitor.h> 120 118 121 119 The monitor is executed by sending events to be processed via the functions 122 120 presented below:: 123 121 124 - da_handle_event_$(MONITOR_NAME)($(event from event enum)); 125 - da_handle_start_event_$(MONITOR_NAME)($(event from event enum)); 126 - da_handle_start_run_event_$(MONITOR_NAME)($(event from event enum)); 122 + da_handle_event($(event from event enum)); 123 + da_handle_start_event($(event from event enum)); 124 + da_handle_start_run_event($(event from event enum)); 127 125 128 - The function ``da_handle_event_$(MONITOR_NAME)()`` is the regular case where 126 + The function ``da_handle_event()`` is the regular case where 129 127 the event will be processed if the monitor is processing events. 130 128 131 129 When a monitor is enabled, it is placed in the initial state of the automata. 132 130 However, the monitor does not know if the system is in the *initial state*. 133 131 134 - The ``da_handle_start_event_$(MONITOR_NAME)()`` function is used to notify the 132 + The ``da_handle_start_event()`` function is used to notify the 135 133 monitor that the system is returning to the initial state, so the monitor can 136 134 start monitoring the next event. 137 135 138 - The ``da_handle_start_run_event_$(MONITOR_NAME)()`` function is used to notify 136 + The ``da_handle_start_run_event()`` function is used to notify 139 137 the monitor that the system is known to be in the initial state, so the 140 138 monitor can start monitoring and monitor the current event. 141 139 142 140 Using the wip model as example, the events "preempt_disable" and 143 141 "sched_waking" should be sent to monitor, respectively, via [2]:: 144 142 145 - da_handle_event_wip(preempt_disable_wip); 146 - da_handle_event_wip(sched_waking_wip); 143 + da_handle_event(preempt_disable_wip); 144 + da_handle_event(sched_waking_wip); 147 145 148 146 While the event "preempt_enabled" will use:: 149 147 150 - da_handle_start_event_wip(preempt_enable_wip); 148 + da_handle_start_event(preempt_enable_wip); 151 149 152 150 To notify the monitor that the system will be returning to the initial state, 153 151 so the system and the monitor should be in sync.
+4
include/linux/rv.h
··· 10 10 #define MAX_DA_NAME_LEN 32 11 11 #define MAX_DA_RETRY_RACING_EVENTS 3 12 12 13 + #define RV_MON_GLOBAL 0 14 + #define RV_MON_PER_CPU 1 15 + #define RV_MON_PER_TASK 2 16 + 13 17 #ifdef CONFIG_RV 14 18 #include <linux/array_size.h> 15 19 #include <linux/bitops.h>
+70 -64
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 + 12 + #ifndef MONITOR_NAME 13 + #error "MONITOR_NAME macro is not defined. Did you include $(MODEL_NAME).h generated by rvgen?" 14 + #endif 15 + 16 + #define RV_AUTOMATON_NAME CONCATENATE(automaton_, MONITOR_NAME) 17 + #define EVENT_MAX CONCATENATE(event_max_, MONITOR_NAME) 18 + #define STATE_MAX CONCATENATE(state_max_, MONITOR_NAME) 19 + #define events CONCATENATE(events_, MONITOR_NAME) 20 + #define states CONCATENATE(states_, MONITOR_NAME) 21 + 9 22 /* 10 - * DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata 11 - * 12 - * Define a set of helper functions for automata. The 'name' argument is used 13 - * as suffix for the functions and data. These functions will handle automaton 14 - * with data type 'type'. 23 + * model_get_state_name - return the (string) name of the given state 15 24 */ 16 - #define DECLARE_AUTOMATA_HELPERS(name, type) \ 17 - \ 18 - /* \ 19 - * model_get_state_name_##name - return the (string) name of the given state \ 20 - */ \ 21 - static char *model_get_state_name_##name(enum states_##name state) \ 22 - { \ 23 - if ((state < 0) || (state >= state_max_##name)) \ 24 - return "INVALID"; \ 25 - \ 26 - return automaton_##name.state_names[state]; \ 27 - } \ 28 - \ 29 - /* \ 30 - * model_get_event_name_##name - return the (string) name of the given event \ 31 - */ \ 32 - static char *model_get_event_name_##name(enum events_##name event) \ 33 - { \ 34 - if ((event < 0) || (event >= event_max_##name)) \ 35 - return "INVALID"; \ 36 - \ 37 - return automaton_##name.event_names[event]; \ 38 - } \ 39 - \ 40 - /* \ 41 - * model_get_initial_state_##name - return the automaton's initial state \ 42 - */ \ 43 - static inline type model_get_initial_state_##name(void) \ 44 - { \ 45 - return automaton_##name.initial_state; \ 46 - } \ 47 - \ 48 - /* \ 49 - * model_get_next_state_##name - process an automaton event occurrence \ 50 - * \ 51 - * Given the current state (curr_state) and the event (event), returns \ 52 - * the next state, or INVALID_STATE in case of error. \ 53 - */ \ 54 - static inline type model_get_next_state_##name(enum states_##name curr_state, \ 55 - enum events_##name event) \ 56 - { \ 57 - if ((curr_state < 0) || (curr_state >= state_max_##name)) \ 58 - return INVALID_STATE; \ 59 - \ 60 - if ((event < 0) || (event >= event_max_##name)) \ 61 - return INVALID_STATE; \ 62 - \ 63 - return automaton_##name.function[curr_state][event]; \ 64 - } \ 65 - \ 66 - /* \ 67 - * model_is_final_state_##name - check if the given state is a final state \ 68 - */ \ 69 - static inline bool model_is_final_state_##name(enum states_##name state) \ 70 - { \ 71 - if ((state < 0) || (state >= state_max_##name)) \ 72 - return 0; \ 73 - \ 74 - return automaton_##name.final_states[state]; \ 25 + static char *model_get_state_name(enum states state) 26 + { 27 + if ((state < 0) || (state >= STATE_MAX)) 28 + return "INVALID"; 29 + 30 + return RV_AUTOMATON_NAME.state_names[state]; 75 31 } 32 + 33 + /* 34 + * model_get_event_name - return the (string) name of the given event 35 + */ 36 + static char *model_get_event_name(enum events event) 37 + { 38 + if ((event < 0) || (event >= EVENT_MAX)) 39 + return "INVALID"; 40 + 41 + return RV_AUTOMATON_NAME.event_names[event]; 42 + } 43 + 44 + /* 45 + * model_get_initial_state - return the automaton's initial state 46 + */ 47 + static inline enum states model_get_initial_state(void) 48 + { 49 + return RV_AUTOMATON_NAME.initial_state; 50 + } 51 + 52 + /* 53 + * model_get_next_state - process an automaton event occurrence 54 + * 55 + * Given the current state (curr_state) and the event (event), returns 56 + * the next state, or INVALID_STATE in case of error. 57 + */ 58 + static inline enum states model_get_next_state(enum states curr_state, 59 + enum events event) 60 + { 61 + if ((curr_state < 0) || (curr_state >= STATE_MAX)) 62 + return INVALID_STATE; 63 + 64 + if ((event < 0) || (event >= EVENT_MAX)) 65 + return INVALID_STATE; 66 + 67 + return RV_AUTOMATON_NAME.function[curr_state][event]; 68 + } 69 + 70 + /* 71 + * model_is_final_state - check if the given state is a final state 72 + */ 73 + static inline bool model_is_final_state(enum states state) 74 + { 75 + if ((state < 0) || (state >= STATE_MAX)) 76 + return 0; 77 + 78 + return RV_AUTOMATON_NAME.final_states[state]; 79 + } 80 + 81 + #endif
+429 -464
include/rv/da_monitor.h
··· 8 8 * The dot2k tool is available at tools/verification/dot2k/ 9 9 * 10 10 * For further information, see: 11 - * Documentation/trace/rv/da_monitor_synthesis.rst 11 + * Documentation/trace/rv/monitor_synthesis.rst 12 12 */ 13 + 14 + #ifndef _RV_DA_MONITOR_H 15 + #define _RV_DA_MONITOR_H 13 16 14 17 #include <rv/automata.h> 15 18 #include <linux/rv.h> 19 + #include <linux/stringify.h> 16 20 #include <linux/bug.h> 17 21 #include <linux/sched.h> 18 22 19 - /* 20 - * Generic helpers for all types of deterministic automata monitors. 21 - */ 22 - #define DECLARE_DA_MON_GENERIC_HELPERS(name, type) \ 23 - \ 24 - static void react_##name(type curr_state, type event) \ 25 - { \ 26 - rv_react(&rv_##name, \ 27 - "rv: monitor %s does not allow event %s on state %s\n", \ 28 - #name, \ 29 - model_get_event_name_##name(event), \ 30 - model_get_state_name_##name(curr_state)); \ 31 - } \ 32 - \ 33 - /* \ 34 - * da_monitor_reset_##name - reset a monitor and setting it to init state \ 35 - */ \ 36 - static inline void da_monitor_reset_##name(struct da_monitor *da_mon) \ 37 - { \ 38 - da_mon->monitoring = 0; \ 39 - da_mon->curr_state = model_get_initial_state_##name(); \ 40 - } \ 41 - \ 42 - /* \ 43 - * da_monitor_start_##name - start monitoring \ 44 - * \ 45 - * The monitor will ignore all events until monitoring is set to true. This \ 46 - * function needs to be called to tell the monitor to start monitoring. \ 47 - */ \ 48 - static inline void da_monitor_start_##name(struct da_monitor *da_mon) \ 49 - { \ 50 - da_mon->curr_state = model_get_initial_state_##name(); \ 51 - da_mon->monitoring = 1; \ 52 - } \ 53 - \ 54 - /* \ 55 - * da_monitoring_##name - returns true if the monitor is processing events \ 56 - */ \ 57 - static inline bool da_monitoring_##name(struct da_monitor *da_mon) \ 58 - { \ 59 - return da_mon->monitoring; \ 60 - } \ 61 - \ 62 - /* \ 63 - * da_monitor_enabled_##name - checks if the monitor is enabled \ 64 - */ \ 65 - static inline bool da_monitor_enabled_##name(void) \ 66 - { \ 67 - /* global switch */ \ 68 - if (unlikely(!rv_monitoring_on())) \ 69 - return 0; \ 70 - \ 71 - /* monitor enabled */ \ 72 - if (unlikely(!rv_##name.enabled)) \ 73 - return 0; \ 74 - \ 75 - return 1; \ 76 - } \ 77 - \ 78 - /* \ 79 - * da_monitor_handling_event_##name - checks if the monitor is ready to handle events \ 80 - */ \ 81 - static inline bool da_monitor_handling_event_##name(struct da_monitor *da_mon) \ 82 - { \ 83 - \ 84 - if (!da_monitor_enabled_##name()) \ 85 - return 0; \ 86 - \ 87 - /* monitor is actually monitoring */ \ 88 - if (unlikely(!da_monitoring_##name(da_mon))) \ 89 - return 0; \ 90 - \ 91 - return 1; \ 23 + static struct rv_monitor rv_this; 24 + 25 + static void react(enum states curr_state, enum events event) 26 + { 27 + rv_react(&rv_this, 28 + "rv: monitor %s does not allow event %s on state %s\n", 29 + __stringify(MONITOR_NAME), 30 + model_get_event_name(event), 31 + model_get_state_name(curr_state)); 92 32 } 93 33 34 + /* 35 + * da_monitor_reset - reset a monitor and setting it to init state 36 + */ 37 + static inline void da_monitor_reset(struct da_monitor *da_mon) 38 + { 39 + da_mon->monitoring = 0; 40 + da_mon->curr_state = model_get_initial_state(); 41 + } 42 + 43 + /* 44 + * da_monitor_start - start monitoring 45 + * 46 + * The monitor will ignore all events until monitoring is set to true. This 47 + * function needs to be called to tell the monitor to start monitoring. 48 + */ 49 + static inline void da_monitor_start(struct da_monitor *da_mon) 50 + { 51 + da_mon->curr_state = model_get_initial_state(); 52 + da_mon->monitoring = 1; 53 + } 54 + 55 + /* 56 + * da_monitoring - returns true if the monitor is processing events 57 + */ 58 + static inline bool da_monitoring(struct da_monitor *da_mon) 59 + { 60 + return da_mon->monitoring; 61 + } 62 + 63 + /* 64 + * da_monitor_enabled - checks if the monitor is enabled 65 + */ 66 + static inline bool da_monitor_enabled(void) 67 + { 68 + /* global switch */ 69 + if (unlikely(!rv_monitoring_on())) 70 + return 0; 71 + 72 + /* monitor enabled */ 73 + if (unlikely(!rv_this.enabled)) 74 + return 0; 75 + 76 + return 1; 77 + } 78 + 79 + /* 80 + * da_monitor_handling_event - checks if the monitor is ready to handle events 81 + */ 82 + static inline bool da_monitor_handling_event(struct da_monitor *da_mon) 83 + { 84 + if (!da_monitor_enabled()) 85 + return 0; 86 + 87 + /* monitor is actually monitoring */ 88 + if (unlikely(!da_monitoring(da_mon))) 89 + return 0; 90 + 91 + return 1; 92 + } 93 + 94 + #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 94 95 /* 95 96 * Event handler for implicit monitors. Implicit monitor is the one which the 96 97 * handler does not need to specify which da_monitor to manipulate. Examples ··· 101 100 * warn and reset the monitor if it runs out of retries. The monitor should be 102 101 * able to handle various orders. 103 102 */ 104 - #define DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type) \ 105 - \ 106 - static inline bool \ 107 - da_event_##name(struct da_monitor *da_mon, enum events_##name event) \ 108 - { \ 109 - enum states_##name curr_state, next_state; \ 110 - \ 111 - curr_state = READ_ONCE(da_mon->curr_state); \ 112 - for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { \ 113 - next_state = model_get_next_state_##name(curr_state, event); \ 114 - if (next_state == INVALID_STATE) { \ 115 - react_##name(curr_state, event); \ 116 - trace_error_##name(model_get_state_name_##name(curr_state), \ 117 - model_get_event_name_##name(event)); \ 118 - return false; \ 119 - } \ 120 - if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { \ 121 - trace_event_##name(model_get_state_name_##name(curr_state), \ 122 - model_get_event_name_##name(event), \ 123 - model_get_state_name_##name(next_state), \ 124 - model_is_final_state_##name(next_state)); \ 125 - return true; \ 126 - } \ 127 - } \ 128 - \ 129 - trace_rv_retries_error(#name, model_get_event_name_##name(event)); \ 130 - pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) \ 131 - " retries reached for event %s, resetting monitor %s", \ 132 - model_get_event_name_##name(event), #name); \ 133 - return false; \ 134 - } \ 135 103 104 + static inline bool da_event(struct da_monitor *da_mon, enum events event) 105 + { 106 + enum states curr_state, next_state; 107 + 108 + curr_state = READ_ONCE(da_mon->curr_state); 109 + for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { 110 + next_state = model_get_next_state(curr_state, event); 111 + if (next_state == INVALID_STATE) { 112 + react(curr_state, event); 113 + CONCATENATE(trace_error_, MONITOR_NAME)( 114 + model_get_state_name(curr_state), 115 + model_get_event_name(event)); 116 + return false; 117 + } 118 + if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { 119 + CONCATENATE(trace_event_, MONITOR_NAME)( 120 + model_get_state_name(curr_state), 121 + model_get_event_name(event), 122 + model_get_state_name(next_state), 123 + model_is_final_state(next_state)); 124 + return true; 125 + } 126 + } 127 + 128 + trace_rv_retries_error(__stringify(MONITOR_NAME), model_get_event_name(event)); 129 + pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) 130 + " retries reached for event %s, resetting monitor %s", 131 + model_get_event_name(event), __stringify(MONITOR_NAME)); 132 + return false; 133 + } 134 + 135 + #elif RV_MON_TYPE == RV_MON_PER_TASK 136 136 /* 137 137 * Event handler for per_task monitors. 138 138 * ··· 141 139 * warn and reset the monitor if it runs out of retries. The monitor should be 142 140 * able to handle various orders. 143 141 */ 144 - #define DECLARE_DA_MON_MODEL_HANDLER_PER_TASK(name, type) \ 145 - \ 146 - static inline bool da_event_##name(struct da_monitor *da_mon, struct task_struct *tsk, \ 147 - enum events_##name event) \ 148 - { \ 149 - enum states_##name curr_state, next_state; \ 150 - \ 151 - curr_state = READ_ONCE(da_mon->curr_state); \ 152 - for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { \ 153 - next_state = model_get_next_state_##name(curr_state, event); \ 154 - if (next_state == INVALID_STATE) { \ 155 - react_##name(curr_state, event); \ 156 - trace_error_##name(tsk->pid, \ 157 - model_get_state_name_##name(curr_state), \ 158 - model_get_event_name_##name(event)); \ 159 - return false; \ 160 - } \ 161 - if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { \ 162 - trace_event_##name(tsk->pid, \ 163 - model_get_state_name_##name(curr_state), \ 164 - model_get_event_name_##name(event), \ 165 - model_get_state_name_##name(next_state), \ 166 - model_is_final_state_##name(next_state)); \ 167 - return true; \ 168 - } \ 169 - } \ 170 - \ 171 - trace_rv_retries_error(#name, model_get_event_name_##name(event)); \ 172 - pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) \ 173 - " retries reached for event %s, resetting monitor %s", \ 174 - model_get_event_name_##name(event), #name); \ 175 - return false; \ 176 - } 177 142 143 + static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk, 144 + enum events event) 145 + { 146 + enum states curr_state, next_state; 147 + 148 + curr_state = READ_ONCE(da_mon->curr_state); 149 + for (int i = 0; i < MAX_DA_RETRY_RACING_EVENTS; i++) { 150 + next_state = model_get_next_state(curr_state, event); 151 + if (next_state == INVALID_STATE) { 152 + react(curr_state, event); 153 + CONCATENATE(trace_error_, MONITOR_NAME)(tsk->pid, 154 + model_get_state_name(curr_state), 155 + model_get_event_name(event)); 156 + return false; 157 + } 158 + if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) { 159 + CONCATENATE(trace_event_, MONITOR_NAME)(tsk->pid, 160 + model_get_state_name(curr_state), 161 + model_get_event_name(event), 162 + model_get_state_name(next_state), 163 + model_is_final_state(next_state)); 164 + return true; 165 + } 166 + } 167 + 168 + trace_rv_retries_error(__stringify(MONITOR_NAME), model_get_event_name(event)); 169 + pr_warn("rv: " __stringify(MAX_DA_RETRY_RACING_EVENTS) 170 + " retries reached for event %s, resetting monitor %s", 171 + model_get_event_name(event), __stringify(MONITOR_NAME)); 172 + return false; 173 + } 174 + #endif /* RV_MON_TYPE */ 175 + 176 + #if RV_MON_TYPE == RV_MON_GLOBAL 178 177 /* 179 178 * Functions to define, init and get a global monitor. 180 179 */ 181 - #define DECLARE_DA_MON_INIT_GLOBAL(name, type) \ 182 - \ 183 - /* \ 184 - * global monitor (a single variable) \ 185 - */ \ 186 - static struct da_monitor da_mon_##name; \ 187 - \ 188 - /* \ 189 - * da_get_monitor_##name - return the global monitor address \ 190 - */ \ 191 - static struct da_monitor *da_get_monitor_##name(void) \ 192 - { \ 193 - return &da_mon_##name; \ 194 - } \ 195 - \ 196 - /* \ 197 - * da_monitor_reset_all_##name - reset the single monitor \ 198 - */ \ 199 - static void da_monitor_reset_all_##name(void) \ 200 - { \ 201 - da_monitor_reset_##name(da_get_monitor_##name()); \ 202 - } \ 203 - \ 204 - /* \ 205 - * da_monitor_init_##name - initialize a monitor \ 206 - */ \ 207 - static inline int da_monitor_init_##name(void) \ 208 - { \ 209 - da_monitor_reset_all_##name(); \ 210 - return 0; \ 211 - } \ 212 - \ 213 - /* \ 214 - * da_monitor_destroy_##name - destroy the monitor \ 215 - */ \ 216 - static inline void da_monitor_destroy_##name(void) \ 217 - { \ 218 - return; \ 180 + 181 + /* 182 + * global monitor (a single variable) 183 + */ 184 + static struct da_monitor da_mon_this; 185 + 186 + /* 187 + * da_get_monitor - return the global monitor address 188 + */ 189 + static struct da_monitor *da_get_monitor(void) 190 + { 191 + return &da_mon_this; 219 192 } 220 193 194 + /* 195 + * da_monitor_reset_all - reset the single monitor 196 + */ 197 + static void da_monitor_reset_all(void) 198 + { 199 + da_monitor_reset(da_get_monitor()); 200 + } 201 + 202 + /* 203 + * da_monitor_init - initialize a monitor 204 + */ 205 + static inline int da_monitor_init(void) 206 + { 207 + da_monitor_reset_all(); 208 + return 0; 209 + } 210 + 211 + /* 212 + * da_monitor_destroy - destroy the monitor 213 + */ 214 + static inline void da_monitor_destroy(void) { } 215 + 216 + #elif RV_MON_TYPE == RV_MON_PER_CPU 221 217 /* 222 218 * Functions to define, init and get a per-cpu monitor. 223 219 */ 224 - #define DECLARE_DA_MON_INIT_PER_CPU(name, type) \ 225 - \ 226 - /* \ 227 - * per-cpu monitor variables \ 228 - */ \ 229 - static DEFINE_PER_CPU(struct da_monitor, da_mon_##name); \ 230 - \ 231 - /* \ 232 - * da_get_monitor_##name - return current CPU monitor address \ 233 - */ \ 234 - static struct da_monitor *da_get_monitor_##name(void) \ 235 - { \ 236 - return this_cpu_ptr(&da_mon_##name); \ 237 - } \ 238 - \ 239 - /* \ 240 - * da_monitor_reset_all_##name - reset all CPUs' monitor \ 241 - */ \ 242 - static void da_monitor_reset_all_##name(void) \ 243 - { \ 244 - struct da_monitor *da_mon; \ 245 - int cpu; \ 246 - for_each_cpu(cpu, cpu_online_mask) { \ 247 - da_mon = per_cpu_ptr(&da_mon_##name, cpu); \ 248 - da_monitor_reset_##name(da_mon); \ 249 - } \ 250 - } \ 251 - \ 252 - /* \ 253 - * da_monitor_init_##name - initialize all CPUs' monitor \ 254 - */ \ 255 - static inline int da_monitor_init_##name(void) \ 256 - { \ 257 - da_monitor_reset_all_##name(); \ 258 - return 0; \ 259 - } \ 260 - \ 261 - /* \ 262 - * da_monitor_destroy_##name - destroy the monitor \ 263 - */ \ 264 - static inline void da_monitor_destroy_##name(void) \ 265 - { \ 266 - return; \ 220 + 221 + /* 222 + * per-cpu monitor variables 223 + */ 224 + static DEFINE_PER_CPU(struct da_monitor, da_mon_this); 225 + 226 + /* 227 + * da_get_monitor - return current CPU monitor address 228 + */ 229 + static struct da_monitor *da_get_monitor(void) 230 + { 231 + return this_cpu_ptr(&da_mon_this); 267 232 } 268 233 234 + /* 235 + * da_monitor_reset_all - reset all CPUs' monitor 236 + */ 237 + static void da_monitor_reset_all(void) 238 + { 239 + struct da_monitor *da_mon; 240 + int cpu; 241 + 242 + for_each_cpu(cpu, cpu_online_mask) { 243 + da_mon = per_cpu_ptr(&da_mon_this, cpu); 244 + da_monitor_reset(da_mon); 245 + } 246 + } 247 + 248 + /* 249 + * da_monitor_init - initialize all CPUs' monitor 250 + */ 251 + static inline int da_monitor_init(void) 252 + { 253 + da_monitor_reset_all(); 254 + return 0; 255 + } 256 + 257 + /* 258 + * da_monitor_destroy - destroy the monitor 259 + */ 260 + static inline void da_monitor_destroy(void) { } 261 + 262 + #elif RV_MON_TYPE == RV_MON_PER_TASK 269 263 /* 270 264 * Functions to define, init and get a per-task monitor. 271 265 */ 272 - #define DECLARE_DA_MON_INIT_PER_TASK(name, type) \ 273 - \ 274 - /* \ 275 - * The per-task monitor is stored a vector in the task struct. This variable \ 276 - * stores the position on the vector reserved for this monitor. \ 277 - */ \ 278 - static int task_mon_slot_##name = RV_PER_TASK_MONITOR_INIT; \ 279 - \ 280 - /* \ 281 - * da_get_monitor_##name - return the monitor in the allocated slot for tsk \ 282 - */ \ 283 - static inline struct da_monitor *da_get_monitor_##name(struct task_struct *tsk) \ 284 - { \ 285 - return &tsk->rv[task_mon_slot_##name].da_mon; \ 286 - } \ 287 - \ 288 - static void da_monitor_reset_all_##name(void) \ 289 - { \ 290 - struct task_struct *g, *p; \ 291 - int cpu; \ 292 - \ 293 - read_lock(&tasklist_lock); \ 294 - for_each_process_thread(g, p) \ 295 - da_monitor_reset_##name(da_get_monitor_##name(p)); \ 296 - for_each_present_cpu(cpu) \ 297 - da_monitor_reset_##name(da_get_monitor_##name(idle_task(cpu))); \ 298 - read_unlock(&tasklist_lock); \ 299 - } \ 300 - \ 301 - /* \ 302 - * da_monitor_init_##name - initialize the per-task monitor \ 303 - * \ 304 - * Try to allocate a slot in the task's vector of monitors. If there \ 305 - * is an available slot, use it and reset all task's monitor. \ 306 - */ \ 307 - static int da_monitor_init_##name(void) \ 308 - { \ 309 - int slot; \ 310 - \ 311 - slot = rv_get_task_monitor_slot(); \ 312 - if (slot < 0 || slot >= RV_PER_TASK_MONITOR_INIT) \ 313 - return slot; \ 314 - \ 315 - task_mon_slot_##name = slot; \ 316 - \ 317 - da_monitor_reset_all_##name(); \ 318 - return 0; \ 319 - } \ 320 - \ 321 - /* \ 322 - * da_monitor_destroy_##name - return the allocated slot \ 323 - */ \ 324 - static inline void da_monitor_destroy_##name(void) \ 325 - { \ 326 - if (task_mon_slot_##name == RV_PER_TASK_MONITOR_INIT) { \ 327 - WARN_ONCE(1, "Disabling a disabled monitor: " #name); \ 328 - return; \ 329 - } \ 330 - rv_put_task_monitor_slot(task_mon_slot_##name); \ 331 - task_mon_slot_##name = RV_PER_TASK_MONITOR_INIT; \ 332 - return; \ 266 + 267 + /* 268 + * The per-task monitor is stored a vector in the task struct. This variable 269 + * stores the position on the vector reserved for this monitor. 270 + */ 271 + static int task_mon_slot = RV_PER_TASK_MONITOR_INIT; 272 + 273 + /* 274 + * da_get_monitor - return the monitor in the allocated slot for tsk 275 + */ 276 + static inline struct da_monitor *da_get_monitor(struct task_struct *tsk) 277 + { 278 + return &tsk->rv[task_mon_slot].da_mon; 279 + } 280 + 281 + static void da_monitor_reset_all(void) 282 + { 283 + struct task_struct *g, *p; 284 + int cpu; 285 + 286 + read_lock(&tasklist_lock); 287 + for_each_process_thread(g, p) 288 + da_monitor_reset(da_get_monitor(p)); 289 + for_each_present_cpu(cpu) 290 + da_monitor_reset(da_get_monitor(idle_task(cpu))); 291 + read_unlock(&tasklist_lock); 333 292 } 334 293 335 294 /* 336 - * Handle event for implicit monitor: da_get_monitor_##name() will figure out 337 - * the monitor. 295 + * da_monitor_init - initialize the per-task monitor 296 + * 297 + * Try to allocate a slot in the task's vector of monitors. If there 298 + * is an available slot, use it and reset all task's monitor. 338 299 */ 339 - #define DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type) \ 340 - \ 341 - static inline void __da_handle_event_##name(struct da_monitor *da_mon, \ 342 - enum events_##name event) \ 343 - { \ 344 - bool retval; \ 345 - \ 346 - retval = da_event_##name(da_mon, event); \ 347 - if (!retval) \ 348 - da_monitor_reset_##name(da_mon); \ 349 - } \ 350 - \ 351 - /* \ 352 - * da_handle_event_##name - handle an event \ 353 - */ \ 354 - static inline void da_handle_event_##name(enum events_##name event) \ 355 - { \ 356 - struct da_monitor *da_mon = da_get_monitor_##name(); \ 357 - bool retval; \ 358 - \ 359 - retval = da_monitor_handling_event_##name(da_mon); \ 360 - if (!retval) \ 361 - return; \ 362 - \ 363 - __da_handle_event_##name(da_mon, event); \ 364 - } \ 365 - \ 366 - /* \ 367 - * da_handle_start_event_##name - start monitoring or handle event \ 368 - * \ 369 - * This function is used to notify the monitor that the system is returning \ 370 - * to the initial state, so the monitor can start monitoring in the next event. \ 371 - * Thus: \ 372 - * \ 373 - * If the monitor already started, handle the event. \ 374 - * If the monitor did not start yet, start the monitor but skip the event. \ 375 - */ \ 376 - static inline bool da_handle_start_event_##name(enum events_##name event) \ 377 - { \ 378 - struct da_monitor *da_mon; \ 379 - \ 380 - if (!da_monitor_enabled_##name()) \ 381 - return 0; \ 382 - \ 383 - da_mon = da_get_monitor_##name(); \ 384 - \ 385 - if (unlikely(!da_monitoring_##name(da_mon))) { \ 386 - da_monitor_start_##name(da_mon); \ 387 - return 0; \ 388 - } \ 389 - \ 390 - __da_handle_event_##name(da_mon, event); \ 391 - \ 392 - return 1; \ 393 - } \ 394 - \ 395 - /* \ 396 - * da_handle_start_run_event_##name - start monitoring and handle event \ 397 - * \ 398 - * This function is used to notify the monitor that the system is in the \ 399 - * initial state, so the monitor can start monitoring and handling event. \ 400 - */ \ 401 - static inline bool da_handle_start_run_event_##name(enum events_##name event) \ 402 - { \ 403 - struct da_monitor *da_mon; \ 404 - \ 405 - if (!da_monitor_enabled_##name()) \ 406 - return 0; \ 407 - \ 408 - da_mon = da_get_monitor_##name(); \ 409 - \ 410 - if (unlikely(!da_monitoring_##name(da_mon))) \ 411 - da_monitor_start_##name(da_mon); \ 412 - \ 413 - __da_handle_event_##name(da_mon, event); \ 414 - \ 415 - return 1; \ 300 + static int da_monitor_init(void) 301 + { 302 + int slot; 303 + 304 + slot = rv_get_task_monitor_slot(); 305 + if (slot < 0 || slot >= RV_PER_TASK_MONITOR_INIT) 306 + return slot; 307 + 308 + task_mon_slot = slot; 309 + 310 + da_monitor_reset_all(); 311 + return 0; 416 312 } 417 313 314 + /* 315 + * da_monitor_destroy - return the allocated slot 316 + */ 317 + static inline void da_monitor_destroy(void) 318 + { 319 + if (task_mon_slot == RV_PER_TASK_MONITOR_INIT) { 320 + WARN_ONCE(1, "Disabling a disabled monitor: " __stringify(MONITOR_NAME)); 321 + return; 322 + } 323 + rv_put_task_monitor_slot(task_mon_slot); 324 + task_mon_slot = RV_PER_TASK_MONITOR_INIT; 325 + } 326 + #endif /* RV_MON_TYPE */ 327 + 328 + #if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU 329 + /* 330 + * Handle event for implicit monitor: da_get_monitor() will figure out 331 + * the monitor. 332 + */ 333 + 334 + static inline void __da_handle_event(struct da_monitor *da_mon, 335 + enum events event) 336 + { 337 + bool retval; 338 + 339 + retval = da_event(da_mon, event); 340 + if (!retval) 341 + da_monitor_reset(da_mon); 342 + } 343 + 344 + /* 345 + * da_handle_event - handle an event 346 + */ 347 + static inline void da_handle_event(enum events event) 348 + { 349 + struct da_monitor *da_mon = da_get_monitor(); 350 + bool retval; 351 + 352 + retval = da_monitor_handling_event(da_mon); 353 + if (!retval) 354 + return; 355 + 356 + __da_handle_event(da_mon, event); 357 + } 358 + 359 + /* 360 + * da_handle_start_event - start monitoring or handle event 361 + * 362 + * This function is used to notify the monitor that the system is returning 363 + * to the initial state, so the monitor can start monitoring in the next event. 364 + * Thus: 365 + * 366 + * If the monitor already started, handle the event. 367 + * If the monitor did not start yet, start the monitor but skip the event. 368 + */ 369 + static inline bool da_handle_start_event(enum events event) 370 + { 371 + struct da_monitor *da_mon; 372 + 373 + if (!da_monitor_enabled()) 374 + return 0; 375 + 376 + da_mon = da_get_monitor(); 377 + 378 + if (unlikely(!da_monitoring(da_mon))) { 379 + da_monitor_start(da_mon); 380 + return 0; 381 + } 382 + 383 + __da_handle_event(da_mon, event); 384 + 385 + return 1; 386 + } 387 + 388 + /* 389 + * da_handle_start_run_event - start monitoring and handle event 390 + * 391 + * This function is used to notify the monitor that the system is in the 392 + * initial state, so the monitor can start monitoring and handling event. 393 + */ 394 + static inline bool da_handle_start_run_event(enum events event) 395 + { 396 + struct da_monitor *da_mon; 397 + 398 + if (!da_monitor_enabled()) 399 + return 0; 400 + 401 + da_mon = da_get_monitor(); 402 + 403 + if (unlikely(!da_monitoring(da_mon))) 404 + da_monitor_start(da_mon); 405 + 406 + __da_handle_event(da_mon, event); 407 + 408 + return 1; 409 + } 410 + 411 + #elif RV_MON_TYPE == RV_MON_PER_TASK 418 412 /* 419 413 * Handle event for per task. 420 414 */ 421 - #define DECLARE_DA_MON_MONITOR_HANDLER_PER_TASK(name, type) \ 422 - \ 423 - static inline void \ 424 - __da_handle_event_##name(struct da_monitor *da_mon, struct task_struct *tsk, \ 425 - enum events_##name event) \ 426 - { \ 427 - bool retval; \ 428 - \ 429 - retval = da_event_##name(da_mon, tsk, event); \ 430 - if (!retval) \ 431 - da_monitor_reset_##name(da_mon); \ 432 - } \ 433 - \ 434 - /* \ 435 - * da_handle_event_##name - handle an event \ 436 - */ \ 437 - static inline void \ 438 - da_handle_event_##name(struct task_struct *tsk, enum events_##name event) \ 439 - { \ 440 - struct da_monitor *da_mon = da_get_monitor_##name(tsk); \ 441 - bool retval; \ 442 - \ 443 - retval = da_monitor_handling_event_##name(da_mon); \ 444 - if (!retval) \ 445 - return; \ 446 - \ 447 - __da_handle_event_##name(da_mon, tsk, event); \ 448 - } \ 449 - \ 450 - /* \ 451 - * da_handle_start_event_##name - start monitoring or handle event \ 452 - * \ 453 - * This function is used to notify the monitor that the system is returning \ 454 - * to the initial state, so the monitor can start monitoring in the next event. \ 455 - * Thus: \ 456 - * \ 457 - * If the monitor already started, handle the event. \ 458 - * If the monitor did not start yet, start the monitor but skip the event. \ 459 - */ \ 460 - static inline bool \ 461 - da_handle_start_event_##name(struct task_struct *tsk, enum events_##name event) \ 462 - { \ 463 - struct da_monitor *da_mon; \ 464 - \ 465 - if (!da_monitor_enabled_##name()) \ 466 - return 0; \ 467 - \ 468 - da_mon = da_get_monitor_##name(tsk); \ 469 - \ 470 - if (unlikely(!da_monitoring_##name(da_mon))) { \ 471 - da_monitor_start_##name(da_mon); \ 472 - return 0; \ 473 - } \ 474 - \ 475 - __da_handle_event_##name(da_mon, tsk, event); \ 476 - \ 477 - return 1; \ 478 - } \ 479 - \ 480 - /* \ 481 - * da_handle_start_run_event_##name - start monitoring and handle event \ 482 - * \ 483 - * This function is used to notify the monitor that the system is in the \ 484 - * initial state, so the monitor can start monitoring and handling event. \ 485 - */ \ 486 - static inline bool \ 487 - da_handle_start_run_event_##name(struct task_struct *tsk, enum events_##name event) \ 488 - { \ 489 - struct da_monitor *da_mon; \ 490 - \ 491 - if (!da_monitor_enabled_##name()) \ 492 - return 0; \ 493 - \ 494 - da_mon = da_get_monitor_##name(tsk); \ 495 - \ 496 - if (unlikely(!da_monitoring_##name(da_mon))) \ 497 - da_monitor_start_##name(da_mon); \ 498 - \ 499 - __da_handle_event_##name(da_mon, tsk, event); \ 500 - \ 501 - return 1; \ 415 + 416 + static inline void __da_handle_event(struct da_monitor *da_mon, 417 + struct task_struct *tsk, enum events event) 418 + { 419 + bool retval; 420 + 421 + retval = da_event(da_mon, tsk, event); 422 + if (!retval) 423 + da_monitor_reset(da_mon); 502 424 } 503 425 504 426 /* 505 - * Entry point for the global monitor. 427 + * da_handle_event - handle an event 506 428 */ 507 - #define DECLARE_DA_MON_GLOBAL(name, type) \ 508 - \ 509 - DECLARE_AUTOMATA_HELPERS(name, type) \ 510 - DECLARE_DA_MON_GENERIC_HELPERS(name, type) \ 511 - DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type) \ 512 - DECLARE_DA_MON_INIT_GLOBAL(name, type) \ 513 - DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type) 429 + static inline void da_handle_event(struct task_struct *tsk, enum events event) 430 + { 431 + struct da_monitor *da_mon = da_get_monitor(tsk); 432 + bool retval; 433 + 434 + retval = da_monitor_handling_event(da_mon); 435 + if (!retval) 436 + return; 437 + 438 + __da_handle_event(da_mon, tsk, event); 439 + } 514 440 515 441 /* 516 - * Entry point for the per-cpu monitor. 442 + * da_handle_start_event - start monitoring or handle event 443 + * 444 + * This function is used to notify the monitor that the system is returning 445 + * to the initial state, so the monitor can start monitoring in the next event. 446 + * Thus: 447 + * 448 + * If the monitor already started, handle the event. 449 + * If the monitor did not start yet, start the monitor but skip the event. 517 450 */ 518 - #define DECLARE_DA_MON_PER_CPU(name, type) \ 519 - \ 520 - DECLARE_AUTOMATA_HELPERS(name, type) \ 521 - DECLARE_DA_MON_GENERIC_HELPERS(name, type) \ 522 - DECLARE_DA_MON_MODEL_HANDLER_IMPLICIT(name, type) \ 523 - DECLARE_DA_MON_INIT_PER_CPU(name, type) \ 524 - DECLARE_DA_MON_MONITOR_HANDLER_IMPLICIT(name, type) 451 + static inline bool da_handle_start_event(struct task_struct *tsk, 452 + enum events event) 453 + { 454 + struct da_monitor *da_mon; 455 + 456 + if (!da_monitor_enabled()) 457 + return 0; 458 + 459 + da_mon = da_get_monitor(tsk); 460 + 461 + if (unlikely(!da_monitoring(da_mon))) { 462 + da_monitor_start(da_mon); 463 + return 0; 464 + } 465 + 466 + __da_handle_event(da_mon, tsk, event); 467 + 468 + return 1; 469 + } 525 470 526 471 /* 527 - * Entry point for the per-task monitor. 472 + * da_handle_start_run_event - start monitoring and handle event 473 + * 474 + * This function is used to notify the monitor that the system is in the 475 + * initial state, so the monitor can start monitoring and handling event. 528 476 */ 529 - #define DECLARE_DA_MON_PER_TASK(name, type) \ 530 - \ 531 - DECLARE_AUTOMATA_HELPERS(name, type) \ 532 - DECLARE_DA_MON_GENERIC_HELPERS(name, type) \ 533 - DECLARE_DA_MON_MODEL_HANDLER_PER_TASK(name, type) \ 534 - DECLARE_DA_MON_INIT_PER_TASK(name, type) \ 535 - DECLARE_DA_MON_MONITOR_HANDLER_PER_TASK(name, type) 477 + static inline bool da_handle_start_run_event(struct task_struct *tsk, 478 + enum events event) 479 + { 480 + struct da_monitor *da_mon; 481 + 482 + if (!da_monitor_enabled()) 483 + return 0; 484 + 485 + da_mon = da_get_monitor(tsk); 486 + 487 + if (unlikely(!da_monitoring(da_mon))) 488 + da_monitor_start(da_mon); 489 + 490 + __da_handle_event(da_mon, tsk, event); 491 + 492 + return 1; 493 + } 494 + #endif /* RV_MON_TYPE */ 495 + 496 + #endif
+14 -16
kernel/trace/rv/monitors/nrp/nrp.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "nrp" 12 11 ··· 14 15 #include <rv_trace.h> 15 16 #include <monitors/sched/sched.h> 16 17 18 + #define RV_MON_TYPE RV_MON_PER_TASK 17 19 #include "nrp.h" 18 - 19 - static struct rv_monitor rv_nrp; 20 - DECLARE_DA_MON_PER_TASK(nrp, unsigned char); 20 + #include <rv/da_monitor.h> 21 21 22 22 #ifdef CONFIG_X86_LOCAL_APIC 23 23 #include <asm/trace/irq_vectors.h> 24 24 25 25 static void handle_vector_irq_entry(void *data, int vector) 26 26 { 27 - da_handle_event_nrp(current, irq_entry_nrp); 27 + da_handle_event(current, irq_entry_nrp); 28 28 } 29 29 30 30 static void attach_vector_irq(void) ··· 58 60 59 61 static void handle_irq_entry(void *data, int irq, struct irqaction *action) 60 62 { 61 - da_handle_event_nrp(current, irq_entry_nrp); 63 + da_handle_event(current, irq_entry_nrp); 62 64 } 63 65 64 66 static void handle_sched_need_resched(void *data, struct task_struct *tsk, ··· 70 72 * which may not mirror the system state but makes the monitor simpler, 71 73 */ 72 74 if (tif == TIF_NEED_RESCHED) 73 - da_handle_start_event_nrp(tsk, sched_need_resched_nrp); 75 + da_handle_start_event(tsk, sched_need_resched_nrp); 74 76 } 75 77 76 78 static void handle_schedule_entry(void *data, bool preempt) 77 79 { 78 80 if (preempt) 79 - da_handle_event_nrp(current, schedule_entry_preempt_nrp); 81 + da_handle_event(current, schedule_entry_preempt_nrp); 80 82 else 81 - da_handle_event_nrp(current, schedule_entry_nrp); 83 + da_handle_event(current, schedule_entry_nrp); 82 84 } 83 85 84 86 static int enable_nrp(void) 85 87 { 86 88 int retval; 87 89 88 - retval = da_monitor_init_nrp(); 90 + retval = da_monitor_init(); 89 91 if (retval) 90 92 return retval; 91 93 ··· 99 101 100 102 static void disable_nrp(void) 101 103 { 102 - rv_nrp.enabled = 0; 104 + rv_this.enabled = 0; 103 105 104 106 rv_detach_trace_probe("nrp", irq_handler_entry, handle_irq_entry); 105 107 rv_detach_trace_probe("nrp", sched_set_need_resched_tp, handle_sched_need_resched); 106 108 rv_detach_trace_probe("nrp", sched_entry_tp, handle_schedule_entry); 107 109 detach_vector_irq(); 108 110 109 - da_monitor_destroy_nrp(); 111 + da_monitor_destroy(); 110 112 } 111 113 112 - static struct rv_monitor rv_nrp = { 114 + static struct rv_monitor rv_this = { 113 115 .name = "nrp", 114 116 .description = "need resched preempts.", 115 117 .enable = enable_nrp, 116 118 .disable = disable_nrp, 117 - .reset = da_monitor_reset_all_nrp, 119 + .reset = da_monitor_reset_all, 118 120 .enabled = 0, 119 121 }; 120 122 121 123 static int __init register_nrp(void) 122 124 { 123 - return rv_register_monitor(&rv_nrp, &rv_sched); 125 + return rv_register_monitor(&rv_this, &rv_sched); 124 126 } 125 127 126 128 static void __exit unregister_nrp(void) 127 129 { 128 - rv_unregister_monitor(&rv_nrp); 130 + rv_unregister_monitor(&rv_this); 129 131 } 130 132 131 133 module_init(register_nrp);
+12 -10
kernel/trace/rv/monitors/nrp/nrp.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME nrp 9 + 8 10 enum states_nrp { 9 - preempt_irq_nrp = 0, 11 + preempt_irq_nrp, 10 12 any_thread_running_nrp, 11 13 nested_preempt_nrp, 12 14 rescheduling_nrp, 13 - state_max_nrp 15 + state_max_nrp, 14 16 }; 15 17 16 18 #define INVALID_STATE state_max_nrp 17 19 18 20 enum events_nrp { 19 - irq_entry_nrp = 0, 21 + irq_entry_nrp, 20 22 sched_need_resched_nrp, 21 23 schedule_entry_nrp, 22 24 schedule_entry_preempt_nrp, 23 - event_max_nrp 25 + event_max_nrp, 24 26 }; 25 27 26 28 struct automaton_nrp { ··· 38 36 "preempt_irq", 39 37 "any_thread_running", 40 38 "nested_preempt", 41 - "rescheduling" 39 + "rescheduling", 42 40 }, 43 41 .event_names = { 44 42 "irq_entry", 45 43 "sched_need_resched", 46 44 "schedule_entry", 47 - "schedule_entry_preempt" 45 + "schedule_entry_preempt", 48 46 }, 49 47 .function = { 50 48 { 51 49 preempt_irq_nrp, 52 50 preempt_irq_nrp, 53 51 nested_preempt_nrp, 54 - nested_preempt_nrp 52 + nested_preempt_nrp, 55 53 }, 56 54 { 57 55 any_thread_running_nrp, 58 56 rescheduling_nrp, 59 57 any_thread_running_nrp, 60 - INVALID_STATE 58 + INVALID_STATE, 61 59 }, 62 60 { 63 61 nested_preempt_nrp, 64 62 preempt_irq_nrp, 65 63 any_thread_running_nrp, 66 - any_thread_running_nrp 64 + any_thread_running_nrp, 67 65 }, 68 66 { 69 67 preempt_irq_nrp, 70 68 rescheduling_nrp, 71 69 any_thread_running_nrp, 72 - any_thread_running_nrp 70 + any_thread_running_nrp, 73 71 }, 74 72 }, 75 73 .initial_state = preempt_irq_nrp,
+19 -21
kernel/trace/rv/monitors/opid/opid.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "opid" 12 11 ··· 15 16 #include <rv_trace.h> 16 17 #include <monitors/sched/sched.h> 17 18 19 + #define RV_MON_TYPE RV_MON_PER_CPU 18 20 #include "opid.h" 19 - 20 - static struct rv_monitor rv_opid; 21 - DECLARE_DA_MON_PER_CPU(opid, unsigned char); 21 + #include <rv/da_monitor.h> 22 22 23 23 #ifdef CONFIG_X86_LOCAL_APIC 24 24 #include <asm/trace/irq_vectors.h> 25 25 26 26 static void handle_vector_irq_entry(void *data, int vector) 27 27 { 28 - da_handle_event_opid(irq_entry_opid); 28 + da_handle_event(irq_entry_opid); 29 29 } 30 30 31 31 static void attach_vector_irq(void) ··· 59 61 60 62 static void handle_irq_disable(void *data, unsigned long ip, unsigned long parent_ip) 61 63 { 62 - da_handle_event_opid(irq_disable_opid); 64 + da_handle_event(irq_disable_opid); 63 65 } 64 66 65 67 static void handle_irq_enable(void *data, unsigned long ip, unsigned long parent_ip) 66 68 { 67 - da_handle_event_opid(irq_enable_opid); 69 + da_handle_event(irq_enable_opid); 68 70 } 69 71 70 72 static void handle_irq_entry(void *data, int irq, struct irqaction *action) 71 73 { 72 - da_handle_event_opid(irq_entry_opid); 74 + da_handle_event(irq_entry_opid); 73 75 } 74 76 75 77 static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip) 76 78 { 77 - da_handle_event_opid(preempt_disable_opid); 79 + da_handle_event(preempt_disable_opid); 78 80 } 79 81 80 82 static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip) 81 83 { 82 - da_handle_event_opid(preempt_enable_opid); 84 + da_handle_event(preempt_enable_opid); 83 85 } 84 86 85 87 static void handle_sched_need_resched(void *data, struct task_struct *tsk, int cpu, int tif) 86 88 { 87 89 /* The monitor's intitial state is not in_irq */ 88 90 if (this_cpu_read(hardirq_context)) 89 - da_handle_event_opid(sched_need_resched_opid); 91 + da_handle_event(sched_need_resched_opid); 90 92 else 91 - da_handle_start_event_opid(sched_need_resched_opid); 93 + da_handle_start_event(sched_need_resched_opid); 92 94 } 93 95 94 96 static void handle_sched_waking(void *data, struct task_struct *p) 95 97 { 96 98 /* The monitor's intitial state is not in_irq */ 97 99 if (this_cpu_read(hardirq_context)) 98 - da_handle_event_opid(sched_waking_opid); 100 + da_handle_event(sched_waking_opid); 99 101 else 100 - da_handle_start_event_opid(sched_waking_opid); 102 + da_handle_start_event(sched_waking_opid); 101 103 } 102 104 103 105 static int enable_opid(void) 104 106 { 105 107 int retval; 106 108 107 - retval = da_monitor_init_opid(); 109 + retval = da_monitor_init(); 108 110 if (retval) 109 111 return retval; 110 112 ··· 122 124 123 125 static void disable_opid(void) 124 126 { 125 - rv_opid.enabled = 0; 127 + rv_this.enabled = 0; 126 128 127 129 rv_detach_trace_probe("opid", irq_disable, handle_irq_disable); 128 130 rv_detach_trace_probe("opid", irq_enable, handle_irq_enable); ··· 133 135 rv_detach_trace_probe("opid", sched_waking, handle_sched_waking); 134 136 detach_vector_irq(); 135 137 136 - da_monitor_destroy_opid(); 138 + da_monitor_destroy(); 137 139 } 138 140 139 141 /* 140 142 * This is the monitor register section. 141 143 */ 142 - static struct rv_monitor rv_opid = { 144 + static struct rv_monitor rv_this = { 143 145 .name = "opid", 144 146 .description = "operations with preemption and irq disabled.", 145 147 .enable = enable_opid, 146 148 .disable = disable_opid, 147 - .reset = da_monitor_reset_all_opid, 149 + .reset = da_monitor_reset_all, 148 150 .enabled = 0, 149 151 }; 150 152 151 153 static int __init register_opid(void) 152 154 { 153 - return rv_register_monitor(&rv_opid, &rv_sched); 155 + return rv_register_monitor(&rv_this, &rv_sched); 154 156 } 155 157 156 158 static void __exit unregister_opid(void) 157 159 { 158 - rv_unregister_monitor(&rv_opid); 160 + rv_unregister_monitor(&rv_this); 159 161 } 160 162 161 163 module_init(register_opid);
+13 -11
kernel/trace/rv/monitors/opid/opid.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME opid 9 + 8 10 enum states_opid { 9 - disabled_opid = 0, 11 + disabled_opid, 10 12 enabled_opid, 11 13 in_irq_opid, 12 14 irq_disabled_opid, 13 15 preempt_disabled_opid, 14 - state_max_opid 16 + state_max_opid, 15 17 }; 16 18 17 19 #define INVALID_STATE state_max_opid 18 20 19 21 enum events_opid { 20 - irq_disable_opid = 0, 22 + irq_disable_opid, 21 23 irq_enable_opid, 22 24 irq_entry_opid, 23 25 preempt_disable_opid, 24 26 preempt_enable_opid, 25 27 sched_need_resched_opid, 26 28 sched_waking_opid, 27 - event_max_opid 29 + event_max_opid, 28 30 }; 29 31 30 32 struct automaton_opid { ··· 43 41 "enabled", 44 42 "in_irq", 45 43 "irq_disabled", 46 - "preempt_disabled" 44 + "preempt_disabled", 47 45 }, 48 46 .event_names = { 49 47 "irq_disable", ··· 52 50 "preempt_disable", 53 51 "preempt_enable", 54 52 "sched_need_resched", 55 - "sched_waking" 53 + "sched_waking", 56 54 }, 57 55 .function = { 58 56 { ··· 62 60 INVALID_STATE, 63 61 irq_disabled_opid, 64 62 disabled_opid, 65 - disabled_opid 63 + disabled_opid, 66 64 }, 67 65 { 68 66 irq_disabled_opid, ··· 71 69 preempt_disabled_opid, 72 70 enabled_opid, 73 71 INVALID_STATE, 74 - INVALID_STATE 72 + INVALID_STATE, 75 73 }, 76 74 { 77 75 INVALID_STATE, ··· 80 78 INVALID_STATE, 81 79 INVALID_STATE, 82 80 in_irq_opid, 83 - in_irq_opid 81 + in_irq_opid, 84 82 }, 85 83 { 86 84 INVALID_STATE, ··· 89 87 disabled_opid, 90 88 INVALID_STATE, 91 89 irq_disabled_opid, 92 - INVALID_STATE 90 + INVALID_STATE, 93 91 }, 94 92 { 95 93 disabled_opid, ··· 98 96 INVALID_STATE, 99 97 enabled_opid, 100 98 INVALID_STATE, 101 - INVALID_STATE 99 + INVALID_STATE, 102 100 }, 103 101 }, 104 102 .initial_state = disabled_opid,
-2
kernel/trace/rv/monitors/rtapp/rtapp.c
··· 8 8 9 9 #include "rtapp.h" 10 10 11 - struct rv_monitor rv_rtapp; 12 - 13 11 struct rv_monitor rv_rtapp = { 14 12 .name = "rtapp", 15 13 .description = "Collection of monitors for detecting problems with real-time applications",
-2
kernel/trace/rv/monitors/sched/sched.c
··· 8 8 9 9 #include "sched.h" 10 10 11 - struct rv_monitor rv_sched; 12 - 13 11 struct rv_monitor rv_sched = { 14 12 .name = "sched", 15 13 .description = "container for several scheduler monitor specifications.",
+12 -14
kernel/trace/rv/monitors/sco/sco.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "sco" 12 11 ··· 13 14 #include <rv_trace.h> 14 15 #include <monitors/sched/sched.h> 15 16 17 + #define RV_MON_TYPE RV_MON_PER_CPU 16 18 #include "sco.h" 17 - 18 - static struct rv_monitor rv_sco; 19 - DECLARE_DA_MON_PER_CPU(sco, unsigned char); 19 + #include <rv/da_monitor.h> 20 20 21 21 static void handle_sched_set_state(void *data, struct task_struct *tsk, int state) 22 22 { 23 - da_handle_start_event_sco(sched_set_state_sco); 23 + da_handle_start_event(sched_set_state_sco); 24 24 } 25 25 26 26 static void handle_schedule_entry(void *data, bool preempt) 27 27 { 28 - da_handle_event_sco(schedule_entry_sco); 28 + da_handle_event(schedule_entry_sco); 29 29 } 30 30 31 31 static void handle_schedule_exit(void *data, bool is_switch) 32 32 { 33 - da_handle_start_event_sco(schedule_exit_sco); 33 + da_handle_start_event(schedule_exit_sco); 34 34 } 35 35 36 36 static int enable_sco(void) 37 37 { 38 38 int retval; 39 39 40 - retval = da_monitor_init_sco(); 40 + retval = da_monitor_init(); 41 41 if (retval) 42 42 return retval; 43 43 ··· 49 51 50 52 static void disable_sco(void) 51 53 { 52 - rv_sco.enabled = 0; 54 + rv_this.enabled = 0; 53 55 54 56 rv_detach_trace_probe("sco", sched_set_state_tp, handle_sched_set_state); 55 57 rv_detach_trace_probe("sco", sched_entry_tp, handle_schedule_entry); 56 58 rv_detach_trace_probe("sco", sched_exit_tp, handle_schedule_exit); 57 59 58 - da_monitor_destroy_sco(); 60 + da_monitor_destroy(); 59 61 } 60 62 61 - static struct rv_monitor rv_sco = { 63 + static struct rv_monitor rv_this = { 62 64 .name = "sco", 63 65 .description = "scheduling context operations.", 64 66 .enable = enable_sco, 65 67 .disable = disable_sco, 66 - .reset = da_monitor_reset_all_sco, 68 + .reset = da_monitor_reset_all, 67 69 .enabled = 0, 68 70 }; 69 71 70 72 static int __init register_sco(void) 71 73 { 72 - return rv_register_monitor(&rv_sco, &rv_sched); 74 + return rv_register_monitor(&rv_this, &rv_sched); 73 75 } 74 76 75 77 static void __exit unregister_sco(void) 76 78 { 77 - rv_unregister_monitor(&rv_sco); 79 + rv_unregister_monitor(&rv_this); 78 80 } 79 81 80 82 module_init(register_sco);
+8 -6
kernel/trace/rv/monitors/sco/sco.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME sco 9 + 8 10 enum states_sco { 9 - thread_context_sco = 0, 11 + thread_context_sco, 10 12 scheduling_context_sco, 11 - state_max_sco 13 + state_max_sco, 12 14 }; 13 15 14 16 #define INVALID_STATE state_max_sco 15 17 16 18 enum events_sco { 17 - sched_set_state_sco = 0, 19 + sched_set_state_sco, 18 20 schedule_entry_sco, 19 21 schedule_exit_sco, 20 - event_max_sco 22 + event_max_sco, 21 23 }; 22 24 23 25 struct automaton_sco { ··· 33 31 static const struct automaton_sco automaton_sco = { 34 32 .state_names = { 35 33 "thread_context", 36 - "scheduling_context" 34 + "scheduling_context", 37 35 }, 38 36 .event_names = { 39 37 "sched_set_state", 40 38 "schedule_entry", 41 - "schedule_exit" 39 + "schedule_exit", 42 40 }, 43 41 .function = { 44 42 { thread_context_sco, scheduling_context_sco, INVALID_STATE },
+13 -15
kernel/trace/rv/monitors/scpd/scpd.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "scpd" 12 11 ··· 14 15 #include <rv_trace.h> 15 16 #include <monitors/sched/sched.h> 16 17 18 + #define RV_MON_TYPE RV_MON_PER_CPU 17 19 #include "scpd.h" 18 - 19 - static struct rv_monitor rv_scpd; 20 - DECLARE_DA_MON_PER_CPU(scpd, unsigned char); 20 + #include <rv/da_monitor.h> 21 21 22 22 static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip) 23 23 { 24 - da_handle_event_scpd(preempt_disable_scpd); 24 + da_handle_event(preempt_disable_scpd); 25 25 } 26 26 27 27 static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip) 28 28 { 29 - da_handle_start_event_scpd(preempt_enable_scpd); 29 + da_handle_start_event(preempt_enable_scpd); 30 30 } 31 31 32 32 static void handle_schedule_entry(void *data, bool preempt) 33 33 { 34 - da_handle_event_scpd(schedule_entry_scpd); 34 + da_handle_event(schedule_entry_scpd); 35 35 } 36 36 37 37 static void handle_schedule_exit(void *data, bool is_switch) 38 38 { 39 - da_handle_event_scpd(schedule_exit_scpd); 39 + da_handle_event(schedule_exit_scpd); 40 40 } 41 41 42 42 static int enable_scpd(void) 43 43 { 44 44 int retval; 45 45 46 - retval = da_monitor_init_scpd(); 46 + retval = da_monitor_init(); 47 47 if (retval) 48 48 return retval; 49 49 ··· 56 58 57 59 static void disable_scpd(void) 58 60 { 59 - rv_scpd.enabled = 0; 61 + rv_this.enabled = 0; 60 62 61 63 rv_detach_trace_probe("scpd", preempt_disable, handle_preempt_disable); 62 64 rv_detach_trace_probe("scpd", preempt_enable, handle_preempt_enable); 63 65 rv_detach_trace_probe("scpd", sched_entry_tp, handle_schedule_entry); 64 66 rv_detach_trace_probe("scpd", sched_exit_tp, handle_schedule_exit); 65 67 66 - da_monitor_destroy_scpd(); 68 + da_monitor_destroy(); 67 69 } 68 70 69 - static struct rv_monitor rv_scpd = { 71 + static struct rv_monitor rv_this = { 70 72 .name = "scpd", 71 73 .description = "schedule called with preemption disabled.", 72 74 .enable = enable_scpd, 73 75 .disable = disable_scpd, 74 - .reset = da_monitor_reset_all_scpd, 76 + .reset = da_monitor_reset_all, 75 77 .enabled = 0, 76 78 }; 77 79 78 80 static int __init register_scpd(void) 79 81 { 80 - return rv_register_monitor(&rv_scpd, &rv_sched); 82 + return rv_register_monitor(&rv_this, &rv_sched); 81 83 } 82 84 83 85 static void __exit unregister_scpd(void) 84 86 { 85 - rv_unregister_monitor(&rv_scpd); 87 + rv_unregister_monitor(&rv_this); 86 88 } 87 89 88 90 module_init(register_scpd);
+8 -6
kernel/trace/rv/monitors/scpd/scpd.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME scpd 9 + 8 10 enum states_scpd { 9 - cant_sched_scpd = 0, 11 + cant_sched_scpd, 10 12 can_sched_scpd, 11 - state_max_scpd 13 + state_max_scpd, 12 14 }; 13 15 14 16 #define INVALID_STATE state_max_scpd 15 17 16 18 enum events_scpd { 17 - preempt_disable_scpd = 0, 19 + preempt_disable_scpd, 18 20 preempt_enable_scpd, 19 21 schedule_entry_scpd, 20 22 schedule_exit_scpd, 21 - event_max_scpd 23 + event_max_scpd, 22 24 }; 23 25 24 26 struct automaton_scpd { ··· 34 32 static const struct automaton_scpd automaton_scpd = { 35 33 .state_names = { 36 34 "cant_sched", 37 - "can_sched" 35 + "can_sched", 38 36 }, 39 37 .event_names = { 40 38 "preempt_disable", 41 39 "preempt_enable", 42 40 "schedule_entry", 43 - "schedule_exit" 41 + "schedule_exit", 44 42 }, 45 43 .function = { 46 44 { can_sched_scpd, INVALID_STATE, INVALID_STATE, INVALID_STATE },
+13 -15
kernel/trace/rv/monitors/snep/snep.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "snep" 12 11 ··· 14 15 #include <rv_trace.h> 15 16 #include <monitors/sched/sched.h> 16 17 18 + #define RV_MON_TYPE RV_MON_PER_CPU 17 19 #include "snep.h" 18 - 19 - static struct rv_monitor rv_snep; 20 - DECLARE_DA_MON_PER_CPU(snep, unsigned char); 20 + #include <rv/da_monitor.h> 21 21 22 22 static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip) 23 23 { 24 - da_handle_start_event_snep(preempt_disable_snep); 24 + da_handle_start_event(preempt_disable_snep); 25 25 } 26 26 27 27 static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip) 28 28 { 29 - da_handle_start_event_snep(preempt_enable_snep); 29 + da_handle_start_event(preempt_enable_snep); 30 30 } 31 31 32 32 static void handle_schedule_entry(void *data, bool preempt) 33 33 { 34 - da_handle_event_snep(schedule_entry_snep); 34 + da_handle_event(schedule_entry_snep); 35 35 } 36 36 37 37 static void handle_schedule_exit(void *data, bool is_switch) 38 38 { 39 - da_handle_start_event_snep(schedule_exit_snep); 39 + da_handle_start_event(schedule_exit_snep); 40 40 } 41 41 42 42 static int enable_snep(void) 43 43 { 44 44 int retval; 45 45 46 - retval = da_monitor_init_snep(); 46 + retval = da_monitor_init(); 47 47 if (retval) 48 48 return retval; 49 49 ··· 56 58 57 59 static void disable_snep(void) 58 60 { 59 - rv_snep.enabled = 0; 61 + rv_this.enabled = 0; 60 62 61 63 rv_detach_trace_probe("snep", preempt_disable, handle_preempt_disable); 62 64 rv_detach_trace_probe("snep", preempt_enable, handle_preempt_enable); 63 65 rv_detach_trace_probe("snep", sched_entry_tp, handle_schedule_entry); 64 66 rv_detach_trace_probe("snep", sched_exit_tp, handle_schedule_exit); 65 67 66 - da_monitor_destroy_snep(); 68 + da_monitor_destroy(); 67 69 } 68 70 69 - static struct rv_monitor rv_snep = { 71 + static struct rv_monitor rv_this = { 70 72 .name = "snep", 71 73 .description = "schedule does not enable preempt.", 72 74 .enable = enable_snep, 73 75 .disable = disable_snep, 74 - .reset = da_monitor_reset_all_snep, 76 + .reset = da_monitor_reset_all, 75 77 .enabled = 0, 76 78 }; 77 79 78 80 static int __init register_snep(void) 79 81 { 80 - return rv_register_monitor(&rv_snep, &rv_sched); 82 + return rv_register_monitor(&rv_this, &rv_sched); 81 83 } 82 84 83 85 static void __exit unregister_snep(void) 84 86 { 85 - rv_unregister_monitor(&rv_snep); 87 + rv_unregister_monitor(&rv_this); 86 88 } 87 89 88 90 module_init(register_snep);
+10 -8
kernel/trace/rv/monitors/snep/snep.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME snep 9 + 8 10 enum states_snep { 9 - non_scheduling_context_snep = 0, 11 + non_scheduling_context_snep, 10 12 scheduling_contex_snep, 11 - state_max_snep 13 + state_max_snep, 12 14 }; 13 15 14 16 #define INVALID_STATE state_max_snep 15 17 16 18 enum events_snep { 17 - preempt_disable_snep = 0, 19 + preempt_disable_snep, 18 20 preempt_enable_snep, 19 21 schedule_entry_snep, 20 22 schedule_exit_snep, 21 - event_max_snep 23 + event_max_snep, 22 24 }; 23 25 24 26 struct automaton_snep { ··· 34 32 static const struct automaton_snep automaton_snep = { 35 33 .state_names = { 36 34 "non_scheduling_context", 37 - "scheduling_contex" 35 + "scheduling_contex", 38 36 }, 39 37 .event_names = { 40 38 "preempt_disable", 41 39 "preempt_enable", 42 40 "schedule_entry", 43 - "schedule_exit" 41 + "schedule_exit", 44 42 }, 45 43 .function = { 46 44 { 47 45 non_scheduling_context_snep, 48 46 non_scheduling_context_snep, 49 47 scheduling_contex_snep, 50 - INVALID_STATE 48 + INVALID_STATE, 51 49 }, 52 50 { 53 51 INVALID_STATE, 54 52 INVALID_STATE, 55 53 INVALID_STATE, 56 - non_scheduling_context_snep 54 + non_scheduling_context_snep, 57 55 }, 58 56 }, 59 57 .initial_state = non_scheduling_context_snep,
+12 -14
kernel/trace/rv/monitors/snroc/snroc.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "snroc" 12 11 ··· 13 14 #include <rv_trace.h> 14 15 #include <monitors/sched/sched.h> 15 16 17 + #define RV_MON_TYPE RV_MON_PER_TASK 16 18 #include "snroc.h" 17 - 18 - static struct rv_monitor rv_snroc; 19 - DECLARE_DA_MON_PER_TASK(snroc, unsigned char); 19 + #include <rv/da_monitor.h> 20 20 21 21 static void handle_sched_set_state(void *data, struct task_struct *tsk, int state) 22 22 { 23 - da_handle_event_snroc(tsk, sched_set_state_snroc); 23 + da_handle_event(tsk, sched_set_state_snroc); 24 24 } 25 25 26 26 static void handle_sched_switch(void *data, bool preempt, ··· 27 29 struct task_struct *next, 28 30 unsigned int prev_state) 29 31 { 30 - da_handle_start_event_snroc(prev, sched_switch_out_snroc); 31 - da_handle_event_snroc(next, sched_switch_in_snroc); 32 + da_handle_start_event(prev, sched_switch_out_snroc); 33 + da_handle_event(next, sched_switch_in_snroc); 32 34 } 33 35 34 36 static int enable_snroc(void) 35 37 { 36 38 int retval; 37 39 38 - retval = da_monitor_init_snroc(); 40 + retval = da_monitor_init(); 39 41 if (retval) 40 42 return retval; 41 43 ··· 47 49 48 50 static void disable_snroc(void) 49 51 { 50 - rv_snroc.enabled = 0; 52 + rv_this.enabled = 0; 51 53 52 54 rv_detach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state); 53 55 rv_detach_trace_probe("snroc", sched_switch, handle_sched_switch); 54 56 55 - da_monitor_destroy_snroc(); 57 + da_monitor_destroy(); 56 58 } 57 59 58 - static struct rv_monitor rv_snroc = { 60 + static struct rv_monitor rv_this = { 59 61 .name = "snroc", 60 62 .description = "set non runnable on its own context.", 61 63 .enable = enable_snroc, 62 64 .disable = disable_snroc, 63 - .reset = da_monitor_reset_all_snroc, 65 + .reset = da_monitor_reset_all, 64 66 .enabled = 0, 65 67 }; 66 68 67 69 static int __init register_snroc(void) 68 70 { 69 - return rv_register_monitor(&rv_snroc, &rv_sched); 71 + return rv_register_monitor(&rv_this, &rv_sched); 70 72 } 71 73 72 74 static void __exit unregister_snroc(void) 73 75 { 74 - rv_unregister_monitor(&rv_snroc); 76 + rv_unregister_monitor(&rv_this); 75 77 } 76 78 77 79 module_init(register_snroc);
+8 -6
kernel/trace/rv/monitors/snroc/snroc.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME snroc 9 + 8 10 enum states_snroc { 9 - other_context_snroc = 0, 11 + other_context_snroc, 10 12 own_context_snroc, 11 - state_max_snroc 13 + state_max_snroc, 12 14 }; 13 15 14 16 #define INVALID_STATE state_max_snroc 15 17 16 18 enum events_snroc { 17 - sched_set_state_snroc = 0, 19 + sched_set_state_snroc, 18 20 sched_switch_in_snroc, 19 21 sched_switch_out_snroc, 20 - event_max_snroc 22 + event_max_snroc, 21 23 }; 22 24 23 25 struct automaton_snroc { ··· 33 31 static const struct automaton_snroc automaton_snroc = { 34 32 .state_names = { 35 33 "other_context", 36 - "own_context" 34 + "own_context", 37 35 }, 38 36 .event_names = { 39 37 "sched_set_state", 40 38 "sched_switch_in", 41 - "sched_switch_out" 39 + "sched_switch_out", 42 40 }, 43 41 .function = { 44 42 { INVALID_STATE, own_context_snroc, INVALID_STATE },
+18 -20
kernel/trace/rv/monitors/sssw/sssw.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "sssw" 12 11 ··· 14 15 #include <rv_trace.h> 15 16 #include <monitors/sched/sched.h> 16 17 18 + #define RV_MON_TYPE RV_MON_PER_TASK 17 19 #include "sssw.h" 18 - 19 - static struct rv_monitor rv_sssw; 20 - DECLARE_DA_MON_PER_TASK(sssw, unsigned char); 20 + #include <rv/da_monitor.h> 21 21 22 22 static void handle_sched_set_state(void *data, struct task_struct *tsk, int state) 23 23 { 24 24 if (state == TASK_RUNNING) 25 - da_handle_start_event_sssw(tsk, sched_set_state_runnable_sssw); 25 + da_handle_start_event(tsk, sched_set_state_runnable_sssw); 26 26 else 27 - da_handle_event_sssw(tsk, sched_set_state_sleepable_sssw); 27 + da_handle_event(tsk, sched_set_state_sleepable_sssw); 28 28 } 29 29 30 30 static void handle_sched_switch(void *data, bool preempt, ··· 32 34 unsigned int prev_state) 33 35 { 34 36 if (preempt) 35 - da_handle_event_sssw(prev, sched_switch_preempt_sssw); 37 + da_handle_event(prev, sched_switch_preempt_sssw); 36 38 else if (prev_state == TASK_RUNNING) 37 - da_handle_event_sssw(prev, sched_switch_yield_sssw); 39 + da_handle_event(prev, sched_switch_yield_sssw); 38 40 else if (prev_state == TASK_RTLOCK_WAIT) 39 41 /* special case of sleeping task with racy conditions */ 40 - da_handle_event_sssw(prev, sched_switch_blocking_sssw); 42 + da_handle_event(prev, sched_switch_blocking_sssw); 41 43 else 42 - da_handle_event_sssw(prev, sched_switch_suspend_sssw); 43 - da_handle_event_sssw(next, sched_switch_in_sssw); 44 + da_handle_event(prev, sched_switch_suspend_sssw); 45 + da_handle_event(next, sched_switch_in_sssw); 44 46 } 45 47 46 48 static void handle_sched_wakeup(void *data, struct task_struct *p) ··· 49 51 * Wakeup can also lead to signal_wakeup although the system is 50 52 * actually runnable. The monitor can safely start with this event. 51 53 */ 52 - da_handle_start_event_sssw(p, sched_wakeup_sssw); 54 + da_handle_start_event(p, sched_wakeup_sssw); 53 55 } 54 56 55 57 static void handle_signal_deliver(void *data, int sig, 56 58 struct kernel_siginfo *info, 57 59 struct k_sigaction *ka) 58 60 { 59 - da_handle_event_sssw(current, signal_deliver_sssw); 61 + da_handle_event(current, signal_deliver_sssw); 60 62 } 61 63 62 64 static int enable_sssw(void) 63 65 { 64 66 int retval; 65 67 66 - retval = da_monitor_init_sssw(); 68 + retval = da_monitor_init(); 67 69 if (retval) 68 70 return retval; 69 71 ··· 77 79 78 80 static void disable_sssw(void) 79 81 { 80 - rv_sssw.enabled = 0; 82 + rv_this.enabled = 0; 81 83 82 84 rv_detach_trace_probe("sssw", sched_set_state_tp, handle_sched_set_state); 83 85 rv_detach_trace_probe("sssw", sched_switch, handle_sched_switch); 84 86 rv_detach_trace_probe("sssw", sched_wakeup, handle_sched_wakeup); 85 87 rv_detach_trace_probe("sssw", signal_deliver, handle_signal_deliver); 86 88 87 - da_monitor_destroy_sssw(); 89 + da_monitor_destroy(); 88 90 } 89 91 90 - static struct rv_monitor rv_sssw = { 92 + static struct rv_monitor rv_this = { 91 93 .name = "sssw", 92 94 .description = "set state sleep and wakeup.", 93 95 .enable = enable_sssw, 94 96 .disable = disable_sssw, 95 - .reset = da_monitor_reset_all_sssw, 97 + .reset = da_monitor_reset_all, 96 98 .enabled = 0, 97 99 }; 98 100 99 101 static int __init register_sssw(void) 100 102 { 101 - return rv_register_monitor(&rv_sssw, &rv_sched); 103 + return rv_register_monitor(&rv_this, &rv_sched); 102 104 } 103 105 104 106 static void __exit unregister_sssw(void) 105 107 { 106 - rv_unregister_monitor(&rv_sssw); 108 + rv_unregister_monitor(&rv_this); 107 109 } 108 110 109 111 module_init(register_sssw);
+12 -10
kernel/trace/rv/monitors/sssw/sssw.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME sssw 9 + 8 10 enum states_sssw { 9 - runnable_sssw = 0, 11 + runnable_sssw, 10 12 signal_wakeup_sssw, 11 13 sleepable_sssw, 12 14 sleeping_sssw, 13 - state_max_sssw 15 + state_max_sssw, 14 16 }; 15 17 16 18 #define INVALID_STATE state_max_sssw 17 19 18 20 enum events_sssw { 19 - sched_set_state_runnable_sssw = 0, 21 + sched_set_state_runnable_sssw, 20 22 sched_set_state_sleepable_sssw, 21 23 sched_switch_blocking_sssw, 22 24 sched_switch_in_sssw, ··· 27 25 sched_switch_yield_sssw, 28 26 sched_wakeup_sssw, 29 27 signal_deliver_sssw, 30 - event_max_sssw 28 + event_max_sssw, 31 29 }; 32 30 33 31 struct automaton_sssw { ··· 43 41 "runnable", 44 42 "signal_wakeup", 45 43 "sleepable", 46 - "sleeping" 44 + "sleeping", 47 45 }, 48 46 .event_names = { 49 47 "sched_set_state_runnable", ··· 54 52 "sched_switch_suspend", 55 53 "sched_switch_yield", 56 54 "sched_wakeup", 57 - "signal_deliver" 55 + "signal_deliver", 58 56 }, 59 57 .function = { 60 58 { ··· 66 64 INVALID_STATE, 67 65 runnable_sssw, 68 66 runnable_sssw, 69 - runnable_sssw 67 + runnable_sssw, 70 68 }, 71 69 { 72 70 INVALID_STATE, ··· 77 75 INVALID_STATE, 78 76 signal_wakeup_sssw, 79 77 signal_wakeup_sssw, 80 - runnable_sssw 78 + runnable_sssw, 81 79 }, 82 80 { 83 81 runnable_sssw, ··· 88 86 sleeping_sssw, 89 87 signal_wakeup_sssw, 90 88 runnable_sssw, 91 - sleepable_sssw 89 + sleepable_sssw, 92 90 }, 93 91 { 94 92 INVALID_STATE, ··· 99 97 INVALID_STATE, 100 98 INVALID_STATE, 101 99 runnable_sssw, 102 - INVALID_STATE 100 + INVALID_STATE, 103 101 }, 104 102 }, 105 103 .initial_state = runnable_sssw,
+16 -18
kernel/trace/rv/monitors/sts/sts.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "sts" 12 11 ··· 15 16 #include <rv_trace.h> 16 17 #include <monitors/sched/sched.h> 17 18 19 + #define RV_MON_TYPE RV_MON_PER_CPU 18 20 #include "sts.h" 19 - 20 - static struct rv_monitor rv_sts; 21 - DECLARE_DA_MON_PER_CPU(sts, unsigned char); 21 + #include <rv/da_monitor.h> 22 22 23 23 #ifdef CONFIG_X86_LOCAL_APIC 24 24 #include <asm/trace/irq_vectors.h> 25 25 26 26 static void handle_vector_irq_entry(void *data, int vector) 27 27 { 28 - da_handle_event_sts(irq_entry_sts); 28 + da_handle_event(irq_entry_sts); 29 29 } 30 30 31 31 static void attach_vector_irq(void) ··· 59 61 60 62 static void handle_irq_disable(void *data, unsigned long ip, unsigned long parent_ip) 61 63 { 62 - da_handle_event_sts(irq_disable_sts); 64 + da_handle_event(irq_disable_sts); 63 65 } 64 66 65 67 static void handle_irq_enable(void *data, unsigned long ip, unsigned long parent_ip) 66 68 { 67 - da_handle_event_sts(irq_enable_sts); 69 + da_handle_event(irq_enable_sts); 68 70 } 69 71 70 72 static void handle_irq_entry(void *data, int irq, struct irqaction *action) 71 73 { 72 - da_handle_event_sts(irq_entry_sts); 74 + da_handle_event(irq_entry_sts); 73 75 } 74 76 75 77 static void handle_sched_switch(void *data, bool preempt, ··· 77 79 struct task_struct *next, 78 80 unsigned int prev_state) 79 81 { 80 - da_handle_event_sts(sched_switch_sts); 82 + da_handle_event(sched_switch_sts); 81 83 } 82 84 83 85 static void handle_schedule_entry(void *data, bool preempt) 84 86 { 85 - da_handle_event_sts(schedule_entry_sts); 87 + da_handle_event(schedule_entry_sts); 86 88 } 87 89 88 90 static void handle_schedule_exit(void *data, bool is_switch) 89 91 { 90 - da_handle_start_event_sts(schedule_exit_sts); 92 + da_handle_start_event(schedule_exit_sts); 91 93 } 92 94 93 95 static int enable_sts(void) 94 96 { 95 97 int retval; 96 98 97 - retval = da_monitor_init_sts(); 99 + retval = da_monitor_init(); 98 100 if (retval) 99 101 return retval; 100 102 ··· 111 113 112 114 static void disable_sts(void) 113 115 { 114 - rv_sts.enabled = 0; 116 + rv_this.enabled = 0; 115 117 116 118 rv_detach_trace_probe("sts", irq_disable, handle_irq_disable); 117 119 rv_detach_trace_probe("sts", irq_enable, handle_irq_enable); ··· 121 123 rv_detach_trace_probe("sts", sched_exit_tp, handle_schedule_exit); 122 124 detach_vector_irq(); 123 125 124 - da_monitor_destroy_sts(); 126 + da_monitor_destroy(); 125 127 } 126 128 127 129 /* 128 130 * This is the monitor register section. 129 131 */ 130 - static struct rv_monitor rv_sts = { 132 + static struct rv_monitor rv_this = { 131 133 .name = "sts", 132 134 .description = "schedule implies task switch.", 133 135 .enable = enable_sts, 134 136 .disable = disable_sts, 135 - .reset = da_monitor_reset_all_sts, 137 + .reset = da_monitor_reset_all, 136 138 .enabled = 0, 137 139 }; 138 140 139 141 static int __init register_sts(void) 140 142 { 141 - return rv_register_monitor(&rv_sts, &rv_sched); 143 + return rv_register_monitor(&rv_this, &rv_sched); 142 144 } 143 145 144 146 static void __exit unregister_sts(void) 145 147 { 146 - rv_unregister_monitor(&rv_sts); 148 + rv_unregister_monitor(&rv_this); 147 149 } 148 150 149 151 module_init(register_sts);
+15 -13
kernel/trace/rv/monitors/sts/sts.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME sts 9 + 8 10 enum states_sts { 9 - can_sched_sts = 0, 11 + can_sched_sts, 10 12 cant_sched_sts, 11 13 disable_to_switch_sts, 12 14 enable_to_exit_sts, 13 15 in_irq_sts, 14 16 scheduling_sts, 15 17 switching_sts, 16 - state_max_sts 18 + state_max_sts, 17 19 }; 18 20 19 21 #define INVALID_STATE state_max_sts 20 22 21 23 enum events_sts { 22 - irq_disable_sts = 0, 24 + irq_disable_sts, 23 25 irq_enable_sts, 24 26 irq_entry_sts, 25 27 sched_switch_sts, 26 28 schedule_entry_sts, 27 29 schedule_exit_sts, 28 - event_max_sts 30 + event_max_sts, 29 31 }; 30 32 31 33 struct automaton_sts { ··· 46 44 "enable_to_exit", 47 45 "in_irq", 48 46 "scheduling", 49 - "switching" 47 + "switching", 50 48 }, 51 49 .event_names = { 52 50 "irq_disable", ··· 54 52 "irq_entry", 55 53 "sched_switch", 56 54 "schedule_entry", 57 - "schedule_exit" 55 + "schedule_exit", 58 56 }, 59 57 .function = { 60 58 { ··· 63 61 INVALID_STATE, 64 62 INVALID_STATE, 65 63 scheduling_sts, 66 - INVALID_STATE 64 + INVALID_STATE, 67 65 }, 68 66 { 69 67 INVALID_STATE, ··· 71 69 cant_sched_sts, 72 70 INVALID_STATE, 73 71 INVALID_STATE, 74 - INVALID_STATE 72 + INVALID_STATE, 75 73 }, 76 74 { 77 75 INVALID_STATE, ··· 79 77 in_irq_sts, 80 78 switching_sts, 81 79 INVALID_STATE, 82 - INVALID_STATE 80 + INVALID_STATE, 83 81 }, 84 82 { 85 83 enable_to_exit_sts, ··· 87 85 enable_to_exit_sts, 88 86 INVALID_STATE, 89 87 INVALID_STATE, 90 - can_sched_sts 88 + can_sched_sts, 91 89 }, 92 90 { 93 91 INVALID_STATE, ··· 95 93 in_irq_sts, 96 94 INVALID_STATE, 97 95 INVALID_STATE, 98 - INVALID_STATE 96 + INVALID_STATE, 99 97 }, 100 98 { 101 99 disable_to_switch_sts, ··· 103 101 INVALID_STATE, 104 102 INVALID_STATE, 105 103 INVALID_STATE, 106 - INVALID_STATE 104 + INVALID_STATE, 107 105 }, 108 106 { 109 107 INVALID_STATE, ··· 111 109 INVALID_STATE, 112 110 INVALID_STATE, 113 111 INVALID_STATE, 114 - INVALID_STATE 112 + INVALID_STATE, 115 113 }, 116 114 }, 117 115 .initial_state = can_sched_sts,
+12 -14
kernel/trace/rv/monitors/wip/wip.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "wip" 12 11 ··· 13 14 #include <trace/events/sched.h> 14 15 #include <trace/events/preemptirq.h> 15 16 17 + #define RV_MON_TYPE RV_MON_PER_CPU 16 18 #include "wip.h" 17 - 18 - static struct rv_monitor rv_wip; 19 - DECLARE_DA_MON_PER_CPU(wip, unsigned char); 19 + #include <rv/da_monitor.h> 20 20 21 21 static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip) 22 22 { 23 - da_handle_event_wip(preempt_disable_wip); 23 + da_handle_event(preempt_disable_wip); 24 24 } 25 25 26 26 static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip) 27 27 { 28 - da_handle_start_event_wip(preempt_enable_wip); 28 + da_handle_start_event(preempt_enable_wip); 29 29 } 30 30 31 31 static void handle_sched_waking(void *data, struct task_struct *task) 32 32 { 33 - da_handle_event_wip(sched_waking_wip); 33 + da_handle_event(sched_waking_wip); 34 34 } 35 35 36 36 static int enable_wip(void) 37 37 { 38 38 int retval; 39 39 40 - retval = da_monitor_init_wip(); 40 + retval = da_monitor_init(); 41 41 if (retval) 42 42 return retval; 43 43 ··· 49 51 50 52 static void disable_wip(void) 51 53 { 52 - rv_wip.enabled = 0; 54 + rv_this.enabled = 0; 53 55 54 56 rv_detach_trace_probe("wip", preempt_disable, handle_preempt_disable); 55 57 rv_detach_trace_probe("wip", preempt_enable, handle_preempt_enable); 56 58 rv_detach_trace_probe("wip", sched_waking, handle_sched_waking); 57 59 58 - da_monitor_destroy_wip(); 60 + da_monitor_destroy(); 59 61 } 60 62 61 - static struct rv_monitor rv_wip = { 63 + static struct rv_monitor rv_this = { 62 64 .name = "wip", 63 65 .description = "wakeup in preemptive per-cpu testing monitor.", 64 66 .enable = enable_wip, 65 67 .disable = disable_wip, 66 - .reset = da_monitor_reset_all_wip, 68 + .reset = da_monitor_reset_all, 67 69 .enabled = 0, 68 70 }; 69 71 70 72 static int __init register_wip(void) 71 73 { 72 - return rv_register_monitor(&rv_wip, NULL); 74 + return rv_register_monitor(&rv_this, NULL); 73 75 } 74 76 75 77 static void __exit unregister_wip(void) 76 78 { 77 - rv_unregister_monitor(&rv_wip); 79 + rv_unregister_monitor(&rv_this); 78 80 } 79 81 80 82 module_init(register_wip);
+8 -6
kernel/trace/rv/monitors/wip/wip.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME wip 9 + 8 10 enum states_wip { 9 - preemptive_wip = 0, 11 + preemptive_wip, 10 12 non_preemptive_wip, 11 - state_max_wip 13 + state_max_wip, 12 14 }; 13 15 14 16 #define INVALID_STATE state_max_wip 15 17 16 18 enum events_wip { 17 - preempt_disable_wip = 0, 19 + preempt_disable_wip, 18 20 preempt_enable_wip, 19 21 sched_waking_wip, 20 - event_max_wip 22 + event_max_wip, 21 23 }; 22 24 23 25 struct automaton_wip { ··· 33 31 static const struct automaton_wip automaton_wip = { 34 32 .state_names = { 35 33 "preemptive", 36 - "non_preemptive" 34 + "non_preemptive", 37 35 }, 38 36 .event_names = { 39 37 "preempt_disable", 40 38 "preempt_enable", 41 - "sched_waking" 39 + "sched_waking", 42 40 }, 43 41 .function = { 44 42 { non_preemptive_wip, INVALID_STATE, INVALID_STATE },
+13 -15
kernel/trace/rv/monitors/wwnr/wwnr.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "wwnr" 12 11 13 12 #include <rv_trace.h> 14 13 #include <trace/events/sched.h> 15 14 15 + #define RV_MON_TYPE RV_MON_PER_TASK 16 16 #include "wwnr.h" 17 - 18 - static struct rv_monitor rv_wwnr; 19 - DECLARE_DA_MON_PER_TASK(wwnr, unsigned char); 17 + #include <rv/da_monitor.h> 20 18 21 19 static void handle_switch(void *data, bool preempt, struct task_struct *p, 22 20 struct task_struct *n, unsigned int prev_state) 23 21 { 24 22 /* start monitoring only after the first suspension */ 25 23 if (prev_state == TASK_INTERRUPTIBLE) 26 - da_handle_start_event_wwnr(p, switch_out_wwnr); 24 + da_handle_start_event(p, switch_out_wwnr); 27 25 else 28 - da_handle_event_wwnr(p, switch_out_wwnr); 26 + da_handle_event(p, switch_out_wwnr); 29 27 30 - da_handle_event_wwnr(n, switch_in_wwnr); 28 + da_handle_event(n, switch_in_wwnr); 31 29 } 32 30 33 31 static void handle_wakeup(void *data, struct task_struct *p) 34 32 { 35 - da_handle_event_wwnr(p, wakeup_wwnr); 33 + da_handle_event(p, wakeup_wwnr); 36 34 } 37 35 38 36 static int enable_wwnr(void) 39 37 { 40 38 int retval; 41 39 42 - retval = da_monitor_init_wwnr(); 40 + retval = da_monitor_init(); 43 41 if (retval) 44 42 return retval; 45 43 ··· 49 51 50 52 static void disable_wwnr(void) 51 53 { 52 - rv_wwnr.enabled = 0; 54 + rv_this.enabled = 0; 53 55 54 56 rv_detach_trace_probe("wwnr", sched_switch, handle_switch); 55 57 rv_detach_trace_probe("wwnr", sched_wakeup, handle_wakeup); 56 58 57 - da_monitor_destroy_wwnr(); 59 + da_monitor_destroy(); 58 60 } 59 61 60 - static struct rv_monitor rv_wwnr = { 62 + static struct rv_monitor rv_this = { 61 63 .name = "wwnr", 62 64 .description = "wakeup while not running per-task testing model.", 63 65 .enable = enable_wwnr, 64 66 .disable = disable_wwnr, 65 - .reset = da_monitor_reset_all_wwnr, 67 + .reset = da_monitor_reset_all, 66 68 .enabled = 0, 67 69 }; 68 70 69 71 static int __init register_wwnr(void) 70 72 { 71 - return rv_register_monitor(&rv_wwnr, NULL); 73 + return rv_register_monitor(&rv_this, NULL); 72 74 } 73 75 74 76 static void __exit unregister_wwnr(void) 75 77 { 76 - rv_unregister_monitor(&rv_wwnr); 78 + rv_unregister_monitor(&rv_this); 77 79 } 78 80 79 81 module_init(register_wwnr);
+8 -6
kernel/trace/rv/monitors/wwnr/wwnr.h
··· 5 5 * Documentation/trace/rv/deterministic_automata.rst 6 6 */ 7 7 8 + #define MONITOR_NAME wwnr 9 + 8 10 enum states_wwnr { 9 - not_running_wwnr = 0, 11 + not_running_wwnr, 10 12 running_wwnr, 11 - state_max_wwnr 13 + state_max_wwnr, 12 14 }; 13 15 14 16 #define INVALID_STATE state_max_wwnr 15 17 16 18 enum events_wwnr { 17 - switch_in_wwnr = 0, 19 + switch_in_wwnr, 18 20 switch_out_wwnr, 19 21 wakeup_wwnr, 20 - event_max_wwnr 22 + event_max_wwnr, 21 23 }; 22 24 23 25 struct automaton_wwnr { ··· 33 31 static const struct automaton_wwnr automaton_wwnr = { 34 32 .state_names = { 35 33 "not_running", 36 - "running" 34 + "running", 37 35 }, 38 36 .event_names = { 39 37 "switch_in", 40 38 "switch_out", 41 - "wakeup" 39 + "wakeup", 42 40 }, 43 41 .function = { 44 42 { running_wwnr, INVALID_STATE, not_running_wwnr },
+10 -10
tools/verification/rvgen/rvgen/automata.py
··· 28 28 self.function = self.__create_matrix() 29 29 self.events_start, self.events_start_run = self.__store_init_events() 30 30 31 - def __get_model_name(self): 31 + def __get_model_name(self) -> str: 32 32 basename = ntpath.basename(self.__dot_path) 33 33 if not basename.endswith(".dot") and not basename.endswith(".gv"): 34 34 print("not a dot file") ··· 40 40 41 41 return model_name 42 42 43 - def __open_dot(self): 43 + def __open_dot(self) -> list[str]: 44 44 cursor = 0 45 45 dot_lines = [] 46 46 try: ··· 60 60 cursor += 1 61 61 return dot_lines 62 62 63 - def __get_cursor_begin_states(self): 63 + def __get_cursor_begin_states(self) -> int: 64 64 cursor = 0 65 65 while self.__dot_lines[cursor].split()[0] != "{node": 66 66 cursor += 1 67 67 return cursor 68 68 69 - def __get_cursor_begin_events(self): 69 + def __get_cursor_begin_events(self) -> int: 70 70 cursor = 0 71 71 while self.__dot_lines[cursor].split()[0] != "{node": 72 72 cursor += 1 ··· 76 76 cursor += 1 77 77 return cursor 78 78 79 - def __get_state_variables(self): 79 + def __get_state_variables(self) -> tuple[list[str], str, list[str]]: 80 80 # wait for node declaration 81 81 states = [] 82 82 final_states = [] ··· 116 116 117 117 return states, initial_state, final_states 118 118 119 - def __get_event_variables(self): 119 + def __get_event_variables(self) -> list[str]: 120 120 # here we are at the begin of transitions, take a note, we will return later. 121 121 cursor = self.__get_cursor_begin_events() 122 122 ··· 140 140 141 141 return sorted(set(events)) 142 142 143 - def __create_matrix(self): 143 + def __create_matrix(self) -> list[list[str]]: 144 144 # transform the array into a dictionary 145 145 events = self.events 146 146 states = self.states ··· 174 174 175 175 return matrix 176 176 177 - def __store_init_events(self): 177 + def __store_init_events(self) -> tuple[list[bool], list[bool]]: 178 178 events_start = [False] * len(self.events) 179 179 events_start_run = [False] * len(self.events) 180 180 for i, _ in enumerate(self.events): ··· 196 196 events_start_run[i] = True 197 197 return events_start, events_start_run 198 198 199 - def is_start_event(self, event): 199 + def is_start_event(self, event: str) -> bool: 200 200 return self.events_start[self.events.index(event)] 201 201 202 - def is_start_run_event(self, event): 202 + def is_start_run_event(self, event: str) -> bool: 203 203 # prefer handle_start_event if there 204 204 if any(self.events_start): 205 205 return False
+38 -73
tools/verification/rvgen/rvgen/dot2c.py
··· 26 26 super().__init__(file_path, model_name) 27 27 self.line_length = 100 28 28 29 - def __buff_to_string(self, buff): 30 - string = "" 31 - 32 - for line in buff: 33 - string = string + line + "\n" 34 - 35 - # cut off the last \n 36 - return string[:-1] 37 - 38 - def __get_enum_states_content(self): 29 + def __get_enum_states_content(self) -> list[str]: 39 30 buff = [] 40 - buff.append("\t%s%s = 0," % (self.initial_state, self.enum_suffix)) 31 + buff.append("\t%s%s," % (self.initial_state, self.enum_suffix)) 41 32 for state in self.states: 42 33 if state != self.initial_state: 43 34 buff.append("\t%s%s," % (state, self.enum_suffix)) 44 - buff.append("\tstate_max%s" % (self.enum_suffix)) 35 + buff.append("\tstate_max%s," % (self.enum_suffix)) 45 36 46 37 return buff 47 38 48 - def get_enum_states_string(self): 49 - buff = self.__get_enum_states_content() 50 - return self.__buff_to_string(buff) 51 - 52 - def format_states_enum(self): 39 + def format_states_enum(self) -> list[str]: 53 40 buff = [] 54 41 buff.append("enum %s {" % self.enum_states_def) 55 - buff.append(self.get_enum_states_string()) 42 + buff += self.__get_enum_states_content() 56 43 buff.append("};\n") 57 44 58 45 return buff 59 46 60 - def __get_enum_events_content(self): 47 + def __get_enum_events_content(self) -> list[str]: 61 48 buff = [] 62 - first = True 63 49 for event in self.events: 64 - if first: 65 - buff.append("\t%s%s = 0," % (event, self.enum_suffix)) 66 - first = False 67 - else: 68 - buff.append("\t%s%s," % (event, self.enum_suffix)) 50 + buff.append("\t%s%s," % (event, self.enum_suffix)) 69 51 70 - buff.append("\tevent_max%s" % self.enum_suffix) 52 + buff.append("\tevent_max%s," % self.enum_suffix) 71 53 72 54 return buff 73 55 74 - def get_enum_events_string(self): 75 - buff = self.__get_enum_events_content() 76 - return self.__buff_to_string(buff) 77 - 78 - def format_events_enum(self): 56 + def format_events_enum(self) -> list[str]: 79 57 buff = [] 80 58 buff.append("enum %s {" % self.enum_events_def) 81 - buff.append(self.get_enum_events_string()) 59 + buff += self.__get_enum_events_content() 82 60 buff.append("};\n") 83 61 84 62 return buff 85 63 86 - def get_minimun_type(self): 64 + def get_minimun_type(self) -> str: 87 65 min_type = "unsigned char" 88 66 89 67 if self.states.__len__() > 255: ··· 75 97 76 98 return min_type 77 99 78 - def format_automaton_definition(self): 100 + def format_automaton_definition(self) -> list[str]: 79 101 min_type = self.get_minimun_type() 80 102 buff = [] 81 103 buff.append("struct %s {" % self.struct_automaton_def) ··· 87 109 buff.append("};\n") 88 110 return buff 89 111 90 - def format_aut_init_header(self): 112 + def format_aut_init_header(self) -> list[str]: 91 113 buff = [] 92 114 buff.append("static const struct %s %s = {" % (self.struct_automaton_def, self.var_automaton_def)) 93 115 return buff 94 116 95 - def __get_string_vector_per_line_content(self, buff): 96 - first = True 97 - string = "" 98 - for entry in buff: 99 - if first: 100 - string = string + "\t\t\"" + entry 101 - first = False; 102 - else: 103 - string = string + "\",\n\t\t\"" + entry 104 - string = string + "\"" 117 + def __get_string_vector_per_line_content(self, entries: list[str]) -> str: 118 + buff = [] 119 + for entry in entries: 120 + buff.append(f"\t\t\"{entry}\",") 121 + return "\n".join(buff) 105 122 106 - return string 107 - 108 - def get_aut_init_events_string(self): 109 - return self.__get_string_vector_per_line_content(self.events) 110 - 111 - def get_aut_init_states_string(self): 112 - return self.__get_string_vector_per_line_content(self.states) 113 - 114 - def format_aut_init_events_string(self): 123 + def format_aut_init_events_string(self) -> list[str]: 115 124 buff = [] 116 125 buff.append("\t.event_names = {") 117 - buff.append(self.get_aut_init_events_string()) 126 + buff.append(self.__get_string_vector_per_line_content(self.events)) 118 127 buff.append("\t},") 119 128 return buff 120 129 121 - def format_aut_init_states_string(self): 130 + def format_aut_init_states_string(self) -> list[str]: 122 131 buff = [] 123 132 buff.append("\t.state_names = {") 124 - buff.append(self.get_aut_init_states_string()) 133 + buff.append(self.__get_string_vector_per_line_content(self.states)) 125 134 buff.append("\t},") 126 135 127 136 return buff 128 137 129 - def __get_max_strlen_of_states(self): 138 + def __get_max_strlen_of_states(self) -> int: 130 139 max_state_name = max(self.states, key = len).__len__() 131 140 return max(max_state_name, self.invalid_state_str.__len__()) 132 141 133 - def get_aut_init_function(self): 142 + def get_aut_init_function(self) -> str: 134 143 nr_states = self.states.__len__() 135 144 nr_events = self.events.__len__() 136 145 buff = [] ··· 140 175 if y != nr_events-1: 141 176 line += ",\n" if linetoolong else ", " 142 177 else: 143 - line += "\n\t\t}," if linetoolong else " }," 178 + line += ",\n\t\t}," if linetoolong else " }," 144 179 buff.append(line) 145 180 146 - return self.__buff_to_string(buff) 181 + return '\n'.join(buff) 147 182 148 - def format_aut_init_function(self): 183 + def format_aut_init_function(self) -> list[str]: 149 184 buff = [] 150 185 buff.append("\t.function = {") 151 186 buff.append(self.get_aut_init_function()) ··· 153 188 154 189 return buff 155 190 156 - def get_aut_init_initial_state(self): 191 + def get_aut_init_initial_state(self) -> str: 157 192 return self.initial_state 158 193 159 - def format_aut_init_initial_state(self): 194 + def format_aut_init_initial_state(self) -> list[str]: 160 195 buff = [] 161 196 initial_state = self.get_aut_init_initial_state() 162 197 buff.append("\t.initial_state = " + initial_state + self.enum_suffix + ",") 163 198 164 199 return buff 165 200 166 - def get_aut_init_final_states(self): 201 + def get_aut_init_final_states(self) -> str: 167 202 line = "" 168 203 first = True 169 204 for state in self.states: 170 - if first == False: 205 + if not first: 171 206 line = line + ', ' 172 207 else: 173 208 first = False 174 209 175 - if self.final_states.__contains__(state): 210 + if state in self.final_states: 176 211 line = line + '1' 177 212 else: 178 213 line = line + '0' 179 214 return line 180 215 181 - def format_aut_init_final_states(self): 216 + def format_aut_init_final_states(self) -> list[str]: 182 217 buff = [] 183 218 buff.append("\t.final_states = { %s }," % self.get_aut_init_final_states()) 184 219 185 220 return buff 186 221 187 - def __get_automaton_initialization_footer_string(self): 222 + def __get_automaton_initialization_footer_string(self) -> str: 188 223 footer = "};\n" 189 224 return footer 190 225 191 - def format_aut_init_footer(self): 226 + def format_aut_init_footer(self) -> list[str]: 192 227 buff = [] 193 228 buff.append(self.__get_automaton_initialization_footer_string()) 194 229 195 230 return buff 196 231 197 - def format_invalid_state(self): 232 + def format_invalid_state(self) -> list[str]: 198 233 buff = [] 199 234 buff.append("#define %s state_max%s\n" % (self.invalid_state_str, self.enum_suffix)) 200 235 201 236 return buff 202 237 203 - def format_model(self): 238 + def format_model(self) -> list[str]: 204 239 buff = [] 205 240 buff += self.format_states_enum() 206 241 buff += self.format_invalid_state() ··· 218 253 219 254 def print_model_classic(self): 220 255 buff = self.format_model() 221 - print(self.__buff_to_string(buff)) 256 + print('\n'.join(buff))
+14 -12
tools/verification/rvgen/rvgen/dot2k.py
··· 21 21 Dot2c.__init__(self, file_path, extra_params.get("model_name")) 22 22 self.enum_suffix = "_%s" % self.name 23 23 24 - def fill_monitor_type(self): 24 + def fill_monitor_type(self) -> str: 25 25 return self.monitor_type.upper() 26 26 27 - def fill_tracepoint_handlers_skel(self): 27 + def fill_tracepoint_handlers_skel(self) -> str: 28 28 buff = [] 29 29 for event in self.events: 30 30 buff.append("static void handle_%s(void *data, /* XXX: fill header */)" % event) ··· 38 38 handle = "handle_start_run_event" 39 39 if self.monitor_type == "per_task": 40 40 buff.append("\tstruct task_struct *p = /* XXX: how do I get p? */;"); 41 - buff.append("\tda_%s_%s(p, %s%s);" % (handle, self.name, event, self.enum_suffix)); 41 + buff.append("\tda_%s(p, %s%s);" % (handle, event, self.enum_suffix)); 42 42 else: 43 - buff.append("\tda_%s_%s(%s%s);" % (handle, self.name, event, self.enum_suffix)); 43 + buff.append("\tda_%s(%s%s);" % (handle, event, self.enum_suffix)); 44 44 buff.append("}") 45 45 buff.append("") 46 46 return '\n'.join(buff) 47 47 48 - def fill_tracepoint_attach_probe(self): 48 + def fill_tracepoint_attach_probe(self) -> str: 49 49 buff = [] 50 50 for event in self.events: 51 51 buff.append("\trv_attach_trace_probe(\"%s\", /* XXX: tracepoint */, handle_%s);" % (self.name, event)) 52 52 return '\n'.join(buff) 53 53 54 - def fill_tracepoint_detach_helper(self): 54 + def fill_tracepoint_detach_helper(self) -> str: 55 55 buff = [] 56 56 for event in self.events: 57 57 buff.append("\trv_detach_trace_probe(\"%s\", /* XXX: tracepoint */, handle_%s);" % (self.name, event)) 58 58 return '\n'.join(buff) 59 59 60 - def fill_model_h_header(self): 60 + def fill_model_h_header(self) -> list[str]: 61 61 buff = [] 62 62 buff.append("/* SPDX-License-Identifier: GPL-2.0 */") 63 63 buff.append("/*") ··· 66 66 buff.append(" * Documentation/trace/rv/deterministic_automata.rst") 67 67 buff.append(" */") 68 68 buff.append("") 69 + buff.append("#define MONITOR_NAME %s" % (self.name)) 70 + buff.append("") 69 71 70 72 return buff 71 73 72 - def fill_model_h(self): 74 + def fill_model_h(self) -> str: 73 75 # 74 76 # Adjust the definition names 75 77 # ··· 85 83 86 84 return '\n'.join(buff) 87 85 88 - def fill_monitor_class_type(self): 86 + def fill_monitor_class_type(self) -> str: 89 87 if self.monitor_type == "per_task": 90 88 return "DA_MON_EVENTS_ID" 91 89 return "DA_MON_EVENTS_IMPLICIT" 92 90 93 - def fill_monitor_class(self): 91 + def fill_monitor_class(self) -> str: 94 92 if self.monitor_type == "per_task": 95 93 return "da_monitor_id" 96 94 return "da_monitor" 97 95 98 - def fill_tracepoint_args_skel(self, tp_type): 96 + def fill_tracepoint_args_skel(self, tp_type: str) -> str: 99 97 buff = [] 100 98 tp_args_event = [ 101 99 ("char *", "state"), ··· 117 115 buff.append(" TP_ARGS(%s)" % tp_args_c) 118 116 return '\n'.join(buff) 119 117 120 - def fill_main_c(self): 118 + def fill_main_c(self) -> str: 121 119 main_c = super().fill_main_c() 122 120 123 121 min_type = self.get_minimun_type()
-2
tools/verification/rvgen/rvgen/templates/container/main.c
··· 8 8 9 9 #include "%%MODEL_NAME%%.h" 10 10 11 - struct rv_monitor rv_%%MODEL_NAME%%; 12 - 13 11 struct rv_monitor rv_%%MODEL_NAME%% = { 14 12 .name = "%%MODEL_NAME%%", 15 13 .description = "%%DESCRIPTION%%",
+9 -16
tools/verification/rvgen/rvgen/templates/dot2k/main.c
··· 6 6 #include <linux/init.h> 7 7 #include <linux/rv.h> 8 8 #include <rv/instrumentation.h> 9 - #include <rv/da_monitor.h> 10 9 11 10 #define MODULE_NAME "%%MODEL_NAME%%" 12 11 ··· 19 20 * This is the self-generated part of the monitor. Generally, there is no need 20 21 * to touch this section. 21 22 */ 23 + #define RV_MON_TYPE RV_MON_%%MONITOR_TYPE%% 22 24 #include "%%MODEL_NAME%%.h" 23 - 24 - /* 25 - * Declare the deterministic automata monitor. 26 - * 27 - * The rv monitor reference is needed for the monitor declaration. 28 - */ 29 - static struct rv_monitor rv_%%MODEL_NAME%%; 30 - DECLARE_DA_MON_%%MONITOR_TYPE%%(%%MODEL_NAME%%, %%MIN_TYPE%%); 25 + #include <rv/da_monitor.h> 31 26 32 27 /* 33 28 * This is the instrumentation part of the monitor. ··· 35 42 { 36 43 int retval; 37 44 38 - retval = da_monitor_init_%%MODEL_NAME%%(); 45 + retval = da_monitor_init(); 39 46 if (retval) 40 47 return retval; 41 48 ··· 46 53 47 54 static void disable_%%MODEL_NAME%%(void) 48 55 { 49 - rv_%%MODEL_NAME%%.enabled = 0; 56 + rv_this.enabled = 0; 50 57 51 58 %%TRACEPOINT_DETACH%% 52 59 53 - da_monitor_destroy_%%MODEL_NAME%%(); 60 + da_monitor_destroy(); 54 61 } 55 62 56 63 /* 57 64 * This is the monitor register section. 58 65 */ 59 - static struct rv_monitor rv_%%MODEL_NAME%% = { 66 + static struct rv_monitor rv_this = { 60 67 .name = "%%MODEL_NAME%%", 61 68 .description = "%%DESCRIPTION%%", 62 69 .enable = enable_%%MODEL_NAME%%, 63 70 .disable = disable_%%MODEL_NAME%%, 64 - .reset = da_monitor_reset_all_%%MODEL_NAME%%, 71 + .reset = da_monitor_reset_all, 65 72 .enabled = 0, 66 73 }; 67 74 68 75 static int __init register_%%MODEL_NAME%%(void) 69 76 { 70 - return rv_register_monitor(&rv_%%MODEL_NAME%%, %%PARENT%%); 77 + return rv_register_monitor(&rv_this, %%PARENT%%); 71 78 } 72 79 73 80 static void __exit unregister_%%MODEL_NAME%%(void) 74 81 { 75 - rv_unregister_monitor(&rv_%%MODEL_NAME%%); 82 + rv_unregister_monitor(&rv_this); 76 83 } 77 84 78 85 module_init(register_%%MODEL_NAME%%);