1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/module.h>
3 #include <linux/kthread.h>
4 #include <linux/ftrace.h>
6 extern void my_direct_func1(void);
7 extern void my_direct_func2(void);
9 void my_direct_func1(void)
11 trace_printk("my direct func1\n");
14 void my_direct_func2(void)
16 trace_printk("my direct func2\n");
19 extern void my_tramp1(void *);
20 extern void my_tramp2(void *);
22 static unsigned long my_ip = (unsigned long)schedule;
25 " .pushsection .text, \"ax\", @progbits\n"
26 " .type my_tramp1, @function\n"
31 " call my_direct_func1\n"
33 " .size my_tramp1, .-my_tramp1\n"
35 " .type my_tramp2, @function\n"
40 " call my_direct_func2\n"
43 " .size my_tramp2, .-my_tramp2\n"
47 static unsigned long my_tramp = (unsigned long)my_tramp1;
48 static unsigned long tramps[2] = {
49 (unsigned long)my_tramp1,
50 (unsigned long)my_tramp2,
53 static int simple_thread(void *arg)
58 while (!kthread_should_stop()) {
59 set_current_state(TASK_INTERRUPTIBLE);
60 schedule_timeout(2 * HZ);
65 ret = modify_ftrace_direct(my_ip, my_tramp, tramps[t]);
74 static struct task_struct *simple_tsk;
76 static int __init ftrace_direct_init(void)
80 ret = register_ftrace_direct(my_ip, my_tramp);
82 simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");
86 static void __exit ftrace_direct_exit(void)
88 kthread_stop(simple_tsk);
89 unregister_ftrace_direct(my_ip, my_tramp);
92 module_init(ftrace_direct_init);
93 module_exit(ftrace_direct_exit);
95 MODULE_AUTHOR("Steven Rostedt");
96 MODULE_DESCRIPTION("Example use case of using modify_ftrace_direct()");
97 MODULE_LICENSE("GPL");