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
ada6b83
Documentation
arch
block
crypto
drivers
fs
include
init
ipc
kernel
irq
power
time
trace
Kconfig
Makefile
ftrace.c
trace.c
trace.h
trace_functions.c
trace_irqsoff.c
trace_sched_switch.c
trace_sched_wakeup.c
trace_selftest.c
trace_selftest_dynamic.c
trace_sysprof.c
.gitignore
Kconfig.hz
Kconfig.preempt
Makefile
acct.c
audit.c
audit.h
audit_tree.c
auditfilter.c
auditsc.c
backtracetest.c
bounds.c
capability.c
cgroup.c
cgroup_debug.c
compat.c
configs.c
cpu.c
cpuset.c
delayacct.c
dma.c
exec_domain.c
exit.c
extable.c
fork.c
futex.c
futex_compat.c
hrtimer.c
itimer.c
kallsyms.c
kexec.c
kfifo.c
kgdb.c
kmod.c
kprobes.c
ksysfs.c
kthread.c
latencytop.c
lockdep.c
lockdep_internals.h
lockdep_proc.c
marker.c
module.c
mutex-debug.c
mutex-debug.h
mutex.c
mutex.h
notifier.c
ns_cgroup.c
nsproxy.c
panic.c
params.c
pid.c
pid_namespace.c
pm_qos_params.c
posix-cpu-timers.c
posix-timers.c
printk.c
profile.c
ptrace.c
rcuclassic.c
rcupdate.c
rcupreempt.c
rcupreempt_trace.c
rcutorture.c
relay.c
res_counter.c
resource.c
rtmutex-debug.c
rtmutex-debug.h
rtmutex-tester.c
rtmutex.c
rtmutex.h
rtmutex_common.h
rwsem.c
sched.c
sched_clock.c
sched_debug.c
sched_fair.c
sched_features.h
sched_idletask.c
sched_rt.c
sched_stats.h
seccomp.c
semaphore.c
signal.c
softirq.c
softlockup.c
spinlock.c
srcu.c
stacktrace.c
stop_machine.c
sys.c
sys_ni.c
sysctl.c
sysctl_check.c
taskstats.c
test_kprobes.c
time.c
timeconst.pl
timer.c
tsacct.c
uid16.c
user.c
user_namespace.c
utsname.c
utsname_sysctl.c
wait.c
workqueue.c
lib
mm
net
samples
scripts
security
sound
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
kernel
/
trace
/
trace_sysprof.c
Blame
Blame
Latest commit
History
History
284 lines (225 loc) · 5.71 KB
Breadcrumbs
linux
/
kernel
/
trace
/
trace_sysprof.c
Top
File metadata and controls
Code
Blame
284 lines (225 loc) · 5.71 KB
Raw
/* * trace stack traces * * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com> * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> * Copyright (C) 2004, 2005, Soeren Sandmann */ #include <linux/kallsyms.h> #include <linux/debugfs.h> #include <linux/hrtimer.h> #include <linux/uaccess.h> #include <linux/ftrace.h> #include <linux/module.h> #include <linux/irq.h> #include <linux/fs.h> #include "trace.h" static struct trace_array *sysprof_trace; static int __read_mostly tracer_enabled; /* * 1 msec sample interval by default: */ static unsigned long sample_period = 1000000; static const unsigned int sample_max_depth = 512; static DEFINE_MUTEX(sample_timer_lock); /* * Per CPU hrtimers that do the profiling: */ static DEFINE_PER_CPU(struct hrtimer, stack_trace_hrtimer); struct stack_frame { const void __user *next_fp; unsigned long return_address; }; static int copy_stack_frame(const void __user *fp, struct stack_frame *frame) { int ret; if (!access_ok(VERIFY_READ, fp, sizeof(*frame))) return 0; ret = 1; pagefault_disable(); if (__copy_from_user_inatomic(frame, fp, sizeof(*frame))) ret = 0; pagefault_enable(); return ret; } static void timer_notify(struct pt_regs *regs, int cpu) { struct trace_array_cpu *data; struct stack_frame frame; struct trace_array *tr; const void __user *fp; int is_user; int i; if (!regs) return; tr = sysprof_trace; data = tr->data[cpu]; is_user = user_mode(regs); if (!current || current->pid == 0) return; if (is_user && current->state != TASK_RUNNING) return; if (!is_user) { /* kernel */ ftrace(tr, data, current->pid, 1, 0); return; } trace_special(tr, data, 0, current->pid, regs->ip); fp = (void __user *)regs->bp; for (i = 0; i < sample_max_depth; i++) { frame.next_fp = 0; frame.return_address = 0; if (!copy_stack_frame(fp, &frame)) break; if ((unsigned long)fp < regs->sp) break; trace_special(tr, data, 1, frame.return_address, (unsigned long)fp); fp = frame.next_fp; } trace_special(tr, data, 2, current->pid, i); /* * Special trace entry if we overflow the max depth: */ if (i == sample_max_depth) trace_special(tr, data, -1, -1, -1); } static enum hrtimer_restart stack_trace_timer_fn(struct hrtimer *hrtimer) { /* trace here */ timer_notify(get_irq_regs(), smp_processor_id()); hrtimer_forward_now(hrtimer, ns_to_ktime(sample_period)); return HRTIMER_RESTART; } static void start_stack_timer(int cpu) { struct hrtimer *hrtimer = &per_cpu(stack_trace_hrtimer, cpu); hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hrtimer->function = stack_trace_timer_fn; hrtimer->cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; hrtimer_start(hrtimer, ns_to_ktime(sample_period), HRTIMER_MODE_REL); } static void start_stack_timers(void) { cpumask_t saved_mask = current->cpus_allowed; int cpu; for_each_online_cpu(cpu) { set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); start_stack_timer(cpu); } set_cpus_allowed_ptr(current, &saved_mask); } static void stop_stack_timer(int cpu) { struct hrtimer *hrtimer = &per_cpu(stack_trace_hrtimer, cpu); hrtimer_cancel(hrtimer); } static void stop_stack_timers(void) { int cpu; for_each_online_cpu(cpu) stop_stack_timer(cpu); } static void stack_reset(struct trace_array *tr) { int cpu; tr->time_start = ftrace_now(tr->cpu); for_each_online_cpu(cpu) tracing_reset(tr->data[cpu]); } static void start_stack_trace(struct trace_array *tr) { mutex_lock(&sample_timer_lock); stack_reset(tr); start_stack_timers(); tracer_enabled = 1; mutex_unlock(&sample_timer_lock); } static void stop_stack_trace(struct trace_array *tr) { mutex_lock(&sample_timer_lock); stop_stack_timers(); tracer_enabled = 0; mutex_unlock(&sample_timer_lock); } static void stack_trace_init(struct trace_array *tr) { sysprof_trace = tr; if (tr->ctrl) start_stack_trace(tr); } static void stack_trace_reset(struct trace_array *tr) { if (tr->ctrl) stop_stack_trace(tr); } static void stack_trace_ctrl_update(struct trace_array *tr) { /* When starting a new trace, reset the buffers */ if (tr->ctrl) start_stack_trace(tr); else stop_stack_trace(tr); } static struct tracer stack_trace __read_mostly = { .name = "sysprof", .init = stack_trace_init, .reset = stack_trace_reset, .ctrl_update = stack_trace_ctrl_update, #ifdef CONFIG_FTRACE_SELFTEST .selftest = trace_selftest_startup_sysprof, #endif }; __init static int init_stack_trace(void) { return register_tracer(&stack_trace); } device_initcall(init_stack_trace); #define MAX_LONG_DIGITS 22 static ssize_t sysprof_sample_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) { char buf[MAX_LONG_DIGITS]; int r; r = sprintf(buf, "%ld\n", nsecs_to_usecs(sample_period)); return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); } static ssize_t sysprof_sample_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos) { char buf[MAX_LONG_DIGITS]; unsigned long val; if (cnt > MAX_LONG_DIGITS-1) cnt = MAX_LONG_DIGITS-1; if (copy_from_user(&buf, ubuf, cnt)) return -EFAULT; buf[cnt] = 0; val = simple_strtoul(buf, NULL, 10); /* * Enforce a minimum sample period of 100 usecs: */ if (val < 100) val = 100; mutex_lock(&sample_timer_lock); stop_stack_timers(); sample_period = val * 1000; start_stack_timers(); mutex_unlock(&sample_timer_lock); return cnt; } static struct file_operations sysprof_sample_fops = { .read = sysprof_sample_read, .write = sysprof_sample_write, }; void init_tracer_sysprof_debugfs(struct dentry *d_tracer) { struct dentry *entry; entry = debugfs_create_file("sysprof_sample_period", 0644, d_tracer, NULL, &sysprof_sample_fops); if (entry) return; pr_warning("Could not create debugfs 'dyn_ftrace_total_info' entry\n"); }
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
You can’t perform that action at this time.