xref: /linux/Documentation/trace/boottime-trace.rst (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
147781947SMasami Hiramatsu.. SPDX-License-Identifier: GPL-2.0
247781947SMasami Hiramatsu
347781947SMasami Hiramatsu=================
447781947SMasami HiramatsuBoot-time tracing
547781947SMasami Hiramatsu=================
647781947SMasami Hiramatsu
747781947SMasami Hiramatsu:Author: Masami Hiramatsu <mhiramat@kernel.org>
847781947SMasami Hiramatsu
947781947SMasami HiramatsuOverview
1047781947SMasami Hiramatsu========
1147781947SMasami Hiramatsu
1247781947SMasami HiramatsuBoot-time tracing allows users to trace boot-time process including
1347781947SMasami Hiramatsudevice initialization with full features of ftrace including per-event
1447781947SMasami Hiramatsufilter and actions, histograms, kprobe-events and synthetic-events,
1547781947SMasami Hiramatsuand trace instances.
16b8381ce7SMasami HiramatsuSince kernel command line is not enough to control these complex features,
1747781947SMasami Hiramatsuthis uses bootconfig file to describe tracing feature programming.
1847781947SMasami Hiramatsu
1947781947SMasami HiramatsuOptions in the Boot Config
2047781947SMasami Hiramatsu==========================
2147781947SMasami Hiramatsu
2247781947SMasami HiramatsuHere is the list of available options list for boot time tracing in
2347781947SMasami Hiramatsuboot config file [1]_. All options are under "ftrace." or "kernel."
24b8381ce7SMasami Hiramatsuprefix. See kernel parameters for the options which starts
2547781947SMasami Hiramatsuwith "kernel." prefix [2]_.
2647781947SMasami Hiramatsu
2747781947SMasami Hiramatsu.. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>`
2847781947SMasami Hiramatsu.. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>`
2947781947SMasami Hiramatsu
3047781947SMasami HiramatsuFtrace Global Options
3147781947SMasami Hiramatsu---------------------
3247781947SMasami Hiramatsu
3347781947SMasami HiramatsuFtrace global options have "kernel." prefix in boot config, which means
3447781947SMasami Hiramatsuthese options are passed as a part of kernel legacy command line.
3547781947SMasami Hiramatsu
3647781947SMasami Hiramatsukernel.tp_printk
3747781947SMasami Hiramatsu   Output trace-event data on printk buffer too.
3847781947SMasami Hiramatsu
3947781947SMasami Hiramatsukernel.dump_on_oops [= MODE]
4047781947SMasami Hiramatsu   Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer
4147781947SMasami Hiramatsu   on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops.
4247781947SMasami Hiramatsu
4347781947SMasami Hiramatsukernel.traceoff_on_warning
4447781947SMasami Hiramatsu   Stop tracing if WARN_ON() occurs.
4547781947SMasami Hiramatsu
4647781947SMasami Hiramatsukernel.fgraph_max_depth = MAX_DEPTH
4747781947SMasami Hiramatsu   Set MAX_DEPTH to maximum depth of fgraph tracer.
4847781947SMasami Hiramatsu
4947781947SMasami Hiramatsukernel.fgraph_filters = FILTER[, FILTER2...]
5047781947SMasami Hiramatsu   Add fgraph tracing function filters.
5147781947SMasami Hiramatsu
5247781947SMasami Hiramatsukernel.fgraph_notraces = FILTER[, FILTER2...]
53b8381ce7SMasami Hiramatsu   Add fgraph non-tracing function filters.
5447781947SMasami Hiramatsu
5547781947SMasami Hiramatsu
5647781947SMasami HiramatsuFtrace Per-instance Options
5747781947SMasami Hiramatsu---------------------------
5847781947SMasami Hiramatsu
5947781947SMasami HiramatsuThese options can be used for each instance including global ftrace node.
6047781947SMasami Hiramatsu
6147781947SMasami Hiramatsuftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
6247781947SMasami Hiramatsu   Enable given ftrace options.
6347781947SMasami Hiramatsu
64c51ba517SMasami Hiramatsuftrace.[instance.INSTANCE.]tracing_on = 0|1
65c51ba517SMasami Hiramatsu   Enable/Disable tracing on this instance when starting boot-time tracing.
66c51ba517SMasami Hiramatsu   (you can enable it by the "traceon" event trigger action)
67c51ba517SMasami Hiramatsu
6847781947SMasami Hiramatsuftrace.[instance.INSTANCE.]trace_clock = CLOCK
6947781947SMasami Hiramatsu   Set given CLOCK to ftrace's trace_clock.
7047781947SMasami Hiramatsu
7147781947SMasami Hiramatsuftrace.[instance.INSTANCE.]buffer_size = SIZE
7247781947SMasami Hiramatsu   Configure ftrace buffer size to SIZE. You can use "KB" or "MB"
7347781947SMasami Hiramatsu   for that SIZE.
7447781947SMasami Hiramatsu
7547781947SMasami Hiramatsuftrace.[instance.INSTANCE.]alloc_snapshot
7647781947SMasami Hiramatsu   Allocate snapshot buffer.
7747781947SMasami Hiramatsu
7847781947SMasami Hiramatsuftrace.[instance.INSTANCE.]cpumask = CPUMASK
7947781947SMasami Hiramatsu   Set CPUMASK as trace cpu-mask.
8047781947SMasami Hiramatsu
8147781947SMasami Hiramatsuftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]]
8247781947SMasami Hiramatsu   Enable given events on boot. You can use a wild card in EVENT.
8347781947SMasami Hiramatsu
8447781947SMasami Hiramatsuftrace.[instance.INSTANCE.]tracer = TRACER
8547781947SMasami Hiramatsu   Set TRACER to current tracer on boot. (e.g. function)
8647781947SMasami Hiramatsu
8747781947SMasami Hiramatsuftrace.[instance.INSTANCE.]ftrace.filters
88b8381ce7SMasami Hiramatsu   This will take an array of tracing function filter rules.
8947781947SMasami Hiramatsu
9047781947SMasami Hiramatsuftrace.[instance.INSTANCE.]ftrace.notraces
91b8381ce7SMasami Hiramatsu   This will take an array of NON-tracing function filter rules.
9247781947SMasami Hiramatsu
9347781947SMasami Hiramatsu
9447781947SMasami HiramatsuFtrace Per-Event Options
9547781947SMasami Hiramatsu------------------------
9647781947SMasami Hiramatsu
9747781947SMasami HiramatsuThese options are setting per-event options.
9847781947SMasami Hiramatsu
9947781947SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
100b8381ce7SMasami Hiramatsu   Enable GROUP:EVENT tracing.
10147781947SMasami Hiramatsu
102ee0a0701SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.enable
103ee0a0701SMasami Hiramatsu   Enable all event tracing within GROUP.
104ee0a0701SMasami Hiramatsu
105ee0a0701SMasami Hiramatsuftrace.[instance.INSTANCE.]event.enable
106ee0a0701SMasami Hiramatsu   Enable all event tracing.
107ee0a0701SMasami Hiramatsu
10847781947SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
10947781947SMasami Hiramatsu   Set FILTER rule to the GROUP:EVENT.
11047781947SMasami Hiramatsu
11147781947SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]]
11247781947SMasami Hiramatsu   Set ACTIONs to the GROUP:EVENT.
11347781947SMasami Hiramatsu
11447781947SMasami Hiramatsuftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]]
11547781947SMasami Hiramatsu   Defines new kprobe event based on PROBEs. It is able to define
11647781947SMasami Hiramatsu   multiple probes on one event, but those must have same type of
11747781947SMasami Hiramatsu   arguments. This option is available only for the event which
11847781947SMasami Hiramatsu   group name is "kprobes".
11947781947SMasami Hiramatsu
12047781947SMasami Hiramatsuftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]]
12147781947SMasami Hiramatsu   Defines new synthetic event with FIELDs. Each field should be
12247781947SMasami Hiramatsu   "type varname".
12347781947SMasami Hiramatsu
12447781947SMasami HiramatsuNote that kprobe and synthetic event definitions can be written under
12547781947SMasami Hiramatsuinstance node, but those are also visible from other instances. So please
12647781947SMasami Hiramatsutake care for event name conflict.
12747781947SMasami Hiramatsu
12855978953SMasami HiramatsuFtrace Histogram Options
12955978953SMasami Hiramatsu------------------------
13055978953SMasami Hiramatsu
13155978953SMasami HiramatsuSince it is too long to write a histogram action as a string for per-event
13255978953SMasami Hiramatsuaction option, there are tree-style options under per-event 'hist' subkey
13355978953SMasami Hiramatsufor the histogram actions. For the detail of the each parameter,
134*0dc91592SYanteng Siplease read the event histogram document (Documentation/trace/histogram.rst)
13555978953SMasami Hiramatsu
13655978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]keys = KEY1[, KEY2[...]]
13755978953SMasami Hiramatsu  Set histogram key parameters. (Mandatory)
13855978953SMasami Hiramatsu  The 'N' is a digit string for the multiple histogram. You can omit it
13955978953SMasami Hiramatsu  if there is one histogram on the event.
14055978953SMasami Hiramatsu
14155978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]values = VAL1[, VAL2[...]]
14255978953SMasami Hiramatsu  Set histogram value parameters.
14355978953SMasami Hiramatsu
14455978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]sort = SORT1[, SORT2[...]]
14555978953SMasami Hiramatsu  Set histogram sort parameter options.
14655978953SMasami Hiramatsu
14755978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]size = NR_ENTRIES
14855978953SMasami Hiramatsu  Set histogram size (number of entries).
14955978953SMasami Hiramatsu
15055978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]name = NAME
15155978953SMasami Hiramatsu  Set histogram name.
15255978953SMasami Hiramatsu
15355978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]var.VARIABLE = EXPR
15455978953SMasami Hiramatsu  Define a new VARIABLE by EXPR expression.
15555978953SMasami Hiramatsu
15655978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<pause|continue|clear>
15755978953SMasami Hiramatsu  Set histogram control parameter. You can set one of them.
15855978953SMasami Hiramatsu
15955978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]event = GROUP.EVENT
16055978953SMasami Hiramatsu  Set histogram 'onmatch' handler matching event parameter.
16155978953SMasami Hiramatsu  The 'M' is a digit string for the multiple 'onmatch' handler. You can omit it
16255978953SMasami Hiramatsu  if there is one 'onmatch' handler on this histogram.
16355978953SMasami Hiramatsu
16455978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]trace = EVENT[, ARG1[...]]
16555978953SMasami Hiramatsu  Set histogram 'trace' action for 'onmatch'.
16655978953SMasami Hiramatsu  EVENT must be a synthetic event name, and ARG1... are parameters
16755978953SMasami Hiramatsu  for that event. Mandatory if 'onmatch.event' option is set.
16855978953SMasami Hiramatsu
16955978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmax.[M.]var = VAR
17055978953SMasami Hiramatsu  Set histogram 'onmax' handler variable parameter.
17155978953SMasami Hiramatsu
17255978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onchange.[M.]var = VAR
17355978953SMasami Hiramatsu  Set histogram 'onchange' handler variable parameter.
17455978953SMasami Hiramatsu
17555978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]save = ARG1[, ARG2[...]]
17655978953SMasami Hiramatsu  Set histogram 'save' action parameters for 'onmax' or 'onchange' handler.
17755978953SMasami Hiramatsu  This option or below 'snapshot' option is mandatory if 'onmax.var' or
17855978953SMasami Hiramatsu  'onchange.var' option is set.
17955978953SMasami Hiramatsu
18055978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]snapshot
18155978953SMasami Hiramatsu  Set histogram 'snapshot' action for 'onmax' or 'onchange' handler.
18255978953SMasami Hiramatsu  This option or above 'save' option is mandatory if 'onmax.var' or
18355978953SMasami Hiramatsu  'onchange.var' option is set.
18455978953SMasami Hiramatsu
18555978953SMasami Hiramatsuftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.filter = FILTER_EXPR
18655978953SMasami Hiramatsu  Set histogram filter expression. You don't need 'if' in the FILTER_EXPR.
18755978953SMasami Hiramatsu
18855978953SMasami HiramatsuNote that this 'hist' option can conflict with the per-event 'actions'
18955978953SMasami Hiramatsuoption if the 'actions' option has a histogram action.
19055978953SMasami Hiramatsu
19147781947SMasami Hiramatsu
192fd264ce9SMasami HiramatsuWhen to Start
193fd264ce9SMasami Hiramatsu=============
194fd264ce9SMasami Hiramatsu
195fd264ce9SMasami HiramatsuAll boot-time tracing options starting with ``ftrace`` will be enabled at the
196fd264ce9SMasami Hiramatsuend of core_initcall. This means you can trace the events from postcore_initcall.
197fd264ce9SMasami HiramatsuMost of the subsystems and architecture dependent drivers will be initialized
198fd264ce9SMasami Hiramatsuafter that (arch_initcall or subsys_initcall). Thus, you can trace those with
199fd264ce9SMasami Hiramatsuboot-time tracing.
200fd264ce9SMasami HiramatsuIf you want to trace events before core_initcall, you can use the options
201fd264ce9SMasami Hiramatsustarting with ``kernel``. Some of them will be enabled eariler than the initcall
202fd264ce9SMasami Hiramatsuprocessing (for example,. ``kernel.ftrace=function`` and ``kernel.trace_event``
203fd264ce9SMasami Hiramatsuwill start before the initcall.)
204fd264ce9SMasami Hiramatsu
205fd264ce9SMasami Hiramatsu
20647781947SMasami HiramatsuExamples
20747781947SMasami Hiramatsu========
20847781947SMasami Hiramatsu
20947781947SMasami HiramatsuFor example, to add filter and actions for each event, define kprobe
21047781947SMasami Hiramatsuevents, and synthetic events with histogram, write a boot config like
21147781947SMasami Hiramatsubelow::
21247781947SMasami Hiramatsu
21347781947SMasami Hiramatsu  ftrace.event {
21447781947SMasami Hiramatsu        task.task_newtask {
21547781947SMasami Hiramatsu                filter = "pid < 128"
21647781947SMasami Hiramatsu                enable
21747781947SMasami Hiramatsu        }
21847781947SMasami Hiramatsu        kprobes.vfs_read {
21947781947SMasami Hiramatsu                probes = "vfs_read $arg1 $arg2"
22047781947SMasami Hiramatsu                filter = "common_pid < 200"
22147781947SMasami Hiramatsu                enable
22247781947SMasami Hiramatsu        }
22347781947SMasami Hiramatsu        synthetic.initcall_latency {
22447781947SMasami Hiramatsu                fields = "unsigned long func", "u64 lat"
22555978953SMasami Hiramatsu                hist {
22655978953SMasami Hiramatsu                        keys = func.sym, lat
22755978953SMasami Hiramatsu                        values = lat
22855978953SMasami Hiramatsu                        sort = lat
22947781947SMasami Hiramatsu                }
23047781947SMasami Hiramatsu        }
23155978953SMasami Hiramatsu        initcall.initcall_start.hist {
23255978953SMasami Hiramatsu                keys = func
23355978953SMasami Hiramatsu                var.ts0 = common_timestamp.usecs
23455978953SMasami Hiramatsu        }
23555978953SMasami Hiramatsu        initcall.initcall_finish.hist {
23655978953SMasami Hiramatsu                keys = func
23755978953SMasami Hiramatsu                var.lat = common_timestamp.usecs - $ts0
23855978953SMasami Hiramatsu                onmatch {
23955978953SMasami Hiramatsu                        event = initcall.initcall_start
24055978953SMasami Hiramatsu                        trace = initcall_latency, func, $lat
24155978953SMasami Hiramatsu                }
24247781947SMasami Hiramatsu        }
24347781947SMasami Hiramatsu  }
24447781947SMasami Hiramatsu
245b8381ce7SMasami HiramatsuAlso, boot-time tracing supports "instance" node, which allows us to run
24647781947SMasami Hiramatsuseveral tracers for different purpose at once. For example, one tracer
247b8381ce7SMasami Hiramatsuis for tracing functions starting with "user\_", and others tracing
248b8381ce7SMasami Hiramatsu"kernel\_" functions, you can write boot config as below::
24947781947SMasami Hiramatsu
25047781947SMasami Hiramatsu  ftrace.instance {
25147781947SMasami Hiramatsu        foo {
25247781947SMasami Hiramatsu                tracer = "function"
25347781947SMasami Hiramatsu                ftrace.filters = "user_*"
25447781947SMasami Hiramatsu        }
25547781947SMasami Hiramatsu        bar {
25647781947SMasami Hiramatsu                tracer = "function"
25747781947SMasami Hiramatsu                ftrace.filters = "kernel_*"
25847781947SMasami Hiramatsu        }
25947781947SMasami Hiramatsu  }
26047781947SMasami Hiramatsu
26147781947SMasami HiramatsuThe instance node also accepts event nodes so that each instance
26247781947SMasami Hiramatsucan customize its event tracing.
26347781947SMasami Hiramatsu
26419c311aeSMasami HiramatsuWith the trigger action and kprobes, you can trace function-graph while
26519c311aeSMasami Hiramatsua function is called. For example, this will trace all function calls in
26619c311aeSMasami Hiramatsuthe pci_proc_init()::
26719c311aeSMasami Hiramatsu
26819c311aeSMasami Hiramatsu  ftrace {
26919c311aeSMasami Hiramatsu        tracing_on = 0
27019c311aeSMasami Hiramatsu        tracer = function_graph
27119c311aeSMasami Hiramatsu        event.kprobes {
27219c311aeSMasami Hiramatsu                start_event {
27319c311aeSMasami Hiramatsu                        probes = "pci_proc_init"
27419c311aeSMasami Hiramatsu                        actions = "traceon"
27519c311aeSMasami Hiramatsu                }
27619c311aeSMasami Hiramatsu                end_event {
27719c311aeSMasami Hiramatsu                        probes = "pci_proc_init%return"
27819c311aeSMasami Hiramatsu                        actions = "traceoff"
27919c311aeSMasami Hiramatsu                }
28019c311aeSMasami Hiramatsu        }
28119c311aeSMasami Hiramatsu  }
28219c311aeSMasami Hiramatsu
28319c311aeSMasami Hiramatsu
28447781947SMasami HiramatsuThis boot-time tracing also supports ftrace kernel parameters via boot
28547781947SMasami Hiramatsuconfig.
28647781947SMasami HiramatsuFor example, following kernel parameters::
28747781947SMasami Hiramatsu
28847781947SMasami Hiramatsu trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*"
28947781947SMasami Hiramatsu
29047781947SMasami HiramatsuThis can be written in boot config like below::
29147781947SMasami Hiramatsu
29247781947SMasami Hiramatsu  kernel {
29347781947SMasami Hiramatsu        trace_options = sym-addr
29447781947SMasami Hiramatsu        trace_event = "initcall:*"
29547781947SMasami Hiramatsu        tp_printk
29647781947SMasami Hiramatsu        trace_buf_size = 1M
29747781947SMasami Hiramatsu        ftrace = function
29847781947SMasami Hiramatsu        ftrace_filter = "vfs*"
29947781947SMasami Hiramatsu  }
30047781947SMasami Hiramatsu
30147781947SMasami HiramatsuNote that parameters start with "kernel" prefix instead of "ftrace".
302