* [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls
[not found] <cover.1684880087.git.nolan.hergert@intel.com>
@ 2023-05-24 18:20 ` nolan.hergert
0 siblings, 0 replies; 3+ messages in thread
From: nolan.hergert @ 2023-05-24 18:20 UTC (permalink / raw)
To: devel
During LoadImage, there 6-7 of the same call to CoreLocateDevicePath
and can be cached during a particular call to LoadImage. For
implementations with significant numbers of calls to LoadImage (>250),
this change will improve the boot time by >10ms.
Signed-off-by: Nolan Hergert <nolan.hergert@intel.com>
---
MdeModulePkg/Core/Dxe/Hand/Locate.c | 21 ++++++++++++++++-----
MdeModulePkg/Core/Dxe/Image/Image.c | 15 +++++++++++++--
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c
index a29010a54565..52b7b7a7cd8c 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Locate.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c
@@ -14,6 +14,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
UINTN mEfiLocateHandleRequest = 0;
+extern EFI_DEVICE_PATH_PROTOCOL *gFilePathCache;
+extern EFI_HANDLE gDeviceHandleCache;
+extern EFI_DEVICE_PATH_PROTOCOL *gOutgoingDevicePathCache;
+
//
// Internal prototypes
//
@@ -467,10 +471,21 @@ CoreLocateDevicePath (
return EFI_INVALID_PARAMETER;
}
- if ((DevicePath == NULL) || (*DevicePath == NULL)) {
+ if ((DevicePath == NULL) || (*DevicePath == NULL) || (Device == NULL)) {
return EFI_INVALID_PARAMETER;
}
+ if (gFilePathCache != NULL) {
+ Size = GetDevicePathSize (gFilePathCache) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ SourceSize = GetDevicePathSize (*DevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ if ((Size == SourceSize) && (CompareMem (gFilePathCache, *DevicePath, (UINTN)Size) == 0)) {
+ *Device = gDeviceHandleCache;
+ *DevicePath = gOutgoingDevicePathCache;
+ return EFI_SUCCESS;
+ }
+ }
+
Handles = NULL;
BestDevice = NULL;
SourcePath = *DevicePath;
@@ -541,10 +556,6 @@ CoreLocateDevicePath (
return EFI_NOT_FOUND;
}
- if (Device == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
*Device = BestDevice;
//
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 9dbfb2a1fad2..e76f788a4d89 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -12,7 +12,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Module Globals
//
-LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
+LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
+EFI_DEVICE_PATH_PROTOCOL *gFilePathCache = NULL;
+EFI_DEVICE_PATH_PROTOCOL *gOutgoingDevicePathCache = NULL;
+EFI_HANDLE gDeviceHandleCache = NULL;
typedef struct {
LIST_ENTRY Link;
@@ -1219,7 +1222,10 @@ CoreLoadImageCommon (
Node = NULL;
Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);
if (!EFI_ERROR (Status)) {
- ImageIsFromFv = TRUE;
+ ImageIsFromFv = TRUE;
+ gFilePathCache = FilePath;
+ gOutgoingDevicePathCache = HandleFilePath;
+ gDeviceHandleCache = DeviceHandle;
} else {
HandleFilePath = FilePath;
Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
@@ -1497,6 +1503,11 @@ Done:
Image->LoadImageStatus = Status;
}
+ // Clear cache
+ gFilePathCache = NULL;
+ gOutgoingDevicePathCache = NULL;
+ gDeviceHandleCache = NULL;
+
return Status;
}
--
2.38.1.windows.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls
@ 2023-05-24 19:07 Nolan Hergert
0 siblings, 0 replies; 3+ messages in thread
From: Nolan Hergert @ 2023-05-24 19:07 UTC (permalink / raw)
To: devel; +Cc: Dandan Bi, Liming Gao
During LoadImage, there 6-7 of the same call to CoreLocateDevicePath
and can be cached during a particular call to LoadImage. For
implementations with significant numbers of calls to LoadImage (>250),
this change will improve the boot time by >10ms.
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Nolan Hergert <nolan.hergert@intel.com>
---
MdeModulePkg/Core/Dxe/Hand/Locate.c | 21 ++++++++++++++++-----
MdeModulePkg/Core/Dxe/Image/Image.c | 15 +++++++++++++--
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c
index a29010a54565..52b7b7a7cd8c 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Locate.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c
@@ -14,6 +14,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
UINTN mEfiLocateHandleRequest = 0;
+extern EFI_DEVICE_PATH_PROTOCOL *gFilePathCache;
+extern EFI_HANDLE gDeviceHandleCache;
+extern EFI_DEVICE_PATH_PROTOCOL *gOutgoingDevicePathCache;
+
//
// Internal prototypes
//
@@ -467,10 +471,21 @@ CoreLocateDevicePath (
return EFI_INVALID_PARAMETER;
}
- if ((DevicePath == NULL) || (*DevicePath == NULL)) {
+ if ((DevicePath == NULL) || (*DevicePath == NULL) || (Device == NULL)) {
return EFI_INVALID_PARAMETER;
}
+ if (gFilePathCache != NULL) {
+ Size = GetDevicePathSize (gFilePathCache) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ SourceSize = GetDevicePathSize (*DevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ if ((Size == SourceSize) && (CompareMem (gFilePathCache, *DevicePath, (UINTN)Size) == 0)) {
+ *Device = gDeviceHandleCache;
+ *DevicePath = gOutgoingDevicePathCache;
+ return EFI_SUCCESS;
+ }
+ }
+
Handles = NULL;
BestDevice = NULL;
SourcePath = *DevicePath;
@@ -541,10 +556,6 @@ CoreLocateDevicePath (
return EFI_NOT_FOUND;
}
- if (Device == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
*Device = BestDevice;
//
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 9dbfb2a1fad2..e76f788a4d89 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -12,7 +12,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Module Globals
//
-LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
+LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
+EFI_DEVICE_PATH_PROTOCOL *gFilePathCache = NULL;
+EFI_DEVICE_PATH_PROTOCOL *gOutgoingDevicePathCache = NULL;
+EFI_HANDLE gDeviceHandleCache = NULL;
typedef struct {
LIST_ENTRY Link;
@@ -1219,7 +1222,10 @@ CoreLoadImageCommon (
Node = NULL;
Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);
if (!EFI_ERROR (Status)) {
- ImageIsFromFv = TRUE;
+ ImageIsFromFv = TRUE;
+ gFilePathCache = FilePath;
+ gOutgoingDevicePathCache = HandleFilePath;
+ gDeviceHandleCache = DeviceHandle;
} else {
HandleFilePath = FilePath;
Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
@@ -1497,6 +1503,11 @@ Done:
Image->LoadImageStatus = Status;
}
+ // Clear cache
+ gFilePathCache = NULL;
+ gOutgoingDevicePathCache = NULL;
+ gDeviceHandleCache = NULL;
+
return Status;
}
--
2.38.1.windows.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls
@ 2023-05-24 0:08 Hergert, Nolan
0 siblings, 0 replies; 3+ messages in thread
From: Hergert, Nolan @ 2023-05-24 0:08 UTC (permalink / raw)
To: devel@edk2.groups.io
[-- Attachment #1: Type: text/plain, Size: 4001 bytes --]
>From 4282ca25cde475a4ec2b81c5e878414a5829f88b Mon Sep 17 00:00:00 2001
Message-Id: <4282ca25cde475a4ec2b81c5e878414a5829f88b.1684880087.git.nolan.hergert@intel.com>
In-Reply-To: <cover.1684880087.git.nolan.hergert@intel.com>
References: <cover.1684880087.git.nolan.hergert@intel.com>
From: Nolan Hergert <nolan.hergert@intel.com>
Date: Fri, 19 May 2023 14:58:00 -0700
Subject: [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls
During LoadImage, there 6-7 of the same call to CoreLocateDevicePath
and can be cached during a particular call to LoadImage. For
implementations with significant numbers of calls to LoadImage (>250),
this change will improve the boot time by >10ms.
Signed-off-by: Nolan Hergert <nolan.hergert@intel.com>
---
MdeModulePkg/Core/Dxe/Hand/Locate.c | 21 ++++++++++++++++-----
MdeModulePkg/Core/Dxe/Image/Image.c | 15 +++++++++++++--
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c
index a29010a54565..52b7b7a7cd8c 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Locate.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c
@@ -14,6 +14,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
UINTN mEfiLocateHandleRequest = 0;
+extern EFI_DEVICE_PATH_PROTOCOL *gFilePathCache;
+extern EFI_HANDLE gDeviceHandleCache;
+extern EFI_DEVICE_PATH_PROTOCOL *gOutgoingDevicePathCache;
+
//
// Internal prototypes
//
@@ -467,10 +471,21 @@ CoreLocateDevicePath (
return EFI_INVALID_PARAMETER;
}
- if ((DevicePath == NULL) || (*DevicePath == NULL)) {
+ if ((DevicePath == NULL) || (*DevicePath == NULL) || (Device == NULL)) {
return EFI_INVALID_PARAMETER;
}
+ if (gFilePathCache != NULL) {
+ Size = GetDevicePathSize (gFilePathCache) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ SourceSize = GetDevicePathSize (*DevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ if ((Size == SourceSize) && (CompareMem (gFilePathCache, *DevicePath, (UINTN)Size) == 0)) {
+ *Device = gDeviceHandleCache;
+ *DevicePath = gOutgoingDevicePathCache;
+ return EFI_SUCCESS;
+ }
+ }
+
Handles = NULL;
BestDevice = NULL;
SourcePath = *DevicePath;
@@ -541,10 +556,6 @@ CoreLocateDevicePath (
return EFI_NOT_FOUND;
}
- if (Device == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
*Device = BestDevice;
//
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 9dbfb2a1fad2..e76f788a4d89 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -12,7 +12,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Module Globals
//
-LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
+LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
+EFI_DEVICE_PATH_PROTOCOL *gFilePathCache = NULL;
+EFI_DEVICE_PATH_PROTOCOL *gOutgoingDevicePathCache = NULL;
+EFI_HANDLE gDeviceHandleCache = NULL;
typedef struct {
LIST_ENTRY Link;
@@ -1219,7 +1222,10 @@ CoreLoadImageCommon (
Node = NULL;
Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);
if (!EFI_ERROR (Status)) {
- ImageIsFromFv = TRUE;
+ ImageIsFromFv = TRUE;
+ gFilePathCache = FilePath;
+ gOutgoingDevicePathCache = HandleFilePath;
+ gDeviceHandleCache = DeviceHandle;
} else {
HandleFilePath = FilePath;
Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
@@ -1497,6 +1503,11 @@ Done:
Image->LoadImageStatus = Status;
}
+ // Clear cache
+ gFilePathCache = NULL;
+ gOutgoingDevicePathCache = NULL;
+ gDeviceHandleCache = NULL;
+
return Status;
}
--
2.38.1.windows.1
[-- Attachment #2: Type: text/html, Size: 9280 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-24 19:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1684880087.git.nolan.hergert@intel.com>
2023-05-24 18:20 ` [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls nolan.hergert
2023-05-24 19:07 Nolan Hergert
-- strict thread matches above, loose matches on Subject: below --
2023-05-24 0:08 Hergert, Nolan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox