]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
MdeModulePkg: Change OPTIONAL keyword usage style
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
13
14 **/
15
16
17 #include <PiPei.h>
18
19 #include <Guid/ExtendedFirmwarePerformance.h>
20 #include <Guid/PerformanceMeasurement.h>
21
22 #include <Library/PerformanceLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/HobLib.h>
25 #include <Library/BaseLib.h>
26 #include <Library/TimerLib.h>
27 #include <Library/PcdLib.h>
28 #include <Library/BaseMemoryLib.h>
29
30 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
31 #define PEI_MAX_RECORD_SIZE (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + STRING_SIZE)
32
33
34 /**
35 Return the pointer to the FPDT record in the allocated memory.
36
37 @param RecordSize The size of FPDT record.
38 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
39 @param PeiPerformanceLogHeader Pointer to the header of the PEI Performance records in the GUID Hob.
40
41 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
42 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
43 **/
44 EFI_STATUS
45 GetFpdtRecordPtr (
46 IN UINT8 RecordSize,
47 IN OUT FPDT_RECORD_PTR *FpdtRecordPtr,
48 IN OUT FPDT_PEI_EXT_PERF_HEADER **PeiPerformanceLogHeader
49 )
50 {
51 UINT16 PeiPerformanceLogEntries;
52 UINTN PeiPerformanceSize;
53 UINT8 *PeiFirmwarePerformance;
54 EFI_HOB_GUID_TYPE *GuidHob;
55
56 //
57 // Get the number of PeiPerformanceLogEntries form PCD.
58 //
59 PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?
60 PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :
61 PcdGet8 (PcdMaxPeiPerformanceLogEntries));
62
63 //
64 // Create GUID HOB Data.
65 //
66 GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);
67 PeiFirmwarePerformance = NULL;
68 while (GuidHob != NULL) {
69 //
70 // PEI Performance HOB was found, then return the existing one.
71 //
72 PeiFirmwarePerformance = (UINT8*)GET_GUID_HOB_DATA (GuidHob);
73 *PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
74 if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize > (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
75 (*PeiPerformanceLogHeader)->HobIsFull = TRUE;
76 }
77 if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize <= (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
78 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + (*PeiPerformanceLogHeader)->SizeOfAllEntries);
79 break;
80 }
81 //
82 // Previous HOB is used, then find next one.
83 //
84 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));
85 }
86
87 if (GuidHob == NULL) {
88 //
89 // PEI Performance HOB was not found, then build one.
90 //
91 PeiPerformanceSize = sizeof (FPDT_PEI_EXT_PERF_HEADER) +
92 PEI_MAX_RECORD_SIZE * PeiPerformanceLogEntries;
93 PeiFirmwarePerformance = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);
94 if (PeiFirmwarePerformance != NULL) {
95 ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);
96 (*PeiPerformanceLogHeader) = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
97 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));
98 }
99 }
100
101 if (PeiFirmwarePerformance == NULL) {
102 //
103 // there is no enough resource to store performance data
104 //
105 return EFI_OUT_OF_RESOURCES;
106 }
107
108 return EFI_SUCCESS;
109 }
110
111 /**
112 Check whether the Token is a known one which is uesed by core.
113
114 @param Token Pointer to a Null-terminated ASCII string
115
116 @retval TRUE Is a known one used by core.
117 @retval FALSE Not a known one.
118
119 **/
120 BOOLEAN
121 IsKnownTokens (
122 IN CONST CHAR8 *Token
123 )
124 {
125 if (Token == NULL) {
126 return FALSE;
127 }
128
129 if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
130 AsciiStrCmp (Token, PEI_TOK) == 0 ||
131 AsciiStrCmp (Token, DXE_TOK) == 0 ||
132 AsciiStrCmp (Token, BDS_TOK) == 0 ||
133 AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
134 AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||
135 AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||
136 AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||
137 AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||
138 AsciiStrCmp (Token, PEIM_TOK) == 0) {
139 return TRUE;
140 } else {
141 return FALSE;
142 }
143 }
144
145 /**
146 Check whether the ID is a known one which map to the known Token.
147
148 @param Identifier 32-bit identifier.
149
150 @retval TRUE Is a known one used by core.
151 @retval FALSE Not a known one.
152
153 **/
154 BOOLEAN
155 IsKnownID (
156 IN UINT32 Identifier
157 )
158 {
159 if (Identifier == MODULE_START_ID ||
160 Identifier == MODULE_END_ID ||
161 Identifier == MODULE_LOADIMAGE_START_ID ||
162 Identifier == MODULE_LOADIMAGE_END_ID ||
163 Identifier == MODULE_DB_START_ID ||
164 Identifier == MODULE_DB_END_ID ||
165 Identifier == MODULE_DB_SUPPORT_START_ID ||
166 Identifier == MODULE_DB_SUPPORT_END_ID ||
167 Identifier == MODULE_DB_STOP_START_ID ||
168 Identifier == MODULE_DB_STOP_END_ID) {
169 return TRUE;
170 } else {
171 return FALSE;
172 }
173 }
174
175 /**
176 Get the FPDT record identifier.
177
178 @param Attribute The attribute of the Record.
179 PerfStartEntry: Start Record.
180 PerfEndEntry: End Record.
181 @param Handle Pointer to environment specific context used to identify the component being measured.
182 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
183 @param ProgressID On return, pointer to the ProgressID.
184
185 @retval EFI_SUCCESS Get record info successfully.
186 @retval EFI_INVALID_PARAMETER No matched FPDT record.
187
188 **/
189 EFI_STATUS
190 GetFpdtRecordId (
191 IN BOOLEAN Attribute,
192 IN CONST VOID *Handle,
193 IN CONST CHAR8 *String,
194 OUT UINT16 *ProgressID
195 )
196 {
197 //
198 // Get the ProgressID based on the Token.
199 // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.
200 //
201 if (String != NULL) {
202 if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"
203 if (Attribute == PerfStartEntry) {
204 *ProgressID = MODULE_LOADIMAGE_START_ID;
205 } else {
206 *ProgressID = MODULE_LOADIMAGE_END_ID;
207 }
208 } else if (AsciiStrCmp (String, SEC_TOK) == 0 || // "SEC"
209 AsciiStrCmp (String, PEI_TOK) == 0) { // "PEI"
210 if (Attribute == PerfStartEntry) {
211 *ProgressID = PERF_CROSSMODULE_START_ID;
212 } else {
213 *ProgressID = PERF_CROSSMODULE_END_ID;
214 }
215 } else if (AsciiStrCmp (String, PEIM_TOK) == 0) { // "PEIM"
216 if (Attribute == PerfStartEntry) {
217 *ProgressID = MODULE_START_ID;
218 } else {
219 *ProgressID = MODULE_END_ID;
220 }
221 } else { //Pref used in Modules.
222 if (Attribute == PerfStartEntry) {
223 *ProgressID = PERF_INMODULE_START_ID;
224 } else {
225 *ProgressID = PERF_INMODULE_END_ID;
226 }
227 }
228 } else if (Handle != NULL) { //Pref used in Modules.
229 if (Attribute == PerfStartEntry) {
230 *ProgressID = PERF_INMODULE_START_ID;
231 } else {
232 *ProgressID = PERF_INMODULE_END_ID;
233 }
234 } else {
235 return EFI_INVALID_PARAMETER;
236 }
237
238 return EFI_SUCCESS;
239 }
240
241 /**
242 Copies the string from Source into Destination and updates Length with the
243 size of the string.
244
245 @param Destination - destination of the string copy
246 @param Source - pointer to the source string which will get copied
247 @param Length - pointer to a length variable to be updated
248
249 **/
250 VOID
251 CopyStringIntoPerfRecordAndUpdateLength (
252 IN OUT CHAR8 *Destination,
253 IN CONST CHAR8 *Source,
254 IN OUT UINT8 *Length
255 )
256 {
257 UINTN StringLen;
258 UINTN DestMax;
259
260 ASSERT (Source != NULL);
261
262 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
263 DestMax = STRING_SIZE;
264 } else {
265 DestMax = AsciiStrSize (Source);
266 if (DestMax > STRING_SIZE) {
267 DestMax = STRING_SIZE;
268 }
269 }
270 StringLen = AsciiStrLen (Source);
271 if (StringLen >= DestMax) {
272 StringLen = DestMax -1;
273 }
274
275 AsciiStrnCpyS(Destination, DestMax, Source, StringLen);
276 *Length += (UINT8)DestMax;
277
278 return;
279 }
280
281
282 /**
283 Convert PEI performance log to FPDT String boot record.
284
285 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
286 @param Guid - Pointer to a GUID.
287 @param String - Pointer to a string describing the measurement.
288 @param Ticker - 64-bit time stamp.
289 @param Address - Pointer to a location in memory relevant to the measurement.
290 @param PerfId - Performance identifier describing the type of measurement.
291 @param Attribute - The attribute of the measurement. According to attribute can create a start
292 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
293 or a general record for other Perf macros.
294
295 @retval EFI_SUCCESS - Successfully created performance record.
296 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
297 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
298 pointer or invalid PerfId.
299
300 **/
301 EFI_STATUS
302 InsertFpdtRecord (
303 IN CONST VOID *CallerIdentifier OPTIONAL,
304 IN CONST VOID *Guid OPTIONAL,
305 IN CONST CHAR8 *String OPTIONAL,
306 IN UINT64 Ticker,
307 IN UINT64 Address OPTIONAL,
308 IN UINT16 PerfId,
309 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
310 )
311 {
312 FPDT_RECORD_PTR FpdtRecordPtr;
313 CONST VOID *ModuleGuid;
314 CONST CHAR8 *StringPtr;
315 EFI_STATUS Status;
316 UINT64 TimeStamp;
317 FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;
318
319 StringPtr = NULL;
320 FpdtRecordPtr.RecordHeader = NULL;
321 PeiPerformanceLogHeader = NULL;
322
323 //
324 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
325 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
326 //
327 if (Attribute != PerfEntry) {
328 //
329 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
330 // !!! Note: If the Perf is not the known Token used in the core but have same
331 // ID with the core Token, this case will not be supported.
332 // And in currtnt usage mode, for the unkown ID, there is a general rule:
333 // If it is start pref: the lower 4 bits of the ID should be 0.
334 // If it is end pref: the lower 4 bits of the ID should not be 0.
335 // If input ID doesn't follow the rule, we will adjust it.
336 //
337 if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
338 return EFI_UNSUPPORTED;
339 } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
340 if (Attribute == PerfStartEntry && ((PerfId & 0x000F) != 0)) {
341 PerfId &= 0xFFF0;
342 } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {
343 PerfId += 1;
344 }
345 } else if (PerfId == 0) {
346 Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &PerfId);
347 if (EFI_ERROR (Status)) {
348 return Status;
349 }
350 }
351 }
352
353 //
354 // 2. Get the buffer to store the FPDT record.
355 //
356 Status = GetFpdtRecordPtr (PEI_MAX_RECORD_SIZE, &FpdtRecordPtr, &PeiPerformanceLogHeader);
357 if (EFI_ERROR (Status)) {
358 return Status;
359 }
360
361 //
362 // 3 Get the TimeStamp.
363 //
364 if (Ticker == 0) {
365 Ticker = GetPerformanceCounter ();
366 TimeStamp = GetTimeInNanoSecond (Ticker);
367 } else if (Ticker == 1) {
368 TimeStamp = 0;
369 } else {
370 TimeStamp = GetTimeInNanoSecond (Ticker);
371 }
372
373 //
374 // 4.Get the ModuleGuid.
375 //
376 if (CallerIdentifier != NULL) {
377 ModuleGuid = CallerIdentifier;
378 } else {
379 ModuleGuid = &gEfiCallerIdGuid;
380 }
381
382 //
383 // 5. Fill in the FPDT record according to different Performance Identifier.
384 //
385 switch (PerfId) {
386 case MODULE_START_ID:
387 case MODULE_END_ID:
388 StringPtr = PEIM_TOK;
389 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
390 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;
391 FpdtRecordPtr.GuidEvent->Header.Length = sizeof (FPDT_GUID_EVENT_RECORD);
392 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;
393 FpdtRecordPtr.GuidEvent->ProgressID = PerfId;
394 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;
395 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
396 }
397 break;
398
399 case MODULE_LOADIMAGE_START_ID:
400 case MODULE_LOADIMAGE_END_ID:
401 StringPtr = LOAD_IMAGE_TOK;
402 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
403 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;
404 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
405 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
406 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;
407 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;
408 if (PerfId == MODULE_LOADIMAGE_START_ID) {
409 PeiPerformanceLogHeader->LoadImageCount++;
410 }
411 FpdtRecordPtr.GuidQwordEvent->Qword = PeiPerformanceLogHeader->LoadImageCount;
412 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
413 }
414 break;
415
416 case PERF_EVENTSIGNAL_START_ID:
417 case PERF_EVENTSIGNAL_END_ID:
418 case PERF_CALLBACK_START_ID:
419 case PERF_CALLBACK_END_ID:
420 if (String == NULL || Guid == NULL) {
421 return EFI_INVALID_PARAMETER;
422 }
423 StringPtr = String;
424 if (AsciiStrLen (String) == 0) {
425 StringPtr = "unknown name";
426 }
427 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
428 FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;
429 FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);
430 FpdtRecordPtr.DualGuidStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
431 FpdtRecordPtr.DualGuidStringEvent->ProgressID = PerfId;
432 FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;
433 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, ModuleGuid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));
434 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));
435 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);
436 }
437 break;
438
439 case PERF_EVENT_ID:
440 case PERF_FUNCTION_START_ID:
441 case PERF_FUNCTION_END_ID:
442 case PERF_INMODULE_START_ID:
443 case PERF_INMODULE_END_ID:
444 case PERF_CROSSMODULE_START_ID:
445 case PERF_CROSSMODULE_END_ID:
446 if (String != NULL && AsciiStrLen (String) != 0) {
447 StringPtr = String;
448 } else {
449 StringPtr = "unknown name";
450 }
451 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
452 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
453 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
454 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
455 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
456 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
457 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
458 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
459 }
460 break;
461
462 default:
463 if (Attribute != PerfEntry) {
464 if (String != NULL && AsciiStrLen (String) != 0) {
465 StringPtr = String;
466 } else {
467 StringPtr = "unknown name";
468 }
469 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
470 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
471 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
472 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
473 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
474 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
475 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
476 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
477 }
478 } else {
479 return EFI_INVALID_PARAMETER;
480 }
481 break;
482 }
483
484 //
485 // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
486 //
487 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
488 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
489 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
490 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
491 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
492 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
493 if (Guid != NULL) {
494 //
495 // Cache the event guid in string event record.
496 //
497 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (EFI_GUID));
498 } else {
499 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
500 }
501 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
502 }
503
504 //
505 // 6. Update the length of the used buffer after fill in the record.
506 //
507 PeiPerformanceLogHeader->SizeOfAllEntries += FpdtRecordPtr.RecordHeader->Length;
508
509 return EFI_SUCCESS;
510 }
511
512 /**
513 Creates a record for the beginning of a performance measurement.
514
515 If TimeStamp is zero, then this function reads the current time stamp
516 and adds that time stamp value to the record as the start time.
517
518 If TimeStamp is one, then this function reads 0 as the start time.
519
520 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
521
522 @param Handle Pointer to environment specific context used
523 to identify the component being measured.
524 @param Token Pointer to a Null-terminated ASCII string
525 that identifies the component being measured.
526 @param Module Pointer to a Null-terminated ASCII string
527 that identifies the module being measured.
528 @param TimeStamp 64-bit time stamp.
529 @param Identifier 32-bit identifier. If the value is 0, the created record
530 is same as the one created by StartPerformanceMeasurement.
531
532 @retval RETURN_SUCCESS The start of the measurement was recorded.
533 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
534
535 **/
536 RETURN_STATUS
537 EFIAPI
538 StartPerformanceMeasurementEx (
539 IN CONST VOID *Handle OPTIONAL,
540 IN CONST CHAR8 *Token OPTIONAL,
541 IN CONST CHAR8 *Module OPTIONAL,
542 IN UINT64 TimeStamp,
543 IN UINT32 Identifier
544 )
545 {
546 CONST CHAR8 *String;
547
548 if (Token != NULL) {
549 String = Token;
550 } else if (Module != NULL) {
551 String = Module;
552 } else {
553 String = NULL;
554 }
555
556 return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfStartEntry);
557
558 }
559
560 /**
561
562 Creates a record for the end of a performance measurement.
563
564 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
565 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.
566 If the TimeStamp is one, then this function reads 0 as the end time.
567
568 @param Handle Pointer to environment specific context used
569 to identify the component being measured.
570 @param Token Pointer to a Null-terminated ASCII string
571 that identifies the component being measured.
572 @param Module Pointer to a Null-terminated ASCII string
573 that identifies the module being measured.
574 @param TimeStamp 64-bit time stamp.
575 @param Identifier 32-bit identifier. If the value is 0, the found record
576 is same as the one found by EndPerformanceMeasurement.
577
578 @retval RETURN_SUCCESS The end of the measurement was recorded.
579 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
580
581 **/
582 RETURN_STATUS
583 EFIAPI
584 EndPerformanceMeasurementEx (
585 IN CONST VOID *Handle OPTIONAL,
586 IN CONST CHAR8 *Token OPTIONAL,
587 IN CONST CHAR8 *Module OPTIONAL,
588 IN UINT64 TimeStamp,
589 IN UINT32 Identifier
590 )
591 {
592 CONST CHAR8 *String;
593
594 if (Token != NULL) {
595 String = Token;
596 } else if (Module != NULL) {
597 String = Module;
598 } else {
599 String = NULL;
600 }
601
602 return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfEndEntry);
603 }
604
605 /**
606 Attempts to retrieve a performance measurement log entry from the performance measurement log.
607 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
608 and then assign the Identifier with 0.
609
610 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
611 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
612 and the key for the second entry in the log is returned. If the performance log is empty,
613 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
614 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
615 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
616 retrieved and an implementation specific non-zero key value that specifies the end of the performance
617 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
618 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
619 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
620 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
621 If Handle is NULL, then ASSERT().
622 If Token is NULL, then ASSERT().
623 If Module is NULL, then ASSERT().
624 If StartTimeStamp is NULL, then ASSERT().
625 If EndTimeStamp is NULL, then ASSERT().
626 If Identifier is NULL, then ASSERT().
627
628 !!!NOT Support yet!!!
629
630 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
631 0, then the first performance measurement log entry is retrieved.
632 On exit, the key of the next performance of entry entry.
633 @param Handle Pointer to environment specific context used to identify the component
634 being measured.
635 @param Token Pointer to a Null-terminated ASCII string that identifies the component
636 being measured.
637 @param Module Pointer to a Null-terminated ASCII string that identifies the module
638 being measured.
639 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
640 was started.
641 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
642 was ended.
643 @param Identifier Pointer to the 32-bit identifier that was recorded.
644
645 @return The key for the next performance log entry (in general case).
646
647 **/
648 UINTN
649 EFIAPI
650 GetPerformanceMeasurementEx (
651 IN UINTN LogEntryKey,
652 OUT CONST VOID **Handle,
653 OUT CONST CHAR8 **Token,
654 OUT CONST CHAR8 **Module,
655 OUT UINT64 *StartTimeStamp,
656 OUT UINT64 *EndTimeStamp,
657 OUT UINT32 *Identifier
658 )
659 {
660 return 0;
661 }
662
663 /**
664 Creates a record for the beginning of a performance measurement.
665
666 If TimeStamp is zero, then this function reads the current time stamp
667 and adds that time stamp value to the record as the start time.
668
669 If TimeStamp is one, then this function reads 0 as the start time.
670
671 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
672
673
674 @param Handle Pointer to environment specific context used
675 to identify the component being measured.
676 @param Token Pointer to a Null-terminated ASCII string
677 that identifies the component being measured.
678 @param Module Pointer to a Null-terminated ASCII string
679 that identifies the module being measured.
680 @param TimeStamp 64-bit time stamp.
681
682 @retval RETURN_SUCCESS The start of the measurement was recorded.
683 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
684
685 **/
686 RETURN_STATUS
687 EFIAPI
688 StartPerformanceMeasurement (
689 IN CONST VOID *Handle OPTIONAL,
690 IN CONST CHAR8 *Token OPTIONAL,
691 IN CONST CHAR8 *Module OPTIONAL,
692 IN UINT64 TimeStamp
693 )
694 {
695 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
696 }
697
698 /**
699
700 Creates a record for the end of a performance measurement.
701
702 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
703 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.
704 If the TimeStamp is one, then this function reads 0 as the end time.
705
706 @param Handle Pointer to environment specific context used
707 to identify the component being measured.
708 @param Token Pointer to a Null-terminated ASCII string
709 that identifies the component being measured.
710 @param Module Pointer to a Null-terminated ASCII string
711 that identifies the module being measured.
712 @param TimeStamp 64-bit time stamp.
713
714 @retval RETURN_SUCCESS The end of the measurement was recorded.
715 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
716
717 **/
718 RETURN_STATUS
719 EFIAPI
720 EndPerformanceMeasurement (
721 IN CONST VOID *Handle OPTIONAL,
722 IN CONST CHAR8 *Token OPTIONAL,
723 IN CONST CHAR8 *Module OPTIONAL,
724 IN UINT64 TimeStamp
725 )
726 {
727 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
728 }
729
730 /**
731 Attempts to retrieve a performance measurement log entry from the performance measurement log.
732 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
733 and then eliminate the Identifier.
734
735 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
736 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
737 and the key for the second entry in the log is returned. If the performance log is empty,
738 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
739 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
740 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
741 retrieved and an implementation specific non-zero key value that specifies the end of the performance
742 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
743 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
744 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
745 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
746 If Handle is NULL, then ASSERT().
747 If Token is NULL, then ASSERT().
748 If Module is NULL, then ASSERT().
749 If StartTimeStamp is NULL, then ASSERT().
750 If EndTimeStamp is NULL, then ASSERT().
751
752 NOT Support yet.
753
754 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
755 0, then the first performance measurement log entry is retrieved.
756 On exit, the key of the next performance of entry entry.
757 @param Handle Pointer to environment specific context used to identify the component
758 being measured.
759 @param Token Pointer to a Null-terminated ASCII string that identifies the component
760 being measured.
761 @param Module Pointer to a Null-terminated ASCII string that identifies the module
762 being measured.
763 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
764 was started.
765 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
766 was ended.
767
768 @return The key for the next performance log entry (in general case).
769
770 **/
771 UINTN
772 EFIAPI
773 GetPerformanceMeasurement (
774 IN UINTN LogEntryKey,
775 OUT CONST VOID **Handle,
776 OUT CONST CHAR8 **Token,
777 OUT CONST CHAR8 **Module,
778 OUT UINT64 *StartTimeStamp,
779 OUT UINT64 *EndTimeStamp
780 )
781 {
782 return 0;
783 }
784
785 /**
786 Returns TRUE if the performance measurement macros are enabled.
787
788 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
789 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
790
791 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
792 PcdPerformanceLibraryPropertyMask is set.
793 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
794 PcdPerformanceLibraryPropertyMask is clear.
795
796 **/
797 BOOLEAN
798 EFIAPI
799 PerformanceMeasurementEnabled (
800 VOID
801 )
802 {
803 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
804 }
805
806 /**
807 Create performance record with event description and a timestamp.
808
809 @param CallerIdentifier - Image handle or pointer to caller ID GUID
810 @param Guid - Pointer to a GUID
811 @param String - Pointer to a string describing the measurement
812 @param Address - Pointer to a location in memory relevant to the measurement
813 @param Identifier - Performance identifier describing the type of measurement
814
815 @retval RETURN_SUCCESS - Successfully created performance record
816 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
817 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
818 pointer or invalid PerfId
819
820 **/
821 RETURN_STATUS
822 EFIAPI
823 LogPerformanceMeasurement (
824 IN CONST VOID *CallerIdentifier,
825 IN CONST VOID *Guid OPTIONAL,
826 IN CONST CHAR8 *String OPTIONAL,
827 IN UINT64 Address OPTIONAL,
828 IN UINT32 Identifier
829 )
830 {
831 return (RETURN_STATUS)InsertFpdtRecord (CallerIdentifier, Guid, String, 0, Address, (UINT16)Identifier, PerfEntry);
832 }
833
834 /**
835 Check whether the specified performance measurement can be logged.
836
837 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
838 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
839
840 @param Type - Type of the performance measurement entry.
841
842 @retval TRUE The performance measurement can be logged.
843 @retval FALSE The performance measurement can NOT be logged.
844
845 **/
846 BOOLEAN
847 EFIAPI
848 LogPerformanceMeasurementEnabled (
849 IN CONST UINTN Type
850 )
851 {
852 //
853 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
854 //
855 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {
856 return TRUE;
857 }
858 return FALSE;
859 }