Skip to content

Commit aa1a8ce

Browse files
committed
Merge tag 'trace-v5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: "New tracing features: - The ring buffer is no longer disabled when reading the trace file. The trace_pipe file was made to be used for live tracing and reading as it acted like the normal producer/consumer. As the trace file would not consume the data, the easy way of handling it was to just disable writes to the ring buffer. This came to a surprise to the BPF folks who complained about lost events due to reading. This is no longer an issue. If someone wants to keep the old disabling there's a new option "pause-on-trace" that can be set. - New set_ftrace_notrace_pid file. PIDs in this file will not be traced by the function tracer. Similar to set_ftrace_pid, which makes the function tracer only trace those tasks with PIDs in the file, the set_ftrace_notrace_pid does the reverse. - New set_event_notrace_pid file. PIDs in this file will cause events not to be traced if triggered by a task with a matching PID. Similar to the set_event_pid file but will not be traced. Note, sched_waking and sched_switch events may still be traced if one of the tasks referenced by those events contains a PID that is allowed to be traced. Tracing related features: - New bootconfig option, that is attached to the initrd file. If bootconfig is on the command line, then the initrd file is searched looking for a bootconfig appended at the end. - New GPU tracepoint infrastructure to help the gfx drivers to get off debugfs (acked by Greg Kroah-Hartman) And other minor updates and fixes" * tag 'trace-v5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (27 commits) tracing: Do not allocate buffer in trace_find_next_entry() in atomic tracing: Add documentation on set_ftrace_notrace_pid and set_event_notrace_pid selftests/ftrace: Add test to test new set_event_notrace_pid file selftests/ftrace: Add test to test new set_ftrace_notrace_pid file tracing: Create set_event_notrace_pid to not trace tasks ftrace: Create set_ftrace_notrace_pid to not trace tasks ftrace: Make function trace pid filtering a bit more exact ftrace/kprobe: Show the maxactive number on kprobe_events tracing: Have the document reflect that the trace file keeps tracing enabled ring-buffer/tracing: Have iterator acknowledge dropped events tracing: Do not disable tracing when reading the trace file ring-buffer: Do not disable recording when there is an iterator ring-buffer: Make resize disable per cpu buffer instead of total buffer ring-buffer: Optimize rb_iter_head_event() ring-buffer: Do not die if rb_iter_peek() fails more than thrice ring-buffer: Have rb_iter_head_event() handle concurrent writer ring-buffer: Add page_stamp to iterator for synchronization ring-buffer: Rename ring_buffer_read() to read_buffer_iter_advance() ring-buffer: Have ring_buffer_empty() not depend on tracing stopped tracing: Save off entry when peeking at next entry ...
2 parents 4c205c8 + 8e99cf9 commit aa1a8ce

28 files changed

+1194
-256
lines changed

Documentation/trace/ftrace.rst

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ of ftrace. Here is a list of some of the key files:
125125
trace:
126126

127127
This file holds the output of the trace in a human
128-
readable format (described below). Note, tracing is temporarily
129-
disabled when the file is open for reading. Once all readers
130-
are closed, tracing is re-enabled. Opening this file for
128+
readable format (described below). Opening this file for
131129
writing with the O_TRUNC flag clears the ring buffer content.
130+
Note, this file is not a consumer. If tracing is off
131+
(no tracer running, or tracing_on is zero), it will produce
132+
the same output each time it is read. When tracing is on,
133+
it may produce inconsistent results as it tries to read
134+
the entire buffer without consuming it.
132135

133136
trace_pipe:
134137

@@ -142,9 +145,7 @@ of ftrace. Here is a list of some of the key files:
142145
will not be read again with a sequential read. The
143146
"trace" file is static, and if the tracer is not
144147
adding more data, it will display the same
145-
information every time it is read. Unlike the
146-
"trace" file, opening this file for reading will not
147-
temporarily disable tracing.
148+
information every time it is read.
148149

149150
trace_options:
150151

@@ -262,6 +263,20 @@ of ftrace. Here is a list of some of the key files:
262263
traced by the function tracer as well. This option will also
263264
cause PIDs of tasks that exit to be removed from the file.
264265

266+
set_ftrace_notrace_pid:
267+
268+
Have the function tracer ignore threads whose PID are listed in
269+
this file.
270+
271+
If the "function-fork" option is set, then when a task whose
272+
PID is listed in this file forks, the child's PID will
273+
automatically be added to this file, and the child will not be
274+
traced by the function tracer as well. This option will also
275+
cause PIDs of tasks that exit to be removed from the file.
276+
277+
If a PID is in both this file and "set_ftrace_pid", then this
278+
file takes precedence, and the thread will not be traced.
279+
265280
set_event_pid:
266281

267282
Have the events only trace a task with a PID listed in this file.
@@ -273,6 +288,19 @@ of ftrace. Here is a list of some of the key files:
273288
cause the PIDs of tasks to be removed from this file when the task
274289
exits.
275290

291+
set_event_notrace_pid:
292+
293+
Have the events not trace a task with a PID listed in this file.
294+
Note, sched_switch and sched_wakeup will trace threads not listed
295+
in this file, even if a thread's PID is in the file if the
296+
sched_switch or sched_wakeup events also trace a thread that should
297+
be traced.
298+
299+
To have the PIDs of children of tasks with their PID in this file
300+
added on fork, enable the "event-fork" option. That option will also
301+
cause the PIDs of tasks to be removed from this file when the task
302+
exits.
303+
276304
set_graph_function:
277305

278306
Functions listed in this file will cause the function graph
@@ -1125,6 +1153,12 @@ Here are the available options:
11251153
the trace displays additional information about the
11261154
latency, as described in "Latency trace format".
11271155

1156+
pause-on-trace
1157+
When set, opening the trace file for read, will pause
1158+
writing to the ring buffer (as if tracing_on was set to zero).
1159+
This simulates the original behavior of the trace file.
1160+
When the file is closed, tracing will be enabled again.
1161+
11281162
record-cmd
11291163
When any event or tracer is enabled, a hook is enabled
11301164
in the sched_switch trace point to fill comm cache
@@ -1176,6 +1210,8 @@ Here are the available options:
11761210
tasks fork. Also, when tasks with PIDs in set_event_pid exit,
11771211
their PIDs will be removed from the file.
11781212

1213+
This affects PIDs listed in set_event_notrace_pid as well.
1214+
11791215
function-trace
11801216
The latency tracers will enable function tracing
11811217
if this option is enabled (default it is). When
@@ -1190,6 +1226,8 @@ Here are the available options:
11901226
set_ftrace_pid exit, their PIDs will be removed from the
11911227
file.
11921228

