From nobody Thu May 9 03:45:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111813+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111813+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1701184594; cv=none; d=zohomail.com; s=zohoarc; b=Q24lahTi5x3ne17s5tckk6nk+us3FDKtofrpodQau+Pbm9PWGDp0Ve8R0vR5l2MzPlPp+UUNEea7xE8Jguoh+eY3RjXxB54yQ7twFupfIDhBUQ139a4+DPsqR2ete4FXru20pcxd3KlBDam/0W0FC6IGIzBVEdczbUe1JK0ocyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701184594; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=KjonuT8+2aUtUaTigX1qyONd+0jxRx9Qk5aYrLih+Wo=; b=g4dgVQj3rHb2IcQdouLSd7vRYcDLiilJ4mYzz5eoZok68UqSQrMTusAixQj567dGABxNnCgRbqMa+BEKlwLvvTSWkA4DgMYXEbZ7bq+I5I8TKbChSAFwwX63N2D2QUc6UJ86F7AOlGqkEc44Gat+hdDO3GarCJOXkNQUEuGEKy0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111813+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170118459408338.991819087393765; Tue, 28 Nov 2023 07:16:34 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qtAQUH3xNCxgqwx0cwMV92OHsWK39huCjF4Wi+VuY0o=; c=relaxed/simple; d=groups.io; h=From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Thread-Index:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Language; s=20140610; t=1701184593; v=1; b=G3wvsSf4FK9XMbyJwZsU3ZFy3MBXTIvGHr3HaE/1SEVR2QxSw0y02xL13hjJKYCWNM6NdMgD hxSyqud0A0XnDE9zQGyxGprBCe1ClWEqDVf7hmuvNM6ddNAa373KwPNuAzq1zOLWmsuOZRNDojn zbuEVEKUuEOet2ILNLpi8C/w= X-Received: by 127.0.0.2 with SMTP id BSGMYY1788612xhWOyml6yn4; Tue, 28 Nov 2023 07:16:33 -0800 X-Received: from zrleap.intel-email.com (zrleap.intel-email.com [114.80.218.36]) by mx.groups.io with SMTP id smtpd.web10.34956.1701184592236774267 for ; Tue, 28 Nov 2023 07:16:32 -0800 X-Received: from zrleap.intel-email.com (localhost [127.0.0.1]) by zrleap.intel-email.com (Postfix) with ESMTP id 5A48BA32E033 for ; Tue, 28 Nov 2023 23:16:29 +0800 (CST) X-Received: from localhost (localhost [127.0.0.1]) by zrleap.intel-email.com (Postfix) with ESMTP id 427A9A32E01D for ; Tue, 28 Nov 2023 23:16:29 +0800 (CST) X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by zrleap.intel-email.com (Postfix) with SMTP id 61B11A32E035 for ; Tue, 28 Nov 2023 23:16:26 +0800 (CST) X-Received: from DESKTOPS6D0PVI ([114.93.194.54]) (envelope-sender ) by 192.168.6.13 with ESMTP(SSL) for ; Tue, 28 Nov 2023 23:16:24 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 114.93.194.54 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming via groups.io" To: , , "'Ni, Ray'" Cc: "'Wang, Jian J'" , "'Bi, Dandan'" References: <20231109014607.573019-1-zhi.jin@intel.com> In-Reply-To: Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIIDEvMV0gTWRlTW9kdWxlUGtnOiBPcHRpbWl6ZSBDb3JlSW5zdGFsbE11bHRpcGxlUHJvdG9jb2xJbnRlcmZhY2Vz?= Date: Tue, 28 Nov 2023 23:16:25 +0800 Message-ID: <027001da220d$dadd8200$90988600$@byosoft.com.cn> MIME-Version: 1.0 Thread-Index: AQEZwOnqEFB2f6SGU/ztyWmi+AQKEwKRt83AAbNaEMGx7nEjIA== 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,gaoliming@byosoft.com.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: pvJDFYCzpHxQQB1mG4OCe8PHx1787277AA= Content-Type: multipart/alternative; boundary="----=_NextPart_000_0271_01DA2250.E9033300" Content-Language: zh-cn X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701184594988000001 ------=_NextPart_000_0271_01DA2250.E9033300 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Jin: This change is good to me. Reviewed-by: Liming Gao =20 Thanks Liming =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io = =E4=BB=A3=E8=A1=A8 Zhi Jin =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2023=E5=B9=B411=E6=9C=8827=E6=97=A5 1= 4:54 =E6=94=B6=E4=BB=B6=E4=BA=BA: Ni, Ray ; devel@edk2.groups.= io; Gao, Liming =E6=8A=84=E9=80=81: Wang, Jian J ; Bi, Dandan =E4=B8=BB=E9=A2=98: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces =20 Hi @Liming Gao, =20 Would you please help to review this patch? Thanks! =20 BRs Zhi Jin =20 From: Ni, Ray >=20 Sent: Thursday, November 09, 2023 10:36 AM To: Jin, Zhi >; devel@edk2.groups.io =20 Cc: Wang, Jian J >; Gao, Liming >; Bi, Dandan > Subject: Re: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces =20 Reviewed-by: Ray Ni > =20 Thanks, Ray _____ =20 From: Jin, Zhi > Sent: Thursday, November 9, 2023 9:46 AM To: devel@edk2.groups.io > Cc: Jin, Zhi >; Wang, Jian J >; Gao, Liming >; Bi, Dandan >; Ni, Ray > Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces=20 =20 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; } =20 +/** + 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 =3D=3D NULL) { + return FALSE; + } + + Found =3D FALSE; + SourceSize =3D GetDevicePathSize (DevicePath); + ASSERT (SourceSize >=3D END_DEVICE_PATH_LENGTH); + + CoreAcquireProtocolLock (); + // + // Look up the protocol entry + // + ProtEntry =3D CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE); + if (ProtEntry =3D=3D NULL) { + goto Done; + } + + for (Link =3D ProtEntry->Protocols.ForwardLink; Link !=3D &ProtEntry->Protocols; Link =3D Link->ForwardLink) { + // + // Loop on the DevicePathProtocol interfaces + // + Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + + // + // Check if DevicePath is same as this interface + // + Size =3D GetDevicePathSize (Prot->Interface); + ASSERT (Size >=3D END_DEVICE_PATH_LENGTH); + if ((Size =3D=3D SourceSize) && (CompareMem (DevicePath, Prot->Interfa= ce, Size - END_DEVICE_PATH_LENGTH) =3D=3D 0)) { + Found =3D TRUE; + break; + } + } + +Done: + CoreReleaseProtocolLock (); + return Found; +} + /** Removes an event from a register protocol notify list on a protocol. =20 @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; =20 if (Handle =3D=3D 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 =3D NULL; - DevicePath =3D Interface; - Status =3D CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle); - if (!EFI_ERROR (Status) && (DeviceHandle !=3D NULL) && IsDevicePathE= nd (DevicePath)) { - Status =3D EFI_ALREADY_STARTED; - continue; - } + if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) && + IsDevicePathInstalled (Interface)) { + Status =3D EFI_ALREADY_STARTED; + continue; } =20 // --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111813): https://edk2.groups.io/g/devel/message/111813 Mute This Topic: https://groups.io/mt/102851994/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- ------=_NextPart_000_0271_01DA2250.E9033300 Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: quoted-printable

