Skip to content

Commit fefa636

Browse files
committed
Merge tag 'trace-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: "Updates for tracing and bootconfig: - Add support for "bool" type in synthetic events - Add per instance tracing for bootconfig - Support perf-style return probe ("SYMBOL%return") in kprobes and uprobes - Allow for kprobes to be enabled earlier in boot up - Added tracepoint helper function to allow testing if tracepoints are enabled in headers - Synthetic events can now have dynamic strings (variable length) - Various fixes and cleanups" * tag 'trace-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (58 commits) tracing: support "bool" type in synthetic trace events selftests/ftrace: Add test case for synthetic event syntax errors tracing: Handle synthetic event array field type checking correctly selftests/ftrace: Change synthetic event name for inter-event-combined test tracing: Add synthetic event error logging tracing: Check that the synthetic event and field names are legal tracing: Move is_good_name() from trace_probe.h to trace.h tracing: Don't show dynamic string internals in synthetic event description tracing: Fix some typos in comments tracing/boot: Add ftrace.instance.*.alloc_snapshot option tracing: Fix race in trace_open and buffer resize call tracing: Check return value of __create_val_fields() before using its result tracing: Fix synthetic print fmt check for use of __get_str() tracing: Remove a pointless assignment ftrace: ftrace_global_list is renamed to ftrace_ops_list ftrace: Format variable declarations of ftrace_allocate_records ftrace: Simplify the calculation of page number for ftrace_page->records ftrace: Simplify the dyn_ftrace->flags macro ftrace: Simplify the hash calculation ftrace: Use fls() to get the bits for dup_hash() ...
2 parents 2d0f6b0 + 6107742 commit fefa636

45 files changed

Lines changed: 1705 additions & 332 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/trace/boottime-trace.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ These options can be used for each instance including global ftrace node.
6161
ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
6262
Enable given ftrace options.
6363

64+
ftrace.[instance.INSTANCE.]tracing_on = 0|1
65+
Enable/Disable tracing on this instance when starting boot-time tracing.
66+
(you can enable it by the "traceon" event trigger action)
67+
6468
ftrace.[instance.INSTANCE.]trace_clock = CLOCK
6569
Set given CLOCK to ftrace's trace_clock.
6670

@@ -116,6 +120,20 @@ instance node, but those are also visible from other instances. So please
116120
take care for event name conflict.
117121

118122

123+
When to Start
124+
=============
125+
126+
All boot-time tracing options starting with ``ftrace`` will be enabled at the
127+
end of core_initcall. This means you can trace the events from postcore_initcall.
128+
Most of the subsystems and architecture dependent drivers will be initialized
129+
after that (arch_initcall or subsys_initcall). Thus, you can trace those with
130+
boot-time tracing.
131+
If you want to trace events before core_initcall, you can use the options
132+
starting with ``kernel``. Some of them will be enabled eariler than the initcall
133+
processing (for example,. ``kernel.ftrace=function`` and ``kernel.trace_event``
134+
will start before the initcall.)
135+
136+
119137
Examples
120138
========
121139

@@ -164,6 +182,26 @@ is for tracing functions starting with "user\_", and others tracing
164182
The instance node also accepts event nodes so that each instance
165183
can customize its event tracing.
166184

185+
With the trigger action and kprobes, you can trace function-graph while
186+
a function is called. For example, this will trace all function calls in
187+
the pci_proc_init()::
188+
189+
ftrace {
190+
tracing_on = 0
191+
tracer = function_graph
192+
event.kprobes {
193+
start_event {
194+
probes = "pci_proc_init"
195+
actions = "traceon"
196+
}
197+
end_event {
198+
probes = "pci_proc_init%return"
199+
actions = "traceoff"
200+
}
201+
}
202+
}
203+
204+
167205
This boot-time tracing also supports ftrace kernel parameters via boot
168206
config.
169207
For example, following kernel parameters::

Documentation/trace/events.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,19 @@ name::
589589
{ .type = "int", .name = "my_int_field" },
590590
};
591591

592-
See synth_field_size() for available types. If field_name contains [n]
593-
the field is considered to be an array.
592+
See synth_field_size() for available types.
593+
594+
If field_name contains [n], the field is considered to be a static array.
595+
596+
If field_names contains[] (no subscript), the field is considered to
597+
be a dynamic array, which will only take as much space in the event as
598+
is required to hold the array.
599+
600+
Because space for an event is reserved before assigning field values
601+
to the event, using dynamic arrays implies that the piecewise
602+
in-kernel API described below can't be used with dynamic arrays. The
603+
other non-piecewise in-kernel APIs can, however, be used with dynamic
604+
arrays.
594605

595606
If the event is created from within a module, a pointer to the module
596607
must be passed to synth_event_create(). This will ensure that the

Documentation/trace/histogram.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,24 @@ consisting of the name of the new event along with one or more
17761776
variables and their types, which can be any valid field type,
17771777
separated by semicolons, to the tracing/synthetic_events file.
17781778

