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