Skip to content

Commit b78f129

Browse files
committed
Merge tag 'trace-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing updates from Steven Rostedt: - Have module addresses get updated in the persistent ring buffer The addresses of the modules from the previous boot are saved in the persistent ring buffer. If the same modules are loaded and an address is in the old buffer points to an address that was both saved in the persistent ring buffer and is loaded in memory, shift the address to point to the address that is loaded in memory in the trace event. - Print function names for irqs off and preempt off callsites When ignoring the print fmt of a trace event and just printing the fields directly, have the fields for preempt off and irqs off events still show the function name (via kallsyms) instead of just showing the raw address. - Clean ups of the histogram code The histogram functions saved over 800 bytes on the stack to process events as they come in. Instead, create per-cpu buffers that can hold this information and have a separate location for each context level (thread, softirq, IRQ and NMI). Also add some more comments to the code. - Add "common_comm" field for histograms Add "common_comm" that uses the current->comm as a field in an event histogram and acts like any of the other fields of the event. - Show "subops" in the enabled_functions file When the function graph infrastructure is used, a subsystem has a "subops" that it attaches its callback function to. Instead of the enabled_functions just showing a function calling the function that calls the subops functions, also show the subops functions that will get called for that function too. - Add "copy_trace_marker" option to instances There are cases where an instance is created for tooling to write into, but the old tooling has the top level instance hardcoded into the application. New tools want to consume the data from an instance and not the top level buffer. By adding a copy_trace_marker option, whenever the top instance trace_marker is written into, a copy of it is also written into the instance with this option set. This allows new tools to read what old tools are writing into the top buffer. If this option is cleared by the top instance, then what is written into the trace_marker is not written into the top instance. This is a way to redirect the trace_marker writes into another instance. - Have tracepoints created by DECLARE_TRACE() use trace_<name>_tp() If a tracepoint is created by DECLARE_TRACE() instead of TRACE_EVENT(), then it will not be exposed via tracefs. Currently there's no way to differentiate in the kernel the tracepoint functions between those that are exposed via tracefs or not. A calling convention has been made manually to append a "_tp" prefix for events created by DECLARE_TRACE(). Instead of doing this manually, force it so that all DECLARE_TRACE() events have this notation. - Use __string() for task->comm in some sched events Instead of hardcoding the comm to be TASK_COMM_LEN in some of the scheduler events use __string() which makes it dynamic. Note, if these events are parsed by user space it they may break, and the event may have to be converted back to the hardcoded size. - Have function graph "depth" be unsigned to the user Internally to the kernel, the "depth" field of the function graph event is signed due to -1 being used for end of boundary. What actually gets recorded in the event itself is zero or positive. Reflect this to user space by showing "depth" as unsigned int and be consistent across all events. - Allow an arbitrary long CPU string to osnoise_cpus_write() The filtering of which CPUs to write to can exceed 256 bytes. If a machine has 256 CPUs, and the filter is to filter every other CPU, the write would take a string larger than 256 bytes. Instead of using a fixed size buffer on the stack that is 256 bytes, allocate it to handle what is passed in. - Stop having ftrace check the per-cpu data "disabled" flag The "disabled" flag in the data structure passed to most ftrace functions is checked to know if tracing has been disabled or not. This flag was added back in 2008 before the ring buffer had its own way to disable tracing. The "disable" flag is now not always set when needed, and the ring buffer flag should be used in all locations where the disabled is needed. Since the "disable" flag is redundant and incorrect, stop using it. Fix up some locations that use the "disable" flag to use the ring buffer info. - Use a new tracer_tracing_disable/enable() instead of data->disable flag There's a few cases that set the data->disable flag to stop tracing, but this flag is not consistently used. It is also an on/off switch where if a function set it and calls another function that sets it, the called function may incorrectly enable it. Use a new trace_tracing_disable() and tracer_tracing_enable() that uses a counter and can be nested. These use the ring buffer flags which are always checked making the disabling more consistent. - Save the trace clock in the persistent ring buffer Save what clock was used for tracing in the persistent ring buffer and set it back to that clock after a reboot. - Remove unused reference to a per CPU data pointer in mmiotrace functions - Remove unused buffer_page field from trace_array_cpu structure - Remove more strncpy() instances - Other minor clean ups and fixes * tag 'trace-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: (36 commits) tracing: Fix compilation warning on arm32 tracing: Record trace_clock and recover when reboot tracing/sched: Use __string() instead of fixed lengths for task->comm tracepoint: Have tracepoints created with DECLARE_TRACE() have _tp suffix tracing: Cleanup upper_empty() in pid_list tracing: Allow the top level trace_marker to write into another instances tracing: Add a helper function to handle the dereference arg in verifier tracing: Remove unnecessary "goto out" that simply returns ret is trigger code tracing: Fix error handling in event_trigger_parse() tracing: Rename event_trigger_alloc() to trigger_data_alloc() tracing: Replace deprecated strncpy() with strscpy() for stack_trace_filter_buf tracing: Remove unused buffer_page field from trace_array_cpu structure tracing: Use atomic_inc_return() for updating "disabled" counter in irqsoff tracer tracing: Convert the per CPU "disabled" counter to local from atomic tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field ring-buffer: Add ring_buffer_record_is_on_cpu() tracing: Do not use per CPU array_buffer.data->disabled for cpumask ftrace: Do not disabled function graph based on "disabled" field tracing: kdb: Use tracer_tracing_on/off() instead of setting per CPU disabled tracing: Use tracer_tracing_disable() instead of "disabled" field for ftrace_dump_one() ...
2 parents 472c5f7 + 2fbdb6d commit b78f129

