* models in C generated by the dot2k tool.
*/
+#ifndef _RV_AUTOMATA_H
+#define _RV_AUTOMATA_H
+
#ifndef MONITOR_NAME
#error "MONITOR_NAME macro is not defined. Did you include $(MODEL_NAME).h generated by rvgen?"
#endif
-#ifndef type
-#define type unsigned char
-#endif
-
#define RV_AUTOMATON_NAME CONCATENATE(automaton_, MONITOR_NAME)
#define EVENT_MAX CONCATENATE(event_max_, MONITOR_NAME)
#define STATE_MAX CONCATENATE(state_max_, MONITOR_NAME)
#define events CONCATENATE(events_, MONITOR_NAME)
#define states CONCATENATE(states_, MONITOR_NAME)
-/*
- * DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata
- *
- * Define a set of helper functions for automata. The 'name' argument is used
- * as suffix for the functions and data. These functions will handle automaton
- * with data type 'type'.
- */
-#define DECLARE_AUTOMATA_HELPERS(name, type)
-
/*
* model_get_state_name - return the (string) name of the given state
*/
/*
* model_get_initial_state - return the automaton's initial state
*/
-static inline type model_get_initial_state(void)
+static inline enum states model_get_initial_state(void)
{
return RV_AUTOMATON_NAME.initial_state;
}
* Given the current state (curr_state) and the event (event), returns
* the next state, or INVALID_STATE in case of error.
*/
-static inline type model_get_next_state(enum states curr_state,
- enum events event)
+static inline enum states model_get_next_state(enum states curr_state,
+ enum events event)
{
if ((curr_state < 0) || (curr_state >= STATE_MAX))
return INVALID_STATE;
return RV_AUTOMATON_NAME.final_states[state];
}
+
+#endif
* Documentation/trace/rv/da_monitor_synthesis.rst
*/
+#ifndef _RV_DA_MONITOR_H
+#define _RV_DA_MONITOR_H
+
#include <rv/automata.h>
#include <linux/rv.h>
#include <linux/stringify.h>
static struct rv_monitor rv_this;
-/*
- * Generic helpers for all types of deterministic automata monitors.
- */
-#define DECLARE_DA_MON_GENERIC_HELPERS(name, type)
-
-static void react(type curr_state, type event)
+static void react(enum states curr_state, enum events event)
{
rv_react(&rv_this,
"rv: monitor %s does not allow event %s on state %s\n",
*/
static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
{
-
if (!da_monitor_enabled())
return 0;
return 1;
}
+#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
/*
* Event handler for implicit monitors. Implicit monitor is the one which the
* handler does not need to specify which da_monitor to manipulate. Examples
* warn and reset the monitor if it runs out of retries. The monitor should be
* able to handle various orders.
*/
-#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
-static inline bool
-da_event(struct da_monitor *da_mon, enum events event)
+static inline bool da_event(struct da_monitor *da_mon, enum events event)
{
enum states curr_state, next_state;
next_state = model_get_next_state(curr_state, event);
if (next_state == INVALID_STATE) {
react(curr_state, event);
- CONCATENATE(trace_error_, MONITOR_NAME)(model_get_state_name(curr_state),
- model_get_event_name(event));
+ CONCATENATE(trace_error_, MONITOR_NAME)(
+ model_get_state_name(curr_state),
+ model_get_event_name(event));
return false;
}
if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) {
- CONCATENATE(trace_event_, MONITOR_NAME)(model_get_state_name(curr_state),
- model_get_event_name(event),
- model_get_state_name(next_state),
- model_is_final_state(next_state));
+ CONCATENATE(trace_event_, MONITOR_NAME)(
+ model_get_state_name(curr_state),
+ model_get_event_name(event),
+ model_get_state_name(next_state),
+ model_is_final_state(next_state));
return true;
}
}
return false;
}
+#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* Event handler for per_task monitors.
*
* warn and reset the monitor if it runs out of retries. The monitor should be
* able to handle various orders.
*/
-#elif RV_MON_TYPE == RV_MON_PER_TASK
static inline bool da_event(struct da_monitor *da_mon, struct task_struct *tsk,
- enum events event)
+ enum events event)
{
enum states curr_state, next_state;
if (next_state == INVALID_STATE) {
react(curr_state, event);
CONCATENATE(trace_error_, MONITOR_NAME)(tsk->pid,
- model_get_state_name(curr_state),
- model_get_event_name(event));
+ model_get_state_name(curr_state),
+ model_get_event_name(event));
return false;
}
if (likely(try_cmpxchg(&da_mon->curr_state, &curr_state, next_state))) {
CONCATENATE(trace_event_, MONITOR_NAME)(tsk->pid,
- model_get_state_name(curr_state),
- model_get_event_name(event),
- model_get_state_name(next_state),
- model_is_final_state(next_state));
+ model_get_state_name(curr_state),
+ model_get_event_name(event),
+ model_get_state_name(next_state),
+ model_is_final_state(next_state));
return true;
}
}
model_get_event_name(event), __stringify(MONITOR_NAME));
return false;
}
-#endif
+#endif /* RV_MON_TYPE */
+#if RV_MON_TYPE == RV_MON_GLOBAL
/*
* Functions to define, init and get a global monitor.
*/
-#if RV_MON_TYPE == RV_MON_GLOBAL
/*
* global monitor (a single variable)
/*
* da_monitor_destroy - destroy the monitor
*/
-static inline void da_monitor_destroy(void)
-{
- return;
-}
+static inline void da_monitor_destroy(void) { }
+#elif RV_MON_TYPE == RV_MON_PER_CPU
/*
* Functions to define, init and get a per-cpu monitor.
*/
-#elif RV_MON_TYPE == RV_MON_PER_CPU
/*
* per-cpu monitor variables
{
struct da_monitor *da_mon;
int cpu;
+
for_each_cpu(cpu, cpu_online_mask) {
da_mon = per_cpu_ptr(&da_mon_this, cpu);
da_monitor_reset(da_mon);
/*
* da_monitor_destroy - destroy the monitor
*/
-static inline void da_monitor_destroy(void)
-{
- return;
-}
+static inline void da_monitor_destroy(void) { }
+#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* Functions to define, init and get a per-task monitor.
*/
-#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* The per-task monitor is stored a vector in the task struct. This variable
}
rv_put_task_monitor_slot(task_mon_slot);
task_mon_slot = RV_PER_TASK_MONITOR_INIT;
- return;
}
-#endif
+#endif /* RV_MON_TYPE */
+#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
/*
* Handle event for implicit monitor: da_get_monitor() will figure out
* the monitor.
*/
-#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
static inline void __da_handle_event(struct da_monitor *da_mon,
- enum events event)
+ enum events event)
{
bool retval;
return 1;
}
+#elif RV_MON_TYPE == RV_MON_PER_TASK
/*
* Handle event for per task.
*/
-#elif RV_MON_TYPE == RV_MON_PER_TASK
-static inline void
-__da_handle_event(struct da_monitor *da_mon, struct task_struct *tsk,
- enum events event)
+static inline void __da_handle_event(struct da_monitor *da_mon,
+ struct task_struct *tsk, enum events event)
{
bool retval;
/*
* da_handle_event - handle an event
*/
-static inline void
-da_handle_event(struct task_struct *tsk, enum events event)
+static inline void da_handle_event(struct task_struct *tsk, enum events event)
{
struct da_monitor *da_mon = da_get_monitor(tsk);
bool retval;
* If the monitor already started, handle the event.
* If the monitor did not start yet, start the monitor but skip the event.
*/
-static inline bool
-da_handle_start_event(struct task_struct *tsk, enum events event)
+static inline bool da_handle_start_event(struct task_struct *tsk,
+ enum events event)
{
struct da_monitor *da_mon;
* This function is used to notify the monitor that the system is in the
* initial state, so the monitor can start monitoring and handling event.
*/
-static inline bool
-da_handle_start_run_event(struct task_struct *tsk, enum events event)
+static inline bool da_handle_start_run_event(struct task_struct *tsk,
+ enum events event)
{
struct da_monitor *da_mon;
return 1;
}
-#endif
+#endif /* RV_MON_TYPE */
-/*
- * Entry point for the global monitor.
- */
-#define DECLARE_DA_MON_GLOBAL(name, type)
-
-/*
- * Entry point for the per-cpu monitor.
- */
-#define DECLARE_DA_MON_PER_CPU(name, type)
-
-/*
- * Entry point for the per-task monitor.
- */
-#define DECLARE_DA_MON_PER_TASK(name, type)
+#endif