From: "Zhi Jin" <zhi.jin@intel.com>
To: devel@edk2.groups.io
Cc: Zhi Jin <zhi.jin@intel.com>, Jian J Wang <jian.j.wang@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Dandan Bi <dandan.bi@intel.com>, Ray Ni <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces
Date: Thu, 9 Nov 2023 09:46:07 +0800 [thread overview]
Message-ID: <20231109014607.573019-1-zhi.jin@intel.com> (raw)
CoreLocateDevicePath is used in CoreInstallMultipleProtocolInterfaces to
check if a Device Path Protocol instance with the same device path is
alreay installed.
CoreLocateDevicePath is a generic API, and would introduce some
unnecessary overhead for such usage.
The optimization is:
1. Implement IsDevicePathInstalled to loop all the Device Path
Protocols installed and check if any of them matchs the given device
path.
2. Replace CoreLocateDevicePath with IsDevicePathInstalled in
CoreInstallMultipleProtocolInterfaces.
This optimization could save several seconds in PCI enumeration on a
system with many PCI devices.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhi Jin <zhi.jin@intel.com>
---
MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++----
1 file changed, 64 insertions(+), 10 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c
index bd6c57843e..a08cf19bfd 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c
@@ -197,6 +197,66 @@ CoreFindProtocolInterface (
return Prot;
}
+/**
+ Check if the given device path is already installed
+
+ @param DevicePath The given device path
+
+ @retval TRUE The device path is already installed
+ @retval FALSE The device path is not installed
+
+**/
+BOOLEAN
+IsDevicePathInstalled (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ UINTN SourceSize;
+ UINTN Size;
+ BOOLEAN Found;
+ LIST_ENTRY *Link;
+ PROTOCOL_ENTRY *ProtEntry;
+ PROTOCOL_INTERFACE *Prot;
+
+ if (DevicePath == NULL) {
+ return FALSE;
+ }
+
+ Found = FALSE;
+ SourceSize = GetDevicePathSize (DevicePath);
+ ASSERT (SourceSize >= END_DEVICE_PATH_LENGTH);
+
+ CoreAcquireProtocolLock ();
+ //
+ // Look up the protocol entry
+ //
+ ProtEntry = CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE);
+ if (ProtEntry == NULL) {
+ goto Done;
+ }
+
+ for (Link = ProtEntry->Protocols.ForwardLink; Link != &ProtEntry->Protocols; Link = Link->ForwardLink) {
+ //
+ // Loop on the DevicePathProtocol interfaces
+ //
+ Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
+
+ //
+ // Check if DevicePath is same as this interface
+ //
+ Size = GetDevicePathSize (Prot->Interface);
+ ASSERT (Size >= END_DEVICE_PATH_LENGTH);
+ if ((Size == SourceSize) && (CompareMem (DevicePath, Prot->Interface, Size - END_DEVICE_PATH_LENGTH) == 0)) {
+ Found = TRUE;
+ break;
+ }
+ }
+
+Done:
+ CoreReleaseProtocolLock ();
+ return Found;
+}
+
/**
Removes an event from a register protocol notify list on a protocol.
@@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces (
EFI_TPL OldTpl;
UINTN Index;
EFI_HANDLE OldHandle;
- EFI_HANDLE DeviceHandle;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
if (Handle == NULL) {
return EFI_INVALID_PARAMETER;
@@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces (
//
// Make sure you are installing on top a device path that has already been added.
//
- if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) {
- DeviceHandle = NULL;
- DevicePath = Interface;
- Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle);
- if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (DevicePath)) {
- Status = EFI_ALREADY_STARTED;
- continue;
- }
+ if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) &&
+ IsDevicePathInstalled (Interface)) {
+ Status = EFI_ALREADY_STARTED;
+ continue;
}
//
--
2.39.2
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110945): https://edk2.groups.io/g/devel/message/110945
Mute This Topic: https://groups.io/mt/102478834/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next reply other threads:[~2023-11-09 2:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 1:46 Zhi Jin [this message]
2023-11-09 2:36 ` [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Ni, Ray
2023-11-27 6:53 ` Zhi Jin
2023-11-28 15:16 ` 回复: " gaoliming via groups.io
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231109014607.573019-1-zhi.jin@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox