|
| 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 "sncid" |
| 12 | + |
| 13 | +#include <trace/events/sched.h> |
| 14 | +#include <trace/events/preemptirq.h> |
| 15 | +#include <rv_trace.h> |
| 16 | +#include <monitors/sched/sched.h> |
| 17 | + |
| 18 | +#include "sncid.h" |
| 19 | + |
| 20 | +static struct rv_monitor rv_sncid; |
| 21 | +DECLARE_DA_MON_PER_CPU(sncid, unsigned char); |
| 22 | + |
| 23 | +static void handle_irq_disable(void *data, unsigned long ip, unsigned long parent_ip) |
| 24 | +{ |
| 25 | + da_handle_event_sncid(irq_disable_sncid); |
| 26 | +} |
| 27 | + |
| 28 | +static void handle_irq_enable(void *data, unsigned long ip, unsigned long parent_ip) |
| 29 | +{ |
| 30 | + da_handle_start_event_sncid(irq_enable_sncid); |
| 31 | +} |
| 32 | + |
| 33 | +static void handle_schedule_entry(void *data, bool preempt, unsigned long ip) |
| 34 | +{ |
| 35 | + da_handle_start_event_sncid(schedule_entry_sncid); |
| 36 | +} |
| 37 | + |
| 38 | +static void handle_schedule_exit(void *data, bool is_switch, unsigned long ip) |
| 39 | +{ |
| 40 | + da_handle_start_event_sncid(schedule_exit_sncid); |
| 41 | +} |
| 42 | + |
| 43 | +static int enable_sncid(void) |
| 44 | +{ |
| 45 | + int retval; |
| 46 | + |
| 47 | + retval = da_monitor_init_sncid(); |
| 48 | + if (retval) |
| 49 | + return retval; |
| 50 | + |
| 51 | + rv_attach_trace_probe("sncid", irq_disable, handle_irq_disable); |
| 52 | + rv_attach_trace_probe("sncid", irq_enable, handle_irq_enable); |
| 53 | + rv_attach_trace_probe("sncid", sched_entry_tp, handle_schedule_entry); |
| 54 | + rv_attach_trace_probe("sncid", sched_exit_tp, handle_schedule_exit); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +static void disable_sncid(void) |
| 60 | +{ |
| 61 | + rv_sncid.enabled = 0; |
| 62 | + |
| 63 | + rv_detach_trace_probe("sncid", irq_disable, handle_irq_disable); |
| 64 | + rv_detach_trace_probe("sncid", irq_enable, handle_irq_enable); |
| 65 | + rv_detach_trace_probe("sncid", sched_entry_tp, handle_schedule_entry); |
| 66 | + rv_detach_trace_probe("sncid", sched_exit_tp, handle_schedule_exit); |
| 67 | + |
| 68 | + da_monitor_destroy_sncid(); |
| 69 | +} |
| 70 | + |
| 71 | +static struct rv_monitor rv_sncid = { |
| 72 | + .name = "sncid", |
| 73 | + .description = "schedule not called with interrupt disabled.", |
| 74 | + .enable = enable_sncid, |
| 75 | + .disable = disable_sncid, |
| 76 | + .reset = da_monitor_reset_all_sncid, |
| 77 | + .enabled = 0, |
| 78 | +}; |
| 79 | + |
| 80 | +static int __init register_sncid(void) |
| 81 | +{ |
| 82 | + rv_register_monitor(&rv_sncid, &rv_sched); |
| 83 | + return 0; |
| 84 | +} |
| 85 | + |
| 86 | +static void __exit unregister_sncid(void) |
| 87 | +{ |
| 88 | + rv_unregister_monitor(&rv_sncid); |
| 89 | +} |
| 90 | + |
| 91 | +module_init(register_sncid); |
| 92 | +module_exit(unregister_sncid); |
| 93 | + |
| 94 | +MODULE_LICENSE("GPL"); |
| 95 | +MODULE_AUTHOR("Gabriele Monaco <gmonaco@redhat.com>"); |
| 96 | +MODULE_DESCRIPTION("sncid: schedule not called with interrupt disabled."); |
0 commit comments