Skip to main content
The Linux kernel provides several dynamic instrumentation mechanisms that let you insert probes, collect traces, and measure timing without patching or recompiling the kernel. This page covers kprobes for code-path breakpoints, ftrace for function-level profiling, and MMIO traces for debugging driver register access failures.

Kprobes

Kprobes lets you break into any kernel instruction address and run a custom handler when execution reaches that point. The technique is non-disruptive — the running kernel is not stopped and other CPUs continue executing.

How kprobes works

  1. You register a probe on a symbol or address.
  2. The kernel replaces the target instruction with a trap.
  3. When the trap fires, the kprobe handler runs in the same context as the interrupted code.
  4. The kernel restores the original instruction and continues execution.
Kprobes are particularly useful for:
  • Tracing scheduler events (schedule(), try_to_wake_up())
  • Counting how often a slow code path is taken
  • Capturing call arguments without adding printk and rebuilding

Kconfig

Verify on target:

Kprobe trace events via tracefs

The easiest way to use kprobes is through the tracefs kprobe_events interface:
For full kprobes documentation, see Kernel Probes (kprobes).

Ftrace

Ftrace is the kernel’s built-in function tracer. It can record every function call in the kernel, trace specific subsystems, or profile latency-sensitive code paths. Results are read from the tracefs interface (/sys/kernel/tracing/).

Function tracer

The function tracer records the name and CPU of every kernel function called:

Function graph tracer

The function_graph tracer records entry and exit of each function, including execution time. Useful for identifying slow code paths:
Sample output:

Trace boot initcalls

Add to the kernel command line to trace all initcalls at boot:
Parse results with:
For full ftrace documentation, see Function Tracer.

MMIO trace events

Memory-mapped I/O (MMIO) traces record every register read and write performed by the kernel, using __raw_{read,write}{b,l,w,q} accessors. They are essential for diagnosing the following crash categories on Qualcomm® SoCs: Table: MMIO crash scenarios

Enable MMIO traces

Kconfig:
At runtime, enable rwmmio trace events via tracefs:
Sample output:
Each line identifies the calling function (with offset), the access type (readl/writel/writeq), and the physical address. Cross-reference the address against the SoC Technical Reference Manual to identify the register block involved in a crash.

Dump MMIO trace on console at crash

To capture MMIO traces even when the system crashes before you can read tracefs, enable console dumping of the ftrace buffer:
The last trace entries are then included in the kernel panic output on the serial console.