1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/module.h>
3 #include <linux/kthread.h>
4 #include <linux/ftrace.h>
6 void my_direct_func1(void)
8 trace_printk("my direct func1\n");
11 void my_direct_func2(void)
13 trace_printk("my direct func2\n");
16 extern void my_tramp1(void *);
17 extern void my_tramp2(void *);
19 static unsigned long my_ip
= (unsigned long)schedule
;
22 " .pushsection .text, \"ax\", @progbits\n"
23 " .type my_tramp1, @function\n"
28 " call my_direct_func1\n"
30 " .size my_tramp1, .-my_tramp1\n"
32 " .type my_tramp2, @function\n"
37 " call my_direct_func2\n"
40 " .size my_tramp2, .-my_tramp2\n"
44 static unsigned long my_tramp
= (unsigned long)my_tramp1
;
45 static unsigned long tramps
[2] = {
46 (unsigned long)my_tramp1
,
47 (unsigned long)my_tramp2
,
50 static int simple_thread(void *arg
)
55 while (!kthread_should_stop()) {
56 set_current_state(TASK_INTERRUPTIBLE
);
57 schedule_timeout(2 * HZ
);
62 ret
= modify_ftrace_direct(my_ip
, my_tramp
, tramps
[t
]);
71 static struct task_struct
*simple_tsk
;
73 static int __init
ftrace_direct_init(void)
77 ret
= register_ftrace_direct(my_ip
, my_tramp
);
79 simple_tsk
= kthread_run(simple_thread
, NULL
, "event-sample-fn");
83 static void __exit
ftrace_direct_exit(void)
85 kthread_stop(simple_tsk
);
86 unregister_ftrace_direct(my_ip
, my_tramp
);
89 module_init(ftrace_direct_init
);
90 module_exit(ftrace_direct_exit
);
92 MODULE_AUTHOR("Steven Rostedt");
93 MODULE_DESCRIPTION("Example use case of using modify_ftrace_direct()");
94 MODULE_LICENSE("GPL");