xref: /OK3568_Linux_fs/kernel/Documentation/trace/boottime-trace.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun=================
4*4882a593SmuzhiyunBoot-time tracing
5*4882a593Smuzhiyun=================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun:Author: Masami Hiramatsu <mhiramat@kernel.org>
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunOverview
10*4882a593Smuzhiyun========
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunBoot-time tracing allows users to trace boot-time process including
13*4882a593Smuzhiyundevice initialization with full features of ftrace including per-event
14*4882a593Smuzhiyunfilter and actions, histograms, kprobe-events and synthetic-events,
15*4882a593Smuzhiyunand trace instances.
16*4882a593SmuzhiyunSince kernel command line is not enough to control these complex features,
17*4882a593Smuzhiyunthis uses bootconfig file to describe tracing feature programming.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunOptions in the Boot Config
20*4882a593Smuzhiyun==========================
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunHere is the list of available options list for boot time tracing in
23*4882a593Smuzhiyunboot config file [1]_. All options are under "ftrace." or "kernel."
24*4882a593Smuzhiyunprefix. See kernel parameters for the options which starts
25*4882a593Smuzhiyunwith "kernel." prefix [2]_.
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun.. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>`
28*4882a593Smuzhiyun.. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>`
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunFtrace Global Options
31*4882a593Smuzhiyun---------------------
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunFtrace global options have "kernel." prefix in boot config, which means
34*4882a593Smuzhiyunthese options are passed as a part of kernel legacy command line.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyunkernel.tp_printk
37*4882a593Smuzhiyun   Output trace-event data on printk buffer too.
38*4882a593Smuzhiyun
39*4882a593Smuzhiyunkernel.dump_on_oops [= MODE]
40*4882a593Smuzhiyun   Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer
41*4882a593Smuzhiyun   on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops.
42*4882a593Smuzhiyun
43*4882a593Smuzhiyunkernel.traceoff_on_warning
44*4882a593Smuzhiyun   Stop tracing if WARN_ON() occurs.
45*4882a593Smuzhiyun
46*4882a593Smuzhiyunkernel.fgraph_max_depth = MAX_DEPTH
47*4882a593Smuzhiyun   Set MAX_DEPTH to maximum depth of fgraph tracer.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyunkernel.fgraph_filters = FILTER[, FILTER2...]
50*4882a593Smuzhiyun   Add fgraph tracing function filters.
51*4882a593Smuzhiyun
52*4882a593Smuzhiyunkernel.fgraph_notraces = FILTER[, FILTER2...]
53*4882a593Smuzhiyun   Add fgraph non-tracing function filters.
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunFtrace Per-instance Options
57*4882a593Smuzhiyun---------------------------
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunThese options can be used for each instance including global ftrace node.
60*4882a593Smuzhiyun
61*4882a593Smuzhiyunftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
62*4882a593Smuzhiyun   Enable given ftrace options.
63*4882a593Smuzhiyun
64*4882a593Smuzhiyunftrace.[instance.INSTANCE.]tracing_on = 0|1
65*4882a593Smuzhiyun   Enable/Disable tracing on this instance when starting boot-time tracing.
66*4882a593Smuzhiyun   (you can enable it by the "traceon" event trigger action)
67*4882a593Smuzhiyun
68*4882a593Smuzhiyunftrace.[instance.INSTANCE.]trace_clock = CLOCK
69*4882a593Smuzhiyun   Set given CLOCK to ftrace's trace_clock.
70*4882a593Smuzhiyun
71*4882a593Smuzhiyunftrace.[instance.INSTANCE.]buffer_size = SIZE
72*4882a593Smuzhiyun   Configure ftrace buffer size to SIZE. You can use "KB" or "MB"
73*4882a593Smuzhiyun   for that SIZE.
74*4882a593Smuzhiyun
75*4882a593Smuzhiyunftrace.[instance.INSTANCE.]alloc_snapshot
76*4882a593Smuzhiyun   Allocate snapshot buffer.
77*4882a593Smuzhiyun
78*4882a593Smuzhiyunftrace.[instance.INSTANCE.]cpumask = CPUMASK
79*4882a593Smuzhiyun   Set CPUMASK as trace cpu-mask.
80*4882a593Smuzhiyun
81*4882a593Smuzhiyunftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]]
82*4882a593Smuzhiyun   Enable given events on boot. You can use a wild card in EVENT.
83*4882a593Smuzhiyun
84*4882a593Smuzhiyunftrace.[instance.INSTANCE.]tracer = TRACER
85*4882a593Smuzhiyun   Set TRACER to current tracer on boot. (e.g. function)
86*4882a593Smuzhiyun
87*4882a593Smuzhiyunftrace.[instance.INSTANCE.]ftrace.filters
88*4882a593Smuzhiyun   This will take an array of tracing function filter rules.
89*4882a593Smuzhiyun
90*4882a593Smuzhiyunftrace.[instance.INSTANCE.]ftrace.notraces
91*4882a593Smuzhiyun   This will take an array of NON-tracing function filter rules.
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunFtrace Per-Event Options
95*4882a593Smuzhiyun------------------------
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunThese options are setting per-event options.
98*4882a593Smuzhiyun
99*4882a593Smuzhiyunftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
100*4882a593Smuzhiyun   Enable GROUP:EVENT tracing.
101*4882a593Smuzhiyun
102*4882a593Smuzhiyunftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
103*4882a593Smuzhiyun   Set FILTER rule to the GROUP:EVENT.
104*4882a593Smuzhiyun
105*4882a593Smuzhiyunftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]]
106*4882a593Smuzhiyun   Set ACTIONs to the GROUP:EVENT.
107*4882a593Smuzhiyun
108*4882a593Smuzhiyunftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]]
109*4882a593Smuzhiyun   Defines new kprobe event based on PROBEs. It is able to define
110*4882a593Smuzhiyun   multiple probes on one event, but those must have same type of
111*4882a593Smuzhiyun   arguments. This option is available only for the event which
112*4882a593Smuzhiyun   group name is "kprobes".
113*4882a593Smuzhiyun
114*4882a593Smuzhiyunftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]]
115*4882a593Smuzhiyun   Defines new synthetic event with FIELDs. Each field should be
116*4882a593Smuzhiyun   "type varname".
117*4882a593Smuzhiyun
118*4882a593SmuzhiyunNote that kprobe and synthetic event definitions can be written under
119*4882a593Smuzhiyuninstance node, but those are also visible from other instances. So please
120*4882a593Smuzhiyuntake care for event name conflict.
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunWhen to Start
124*4882a593Smuzhiyun=============
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunAll boot-time tracing options starting with ``ftrace`` will be enabled at the
127*4882a593Smuzhiyunend of core_initcall. This means you can trace the events from postcore_initcall.
128*4882a593SmuzhiyunMost of the subsystems and architecture dependent drivers will be initialized
129*4882a593Smuzhiyunafter that (arch_initcall or subsys_initcall). Thus, you can trace those with
130*4882a593Smuzhiyunboot-time tracing.
131*4882a593SmuzhiyunIf you want to trace events before core_initcall, you can use the options
132*4882a593Smuzhiyunstarting with ``kernel``. Some of them will be enabled eariler than the initcall
133*4882a593Smuzhiyunprocessing (for example,. ``kernel.ftrace=function`` and ``kernel.trace_event``
134*4882a593Smuzhiyunwill start before the initcall.)
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun
137*4882a593SmuzhiyunExamples
138*4882a593Smuzhiyun========
139*4882a593Smuzhiyun
140*4882a593SmuzhiyunFor example, to add filter and actions for each event, define kprobe
141*4882a593Smuzhiyunevents, and synthetic events with histogram, write a boot config like
142*4882a593Smuzhiyunbelow::
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun  ftrace.event {
145*4882a593Smuzhiyun        task.task_newtask {
146*4882a593Smuzhiyun                filter = "pid < 128"
147*4882a593Smuzhiyun                enable
148*4882a593Smuzhiyun        }
149*4882a593Smuzhiyun        kprobes.vfs_read {
150*4882a593Smuzhiyun                probes = "vfs_read $arg1 $arg2"
151*4882a593Smuzhiyun                filter = "common_pid < 200"
152*4882a593Smuzhiyun                enable
153*4882a593Smuzhiyun        }
154*4882a593Smuzhiyun        synthetic.initcall_latency {
155*4882a593Smuzhiyun                fields = "unsigned long func", "u64 lat"
156*4882a593Smuzhiyun                actions = "hist:keys=func.sym,lat:vals=lat:sort=lat"
157*4882a593Smuzhiyun        }
158*4882a593Smuzhiyun        initcall.initcall_start {
159*4882a593Smuzhiyun                actions = "hist:keys=func:ts0=common_timestamp.usecs"
160*4882a593Smuzhiyun        }
161*4882a593Smuzhiyun        initcall.initcall_finish {
162*4882a593Smuzhiyun                actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)"
163*4882a593Smuzhiyun        }
164*4882a593Smuzhiyun  }
165*4882a593Smuzhiyun
166*4882a593SmuzhiyunAlso, boot-time tracing supports "instance" node, which allows us to run
167*4882a593Smuzhiyunseveral tracers for different purpose at once. For example, one tracer
168*4882a593Smuzhiyunis for tracing functions starting with "user\_", and others tracing
169*4882a593Smuzhiyun"kernel\_" functions, you can write boot config as below::
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun  ftrace.instance {
172*4882a593Smuzhiyun        foo {
173*4882a593Smuzhiyun                tracer = "function"
174*4882a593Smuzhiyun                ftrace.filters = "user_*"
175*4882a593Smuzhiyun        }
176*4882a593Smuzhiyun        bar {
177*4882a593Smuzhiyun                tracer = "function"
178*4882a593Smuzhiyun                ftrace.filters = "kernel_*"
179*4882a593Smuzhiyun        }
180*4882a593Smuzhiyun  }
181*4882a593Smuzhiyun
182*4882a593SmuzhiyunThe instance node also accepts event nodes so that each instance
183*4882a593Smuzhiyuncan customize its event tracing.
184*4882a593Smuzhiyun
185*4882a593SmuzhiyunWith the trigger action and kprobes, you can trace function-graph while
186*4882a593Smuzhiyuna function is called. For example, this will trace all function calls in
187*4882a593Smuzhiyunthe pci_proc_init()::
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun  ftrace {
190*4882a593Smuzhiyun        tracing_on = 0
191*4882a593Smuzhiyun        tracer = function_graph
192*4882a593Smuzhiyun        event.kprobes {
193*4882a593Smuzhiyun                start_event {
194*4882a593Smuzhiyun                        probes = "pci_proc_init"
195*4882a593Smuzhiyun                        actions = "traceon"
196*4882a593Smuzhiyun                }
197*4882a593Smuzhiyun                end_event {
198*4882a593Smuzhiyun                        probes = "pci_proc_init%return"
199*4882a593Smuzhiyun                        actions = "traceoff"
200*4882a593Smuzhiyun                }
201*4882a593Smuzhiyun        }
202*4882a593Smuzhiyun  }
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun
205*4882a593SmuzhiyunThis boot-time tracing also supports ftrace kernel parameters via boot
206*4882a593Smuzhiyunconfig.
207*4882a593SmuzhiyunFor example, following kernel parameters::
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*"
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunThis can be written in boot config like below::
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun  kernel {
214*4882a593Smuzhiyun        trace_options = sym-addr
215*4882a593Smuzhiyun        trace_event = "initcall:*"
216*4882a593Smuzhiyun        tp_printk
217*4882a593Smuzhiyun        trace_buf_size = 1M
218*4882a593Smuzhiyun        ftrace = function
219*4882a593Smuzhiyun        ftrace_filter = "vfs*"
220*4882a593Smuzhiyun  }
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunNote that parameters start with "kernel" prefix instead of "ftrace".
223