From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.2742.1684955274962054956 for ; Wed, 24 May 2023 12:07:55 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=PZmV7AO4; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: nolan.hergert@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684955274; x=1716491274; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=TveV6eeRgpauZ2W5kBU1K7qiO9R9JLFnNfp653Y6zwU=; b=PZmV7AO44oP9z6g4vDrC5BowNErSeKgALvEpbkhEGTsGuW5q2UulY/BX ZvOVe3gssAOWHF4OY65Ds7KgUatJVpK58LEefiP9Pf5GZIhhuS4h8dW6p BxFfuEX9EhMHIEEjsnjgn9HdDAYDVjtUFWtMi+2REEK0E7CHI/SQ9WIy1 gUnxBP4K0kiQ1CgRMzO7DjKk09O4LDxTx2T1irgyb3x7sk1hmbYzUKdD9 54IuHiv4/f0jBDqvg55cP0IPVkkskDY+J5v9msmdhp8Pbi6b6EdnHrRaY 8ev+6KybrIsBqg+fnZy8xwQfGMU6iQo14jTcnoSDi43eY8+hZh8X9yfSG w==; X-IronPort-AV: E=McAfee;i="6600,9927,10720"; a="352510254" X-IronPort-AV: E=Sophos;i="6.00,190,1681196400"; d="scan'208";a="352510254" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2023 12:07:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10720"; a="698659143" X-IronPort-AV: E=Sophos;i="6.00,190,1681196400"; d="scan'208";a="698659143" Received: from fm05wvaw1104.amr.corp.intel.com ([10.121.58.255]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2023 12:07:48 -0700 From: "Nolan Hergert" To: devel@edk2.groups.io Cc: Dandan Bi , Liming Gao Subject: [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls Date: Wed, 24 May 2023 12:07:42 -0700 Message-Id: <20230524190742.10894-1-nolan.hergert@intel.com> X-Mailer: git-send-email 2.38.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Liming Gao Signed-off-by: Nolan Hergert --- 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