xref: /linux/tools/verification/rvgen/tests/golden/da_global/da_global.c (revision 55ee4b931a7ffedc886175d265dd6e6d08fd4151)
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 "da_global"
11 
12 /*
13  * XXX: include required tracepoint headers, e.g.,
14  * #include <trace/events/sched.h>
15  */
16 #include <rv_trace.h>
17 
18 /*
19  * This is the self-generated part of the monitor. Generally, there is no need
20  * to touch this section.
21  */
22 #define RV_MON_TYPE RV_MON_GLOBAL
23 #include "da_global.h"
24 #include <rv/da_monitor.h>
25 
26 /*
27  * This is the instrumentation part of the monitor.
28  *
29  * This is the section where manual work is required. Here the kernel events
30  * are translated into model's event.
31  *
32  */
33 static void handle_event_1(void *data, /* XXX: fill header */)
34 {
35 	da_handle_event(event_1_da_global);
36 }
37 
38 static void handle_event_2(void *data, /* XXX: fill header */)
39 {
40 	/* XXX: validate that this event always leads to the initial state */
41 	da_handle_start_event(event_2_da_global);
42 }
43 
44 static int enable_da_global(void)
45 {
46 	int retval;
47 
48 	retval = da_monitor_init();
49 	if (retval)
50 		return retval;
51 
52 	rv_attach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_1);
53 	rv_attach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_2);
54 
55 	return 0;
56 }
57 
58 static void disable_da_global(void)
59 {
60 	rv_this.enabled = 0;
61 
62 	rv_detach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_1);
63 	rv_detach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_2);
64 
65 	da_monitor_destroy();
66 }
67 
68 /*
69  * This is the monitor register section.
70  */
71 static struct rv_monitor rv_this = {
72 	.name = "da_global",
73 	.description = "auto-generated",
74 	.enable = enable_da_global,
75 	.disable = disable_da_global,
76 	.reset = da_monitor_reset_all,
77 	.enabled = 0,
78 };
79 
80 static int __init register_da_global(void)
81 {
82 	return rv_register_monitor(&rv_this, NULL);
83 }
84 
85 static void __exit unregister_da_global(void)
86 {
87 	rv_unregister_monitor(&rv_this);
88 }
89 
90 module_init(register_da_global);
91 module_exit(unregister_da_global);
92 
93 MODULE_LICENSE("GPL");
94 MODULE_AUTHOR("rvgen: auto-generated");
95 MODULE_DESCRIPTION("da_global: auto-generated");
96