Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/ftrace.h>
0003 #include <linux/tracepoint.h>
0004 #include <linux/kernel.h>
0005 #include <linux/module.h>
0006 #include <linux/init.h>
0007 #include <linux/rv.h>
0008 #include <rv/instrumentation.h>
0009 #include <rv/da_monitor.h>
0010 
0011 #define MODULE_NAME "wwnr"
0012 
0013 #include <trace/events/rv.h>
0014 #include <trace/events/sched.h>
0015 
0016 #include "wwnr.h"
0017 
0018 struct rv_monitor rv_wwnr;
0019 DECLARE_DA_MON_PER_TASK(wwnr, unsigned char);
0020 
0021 static void handle_switch(void *data, bool preempt, struct task_struct *p,
0022               struct task_struct *n, unsigned int prev_state)
0023 {
0024     /* start monitoring only after the first suspension */
0025     if (prev_state == TASK_INTERRUPTIBLE)
0026         da_handle_start_event_wwnr(p, switch_out_wwnr);
0027     else
0028         da_handle_event_wwnr(p, switch_out_wwnr);
0029 
0030     da_handle_event_wwnr(n, switch_in_wwnr);
0031 }
0032 
0033 static void handle_wakeup(void *data, struct task_struct *p)
0034 {
0035     da_handle_event_wwnr(p, wakeup_wwnr);
0036 }
0037 
0038 static int enable_wwnr(void)
0039 {
0040     int retval;
0041 
0042     retval = da_monitor_init_wwnr();
0043     if (retval)
0044         return retval;
0045 
0046     rv_attach_trace_probe("wwnr", sched_switch, handle_switch);
0047     rv_attach_trace_probe("wwnr", sched_wakeup, handle_wakeup);
0048 
0049     return 0;
0050 }
0051 
0052 static void disable_wwnr(void)
0053 {
0054     rv_wwnr.enabled = 0;
0055 
0056     rv_detach_trace_probe("wwnr", sched_switch, handle_switch);
0057     rv_detach_trace_probe("wwnr", sched_wakeup, handle_wakeup);
0058 
0059     da_monitor_destroy_wwnr();
0060 }
0061 
0062 struct rv_monitor rv_wwnr = {
0063     .name = "wwnr",
0064     .description = "wakeup while not running per-task testing model.",
0065     .enable = enable_wwnr,
0066     .disable = disable_wwnr,
0067     .reset = da_monitor_reset_all_wwnr,
0068     .enabled = 0,
0069 };
0070 
0071 static int register_wwnr(void)
0072 {
0073     rv_register_monitor(&rv_wwnr);
0074     return 0;
0075 }
0076 
0077 static void unregister_wwnr(void)
0078 {
0079     rv_unregister_monitor(&rv_wwnr);
0080 }
0081 
0082 module_init(register_wwnr);
0083 module_exit(unregister_wwnr);
0084 
0085 MODULE_LICENSE("GPL");
0086 MODULE_AUTHOR("Daniel Bristot de Oliveira <bristot@kernel.org>");
0087 MODULE_DESCRIPTION("wwnr: wakeup while not running monitor");