File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ config SAMPLE_TRACE_PRINTK
1919 This builds a module that calls trace_printk() and can be used to
2020 test various trace_printk() calls from a module.
2121
22+ config SAMPLE_FTRACE_DIRECT
23+ tristate "Build register_ftrace_direct() example"
24+ depends on DYNAMIC_FTRACE_WITH_DIRECT_CALLS && m
25+ depends on X86_64 # has x86_64 inlined asm
26+ help
27+ This builds an ftrace direct function example
28+ that hooks to wake_up_process and prints the parameters.
29+
2230config SAMPLE_KOBJECT
2331 tristate "Build kobject examples"
2432 help
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ obj-$(CONFIG_SAMPLE_RPMSG_CLIENT) += rpmsg/
1717subdir-$(CONFIG_SAMPLE_SECCOMP) += seccomp
1818obj-$(CONFIG_SAMPLE_TRACE_EVENTS) += trace_events/
1919obj-$(CONFIG_SAMPLE_TRACE_PRINTK) += trace_printk/
20+ obj-$(CONFIG_SAMPLE_FTRACE_DIRECT) += ftrace/
2021obj-$(CONFIG_VIDEO_PCI_SKELETON) += v4l/
2122obj-y += vfio-mdev/
2223subdir-$(CONFIG_SAMPLE_VFS) += vfs
Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: GPL-2.0-only
2+
3+ obj-$(CONFIG_SAMPLE_FTRACE_DIRECT) += ftrace-direct.o
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0-only
2+ #include <linux/module.h>
3+
4+ #include <linux/sched.h> /* for wake_up_process() */
5+ #include <linux/ftrace.h>
6+
7+ void my_direct_func (struct task_struct * p )
8+ {
9+ trace_printk ("wakeing up %s-%d\n" , p -> comm , p -> pid );
10+ }
11+
12+ extern void my_tramp (void * );
13+
14+ asm (
15+ " .pushsection .text, \"ax\", @progbits\n"
16+ " my_tramp:"
17+ " pushq %rbp\n"
18+ " movq %rsp, %rbp\n"
19+ " pushq %rdi\n"
20+ " call my_direct_func\n"
21+ " popq %rdi\n"
22+ " leave\n"
23+ " ret\n"
24+ " .popsection\n"
25+ );
26+
27+
28+ static int __init ftrace_direct_init (void )
29+ {
30+ return register_ftrace_direct ((unsigned long )wake_up_process ,
31+ (unsigned long )my_tramp );
32+ }
33+
34+ static void __exit ftrace_direct_exit (void )
35+ {
36+ unregister_ftrace_direct ((unsigned long )wake_up_process ,
37+ (unsigned long )my_tramp );
38+ }
39+
40+ module_init (ftrace_direct_init );
41+ module_exit (ftrace_direct_exit );
42+
43+ MODULE_AUTHOR ("Steven Rostedt" );
44+ MODULE_DESCRIPTION ("Example use case of using register_ftrace_direct()" );
45+ MODULE_LICENSE ("GPL" );
You can’t perform that action at this time.
0 commit comments