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