Skip to content

Commit e310396

Browse files
committed
Merge tag 'trace-v5.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: - Added new "bootconfig". This looks for a file appended to initrd to add boot config options, and has been discussed thoroughly at Linux Plumbers. Very useful for adding kprobes at bootup. Only enabled if "bootconfig" is on the real kernel command line. - Created dynamic event creation. Merges common code between creating synthetic events and kprobe events. - Rename perf "ring_buffer" structure to "perf_buffer" - Rename ftrace "ring_buffer" structure to "trace_buffer" Had to rename existing "trace_buffer" to "array_buffer" - Allow trace_printk() to work withing (some) tracing code. - Sort of tracing configs to be a little better organized - Fixed bug where ftrace_graph hash was not being protected properly - Various other small fixes and clean ups * tag 'trace-v5.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (88 commits) bootconfig: Show the number of nodes on boot message tools/bootconfig: Show the number of bootconfig nodes bootconfig: Add more parse error messages bootconfig: Use bootconfig instead of boot config ftrace: Protect ftrace_graph_hash with ftrace_sync ftrace: Add comment to why rcu_dereference_sched() is open coded tracing: Annotate ftrace_graph_notrace_hash pointer with __rcu tracing: Annotate ftrace_graph_hash pointer with __rcu bootconfig: Only load bootconfig if "bootconfig" is on the kernel cmdline tracing: Use seq_buf for building dynevent_cmd string tracing: Remove useless code in dynevent_arg_pair_add() tracing: Remove check_arg() callbacks from dynevent args tracing: Consolidate some synth_event_trace code tracing: Fix now invalid var_ref_vals assumption in trace action tracing: Change trace_boot to use synth_event interface tracing: Move tracing selftests to bottom of menu tracing: Move mmio tracer config up with the other tracers tracing: Move tracing test module configs together tracing: Move all function tracing configs together tracing: Documentation for in-kernel synthetic event API ...
2 parents c1ef57a + a005740 commit e310396

File tree

90 files changed

+6490
-836
lines changed

Some content is hidden

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

90 files changed

