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 A133E7803D0 for ; Mon, 27 Nov 2023 06:53:52 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=CmZU3IWY9GQ8Up6KkYda9zmgx2vVTipdc11Tw+GxQ8A=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20140610; t=1701068031; v=1; b=B7Zvwm11OdHyixoP/pLXBsh3NEekieLPPh8HE9rz2eutf+Q4IPHCbylubGUlUS2n1x2Of1Y+ eRBRwTDZSPKj5vS8t/R66w7ZQTfYXM0caP8bPkVx5YLx6vgrMp4Nj5zRI80Jlek3xMgc4S3U6Q+ AM0WjoqE61PevRD5Yh+rm1eI= X-Received: by 127.0.0.2 with SMTP id IvsEYY7687511xEZ7MHMhoz5; Sun, 26 Nov 2023 22:53:51 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.87642.1701068030301772057 for ; Sun, 26 Nov 2023 22:53:50 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="478836915" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208,217";a="478836915" X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2023 22:53:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="761517823" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208,217";a="761517823" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 26 Nov 2023 22:53:49 -0800 X-Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Sun, 26 Nov 2023 22:53:48 -0800 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Sun, 26 Nov 2023 22:53:48 -0800 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Sun, 26 Nov 2023 22:53:48 -0800 X-Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.41) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Sun, 26 Nov 2023 22:53:48 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OsrrT9wqxn9bSYMAaQyp2qxLC8YoY0/2ouUNeWmo5/ITkNYgR0mPK+ohZL5J5z910vB49FfybuSBGx3RKQmvuNn25Dcateik7BFIKm8v1fAfGBr44kxtt+7w1gFTH3ASIYbbM6boJixz2EC8Kk/mwJ5ISksRjENklFc6Md15gL3/8kgCUVsCSMmJQsPHM0Kgt/fsyoDQJJdIwzKK31N6nEsNs/5EQ17kIMgM0I0xfzMiDq5UABmn/RT4xRheY3hUj86SHaK8ZPACcCQbkePKONktqHuT4fX9jDXtw+OejDfOWIdARRwI9FMlb6Al+WG8xfqFQ6AfZFQrFEdeVEcODw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=X56uuJPu5dKeSaPghyKq4+JnPNKs4falxlrAXwUKIbM=; b=UNLmionlUFKWf3Nfs2ztU6f10BskgbdhNEEUcPA3xsGauxFo3ixMRxjUEBG3hO8YKNAIQocJ5VIUIIEQeCP759ZLruwKiMMFWe9m0zKDvxhvPrT0XDhPMDyRuvhs4yUBl5gQlOJ/RndGW/VwSK7m178rw7AaMN7ttgGoinGHWEY4XzkIOuSY/GjEgm6wCWkiidvFzb0nbYxaOmhV9PFF4cKrfaaKG2/TO2FvPpxoOIEk7pQXYLOQs1QjHL/nKylJkBcDL1bEc/444Qu0+9xh1BGTcniuy9Hc6uz3aUZpgOEF+V4VJWVLdREPhppRzgKJSXXjcs3I9NMOIdBA3AbQhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from CO1PR11MB5185.namprd11.prod.outlook.com (2603:10b6:303:6e::11) by DS0PR11MB7733.namprd11.prod.outlook.com (2603:10b6:8:dc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.27; Mon, 27 Nov 2023 06:53:46 +0000 X-Received: from CO1PR11MB5185.namprd11.prod.outlook.com ([fe80::131a:3b1:ff6f:b730]) by CO1PR11MB5185.namprd11.prod.outlook.com ([fe80::131a:3b1:ff6f:b730%7]) with mapi id 15.20.7025.022; Mon, 27 Nov 2023 06:53:46 +0000 From: "Zhi Jin" To: "Ni, Ray" , "devel@edk2.groups.io" , "Gao, Liming" CC: "Wang, Jian J" , "Bi, Dandan" Subject: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Thread-Topic: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Thread-Index: AQHaEq599JimthvTrUWl4GGJVrvNv7BxRZYAgByQsoA= Date: Mon, 27 Nov 2023 06:53:45 +0000 Message-ID: References: <20231109014607.573019-1-zhi.jin@intel.com> In-Reply-To: Accept-Language: en-US X-Mentions: gaoliming@byosoft.com.cn X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CO1PR11MB5185:EE_|DS0PR11MB7733:EE_ x-ms-office365-filtering-correlation-id: 161d11a9-c3ed-4170-5b57-08dbef1599f9 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: UkBMHNVj7RTOkp0tqvBulhoelWyZX09XuWpmgh/8X7+9h98/9MWKwM+uhEa6qW6AsjcE5KBdPUg8dV3wINxDnSGyxLRof8jqaJW6WWqUu/eL8et8ToJKpQ08csZKAfblknflHxZe0QKR8hmT73iWW0eHYkY1EAbOq+kPTe9I4se6FWXVIwo45TnaIKiv9pPpOTpn02trBRo6g9FFE1nr3toa2hbIvK2mMqxnA4iBSXUpV+CFPKdoyv6qG/0eg99oKjSFYmBMYXZT1m2RPQIqHUfRQqcRFBHF7056qgNR7b6Pq6WVP3YpalOtUuap5537Brb2KEmCPGPUyUe90uE/BkGcnE07Jy6uH9zrnHShbPlJ3TqINWsYBCv2sfmP+SmsijZuNaHPAQGU0DqZTH855CvtmSleWFfK/zXSKYF4krQYeLww6FhBpb5UTZNp11etm2pWg2lX7dTKgMq8KuNe5eu9zkLkSFOqXhmXn05Vgqh0tjKmW5uY0hSKOm7HvunmkV5ivtSBgp7yEqxEJje4se5mBZERWeRUvwdZ5zUHpkDRLU143nlC1B6D2++CG8eHN7cHjUunjH35S+ckbSQ/xTFcOFbFS84nnw/qnFuozT+I8u8qCEnWsj7gjoFrrfEoKBipS4aQ2ojOl24qqoAeqg== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?aKqMH4fVfP3wHSVvWLpfuCOmxu5iUHxL6e8X0JpaW2uiXxZkKWXJWKAacLwC?= =?us-ascii?Q?O2ux7fCnWmYPb9aJps8E5Rc55+mNlP2gt58rAJuNjl+xvDdVdI8+hN4CQ+4g?= =?us-ascii?Q?sBUVzt5AFXG4f+r9QmYtS9T9VMTmTotKSFfjGbFk1ikDSbyIf9+t9hjINdD1?= =?us-ascii?Q?fQLxBSRnuYW7VFs/6xt0v0Am13viUCLSEh9V2okZoFA6zwrjzGaYHbnsZgYD?= =?us-ascii?Q?fkaBN45TWfJwn5niU3sc9oHsu1BhVc/2DDFYM1Fa3ZaYVuDQK48pLoL6bHqA?= =?us-ascii?Q?CL/GrlCQHGiBzCWwv0pOhhBmPaWP+NCT+wP+jfxobV0M0fHN0dYHBSpQfKfz?= =?us-ascii?Q?z2OWJZfssHL/i06M64suBB903neLncJgLZDkkcpaqyxadl/vefCxCvljk4s+?= =?us-ascii?Q?+9uWANPw9pSe2rHYmX3s0VZjd9n2H44WMiLfuk5FUqqVSgIAACrh1SQgYOBk?= =?us-ascii?Q?pZ16Jk7LOqVu1SJBtxohDxjtHSUR+eg5YuPzNb6iQoVkclUFwCPMUtmcB4u4?= =?us-ascii?Q?zeLWEIQhkKttADeIJPxKGQu+DKhU3DH5XrMzfFDvxVylb5oRotuQy+X54ns/?= =?us-ascii?Q?+aJNXEePjFIZ0lrwj9R2+UeFlvioafa+LHux9TN/JoaIk+olA4MOqSs+RWp/?= =?us-ascii?Q?Z+fLJm9StqeAn3VFrE7hRf5m3y0P0EdxW4ZYtCrQozR9A8zsJfST9Q0EArb6?= =?us-ascii?Q?kDzx/wvmaxkZAZZGinOQPFk1R8E1fUDxLsPsPB0sS56kJERdhUhnopw0iYpR?= =?us-ascii?Q?vhTFHt+iP+1MvDTXlxQ1/RFza9OD0JfM2S5UpROnCkaTG5YtGHLNnJo782Gy?= =?us-ascii?Q?l7xEvyP9FtqJvRv5gdtslY8QCtRc4rM0dA8a589SGx7bFJAREurvAtMTZwgh?= =?us-ascii?Q?RpGwzPv2QJAmk+i0EAfoji/rNcdF1EDlzlR3Kie5LzTdW51S3tSlMQSM0QkT?= =?us-ascii?Q?SAQ5fFxnHlL6PbggZIGd3nwDEwjE6MBPKZ50w1mgIXBRcQlKydviHJ+yyiOD?= =?us-ascii?Q?ZIk81BHblu1IVgJeWIpYcVvVEBn6JM1ljG5xsF/hqwEZMwsXXkAp/xdJ3+q6?= =?us-ascii?Q?tZUuKoJjhZDtnVnp0D4aX6epZsakYH5FNAtp+rh34T4B9XTH+njk6IPTI3Hh?= =?us-ascii?Q?0MXnUf2wIH2Ke0srff8Ghzqr5s91RINqLkOYJIvtvR9znzco69YhK7i8KJXj?= =?us-ascii?Q?3RBPRmmM8kddawmI3K+hje7K5zGhB8n50shCkFBb8laoRkhdKo3LPuYrIrq+?= =?us-ascii?Q?loI0WQIK6au1gGAhrnX9mJKRvkYQAWksUn+4l96C+ItoMooN6vzVMI9X3Pum?= =?us-ascii?Q?z9n04oQ1STOXZ0bGE8adiZ2YiV+Aw6QD3h5Dl18sH9yrUM+hq5NSwwLwHeHU?= =?us-ascii?Q?lK6cuXXzxpmk5UtudgT8X3PcjVWp2FDja4XAMThutc1XRg8/Ab8xDjC4JIJS?= =?us-ascii?Q?0nup5kAv+0YyuMwwT9y0lD1B9jPaOrBsvRJVxiHw6MLfWYlietq43x3JRfaX?= =?us-ascii?Q?MqEy84BL/abSPdyV4UfKSnk30qLZHmiF1KTcii9MHlON78p9FJhusaseFmbF?= =?us-ascii?Q?VhBF017lJjHLkyFcIE4=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB5185.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 161d11a9-c3ed-4170-5b57-08dbef1599f9 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2023 06:53:45.9406 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: mQYNMhbmpAPMHd7tVQBhulMFDq+MsGWsiQUtPxLTENufD4Tfs2ikhBbnoAq07vsm5OV1WypX/pX7/GBSNoVz/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB7733 X-OriginatorOrg: intel.com 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: mDEzIVJrmbaohfav5EdPBNOQx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_CO1PR11MB51858BF942AF0B1B1328F4FDF7BDACO1PR11MB5185namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=B7Zvwm11; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 --_000_CO1PR11MB51858BF942AF0B1B1328F4FDF7BDACO1PR11MB5185namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi @Liming Gao, Would you please help to review this patch? Thanks! BRs Zhi Jin From: Ni, Ray Sent: Thursday, November 09, 2023 10:36 AM To: Jin, Zhi ; devel@edk2.groups.io Cc: Wang, Jian J ; Gao, Liming ; Bi, Dandan Subject: Re: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocol= Interfaces Reviewed-by: Ray Ni > Thanks, Ray ________________________________ 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 CoreInstallMultipleProtocolInte= rfaces 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/Ha= nd/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 =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->Pr= otocols; 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. @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; 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; } // -- 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 (#111726): https://edk2.groups.io/g/devel/message/111726 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_CO1PR11MB51858BF942AF0B1B1328F4FDF7BDACO1PR11MB5185namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi @Liming Gao,

 

        &nbs= p;     Would you please help to review this patch? Than= ks!

 

