1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/module.h>
4 #include <linux/sched.h> /* for wake_up_process() */
5 #include <linux/ftrace.h>
6 #include <asm/asm-offsets.h>
8 extern void my_direct_func(struct task_struct *p);
10 void my_direct_func(struct task_struct *p)
12 trace_printk("waking up %s-%d\n", p->comm, p->pid);
15 extern void my_tramp(void *);
22 " .pushsection .text, \"ax\", @progbits\n"
23 " .type my_tramp, @function\n"
30 " call my_direct_func\n"
34 " .size my_tramp, .-my_tramp\n"
38 #endif /* CONFIG_X86_64 */
43 " .pushsection .text, \"ax\", @progbits\n"
44 " .type my_tramp, @function\n"
48 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
49 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
50 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
51 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
52 " brasl %r14,my_direct_func\n"
53 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
54 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
55 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
58 " .size my_tramp, .-my_tramp\n"
62 #endif /* CONFIG_S390 */
64 static int __init ftrace_direct_init(void)
66 return register_ftrace_direct((unsigned long)wake_up_process,
67 (unsigned long)my_tramp);
70 static void __exit ftrace_direct_exit(void)
72 unregister_ftrace_direct((unsigned long)wake_up_process,
73 (unsigned long)my_tramp);
76 module_init(ftrace_direct_init);
77 module_exit(ftrace_direct_exit);
79 MODULE_AUTHOR("Steven Rostedt");
80 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
81 MODULE_LICENSE("GPL");