Jin:

 This change is= good to me. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn><= /o:p>

 

Thank= s

Liming

=B7=A2=BC= =FE=C8=CB: devel@edk2.groups.io <devel@edk2.groups.io> =B4=FA=B1=ED Zhi Jin
=B7=A2=CB=CD=CA=B1=BC=E4: 2023=C4=EA11=D4= =C227=C8=D5 14:54
=CA=D5=BC=FE=C8=CB: Ni, R= ay <ray.ni@intel.com>; devel@edk2.groups.io; Gao, Liming <gaolimin= g@byosoft.com.cn>
=B3=AD=CB=CD: Wang, Jian J <jian.j.wang@intel.com>; Bi, Danda= n <dandan.bi@intel.com>
=D6=F7=CC=E2:= Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: O= ptimize CoreInstallMultipleProtocolInterfaces

<= /div>

 =

Hi @Liming Gao,

 =

   =            Would you plea= se help to review this patch? Thanks!

 

BRs

Zhi Jin

 

From: Ni, Ray <ray.ni@intel.com>
Sent: Thursday, N= ovember 09, 2023 10:36 AM
To: Jin, Zhi <zhi.jin@intel.com>; devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming <= ;gaoliming@byosoft.com.cn&g= t;; Bi, Dandan <dandan.bi@intel.c= om>
Subject: Re: [PATCH 1/1] MdeModulePkg: Optimize CoreIn= stallMultipleProtocolInterfaces

 

Reviewed-by: Ray Ni <ray.n= i@intel.com>

=  

Thanks,

Ray