1779+
See synth_field_size() for available types.
1780+
1781+
If field_name contains [n], the field is considered to be a static array.
1782+
1783+
If field_names contains[] (no subscript), the field is considered to
1784+
be a dynamic array, which will only take as much space in the event as
1785+
is required to hold the array.
1786+
1787+
A string field can be specified using either the static notation:
1788+
1789+
char name[32];
1790+
1791+
Or the dynamic:
1792+
1793+
char name[];
1794+
1795+
The size limit for either is 256.
1796+
17791797
For instance, the following creates a new event named 'wakeup_latency'
17801798
with 3 fields: lat, pid, and prio. Each of those fields is simply a
17811799
variable reference to a variable on another event::

Documentation/trace/kprobetrace.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ Synopsis of kprobe_events
3030

3131
p[:[GRP/]EVENT] [MOD:]SYM[+offs]|MEMADDR [FETCHARGS] : Set a probe
3232
r[MAXACTIVE][:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe
33+
p:[GRP/]EVENT] [MOD:]SYM[+0]%return [FETCHARGS] : Set a return probe
3334
-:[GRP/]EVENT : Clear a probe
3435

3536
GRP : Group name. If omitted, use "kprobes" for it.
3637
EVENT : Event name. If omitted, the event name is generated
3738
based on SYM+offs or MEMADDR.
3839
MOD : Module name which has given SYM.
3940
SYM[+offs] : Symbol+offset where the probe is inserted.
41+
SYM%return : Return address of the symbol
4042
MEMADDR : Address where the probe is inserted.
4143
MAXACTIVE : Maximum number of instances of the specified function that
4244
can be probed simultaneously, or 0 for the default value

Documentation/trace/tracepoints.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,30 @@ with jump labels and avoid conditional branches.
146146
define tracepoints. Check http://lwn.net/Articles/379903,
147147
http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362
148148
for a series of articles with more details.
149+
150+
If you require calling a tracepoint from a header file, it is not
151+
recommended to call one directly or to use the trace_<tracepoint>_enabled()
152+
function call, as tracepoints in header files can have side effects if a
153+
header is included from a file that has CREATE_TRACE_POINTS set, as
154+
well as the trace_<tracepoint>() is not that small of an inline
155+
and can bloat the kernel if used by other inlined functions. Instead,
156+
include tracepoint-defs.h and use tracepoint_enabled().
157+
158+
In a C file::
159+
160+
void do_trace_foo_bar_wrapper(args)
161+
{
162+
trace_foo_bar(args);
163+
}
164+
165+
In the header file::
166+
167+
DECLARE_TRACEPOINT(foo_bar);
168+
169+
static inline void some_inline_function()
170+
{
171+
[..]
172+
if (tracepoint_enabled(foo_bar))
173+
do_trace_foo_bar_wrapper(args);
174+
[..]
175+
}

Documentation/trace/uprobetracer.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ Synopsis of uprobe_tracer
2828

2929
p[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] : Set a uprobe
3030
r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] : Set a return uprobe (uretprobe)
31+
p[:[GRP/]EVENT] PATH:OFFSET%return [FETCHARGS] : Set a return uprobe (uretprobe)
3132
-:[GRP/]EVENT : Clear uprobe or uretprobe event
3233

3334
GRP : Group name. If omitted, "uprobes" is the default value.
3435
EVENT : Event name. If omitted, the event name is generated based
3536
on PATH+OFFSET.
3637
PATH : Path to an executable or a library.
3738
OFFSET : Offset where the probe is inserted.
39+
OFFSET%return : Offset where the return probe is inserted.
3840

3941
FETCHARGS : Arguments. Each probe can have up to 128 args.
4042
%REG : Fetch register REG

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6626,6 +6626,7 @@ F: fs/proc/bootconfig.c
66266626
F: include/linux/bootconfig.h
66276627
F: lib/bootconfig.c
66286628
F: tools/bootconfig/*
6629+
F: tools/bootconfig/scripts/*
66296630

66306631
EXYNOS DP DRIVER
66316632
M: Jingoo Han <jingoohan1@gmail.com>

arch/x86/include/asm/msr.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,20 @@ struct saved_msrs {
6060
#define EAX_EDX_RET(val, low, high) "=A" (val)
6161
#endif
6262

63-
#ifdef CONFIG_TRACEPOINTS
6463
/*
6564
* Be very careful with includes. This header is prone to include loops.
6665
*/
6766
#include <asm/atomic.h>
6867
#include <linux/tracepoint-defs.h>
6968