BRs

Zhi Jin

 

From: Ni, Ray <ray.ni@intel.com>
Sent: Thursday, November 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 <gaol= iming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com>
Subject: Re: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleP= rotocolInterfaces

 

Reviewed-by: Ray Ni <ray.ni@intel.com>

 

Thanks,

Ray


From: Jin, Zhi <z= hi.jin@intel.com>
Sent: Thursday, November 9, 2023 9:46 AM
To: devel@edk2.groups.io= <devel@edk2.groups.io> Cc: Jin, Zhi <zhi.jin@intel.= com>; Wang, Jian J <jian= .j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com>; Ni= , Ray <ray.ni@intel.com>
Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProto= colInterfaces

 

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@in= tel.com>
Cc: Liming Gao <gaoliming@by= osoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.co= m>
Cc: Ray Ni <ray.ni@intel.com>=
Signed-off-by: Zhi Jin <zhi.jin@int= el.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/Ha= nd/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       &n= bsp;    The given device path
+
+  @retval TRUE         &= nbsp;        The device path is already = installed
+  @retval FALSE         =         The device path is not installed=
+
+**/
+BOOLEAN
+IsDevicePathInstalled (
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath
+  )
+{
+  UINTN          &n= bsp;          SourceSize;
+  UINTN          &n= bsp;          Size;
+  BOOLEAN          =          Found;
+  LIST_ENTRY         &nb= sp;      *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 (&gEfiDevicePathProtocolGui= d, FALSE);
+  if (ProtEntry =3D=3D NULL) {
+    goto Done;
+  }
+
+  for (Link =3D ProtEntry->Protocols.ForwardLink; Link !=3D &P= rotEntry->Protocols; Link =3D Link->ForwardLink) {
+    //
+    // Loop on the DevicePathProtocol interfaces
+    //
+    Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROT= OCOL_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 (De= vicePath, Prot->Interface, 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 pro= tocol.
 
@@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces (
   EFI_TPL         &= nbsp;         OldTpl;
   UINTN         &nb= sp;           Index;
   EFI_HANDLE        &nbs= p;       OldHandle;
-  EFI_HANDLE         &nb= sp;      DeviceHandle;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
 
   if (Handle =3D=3D NULL) {
     return EFI_INVALID_PARAMETER;
@@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces (
     //
     // Make sure you are installing on top a device pa= th that has already been added.
     //
-    if (CompareGuid (Protocol, &gEfiDevicePathProtocolG= uid)) {
-      DeviceHandle =3D NULL;
-      DevicePath   =3D Interface;
-      Status       = =3D CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath,= &DeviceHandle);
-      if (!EFI_ERROR (Status) && (DeviceH= andle !=3D NULL) && IsDevicePathEnd (DevicePath)) {
-        Status =3D EFI_ALREADY_STARTED;=
-        continue;
-      }
+    if (CompareGuid (Protocol, &gEfiDevicePathProtocolG= uid) &&
+        IsDevicePathInstalled (Interfac= e)) {
+      Status =3D EFI_ALREADY_STARTED;
+      continue;
     }
 
     //
--
2.39.2

_._,_._,_

Groups.io Links:

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

View/Reply Online (#111726) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_CO1PR11MB51858BF942AF0B1B1328F4FDF7BDACO1PR11MB5185namp_--