Speeding up printf for BIOS Trace

UEFI, like other embedded code bases, is riddled with printf style debug statements. In debug builds, these can slow the boot process down tremendously. There is a way to circumvent this.


In the EDK2-based version of UEFI, debug print statements are actually macros which call debug print routines with several possible destinations. These macros, such as “DEBUG”, use a syntax and process which includes, as an argument, a printf style text formatting string. The processing code to turn the arguments into a readable string can run thousands of instructions in the target code being debugged. This execution time added to the backpressure caused by synchronous call to drivers for slow transports such as RS232 serial IO can cause the execution speed of the boot code to increase from tens of seconds to several minutes. This in turn can mask bugs which are time-dependent.

These issues can be circumvented when the platform silicon supports a System Trace Macrocell (STM). STM is a newer trace element that can provide event and data value tracing necessary to render and observe changes in the state of the system. Redirecting BIOS debug output to the STM (within x86 systems, the Intel® Trace Hub) virtually eliminates backpressure, and provides the possibility of moving almost all the overhead of printf to the debug tool and outside of the user’s product.

The SourcePoint Tool-Hosted Printf facility uses the STM and specifies that SourcePoint does the display, rather than the target software. This is accomplished by emitting the address of the printf format string, and the printf arguments as data packets. This greatly reduces the number of bytes traced. Trace Hub metadata is one or more XML files used by SourcePoint to format and display Trace Hub trace data. It includes information about the masters and channels in a system, including names, display formats, and system-wide settings. The Configuration screen on Intel-based systems looks like this:

Trace Hub configuration screen

For more information on Tool-Hosted Printf, see our eBook, Intel’s Trace Hub | New Methods for Software Debug Find Root Cause Faster (note: requires registration).