<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof ContentPasted0">
>From 4282ca25cde475a4ec2b81c5e878414a5829f88b Mon Sep 17 00:00:00 2001
<div class="ContentPasted0">Message-Id: <4282ca25cde475a4ec2b81c5e878414a5829f88b.1684880087.git.nolan.hergert@intel.com></div>
<div class="ContentPasted0">In-Reply-To: <cover.1684880087.git.nolan.hergert@intel.com></div>
<div class="ContentPasted0">References: <cover.1684880087.git.nolan.hergert@intel.com></div>
<div class="ContentPasted0">From: Nolan Hergert <nolan.hergert@intel.com></div>
<div class="ContentPasted0">Date: Fri, 19 May 2023 14:58:00 -0700</div>
<div class="ContentPasted0">Subject: [PATCH 1/1] MdeModulePkg: Cache device path during LoadImage calls</div>
<div><br class="ContentPasted0">
</div>
<div class="ContentPasted0">During LoadImage, there 6-7 of the same call to CoreLocateDevicePath</div>
<div class="ContentPasted0">and can be cached during a particular call to LoadImage. For</div>
<div class="ContentPasted0">implementations with significant numbers of calls to LoadImage (>250),</div>
<div class="ContentPasted0">this change will improve the boot time by >10ms.</div>
<div><br class="ContentPasted0">
</div>
<div class="ContentPasted0">Signed-off-by: Nolan Hergert <nolan.hergert@intel.com></div>
<div class="ContentPasted0">---</div>
<div class="ContentPasted0"> MdeModulePkg/Core/Dxe/Hand/Locate.c | 21 ++++++++++++++++-----</div>
<div class="ContentPasted0"> MdeModulePkg/Core/Dxe/Image/Image.c | 15 +++++++++++++--</div>
<div class="ContentPasted0"> 2 files changed, 29 insertions(+), 7 deletions(-)</div>
<div><br class="ContentPasted0">
</div>
<div class="ContentPasted0">diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c</div>
<div class="ContentPasted0">index a29010a54565..52b7b7a7cd8c 100644</div>
<div class="ContentPasted0">--- a/MdeModulePkg/Core/Dxe/Hand/Locate.c</div>
<div class="ContentPasted0">+++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c</div>
<div class="ContentPasted0">@@ -14,6 +14,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent</div>
<div class="ContentPasted0"> //</div>
<div class="ContentPasted0"> UINTN  mEfiLocateHandleRequest = 0;</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">+extern EFI_DEVICE_PATH_PROTOCOL  *gFilePathCache;</div>
<div class="ContentPasted0">+extern EFI_HANDLE                gDeviceHandleCache;</div>
<div class="ContentPasted0">+extern EFI_DEVICE_PATH_PROTOCOL  *gOutgoingDevicePathCache;</div>
<div class="ContentPasted0">+</div>
<div class="ContentPasted0"> //</div>
<div class="ContentPasted0"> // Internal prototypes</div>
<div class="ContentPasted0"> //</div>
<div class="ContentPasted0">@@ -467,10 +471,21 @@ CoreLocateDevicePath (</div>
<div class="ContentPasted0">     return EFI_INVALID_PARAMETER;</div>
<div class="ContentPasted0">   }</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">-  if ((DevicePath == NULL) || (*DevicePath == NULL)) {</div>
<div class="ContentPasted0">+  if ((DevicePath == NULL) || (*DevicePath == NULL) || (Device == NULL)) {</div>
<div class="ContentPasted0">     return EFI_INVALID_PARAMETER;</div>
<div class="ContentPasted0">   }</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">+  if (gFilePathCache != NULL) {</div>
<div class="ContentPasted0">+    Size       = GetDevicePathSize (gFilePathCache) - sizeof (EFI_DEVICE_PATH_PROTOCOL);</div>
<div class="ContentPasted0">+    SourceSize = GetDevicePathSize (*DevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);</div>
<div class="ContentPasted0">+</div>
<div class="ContentPasted0">+    if ((Size == SourceSize) && (CompareMem (gFilePathCache, *DevicePath, (UINTN)Size) == 0)) {</div>
<div class="ContentPasted0">+      *Device     = gDeviceHandleCache;</div>
<div class="ContentPasted0">+      *DevicePath = gOutgoingDevicePathCache;</div>
<div class="ContentPasted0">+      return EFI_SUCCESS;</div>
<div class="ContentPasted0">+    }</div>
<div class="ContentPasted0">+  }</div>
<div class="ContentPasted0">+</div>
<div class="ContentPasted0">   Handles       = NULL;</div>
<div class="ContentPasted0">   BestDevice    = NULL;</div>
<div class="ContentPasted0">   SourcePath    = *DevicePath;</div>
<div class="ContentPasted0">@@ -541,10 +556,6 @@ CoreLocateDevicePath (</div>
<div class="ContentPasted0">     return EFI_NOT_FOUND;</div>
<div class="ContentPasted0">   }</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">-  if (Device == NULL) {</div>
<div class="ContentPasted0">-    return EFI_INVALID_PARAMETER;</div>
<div class="ContentPasted0">-  }</div>
<div class="ContentPasted0">-</div>
<div class="ContentPasted0">   *Device = BestDevice;</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">   //</div>
<div class="ContentPasted0">diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c</div>
<div class="ContentPasted0">index 9dbfb2a1fad2..e76f788a4d89 100644</div>
<div class="ContentPasted0">--- a/MdeModulePkg/Core/Dxe/Image/Image.c</div>
<div class="ContentPasted0">+++ b/MdeModulePkg/Core/Dxe/Image/Image.c</div>
<div class="ContentPasted0">@@ -12,7 +12,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent</div>
<div class="ContentPasted0"> //</div>
<div class="ContentPasted0"> // Module Globals</div>
<div class="ContentPasted0"> //</div>
<div class="ContentPasted0">-LOADED_IMAGE_PRIVATE_DATA  *mCurrentImage = NULL;</div>
<div class="ContentPasted0">+LOADED_IMAGE_PRIVATE_DATA  *mCurrentImage            = NULL;</div>
<div class="ContentPasted0">+EFI_DEVICE_PATH_PROTOCOL   *gFilePathCache           = NULL;</div>
<div class="ContentPasted0">+EFI_DEVICE_PATH_PROTOCOL   *gOutgoingDevicePathCache = NULL;</div>
<div class="ContentPasted0">+EFI_HANDLE                 gDeviceHandleCache        = NULL;</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0"> typedef struct {</div>
<div class="ContentPasted0">   LIST_ENTRY                              Link;</div>
<div class="ContentPasted0">@@ -1219,7 +1222,10 @@ CoreLoadImageCommon (</div>
<div class="ContentPasted0">     Node   = NULL;</div>
<div class="ContentPasted0">     Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);</div>
<div class="ContentPasted0">     if (!EFI_ERROR (Status)) {</div>
<div class="ContentPasted0">-      ImageIsFromFv = TRUE;</div>
<div class="ContentPasted0">+      ImageIsFromFv            = TRUE;</div>
<div class="ContentPasted0">+      gFilePathCache           = FilePath;</div>
<div class="ContentPasted0">+      gOutgoingDevicePathCache = HandleFilePath;</div>
<div class="ContentPasted0">+      gDeviceHandleCache       = DeviceHandle;</div>
<div class="ContentPasted0">     } else {</div>
<div class="ContentPasted0">       HandleFilePath = FilePath;</div>
<div class="ContentPasted0">       Status         = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);</div>
<div class="ContentPasted0">@@ -1497,6 +1503,11 @@ Done:</div>
<div class="ContentPasted0">     Image->LoadImageStatus = Status;</div>
<div class="ContentPasted0">   }</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">+  // Clear cache</div>
<div class="ContentPasted0">+  gFilePathCache           = NULL;</div>
<div class="ContentPasted0">+  gOutgoingDevicePathCache = NULL;</div>
<div class="ContentPasted0">+  gDeviceHandleCache       = NULL;</div>
<div class="ContentPasted0">+</div>
<div class="ContentPasted0">   return Status;</div>
<div class="ContentPasted0"> }</div>
<div class="ContentPasted0"> </div>
<div class="ContentPasted0">-- </div>
<div class="ContentPasted0">2.38.1.windows.1</div>
<div><br class="ContentPasted0">
</div>
<br>
</div>
</body>
</html>


<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>


Groups.io Links:<p>


  
    You receive all messages sent to this group.
  
  


<p>
<a target="_blank" href="https://edk2.groups.io/g/devel/message/105264">View/Reply Online (#105264)</a> |


  

|

  <a target="_blank" href="https://groups.io/mt/99111895/1813853">Mute This Topic</a>

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>




<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>