audk/MdeModulePkg/Library
Aaron Young a6648418c1 MdeModulePkg: Optimize BmExpandPartitionDevicePath
Reference: https://github.com/tianocore/edk2/pull/4892

BmExpandPartitionDevicePath is called to expand "short-form" device paths
which are commonly used with OS boot options. To expand a device path, it
calls EfiBootManagerConnectAll to connect all the possible BlockIo
devices in the system to search for a matching partition. However, this
is sometimes unnecessary on certain platforms (such as OVMF/QEMU) because
the boot devices are previously explicity connected
(See: ConnectDevicesFromQemu).  EfiBootManagerConnectAll calls are
extremely costly in terms of boot time and resources and should be avoided
whenever feasible.

(

OVMF call tree:

  PlatformBootManagerAfterConsole()         [OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c]
    PlatformBdsConnectSequence()            [OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c]
      ConnectDevicesFromQemu()              [OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c]
        ...
    EfiBootManagerRefreshAllBootOption()    [MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c]
      ...
    SetBootOrderFromQemu()                  [OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c]
      Match()                               [OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c]
        EfiBootManagerGetLoadOptionBuffer() [MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c]
          BmGetNextLoadOptionBuffer()       [MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c]
            BmGetNextLoadOptionDevicePath() [MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c]
              BmExpandPartitionDevicePath() [MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c]

)

Therefore optimize BmExpandPartitionDevicePath to first search the
existing BlockIo handles for a match. If a match is not found, then
fallback to the original code to call EfiBootManagerConnectAll and search
again. Thus, this optimization should be extremely low-risk given the
fallback to previous behavior.

NOTE: The existing optimization in the code to use a "HDDP" variable to
save the last matched device paths does not cover the first time a boot
option is expanded (i.e. before the "HDDP" is created) nor when the device
configuration has changed (resulting in the boot device moving to a
different location in the PCI Bus/Dev hierarchy). This new optimization
covers both of these cases on requisite platforms which explicity connect
boot devices.

In our testing on OVMF/QEMU VMs with dozens of configured vnic devices,
these extraneous calls to EfiBootManagerConnectAll from
BmExpandPartitionDevicePath were found to cause many seconds (or even
minutes) of additional VM boot time in some cases - due to the vnics
being unnecessarily connected.

Cc: Zhichao Gao zhichao.gao@intel.com
Cc: Ray Ni ray.ni@intel.com
Signed-off-by: Aaron Young <aaron.young@oracle.com>
Message-Id: <20231010150644.37857-1-Aaron.Young@oracle.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
[lersek@redhat.com: add OVMF call tree to commit message]
2023-10-24 13:00:18 +00:00
..
AuthVariableLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseBmpSupportLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseHobLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseIpmiCommandLibNull MdeModulePkg/IpmiCommandLib: Add NULL instance library 2023-01-19 03:57:32 +00:00
BaseIpmiLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseMemoryAllocationLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BasePlatformHookLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseResetSystemLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseRngLibTimerLib MdePkg/Rng: Add GetRngGuid() to RngLib 2023-09-08 09:48:55 +00:00
BaseSerialPortLib16550 MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseSortLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseVariableFlashInfoLib MdeModulePkg/VariableFlashInfoLib: Add initial library 2022-05-19 06:11:20 +00:00
BootDiscoveryPolicyUiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BootLogoLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BootMaintenanceManagerUiLib MdeModulePkg/BootMaintenanceManagerUiLib: Check array index before access 2023-09-12 02:43:14 +00:00
BootManagerUiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BrotliCustomDecompressLib MdeModulePkg: update brotli submodule 2022-02-15 02:13:32 +00:00
CpuExceptionHandlerLibNull UefiCpuPkg: Simplify InitializeSeparateExceptionStacks 2022-08-09 04:12:28 +00:00
CustomizedDisplayLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DebugAgentLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DeviceManagerUiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DisplayUpdateProgressLibGraphics MdeModulePkg: Fix imbalanced debug macros 2022-09-09 01:42:39 +00:00
DisplayUpdateProgressLibText MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeCapsuleLibFmp MdeModulePkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
DxeCapsuleLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeCoreMemoryAllocationLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeCorePerformanceLib MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue 2023-08-30 11:20:29 +00:00
DxeCrc32GuidedSectionExtractLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeDebugPrintErrorLevelLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeFileExplorerProtocol MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeIpmiLibIpmiProtocol MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxePerformanceLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxePrintLibPrint2Protocol MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeReportStatusCodeLib MdeModulePkg/Include: Long debug string is truncated to 104 char 2022-07-23 03:12:49 +00:00
DxeResetSystemLib MdeModulePkg: HOST_APPLICATION IA32/X64 only 2023-04-10 05:59:02 +00:00
DxeSecurityManagementLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
FileExplorerLib MdeModulePkg: Fix conditionally uninitialized variables 2023-04-03 15:29:08 +00:00
FmpAuthenticationLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
FrameBufferBltLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
LockBoxNullLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
LzmaCustomDecompressLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
NonDiscoverableDeviceRegistrationLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
OemHookStatusCodeLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PciHostBridgeLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiCrc32GuidedSectionExtractLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiDebugLibDebugPpi MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiDebugPrintHobLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiDxeDebugLibReportStatusCode edk2/MdeModulePkg/Debuglib: Add Standalone MM support 2022-03-02 02:34:00 +00:00
PeiIpmiLibIpmiPpi MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiPerformanceLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiReportStatusCodeLib MdeModulePkg/Include: Long debug string is truncated to 104 char 2022-07-23 03:12:49 +00:00
PeiResetSystemLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PiDxeS3BootScriptLib MdeModulePkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
PiSmmCoreMemoryAllocationLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PiSmmCoreSmmServicesTableLib MdeModulePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:08 -07:00
PlatformBootManagerLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PlatformHookLibSerialPortPpi MdeModulePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:08 -07:00
PlatformVarCleanupLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
ResetUtilityLib MdeModulePkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
RuntimeDxeReportStatusCodeLib MdeModulePkg/Include: Long debug string is truncated to 104 char 2022-07-23 03:12:49 +00:00
RuntimeResetSystemLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmCorePerformanceLib MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime 2023-06-21 04:37:17 +00:00
SmmCorePlatformHookLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmIpmiLibSmmIpmiProtocol MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmLockBoxLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmMemoryAllocationProfileLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmPerformanceLib MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS 2023-06-21 04:37:17 +00:00
SmmReportStatusCodeLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmSmiHandlerProfileLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
TpmMeasurementLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
TraceHubDebugSysTLib MdeModulePkg: Add TraceHubDebugSysTLib library 2023-05-11 07:26:38 +00:00
UefiBootManagerLib MdeModulePkg: Optimize BmExpandPartitionDevicePath 2023-10-24 13:00:18 +00:00
UefiHiiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
UefiHiiServicesLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
UefiMemoryAllocationProfileLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
UefiSortLib MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example 2023-04-10 05:59:02 +00:00
VarCheckHiiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VarCheckLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VarCheckPcdLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VarCheckPolicyLib MdeModulePkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
VarCheckUefiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VariablePolicyHelperLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VariablePolicyLib MdeModulePkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00