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