Introduction

"Printk-times" is a simple technology which adds some code to the standard kernel printk routine, to output timing data with each message. While crude, this can be used to get an overview of the areas of kernel initialization which take a relatively long time. This feature is used by the Bootup Time Working Group to identify areas of the Linux kernel requiring work to improve bootup time, and to measure the improvements of changes made by the working group.

The technology for this feature consists of a patch and a utility program. The patch alters the printk code in the kernel to emit the timing data.

/!\ UPDATE: The patch was incorporated into the mainline kernel as of version 2.6.11! Both the feature, and the utility program are now part of mainline Linux!!

With printk-times turned on, the system emits the timing data as a floating point number of seconds (to microsecond resolution) for the time at which the printk started. The utility program shows the time between calls, or it can show the times relative to a specific message. This makes it easier to see the timing for specific segments of kernel code.

Rationale

There are other instrumentation systems for the kernel that have more advanced features than this. However, this system is very simple and robust. It does not require extra programs, interfaces in proc of sysfs, or even a root filesystem, in order to obtain measurements of bootup time. It's weakness is that you can only see timing information for areas of the kernel which have printks. In order to get more detail for an area of interest, you have to add additional printks to the kernel, and re-compile it. Also, printks themselves may add too much timing overhead to the kernel, particularly when the output is over a serial line (which is very common in embedded configurations).

For a system that provides much more detailed timing information, you may want to use KernelFunctionInstrumentation instead.

Downloads

Patch

/!\ - patch is not needed anymore. Printk-times was incorporated into the mainline Linux kernel as of version 2.6.11.

Utility program

The program show_delta reads the information from printk output, and displays time values as delta's between printks. This helps to more easily find periods of long time between printks. (This is easier than "eye-balling" the dump, looking for jumps in the time.)

Here's the program: show_delta

(Please use the one in the /scripts directory of the kernel, if using a patch against Linux 2.6.11 or above)

How To Use (2.6 version of kernel)

runtime control of printk times

Jan Engelhardt supplied a patch against 2.6.17 which allows for runtime control of the printk-times control flag. Here is what he wrote:

{{{Currently, enabling/disabling printk timestamps is only possible through reboot (bootparam) or recompile. I normally do not run with timestamps (since syslog handles that in a good manner), but for measuring small kernel delays (e.g. irq probing - see parport thread) I needed subsecond precision, but then again, just for some minutes rather than all kernel messages to come. The following patch adds a module_param() with which the timestamps can be en-/disabled in a live system through

/sys/modules/printk/parameters/printk_time. }}}

The patch is applied in 2.6.18-rc3 (Linus' tree) so it should show up in 2.6.18.

Trouble-shooting

Customizing the printk times clock

Somewhere between 2.6.11 and 2.6.14, the printk routine was modified to use printk_clock() instead of sched_clock() directly. This means that you can override printk_clock() on your platform to use a custom timestamp source different from the one used by sched_clock() (Or, you can avoid calling sched_clock() until it is ready - say, after time_init()).

How To Use (2.4 version of kernel)

Sample Results

Sample Results for show_delta:


Sample Results for dmesg output for 2.6.11-rc4:

Future Work

Here are some ideas for additional work needed on this system:

initcall-times

Matt Mackall provided a patch which measures times for the initialization of each driver. He described it like this:

Here's another tool for looking at boot-up times. It times just the initcalls and is enabled by putting 'initcall_debug' on the command line.

Here is the patch: initcalls-times.patch

Here are Tim Bird's results on an OSK board: {{{/ # dmesg | grep elapsed | sort -r -n | head -20

}}}

PrintkTimes (last edited 2008-05-07 18:22:17 by localhost)