+6490
-836
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
.. _bootconfig:
4+
5+
==================
6+
Boot Configuration
7+
==================
8+
9+
:Author: Masami Hiramatsu <[email protected]>
10+
11+
Overview
12+
========
13+
14+
The boot configuration expands the current kernel command line to support
15+
additional key-value data when booting the kernel in an efficient way.
16+
This allows administrators to pass a structured-Key config file.
17+
18+
Config File Syntax
19+
==================
20+
21+
The boot config syntax is a simple structured key-value. Each key consists
22+
of dot-connected-words, and key and value are connected by ``=``. The value
23+
has to be terminated by semi-colon (``;``) or newline (``\n``).
24+
For array value, array entries are separated by comma (``,``). ::
25+
26+
KEY[.WORD[...]] = VALUE[, VALUE2[...]][;]
27+
28+
Unlike the kernel command line syntax, spaces are OK around the comma and ``=``.
29+
30+
Each key word must contain only alphabets, numbers, dash (``-``) or underscore
31+
(``_``). And each value only contains printable characters or spaces except
32+
for delimiters such as semi-colon (``;``), new-line (``\n``), comma (``,``),
33+
hash (``#``) and closing brace (``}``).
34+
35+
If you want to use those delimiters in a value, you can use either double-
36+
quotes (``"VALUE"``) or single-quotes (``'VALUE'``) to quote it. Note that
37+
you can not escape these quotes.
38+
39+
There can be a key which doesn't have value or has an empty value. Those keys
40+
are used for checking if the key exists or not (like a boolean).
41+
42+
Key-Value Syntax
43+
----------------
44+
45+
The boot config file syntax allows user to merge partially same word keys
46+
by brace. For example::
47+
48+
foo.bar.baz = value1
49+
foo.bar.qux.quux = value2
50+
51+
These can be written also in::
52+
53+
foo.bar {
54+
baz = value1
55+
qux.quux = value2
56+
}
57+
58+
Or more shorter, written as following::
59+
60+
foo.bar { baz = value1; qux.quux = value2 }
61+
62+
In both styles, same key words are automatically merged when parsing it
63+
at boot time. So you can append similar trees or key-values.
64+
65+
Comments
66+
--------
67+
68+
The config syntax accepts shell-script style comments. The comments starting
69+
with hash ("#") until newline ("\n") will be ignored.
70+
71+
::
72+
73+
# comment line
74+
foo = value # value is set to foo.
75+
bar = 1, # 1st element
76+
2, # 2nd element
77+
3 # 3rd element
78+
79+
This is parsed as below::
80+
81+
foo = value
82+
bar = 1, 2, 3
83+
84+
Note that you can not put a comment between value and delimiter(``,`` or
85+
``;``). This means following config has a syntax error ::
86+
87+
key = 1 # comment
88+
,2
89+
90+
91+
/proc/bootconfig
92+
================
93+
94+
/proc/bootconfig is a user-space interface of the boot config.
95+
Unlike /proc/cmdline, this file shows the key-value style list.
96+
Each key-value pair is shown in each line with following style::
97+
98+
KEY[.WORDS...] = "[VALUE]"[,"VALUE2"...]
99+
100+
101+
Boot Kernel With a Boot Config
102+
==============================
103+
104+
Since the boot configuration file is loaded with initrd, it will be added
105+
to the end of the initrd (initramfs) image file. The Linux kernel decodes
106+
the last part of the initrd image in memory to get the boot configuration
107+
data.
108+
Because of this "piggyback" method, there is no need to change or
109+
update the boot loader and the kernel image itself.
110+
111+
To do this operation, Linux kernel provides "bootconfig" command under
112+
tools/bootconfig, which allows admin to apply or delete the config file
113+
to/from initrd image. You can build it by the following command::
114+
115+
# make -C tools/bootconfig
116+
117+
To add your boot config file to initrd image, run bootconfig as below
118+
(Old data is removed automatically if exists)::
119+
120+
# tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z
121+
122+
To remove the config from the image, you can use -d option as below::
123+
124+
# tools/bootconfig/bootconfig -d /boot/initrd.img-X.Y.Z
125+
126+
Then add "bootconfig" on the normal kernel command line to tell the
127+
kernel to look for the bootconfig at the end of the initrd file.
128+
129+
Config File Limitation
130+
======================
131+
132+
Currently the maximum config size size is 32KB and the total key-words (not
133+
key-value entries) must be under 1024 nodes.
134+
Note: this is not the number of entries but nodes, an entry must consume
135+
more than 2 nodes (a key-word and a value). So theoretically, it will be
136+
up to 512 key-value pairs. If keys contains 3 words in average, it can
137+
contain 256 key-value pairs. In most cases, the number of config items
138+
will be under 100 entries and smaller than 8KB, so it would be enough.
139+
If the node number exceeds 1024, parser returns an error even if the file
140+
size is smaller than 32KB.
141+
Anyway, since bootconfig command verifies it when appending a boot config
142+
to initrd image, user can notice it before boot.
143+
144+
145+
Bootconfig APIs
146+
===============
147+
148+
User can query or loop on key-value pairs, also it is possible to find
149+
a root (prefix) key node and find key-values under that node.
150+
151+
If you have a key string, you can query the value directly with the key
152+
using xbc_find_value(). If you want to know what keys exist in the boot
153+
config, you can use xbc_for_each_key_value() to iterate key-value pairs.
154+
Note that you need to use xbc_array_for_each_value() for accessing
155+
each array's value, e.g.::
156+
157+
vnode = NULL;
158+
xbc_find_value("key.word", &vnode);
159+
if (vnode && xbc_node_is_array(vnode))
160+
xbc_array_for_each_value(vnode, value) {
161+
printk("%s ", value);
162+
}
163+
164+
If you want to focus on keys which have a prefix string, you can use
165+
xbc_find_node() to find a node by the prefix string, and iterate
166+
keys under the prefix node with xbc_node_for_each_key_value().
167+
168+
But the most typical usage is to get the named value under prefix
169+
or get the named array under prefix as below::
170+
171+
root = xbc_find_node("key.prefix");
172+
value = xbc_node_find_value(root, "option", &vnode);
173+
...
174+
xbc_node_for_each_array_value(root, "array-option", value, anode) {
175+
...
176+
}
177+
178+
This accesses a value of "key.prefix.option" and an array of
179+
"key.prefix.array-option".
180+
181+
Locking is not needed, since after initialization, the config becomes
182+
read-only. All data and keys must be copied if you need to modify it.
183+
184+
185+
Functions and structures
186+
========================
187+
188+
.. kernel-doc:: include/linux/bootconfig.h
189+
.. kernel-doc:: lib/bootconfig.c
190+

Documentation/admin-guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ configure specific aspects of kernel behavior to your liking.
6464
binderfs
6565
binfmt-misc
6666
blockdev/index
67+
bootconfig
6768
braille-console
6869
btmrvl
6970
cgroup-v1/index

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@
437437
no delay (0).
438438
Format: integer
439439

440+
bootconfig [KNL]
441+
Extended command line options can be added to an initrd
442+
and this will cause the kernel to look for it.
443+
444+
See Documentation/admin-guide/bootconfig.rst
445+
440446
bert_disable [ACPI]
441447
Disable BERT OS support on buggy BIOSes.
442448

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=================
4+
Boot-time tracing
5+
=================
6+
7+
:Author: Masami Hiramatsu <[email protected]>
8+
9+
Overview
10+
========
11+
12+
Boot-time tracing allows users to trace boot-time process including
13+
device initialization with full features of ftrace including per-event
14+
filter and actions, histograms, kprobe-events and synthetic-events,
15+
and trace instances.
16+
Since kernel command line is not enough to control these complex features,
17+
this uses bootconfig file to describe tracing feature programming.
18+
19+
Options in the Boot Config
20+
==========================
21+
22+
Here is the list of available options list for boot time tracing in
23+
boot config file [1]_. All options are under "ftrace." or "kernel."
24+
prefix. See kernel parameters for the options which starts
25+
with "kernel." prefix [2]_.
26+
27+
.. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>`
28+
.. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>`
29+
30+
Ftrace Global Options
31+
---------------------
32+
33+
Ftrace global options have "kernel." prefix in boot config, which means
34+
these options are passed as a part of kernel legacy command line.
35+
36+
kernel.tp_printk
37+
Output trace-event data on printk buffer too.
38+
39+
kernel.dump_on_oops [= MODE]
40+
Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer
41+
on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops.
42+
43+
kernel.traceoff_on_warning
44+
Stop tracing if WARN_ON() occurs.
45+
46+
kernel.fgraph_max_depth = MAX_DEPTH
47+
Set MAX_DEPTH to maximum depth of fgraph tracer.
48+
49+
kernel.fgraph_filters = FILTER[, FILTER2...]
50+
Add fgraph tracing function filters.
51+
52+
kernel.fgraph_notraces = FILTER[, FILTER2...]
53+
Add fgraph non-tracing function filters.
54+
55+
56+
Ftrace Per-instance Options
57+
---------------------------
58+
59+
These options can be used for each instance including global ftrace node.
60+
61+
ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
62+
Enable given ftrace options.
63+
64+
ftrace.[instance.INSTANCE.]trace_clock = CLOCK
65+
Set given CLOCK to ftrace's trace_clock.
66+
67+
ftrace.[instance.INSTANCE.]buffer_size = SIZE
68+
Configure ftrace buffer size to SIZE. You can use "KB" or "MB"
69+
for that SIZE.
70+
71+
ftrace.[instance.INSTANCE.]alloc_snapshot
72+
Allocate snapshot buffer.
73+
74+
ftrace.[instance.INSTANCE.]cpumask = CPUMASK
75+
Set CPUMASK as trace cpu-mask.
76+
77+
ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]]
78+
Enable given events on boot. You can use a wild card in EVENT.
79+
80+
ftrace.[instance.INSTANCE.]tracer = TRACER
81+
Set TRACER to current tracer on boot. (e.g. function)
82+
83+
ftrace.[instance.INSTANCE.]ftrace.filters
84+
This will take an array of tracing function filter rules.
85+
86+
ftrace.[instance.INSTANCE.]ftrace.notraces
87+
This will take an array of NON-tracing function filter rules.
88+
89+
90+
Ftrace Per-Event Options
91+
------------------------
92+
93+
These options are setting per-event options.
94+
95+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
96+
Enable GROUP:EVENT tracing.
97+
98+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
99+
Set FILTER rule to the GROUP:EVENT.
100+
101+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]]
102+
Set ACTIONs to the GROUP:EVENT.
103+
104+
ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]]
105+
Defines new kprobe event based on PROBEs. It is able to define
106+
multiple probes on one event, but those must have same type of
107+
arguments. This option is available only for the event which
108+
group name is "kprobes".
109+
110+
ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]]
111+
Defines new synthetic event with FIELDs. Each field should be
112+
"type varname".
113+
114+
Note that kprobe and synthetic event definitions can be written under
115+
instance node, but those are also visible from other instances. So please
116+
take care for event name conflict.
117+
118+
119+
Examples
120+
========
121+
122+
For example, to add filter and actions for each event, define kprobe
123+
events, and synthetic events with histogram, write a boot config like
124+
below::
125+
126+
ftrace.event {
127+
task.task_newtask {
128+
filter = "pid < 128"
129+
enable
130+
}
131+
kprobes.vfs_read {
132+
probes = "vfs_read $arg1 $arg2"
133+
filter = "common_pid < 200"
134+
enable
135+
}
136+
synthetic.initcall_latency {
137+
fields = "unsigned long func", "u64 lat"
138+
actions = "hist:keys=func.sym,lat:vals=lat:sort=lat"
139+
}
140+
initcall.initcall_start {
141+
actions = "hist:keys=func:ts0=common_timestamp.usecs"
142+
}
143+
initcall.initcall_finish {
144+
actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)"
145+
}
146+
}
147+
148+
Also, boot-time tracing supports "instance" node, which allows us to run
149+
several tracers for different purpose at once. For example, one tracer
150+
is for tracing functions starting with "user\_", and others tracing
151+
"kernel\_" functions, you can write boot config as below::
152+
153+
ftrace.instance {
154+
foo {
155+
tracer = "function"
156+
ftrace.filters = "user_*"
157+
}
158+
bar {
159+
tracer = "function"
160+
ftrace.filters = "kernel_*"
161+
}
162+
}
163+
164+
The instance node also accepts event nodes so that each instance
165+
can customize its event tracing.
166+
167+
This boot-time tracing also supports ftrace kernel parameters via boot
168+
config.
169+
For example, following kernel parameters::
170+
171+
trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*"
172+
173+
This can be written in boot config like below::
174+
175+
kernel {
176+
trace_options = sym-addr
177+
trace_event = "initcall:*"
178+
tp_printk
179+
trace_buf_size = 1M
180+
ftrace = function
181+
ftrace_filter = "vfs*"
182+
}
183+
184+
Note that parameters start with "kernel" prefix instead of "ftrace".

0 commit comments

Comments
 (0)