<= b>From: Jin, Zhi <zhi.jin@intel.com>
Sent: Thursday, November 9, 2023 9:46 = AM
To: devel@edk2.groups.= io <devel@edk2.groups.io= >
Cc: Jin, Zhi <zhi.ji= n@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com>; Ni, Ray <<= a href=3D"mailto:ray.ni@intel.com">ray.ni@intel.com>
Subject:<= /b> [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterface= s

 

CoreLocat= eDevicePath is used in CoreInstallMultipleProtocolInterfaces to
check if= a Device Path Protocol instance with the same device path is
alreay ins= talled.
CoreLocateDevicePath is a generic API, and would introduce some<= br>unnecessary overhead for such usage.

The optimization is:
1. I= mplement IsDevicePathInstalled to loop all the Device Path
   = Protocols installed and check if any of them matchs the given device
&nb= sp;  path.
2. Replace CoreLocateDevicePath with IsDevicePathInstall= ed in
   CoreInstallMultipleProtocolInterfaces.

This op= timization could save several seconds in PCI enumeration on a
system wit= h many PCI devices.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: D= andan 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/Handl= e.c | 74 +++++++++++++++++++++++++----
 1 file changed, 64 insertio= ns(+), 10 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Hand/Handl= e.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c
index bd6c57843e..a08cf19bfd 1= 00644
--- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
+++ b/MdeModulePkg/Co= re/Dxe/Hand/Handle.c
@@ -197,6 +197,66 @@ CoreFindProtocolInterface (   return Prot;
 }
 
+/**
+  Check if= the given device path is already installed
+
+  @param  De= vicePath            = The given device path
+
+  @retval TRUE    &= nbsp;           &nbs= p; The device path is already installed
+  @retval FALSE  = ;            &n= bsp;  The device path is not installed
+
+**/
+BOOLEAN
+Is= DevicePathInstalled (
+  IN EFI_DEVICE_PATH_PROTOCOL  *DeviceP= ath
+  )
+{
+  UINTN      =             &nb= sp;  SourceSize;
+  UINTN      &= nbsp;           &nbs= p;  Size;
+  BOOLEAN       =             Found;+  LIST_ENTRY         &= nbsp;      *Link;
+  PROTOCOL_ENTRY &= nbsp;          *ProtEntry;
= +  PROTOCOL_INTERFACE        *Prot;=
+
+  if (DevicePath =3D=3D NULL) {
+    retur= n FALSE;
+  }
+
+  Found     &n= bsp;   =3D FALSE;
+  SourceSize    =3D Get= DevicePathSize (DevicePath);
+  ASSERT (SourceSize >=3D END_DEVI= CE_PATH_LENGTH);
+
+  CoreAcquireProtocolLock ();
+  //<= br>+  // Look up the protocol entry
+  //
+  ProtEntry= =3D CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE);
+&n= bsp; if (ProtEntry =3D=3D NULL) {
+    goto Done;
+&nb= sp; }
+
+  for (Link =3D ProtEntry->Protocols.ForwardLink; Li= nk !=3D &ProtEntry->Protocols; Link =3D Link->ForwardLink) {
+=     //
+    // Loop on the DevicePathProto= col interfaces
+    //
+    Prot =3D CR= (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
+=
+    //
+    // Check if DevicePath is= same as this interface
+    //
+    Si= ze =3D GetDevicePathSize (Prot->Interface);
+    ASSER= T (Size >=3D END_DEVICE_PATH_LENGTH);
+    if ((Size = =3D=3D SourceSize) && (CompareMem (DevicePath, Prot->Interface, = Size - END_DEVICE_PATH_LENGTH) =3D=3D 0)) {
+    &nb= sp; Found =3D TRUE;
+      break;
+ &nb= sp;  }
+  }
+
+Done:
+  CoreReleaseProtocolLock = ();
+  return Found;
+}
+
 /**
   Remove= s an event from a register protocol notify list on a protocol.
 @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces (
  = ; EFI_TPL           =         OldTpl;
   UINTN&nb= sp;            =         Index;
   EFI_HANDL= E            &n= bsp;   OldHandle;
-  EFI_HANDLE    &n= bsp;           DeviceHand= le;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
 
&nb= sp;  if (Handle =3D=3D NULL) {
     return EFI_= INVALID_PARAMETER;
@@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInte= rfaces (
     //
     // Make= sure you are installing on top a device path that has already been added.<= br>     //
-    if (CompareGuid (Prot= ocol, &gEfiDevicePathProtocolGuid)) {
-     = ; DeviceHandle =3D NULL;
-      DevicePath = ;  =3D Interface;
-      Status  = ;     =3D CoreLocateDevicePath (&gEfiDevicePathProt= ocolGuid, &DevicePath, &DeviceHandle);
-    =   if (!EFI_ERROR (Status) && (DeviceHandle !=3D NULL) &&am= p; IsDevicePathEnd (DevicePath)) {
-      =   Status =3D EFI_ALREADY_STARTED;
-     &n= bsp;  continue;
-      }
+  &= nbsp; if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) &&= ;
+        IsDevicePathInstalled (Int= erface)) {
+      Status =3D EFI_ALREADY_STARTE= D;
+      continue;
    = }
 
     //
--
2.39.2

<= /body>
_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#111813) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [importer@patchew.org]

_._,_._,_
------=_NextPart_000_0271_01DA2250.E9033300--