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 "test_da_kunit" 11 12 /* 13 * XXX: include required tracepoint headers, e.g., 14 * #include <trace/events/sched.h> 15 */ 16 #include <rv_trace.h> 17 18 /* 19 * This is the self-generated part of the monitor. Generally, there is no need 20 * to touch this section. 21 */ 22 #define RV_MON_TYPE RV_MON_PER_CPU 23 #include "test_da_kunit.h" 24 #include <rv/da_monitor.h> 25 26 /* 27 * This is the instrumentation part of the monitor. 28 * 29 * This is the section where manual work is required. Here the kernel events 30 * are translated into model's event. 31 * 32 */ 33 static void handle_event_1(void *data, /* XXX: fill header */) 34 { 35 da_handle_event(event_1_test_da_kunit); 36 } 37 38 static void handle_event_2(void *data, /* XXX: fill header */) 39 { 40 /* XXX: validate that this event always leads to the initial state */ 41 da_handle_start_event(event_2_test_da_kunit); 42 } 43 44 static int enable_test_da_kunit(void) 45 { 46 int retval; 47 48 retval = da_monitor_init(); 49 if (retval) 50 return retval; 51 52 rv_attach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_event_1); 53 rv_attach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_event_2); 54 55 return 0; 56 } 57 58 static void disable_test_da_kunit(void) 59 { 60 rv_this.enabled = 0; 61 62 rv_detach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_event_1); 63 rv_detach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_event_2); 64 65 da_monitor_destroy(); 66 } 67 68 /* 69 * This is the monitor register section. 70 */ 71 static struct rv_monitor rv_this = { 72 .name = "test_da_kunit", 73 .description = "auto-generated", 74 .enable = enable_test_da_kunit, 75 .disable = disable_test_da_kunit, 76 .reset = da_monitor_reset_all, 77 .enabled = 0, 78 }; 79 80 static int __init register_test_da_kunit(void) 81 { 82 return rv_register_monitor(&rv_this, NULL); 83 } 84 85 static void __exit unregister_test_da_kunit(void) 86 { 87 rv_unregister_monitor(&rv_this); 88 } 89 90 module_init(register_test_da_kunit); 91 module_exit(unregister_test_da_kunit); 92 93 MODULE_LICENSE("GPL"); 94 MODULE_AUTHOR("rvgen: auto-generated"); 95 MODULE_DESCRIPTION("test_da_kunit: auto-generated"); 96 97 #if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) 98 #include <kunit/visibility.h> 99 #include "test_da_kunit_kunit.h" 100 101 const struct rv_test_da_kunit_ops rv_test_da_kunit_ops = { 102 .mon = RV_MON_OPS_INIT(), 103 .handle_event_1 = handle_event_1, 104 .handle_event_2 = handle_event_2, 105 }; 106 EXPORT_SYMBOL_IF_KUNIT(rv_test_da_kunit_ops); 107 #endif 108