Failed to Perform an I/O Analysis Task
Symptom
An I/O analysis task fails. The error message is "system not support, please open ftrace." Check whether the system supports ftrace and whether ftrace is enabled.
Possible Cause
The OS kernel version does not support ftrace.
Troubleshooting Procedure
Ftrace is a tracing tool built in the Linux kernel and has been added to mainstream kernels since the kernel version 2.6.27. You can use ftrace to debug or analyze events in the kernel. Ftrace provides different tracers for different scenarios, such as tracing kernel function calls, tracing context switching, viewing the duration when interrupts are disabled, tracing the delay in the kernel mode, and tracing performance problems. System developers can use ftrace to trace and debug kernels to find the root causes of the problems in the kernels and rectify the problems. In addition, users who are interested in kernels can use ftrace to observe the activities in kernels and understand the working mechanism of kernels.
Perform the following steps to recompile the kernel:
- Enable the kernel to support ftrace.
- Before using ftrace, compile it into the kernel. The kernel/trace/Makefile file in the kernel source code directory provides the compilation options related to ftrace, as shown in Table 1.
Table 1 Configuration items related to ftrace No.
Configuration Item
1
CONFIG_FUNCTION_TRACER
2
CONFIG_FUNCTION_GRAPH_TRACER
3
CONFIG_CONTEXT_SWITCH_TRACER
4
CONFIG_NOP_TRACER
5
CONFIG_SCHED_TRACER
6
...
Many configuration items are related to ftrace. Different tracers have different configuration items, and thus have different dependencies. The kernel/trace/Kconfig file in the kernel source code directory describes these dependencies. You can refer to the Makefile and Kconfig files and select the required tracer.
- Generally, it is more intuitive to use make menuconfig when configuring the kernel. Take kernel 2.6.33.1 as an example. To compile ftrace into the kernel, select Kernel hacking and Tracers, as shown in Figure 1 and Figure 2.
- The Tracers menu lists the tracers supported by the kernel, as shown in Figure 3. You can select a tracer as required.
On a 32-bit x86 server, do not select Optimize for size (see Figure 5) in the General setup menu (see Figure 4) during compilation. Otherwise, the Kernel Function Graph Tracer option in is not displayed on the screen shown in Figure 3. This is because in the Kconfig file, the CONFIG_FUNCTION_GRAPH_TRACER configuration item has a special dependency condition depends on !X86_32 || !CC_OPTIMIZE_FOR_SIZE for a 32-bit x86 server.
- Ftrace provides access interfaces for the user mode through debugfs. Therefore, debugfs needs to be compiled into the kernel. To activate the support for debugfs for the kernel, set CONFIG_DEBUG_FS to y in the kernel configuration file (.config). You can also run the make menuconfig command and select Debug Filesystem in the Kernel hacking menu to support debugfs, as shown in Figure 6.
- After the configuration is complete, compile and install the new kernel, and then start the new kernel.
After the support for ftrace is activated for the kernel, the -pg option of the compiler is used during kernel compilation. This option is defined in the kernel/trace/Makefile file, as shown in the following figure.
ifdef CONFIG_FUNCTION_TRACER ORIG_CFLAGS := $(KBUILD_CFLAGS) KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS)) ... endif ...
Using the -pg option adds a lot of debugging information to the compiled kernel image. Generally, the support for ftrace is activated only in the development and test phase to debug the kernel and fix bugs. The kernel eventually used for release will disable the -pg option and will not be able to use ftrace.
- Before using ftrace, compile it into the kernel. The kernel/trace/Makefile file in the kernel source code directory provides the compilation options related to ftrace, as shown in Table 1.
- Access ftrace through debugfs.
- Ftrace provides access interfaces for the user mode through debugfs. After debugfs is activated during kernel configuration, the /sys/kernel/debug directory is created. The debugfs file system is mounted to this directory.
To mount debugfs to the directory, add the following content to the /etc/fstab file:
1debugfs /sys/kernel/debug debugfs defaults 0 0
You can also mount debugfs to the directory when the OS is running.
1mount -t debugfs nodev /sys/kernel/debug
- After the support for ftrace is activated for the kernel, the /sys/kernel/debug/tracing directory is created in debugfs. This directory contains the ftrace control and output files, as shown in Figure 7. The files and directories in this directory vary according to the settings of ftrace during kernel compilation.
- Ftrace provides access interfaces for the user mode through debugfs. After debugfs is activated during kernel configuration, the /sys/kernel/debug directory is created. The debugfs file system is mounted to this directory.
Data files of ftrace
There are many files and directories in the /sys/kernel/debug/trace directory. Some of them are shared by various tracers, and some are used by a specific tracer. Generally, the echo command is used to change the values of these data files. You can also use the functions related to file reading and writing in the program to change the values of these files. Table 2 describes only some data files of ftrace. For details about the usage of other data files of ftrace, see the documents in the Documentation/trace directory in the kernel source package and the source files in the kernel/trace directory.
|
File |
Description |
|---|---|
|
README |
Provides a short usage guide that shows the sequence of ftrace operation commands. You can run the cat command to view the file to understand the general operation process. |
|
current_tracer |
Used to set or display the current tracer. You can run the echo command to write the name of another tracer to this file to switch to the tracer. After the system starts, the default value of the file is nop, that is, no tracing operation is performed. After a trace task is executed for a period of time, you can reset the tracer by writing nop to the file. |
|
available_tracers |
Records the list of tracers that are compiled into the kernel. You can run the cat command to view the content. The tracers contained in this file correspond to the options activated in Figure 3. The tracer name written into the current_tracer file must be in the tracer name list in the available_tracers file. |
|
trace |
Provides an interface for viewing the obtained trace information. You can run the cat command to view the traced kernel activity records in this file. You can also save the content of the file as a record file for future use. |
|
tracing_enabled |
Used to configure whether the tracer specified in the current_tracer file can trace the calling of kernel functions.
|
|
set_graph_function |
Used to set functions whose calling relationship needs to be clearly displayed. The displayed information structure is similar to code in the C language. In this way, the kernel operation process can be analyzed more intuitively. This file is used when the function_graph tracer is used. By default, a calling relationship sequence is generated for all functions. You can write this file to specify the functions that require special attention. |
|
buffer_size_kb |
Used to set the size of the trace buffer used by a single CPU. Tracers write traced information into the buffer. The trace buffer of each CPU is of the same size. The trace buffer is a ring buffer. If too much information is traced, historical information will be overwritten by new information.
NOTE:
To change the value of the file, set the value in the current_tracer file to nop. |
|
tracing_on |
Used to control the pause of tracing. Sometimes, you can write 0 to the file to disable the trace function temporarily when observing certain events. In such case, the newer part in the trace buffer is related to the concerned events. You can write 1 to the file to continue the tracing. |
|
available_filter_functions |
Records the kernel functions that can be traced currently. The activities of the functions that are not listed in this file cannot be traced. |
|
set_ftrace_filter and set_ftrace_notrace |
Used after dynamic ftrace is enabled (CONFIG_DYNAMIC_FTRACE is selected) during kernel compilation. The set_ftrace_filter file is used to specify the functions to be traced, and the set_ftrace_notrace file is used to specify the functions not to be traced. If a function name appears in both files, the execution of the function is not traced. The two files also support simple expressions with wildcards so that you can specify multiple target functions at a time with one expression. The value of set_ftrace_notrace is null by default, that is, all kernel functions can be traced.
NOTE:
The names of the functions to be written into the two files must be included in the available_filter_functions file. |
Ftrace Tracers
Ftrace contains multiple tracers to trace different types of information, such as information about process scheduling and interrupt disabling. You can obtain from the available_tracers file the list of trackers supported by the kernel. When compiling the kernel, you can see the options corresponding to the trackers supported by the kernel, as described in Figure 3.
|
Tracer |
Description |
|---|---|
|
nop |
The nop tracer does not trace any kernel activities. You can write nop to the current_tracer file to delete the previously used tracers and clear the previously collected trace information, that is, refresh the trace file. |
|
function |
Traces the execution of kernel functions. In the set_ftrace_filter file, you can specify the functions to be traced. |
|
function_graph |
Displays the calling relationship of functions. The displayed information structure is similar to code in the C language. In this way, the function calling relationship is intuitive. In the set_graph_function file, you can specify the functions. |
|
sched_switch |
Traces process scheduling activities in the kernel. |
|
irqsoff and preemptoff |
The irqsoff and preemptoff trackers respectively trace the code for disabling interrupts and the code for forbidding process preemption, and record the maximum duration for disabling interrupts. The preemptirqsoff tracker can be considered as a combination of the two trackers. |
Ftrace also supports other tracers, such as initcall, ksym_tracer, mmiotrace, and sysprof. The ftrace framework allows users to add new tracers. You can refer to the documents in the Documentation/trace directory of the kernel source package and the source files in the kernel/trace directory to understand the usage of other tracers and the method for adding new tracers.






