]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: Add performance property configuration table
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
CommitLineData
8dbae30d 1/** @file\r
857dfc45 2 Performance library instance mainly used by DxeCore.\r
3\r
4 This library provides the performance measurement interfaces and initializes performance\r
5 logging for DXE phase. It first initializes its private global data structure for\r
6 performance logging and saves the performance GUIDed HOB passed from PEI phase. \r
f0da4d7d
SZ
7 It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,\r
8 which are consumed by DxePerformanceLib to logging performance data in DXE phase.\r
857dfc45 9\r
10 This library is mainly used by DxeCore to start performance logging to ensure that\r
11 Performance Protocol is installed at the very beginning of DXE phase.\r
a0afd019 12\r
cfb0aba7 13Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
7c50b343 14(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
cd5ebaa0 15This program and the accompanying materials\r
a0afd019 16are licensed and made available under the terms and conditions of the BSD License\r
17which accompanies this distribution. The full text of the license may be found at\r
18http://opensource.org/licenses/bsd-license.php\r
19\r
20THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
21WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
22\r
8dbae30d 23**/\r
a0afd019 24\r
ed7748fe 25\r
aa79b0b3 26#include "DxeCorePerformanceLibInternal.h"\r
ed7748fe 27\r
a0afd019 28\r
29//\r
857dfc45 30// The data structure to hold global performance data.\r
a0afd019 31//\r
fe1e36e5 32GAUGE_DATA_HEADER *mGaugeData;\r
857dfc45 33\r
34//\r
35// The current maximum number of logging entries. If current number of \r
36// entries exceeds this value, it will re-allocate a larger array and\r
37// migration the old data to the larger array.\r
38//\r
fe1e36e5 39UINT32 mMaxGaugeRecords;\r
a0afd019 40\r
857dfc45 41//\r
42// The handle to install Performance Protocol instance.\r
43//\r
a0afd019 44EFI_HANDLE mHandle = NULL;\r
857dfc45 45\r
46//\r
f0da4d7d 47// Interfaces for Performance Protocol.\r
857dfc45 48//\r
a0afd019 49PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
50 StartGauge,\r
51 EndGauge,\r
52 GetGauge\r
53 };\r
54\r
f0da4d7d
SZ
55//\r
56// Interfaces for PerformanceEx Protocol.\r
57//\r
58PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {\r
59 StartGaugeEx,\r
60 EndGaugeEx,\r
61 GetGaugeEx\r
62 };\r
63\r
cfb0aba7
SZ
64PERFORMANCE_PROPERTY mPerformanceProperty;\r
65\r
a0afd019 66/**\r
f0da4d7d 67 Searches in the gauge array with keyword Handle, Token, Module and Identifier.\r
a0afd019 68\r
69 This internal function searches for the gauge entry in the gauge array.\r
f0da4d7d 70 If there is an entry that exactly matches the given keywords\r
a0afd019 71 and its end time stamp is zero, then the index of that gauge entry is returned;\r
72 otherwise, the the number of gauge entries in the array is returned.\r
73\r
74 @param Handle Pointer to environment specific context used\r
75 to identify the component being measured.\r
76 @param Token Pointer to a Null-terminated ASCII string\r
77 that identifies the component being measured.\r
78 @param Module Pointer to a Null-terminated ASCII string\r
79 that identifies the module being measured.\r
f0da4d7d 80 @param Identifier 32-bit identifier.\r
a0afd019 81\r
82 @retval The index of gauge entry in the array.\r
83\r
84**/\r
a0afd019 85UINT32\r
86InternalSearchForGaugeEntry (\r
87 IN CONST VOID *Handle, OPTIONAL\r
88 IN CONST CHAR8 *Token, OPTIONAL\r
f0da4d7d
SZ
89 IN CONST CHAR8 *Module, OPTIONAL\r
90 IN UINT32 Identifier\r
a0afd019 91 )\r
92{\r
93 UINT32 Index;\r
b504f519 94 UINT32 Index2;\r
a0afd019 95 UINT32 NumberOfEntries;\r
f0da4d7d 96 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
a0afd019 97\r
98 if (Token == NULL) {\r
99 Token = "";\r
100 }\r
101 if (Module == NULL) {\r
102 Module = "";\r
103 }\r
104\r
105 NumberOfEntries = mGaugeData->NumberOfEntries;\r
f0da4d7d 106 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
a0afd019 107\r
b504f519
SZ
108 Index2 = 0;\r
109\r
a0afd019 110 for (Index = 0; Index < NumberOfEntries; Index++) {\r
b504f519
SZ
111 Index2 = NumberOfEntries - 1 - Index;\r
112 if (GaugeEntryExArray[Index2].EndTimeStamp == 0 &&\r
113 (GaugeEntryExArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
114 AsciiStrnCmp (GaugeEntryExArray[Index2].Token, Token, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&\r
7a9395cd 115 AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, DXE_PERFORMANCE_STRING_LENGTH) == 0) {\r
b504f519 116 Index = Index2;\r
a0afd019 117 break;\r
118 }\r
119 }\r
120\r
121 return Index;\r
122}\r
123\r
124/**\r
125 Adds a record at the end of the performance measurement log\r
126 that records the start time of a performance measurement.\r
127\r
128 Adds a record to the end of the performance measurement log\r
f0da4d7d 129 that contains the Handle, Token, Module and Identifier.\r
a0afd019 130 The end time of the new record must be set to zero.\r
131 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
132 If TimeStamp is zero, the start time in the record is filled in with the value\r
133 read from the current time stamp.\r
134\r
135 @param Handle Pointer to environment specific context used\r
136 to identify the component being measured.\r
137 @param Token Pointer to a Null-terminated ASCII string\r
138 that identifies the component being measured.\r
139 @param Module Pointer to a Null-terminated ASCII string\r
140 that identifies the module being measured.\r
141 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
142 @param Identifier 32-bit identifier. If the value is 0, the created record\r
143 is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\r
a0afd019 144\r
145 @retval EFI_SUCCESS The data was read correctly from the device.\r
146 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
147\r
148**/\r
a0afd019 149EFI_STATUS\r
150EFIAPI\r
f0da4d7d 151StartGaugeEx (\r
a0afd019 152 IN CONST VOID *Handle, OPTIONAL\r
153 IN CONST CHAR8 *Token, OPTIONAL\r
154 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
155 IN UINT64 TimeStamp,\r
156 IN UINT32 Identifier\r
a0afd019 157 )\r
158{\r
f0da4d7d 159 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
a0afd019 160 UINTN GaugeDataSize;\r
f0da4d7d 161 GAUGE_DATA_HEADER *NewGaugeData;\r
a0afd019 162 UINTN OldGaugeDataSize;\r
163 GAUGE_DATA_HEADER *OldGaugeData;\r
164 UINT32 Index;\r
165\r
166 Index = mGaugeData->NumberOfEntries;\r
167 if (Index >= mMaxGaugeRecords) {\r
168 //\r
857dfc45 169 // Try to enlarge the scale of gauge array.\r
a0afd019 170 //\r
171 OldGaugeData = mGaugeData;\r
f0da4d7d 172 OldGaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords;\r
a0afd019 173\r
f0da4d7d 174 GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords * 2;\r
a0afd019 175\r
f0da4d7d
SZ
176 NewGaugeData = AllocateZeroPool (GaugeDataSize);\r
177 if (NewGaugeData == NULL) {\r
a0afd019 178 return EFI_OUT_OF_RESOURCES;\r
179 }\r
f0da4d7d
SZ
180\r
181 mGaugeData = NewGaugeData;\r
182 mMaxGaugeRecords *= 2;\r
183\r
a0afd019 184 //\r
857dfc45 185 // Initialize new data array and migrate old data one.\r
a0afd019 186 //\r
187 mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
188\r
189 FreePool (OldGaugeData);\r
190 }\r
191\r
f0da4d7d
SZ
192 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
193 GaugeEntryExArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
a0afd019 194\r
195 if (Token != NULL) {\r
0ec2bfc8 196 AsciiStrnCpyS (GaugeEntryExArray[Index].Token, DXE_PERFORMANCE_STRING_SIZE, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
a0afd019 197 }\r
198 if (Module != NULL) {\r
0ec2bfc8 199 AsciiStrnCpyS (GaugeEntryExArray[Index].Module, DXE_PERFORMANCE_STRING_SIZE, Module, DXE_PERFORMANCE_STRING_LENGTH);\r
a0afd019 200 }\r
201\r
f0da4d7d
SZ
202 GaugeEntryExArray[Index].EndTimeStamp = 0;\r
203 GaugeEntryExArray[Index].Identifier = Identifier;\r
204\r
a0afd019 205 if (TimeStamp == 0) {\r
206 TimeStamp = GetPerformanceCounter ();\r
207 }\r
f0da4d7d 208 GaugeEntryExArray[Index].StartTimeStamp = TimeStamp;\r
a0afd019 209\r
210 mGaugeData->NumberOfEntries++;\r
211\r
212 return EFI_SUCCESS;\r
213}\r
214\r
215/**\r
216 Searches the performance measurement log from the beginning of the log\r
217 for the first matching record that contains a zero end time and fills in a valid end time.\r
218\r
219 Searches the performance measurement log from the beginning of the log\r
7a9395cd 220 for the first record that matches Handle, Token and Module and has an end time value of zero.\r
a0afd019 221 If the record can not be found then return EFI_NOT_FOUND.\r
222 If the record is found and TimeStamp is not zero,\r
223 then the end time in the record is filled in with the value specified by TimeStamp.\r
224 If the record is found and TimeStamp is zero, then the end time in the matching record\r
225 is filled in with the current time stamp value.\r
226\r
227 @param Handle Pointer to environment specific context used\r
228 to identify the component being measured.\r
229 @param Token Pointer to a Null-terminated ASCII string\r
230 that identifies the component being measured.\r
231 @param Module Pointer to a Null-terminated ASCII string\r
232 that identifies the module being measured.\r
233 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
234 @param Identifier 32-bit identifier. If the value is 0, the found record\r
235 is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.\r
a0afd019 236\r
237 @retval EFI_SUCCESS The end of the measurement was recorded.\r
238 @retval EFI_NOT_FOUND The specified measurement record could not be found.\r
239\r
240**/\r
a0afd019 241EFI_STATUS\r
242EFIAPI\r
f0da4d7d 243EndGaugeEx (\r
a0afd019 244 IN CONST VOID *Handle, OPTIONAL\r
245 IN CONST CHAR8 *Token, OPTIONAL\r
246 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
247 IN UINT64 TimeStamp,\r
248 IN UINT32 Identifier\r
a0afd019 249 )\r
250{\r
f0da4d7d
SZ
251 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
252 UINT32 Index;\r
a0afd019 253\r
254 if (TimeStamp == 0) {\r
255 TimeStamp = GetPerformanceCounter ();\r
256 }\r
257\r
f0da4d7d 258 Index = InternalSearchForGaugeEntry (Handle, Token, Module, Identifier);\r
a0afd019 259 if (Index >= mGaugeData->NumberOfEntries) {\r
260 return EFI_NOT_FOUND;\r
261 }\r
f0da4d7d
SZ
262 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
263 GaugeEntryExArray[Index].EndTimeStamp = TimeStamp;\r
a0afd019 264\r
265 return EFI_SUCCESS;\r
266}\r
267\r
268/**\r
269 Retrieves a previously logged performance measurement.\r
f0da4d7d
SZ
270 It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,\r
271 and then assign the Identifier with 0.\r
a0afd019 272\r
273 Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
274 If it stands for a valid entry, then EFI_SUCCESS is returned and\r
f0da4d7d 275 GaugeDataEntryEx stores the pointer to that entry.\r
a0afd019 276\r
277 @param LogEntryKey The key for the previous performance measurement log entry.\r
278 If 0, then the first performance measurement log entry is retrieved.\r
f0da4d7d 279 @param GaugeDataEntryEx The indirect pointer to the extended gauge data entry specified by LogEntryKey\r
a0afd019 280 if the retrieval is successful.\r
281\r
f0da4d7d 282 @retval EFI_SUCCESS The GuageDataEntryEx is successfully found based on LogEntryKey.\r
a0afd019 283 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r
284 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r
f0da4d7d 285 @retval EFI_INVALIDE_PARAMETER GaugeDataEntryEx is NULL.\r
a0afd019 286\r
287**/\r
a0afd019 288EFI_STATUS\r
289EFIAPI\r
f0da4d7d
SZ
290GetGaugeEx (\r
291 IN UINTN LogEntryKey,\r
292 OUT GAUGE_DATA_ENTRY_EX **GaugeDataEntryEx\r
a0afd019 293 )\r
294{\r
295 UINTN NumberOfEntries;\r
f0da4d7d 296 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
a0afd019 297\r
298 NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r
299 if (LogEntryKey > NumberOfEntries) {\r
300 return EFI_INVALID_PARAMETER;\r
301 }\r
302 if (LogEntryKey == NumberOfEntries) {\r
303 return EFI_NOT_FOUND;\r
304 }\r
305\r
f0da4d7d
SZ
306 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
307\r
308 if (GaugeDataEntryEx == NULL) {\r
309 return EFI_INVALID_PARAMETER;\r
310 }\r
311 *GaugeDataEntryEx = &GaugeEntryExArray[LogEntryKey];\r
312\r
313 return EFI_SUCCESS;\r
314}\r
315\r
316/**\r
317 Adds a record at the end of the performance measurement log\r
318 that records the start time of a performance measurement.\r
319\r
320 Adds a record to the end of the performance measurement log\r
321 that contains the Handle, Token, and Module.\r
322 The end time of the new record must be set to zero.\r
323 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
324 If TimeStamp is zero, the start time in the record is filled in with the value\r
325 read from the current time stamp.\r
326\r
327 @param Handle Pointer to environment specific context used\r
328 to identify the component being measured.\r
329 @param Token Pointer to a Null-terminated ASCII string\r
330 that identifies the component being measured.\r
331 @param Module Pointer to a Null-terminated ASCII string\r
332 that identifies the module being measured.\r
333 @param TimeStamp 64-bit time stamp.\r
334\r
335 @retval EFI_SUCCESS The data was read correctly from the device.\r
336 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
337\r
338**/\r
339EFI_STATUS\r
340EFIAPI\r
341StartGauge (\r
342 IN CONST VOID *Handle, OPTIONAL\r
343 IN CONST CHAR8 *Token, OPTIONAL\r
344 IN CONST CHAR8 *Module, OPTIONAL\r
345 IN UINT64 TimeStamp\r
346 )\r
347{\r
348 return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
349}\r
350\r
351/**\r
352 Searches the performance measurement log from the beginning of the log\r
353 for the first matching record that contains a zero end time and fills in a valid end time.\r
354\r
355 Searches the performance measurement log from the beginning of the log\r
356 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
357 If the record can not be found then return EFI_NOT_FOUND.\r
358 If the record is found and TimeStamp is not zero,\r
359 then the end time in the record is filled in with the value specified by TimeStamp.\r
360 If the record is found and TimeStamp is zero, then the end time in the matching record\r
361 is filled in with the current time stamp value.\r
362\r
363 @param Handle Pointer to environment specific context used\r
364 to identify the component being measured.\r
365 @param Token Pointer to a Null-terminated ASCII string\r
366 that identifies the component being measured.\r
367 @param Module Pointer to a Null-terminated ASCII string\r
368 that identifies the module being measured.\r
369 @param TimeStamp 64-bit time stamp.\r
370\r
371 @retval EFI_SUCCESS The end of the measurement was recorded.\r
372 @retval EFI_NOT_FOUND The specified measurement record could not be found.\r
373\r
374**/\r
375EFI_STATUS\r
376EFIAPI\r
377EndGauge (\r
378 IN CONST VOID *Handle, OPTIONAL\r
379 IN CONST CHAR8 *Token, OPTIONAL\r
380 IN CONST CHAR8 *Module, OPTIONAL\r
381 IN UINT64 TimeStamp\r
382 )\r
383{\r
384 return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
385}\r
386\r
387/**\r
388 Retrieves a previously logged performance measurement.\r
389 It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,\r
390 and then eliminate the Identifier.\r
391\r
392 Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
393 If it stands for a valid entry, then EFI_SUCCESS is returned and\r
394 GaugeDataEntry stores the pointer to that entry.\r
395\r
396 @param LogEntryKey The key for the previous performance measurement log entry.\r
397 If 0, then the first performance measurement log entry is retrieved.\r
398 @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r
399 if the retrieval is successful.\r
400\r
401 @retval EFI_SUCCESS The GuageDataEntry is successfully found based on LogEntryKey.\r
402 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r
403 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r
404 @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r
405\r
406**/\r
407EFI_STATUS\r
408EFIAPI\r
409GetGauge (\r
410 IN UINTN LogEntryKey,\r
411 OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r
412 )\r
413{\r
414 EFI_STATUS Status;\r
415 GAUGE_DATA_ENTRY_EX *GaugeEntryEx;\r
416\r
1658440e
SZ
417 GaugeEntryEx = NULL;\r
418\r
f0da4d7d
SZ
419 Status = GetGaugeEx (LogEntryKey, &GaugeEntryEx);\r
420 if (EFI_ERROR (Status)) {\r
421 return Status;\r
422 }\r
a0afd019 423\r
424 if (GaugeDataEntry == NULL) {\r
425 return EFI_INVALID_PARAMETER;\r
426 }\r
f0da4d7d
SZ
427\r
428 *GaugeDataEntry = (GAUGE_DATA_ENTRY *) GaugeEntryEx;\r
a0afd019 429\r
430 return EFI_SUCCESS;\r
431}\r
432\r
433/**\r
434 Dumps all the PEI performance log to DXE performance gauge array.\r
435\r
436 This internal function dumps all the PEI performance log to the DXE performance gauge array.\r
437 It retrieves the optional GUID HOB for PEI performance and then saves the performance data\r
438 to DXE performance data structures.\r
439\r
440**/\r
a0afd019 441VOID\r
442InternalGetPeiPerformance (\r
443 VOID\r
444 )\r
445{\r
446 EFI_HOB_GUID_TYPE *GuidHob;\r
447 PEI_PERFORMANCE_LOG_HEADER *LogHob;\r
448 PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
f0da4d7d
SZ
449 UINT32 *LogIdArray;\r
450 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
a0afd019 451 UINT32 Index;\r
452 UINT32 NumberOfEntries;\r
453\r
454 NumberOfEntries = 0;\r
f0da4d7d 455 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
a0afd019 456\r
457 //\r
458 // Dump PEI Log Entries to DXE Guage Data structure.\r
459 //\r
ee0961f7 460 GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);\r
a0afd019 461 if (GuidHob != NULL) {\r
462 LogHob = GET_GUID_HOB_DATA (GuidHob);\r
463 LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (LogHob + 1);\r
a0afd019 464\r
465 NumberOfEntries = LogHob->NumberOfEntries;\r
466 for (Index = 0; Index < NumberOfEntries; Index++) {\r
f0da4d7d 467 GaugeEntryExArray[Index].Handle = LogEntryArray[Index].Handle;\r
96f983fa
QS
468 AsciiStrCpyS (GaugeEntryExArray[Index].Token, DXE_PERFORMANCE_STRING_SIZE, LogEntryArray[Index].Token);\r
469 AsciiStrCpyS (GaugeEntryExArray[Index].Module, DXE_PERFORMANCE_STRING_SIZE, LogEntryArray[Index].Module);\r
f0da4d7d
SZ
470 GaugeEntryExArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;\r
471 GaugeEntryExArray[Index].EndTimeStamp = LogEntryArray[Index].EndTimeStamp;\r
472 GaugeEntryExArray[Index].Identifier = 0;\r
473 }\r
474\r
475 GuidHob = GetFirstGuidHob (&gPerformanceExProtocolGuid);\r
476 if (GuidHob != NULL) {\r
477 LogIdArray = GET_GUID_HOB_DATA (GuidHob);\r
478 for (Index = 0; Index < NumberOfEntries; Index++) {\r
479 GaugeEntryExArray[Index].Identifier = LogIdArray[Index];\r
480 }\r
a0afd019 481 }\r
482 }\r
483 mGaugeData->NumberOfEntries = NumberOfEntries;\r
484}\r
485\r
486/**\r
487 The constructor function initializes Performance infrastructure for DXE phase.\r
488\r
f0da4d7d 489 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance\r
a0afd019 490 and merges PEI performance data to DXE performance log.\r
491 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
492\r
493 @param ImageHandle The firmware allocated handle for the EFI image.\r
494 @param SystemTable A pointer to the EFI System Table.\r
495\r
496 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
497\r
498**/\r
499EFI_STATUS\r
500EFIAPI\r
501DxeCorePerformanceLibConstructor (\r
502 IN EFI_HANDLE ImageHandle,\r
503 IN EFI_SYSTEM_TABLE *SystemTable\r
504 )\r
505{\r
506 EFI_STATUS Status;\r
cfb0aba7
SZ
507 PERFORMANCE_PROPERTY *PerformanceProperty;\r
508\r
a0afd019 509\r
510 if (!PerformanceMeasurementEnabled ()) {\r
511 //\r
512 // Do not initialize performance infrastructure if not required.\r
513 //\r
514 return EFI_SUCCESS;\r
515 }\r
516 //\r
517 // Install the protocol interfaces.\r
518 //\r
f0da4d7d 519 Status = gBS->InstallMultipleProtocolInterfaces (\r
a0afd019 520 &mHandle,\r
521 &gPerformanceProtocolGuid,\r
f0da4d7d
SZ
522 &mPerformanceInterface,\r
523 &gPerformanceExProtocolGuid,\r
524 &mPerformanceExInterface,\r
525 NULL\r
a0afd019 526 );\r
527 ASSERT_EFI_ERROR (Status);\r
528\r
7c50b343
CS
529 mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
530 PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
531 PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
a0afd019 532\r
f0da4d7d 533 mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));\r
a0afd019 534 ASSERT (mGaugeData != NULL);\r
535\r
536 InternalGetPeiPerformance ();\r
537\r
cfb0aba7
SZ
538 Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, &PerformanceProperty);\r
539 if (EFI_ERROR (Status)) {\r
540 //\r
541 // Install configuration table for performance property.\r
542 //\r
543 mPerformanceProperty.Revision = PERFORMANCE_PROPERTY_REVISION;\r
544 mPerformanceProperty.Reserved = 0;\r
545 mPerformanceProperty.Frequency = GetPerformanceCounterProperties (\r
546 &mPerformanceProperty.TimerStartValue,\r
547 &mPerformanceProperty.TimerEndValue\r
548 );\r
549 Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);\r
550 ASSERT_EFI_ERROR (Status);\r
551 }\r
552\r
553 return EFI_SUCCESS;\r
a0afd019 554}\r
555\r
556/**\r
557 Adds a record at the end of the performance measurement log\r
558 that records the start time of a performance measurement.\r
559\r
560 Adds a record to the end of the performance measurement log\r
f0da4d7d 561 that contains the Handle, Token, Module and Identifier.\r
a0afd019 562 The end time of the new record must be set to zero.\r
563 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
564 If TimeStamp is zero, the start time in the record is filled in with the value\r
565 read from the current time stamp.\r
566\r
567 @param Handle Pointer to environment specific context used\r
568 to identify the component being measured.\r
569 @param Token Pointer to a Null-terminated ASCII string\r
570 that identifies the component being measured.\r
571 @param Module Pointer to a Null-terminated ASCII string\r
572 that identifies the module being measured.\r
573 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
574 @param Identifier 32-bit identifier. If the value is 0, the created record\r
575 is same as the one created by StartPerformanceMeasurement.\r
a0afd019 576\r
577 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
578 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
579\r
580**/\r
581RETURN_STATUS\r
582EFIAPI\r
f0da4d7d 583StartPerformanceMeasurementEx (\r
a0afd019 584 IN CONST VOID *Handle, OPTIONAL\r
585 IN CONST CHAR8 *Token, OPTIONAL\r
586 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
587 IN UINT64 TimeStamp,\r
588 IN UINT32 Identifier\r
a0afd019 589 )\r
590{\r
f0da4d7d 591 return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
a0afd019 592}\r
593\r
594/**\r
595 Searches the performance measurement log from the beginning of the log\r
596 for the first matching record that contains a zero end time and fills in a valid end time.\r
597\r
598 Searches the performance measurement log from the beginning of the log\r
7a9395cd 599 for the first record that matches Handle, Token and Module and has an end time value of zero.\r
a0afd019 600 If the record can not be found then return RETURN_NOT_FOUND.\r
601 If the record is found and TimeStamp is not zero,\r
602 then the end time in the record is filled in with the value specified by TimeStamp.\r
603 If the record is found and TimeStamp is zero, then the end time in the matching record\r
604 is filled in with the current time stamp value.\r
605\r
606 @param Handle Pointer to environment specific context used\r
607 to identify the component being measured.\r
608 @param Token Pointer to a Null-terminated ASCII string\r
609 that identifies the component being measured.\r
610 @param Module Pointer to a Null-terminated ASCII string\r
611 that identifies the module being measured.\r
612 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
613 @param Identifier 32-bit identifier. If the value is 0, the found record\r
614 is same as the one found by EndPerformanceMeasurement.\r
a0afd019 615\r
616 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
617 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
618\r
619**/\r
620RETURN_STATUS\r
621EFIAPI\r
f0da4d7d 622EndPerformanceMeasurementEx (\r
a0afd019 623 IN CONST VOID *Handle, OPTIONAL\r
624 IN CONST CHAR8 *Token, OPTIONAL\r
625 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
626 IN UINT64 TimeStamp,\r
627 IN UINT32 Identifier\r
a0afd019 628 )\r
629{\r
f0da4d7d 630 return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
a0afd019 631}\r
632\r
633/**\r
634 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
f0da4d7d
SZ
635 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
636 and then assign the Identifier with 0.\r
a0afd019 637\r
638 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
639 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
640 and the key for the second entry in the log is returned. If the performance log is empty,\r
641 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
642 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
643 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
644 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
645 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
646 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
f0da4d7d 647 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
a0afd019 648 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
649 If Handle is NULL, then ASSERT().\r
650 If Token is NULL, then ASSERT().\r
651 If Module is NULL, then ASSERT().\r
652 If StartTimeStamp is NULL, then ASSERT().\r
653 If EndTimeStamp is NULL, then ASSERT().\r
f0da4d7d 654 If Identifier is NULL, then ASSERT().\r
a0afd019 655\r
656 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
657 0, then the first performance measurement log entry is retrieved.\r
857dfc45 658 On exit, the key of the next performance log entry.\r
a0afd019 659 @param Handle Pointer to environment specific context used to identify the component\r
660 being measured.\r
661 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
662 being measured.\r
663 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
664 being measured.\r
665 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
666 was started.\r
667 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
668 was ended.\r
f0da4d7d 669 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
a0afd019 670\r
671 @return The key for the next performance log entry (in general case).\r
672\r
673**/\r
674UINTN\r
675EFIAPI\r
f0da4d7d
SZ
676GetPerformanceMeasurementEx (\r
677 IN UINTN LogEntryKey, \r
a0afd019 678 OUT CONST VOID **Handle,\r
679 OUT CONST CHAR8 **Token,\r
680 OUT CONST CHAR8 **Module,\r
681 OUT UINT64 *StartTimeStamp,\r
f0da4d7d
SZ
682 OUT UINT64 *EndTimeStamp,\r
683 OUT UINT32 *Identifier\r
a0afd019 684 )\r
685{\r
f0da4d7d
SZ
686 EFI_STATUS Status;\r
687 GAUGE_DATA_ENTRY_EX *GaugeData;\r
a0afd019 688\r
952671b3 689 GaugeData = NULL;\r
690 \r
a0afd019 691 ASSERT (Handle != NULL);\r
692 ASSERT (Token != NULL);\r
693 ASSERT (Module != NULL);\r
694 ASSERT (StartTimeStamp != NULL);\r
695 ASSERT (EndTimeStamp != NULL);\r
f0da4d7d 696 ASSERT (Identifier != NULL);\r
a0afd019 697\r
f0da4d7d 698 Status = GetGaugeEx (LogEntryKey++, &GaugeData);\r
a0afd019 699\r
700 //\r
701 // Make sure that LogEntryKey is a valid log entry key,\r
702 //\r
703 ASSERT (Status != EFI_INVALID_PARAMETER);\r
704\r
705 if (EFI_ERROR (Status)) {\r
706 //\r
707 // The LogEntryKey is the last entry (equals to the total entry number).\r
708 //\r
709 return 0;\r
710 }\r
711\r
712 ASSERT (GaugeData != NULL);\r
713\r
714 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
715 *Token = GaugeData->Token;\r
716 *Module = GaugeData->Module;\r
717 *StartTimeStamp = GaugeData->StartTimeStamp;\r
718 *EndTimeStamp = GaugeData->EndTimeStamp;\r
f0da4d7d 719 *Identifier = GaugeData->Identifier;\r
a0afd019 720\r
721 return LogEntryKey;\r
722}\r
723\r
f0da4d7d
SZ
724/**\r
725 Adds a record at the end of the performance measurement log\r
726 that records the start time of a performance measurement.\r
727\r
728 Adds a record to the end of the performance measurement log\r
729 that contains the Handle, Token, and Module.\r
730 The end time of the new record must be set to zero.\r
731 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
732 If TimeStamp is zero, the start time in the record is filled in with the value\r
733 read from the current time stamp.\r
734\r
735 @param Handle Pointer to environment specific context used\r
736 to identify the component being measured.\r
737 @param Token Pointer to a Null-terminated ASCII string\r
738 that identifies the component being measured.\r
739 @param Module Pointer to a Null-terminated ASCII string\r
740 that identifies the module being measured.\r
741 @param TimeStamp 64-bit time stamp.\r
742\r
743 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
744 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
745\r
746**/\r
747RETURN_STATUS\r
748EFIAPI\r
749StartPerformanceMeasurement (\r
750 IN CONST VOID *Handle, OPTIONAL\r
751 IN CONST CHAR8 *Token, OPTIONAL\r
752 IN CONST CHAR8 *Module, OPTIONAL\r
753 IN UINT64 TimeStamp\r
754 )\r
755{\r
756 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
757}\r
758\r
759/**\r
760 Searches the performance measurement log from the beginning of the log\r
761 for the first matching record that contains a zero end time and fills in a valid end time.\r
762\r
763 Searches the performance measurement log from the beginning of the log\r
764 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
765 If the record can not be found then return RETURN_NOT_FOUND.\r
766 If the record is found and TimeStamp is not zero,\r
767 then the end time in the record is filled in with the value specified by TimeStamp.\r
768 If the record is found and TimeStamp is zero, then the end time in the matching record\r
769 is filled in with the current time stamp value.\r
770\r
771 @param Handle Pointer to environment specific context used\r
772 to identify the component being measured.\r
773 @param Token Pointer to a Null-terminated ASCII string\r
774 that identifies the component being measured.\r
775 @param Module Pointer to a Null-terminated ASCII string\r
776 that identifies the module being measured.\r
777 @param TimeStamp 64-bit time stamp.\r
778\r
779 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
780 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
781\r
782**/\r
783RETURN_STATUS\r
784EFIAPI\r
785EndPerformanceMeasurement (\r
786 IN CONST VOID *Handle, OPTIONAL\r
787 IN CONST CHAR8 *Token, OPTIONAL\r
788 IN CONST CHAR8 *Module, OPTIONAL\r
789 IN UINT64 TimeStamp\r
790 )\r
791{\r
792 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
793}\r
794\r
795/**\r
796 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
797 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
798 and then eliminate the Identifier.\r
799\r
800 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
801 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
802 and the key for the second entry in the log is returned. If the performance log is empty,\r
803 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
804 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
805 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
806 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
807 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
808 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
809 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
810 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
811 If Handle is NULL, then ASSERT().\r
812 If Token is NULL, then ASSERT().\r
813 If Module is NULL, then ASSERT().\r
814 If StartTimeStamp is NULL, then ASSERT().\r
815 If EndTimeStamp is NULL, then ASSERT().\r
816\r
817 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
818 0, then the first performance measurement log entry is retrieved.\r
819 On exit, the key of the next performance log entry.\r
820 @param Handle Pointer to environment specific context used to identify the component\r
821 being measured.\r
822 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
823 being measured.\r
824 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
825 being measured.\r
826 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
827 was started.\r
828 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
829 was ended.\r
830\r
831 @return The key for the next performance log entry (in general case).\r
832\r
833**/\r
834UINTN\r
835EFIAPI\r
836GetPerformanceMeasurement (\r
837 IN UINTN LogEntryKey,\r
838 OUT CONST VOID **Handle,\r
839 OUT CONST CHAR8 **Token,\r
840 OUT CONST CHAR8 **Module,\r
841 OUT UINT64 *StartTimeStamp,\r
842 OUT UINT64 *EndTimeStamp\r
843 )\r
844{\r
845 UINT32 Identifier;\r
846 return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
847}\r
848\r
a0afd019 849/**\r
850 Returns TRUE if the performance measurement macros are enabled.\r
851\r
852 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
853 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
854\r
855 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
856 PcdPerformanceLibraryPropertyMask is set.\r
857 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
858 PcdPerformanceLibraryPropertyMask is clear.\r
859\r
860**/\r
861BOOLEAN\r
862EFIAPI\r
863PerformanceMeasurementEnabled (\r
864 VOID\r
865 )\r
866{\r
867 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
868}\r