Skip to content

Commit d6101ac

Browse files
os-dmergify[bot]
authored andcommitted
MdeModulePkg: Shortcircuit GCD Dumping Logic if Not Printing
CoreDumpGcdMemorySpaceMap() gets called on every update to the GCD, but it only prints if DEBUG_GCD is set. However, the compiler is not smart enough to remove all of this logic if we are not printing anything, so we end up needlessly allocating memory for the copy of the map and spending many cycles looping through each entry, only to not print anything. This code is compiled out on release builds, but slows down debug builds that aren't printing at DEBUG_GCD level. This patch updates CoreDumpGcdMemorySpaceMap() to shortcircuit and immediately exit if DEBUG_GCD is not set. It also adds the same logic to CoreDumpGcdIoSpaceMap(), which is called less frequently, but has the same issue. Signed-off-by: Oliver Smith-Denny <[email protected]>
1 parent 2cff874 commit d6101ac

File tree

1 file changed

+14
-0
lines changed
  • MdeModulePkg/Core/Dxe/Gcd

1 file changed

+14
-0
lines changed

MdeModulePkg/Core/Dxe/Gcd/Gcd.c

+14
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ CoreDumpGcdMemorySpaceMap (
153153
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
154154
UINTN Index;
155155

156+
// The compiler is not smart enough to compile out the whole function if DEBUG_GCD is not enabled, so we end up
157+
// looping through the GCD every time it gets updated, which wastes a lot of needless cycles if we aren't going to
158+
// print it. So shortcircuit and jump out if we don't need to print it.
159+
if (!DebugPrintLevelEnabled (DEBUG_GCD)) {
160+
return;
161+
}
162+
156163
Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
157164
ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
158165

@@ -199,6 +206,13 @@ CoreDumpGcdIoSpaceMap (
199206
EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;
200207
UINTN Index;
201208

209+
// The compiler is not smart enough to compile out the whole function if DEBUG_GCD is not enabled, so we end up
210+
// looping through the GCD every time it gets updated, which wastes a lot of needless cycles if we aren't going to
211+
// print it. So shortcircuit and jump out if we don't need to print it.
212+
if (!DebugPrintLevelEnabled (DEBUG_GCD)) {
213+
return;
214+
}
215+
202216
Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
203217
ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
204218

0 commit comments

Comments
 (0)