From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.1486.1684952480879042278 for ; Wed, 24 May 2023 11:21:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=AO+m7McP; spf=pass (domain: intel.com, ip: 134.134.136.126, 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=1684952480; x=1716488480; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=mRmxHpq472pib6qLzK+xEbv82W0rXrdWrN++5gga+ro=; b=AO+m7McPkVvf1XQ0WSVO29+WiTcSnE7DdeBedcz2vvUviydrlg9HExwv s1tGfo2J/x+pB9QQgiK2/2xfG+AmBIfYD0LBwnx82Ld6xnUa5HKdhh+nX 38lSOHOnsPl5ttdnh6GvFgfFQ9T6Q9me8XdWGRmHZ46WO7hi82HzdNhbf P+D0Y9imfVYRgZTgOVnZXqgM5P3hY77Vx7I3TcM7JyZr3RPSB9E7n6hWk goW7B6cBJst3wqB4Lp7yH3y3CkEm/xOr+W2/qWy5wpic1VH8z0AvyW7uS cfMsr9LSy3llwOGd810hUTynJuypMs5QxQhh7ijUdFYcv2GQboMeuADQg Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10720"; a="338227305" X-IronPort-AV: E=Sophos;i="6.00,190,1681196400"; d="scan'208";a="338227305" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2023 11:21:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10720"; a="878772262" X-IronPort-AV: E=Sophos;i="6.00,190,1681196400"; d="scan'208";a="878772262" Received: from fm05wvaw1104.amr.corp.intel.com ([10.121.58.255]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2023 11:21:20 -0700 From: nolan.hergert@intel.com To: devel@edk2.groups.io Subject: [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls Date: Wed, 24 May 2023 11:20:48 -0700 Message-Id: <4282ca25cde475a4ec2b81c5e878414a5829f88b.1684880087.git.nolan.hergert@intel.com> X-Mailer: git-send-email 2.38.1.windows.1 In-Reply-To: References: 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. 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