xref: /linux/kernel/trace/rv/monitors/sco/sco.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 "sco"
12 
13 #include <trace/events/sched.h>
14 #include <rv_trace.h>
15 #include <monitors/sched/sched.h>
16 
17 #include "sco.h"
18 
19 static struct rv_monitor rv_sco;
20 DECLARE_DA_MON_PER_CPU(sco, 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_start_event_sco(sched_set_state_sco);
25 }
26 
handle_schedule_entry(void * data,bool preempt,unsigned long ip)27 static void handle_schedule_entry(void *data, bool preempt, unsigned long ip)
28 {
29 	da_handle_event_sco(schedule_entry_sco);
30 }
31 
handle_schedule_exit(void * data,bool is_switch,unsigned long ip)32 static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip)
33 {
34 	da_handle_start_event_sco(schedule_exit_sco);
35 }
36 
enable_sco(void)37 static int enable_sco(void)
38 {
39 	int retval;
40 
41 	retval = da_monitor_init_sco();
42 	if (retval)
43 		return retval;
44 
45 	rv_attach_trace_probe("sco", sched_set_state_tp, handle_sched_set_state);
46 	rv_attach_trace_probe("sco", sched_entry_tp, handle_schedule_entry);
47 	rv_attach_trace_probe("sco", sched_exit_tp, handle_schedule_exit);
48 
49 	return 0;
50 }
51 
disable_sco(void)52 static void disable_sco(void)
53 {
54 	rv_sco.enabled = 0;
55 
56 	rv_detach_trace_probe("sco", sched_set_state_tp, handle_sched_set_state);
57 	rv_detach_trace_probe("sco", sched_entry_tp, handle_schedule_entry);
58 	rv_detach_trace_probe("sco", sched_exit_tp, handle_schedule_exit);
59 
60 	da_monitor_destroy_sco();
61 }
62 
63 static struct rv_monitor rv_sco = {
64 	.name = "sco",
65 	.description = "scheduling context operations.",
66 	.enable = enable_sco,
67 	.disable = disable_sco,
68 	.reset = da_monitor_reset_all_sco,
69 	.enabled = 0,
70 };
71 
register_sco(void)72 static int __init register_sco(void)
73 {
74 	rv_register_monitor(&rv_sco, &rv_sched);
75 	return 0;
76 }
77 
unregister_sco(void)78 static void __exit unregister_sco(void)
79 {
80 	rv_unregister_monitor(&rv_sco);
81 }
82 
83 module_init(register_sco);
84 module_exit(unregister_sco);
85 
86 MODULE_LICENSE("GPL");
87 MODULE_AUTHOR("Gabriele Monaco <gmonaco@redhat.com>");
88 MODULE_DESCRIPTION("sco: scheduling context operations.");
89