1229+
This affects PIDs in set_ftrace_notrace_pid as well.
1230+
11931231
display-graph
11941232
When set, the latency tracers (irqsoff, wakeup, etc) will
11951233
use function graph tracing instead of function tracing.
@@ -2126,19 +2164,27 @@ periodically make a CPU constantly busy with interrupts disabled.
21262164
# cat trace
21272165
# tracer: hwlat
21282166
#
2167+
# entries-in-buffer/entries-written: 13/13 #P:8
2168+
#
21292169
# _-----=> irqs-off
21302170
# / _----=> need-resched
21312171
# | / _---=> hardirq/softirq
21322172
# || / _--=> preempt-depth
21332173
# ||| / delay
21342174
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
21352175
# | | | |||| | |
2136-
<...>-3638 [001] d... 19452.055471: #1 inner/outer(us): 12/14 ts:1499801089.066141940
2137-
<...>-3638 [003] d... 19454.071354: #2 inner/outer(us): 11/9 ts:1499801091.082164365
2138-
<...>-3638 [002] dn.. 19461.126852: #3 inner/outer(us): 12/9 ts:1499801098.138150062
2139-
<...>-3638 [001] d... 19488.340960: #4 inner/outer(us): 8/12 ts:1499801125.354139633
2140-
<...>-3638 [003] d... 19494.388553: #5 inner/outer(us): 8/12 ts:1499801131.402150961
2141-
<...>-3638 [003] d... 19501.283419: #6 inner/outer(us): 0/12 ts:1499801138.297435289 nmi-total:4 nmi-count:1
2176+
<...>-1729 [001] d... 678.473449: #1 inner/outer(us): 11/12 ts:1581527483.343962693 count:6
2177+
<...>-1729 [004] d... 689.556542: #2 inner/outer(us): 16/9 ts:1581527494.889008092 count:1
2178+
<...>-1729 [005] d... 714.756290: #3 inner/outer(us): 16/16 ts:1581527519.678961629 count:5
2179+
<...>-1729 [001] d... 718.788247: #4 inner/outer(us): 9/17 ts:1581527523.889012713 count:1
2180+
<...>-1729 [002] d... 719.796341: #5 inner/outer(us): 13/9 ts:1581527524.912872606 count:1
2181+
<...>-1729 [006] d... 844.787091: #6 inner/outer(us): 9/12 ts:1581527649.889048502 count:2
2182+
<...>-1729 [003] d... 849.827033: #7 inner/outer(us): 18/9 ts:1581527654.889013793 count:1
2183+
<...>-1729 [007] d... 853.859002: #8 inner/outer(us): 9/12 ts:1581527658.889065736 count:1
2184+
<...>-1729 [001] d... 855.874978: #9 inner/outer(us): 9/11 ts:1581527660.861991877 count:1
2185+
<...>-1729 [001] d... 863.938932: #10 inner/outer(us): 9/11 ts:1581527668.970010500 count:1 nmi-total:7 nmi-count:1
2186+
<...>-1729 [007] d... 878.050780: #11 inner/outer(us): 9/12 ts:1581527683.385002600 count:1 nmi-total:5 nmi-count:1
2187+
<...>-1729 [007] d... 886.114702: #12 inner/outer(us): 9/12 ts:1581527691.385001600 count:1
21422188

21432189

21442190
The above output is somewhat the same in the header. All events will have
@@ -2148,19 +2194,23 @@ interrupts disabled 'd'. Under the FUNCTION title there is:
21482194
This is the count of events recorded that were greater than the
21492195
tracing_threshold (See below).
21502196

2151-
inner/outer(us): 12/14
2197+
inner/outer(us): 11/11
21522198

21532199
This shows two numbers as "inner latency" and "outer latency". The test
21542200
runs in a loop checking a timestamp twice. The latency detected within
21552201
the two timestamps is the "inner latency" and the latency detected
21562202
after the previous timestamp and the next timestamp in the loop is
21572203
the "outer latency".
21582204

2159-
ts:1499801089.066141940
2205+
ts:1581527483.343962693
2206+
2207+
The absolute timestamp that the first latency was recorded in the window.
2208+
2209+
count:6
21602210

2161-
The absolute timestamp that the event happened.
2211+
The number of times a latency was detected during the window.
21622212

2163-
nmi-total:4 nmi-count:1
2213+
nmi-total:7 nmi-count:1
21642214

