4.4.2 Performance Optimizations

The following table lists the techniques to use to improve the performance of UEFI drivers. By using combinations of all of these techniques, significant performance enhancements can be realized.

Table 16-Speed optimizations

Technique

Description

Compiler flags that optimize for performance.

Some compiler provide flags (such as /Ot, /O2, and /Ox) optimize code for performance. This technique is an easy way to reduce the execution time of a UEFI driver. For the most part, the EDK II balances size and speed optimizations. The flags can be customized to specify a preference for speed or size. Note: When optimization is turned on, each line of source code may not map to the same line when a debugger is active. This can make it more difficult to debug. TIP: Be careful when turning on compiler optimizations because C source that works fine with optimizations disabled may stop working with optimizations enabled. They usually stop working because of missing volatile declarations on variables and data structures that are shared between normal contexts and raised TPL contexts. TIP: Because the UEFI driver is small, it may execute faster. If there are any speed paths in a UEFI driver that cause problems if the UEFI driver executes faster, then these switches may expose those speed paths. These same speed paths also show up as faster processors are used, so it is good to find these speed paths early.

UEFI Services

Whenever possible, use UEFI boot services, UEFI runtime services, and the protocol services provided by other UEFI drivers. The UEFI boot services and UEFI runtime services are likely implemented as native calls that have been optimized for the platform, so there is a performance advantage for using these services. Some protocol services might be native, and other protocol services might be EBC images. Either way, if all UEFI drivers assume that external protocol services are native, then the combination of UEFI drivers and EFI services result in more efficient execution.

PCI I/O Protocol

If a UEFI driver is a PCI driver, then it should take advantage of all the PCI I/O Protocol services to improve the UEFI driver's performance. This approach means that all register accesses should be performed at the largest possible size. For example, perform a single 32-bit read instead of multiple 8-bit reads. Also, take advantage of the read/write multiple, FIFO, and fill modes of the Io(), Mem(), and Pci() services. See Chapter 18 for details on optimization techniques that are specific to PCI.