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