70-
extern struct tracepoint __tracepoint_read_msr;
71-
extern struct tracepoint __tracepoint_write_msr;
72-
extern struct tracepoint __tracepoint_rdpmc;
73-
#define msr_tracepoint_active(t) static_key_false(&(t).key)
69+
#ifdef CONFIG_TRACEPOINTS
70+
DECLARE_TRACEPOINT(read_msr);
71+
DECLARE_TRACEPOINT(write_msr);
72+
DECLARE_TRACEPOINT(rdpmc);
7473
extern void do_trace_write_msr(unsigned int msr, u64 val, int failed);
7574
extern void do_trace_read_msr(unsigned int msr, u64 val, int failed);
7675
extern void do_trace_rdpmc(unsigned int msr, u64 val, int failed);
7776
#else
78-
#define msr_tracepoint_active(t) false
7977
static inline void do_trace_write_msr(unsigned int msr, u64 val, int failed) {}
8078
static inline void do_trace_read_msr(unsigned int msr, u64 val, int failed) {}
8179
static inline void do_trace_rdpmc(unsigned int msr, u64 val, int failed) {}
@@ -128,7 +126,7 @@ static inline unsigned long long native_read_msr(unsigned int msr)
128126

129127
val = __rdmsr(msr);
130128

131-
if (msr_tracepoint_active(__tracepoint_read_msr))
129+
if (tracepoint_enabled(read_msr))
132130
do_trace_read_msr(msr, val, 0);
133131

134132
return val;
@@ -150,7 +148,7 @@ static inline unsigned long long native_read_msr_safe(unsigned int msr,
150148
_ASM_EXTABLE(2b, 3b)
151149
: [err] "=r" (*err), EAX_EDX_RET(val, low, high)
152150
: "c" (msr), [fault] "i" (-EIO));
153-
if (msr_tracepoint_active(__tracepoint_read_msr))
151+
if (tracepoint_enabled(read_msr))
154152
do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), *err);
155153
return EAX_EDX_VAL(val, low, high);
156154
}
@@ -161,7 +159,7 @@ native_write_msr(unsigned int msr, u32 low, u32 high)
161159
{
162160
__wrmsr(msr, low, high);
163161

164-
if (msr_tracepoint_active(__tracepoint_write_msr))
162+
if (tracepoint_enabled(write_msr))
165163
do_trace_write_msr(msr, ((u64)high << 32 | low), 0);
166164
}
167165

@@ -181,7 +179,7 @@ native_write_msr_safe(unsigned int msr, u32 low, u32 high)
181179
: "c" (msr), "0" (low), "d" (high),
182180
[fault] "i" (-EIO)
183181
: "memory");
184-
if (msr_tracepoint_active(__tracepoint_write_msr))
182+
if (tracepoint_enabled(write_msr))
185183
do_trace_write_msr(msr, ((u64)high << 32 | low), err);
186184
return err;
187185
}
@@ -248,7 +246,7 @@ static inline unsigned long long native_read_pmc(int counter)
248246
DECLARE_ARGS(val, low, high);
249247

250248
asm volatile("rdpmc" : EAX_EDX_RET(val, low, high) : "c" (counter));
251-
if (msr_tracepoint_active(__tracepoint_rdpmc))
249+
if (tracepoint_enabled(rdpmc))
252250
do_trace_rdpmc(counter, EAX_EDX_VAL(val, low, high), 0);
253251
return EAX_EDX_VAL(val, low, high);
254252
}

include/linux/ftrace.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ extern struct ftrace_ops __rcu *ftrace_ops_list;
217217
extern struct ftrace_ops ftrace_list_end;
218218

219219
/*
220-
* Traverse the ftrace_global_list, invoking all entries. The reason that we
220+
* Traverse the ftrace_ops_list, invoking all entries. The reason that we
221221
* can use rcu_dereference_raw_check() is that elements removed from this list
222222
* are simply leaked, so there is no need to interact with a grace-period
223223
* mechanism. The rcu_dereference_raw_check() calls are needed to handle
224-
* concurrent insertions into the ftrace_global_list.
224+
* concurrent insertions into the ftrace_ops_list.
225225
*
226226
* Silly Alpha and silly pointer-speculation compiler optimizations!
227227
*/
@@ -432,7 +432,7 @@ bool is_ftrace_trampoline(unsigned long addr);
432432
* DIRECT - there is a direct function to call
433433
*
434434
* When a new ftrace_ops is registered and wants a function to save
435-
* pt_regs, the rec->flag REGS is set. When the function has been
435+
* pt_regs, the rec->flags REGS is set. When the function has been
436436
* set up to save regs, the REG_EN flag is set. Once a function
437437
* starts saving regs it will do so until all ftrace_ops are removed
438438
* from tracing that function.
@@ -450,12 +450,9 @@ enum {
450450
};
451451

452452
#define FTRACE_REF_MAX_SHIFT 23
453-
#define FTRACE_FL_BITS 9
454-
#define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1)
455-
#define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
456453
#define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
457454

458-
#define ftrace_rec_count(rec) ((rec)->flags & ~FTRACE_FL_MASK)
455+
#define ftrace_rec_count(rec) ((rec)->flags & FTRACE_REF_MAX)
459456

460457
struct dyn_ftrace {
461458
unsigned long ip; /* address of mcount call-site */

0 commit comments

Comments
 (0)