]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - samples/ftrace/ftrace-direct.c
Merge tag 'nfs-for-5.15-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
[mirror_ubuntu-kernels.git] / samples / ftrace / ftrace-direct.c
CommitLineData
b06457c8
SRV
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
7void my_direct_func(struct task_struct *p)
8{
760f8bc7 9 trace_printk("waking up %s-%d\n", p->comm, p->pid);
b06457c8
SRV
10}
11
12extern void my_tramp(void *);
13
14asm (
15" .pushsection .text, \"ax\", @progbits\n"
9d907f1a 16" .type my_tramp, @function\n"
983df5f2 17" .globl my_tramp\n"
b06457c8
SRV
18" my_tramp:"
19" pushq %rbp\n"
20" movq %rsp, %rbp\n"
21" pushq %rdi\n"
22" call my_direct_func\n"
23" popq %rdi\n"
24" leave\n"
25" ret\n"
9d907f1a 26" .size my_tramp, .-my_tramp\n"
b06457c8
SRV
27" .popsection\n"
28);
29
30
31static int __init ftrace_direct_init(void)
32{
33 return register_ftrace_direct((unsigned long)wake_up_process,
34 (unsigned long)my_tramp);
35}
36
37static void __exit ftrace_direct_exit(void)
38{
39 unregister_ftrace_direct((unsigned long)wake_up_process,
40 (unsigned long)my_tramp);
41}
42
43module_init(ftrace_direct_init);
44module_exit(ftrace_direct_exit);
45
46MODULE_AUTHOR("Steven Rostedt");
47MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
48MODULE_LICENSE("GPL");