1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ftrace.h>
3 #include <linux/tracepoint.h>
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/init.h>
8 #include <rv/instrumentation.h>
9 #include <rv/da_monitor.h>
11 #define MODULE_NAME "wwnr"
13 #include <trace/events/rv.h>
14 #include <trace/events/sched.h>
18 static struct rv_monitor rv_wwnr;
19 DECLARE_DA_MON_PER_TASK(wwnr, unsigned char);
21 static void handle_switch(void *data, bool preempt, struct task_struct *p,
22 struct task_struct *n, unsigned int prev_state)
24 /* start monitoring only after the first suspension */
25 if (prev_state == TASK_INTERRUPTIBLE)
26 da_handle_start_event_wwnr(p, switch_out_wwnr);
28 da_handle_event_wwnr(p, switch_out_wwnr);
30 da_handle_event_wwnr(n, switch_in_wwnr);
33 static void handle_wakeup(void *data, struct task_struct *p)
35 da_handle_event_wwnr(p, wakeup_wwnr);
38 static int enable_wwnr(void)
42 retval = da_monitor_init_wwnr();
46 rv_attach_trace_probe("wwnr", sched_switch, handle_switch);
47 rv_attach_trace_probe("wwnr", sched_wakeup, handle_wakeup);
52 static void disable_wwnr(void)
56 rv_detach_trace_probe("wwnr", sched_switch, handle_switch);
57 rv_detach_trace_probe("wwnr", sched_wakeup, handle_wakeup);
59 da_monitor_destroy_wwnr();
62 static struct rv_monitor rv_wwnr = {
64 .description = "wakeup while not running per-task testing model.",
65 .enable = enable_wwnr,
66 .disable = disable_wwnr,
67 .reset = da_monitor_reset_all_wwnr,
71 static int __init register_wwnr(void)
73 rv_register_monitor(&rv_wwnr);
77 static void __exit unregister_wwnr(void)
79 rv_unregister_monitor(&rv_wwnr);
82 module_init(register_wwnr);
83 module_exit(unregister_wwnr);
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Daniel Bristot de Oliveira <bristot@kernel.org>");
87 MODULE_DESCRIPTION("wwnr: wakeup while not running monitor");