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 "wwnr" 12 13#include <trace/events/rv.h> 14#include <trace/events/sched.h> 15 16#include "wwnr.h" 17 18static struct rv_monitor rv_wwnr; 19DECLARE_DA_MON_PER_TASK(wwnr, unsigned char); 20 21static void handle_switch(void *data, bool preempt, struct task_struct *p, 22 struct task_struct *n, unsigned int prev_state) 23{ 24 /* start monitoring only after the first suspension */ 25 if (prev_state == TASK_INTERRUPTIBLE) 26 da_handle_start_event_wwnr(p, switch_out_wwnr); 27 else 28 da_handle_event_wwnr(p, switch_out_wwnr); 29 30 da_handle_event_wwnr(n, switch_in_wwnr); 31} 32 33static void handle_wakeup(void *data, struct task_struct *p) 34{ 35 da_handle_event_wwnr(p, wakeup_wwnr); 36} 37 38static int enable_wwnr(void) 39{ 40 int retval; 41 42 retval = da_monitor_init_wwnr(); 43 if (retval) 44 return retval; 45 46 rv_attach_trace_probe("wwnr", sched_switch, handle_switch); 47 rv_attach_trace_probe("wwnr", sched_wakeup, handle_wakeup); 48 49 return 0; 50} 51 52static void disable_wwnr(void) 53{ 54 rv_wwnr.enabled = 0; 55 56 rv_detach_trace_probe("wwnr", sched_switch, handle_switch); 57 rv_detach_trace_probe("wwnr", sched_wakeup, handle_wakeup); 58 59 da_monitor_destroy_wwnr(); 60} 61 62static struct rv_monitor rv_wwnr = { 63 .name = "wwnr", 64 .description = "wakeup while not running per-task testing model.", 65 .enable = enable_wwnr, 66 .disable = disable_wwnr, 67 .reset = da_monitor_reset_all_wwnr, 68 .enabled = 0, 69}; 70 71static int __init register_wwnr(void) 72{ 73 rv_register_monitor(&rv_wwnr); 74 return 0; 75} 76 77static void __exit unregister_wwnr(void) 78{ 79 rv_unregister_monitor(&rv_wwnr); 80} 81 82module_init(register_wwnr); 83module_exit(unregister_wwnr); 84 85MODULE_LICENSE("GPL"); 86MODULE_AUTHOR("Daniel Bristot de Oliveira <bristot@kernel.org>"); 87MODULE_DESCRIPTION("wwnr: wakeup while not running monitor"); 88