xref: /linux/kernel/trace/rv/monitors/wip/wip.c (revision 8812d21219b9c649dd25eb93915e00939944aeb7)
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 #include <rv/da_monitor.h>
10 
11 #define MODULE_NAME "wip"
12 
13 /*
14  * XXX: include required tracepoint headers, e.g.,
15  * #include <linux/trace/events/sched.h>
16  */
17 #include <trace/events/rv.h>
18 
19 /*
20  * This is the self-generated part of the monitor. Generally, there is no need
21  * to touch this section.
22  */
23 #include "wip.h"
24 
25 /*
26  * Declare the deterministic automata monitor.
27  *
28  * The rv monitor reference is needed for the monitor declaration.
29  */
30 struct rv_monitor rv_wip;
31 DECLARE_DA_MON_PER_CPU(wip, unsigned char);
32 
33 /*
34  * This is the instrumentation part of the monitor.
35  *
36  * This is the section where manual work is required. Here the kernel events
37  * are translated into model's event.
38  *
39  */
40 static void handle_preempt_disable(void *data, /* XXX: fill header */)
41 {
42 	da_handle_event_wip(preempt_disable_wip);
43 }
44 
45 static void handle_preempt_enable(void *data, /* XXX: fill header */)
46 {
47 	da_handle_event_wip(preempt_enable_wip);
48 }
49 
50 static void handle_sched_waking(void *data, /* XXX: fill header */)
51 {
52 	da_handle_event_wip(sched_waking_wip);
53 }
54 
55 static int enable_wip(void)
56 {
57 	int retval;
58 
59 	retval = da_monitor_init_wip();
60 	if (retval)
61 		return retval;
62 
63 	rv_attach_trace_probe("wip", /* XXX: tracepoint */, handle_preempt_disable);
64 	rv_attach_trace_probe("wip", /* XXX: tracepoint */, handle_preempt_enable);
65 	rv_attach_trace_probe("wip", /* XXX: tracepoint */, handle_sched_waking);
66 
67 	return 0;
68 }
69 
70 static void disable_wip(void)
71 {
72 	rv_wip.enabled = 0;
73 
74 	rv_detach_trace_probe("wip", /* XXX: tracepoint */, handle_preempt_disable);
75 	rv_detach_trace_probe("wip", /* XXX: tracepoint */, handle_preempt_enable);
76 	rv_detach_trace_probe("wip", /* XXX: tracepoint */, handle_sched_waking);
77 
78 	da_monitor_destroy_wip();
79 }
80 
81 /*
82  * This is the monitor register section.
83  */
84 struct rv_monitor rv_wip = {
85 	.name = "wip",
86 	.description = "auto-generated wip",
87 	.enable = enable_wip,
88 	.disable = disable_wip,
89 	.reset = da_monitor_reset_all_wip,
90 	.enabled = 0,
91 };
92 
93 static int register_wip(void)
94 {
95 	rv_register_monitor(&rv_wip);
96 	return 0;
97 }
98 
99 static void unregister_wip(void)
100 {
101 	rv_unregister_monitor(&rv_wip);
102 }
103 
104 module_init(register_wip);
105 module_exit(unregister_wip);
106 
107 MODULE_LICENSE("GPL");
108 MODULE_AUTHOR("dot2k: auto-generated");
109 MODULE_DESCRIPTION("wip");
110