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