xref: /linux/kernel/trace/rv/monitors/wip/wip.c (revision 1fd1dc41724319406b0aff221a352a400b0ddfc5)
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>
7 #include <linux/rv.h>
8 #include <rv/instrumentation.h>
9 
10 #define MODULE_NAME "wip"
11 
12 #include <rv_trace.h>
13 #include <trace/events/sched.h>
14 #include <trace/events/preemptirq.h>
15 
16 #define RV_MON_TYPE RV_MON_PER_CPU
17 #include "wip.h"
18 #include <rv/da_monitor.h>
19 
20 static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
21 {
22 	da_handle_event(preempt_disable_wip);
23 }
24 
25 static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
26 {
27 	da_handle_start_event(preempt_enable_wip);
28 }
29 
30 static void handle_sched_waking(void *data, struct task_struct *task)
31 {
32 	da_handle_event(sched_waking_wip);
33 }
34 
35 static int enable_wip(void)
36 {
37 	int retval;
38 
39 	retval = da_monitor_init();
40 	if (retval)
41 		return retval;
42 
43 	rv_attach_trace_probe("wip", preempt_enable, handle_preempt_enable);
44 	rv_attach_trace_probe("wip", sched_waking, handle_sched_waking);
45 	rv_attach_trace_probe("wip", preempt_disable, handle_preempt_disable);
46 
47 	return 0;
48 }
49 
50 static void disable_wip(void)
51 {
52 	rv_this.enabled = 0;
53 
54 	rv_detach_trace_probe("wip", preempt_disable, handle_preempt_disable);
55 	rv_detach_trace_probe("wip", preempt_enable, handle_preempt_enable);
56 	rv_detach_trace_probe("wip", sched_waking, handle_sched_waking);
57 
58 	da_monitor_destroy();
59 }
60 
61 static struct rv_monitor rv_this = {
62 	.name = "wip",
63 	.description = "wakeup in preemptive per-cpu testing monitor.",
64 	.enable = enable_wip,
65 	.disable = disable_wip,
66 	.reset = da_monitor_reset_all,
67 	.enabled = 0,
68 };
69 
70 static int __init register_wip(void)
71 {
72 	return rv_register_monitor(&rv_this, NULL);
73 }
74 
75 static void __exit unregister_wip(void)
76 {
77 	rv_unregister_monitor(&rv_this);
78 }
79 
80 module_init(register_wip);
81 module_exit(unregister_wip);
82 
83 MODULE_LICENSE("GPL");
84 MODULE_AUTHOR("Daniel Bristot de Oliveira <bristot@kernel.org>");
85 MODULE_DESCRIPTION("wip: wakeup in preemptive - per-cpu sample monitor.");
86