34 files changed

+720
-356
lines changed

Documentation/trace/ftrace.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,19 @@ Here are the available options:
12051205
default instance. The only way the top level instance has this flag
12061206
cleared, is by it being set in another instance.
12071207

1208+
copy_trace_marker
1209+
If there are applications that hard code writing into the top level
1210+
trace_marker file (/sys/kernel/tracing/trace_marker or trace_marker_raw),
1211+
and the tooling would like it to go into an instance, this option can
1212+
be used. Create an instance and set this option, and then all writes
1213+
into the top level trace_marker file will also be redirected into this
1214+
instance.
1215+
1216+
Note, by default this option is set for the top level instance. If it
1217+
is disabled, then writes to the trace_marker or trace_marker_raw files
1218+
will not be written into the top level file. If no instance has this
1219+
option set, then a write will error with the errno of ENODEV.
1220+
12081221
annotate
12091222
It is sometimes confusing when the CPU buffers are full
12101223
and one CPU buffer had a lot of events recently, thus

Documentation/trace/tracepoints.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ In subsys/file.c (where the tracing statement must be added)::
7171
void somefct(void)
7272
{
7373
...
74-
trace_subsys_eventname(arg, task);
74+
trace_subsys_eventname_tp(arg, task);
7575
...
7676
}
7777

@@ -129,12 +129,12 @@ within an if statement with the following::
129129
for (i = 0; i < count; i++)
130130
tot += calculate_nuggets();
131131

132-
trace_foo_bar(tot);
132+
trace_foo_bar_tp(tot);
133133
}
134134

135-
All trace_<tracepoint>() calls have a matching trace_<tracepoint>_enabled()
135+
All trace_<tracepoint>_tp() calls have a matching trace_<tracepoint>_enabled()
136136
function defined that returns true if the tracepoint is enabled and
137-
false otherwise. The trace_<tracepoint>() should always be within the
137+
false otherwise. The trace_<tracepoint>_tp() should always be within the
138138
block of the if (trace_<tracepoint>_enabled()) to prevent races between
139139
the tracepoint being enabled and the check being seen.
140140

@@ -143,7 +143,10 @@ the static_key of the tracepoint to allow the if statement to be implemented
143143
with jump labels and avoid conditional branches.
144144

145145
.. note:: The convenience macro TRACE_EVENT provides an alternative way to
146-
define tracepoints. Check http://lwn.net/Articles/379903,
146+
define tracepoints. Note, DECLARE_TRACE(foo) creates a function
147+
"trace_foo_tp()" whereas TRACE_EVENT(foo) creates a function
148+
"trace_foo()", and also exposes the tracepoint as a trace event in
149+
/sys/kernel/tracing/events directory. Check http://lwn.net/Articles/379903,
147150
http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362
148151
for a series of articles with more details.
149152

@@ -159,7 +162,9 @@ In a C file::
159162

160163
void do_trace_foo_bar_wrapper(args)
161164
{
162-
trace_foo_bar(args);
165+
trace_foo_bar_tp(args); // for tracepoints created via DECLARE_TRACE
166+
// or
167+
trace_foo_bar(args); // for tracepoints created via TRACE_EVENT
163168
}
164169

165170
In the header file::

include/linux/ftrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
328328
* DIRECT - Used by the direct ftrace_ops helper for direct functions
329329
* (internal ftrace only, should not be used by others)
330330
* SUBOP - Is controlled by another op in field managed.
331+
* GRAPH - Is a component of the fgraph_ops structure
331332
*/
332333
enum {
333334
FTRACE_OPS_FL_ENABLED = BIT(0),
@@ -349,6 +350,7 @@ enum {
349350
FTRACE_OPS_FL_PERMANENT = BIT(16),
350351
FTRACE_OPS_FL_DIRECT = BIT(17),
351352
FTRACE_OPS_FL_SUBOP = BIT(18),
353+
FTRACE_OPS_FL_GRAPH = BIT(19),
352354
};
353355

354356
#ifndef CONFIG_DYNAMIC_FTRACE_WITH_ARGS

include/linux/ring_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void ring_buffer_record_off(struct trace_buffer *buffer);
192192
void ring_buffer_record_on(struct trace_buffer *buffer);
193193
bool ring_buffer_record_is_on(struct trace_buffer *buffer);
194194
bool ring_buffer_record_is_set_on(struct trace_buffer *buffer);
195+
bool ring_buffer_record_is_on_cpu(struct trace_buffer *buffer, int cpu);
195196
void ring_buffer_record_disable_cpu(struct trace_buffer *buffer, int cpu);
196197
void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu);
197198

