1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/module.h>
3 #include <linux/kthread.h>
4 #include <linux/ftrace.h>
5 #include <asm/asm-offsets.h>
7 void my_direct_func1(void)
9 trace_printk("my direct func1\n");
12 void my_direct_func2(void)
14 trace_printk("my direct func2\n");
17 extern void my_tramp1(void *);
18 extern void my_tramp2(void *);
20 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 #endif /* CONFIG_X86_64 */
52 " .pushsection .text, \"ax\", @progbits\n"
53 " .type my_tramp1, @function\n"
57 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
58 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
59 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
60 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
61 " brasl %r14,my_direct_func1\n"
62 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
63 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
64 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
67 " .size my_tramp1, .-my_tramp1\n"
68 " .type my_tramp2, @function\n"
72 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
73 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
74 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
75 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
76 " brasl %r14,my_direct_func2\n"
77 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
78 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
79 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
82 " .size my_tramp2, .-my_tramp2\n"
86 #endif /* CONFIG_S390 */
88 static unsigned long my_tramp = (unsigned long)my_tramp1;
89 static unsigned long tramps[2] = {
90 (unsigned long)my_tramp1,
91 (unsigned long)my_tramp2,
94 static int simple_thread(void *arg)
99 while (!kthread_should_stop()) {
100 set_current_state(TASK_INTERRUPTIBLE);
101 schedule_timeout(2 * HZ);
106 ret = modify_ftrace_direct(my_ip, my_tramp, tramps[t]);
108 my_tramp = tramps[t];
115 static struct task_struct *simple_tsk;
117 static int __init ftrace_direct_init(void)
121 ret = register_ftrace_direct(my_ip, my_tramp);
123 simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");
127 static void __exit ftrace_direct_exit(void)
129 kthread_stop(simple_tsk);
130 unregister_ftrace_direct(my_ip, my_tramp);
133 module_init(ftrace_direct_init);
134 module_exit(ftrace_direct_exit);
136 MODULE_AUTHOR("Steven Rostedt");
137 MODULE_DESCRIPTION("Example use case of using modify_ftrace_direct()");
138 MODULE_LICENSE("GPL");