| 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 "snroc" |
| 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_TASK |
| 17 |
#include "snroc.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_event(tsk, sched_set_state_snroc); |
| 23 |
} |
| 24 |
|
| 25 |
static void handle_sched_switch(void *data, bool preempt, |
| 26 |
struct task_struct *prev, |
| 27 |
struct task_struct *next, |
| 28 |
unsigned int prev_state) |
| 29 |
{ |
| 30 |
da_handle_start_event(prev, sched_switch_out_snroc); |
| 31 |
da_handle_event(next, sched_switch_in_snroc); |
| 32 |
} |
| 33 |
|
| 34 |
static int enable_snroc(void) |
| 35 |
{ |
| 36 |
int retval; |
| 37 |
|
| 38 |
retval = da_monitor_init(); |
| 39 |
if (retval) |
| 40 |
return retval; |
| 41 |
|
| 42 |
rv_attach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state); |
| 43 |
rv_attach_trace_probe("snroc", sched_switch, handle_sched_switch); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
static void disable_snroc(void) |
| 49 |
{ |
| 50 |
rv_this.enabled = 0; |
| 51 |
|
| 52 |
rv_detach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state); |
| 53 |
rv_detach_trace_probe("snroc", sched_switch, handle_sched_switch); |
| 54 |
|
| 55 |
da_monitor_destroy(); |
| 56 |
} |
| 57 |
|
| 58 |
static struct rv_monitor rv_this = { |
| 59 |
.name = "snroc", |
| 60 |
.description = "set non runnable on its own context.", |
| 61 |
.enable = enable_snroc, |
| 62 |
.disable = disable_snroc, |
| 63 |
.reset = da_monitor_reset_all, |
| 64 |
.enabled = 0, |
| 65 |
}; |
| 66 |
|
| 67 |
static int __init register_snroc(void) |
| 68 |
{ |
| 69 |
return rv_register_monitor(&rv_this, &rv_sched); |
| 70 |
} |
| 71 |
|
| 72 |
static void __exit unregister_snroc(void) |
| 73 |
{ |
| 74 |
rv_unregister_monitor(&rv_this); |
| 75 |
} |
| 76 |
|
| 77 |
module_init(register_snroc); |
| 78 |
module_exit(unregister_snroc); |
| 79 |
|
| 80 |
MODULE_LICENSE("GPL"); |
| 81 |
MODULE_AUTHOR("Gabriele Monaco <[email protected]>"); |
| 82 |
MODULE_DESCRIPTION("snroc: set non runnable on its own context."); |