2 Performance library instance used by SMM Core.
4 This library provides the performance measurement interfaces and initializes performance
5 logging for the SMM phase.
6 It initializes SMM phase performance logging by publishing the SMM Performance and PerformanceEx Protocol,
7 which is consumed by SmmPerformanceLib to logging performance data in SMM phase.
9 This library is mainly used by SMM Core to start performance logging to ensure that
10 SMM Performance and PerformanceEx Protocol are installed at the very beginning of SMM phase.
12 Caution: This module requires additional review when modified.
13 This driver will have external input - performance data and communicate buffer in SMM mode.
14 This external input must be validated carefully to avoid security issue like
15 buffer overflow, integer overflow.
17 SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.
19 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
20 This program and the accompanying materials
21 are licensed and made available under the terms and conditions of the BSD License
22 which accompanies this distribution. The full text of the license may be found at
23 http://opensource.org/licenses/bsd-license.php
25 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
26 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
31 #include "SmmCorePerformanceLibInternal.h"
33 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
34 #define FIRMWARE_RECORD_BUFFER 0x1000
35 #define CACHE_HANDLE_GUID_COUNT 0x100
37 SMM_BOOT_PERFORMANCE_TABLE
*mSmmBootPerformanceTable
= NULL
;
41 CHAR8 NameString
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
45 HANDLE_GUID_MAP mCacheHandleGuidTable
[CACHE_HANDLE_GUID_COUNT
];
46 UINTN mCachePairCount
= 0;
48 UINT32 mPerformanceLength
= sizeof (SMM_BOOT_PERFORMANCE_TABLE
);
49 UINT32 mMaxPerformanceLength
= 0;
50 UINT32 mLoadImageCount
= 0;
51 BOOLEAN mFpdtDataIsReported
= FALSE
;
52 BOOLEAN mLackSpaceIsReport
= FALSE
;
53 CHAR8
*mPlatformLanguage
= NULL
;
54 SPIN_LOCK mSmmFpdtLock
;
55 PERFORMANCE_PROPERTY mPerformanceProperty
;
56 UINT32 mCachedLength
= 0;
59 // Interfaces for SMM PerformanceMeasurement Protocol.
61 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface
= {
62 CreatePerformanceMeasurement
,
66 Return the pointer to the FPDT record in the allocated memory.
68 @param RecordSize The size of FPDT record.
69 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
71 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
72 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
77 IN OUT FPDT_RECORD_PTR
*FpdtRecordPtr
80 if (mFpdtDataIsReported
) {
82 // Append Boot records after Smm boot performance records have been reported.
84 if (mPerformanceLength
+ RecordSize
> mMaxPerformanceLength
) {
85 if (!mLackSpaceIsReport
) {
86 DEBUG ((DEBUG_INFO
, "SmmCorePerformanceLib: No enough space to save boot records\n"));
87 mLackSpaceIsReport
= TRUE
;
89 return EFI_OUT_OF_RESOURCES
;
92 // Covert buffer to FPDT Ptr Union type.
94 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)((UINT8
*)mSmmBootPerformanceTable
+ mSmmBootPerformanceTable
->Header
.Length
);
98 // Check if pre-allocated buffer is full
100 if (mPerformanceLength
+ RecordSize
> mMaxPerformanceLength
) {
101 mSmmBootPerformanceTable
= ReallocatePool (
103 mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
,
104 mSmmBootPerformanceTable
107 if (mSmmBootPerformanceTable
== NULL
) {
108 return EFI_OUT_OF_RESOURCES
;
110 mSmmBootPerformanceTable
->Header
.Length
= mPerformanceLength
;
111 mMaxPerformanceLength
= mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
;
114 // Covert buffer to FPDT Ptr Union type.
116 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)((UINT8
*)mSmmBootPerformanceTable
+ mSmmBootPerformanceTable
->Header
.Length
);
118 FpdtRecordPtr
->RecordHeader
->Length
= 0;
124 Check whether the Token is a known one which is uesed by core.
126 @param Token Pointer to a Null-terminated ASCII string
128 @retval TRUE Is a known one used by core.
129 @retval FALSE Not a known one.
134 IN CONST CHAR8
*Token
141 if (AsciiStrCmp (Token
, SEC_TOK
) == 0 ||
142 AsciiStrCmp (Token
, PEI_TOK
) == 0 ||
143 AsciiStrCmp (Token
, DXE_TOK
) == 0 ||
144 AsciiStrCmp (Token
, BDS_TOK
) == 0 ||
145 AsciiStrCmp (Token
, DRIVERBINDING_START_TOK
) == 0 ||
146 AsciiStrCmp (Token
, DRIVERBINDING_SUPPORT_TOK
) == 0 ||
147 AsciiStrCmp (Token
, DRIVERBINDING_STOP_TOK
) == 0 ||
148 AsciiStrCmp (Token
, LOAD_IMAGE_TOK
) == 0 ||
149 AsciiStrCmp (Token
, START_IMAGE_TOK
) == 0 ||
150 AsciiStrCmp (Token
, PEIM_TOK
) == 0) {
158 Check whether the ID is a known one which map to the known Token.
160 @param Identifier 32-bit identifier.
162 @retval TRUE Is a known one used by core.
163 @retval FALSE Not a known one.
171 if (Identifier
== MODULE_START_ID
||
172 Identifier
== MODULE_END_ID
||
173 Identifier
== MODULE_LOADIMAGE_START_ID
||
174 Identifier
== MODULE_LOADIMAGE_END_ID
||
175 Identifier
== MODULE_DB_START_ID
||
176 Identifier
== MODULE_DB_END_ID
||
177 Identifier
== MODULE_DB_SUPPORT_START_ID
||
178 Identifier
== MODULE_DB_SUPPORT_END_ID
||
179 Identifier
== MODULE_DB_STOP_START_ID
||
180 Identifier
== MODULE_DB_STOP_END_ID
) {
188 Get the FPDT record identifier.
190 @param Attribute The attribute of the Record.
191 PerfStartEntry: Start Record.
192 PerfEndEntry: End Record.
193 @param Handle Pointer to environment specific context used to identify the component being measured.
194 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
195 @param ProgressID On return, pointer to the ProgressID.
197 @retval EFI_SUCCESS Get record info successfully.
198 @retval EFI_INVALID_PARAMETER No matched FPDT record.
203 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
,
204 IN CONST VOID
*Handle
,
205 IN CONST CHAR8
*String
,
206 OUT UINT16
*ProgressID
212 if (String
!= NULL
) {
213 if (AsciiStrCmp (String
, START_IMAGE_TOK
) == 0) { // "StartImage:"
214 if (Attribute
== PerfStartEntry
) {
215 *ProgressID
= MODULE_START_ID
;
217 *ProgressID
= MODULE_END_ID
;
219 } else if (AsciiStrCmp (String
, LOAD_IMAGE_TOK
) == 0) { // "LoadImage:"
220 if (Attribute
== PerfStartEntry
) {
221 *ProgressID
= MODULE_LOADIMAGE_START_ID
;
223 *ProgressID
= MODULE_LOADIMAGE_END_ID
;
225 } else { // Pref used in Modules
226 if (Attribute
== PerfStartEntry
) {
227 *ProgressID
= PERF_INMODULE_START_ID
;
229 *ProgressID
= PERF_INMODULE_END_ID
;
232 } else if (Handle
!= NULL
) { // Pref used in Modules
233 if (Attribute
== PerfStartEntry
) {
234 *ProgressID
= PERF_INMODULE_START_ID
;
236 *ProgressID
= PERF_INMODULE_END_ID
;
239 return EFI_UNSUPPORTED
;
245 Get a human readable module name and module guid for the given image handle.
246 If module name can't be found, "" string will return.
247 If module guid can't be found, Zero Guid will return.
249 @param Handle Image handle or Controller handle.
250 @param NameString The ascii string will be filled into it. If not found, null string will return.
251 @param BufferSize Size of the input NameString buffer.
252 @param ModuleGuid Point to the guid buffer to store the got module guid value.
254 @retval EFI_SUCCESS Successfully get module name and guid.
255 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
256 @retval other value Module Name can't be got.
260 GetModuleInfoFromHandle (
261 IN EFI_HANDLE Handle
,
262 OUT CHAR8
*NameString
,
264 OUT EFI_GUID
*ModuleGuid OPTIONAL
268 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
269 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
275 BOOLEAN ModuleGuidIsGet
;
278 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
280 if (NameString
== NULL
|| BufferSize
== 0) {
281 return EFI_INVALID_PARAMETER
;
285 // Try to get the ModuleGuid and name string form the caached array.
287 if (mCachePairCount
> 0) {
288 for (Count
= mCachePairCount
- 1; Count
>= 0; Count
--) {
289 if (Handle
== mCacheHandleGuidTable
[Count
].Handle
) {
290 CopyGuid (ModuleGuid
, &mCacheHandleGuidTable
[Count
].ModuleGuid
);
291 AsciiStrCpyS (NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, mCacheHandleGuidTable
[Count
].NameString
);
297 Status
= EFI_INVALID_PARAMETER
;
299 ModuleGuidIsGet
= FALSE
;
302 // Initialize GUID as zero value.
304 TempGuid
= &gZeroGuid
;
306 // Initialize it as "" string.
310 if (Handle
!= NULL
) {
312 // Try Handle as ImageHandle.
314 Status
= gBS
->HandleProtocol (
316 &gEfiLoadedImageProtocolGuid
,
317 (VOID
**) &LoadedImage
320 if (EFI_ERROR (Status
)) {
322 // Try Handle as Controller Handle
324 Status
= gBS
->OpenProtocol (
326 &gEfiDriverBindingProtocolGuid
,
327 (VOID
**) &DriverBinding
,
330 EFI_OPEN_PROTOCOL_GET_PROTOCOL
332 if (!EFI_ERROR (Status
)) {
334 // Get Image protocol from ImageHandle
336 Status
= gBS
->HandleProtocol (
337 DriverBinding
->ImageHandle
,
338 &gEfiLoadedImageProtocolGuid
,
339 (VOID
**) &LoadedImage
345 if (!EFI_ERROR (Status
) && LoadedImage
!= NULL
) {
347 // Get Module Guid from DevicePath.
349 if (LoadedImage
->FilePath
!= NULL
&&
350 LoadedImage
->FilePath
->Type
== MEDIA_DEVICE_PATH
&&
351 LoadedImage
->FilePath
->SubType
== MEDIA_PIWG_FW_FILE_DP
354 // Determine GUID associated with module logging performance
356 ModuleGuidIsGet
= TRUE
;
357 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) LoadedImage
->FilePath
;
358 TempGuid
= &FvFilePath
->FvFileName
;
362 // Method 1 Get Module Name from PDB string.
364 PdbFileName
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
365 if (PdbFileName
!= NULL
&& BufferSize
> 0) {
367 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
368 if ((PdbFileName
[Index
] == '\\') || (PdbFileName
[Index
] == '/')) {
369 StartIndex
= Index
+ 1;
373 // Copy the PDB file name to our temporary string.
374 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
376 for (Index
= 0; Index
< BufferSize
- 1; Index
++) {
377 NameString
[Index
] = PdbFileName
[Index
+ StartIndex
];
378 if (NameString
[Index
] == 0 || NameString
[Index
] == '.') {
379 NameString
[Index
] = 0;
384 if (Index
== BufferSize
- 1) {
385 NameString
[Index
] = 0;
388 // Module Name is got.
394 if (ModuleGuidIsGet
) {
396 // Method 2 Try to get the image's FFS UI section by image GUID
400 Status
= GetSectionFromAnyFv (
402 EFI_SECTION_USER_INTERFACE
,
404 (VOID
**) &StringPtr
,
408 if (!EFI_ERROR (Status
)) {
410 // Method 3. Get the name string from FFS UI section
412 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
413 NameString
[Index
] = (CHAR8
) StringPtr
[Index
];
415 NameString
[Index
] = 0;
416 FreePool (StringPtr
);
424 if (ModuleGuid
!= NULL
) {
425 CopyGuid (ModuleGuid
, TempGuid
);
426 if (IsZeroGuid(TempGuid
) && (Handle
!= NULL
) && !ModuleGuidIsGet
) {
428 CopyGuid (ModuleGuid
, (EFI_GUID
*) Handle
);
433 // Cache the Handle and Guid pairs.
435 if (mCachePairCount
< CACHE_HANDLE_GUID_COUNT
) {
436 mCacheHandleGuidTable
[mCachePairCount
].Handle
= Handle
;
437 CopyGuid (&mCacheHandleGuidTable
[mCachePairCount
].ModuleGuid
, ModuleGuid
);
438 AsciiStrCpyS (mCacheHandleGuidTable
[mCachePairCount
].NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, NameString
);
446 Copies the string from Source into Destination and updates Length with the
449 @param Destination - destination of the string copy
450 @param Source - pointer to the source string which will get copied
451 @param Length - pointer to a length variable to be updated
455 CopyStringIntoPerfRecordAndUpdateLength (
456 IN OUT CHAR8
*Destination
,
457 IN CONST CHAR8
*Source
,
464 ASSERT (Source
!= NULL
);
466 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
467 DestMax
= STRING_SIZE
;
469 DestMax
= AsciiStrSize (Source
);
470 if (DestMax
> STRING_SIZE
) {
471 DestMax
= STRING_SIZE
;
474 StringLen
= AsciiStrLen (Source
);
475 if (StringLen
>= DestMax
) {
476 StringLen
= DestMax
-1;
479 AsciiStrnCpyS(Destination
, DestMax
, Source
, StringLen
);
480 *Length
+= (UINT8
)DestMax
;
486 Create performance record with event description and a timestamp.
488 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
489 @param Guid - Pointer to a GUID.
490 @param String - Pointer to a string describing the measurement.
491 @param Ticker - 64-bit time stamp.
492 @param Address - Pointer to a location in memory relevant to the measurement.
493 @param PerfId - Performance identifier describing the type of measurement.
494 @param Attribute - The attribute of the measurement. According to attribute can create a start
495 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
496 or a general record for other Perf macros.
498 @retval EFI_SUCCESS - Successfully created performance record.
499 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
500 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
501 pointer or invalid PerfId.
503 @retval EFI_SUCCESS - Successfully created performance record
504 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records
505 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
506 pointer or invalid PerfId
511 IN CONST VOID
*CallerIdentifier
, OPTIONAL
512 IN CONST VOID
*Guid
, OPTIONAL
513 IN CONST CHAR8
*String
, OPTIONAL
515 IN UINT64 Address
, OPTIONAL
517 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
523 CHAR8 ModuleName
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
524 FPDT_RECORD_PTR FpdtRecordPtr
;
525 FPDT_RECORD_PTR CachedFpdtRecordPtr
;
527 CONST CHAR8
*StringPtr
;
533 ZeroMem (ModuleName
, sizeof (ModuleName
));
536 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
537 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
539 if (Attribute
!= PerfEntry
) {
541 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
542 // !!! Note: If the Perf is not the known Token used in the core but have same
543 // ID with the core Token, this case will not be supported.
544 // And in currtnt usage mode, for the unkown ID, there is a general rule:
545 // If it is start pref: the lower 4 bits of the ID should be 0.
546 // If it is end pref: the lower 4 bits of the ID should not be 0.
547 // If input ID doesn't follow the rule, we will adjust it.
549 if ((PerfId
!= 0) && (IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
550 return EFI_INVALID_PARAMETER
;
551 } else if ((PerfId
!= 0) && (!IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
552 if ((Attribute
== PerfStartEntry
) && ((PerfId
& 0x000F) != 0)) {
554 } else if ((Attribute
== PerfEndEntry
) && ((PerfId
& 0x000F) == 0)) {
560 // Get ProgressID form the String Token.
562 Status
= GetFpdtRecordId (Attribute
, CallerIdentifier
, String
, &ProgressId
);
563 if (EFI_ERROR (Status
)) {
571 // 2. Get the buffer to store the FPDT record.
573 Status
= GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE
, &FpdtRecordPtr
);
574 if (EFI_ERROR (Status
)) {
579 // 3. Get the TimeStamp.
582 Ticker
= GetPerformanceCounter ();
583 TimeStamp
= GetTimeInNanoSecond (Ticker
);
584 } else if (Ticker
== 1) {
587 TimeStamp
= GetTimeInNanoSecond (Ticker
);
591 // 4. Fill in the FPDT record according to different Performance Identifier.
594 case MODULE_START_ID
:
596 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
597 StringPtr
= ModuleName
;
599 // Cache the offset of start image start record and use to update the start image end record if needed.
601 if (PerfId
== MODULE_START_ID
&& Attribute
== PerfEntry
) {
602 mCachedLength
= mSmmBootPerformanceTable
->Header
.Length
;
604 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
605 FpdtRecordPtr
.GuidEvent
->Header
.Type
= FPDT_GUID_EVENT_TYPE
;
606 FpdtRecordPtr
.GuidEvent
->Header
.Length
= sizeof (FPDT_GUID_EVENT_RECORD
);
607 FpdtRecordPtr
.GuidEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
608 FpdtRecordPtr
.GuidEvent
->ProgressID
= PerfId
;
609 FpdtRecordPtr
.GuidEvent
->Timestamp
= TimeStamp
;
610 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
611 if (CallerIdentifier
== NULL
&& PerfId
== MODULE_END_ID
&& mCachedLength
!= 0) {
612 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)((UINT8
*)mSmmBootPerformanceTable
+ mCachedLength
);
613 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &CachedFpdtRecordPtr
.GuidEvent
->Guid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
619 case MODULE_LOADIMAGE_START_ID
:
620 case MODULE_LOADIMAGE_END_ID
:
621 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
622 StringPtr
= ModuleName
;
623 if (PerfId
== MODULE_LOADIMAGE_START_ID
) {
626 // Cache the offset of load image start record and use to be updated by the load image end record if needed.
628 if (CallerIdentifier
== NULL
&& Attribute
== PerfEntry
) {
629 mCachedLength
= mSmmBootPerformanceTable
->Header
.Length
;
632 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
633 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
634 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
635 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
636 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
637 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
638 FpdtRecordPtr
.GuidQwordEvent
->Qword
= mLoadImageCount
;
639 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
640 if (PerfId
== MODULE_LOADIMAGE_END_ID
&& mCachedLength
!= 0) {
641 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)((UINT8
*)mSmmBootPerformanceTable
+ mCachedLength
);
642 CopyMem (&CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
));
648 case PERF_EVENTSIGNAL_START_ID
:
649 case PERF_EVENTSIGNAL_END_ID
:
650 case PERF_CALLBACK_START_ID
:
651 case PERF_CALLBACK_END_ID
:
652 if (String
== NULL
|| Guid
== NULL
) {
653 return EFI_INVALID_PARAMETER
;
656 if (AsciiStrLen (String
) == 0) {
657 StringPtr
= "unknown name";
659 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
660 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
661 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
662 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
663 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
664 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
665 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, CallerIdentifier
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
666 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
667 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DualGuidStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
);
672 case PERF_FUNCTION_START_ID
:
673 case PERF_FUNCTION_END_ID
:
674 case PERF_INMODULE_START_ID
:
675 case PERF_INMODULE_END_ID
:
676 case PERF_CROSSMODULE_START_ID
:
677 case PERF_CROSSMODULE_END_ID
:
678 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
679 if (String
!= NULL
) {
682 StringPtr
= ModuleName
;
684 if (AsciiStrLen (StringPtr
) == 0) {
685 StringPtr
= "unknown name";
687 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
688 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
689 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
690 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
691 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
692 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
693 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
694 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
699 if (Attribute
!= PerfEntry
) {
700 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
701 if (String
!= NULL
) {
704 StringPtr
= ModuleName
;
706 if (AsciiStrLen (StringPtr
) == 0) {
707 StringPtr
= "unknown name";
709 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
710 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
711 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
712 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
713 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
714 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
715 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
716 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
719 return EFI_INVALID_PARAMETER
;
725 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
727 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
728 if (StringPtr
== NULL
) {
729 return EFI_INVALID_PARAMETER
;
731 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
732 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
733 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
734 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
735 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
738 // Cache the event guid in string event record.
740 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
742 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
744 if (AsciiStrLen (StringPtr
) == 0) {
745 StringPtr
= "unknown name";
747 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
749 if ((PerfId
== MODULE_LOADIMAGE_START_ID
) || (PerfId
== MODULE_END_ID
)) {
750 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= (UINT8
)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
)+ STRING_SIZE
);
752 if ((PerfId
== MODULE_LOADIMAGE_END_ID
|| PerfId
== MODULE_END_ID
) && mCachedLength
!= 0) {
753 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)((UINT8
*)mSmmBootPerformanceTable
+ mCachedLength
);
754 if (PerfId
== MODULE_LOADIMAGE_END_ID
) {
755 DestMax
= CachedFpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
756 StringLen
= AsciiStrLen (StringPtr
);
757 if (StringLen
>= DestMax
) {
758 StringLen
= DestMax
-1;
760 CopyMem (&CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
761 AsciiStrnCpyS (CachedFpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, StringPtr
, StringLen
);
762 } else if (PerfId
== MODULE_END_ID
) {
763 DestMax
= FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
764 StringLen
= AsciiStrLen (CachedFpdtRecordPtr
.DynamicStringEvent
->String
);
765 if (StringLen
>= DestMax
) {
766 StringLen
= DestMax
-1;
768 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
769 AsciiStrnCpyS (FpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, CachedFpdtRecordPtr
.DynamicStringEvent
->String
, StringLen
);
776 // 5. Update the length of the used buffer after fill in the record.
778 mPerformanceLength
+= FpdtRecordPtr
.RecordHeader
->Length
;
779 mSmmBootPerformanceTable
->Header
.Length
+= FpdtRecordPtr
.RecordHeader
->Length
;
785 SmmReadyToBoot protocol notification event handler.
787 @param Protocol Points to the protocol's unique identifier
788 @param Interface Points to the interface instance
789 @param Handle The handle on which the interface was installed
791 @retval EFI_SUCCESS SmmReadyToBootCallback runs successfully
796 SmmReportFpdtRecordData (
797 IN CONST EFI_GUID
*Protocol
,
804 if (!mFpdtDataIsReported
&& mSmmBootPerformanceTable
!= NULL
) {
805 SmmBPDTddr
= (UINT64
)(UINTN
)mSmmBootPerformanceTable
;
806 REPORT_STATUS_CODE_EX (
808 EFI_SOFTWARE_SMM_DRIVER
,
811 &gEdkiiFpdtExtendedFirmwarePerformanceGuid
,
816 // Set FPDT report state to TRUE.
818 mFpdtDataIsReported
= TRUE
;
824 SmmBase2 protocol notify callback function, when SMST and SMM memory service get initialized
825 this function is callbacked to initialize the Smm Performance Lib
827 @param Event The event of notify protocol.
828 @param Context Notify event context.
833 InitializeSmmCorePerformanceLib (
840 VOID
*SmmReadyToBootRegistration
;
841 PERFORMANCE_PROPERTY
*PerformanceProperty
;
844 // Initialize spin lock
846 InitializeSpinLock (&mSmmFpdtLock
);
849 // Install the protocol interfaces for SMM performance library instance.
852 Status
= gSmst
->SmmInstallProtocolInterface (
854 &gEdkiiSmmPerformanceMeasurementProtocolGuid
,
855 EFI_NATIVE_INTERFACE
,
856 &mPerformanceMeasurementInterface
858 ASSERT_EFI_ERROR (Status
);
860 Status
= gSmst
->SmmRegisterProtocolNotify (
861 &gEdkiiSmmReadyToBootProtocolGuid
,
862 SmmReportFpdtRecordData
,
863 &SmmReadyToBootRegistration
865 Status
= EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid
, (VOID
**) &PerformanceProperty
);
866 if (EFI_ERROR (Status
)) {
868 // Install configuration table for performance property.
870 mPerformanceProperty
.Revision
= PERFORMANCE_PROPERTY_REVISION
;
871 mPerformanceProperty
.Reserved
= 0;
872 mPerformanceProperty
.Frequency
= GetPerformanceCounterProperties (
873 &mPerformanceProperty
.TimerStartValue
,
874 &mPerformanceProperty
.TimerEndValue
876 Status
= gBS
->InstallConfigurationTable (&gPerformanceProtocolGuid
, &mPerformanceProperty
);
877 ASSERT_EFI_ERROR (Status
);
882 The constructor function initializes the Performance Measurement Enable flag and
883 registers SmmBase2 protocol notify callback.
884 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
886 @param ImageHandle The firmware allocated handle for the EFI image.
887 @param SystemTable A pointer to the EFI System Table.
889 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
894 SmmCorePerformanceLibConstructor (
895 IN EFI_HANDLE ImageHandle
,
896 IN EFI_SYSTEM_TABLE
*SystemTable
903 if (!PerformanceMeasurementEnabled ()) {
905 // Do not initialize performance infrastructure if not required.
911 // Create the events to do the library init.
913 Status
= gBS
->CreateEvent (
916 InitializeSmmCorePerformanceLib
,
920 ASSERT_EFI_ERROR (Status
);
923 // Register for protocol notifications on this event
925 Status
= gBS
->RegisterProtocolNotify (
926 &gEfiSmmBase2ProtocolGuid
,
931 ASSERT_EFI_ERROR (Status
);
937 Create performance record with event description and a timestamp.
939 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
940 @param Guid - Pointer to a GUID.
941 @param String - Pointer to a string describing the measurement.
942 @param TimeStamp - 64-bit time stamp.
943 @param Address - Pointer to a location in memory relevant to the measurement.
944 @param Identifier - Performance identifier describing the type of measurement.
945 @param Attribute - The attribute of the measurement. According to attribute can create a start
946 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
947 or a general record for other Perf macros.
949 @retval EFI_SUCCESS - Successfully created performance record.
950 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
951 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
952 pointer or invalid PerfId.
956 CreatePerformanceMeasurement(
957 IN CONST VOID
*CallerIdentifier
, OPTIONAL
958 IN CONST VOID
*Guid
, OPTIONAL
959 IN CONST CHAR8
*String
, OPTIONAL
960 IN UINT64 TimeStamp
, OPTIONAL
961 IN UINT64 Address
, OPTIONAL
962 IN UINT32 Identifier
,
963 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
968 Status
= EFI_SUCCESS
;
970 AcquireSpinLock (&mSmmFpdtLock
);
971 Status
= InsertFpdtRecord (CallerIdentifier
, Guid
, String
, TimeStamp
, Address
, (UINT16
)Identifier
, Attribute
);
972 ReleaseSpinLock (&mSmmFpdtLock
);
977 Adds a record at the end of the performance measurement log
978 that records the start time of a performance measurement.
980 Adds a record to the end of the performance measurement log
981 that contains the Handle, Token, Module and Identifier.
982 The end time of the new record must be set to zero.
983 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
984 If TimeStamp is zero, the start time in the record is filled in with the value
985 read from the current time stamp.
987 @param Handle Pointer to environment specific context used
988 to identify the component being measured.
989 @param Token Pointer to a Null-terminated ASCII string
990 that identifies the component being measured.
991 @param Module Pointer to a Null-terminated ASCII string
992 that identifies the module being measured.
993 @param TimeStamp 64-bit time stamp.
994 @param Identifier 32-bit identifier. If the value is 0, the created record
995 is same as the one created by StartPerformanceMeasurement.
997 @retval RETURN_SUCCESS The start of the measurement was recorded.
998 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1003 StartPerformanceMeasurementEx (
1004 IN CONST VOID
*Handle
, OPTIONAL
1005 IN CONST CHAR8
*Token
, OPTIONAL
1006 IN CONST CHAR8
*Module
, OPTIONAL
1007 IN UINT64 TimeStamp
,
1008 IN UINT32 Identifier
1011 CONST CHAR8
*String
;
1013 if (Token
!= NULL
) {
1015 } else if (Module
!= NULL
) {
1021 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfStartEntry
);
1025 Searches the performance measurement log from the beginning of the log
1026 for the first matching record that contains a zero end time and fills in a valid end time.
1028 Searches the performance measurement log from the beginning of the log
1029 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
1030 If the record can not be found then return RETURN_NOT_FOUND.
1031 If the record is found and TimeStamp is not zero,
1032 then the end time in the record is filled in with the value specified by TimeStamp.
1033 If the record is found and TimeStamp is zero, then the end time in the matching record
1034 is filled in with the current time stamp value.
1036 @param Handle Pointer to environment specific context used
1037 to identify the component being measured.
1038 @param Token Pointer to a Null-terminated ASCII string
1039 that identifies the component being measured.
1040 @param Module Pointer to a Null-terminated ASCII string
1041 that identifies the module being measured.
1042 @param TimeStamp 64-bit time stamp.
1043 @param Identifier 32-bit identifier. If the value is 0, the found record
1044 is same as the one found by EndPerformanceMeasurement.
1046 @retval RETURN_SUCCESS The end of the measurement was recorded.
1047 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1052 EndPerformanceMeasurementEx (
1053 IN CONST VOID
*Handle
, OPTIONAL
1054 IN CONST CHAR8
*Token
, OPTIONAL
1055 IN CONST CHAR8
*Module
, OPTIONAL
1056 IN UINT64 TimeStamp
,
1057 IN UINT32 Identifier
1060 CONST CHAR8
*String
;
1062 if (Token
!= NULL
) {
1064 } else if (Module
!= NULL
) {
1070 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfEndEntry
);
1074 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1075 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
1076 and then assign the Identifier with 0.
1080 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1081 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1082 and the key for the second entry in the log is returned. If the performance log is empty,
1083 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1084 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1085 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1086 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1087 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1088 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1089 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
1090 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1091 If Handle is NULL, then ASSERT().
1092 If Token is NULL, then ASSERT().
1093 If Module is NULL, then ASSERT().
1094 If StartTimeStamp is NULL, then ASSERT().
1095 If EndTimeStamp is NULL, then ASSERT().
1096 If Identifier is NULL, then ASSERT().
1098 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1099 0, then the first performance measurement log entry is retrieved.
1100 On exit, the key of the next performance log entry.
1101 @param Handle Pointer to environment specific context used to identify the component
1103 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1105 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1107 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1109 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1111 @param Identifier Pointer to the 32-bit identifier that was recorded.
1113 @return The key for the next performance log entry (in general case).
1118 GetPerformanceMeasurementEx (
1119 IN UINTN LogEntryKey
,
1120 OUT CONST VOID
**Handle
,
1121 OUT CONST CHAR8
**Token
,
1122 OUT CONST CHAR8
**Module
,
1123 OUT UINT64
*StartTimeStamp
,
1124 OUT UINT64
*EndTimeStamp
,
1125 OUT UINT32
*Identifier
1132 Adds a record at the end of the performance measurement log
1133 that records the start time of a performance measurement.
1135 Adds a record to the end of the performance measurement log
1136 that contains the Handle, Token, and Module.
1137 The end time of the new record must be set to zero.
1138 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1139 If TimeStamp is zero, the start time in the record is filled in with the value
1140 read from the current time stamp.
1142 @param Handle Pointer to environment specific context used
1143 to identify the component being measured.
1144 @param Token Pointer to a Null-terminated ASCII string
1145 that identifies the component being measured.
1146 @param Module Pointer to a Null-terminated ASCII string
1147 that identifies the module being measured.
1148 @param TimeStamp 64-bit time stamp.
1150 @retval RETURN_SUCCESS The start of the measurement was recorded.
1151 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1156 StartPerformanceMeasurement (
1157 IN CONST VOID
*Handle
, OPTIONAL
1158 IN CONST CHAR8
*Token
, OPTIONAL
1159 IN CONST CHAR8
*Module
, OPTIONAL
1163 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1167 Searches the performance measurement log from the beginning of the log
1168 for the first matching record that contains a zero end time and fills in a valid end time.
1170 Searches the performance measurement log from the beginning of the log
1171 for the first record that matches Handle, Token, and Module and has an end time value of zero.
1172 If the record can not be found then return RETURN_NOT_FOUND.
1173 If the record is found and TimeStamp is not zero,
1174 then the end time in the record is filled in with the value specified by TimeStamp.
1175 If the record is found and TimeStamp is zero, then the end time in the matching record
1176 is filled in with the current time stamp value.
1178 @param Handle Pointer to environment specific context used
1179 to identify the component being measured.
1180 @param Token Pointer to a Null-terminated ASCII string
1181 that identifies the component being measured.
1182 @param Module Pointer to a Null-terminated ASCII string
1183 that identifies the module being measured.
1184 @param TimeStamp 64-bit time stamp.
1186 @retval RETURN_SUCCESS The end of the measurement was recorded.
1187 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1192 EndPerformanceMeasurement (
1193 IN CONST VOID
*Handle
, OPTIONAL
1194 IN CONST CHAR8
*Token
, OPTIONAL
1195 IN CONST CHAR8
*Module
, OPTIONAL
1199 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1203 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1204 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
1205 and then eliminate the Identifier.
1209 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1210 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1211 and the key for the second entry in the log is returned. If the performance log is empty,
1212 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1213 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1214 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1215 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1216 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1217 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1218 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
1219 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1220 If Handle is NULL, then ASSERT().
1221 If Token is NULL, then ASSERT().
1222 If Module is NULL, then ASSERT().
1223 If StartTimeStamp is NULL, then ASSERT().
1224 If EndTimeStamp is NULL, then ASSERT().
1226 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1227 0, then the first performance measurement log entry is retrieved.
1228 On exit, the key of the next performance log entry.
1229 @param Handle Pointer to environment specific context used to identify the component
1231 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1233 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1235 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1237 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1240 @return The key for the next performance log entry (in general case).
1245 GetPerformanceMeasurement (
1246 IN UINTN LogEntryKey
,
1247 OUT CONST VOID
**Handle
,
1248 OUT CONST CHAR8
**Token
,
1249 OUT CONST CHAR8
**Module
,
1250 OUT UINT64
*StartTimeStamp
,
1251 OUT UINT64
*EndTimeStamp
1258 Returns TRUE if the performance measurement macros are enabled.
1260 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1261 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
1263 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1264 PcdPerformanceLibraryPropertyMask is set.
1265 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1266 PcdPerformanceLibraryPropertyMask is clear.
1271 PerformanceMeasurementEnabled (
1275 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
1279 Create performance record with event description and a timestamp.
1281 @param CallerIdentifier - Image handle or pointer to caller ID GUID
1282 @param Guid - Pointer to a GUID
1283 @param String - Pointer to a string describing the measurement
1284 @param Address - Pointer to a location in memory relevant to the measurement
1285 @param Identifier - Performance identifier describing the type of measurement
1287 @retval RETURN_SUCCESS - Successfully created performance record
1288 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
1289 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1290 pointer or invalid PerfId
1295 LogPerformanceMeasurement (
1296 IN CONST VOID
*CallerIdentifier
,
1297 IN CONST VOID
*Guid
, OPTIONAL
1298 IN CONST CHAR8
*String
, OPTIONAL
1299 IN UINT64 Address
, OPTIONAL
1300 IN UINT32 Identifier
1303 return (RETURN_STATUS
)CreatePerformanceMeasurement (CallerIdentifier
, Guid
, String
, 0, Address
, Identifier
, PerfEntry
);
1307 Check whether the specified performance measurement can be logged.
1309 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
1310 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
1312 @param Type - Type of the performance measurement entry.
1314 @retval TRUE The performance measurement can be logged.
1315 @retval FALSE The performance measurement can NOT be logged.
1320 LogPerformanceMeasurementEnabled (
1325 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
1327 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {