Chapter 14 Statically Defined Tracing of Kernel Modules

DTrace provides a facility for developers to define customized probes in kernel modules. These static probes appear as additional probes of the sdt provider and impose little to no overhead if the sdt module is not loaded. For example, for x86_64, the overhead is a single-byte NOP, followed by a 4-byte NOP. This chapter provides a full example of how to define and use static probes in a kernel module.

The general principles for naming probes and choosing insertion points are the same for kernel modules as they are for user-space applications. You should define probes that have a semantic meaning that is readily understood by your DTrace user community. Typically, you might name probes for the routine in which you place them and their position in that routine. For example, if your probes provide information about data values on entry to or return from a routine named foo, you might name them foo-entry and foo-return. The data values that are returned by such probes could present the routine as a black box, rather than return intermediate values from the internal implementation of the module. To gather data from deeper within a module, you might insert additional probes with names such as foo-stage1 or foo-post-hardware-init.

In one respect, using static probes with kernel modules can be simpler than for user-space applications. You do not need to modify the build files unless you want to conditionally compile a module to include the probes. Inserting the probes in the source code is slightly more complex, as you cannot use the dtrace -h command to generate the probe macros. However, using a DTRACE_PROBE macro to insert a probe is a relatively simple change to make to the source code.

You can insert sdt static probes in any Oracle Linux kernel module for which you have the source files and the necessary build infrastructure, but note that DTrace supports statically defined tracing of 64-bit kernel modules only.

For more information about the sdt provider, see Section 11.5, “sdt provider”.

For an introduction to the concepts of statically defined tracing as applied to user-space applications, see Chapter 13, Statically Defined Tracing of User Applications.