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
19static struct rv_monitor rv_wip;
20DECLARE_DA_MON_PER_CPU(wip, unsigned char);
21
22static void handle_preempt_disable(void *data, unsigned long ip, unsigned long parent_ip)
23{
24 da_handle_event_wip(event: preempt_disable_wip);
25}
26
27static void handle_preempt_enable(void *data, unsigned long ip, unsigned long parent_ip)
28{
29 da_handle_start_event_wip(event: preempt_enable_wip);
30}
31
32static void handle_sched_waking(void *data, struct task_struct *task)
33{
34 da_handle_event_wip(event: sched_waking_wip);
35}
36
37static 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
52static 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
63static 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
72static int __init register_wip(void)
73{
74 rv_register_monitor(monitor: &rv_wip);
75 return 0;
76}
77
78static void __exit unregister_wip(void)
79{
80 rv_unregister_monitor(monitor: &rv_wip);
81}
82
83module_init(register_wip);
84module_exit(unregister_wip);
85
86MODULE_LICENSE("GPL");
87MODULE_AUTHOR("Daniel Bristot de Oliveira <bristot@kernel.org>");
88MODULE_DESCRIPTION("wip: wakeup in preemptive - per-cpu sample monitor.");
89

source code of linux/kernel/trace/rv/monitors/wip/wip.c