21652215
On architectures that support it, if an NMI comes in during the
21662216
test, the time spent in NMI is reported in "nmi-total" (in

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ source "drivers/thunderbolt/Kconfig"
200200

201201
source "drivers/android/Kconfig"
202202

203+
source "drivers/gpu/trace/Kconfig"
204+
203205
source "drivers/nvdimm/Kconfig"
204206

205207
source "drivers/dax/Kconfig"

drivers/gpu/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
obj-$(CONFIG_TEGRA_HOST1X) += host1x/
66
obj-y += drm/ vga/
77
obj-$(CONFIG_IMX_IPUV3_CORE) += ipu-v3/
8+
obj-$(CONFIG_TRACE_GPU_MEM) += trace/

drivers/gpu/trace/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
config TRACE_GPU_MEM
4+
bool

drivers/gpu/trace/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
obj-$(CONFIG_TRACE_GPU_MEM) += trace_gpu_mem.o

drivers/gpu/trace/trace_gpu_mem.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* GPU memory trace points
4+
*
5+
* Copyright (C) 2020 Google, Inc.
6+
*/
7+
8+
#include <linux/module.h>
9+
10+
#define CREATE_TRACE_POINTS
11+
#include <trace/events/gpu_mem.h>
12+
13+
EXPORT_TRACEPOINT_SYMBOL(gpu_mem_total);

include/linux/bootconfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ static inline int __init xbc_node_compose_key(struct xbc_node *node,
216216
}
217217

218218
/* XBC node initializer */
219-
int __init xbc_init(char *buf);
219+
int __init xbc_init(char *buf, const char **emsg, int *epos);
220+
220221

221222
/* XBC cleanup data structures */
222223
void __init xbc_destroy_all(void);

include/linux/ring_buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ void ring_buffer_read_finish(struct ring_buffer_iter *iter);
135135

136136
struct ring_buffer_event *
137137
ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts);
138-
struct ring_buffer_event *
139-
ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts);
138+
void ring_buffer_iter_advance(struct ring_buffer_iter *iter);
140139
void ring_buffer_iter_reset(struct ring_buffer_iter *iter);
141140
int ring_buffer_iter_empty(struct ring_buffer_iter *iter);
141+
bool ring_buffer_iter_dropped(struct ring_buffer_iter *iter);
142142

143143
unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu);
144144

include/linux/trace_events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct trace_iterator {
8585
struct mutex mutex;
8686
struct ring_buffer_iter **buffer_iter;
8787
unsigned long iter_flags;
88+
void *temp; /* temp holder */
89+
unsigned int temp_size;
8890

8991
/* trace_seq for __print_flags() and __print_symbolic() etc. */
9092
struct trace_seq tmp_seq;

include/trace/events/gpu_mem.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* GPU memory trace points
4+
*
5+
* Copyright (C) 2020 Google, Inc.
6+
*/
7+
8+
#undef TRACE_SYSTEM
9+
#define TRACE_SYSTEM gpu_mem
10+
11+
#if !defined(_TRACE_GPU_MEM_H) || defined(TRACE_HEADER_MULTI_READ)
12+
#define _TRACE_GPU_MEM_H
13+
14+
#include <linux/tracepoint.h>
15+
16+
/*
17+
* The gpu_memory_total event indicates that there's an update to either the
18+
* global or process total gpu memory counters.
19+
*
20+
* This event should be emitted whenever the kernel device driver allocates,
21+
* frees, imports, unimports memory in the GPU addressable space.
22+
*
23+
* @gpu_id: This is the gpu id.
24+
*
25+
* @pid: Put 0 for global total, while positive pid for process total.
26+
*
27+
* @size: Virtual size of the allocation in bytes.
28+
*
29+
*/
30+
TRACE_EVENT(gpu_mem_total,
31+
32+
TP_PROTO(uint32_t gpu_id, uint32_t pid, uint64_t size),
33+
34+
TP_ARGS(gpu_id, pid, size),
35+
36+
TP_STRUCT__entry(
37+
__field(uint32_t, gpu_id)
38+
__field(uint32_t, pid)
39+
__field(uint64_t, size)
40+
),
41+
42+
TP_fast_assign(
43+
__entry->gpu_id = gpu_id;
44+
__entry->pid = pid;
45+
__entry->size = size;
46+
),
47+
48+
TP_printk("gpu_id=%u pid=%u size=%llu",
49+
__entry->gpu_id,
50+
__entry->pid,
51+
__entry->size)
52+
);
53+
54+
#endif /* _TRACE_GPU_MEM_H */
55+
56+
/* This part must be outside protection */
57+
#include <trace/define_trace.h>

0 commit comments

Comments
 (0)