diff options
author | Star Zeng <star.zeng@intel.com> | 2015-09-30 04:29:50 +0000 |
---|---|---|
committer | lzeng14 <lzeng14@Edk2> | 2015-09-30 04:29:50 +0000 |
commit | 2f931dda52dc6e20643c0842acf18c9f0b5a0097 (patch) | |
tree | 976690e58376d7a26d4d25ebf7588effc4e86fd1 | |
parent | 9feefde0cb4fb4edb8b3e5a0168e756d81f46e79 (diff) | |
download | edk2-platforms-2f931dda52dc6e20643c0842acf18c9f0b5a0097.tar.xz |
MdeModulePkg UefiBootManagerLib: Do not assume perf entry count has no change
Current implementation assumes the performance entry count has no change from
multiple GetPerformanceMeasurement() while loops, it may cause the allocated buffer
for PerfEntriesAsDxeHandle at the first loop to be overflowed if the following loop has
the count changed.
This patch is also to sync the change at
commit R17851 "IntelFrameworkModulePkg GenericBdsLib: Resolve array size mismatch".
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18561 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r-- | MdeModulePkg/Library/UefiBootManagerLib/BmPerformance.c | 120 |
1 files changed, 35 insertions, 85 deletions
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmPerformance.c b/MdeModulePkg/Library/UefiBootManagerLib/BmPerformance.c index e45c0bd23a..0abd019440 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmPerformance.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmPerformance.c @@ -62,7 +62,7 @@ BmGetShortPdbFileName ( for (Index = StartIndex; Index < EndIndex; Index++) {
GaugeString[Index1] = PdbFileName[Index];
Index1++;
- if (Index1 == PERF_TOKEN_LENGTH - 1) {
+ if (Index1 == StringSize - 1) {
break;
}
}
@@ -157,7 +157,7 @@ BmWriteBootToOsPerformanceData ( UINT32 LimitCount;
EFI_HANDLE *Handles;
UINTN NoHandles;
- CHAR8 GaugeString[PERF_TOKEN_LENGTH];
+ CHAR8 GaugeString[PERF_TOKEN_SIZE];
UINT8 *Ptr;
UINT32 Index;
UINT64 Ticker;
@@ -172,13 +172,8 @@ BmWriteBootToOsPerformanceData ( UINT64 StartValue;
UINT64 EndValue;
BOOLEAN CountUp;
- UINTN EntryIndex;
- UINTN NumPerfEntries;
- //
- // List of flags indicating PerfEntry contains DXE handle
- //
- BOOLEAN *PerfEntriesAsDxeHandle;
UINTN VarSize;
+ BOOLEAN Found;
//
// Record the performance data for End of BDS
@@ -186,11 +181,6 @@ BmWriteBootToOsPerformanceData ( PERF_END(NULL, "BDS", NULL, 0);
//
- // Reset the entry count
- //
- mBmPerfHeader.Count = 0;
-
- //
// Retrieve time stamp count as early as possible
//
Ticker = GetPerformanceCounter ();
@@ -212,6 +202,11 @@ BmWriteBootToOsPerformanceData ( CountUp = FALSE;
}
+ //
+ // Reset the entry count
+ //
+ mBmPerfHeader.Count = 0;
+
if (mBmAcpiLowMemoryBase == 0x0FFFFFFFF) {
VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
Status = gRT->GetVariable (
@@ -247,73 +242,10 @@ BmWriteBootToOsPerformanceData ( Ptr = (UINT8 *) ((UINT32) mBmAcpiLowMemoryBase + sizeof (PERF_HEADER));
LimitCount = (UINT32) (PERF_DATA_MAX_LENGTH - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
- NumPerfEntries = 0;
- LogEntryKey = 0;
- while ((LogEntryKey = GetPerformanceMeasurement (
- LogEntryKey,
- &Handle,
- &Token,
- &Module,
- &StartTicker,
- &EndTicker)) != 0) {
- NumPerfEntries++;
- }
- PerfEntriesAsDxeHandle = AllocateZeroPool (NumPerfEntries * sizeof (BOOLEAN));
- ASSERT (PerfEntriesAsDxeHandle != NULL);
-
//
- // Get DXE drivers performance
- //
- for (Index = 0; Index < NoHandles; Index++) {
- Ticker = 0;
- LogEntryKey = 0;
- EntryIndex = 0;
- while ((LogEntryKey = GetPerformanceMeasurement (
- LogEntryKey,
- &Handle,
- &Token,
- &Module,
- &StartTicker,
- &EndTicker)) != 0) {
- if (Handle == Handles[Index] && !PerfEntriesAsDxeHandle[EntryIndex]) {
- PerfEntriesAsDxeHandle[EntryIndex] = TRUE;
- }
- EntryIndex++;
- if ((Handle == Handles[Index]) && (EndTicker != 0)) {
- if (StartTicker == 1) {
- StartTicker = StartValue;
- }
- if (EndTicker == 1) {
- EndTicker = StartValue;
- }
- Ticker += CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
- }
- }
-
- Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
-
- if (Duration > 0) {
-
- BmGetNameFromHandle (Handles[Index], GaugeString, PERF_TOKEN_LENGTH);
-
- AsciiStrCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, GaugeString);
- mBmPerfData.Duration = Duration;
-
- CopyMem (Ptr, &mBmPerfData, sizeof (PERF_DATA));
- Ptr += sizeof (PERF_DATA);
-
- mBmPerfHeader.Count++;
- if (mBmPerfHeader.Count == LimitCount) {
- goto Done;
- }
- }
- }
-
- //
- // Get inserted performance data
+ // Get performance data
//
LogEntryKey = 0;
- EntryIndex = 0;
while ((LogEntryKey = GetPerformanceMeasurement (
LogEntryKey,
&Handle,
@@ -321,11 +253,7 @@ BmWriteBootToOsPerformanceData ( &Module,
&StartTicker,
&EndTicker)) != 0) {
- if (!PerfEntriesAsDxeHandle[EntryIndex] && EndTicker != 0) {
-
- ZeroMem (&mBmPerfData, sizeof (PERF_DATA));
-
- AsciiStrnCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, Token, PERF_TOKEN_LENGTH);
+ if (EndTicker != 0) {
if (StartTicker == 1) {
StartTicker = StartValue;
}
@@ -334,7 +262,31 @@ BmWriteBootToOsPerformanceData ( }
Ticker = CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
- mBmPerfData.Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
+ Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
+ if (Duration == 0) {
+ continue;
+ }
+
+ ZeroMem (&mBmPerfData, sizeof (PERF_DATA));
+
+ mBmPerfData.Duration = Duration;
+
+ //
+ // See if the Handle is in the handle buffer
+ //
+ Found = FALSE;
+ for (Index = 0; Index < NoHandles; Index++) {
+ if (Handle == Handles[Index]) {
+ BmGetNameFromHandle (Handles[Index], GaugeString, PERF_TOKEN_SIZE);
+ AsciiStrCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, GaugeString);
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found) {
+ AsciiStrnCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, Token, PERF_TOKEN_LENGTH);
+ }
CopyMem (Ptr, &mBmPerfData, sizeof (PERF_DATA));
Ptr += sizeof (PERF_DATA);
@@ -344,13 +296,11 @@ BmWriteBootToOsPerformanceData ( goto Done;
}
}
- EntryIndex++;
}
Done:
FreePool (Handles);
- FreePool (PerfEntriesAsDxeHandle);
mBmPerfHeader.Signiture = PERFORMANCE_SIGNATURE;
|