xref: /linux/kernel/trace/rv/monitors/snroc/snroc.c (revision 88221ac0d560700b50493aedc768f728aa585141)
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 "snroc"
12 
13 #include <trace/events/sched.h>
14 #include <rv_trace.h>
15 #include <monitors/sched/sched.h>
16 
17 #include "snroc.h"
18 
19 static struct rv_monitor rv_snroc;
20 DECLARE_DA_MON_PER_TASK(snroc, unsigned char);
21 
handle_sched_set_state(void * data,struct task_struct * tsk,int state)22 static void handle_sched_set_state(void *data, struct task_struct *tsk, int state)
23 {
24 	da_handle_event_snroc(tsk, sched_set_state_snroc);
25 }
26 
handle_sched_switch(void * data,bool preempt,struct task_struct * prev,struct task_struct * next,unsigned int prev_state)27 static void handle_sched_switch(void *data, bool preempt,
28 				struct task_struct *prev,
29 				struct task_struct *next,
30 				unsigned int prev_state)
31 {
32 	da_handle_start_event_snroc(prev, sched_switch_out_snroc);
33 	da_handle_event_snroc(next, sched_switch_in_snroc);
34 }
35 
enable_snroc(void)36 static int enable_snroc(void)
37 {
38 	int retval;
39 
40 	retval = da_monitor_init_snroc();
41 	if (retval)
42 		return retval;
43 
44 	rv_attach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state);
45 	rv_attach_trace_probe("snroc", sched_switch, handle_sched_switch);
46 
47 	return 0;
48 }
49 
disable_snroc(void)50 static void disable_snroc(void)
51 {
52 	rv_snroc.enabled = 0;
53 
54 	rv_detach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state);
55 	rv_detach_trace_probe("snroc", sched_switch, handle_sched_switch);
56 
57 	da_monitor_destroy_snroc();
58 }
59 
60 static struct rv_monitor rv_snroc = {
61 	.name = "snroc",
62 	.description = "set non runnable on its own context.",
63 	.enable = enable_snroc,
64 	.disable = disable_snroc,
65 	.reset = da_monitor_reset_all_snroc,
66 	.enabled = 0,
67 };
68 
register_snroc(void)69 static int __init register_snroc(void)
70 {
71 	rv_register_monitor(&rv_snroc, &rv_sched);
72 	return 0;
73 }
74 
unregister_snroc(void)75 static void __exit unregister_snroc(void)
76 {
77 	rv_unregister_monitor(&rv_snroc);
78 }
79 
80 module_init(register_snroc);
81 module_exit(unregister_snroc);
82 
83 MODULE_LICENSE("GPL");
84 MODULE_AUTHOR("Gabriele Monaco <gmonaco@redhat.com>");
85 MODULE_DESCRIPTION("snroc: set non runnable on its own context.");
86