include/linux/tracepoint.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,30 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
464464
#endif
465465

466466
#define DECLARE_TRACE(name, proto, args) \
467-
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
467+
__DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \
468468
cpu_online(raw_smp_processor_id()), \
469469
PARAMS(void *__data, proto))
470470

471471
#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
472-
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
472+
__DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \
473473
cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
474474
PARAMS(void *__data, proto))
475475

476476
#define DECLARE_TRACE_SYSCALL(name, proto, args) \
477+
__DECLARE_TRACE_SYSCALL(name##_tp, PARAMS(proto), PARAMS(args), \
478+
PARAMS(void *__data, proto))
479+
480+
#define DECLARE_TRACE_EVENT(name, proto, args) \
481+
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
482+
cpu_online(raw_smp_processor_id()), \
483+
PARAMS(void *__data, proto))
484+
485+
#define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond) \
486+
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
487+
cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
488+
PARAMS(void *__data, proto))
489+
490+
#define DECLARE_TRACE_EVENT_SYSCALL(name, proto, args) \
477491
__DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args), \
478492
PARAMS(void *__data, proto))
479493

@@ -591,32 +605,32 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
591605

592606
#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
593607
#define DEFINE_EVENT(template, name, proto, args) \
594-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
608+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
595609
#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
596-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
610+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
597611
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
598-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
612+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
599613
#define DEFINE_EVENT_CONDITION(template, name, proto, \
600614
args, cond) \
601-
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
615+
DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \
602616
PARAMS(args), PARAMS(cond))
603617

604618
#define TRACE_EVENT(name, proto, args, struct, assign, print) \
605-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
619+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
606620
#define TRACE_EVENT_FN(name, proto, args, struct, \
607621
assign, print, reg, unreg) \
608-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
609-
#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
622+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
623+
#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
610624
assign, print, reg, unreg) \
611-
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
625+
DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \
612626
PARAMS(args), PARAMS(cond))
613627
#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
614628
struct, assign, print) \
615-
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
629+
DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \
616630
PARAMS(args), PARAMS(cond))
617631
#define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, \
618632
print, reg, unreg) \
619-
DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args))
633+
DECLARE_TRACE_EVENT_SYSCALL(name, PARAMS(proto), PARAMS(args))
620634

621635
#define TRACE_EVENT_FLAGS(event, flag)
622636

include/trace/bpf_probe.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ static inline void bpf_test_buffer_##call(void) \
119119

120120
#undef DECLARE_TRACE
121121
#define DECLARE_TRACE(call, proto, args) \
122-
__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \
123-
__DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), 0)
122+
__BPF_DECLARE_TRACE(call##_tp, PARAMS(proto), PARAMS(args)) \
123+
__DEFINE_EVENT(call##_tp, call##_tp, PARAMS(proto), PARAMS(args), 0)
124124

125125
#undef DECLARE_TRACE_WRITABLE
126126
#define DECLARE_TRACE_WRITABLE(call, proto, args, size) \
127127
__CHECK_WRITABLE_BUF_SIZE(call, PARAMS(proto), PARAMS(args), size) \
128-
__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \
129-
__DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), size)
128+
__BPF_DECLARE_TRACE(call##_tp, PARAMS(proto), PARAMS(args)) \
129+
__DEFINE_EVENT(call##_tp, call##_tp, PARAMS(proto), PARAMS(args), size)
130130

131131
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
132132

include/trace/define_trace.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,18 @@
7474

7575
#undef DECLARE_TRACE
7676
#define DECLARE_TRACE(name, proto, args) \
77-
DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
77+
DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))
7878

7979
#undef DECLARE_TRACE_CONDITION
8080
#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
81+
DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))
82+
83+
#undef DECLARE_TRACE_EVENT
84+
#define DECLARE_TRACE_EVENT(name, proto, args) \
85+
DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
86+
87+
#undef DECLARE_TRACE_EVENT_CONDITION
88+
#define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond) \
8189
DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
8290

8391
/* If requested, create helpers for calling these tracepoints from Rust. */
@@ -115,6 +123,11 @@
115123
#undef DECLARE_TRACE_CONDITION
116124
#define DECLARE_TRACE_CONDITION(name, proto, args, cond)
117125

126+
#undef DECLARE_TRACE_EVENT
127+
#define DECLARE_TRACE_EVENT(name, proto, args)
128+
#undef DECLARE_TRACE_EVENT_CONDITION
129+
#define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond)
130+
118131
#ifdef TRACEPOINTS_ENABLED
119132
#include <trace/trace_events.h>
120133
#include <trace/perf.h>
@@ -136,6 +149,8 @@
136149
#undef TRACE_HEADER_MULTI_READ
137150
#undef DECLARE_TRACE
138151
#undef DECLARE_TRACE_CONDITION
152+
#undef DECLARE_TRACE_EVENT
153+
#undef DECLARE_TRACE_EVENT_CONDITION
139154

140155
/* Only undef what we defined in this file */
141156
#ifdef UNDEF_TRACE_INCLUDE_FILE

0 commit comments

Comments
 (0)