Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
1b0c192
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
include
init
io_uring
ipc
kernel
lib
mm
net
rust
samples
acrn
auxdisplay
binderfs
bpf
cgroup
check-exec
configfs
connector
coresight
damon
fanotify
fprobe
ftrace
Makefile
ftrace-direct-modify.c
ftrace-direct-multi-modify.c
ftrace-direct-multi.c
ftrace-direct-too.c
ftrace-direct.c
ftrace-ops.c
sample-trace-array.c
sample-trace-array.h
hid
hidraw
hung_task
hw_breakpoint
kdb
kfifo
kmemleak
kobject
kprobes
landlock
livepatch
mei
nitro_enclaves
pfsm
pidfd
pktgen
qmi
rpmsg
rust
seccomp
timers
trace_events
trace_printk
uhid
user_events
v4l
vfio-mdev
vfs
watch_queue
watchdog
Kconfig
Makefile
scripts
security
sound
tools
usr
virt
.clang-format
.clippy.toml
.cocciconfig
.editorconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
samples
/
ftrace
/
sample-trace-array.c
Blame
Blame
Latest commit
History
History
143 lines (121 loc) · 3.52 KB
Breadcrumbs
linux
/
samples
/
ftrace
/
sample-trace-array.c
Top
File metadata and controls
Code
Blame
143 lines (121 loc) · 3.52 KB
Raw
// SPDX-License-Identifier: GPL-2.0-only #include <linux/module.h> #include <linux/kthread.h> #include <linux/trace.h> #include <linux/trace_events.h> #include <linux/timer.h> #include <linux/err.h> #include <linux/jiffies.h> #include <linux/workqueue.h> /* * Any file that uses trace points, must include the header. * But only one file, must include the header by defining * CREATE_TRACE_POINTS first. This will make the C code that * creates the handles for the trace points. */ #define CREATE_TRACE_POINTS #include "sample-trace-array.h" struct trace_array *tr; static void mytimer_handler(struct timer_list *unused); static struct task_struct *simple_tsk; static void trace_work_fn(struct work_struct *work) { /* * Disable tracing for event "sample_event". */ trace_array_set_clr_event(tr, "sample-subsystem", "sample_event", false); } static DECLARE_WORK(trace_work, trace_work_fn); /* * mytimer: Timer setup to disable tracing for event "sample_event". This * timer is only for the purposes of the sample module to demonstrate access of * Ftrace instances from within kernel. */ static DEFINE_TIMER(mytimer, mytimer_handler); static void mytimer_handler(struct timer_list *unused) { schedule_work(&trace_work); } static void simple_thread_func(int count) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ); /* * Printing count value using trace_array_printk() - trace_printk() * equivalent for the instance buffers. */ trace_array_printk(tr, _THIS_IP_, "trace_array_printk: count=%d\n", count); /* * Tracepoint for event "sample_event". This will print the * current value of count and current jiffies. */ trace_sample_event(count, jiffies); } static int simple_thread(void *arg) { int count = 0; unsigned long delay = msecs_to_jiffies(5000); /* * Enable tracing for "sample_event". */ trace_array_set_clr_event(tr, "sample-subsystem", "sample_event", true); /* * Adding timer - mytimer. This timer will disable tracing after * delay seconds. * */ add_timer(&mytimer); mod_timer(&mytimer, jiffies+delay); while (!kthread_should_stop()) simple_thread_func(count++); timer_delete(&mytimer); cancel_work_sync(&trace_work); /* * trace_array_put() decrements the reference counter associated with * the trace array - "tr". We are done using the trace array, hence * decrement the reference counter so that it can be destroyed using * trace_array_destroy(). */ trace_array_put(tr); return 0; } static int __init sample_trace_array_init(void) { /* * Return a pointer to the trace array with name "sample-instance" if it * exists, else create a new trace array. * * NOTE: This function increments the reference counter * associated with the trace array - "tr". */ tr = trace_array_get_by_name("sample-instance", "sched,timer,kprobes"); if (!tr) return -1; /* * If context specific per-cpu buffers havent already been allocated. */ trace_array_init_printk(tr); simple_tsk = kthread_run(simple_thread, NULL, "sample-instance"); if (IS_ERR(simple_tsk)) { trace_array_put(tr); trace_array_destroy(tr); return -1; } return 0; } static void __exit sample_trace_array_exit(void) { kthread_stop(simple_tsk); /* * We are unloading our module and no longer require the trace array. * Remove/destroy "tr" using trace_array_destroy() */ trace_array_destroy(tr); } module_init(sample_trace_array_init); module_exit(sample_trace_array_exit); MODULE_AUTHOR("Divya Indi"); MODULE_DESCRIPTION("Sample module for kernel access to Ftrace instances"); MODULE_LICENSE("GPL");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
You can’t perform that action at this time.