From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 2AC407803CD for ; Thu, 9 Nov 2023 02:52:02 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=irRkIVMyTOnZukMeALm31IY7T7PUNHYo34mQDACvnNQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1699498320; v=1; b=D0y8M/PtB+ndIQMsfX/8F7B+BwOMUnpcLfPzXkGmuA5iA5yD681o0ZozcCGMIX38x5nnfJrR iHInAulPm01gSMedFj9I5vVMqKIHtVImZJ4e4o4YrqCndxltlpNX4jYTs9OOgcrDdwCd5ErkC6+ Gr2EkQXCO+mYTSmNY7DhWsy4= X-Received: by 127.0.0.2 with SMTP id TEyXYY7687511xrvev6BxShv; Wed, 08 Nov 2023 18:52:00 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.112364.1699494353538171993 for ; Wed, 08 Nov 2023 17:45:54 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="370099522" X-IronPort-AV: E=Sophos;i="6.03,288,1694761200"; d="scan'208";a="370099522" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 17:45:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="936689781" X-IronPort-AV: E=Sophos;i="6.03,288,1694761200"; d="scan'208";a="936689781" X-Received: from zjin7-devs.sh.intel.com ([10.239.154.113]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 17:45:50 -0800 From: "Zhi Jin" To: devel@edk2.groups.io Cc: Zhi Jin , Jian J Wang , Liming Gao , Dandan Bi , Ray Ni Subject: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Date: Thu, 9 Nov 2023 09:46:07 +0800 Message-Id: <20231109014607.573019-1-zhi.jin@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhi.jin@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: v2WD678mYaRFDRSclH7OTSQvx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="D0y8M/Pt"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 Cc: Liming Gao Cc: Dandan Bi Cc: Ray Ni Signed-off-by: Zhi Jin --- 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] -=-=-=-=-=-=-=-=-=-=-=-