]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
MdeModulePkg/PeiPerformance:Updated to track FPDT record in PEI phase
[mirror_edk2.git] / MdeModulePkg / Library / PeiPerformanceLib / PeiPerformanceLib.c
CommitLineData
8dbae30d 1/** @file\r
857dfc45 2 Performance library instance used in PEI phase.\r
3\r
4 This file implements all APIs in Performance Library class in MdePkg. It creates\r
5 performance logging GUIDed HOB on the first performance logging and then logs the\r
6 performance data to the GUIDed HOB. Due to the limitation of temporary RAM, the maximum\r
7c50b343
CS
7 number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries or \r
8 PcdMaxPeiPerformanceLogEntries16.\r
a0afd019 9\r
9169f676 10Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
7c50b343 11(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
cd5ebaa0 12This program and the accompanying materials\r
a0afd019 13are licensed and made available under the terms and conditions of the BSD License\r
14which accompanies this distribution. The full text of the license may be found at\r
15http://opensource.org/licenses/bsd-license.php\r
16\r
17THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
8dbae30d 20**/\r
a0afd019 21\r
ed7748fe 22\r
a0afd019 23#include <PiPei.h>\r
ed7748fe 24\r
9169f676 25#include <Guid/ExtendedFirmwarePerformance.h>\r
ed7748fe 26\r
a0afd019 27#include <Library/PerformanceLib.h>\r
28#include <Library/DebugLib.h>\r
29#include <Library/HobLib.h>\r
30#include <Library/BaseLib.h>\r
31#include <Library/TimerLib.h>\r
32#include <Library/PcdLib.h>\r
33#include <Library/BaseMemoryLib.h>\r
34\r
9169f676
DB
35#define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
36#define MAX_RECORD_SIZE (sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE)\r
a0afd019 37\r
38/**\r
9169f676 39Check whether the Token is a known one which is uesed by core.\r
a0afd019 40\r
9169f676 41@param Token Pointer to a Null-terminated ASCII string\r
a0afd019 42\r
9169f676
DB
43@retval TRUE Is a known one used by core.\r
44@retval FALSE Not a known one.\r
a0afd019 45\r
46**/\r
9169f676
DB
47BOOLEAN\r
48IsKnownTokens (\r
49 IN CONST CHAR8 *Token\r
a0afd019 50 )\r
51{\r
9169f676
DB
52 if (AsciiStrCmp (Token, SEC_TOK) == 0 ||\r
53 AsciiStrCmp (Token, PEI_TOK) == 0 ||\r
54 AsciiStrCmp (Token, DXE_TOK) == 0 ||\r
55 AsciiStrCmp (Token, BDS_TOK) == 0 ||\r
56 AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||\r
57 AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||\r
58 AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||\r
59 AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||\r
60 AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||\r
61 AsciiStrCmp (Token, PEIM_TOK) == 0) {\r
62 return TRUE;\r
63 } else {\r
64 return FALSE;\r
65 }\r
66}\r
f0da4d7d 67\r
9169f676
DB
68/**\r
69Check whether the ID is a known one which map to the known Token.\r
a0afd019 70\r
9169f676 71@param Identifier 32-bit identifier.\r
a0afd019 72\r
9169f676
DB
73@retval TRUE Is a known one used by core.\r
74@retval FALSE Not a known one.\r
f0da4d7d 75\r
9169f676
DB
76**/\r
77BOOLEAN\r
78IsKnownID (\r
79 IN UINT32 Identifier\r
80 )\r
81{\r
82 if (Identifier == MODULE_START_ID ||\r
83 Identifier == MODULE_END_ID ||\r
84 Identifier == MODULE_LOADIMAGE_START_ID ||\r
85 Identifier == MODULE_LOADIMAGE_END_ID ||\r
86 Identifier == MODULE_DB_START_ID ||\r
87 Identifier == MODULE_DB_END_ID ||\r
88 Identifier == MODULE_DB_SUPPORT_START_ID ||\r
89 Identifier == MODULE_DB_SUPPORT_END_ID ||\r
90 Identifier == MODULE_DB_STOP_START_ID ||\r
91 Identifier == MODULE_DB_STOP_END_ID) {\r
92 return TRUE;\r
a0afd019 93 } else {\r
9169f676 94 return FALSE;\r
a0afd019 95 }\r
a0afd019 96}\r
97\r
98/**\r
9169f676 99 Get the FPDT record info.\r
a0afd019 100\r
9169f676 101 @param IsStart TRUE if the performance log is start log.\r
a0afd019 102 @param Handle Pointer to environment specific context used\r
103 to identify the component being measured.\r
104 @param Token Pointer to a Null-terminated ASCII string\r
105 that identifies the component being measured.\r
106 @param Module Pointer to a Null-terminated ASCII string\r
107 that identifies the module being measured.\r
9169f676 108 @param RecordInfo On return, pointer to the info of the record.\r
a0afd019 109\r
9169f676
DB
110 @retval EFI_SUCCESS Get record info successfully.\r
111 @retval EFI_UNSUPPORTED No matched FPDT record.\r
a0afd019 112\r
113**/\r
9169f676
DB
114EFI_STATUS\r
115GetFpdtRecordInfo (\r
116 IN BOOLEAN IsStart,\r
117 IN CONST VOID *Handle,\r
118 IN CONST CHAR8 *Token,\r
119 IN CONST CHAR8 *Module,\r
120 OUT FPDT_BASIC_RECORD_INFO *RecordInfo\r
a0afd019 121 )\r
122{\r
9169f676
DB
123 UINTN StringSize;\r
124 UINT16 RecordType;\r
a0afd019 125\r
9169f676 126 RecordType = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
a0afd019 127\r
9169f676
DB
128 //\r
129 // Get the ProgressID based on the Token.\r
130 // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.\r
131 //\r
132 if (Token != NULL) {\r
133 if (AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"\r
134 if (IsStart) {\r
135 RecordInfo->ProgressID = MODULE_LOADIMAGE_START_ID;\r
136 } else {\r
137 RecordInfo->ProgressID = MODULE_LOADIMAGE_END_ID;\r
138 }\r
139 if(!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
140 RecordType = FPDT_GUID_QWORD_EVENT_TYPE;\r
141 }\r
142 } else if (AsciiStrCmp (Token, SEC_TOK) == 0 || // "SEC"\r
143 AsciiStrCmp (Token, PEI_TOK) == 0) { // "PEI"\r
144 if (IsStart) {\r
145 RecordInfo->ProgressID = PERF_CROSSMODULE_START_ID;\r
146 } else {\r
147 RecordInfo->ProgressID = PERF_CROSSMODULE_END_ID;\r
148 }\r
149 } else if (AsciiStrCmp (Token, PEIM_TOK) == 0) { // "PEIM"\r
150 if (IsStart) {\r
151 RecordInfo->ProgressID = MODULE_START_ID;\r
152 } else {\r
153 RecordInfo->ProgressID = MODULE_END_ID;\r
154 }\r
155 if(!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
156 RecordType = FPDT_GUID_EVENT_TYPE;\r
157 }\r
158 } else { //Pref used in Modules.\r
159 if (IsStart) {\r
160 RecordInfo->ProgressID = PERF_INMODULE_START_ID;\r
161 } else {\r
162 RecordInfo->ProgressID = PERF_INMODULE_END_ID;\r
163 }\r
164 }\r
165 } else if (Module != NULL || Handle != NULL) { //Pref used in Modules.\r
166 if (IsStart) {\r
167 RecordInfo->ProgressID = PERF_INMODULE_START_ID;\r
168 } else {\r
169 RecordInfo->ProgressID = PERF_INMODULE_END_ID;\r
170 }\r
171 } else {\r
172 return EFI_UNSUPPORTED;\r
a0afd019 173 }\r
9169f676
DB
174\r
175 //\r
176 // Get the Guid and string.\r
177 //\r
178 if(PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
179 RecordInfo->RecordSize = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE;\r
180 } else {\r
181 switch (RecordType) {\r
182 case FPDT_GUID_EVENT_TYPE:\r
183 RecordInfo->RecordSize = sizeof (FPDT_GUID_EVENT_RECORD);\r
a0afd019 184 break;\r
9169f676
DB
185\r
186 case FPDT_GUID_QWORD_EVENT_TYPE:\r
187 RecordInfo->RecordSize = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
188 break;\r
189\r
190 case FPDT_DYNAMIC_STRING_EVENT_TYPE:\r
191 if (Token != NULL) {\r
192 StringSize = AsciiStrSize (Token);\r
193 } else if (Module != NULL) {\r
194 StringSize = AsciiStrSize (Module);\r
195 } else {\r
196 StringSize = STRING_SIZE;\r
197 }\r
198 RecordInfo->RecordSize = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + StringSize);\r
199 break;\r
200\r
201 default:\r
202 //\r
203 // Other type is unsupported in PEI phase yet, return EFI_UNSUPPORTED\r
204 //\r
205 return EFI_UNSUPPORTED;\r
a0afd019 206 }\r
207 }\r
9169f676
DB
208 RecordInfo->Type = RecordType;\r
209 return EFI_SUCCESS;\r
a0afd019 210}\r
211\r
212/**\r
9169f676 213 Convert PEI performance log to FPDT String boot record.\r
a0afd019 214\r
9169f676 215 @param IsStart TRUE if the performance log is start log.\r
a0afd019 216 @param Handle Pointer to environment specific context used\r
217 to identify the component being measured.\r
218 @param Token Pointer to a Null-terminated ASCII string\r
219 that identifies the component being measured.\r
220 @param Module Pointer to a Null-terminated ASCII string\r
221 that identifies the module being measured.\r
9169f676 222 @param Ticker 64-bit time stamp.\r
f0da4d7d 223 @param Identifier 32-bit identifier. If the value is 0, the created record\r
9169f676 224 is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\r
a0afd019 225\r
9169f676
DB
226 @retval EFI_SUCCESS Add FPDT boot record.\r
227 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
228 @retval EFI_UNSUPPORTED No matched FPDT record.\r
a0afd019 229\r
230**/\r
9169f676
DB
231EFI_STATUS\r
232InsertPeiFpdtMeasurement (\r
233 IN BOOLEAN IsStart,\r
a0afd019 234 IN CONST VOID *Handle, OPTIONAL\r
235 IN CONST CHAR8 *Token, OPTIONAL\r
236 IN CONST CHAR8 *Module, OPTIONAL\r
9169f676 237 IN UINT64 Ticker,\r
f0da4d7d 238 IN UINT32 Identifier\r
a0afd019 239 )\r
240{\r
9169f676
DB
241 EFI_HOB_GUID_TYPE *GuidHob;\r
242 UINTN PeiPerformanceSize;\r
243 UINT8 *PeiFirmwarePerformance;\r
244 FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;\r
245 FPDT_RECORD_PTR FpdtRecordPtr;\r
246 FPDT_BASIC_RECORD_INFO RecordInfo;\r
247 CONST VOID *ModuleGuid;\r
248 UINTN DestMax;\r
249 UINTN StrLength;\r
250 CONST CHAR8 *StringPtr;\r
251 EFI_STATUS Status;\r
252 UINT16 PeiPerformanceLogEntries;\r
253 UINT64 TimeStamp;\r
254\r
255 StringPtr = NULL;\r
256 FpdtRecordPtr.RecordHeader = NULL;\r
257 PeiPerformanceLogHeader = NULL;\r
258\r
259 //\r
260 // Get record info (type, size, ProgressID and Module Guid).\r
261 //\r
262 Status = GetFpdtRecordInfo (IsStart, Handle, Token, Module, &RecordInfo);\r
263 if (EFI_ERROR (Status)) {\r
264 return Status;\r
265 }\r
266\r
267 //\r
268 // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.\r
269 // !!! Note: If the Pref is not the known Token used in the core but have same\r
270 // ID with the core Token, this case will not be supported.\r
271 // And in currtnt usage mode, for the unkown ID, there is a general rule:\r
272 // If it is start pref: the lower 4 bits of the ID should be 0.\r
273 // If it is end pref: the lower 4 bits of the ID should not be 0.\r
274 // If input ID doesn't follow the rule, we will adjust it.\r
275 //\r
276 if ((Identifier != 0) && (IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {\r
277 return EFI_UNSUPPORTED;\r
278 } else if ((Identifier != 0) && (!IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {\r
279 if (IsStart && ((Identifier & 0x000F) != 0)) {\r
280 Identifier &= 0xFFF0;\r
281 } else if ((!IsStart) && ((Identifier & 0x000F) == 0)) {\r
282 Identifier += 1;\r
283 }\r
284 RecordInfo.ProgressID = (UINT16)Identifier;\r
285 }\r
7c50b343 286\r
9169f676
DB
287 //\r
288 // Get the number of PeiPerformanceLogEntries form PCD.\r
289 //\r
7c50b343
CS
290 PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
291 PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
292 PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
a0afd019 293\r
9169f676
DB
294 //\r
295 // Create GUID HOB Data.\r
296 //\r
297 GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);\r
298 PeiFirmwarePerformance = NULL;\r
299 while (GuidHob != NULL) {\r
300 //\r
301 // PEI Performance HOB was found, then return the existing one.\r
302 //\r
303 PeiFirmwarePerformance = (UINT8*)GET_GUID_HOB_DATA (GuidHob);\r
304 PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
305 if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize > PeiPerformanceLogEntries * MAX_RECORD_SIZE) {\r
306 PeiPerformanceLogHeader->HobIsFull = TRUE;\r
307 }\r
308 if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize <= PeiPerformanceLogEntries * MAX_RECORD_SIZE) {\r
309 FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + PeiPerformanceLogHeader->SizeOfAllEntries);\r
310 break;\r
311 }\r
312 //\r
313 // Previous HOB is used, then find next one.\r
314 //\r
315 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
316 }\r
a0afd019 317\r
9169f676
DB
318 if (GuidHob == NULL) {\r
319 //\r
320 // PEI Performance HOB was not found, then build one.\r
321 //\r
322 PeiPerformanceSize = sizeof (FPDT_PEI_EXT_PERF_HEADER) +\r
323 MAX_RECORD_SIZE * PeiPerformanceLogEntries;\r
324 PeiFirmwarePerformance = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);\r
325 if (PeiFirmwarePerformance != NULL) {\r
326 ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);\r
327 }\r
328 PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
329 FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));\r
a0afd019 330 }\r
a0afd019 331\r
9169f676
DB
332 if (PeiFirmwarePerformance == NULL) {\r
333 //\r
334 // there is no enough resource to store performance data\r
335 //\r
336 return EFI_OUT_OF_RESOURCES;\r
337 }\r
338\r
339 //\r
340 // Get the TimeStamp.\r
341 //\r
342 if (Ticker == 0) {\r
343 Ticker = GetPerformanceCounter ();\r
344 TimeStamp = GetTimeInNanoSecond (Ticker);\r
345 } else if (Ticker == 1) {\r
346 TimeStamp = 0;\r
347 } else {\r
348 TimeStamp = GetTimeInNanoSecond (Ticker);\r
a0afd019 349 }\r
9169f676
DB
350\r
351 //\r
352 // Get the ModuleGuid.\r
353 //\r
354 if (Handle != NULL) {\r
355 ModuleGuid = Handle;\r
356 } else {\r
357 ModuleGuid = &gEfiCallerIdGuid;\r
a0afd019 358 }\r
359\r
9169f676
DB
360 switch (RecordInfo.Type) {\r
361 case FPDT_GUID_EVENT_TYPE:\r
362 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;\r
363 FpdtRecordPtr.GuidEvent->Header.Length = RecordInfo.RecordSize;;\r
364 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
365 FpdtRecordPtr.GuidEvent->ProgressID = RecordInfo.ProgressID;\r
366 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;\r
367 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
368 PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;\r
369 break;\r
370\r
371 case FPDT_GUID_QWORD_EVENT_TYPE:\r
372 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;\r
373 FpdtRecordPtr.GuidQwordEvent->Header.Length = RecordInfo.RecordSize;;\r
374 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
375 FpdtRecordPtr.GuidQwordEvent->ProgressID = RecordInfo.ProgressID;\r
376 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;\r
377 PeiPerformanceLogHeader->LoadImageCount++;\r
378 FpdtRecordPtr.GuidQwordEvent->Qword = PeiPerformanceLogHeader->LoadImageCount;\r
379 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
380 PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;\r
381 break;\r
382\r
383 case FPDT_DYNAMIC_STRING_EVENT_TYPE:\r
384 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
385 FpdtRecordPtr.DynamicStringEvent->Header.Length = RecordInfo.RecordSize;\r
386 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
387 FpdtRecordPtr.DynamicStringEvent->ProgressID = RecordInfo.ProgressID;\r
388 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
389 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
390 PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;\r
391\r
392 if (Token != NULL) {\r
393 StringPtr = Token;\r
394 } else if (Module != NULL) {\r
395 StringPtr = Module;\r
396 }\r
397 if (StringPtr != NULL && AsciiStrLen (StringPtr) != 0) {\r
398 DestMax = (RecordInfo.RecordSize - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)) / sizeof (CHAR8);\r
399 StrLength = AsciiStrLen (StringPtr);\r
400 if (StrLength >= DestMax) {\r
401 StrLength = DestMax -1;\r
402 }\r
403 AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StrLength);\r
404 } else {\r
405 AsciiStrCpyS (FpdtRecordPtr.DynamicStringEvent->String, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, "unknown name");\r
406 }\r
407 break;\r
f0da4d7d 408\r
9169f676
DB
409 default:\r
410 //\r
411 // Record is not supported in current PEI phase, return EFI_ABORTED\r
412 //\r
413 return EFI_UNSUPPORTED;\r
a0afd019 414 }\r
a0afd019 415\r
9169f676 416 return EFI_SUCCESS;\r
a0afd019 417}\r
418\r
419/**\r
9169f676
DB
420 Creates a record for the beginning of a performance measurement.\r
421\r
422 If TimeStamp is zero, then this function reads the current time stamp\r
423 and adds that time stamp value to the record as the start time.\r
424\r
425 If TimeStamp is one, then this function reads 0 as the start time.\r
a0afd019 426\r
9169f676
DB
427 If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
428\r
429 @param Handle Pointer to environment specific context used\r
430 to identify the component being measured.\r
431 @param Token Pointer to a Null-terminated ASCII string\r
432 that identifies the component being measured.\r
433 @param Module Pointer to a Null-terminated ASCII string\r
434 that identifies the module being measured.\r
435 @param TimeStamp 64-bit time stamp.\r
436 @param Identifier 32-bit identifier. If the value is 0, the created record\r
437 is same as the one created by StartPerformanceMeasurement.\r
438\r
439 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
440 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
441\r
442**/\r
443RETURN_STATUS\r
444EFIAPI\r
445StartPerformanceMeasurementEx (\r
446 IN CONST VOID *Handle, OPTIONAL\r
447 IN CONST CHAR8 *Token, OPTIONAL\r
448 IN CONST CHAR8 *Module, OPTIONAL\r
449 IN UINT64 TimeStamp,\r
450 IN UINT32 Identifier\r
451 )\r
452{\r
453 return InsertPeiFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
454}\r
455\r
456/**\r
457\r
458 Creates a record for the end of a performance measurement.\r
459\r
460 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
461 If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
462 If the TimeStamp is one, then this function reads 0 as the end time.\r
a0afd019 463\r
464 @param Handle Pointer to environment specific context used\r
465 to identify the component being measured.\r
466 @param Token Pointer to a Null-terminated ASCII string\r
467 that identifies the component being measured.\r
468 @param Module Pointer to a Null-terminated ASCII string\r
469 that identifies the module being measured.\r
470 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
471 @param Identifier 32-bit identifier. If the value is 0, the found record\r
472 is same as the one found by EndPerformanceMeasurement.\r
a0afd019 473\r
474 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
475 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
476\r
477**/\r
478RETURN_STATUS\r
479EFIAPI\r
f0da4d7d 480EndPerformanceMeasurementEx (\r
a0afd019 481 IN CONST VOID *Handle, OPTIONAL\r
482 IN CONST CHAR8 *Token, OPTIONAL\r
483 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
484 IN UINT64 TimeStamp,\r
485 IN UINT32 Identifier\r
a0afd019 486 )\r
487{\r
9169f676 488 return InsertPeiFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
a0afd019 489}\r
490\r
491/**\r
492 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
f0da4d7d
SZ
493 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
494 and then assign the Identifier with 0.\r
a0afd019 495\r
496 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
497 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
498 and the key for the second entry in the log is returned. If the performance log is empty,\r
499 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
500 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
501 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
502 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
503 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
504 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
f0da4d7d 505 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
a0afd019 506 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
507 If Handle is NULL, then ASSERT().\r
508 If Token is NULL, then ASSERT().\r
509 If Module is NULL, then ASSERT().\r
510 If StartTimeStamp is NULL, then ASSERT().\r
511 If EndTimeStamp is NULL, then ASSERT().\r
f0da4d7d 512 If Identifier is NULL, then ASSERT().\r
a0afd019 513\r
9169f676
DB
514 !!!NOT Support yet!!!\r
515\r
a0afd019 516 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
517 0, then the first performance measurement log entry is retrieved.\r
f0da4d7d 518 On exit, the key of the next performance of entry entry.\r
a0afd019 519 @param Handle Pointer to environment specific context used to identify the component\r
520 being measured.\r
521 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
522 being measured.\r
523 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
524 being measured.\r
525 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
526 was started.\r
527 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
528 was ended.\r
f0da4d7d 529 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
a0afd019 530\r
531 @return The key for the next performance log entry (in general case).\r
532\r
533**/\r
534UINTN\r
535EFIAPI\r
f0da4d7d 536GetPerformanceMeasurementEx (\r
a0afd019 537 IN UINTN LogEntryKey,\r
538 OUT CONST VOID **Handle,\r
539 OUT CONST CHAR8 **Token,\r
540 OUT CONST CHAR8 **Module,\r
541 OUT UINT64 *StartTimeStamp,\r
f0da4d7d
SZ
542 OUT UINT64 *EndTimeStamp,\r
543 OUT UINT32 *Identifier\r
a0afd019 544 )\r
545{\r
9169f676 546 return 0;\r
a0afd019 547}\r
548\r
f0da4d7d
SZ
549/**\r
550 Creates a record for the beginning of a performance measurement.\r
551\r
f0da4d7d
SZ
552 If TimeStamp is zero, then this function reads the current time stamp\r
553 and adds that time stamp value to the record as the start time.\r
554\r
9169f676
DB
555 If TimeStamp is one, then this function reads 0 as the start time.\r
556\r
557 If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
558\r
559\r
f0da4d7d
SZ
560 @param Handle Pointer to environment specific context used\r
561 to identify the component being measured.\r
562 @param Token Pointer to a Null-terminated ASCII string\r
563 that identifies the component being measured.\r
564 @param Module Pointer to a Null-terminated ASCII string\r
565 that identifies the module being measured.\r
566 @param TimeStamp 64-bit time stamp.\r
567\r
568 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
569 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
570\r
571**/\r
572RETURN_STATUS\r
573EFIAPI\r
574StartPerformanceMeasurement (\r
575 IN CONST VOID *Handle, OPTIONAL\r
576 IN CONST CHAR8 *Token, OPTIONAL\r
577 IN CONST CHAR8 *Module, OPTIONAL\r
578 IN UINT64 TimeStamp\r
579 )\r
580{\r
9169f676 581 return InsertPeiFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, 0);\r
f0da4d7d
SZ
582}\r
583\r
584/**\r
f0da4d7d 585\r
9169f676
DB
586 Creates a record for the end of a performance measurement.\r
587\r
588 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
589 If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
590 If the TimeStamp is one, then this function reads 0 as the end time.\r
f0da4d7d
SZ
591\r
592 @param Handle Pointer to environment specific context used\r
593 to identify the component being measured.\r
594 @param Token Pointer to a Null-terminated ASCII string\r
595 that identifies the component being measured.\r
596 @param Module Pointer to a Null-terminated ASCII string\r
597 that identifies the module being measured.\r
598 @param TimeStamp 64-bit time stamp.\r
599\r
600 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
601 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
602\r
603**/\r
604RETURN_STATUS\r
605EFIAPI\r
606EndPerformanceMeasurement (\r
607 IN CONST VOID *Handle, OPTIONAL\r
608 IN CONST CHAR8 *Token, OPTIONAL\r
609 IN CONST CHAR8 *Module, OPTIONAL\r
610 IN UINT64 TimeStamp\r
611 )\r
612{\r
9169f676 613 return InsertPeiFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, 0);\r
f0da4d7d
SZ
614}\r
615\r
616/**\r
617 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
618 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
619 and then eliminate the Identifier.\r
620\r
621 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
622 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
623 and the key for the second entry in the log is returned. If the performance log is empty,\r
624 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
625 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
626 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
627 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
628 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
629 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
630 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
631 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
632 If Handle is NULL, then ASSERT().\r
633 If Token is NULL, then ASSERT().\r
634 If Module is NULL, then ASSERT().\r
635 If StartTimeStamp is NULL, then ASSERT().\r
636 If EndTimeStamp is NULL, then ASSERT().\r
637\r
9169f676
DB
638 NOT Support yet.\r
639\r
f0da4d7d
SZ
640 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
641 0, then the first performance measurement log entry is retrieved.\r
642 On exit, the key of the next performance of entry entry.\r
643 @param Handle Pointer to environment specific context used to identify the component\r
644 being measured.\r
645 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
646 being measured.\r
647 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
648 being measured.\r
649 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
650 was started.\r
651 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
652 was ended.\r
653\r
654 @return The key for the next performance log entry (in general case).\r
655\r
656**/\r
657UINTN\r
658EFIAPI\r
659GetPerformanceMeasurement (\r
660 IN UINTN LogEntryKey,\r
661 OUT CONST VOID **Handle,\r
662 OUT CONST CHAR8 **Token,\r
663 OUT CONST CHAR8 **Module,\r
664 OUT UINT64 *StartTimeStamp,\r
665 OUT UINT64 *EndTimeStamp\r
666 )\r
667{\r
9169f676 668 return 0;\r
f0da4d7d
SZ
669}\r
670\r
a0afd019 671/**\r
672 Returns TRUE if the performance measurement macros are enabled.\r
673\r
674 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
675 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
676\r
677 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
678 PcdPerformanceLibraryPropertyMask is set.\r
679 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
680 PcdPerformanceLibraryPropertyMask is clear.\r
681\r
682**/\r
683BOOLEAN\r
684EFIAPI\r
685PerformanceMeasurementEnabled (\r
686 VOID\r
687 )\r
688{\r
689 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
690}\r