2 Performance library instance mainly used by DxeCore.
4 This library provides the performance measurement interfaces and initializes performance
5 logging for DXE phase. It first initializes its private global data structure for
6 performance logging and saves the performance GUIDed HOB passed from PEI phase.
7 It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,
8 which are consumed by DxePerformanceLib to logging performance data in DXE phase.
10 This library is mainly used by DxeCore to start performance logging to ensure that
11 Performance Protocol is installed at the very beginning of DXE phase.
13 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
14 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
15 SPDX-License-Identifier: BSD-2-Clause-Patent
20 #include "DxeCorePerformanceLibInternal.h"
23 // Data for FPDT performance records.
25 #define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
26 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
27 #define FIRMWARE_RECORD_BUFFER 0x10000
28 #define CACHE_HANDLE_GUID_COUNT 0x800
30 BOOT_PERFORMANCE_TABLE
*mAcpiBootPerformanceTable
= NULL
;
31 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate
= {
33 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE
,
34 sizeof (BOOT_PERFORMANCE_TABLE
)
38 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT
, // Type
39 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD
), // Length
40 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT
// Revision
44 // These values will be updated at runtime.
47 0, // OsLoaderLoadImageStart
48 0, // OsLoaderStartImageStart
49 0, // ExitBootServicesEntry
50 0 // ExitBootServicesExit
56 CHAR8 NameString
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
60 HANDLE_GUID_MAP mCacheHandleGuidTable
[CACHE_HANDLE_GUID_COUNT
];
61 UINTN mCachePairCount
= 0;
63 UINT32 mLoadImageCount
= 0;
64 UINT32 mPerformanceLength
= 0;
65 UINT32 mMaxPerformanceLength
= 0;
66 UINT32 mBootRecordSize
= 0;
67 UINTN mBootRecordMaxSize
= 0;
68 UINT32 mCachedLength
= 0;
70 BOOLEAN mFpdtBufferIsReported
= FALSE
;
71 BOOLEAN mLackSpaceIsReported
= FALSE
;
72 CHAR8
*mPlatformLanguage
= NULL
;
73 UINT8
*mPerformancePointer
= NULL
;
74 UINT8
*mBootRecordBuffer
= NULL
;
75 BOOLEAN mLockInsertRecord
= FALSE
;
76 CHAR8
*mDevicePathString
= NULL
;
78 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*mDevicePathToText
= NULL
;
81 // Interfaces for PerformanceMeasurement Protocol.
83 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface
= {
84 CreatePerformanceMeasurement
,
87 PERFORMANCE_PROPERTY mPerformanceProperty
;
90 Return the pointer to the FPDT record in the allocated memory.
92 @param RecordSize The size of FPDT record.
93 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
95 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
96 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
101 IN OUT FPDT_RECORD_PTR
*FpdtRecordPtr
104 if (mFpdtBufferIsReported
) {
106 // Append Boot records to the boot performance table.
108 if (mBootRecordSize
+ RecordSize
> mBootRecordMaxSize
) {
109 if (!mLackSpaceIsReported
) {
110 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: No enough space to save boot records\n"));
111 mLackSpaceIsReported
= TRUE
;
113 return EFI_OUT_OF_RESOURCES
;
116 // Save boot record into BootPerformance table
118 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mBootRecordSize
);
122 // Check if pre-allocated buffer is full
124 if (mPerformanceLength
+ RecordSize
> mMaxPerformanceLength
) {
125 mPerformancePointer
= ReallocatePool (
127 mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
,
130 if (mPerformancePointer
== NULL
) {
131 return EFI_OUT_OF_RESOURCES
;
133 mMaxPerformanceLength
= mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
;
136 // Covert buffer to FPDT Ptr Union type.
138 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mPerformanceLength
);
144 Check whether the Token is a known one which is uesed by core.
146 @param Token Pointer to a Null-terminated ASCII string
148 @retval TRUE Is a known one used by core.
149 @retval FALSE Not a known one.
154 IN CONST CHAR8
*Token
161 if (AsciiStrCmp (Token
, SEC_TOK
) == 0 ||
162 AsciiStrCmp (Token
, PEI_TOK
) == 0 ||
163 AsciiStrCmp (Token
, DXE_TOK
) == 0 ||
164 AsciiStrCmp (Token
, BDS_TOK
) == 0 ||
165 AsciiStrCmp (Token
, DRIVERBINDING_START_TOK
) == 0 ||
166 AsciiStrCmp (Token
, DRIVERBINDING_SUPPORT_TOK
) == 0 ||
167 AsciiStrCmp (Token
, DRIVERBINDING_STOP_TOK
) == 0 ||
168 AsciiStrCmp (Token
, LOAD_IMAGE_TOK
) == 0 ||
169 AsciiStrCmp (Token
, START_IMAGE_TOK
) == 0 ||
170 AsciiStrCmp (Token
, PEIM_TOK
) == 0) {
178 Check whether the ID is a known one which map to the known Token.
180 @param Identifier 32-bit identifier.
182 @retval TRUE Is a known one used by core.
183 @retval FALSE Not a known one.
191 if (Identifier
== MODULE_START_ID
||
192 Identifier
== MODULE_END_ID
||
193 Identifier
== MODULE_LOADIMAGE_START_ID
||
194 Identifier
== MODULE_LOADIMAGE_END_ID
||
195 Identifier
== MODULE_DB_START_ID
||
196 Identifier
== MODULE_DB_END_ID
||
197 Identifier
== MODULE_DB_SUPPORT_START_ID
||
198 Identifier
== MODULE_DB_SUPPORT_END_ID
||
199 Identifier
== MODULE_DB_STOP_START_ID
||
200 Identifier
== MODULE_DB_STOP_END_ID
) {
208 This internal function dumps all the SMM performance data and size.
210 @param SmmPerfData Smm Performance data. The buffer contain the SMM perf data is allocated by this function and caller needs to free it.
211 @param SmmPerfDataSize Smm Performance data size.
212 @param SkipGetPerfData Skip to get performance data, just get the size.
216 InternalGetSmmPerfData (
217 OUT VOID
**SmmPerfData
,
218 OUT UINTN
*SmmPerfDataSize
,
219 IN BOOLEAN SkipGetPerfData
223 UINT8
*SmmBootRecordCommBuffer
;
224 EFI_SMM_COMMUNICATE_HEADER
*SmmCommBufferHeader
;
225 SMM_BOOT_RECORD_COMMUNICATE
*SmmCommData
;
227 EFI_SMM_COMMUNICATION_PROTOCOL
*Communication
;
228 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*SmmCommRegionTable
;
229 EFI_MEMORY_DESCRIPTOR
*SmmCommMemRegion
;
231 VOID
*SmmBootRecordData
;
232 UINTN SmmBootRecordDataSize
;
233 UINTN ReservedMemSize
;
236 // Collect boot records from SMM drivers.
238 SmmBootRecordCommBuffer
= NULL
;
240 SmmBootRecordData
= NULL
;
242 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &Communication
);
243 if (!EFI_ERROR (Status
)) {
245 // Initialize communicate buffer
246 // Get the prepared Reserved Memory Range
248 Status
= EfiGetSystemConfigurationTable (
249 &gEdkiiPiSmmCommunicationRegionTableGuid
,
250 (VOID
**) &SmmCommRegionTable
252 if (!EFI_ERROR (Status
)) {
253 ASSERT (SmmCommRegionTable
!= NULL
);
254 SmmCommMemRegion
= (EFI_MEMORY_DESCRIPTOR
*) (SmmCommRegionTable
+ 1);
255 for (Index
= 0; Index
< SmmCommRegionTable
->NumberOfEntries
; Index
++) {
256 if (SmmCommMemRegion
->Type
== EfiConventionalMemory
) {
259 SmmCommMemRegion
= (EFI_MEMORY_DESCRIPTOR
*) ((UINT8
*) SmmCommMemRegion
+ SmmCommRegionTable
->DescriptorSize
);
261 ASSERT (Index
< SmmCommRegionTable
->NumberOfEntries
);
262 ASSERT (SmmCommMemRegion
->PhysicalStart
> 0);
263 ASSERT (SmmCommMemRegion
->NumberOfPages
> 0);
264 ReservedMemSize
= (UINTN
) SmmCommMemRegion
->NumberOfPages
* EFI_PAGE_SIZE
;
267 // Check enough reserved memory space
269 if (ReservedMemSize
> SMM_BOOT_RECORD_COMM_SIZE
) {
270 SmmBootRecordCommBuffer
= (VOID
*) (UINTN
) SmmCommMemRegion
->PhysicalStart
;
271 SmmCommBufferHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)SmmBootRecordCommBuffer
;
272 SmmCommData
= (SMM_BOOT_RECORD_COMMUNICATE
*)SmmCommBufferHeader
->Data
;
273 ZeroMem((UINT8
*)SmmCommData
, sizeof(SMM_BOOT_RECORD_COMMUNICATE
));
275 CopyGuid (&SmmCommBufferHeader
->HeaderGuid
, &gEfiFirmwarePerformanceGuid
);
276 SmmCommBufferHeader
->MessageLength
= sizeof(SMM_BOOT_RECORD_COMMUNICATE
);
277 CommSize
= SMM_BOOT_RECORD_COMM_SIZE
;
280 // Get the size of boot records.
282 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE
;
283 SmmCommData
->BootRecordData
= NULL
;
284 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
286 if (!EFI_ERROR (Status
) && !EFI_ERROR (SmmCommData
->ReturnStatus
) && SmmCommData
->BootRecordSize
!= 0) {
287 if (SkipGetPerfData
) {
288 *SmmPerfDataSize
= SmmCommData
->BootRecordSize
;
292 // Get all boot records
294 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET
;
295 SmmBootRecordDataSize
= SmmCommData
->BootRecordSize
;
296 SmmBootRecordData
= AllocateZeroPool(SmmBootRecordDataSize
);
297 ASSERT (SmmBootRecordData
!= NULL
);
298 SmmCommData
->BootRecordOffset
= 0;
299 SmmCommData
->BootRecordData
= (VOID
*) ((UINTN
) SmmCommMemRegion
->PhysicalStart
+ SMM_BOOT_RECORD_COMM_SIZE
);
300 SmmCommData
->BootRecordSize
= ReservedMemSize
- SMM_BOOT_RECORD_COMM_SIZE
;
301 while (SmmCommData
->BootRecordOffset
< SmmBootRecordDataSize
) {
302 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
303 ASSERT_EFI_ERROR (Status
);
304 ASSERT_EFI_ERROR(SmmCommData
->ReturnStatus
);
305 if (SmmCommData
->BootRecordOffset
+ SmmCommData
->BootRecordSize
> SmmBootRecordDataSize
) {
306 CopyMem ((UINT8
*) SmmBootRecordData
+ SmmCommData
->BootRecordOffset
, SmmCommData
->BootRecordData
, SmmBootRecordDataSize
- SmmCommData
->BootRecordOffset
);
308 CopyMem ((UINT8
*) SmmBootRecordData
+ SmmCommData
->BootRecordOffset
, SmmCommData
->BootRecordData
, SmmCommData
->BootRecordSize
);
310 SmmCommData
->BootRecordOffset
= SmmCommData
->BootRecordOffset
+ SmmCommData
->BootRecordSize
;
312 *SmmPerfData
= SmmBootRecordData
;
313 *SmmPerfDataSize
= SmmBootRecordDataSize
;
321 Allocate buffer for Boot Performance table.
327 AllocateBootPerformanceTable (
333 UINTN BootPerformanceDataSize
;
334 UINT8
*BootPerformanceData
;
335 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
336 UINTN SmmBootRecordDataSize
;
338 SmmBootRecordDataSize
= 0;
341 // Get SMM performance data size at the point of EndOfDxe in order to allocate the boot performance table.
342 // Will Get all the data at ReadyToBoot.
344 InternalGetSmmPerfData (NULL
, &SmmBootRecordDataSize
, TRUE
);
347 // Prepare memory for Boot Performance table.
348 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
350 BootPerformanceDataSize
= sizeof (BOOT_PERFORMANCE_TABLE
) + mPerformanceLength
+ SmmBootRecordDataSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
353 // Try to allocate the same runtime buffer as last time boot.
355 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
356 Size
= sizeof (PerformanceVariable
);
357 Status
= gRT
->GetVariable (
358 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
359 &gEfiFirmwarePerformanceGuid
,
364 if (!EFI_ERROR (Status
)) {
365 Status
= gBS
->AllocatePages (
367 EfiReservedMemoryType
,
368 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
),
369 &PerformanceVariable
.BootPerformanceTablePointer
371 if (!EFI_ERROR (Status
)) {
372 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) (UINTN
) PerformanceVariable
.BootPerformanceTablePointer
;
376 if (mAcpiBootPerformanceTable
== NULL
) {
378 // Fail to allocate at specified address, continue to allocate at any address.
380 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) AllocatePeiAccessiblePages (
381 EfiReservedMemoryType
,
382 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
)
384 if (mAcpiBootPerformanceTable
!= NULL
) {
385 ZeroMem (mAcpiBootPerformanceTable
, BootPerformanceDataSize
);
388 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable
));
390 if (mAcpiBootPerformanceTable
== NULL
) {
391 return EFI_OUT_OF_RESOURCES
;
395 // Prepare Boot Performance Table.
397 BootPerformanceData
= (UINT8
*) mAcpiBootPerformanceTable
;
399 // Fill Basic Boot record to Boot Performance Table.
401 CopyMem (mAcpiBootPerformanceTable
, &mBootPerformanceTableTemplate
, sizeof (mBootPerformanceTableTemplate
));
402 BootPerformanceData
= BootPerformanceData
+ mAcpiBootPerformanceTable
->Header
.Length
;
404 // Fill Boot records from boot drivers.
406 if (mPerformancePointer
!= NULL
) {
407 CopyMem (BootPerformanceData
, mPerformancePointer
, mPerformanceLength
);
408 mAcpiBootPerformanceTable
->Header
.Length
+= mPerformanceLength
;
409 BootPerformanceData
= BootPerformanceData
+ mPerformanceLength
;
410 FreePool (mPerformancePointer
);
411 mPerformancePointer
= NULL
;
412 mPerformanceLength
= 0;
413 mMaxPerformanceLength
= 0;
416 mBootRecordBuffer
= (UINT8
*) mAcpiBootPerformanceTable
;
417 mBootRecordSize
= mAcpiBootPerformanceTable
->Header
.Length
;
418 mBootRecordMaxSize
= BootPerformanceDataSize
;
424 Get a human readable module name and module guid for the given image handle.
425 If module name can't be found, "" string will return.
426 If module guid can't be found, Zero Guid will return.
428 @param Handle Image handle or Controller handle.
429 @param NameString The ascii string will be filled into it. If not found, null string will return.
430 @param BufferSize Size of the input NameString buffer.
431 @param ModuleGuid Point to the guid buffer to store the got module guid value.
433 @retval EFI_SUCCESS Successfully get module name and guid.
434 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
435 @retval other value Module Name can't be got.
438 GetModuleInfoFromHandle (
439 IN EFI_HANDLE Handle
,
440 OUT CHAR8
*NameString
,
442 OUT EFI_GUID
*ModuleGuid OPTIONAL
446 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
447 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
453 BOOLEAN ModuleGuidIsGet
;
456 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
457 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
459 if (NameString
== NULL
|| BufferSize
== 0) {
460 return EFI_INVALID_PARAMETER
;
463 // Try to get the ModuleGuid and name string form the caached array.
465 if (mCachePairCount
> 0) {
466 for (Count
= mCachePairCount
-1; Count
>= 0; Count
--) {
467 if (Handle
== mCacheHandleGuidTable
[Count
].Handle
) {
468 CopyGuid (ModuleGuid
, &mCacheHandleGuidTable
[Count
].ModuleGuid
);
469 AsciiStrCpyS (NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, mCacheHandleGuidTable
[Count
].NameString
);
475 Status
= EFI_INVALID_PARAMETER
;
477 ModuleGuidIsGet
= FALSE
;
480 // Initialize GUID as zero value.
482 TempGuid
= &gZeroGuid
;
484 // Initialize it as "" string.
488 if (Handle
!= NULL
) {
490 // Try Handle as ImageHandle.
492 Status
= gBS
->HandleProtocol (
494 &gEfiLoadedImageProtocolGuid
,
495 (VOID
**) &LoadedImage
498 if (EFI_ERROR (Status
)) {
500 // Try Handle as Controller Handle
502 Status
= gBS
->OpenProtocol (
504 &gEfiDriverBindingProtocolGuid
,
505 (VOID
**) &DriverBinding
,
508 EFI_OPEN_PROTOCOL_GET_PROTOCOL
510 if (!EFI_ERROR (Status
)) {
512 // Get Image protocol from ImageHandle
514 Status
= gBS
->HandleProtocol (
515 DriverBinding
->ImageHandle
,
516 &gEfiLoadedImageProtocolGuid
,
517 (VOID
**) &LoadedImage
523 if (!EFI_ERROR (Status
) && LoadedImage
!= NULL
) {
525 // Get Module Guid from DevicePath.
527 if (LoadedImage
->FilePath
!= NULL
&&
528 LoadedImage
->FilePath
->Type
== MEDIA_DEVICE_PATH
&&
529 LoadedImage
->FilePath
->SubType
== MEDIA_PIWG_FW_FILE_DP
532 // Determine GUID associated with module logging performance
534 ModuleGuidIsGet
= TRUE
;
535 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) LoadedImage
->FilePath
;
536 TempGuid
= &FvFilePath
->FvFileName
;
540 // Method 1 Get Module Name from PDB string.
542 PdbFileName
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
543 if (PdbFileName
!= NULL
&& BufferSize
> 0) {
545 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
546 if ((PdbFileName
[Index
] == '\\') || (PdbFileName
[Index
] == '/')) {
547 StartIndex
= Index
+ 1;
551 // Copy the PDB file name to our temporary string.
552 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
554 for (Index
= 0; Index
< BufferSize
- 1; Index
++) {
555 NameString
[Index
] = PdbFileName
[Index
+ StartIndex
];
556 if (NameString
[Index
] == 0 || NameString
[Index
] == '.') {
557 NameString
[Index
] = 0;
562 if (Index
== BufferSize
- 1) {
563 NameString
[Index
] = 0;
566 // Module Name is got.
573 // Method 2: Get the name string from ComponentName2 protocol
575 Status
= gBS
->HandleProtocol (
577 &gEfiComponentName2ProtocolGuid
,
578 (VOID
**) &ComponentName2
580 if (!EFI_ERROR (Status
)) {
582 // Get the current platform language setting
584 if (mPlatformLanguage
== NULL
) {
585 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**) &mPlatformLanguage
, NULL
);
587 if (mPlatformLanguage
!= NULL
) {
588 Status
= ComponentName2
->GetDriverName (
590 mPlatformLanguage
!= NULL
? mPlatformLanguage
: "en-US",
593 if (!EFI_ERROR (Status
)) {
594 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
595 NameString
[Index
] = (CHAR8
) StringPtr
[Index
];
597 NameString
[Index
] = 0;
599 // Module Name is got.
606 if (ModuleGuidIsGet
) {
608 // Method 3 Try to get the image's FFS UI section by image GUID
612 Status
= GetSectionFromAnyFv (
614 EFI_SECTION_USER_INTERFACE
,
616 (VOID
**) &StringPtr
,
620 if (!EFI_ERROR (Status
)) {
622 // Method 3. Get the name string from FFS UI section
624 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
625 NameString
[Index
] = (CHAR8
) StringPtr
[Index
];
627 NameString
[Index
] = 0;
628 FreePool (StringPtr
);
636 if (ModuleGuid
!= NULL
) {
637 CopyGuid (ModuleGuid
, TempGuid
);
638 if (IsZeroGuid(TempGuid
) && (Handle
!= NULL
) && !ModuleGuidIsGet
) {
640 CopyGuid (ModuleGuid
, (EFI_GUID
*) Handle
);
645 // Cache the Handle and Guid pairs.
647 if (mCachePairCount
< CACHE_HANDLE_GUID_COUNT
) {
648 mCacheHandleGuidTable
[mCachePairCount
].Handle
= Handle
;
649 CopyGuid (&mCacheHandleGuidTable
[mCachePairCount
].ModuleGuid
, ModuleGuid
);
650 AsciiStrCpyS (mCacheHandleGuidTable
[mCachePairCount
].NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, NameString
);
658 Get the FPDT record identifier.
660 @param Attribute The attribute of the Record.
661 PerfStartEntry: Start Record.
662 PerfEndEntry: End Record.
663 @param Handle Pointer to environment specific context used to identify the component being measured.
664 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
665 @param ProgressID On return, pointer to the ProgressID.
667 @retval EFI_SUCCESS Get record info successfully.
668 @retval EFI_INVALID_PARAMETER No matched FPDT record.
673 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
,
674 IN CONST VOID
*Handle
,
675 IN CONST CHAR8
*String
,
676 OUT UINT16
*ProgressID
682 if (String
!= NULL
) {
683 if (AsciiStrCmp (String
, START_IMAGE_TOK
) == 0) { // "StartImage:"
684 if (Attribute
== PerfStartEntry
) {
685 *ProgressID
= MODULE_START_ID
;
687 *ProgressID
= MODULE_END_ID
;
689 } else if (AsciiStrCmp (String
, LOAD_IMAGE_TOK
) == 0) { // "LoadImage:"
690 if (Attribute
== PerfStartEntry
) {
691 *ProgressID
= MODULE_LOADIMAGE_START_ID
;
693 *ProgressID
= MODULE_LOADIMAGE_END_ID
;
695 } else if (AsciiStrCmp (String
, DRIVERBINDING_START_TOK
) == 0) { // "DB:Start:"
696 if (Attribute
== PerfStartEntry
) {
697 *ProgressID
= MODULE_DB_START_ID
;
699 *ProgressID
= MODULE_DB_END_ID
;
701 } else if (AsciiStrCmp (String
, DRIVERBINDING_SUPPORT_TOK
) == 0) { // "DB:Support:"
702 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
703 return RETURN_UNSUPPORTED
;
705 if (Attribute
== PerfStartEntry
) {
706 *ProgressID
= MODULE_DB_SUPPORT_START_ID
;
708 *ProgressID
= MODULE_DB_SUPPORT_END_ID
;
710 } else if (AsciiStrCmp (String
, DRIVERBINDING_STOP_TOK
) == 0) { // "DB:Stop:"
711 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
712 return RETURN_UNSUPPORTED
;
714 if (Attribute
== PerfStartEntry
) {
715 *ProgressID
= MODULE_DB_STOP_START_ID
;
717 *ProgressID
= MODULE_DB_STOP_END_ID
;
719 } else if (AsciiStrCmp (String
, PEI_TOK
) == 0 || // "PEI"
720 AsciiStrCmp (String
, DXE_TOK
) == 0 || // "DXE"
721 AsciiStrCmp (String
, BDS_TOK
) == 0) { // "BDS"
722 if (Attribute
== PerfStartEntry
) {
723 *ProgressID
= PERF_CROSSMODULE_START_ID
;
725 *ProgressID
= PERF_CROSSMODULE_END_ID
;
727 } else { // Pref used in Modules.
728 if (Attribute
== PerfStartEntry
) {
729 *ProgressID
= PERF_INMODULE_START_ID
;
731 *ProgressID
= PERF_INMODULE_END_ID
;
734 } else if (Handle
!= NULL
) { // Pref used in Modules.
735 if (Attribute
== PerfStartEntry
) {
736 *ProgressID
= PERF_INMODULE_START_ID
;
738 *ProgressID
= PERF_INMODULE_END_ID
;
741 return EFI_INVALID_PARAMETER
;
747 Copies the string from Source into Destination and updates Length with the
750 @param Destination - destination of the string copy
751 @param Source - pointer to the source string which will get copied
752 @param Length - pointer to a length variable to be updated
756 CopyStringIntoPerfRecordAndUpdateLength (
757 IN OUT CHAR8
*Destination
,
758 IN CONST CHAR8
*Source
,
765 ASSERT (Source
!= NULL
);
767 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
768 DestMax
= STRING_SIZE
;
770 DestMax
= AsciiStrSize (Source
);
771 if (DestMax
> STRING_SIZE
) {
772 DestMax
= STRING_SIZE
;
775 StringLen
= AsciiStrLen (Source
);
776 if (StringLen
>= DestMax
) {
777 StringLen
= DestMax
-1;
780 AsciiStrnCpyS(Destination
, DestMax
, Source
, StringLen
);
781 *Length
+= (UINT8
)DestMax
;
787 Get a string description for device for the given controller handle and update record
788 length. If ComponentName2 GetControllerName is supported, the value is included in the string,
789 followed by device path, otherwise just device path.
791 @param Handle - Image handle
792 @param ControllerHandle - Controller handle.
793 @param ComponentNameString - Pointer to a location where the string will be saved
794 @param Length - Pointer to record length to be updated
796 @retval EFI_SUCCESS - Successfully got string description for device
797 @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found
801 GetDeviceInfoFromHandleAndUpdateLength (
802 IN CONST VOID
*Handle
,
803 IN EFI_HANDLE ControllerHandle
,
804 OUT CHAR8
*ComponentNameString
,
808 EFI_DEVICE_PATH_PROTOCOL
*DevicePathProtocol
;
809 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
812 CHAR8
*AsciiStringPtr
;
813 UINTN ControllerNameStringSize
;
814 UINTN DevicePathStringSize
;
816 ControllerNameStringSize
= 0;
818 Status
= gBS
->HandleProtocol (
820 &gEfiComponentName2ProtocolGuid
,
821 (VOID
**) &ComponentName2
824 if (!EFI_ERROR(Status
)) {
826 // Get the current platform language setting
828 if (mPlatformLanguage
== NULL
) {
829 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&mPlatformLanguage
, NULL
);
832 Status
= ComponentName2
->GetControllerName (
836 mPlatformLanguage
!= NULL
? mPlatformLanguage
: "en-US",
841 if (!EFI_ERROR (Status
)) {
843 // This will produce the size of the unicode string, which is twice as large as the ASCII one
844 // This must be an even number, so ok to divide by 2
846 ControllerNameStringSize
= StrSize(StringPtr
) / 2;
849 // The + 1 is because we want to add a space between the ControllerName and the device path
851 if ((ControllerNameStringSize
+ (*Length
) + 1) > FPDT_MAX_PERF_RECORD_SIZE
) {
853 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
855 ControllerNameStringSize
= FPDT_MAX_PERF_RECORD_SIZE
- (*Length
) - 1;
858 UnicodeStrnToAsciiStrS(StringPtr
, ControllerNameStringSize
- 1, ComponentNameString
, ControllerNameStringSize
, &ControllerNameStringSize
);
861 // Add a space in the end of the ControllerName
863 AsciiStringPtr
= ComponentNameString
+ ControllerNameStringSize
- 1;
864 *AsciiStringPtr
= 0x20;
867 ControllerNameStringSize
++;
869 *Length
+= (UINT8
)ControllerNameStringSize
;
873 // This function returns the device path protocol from the handle specified by Handle. If Handle is
874 // NULL or Handle does not contain a device path protocol, then NULL is returned.
876 DevicePathProtocol
= DevicePathFromHandle(ControllerHandle
);
878 if (DevicePathProtocol
!= NULL
) {
879 StringPtr
= ConvertDevicePathToText (DevicePathProtocol
, TRUE
, FALSE
);
880 if (StringPtr
!= NULL
) {
882 // This will produce the size of the unicode string, which is twice as large as the ASCII one
883 // This must be an even number, so ok to divide by 2
885 DevicePathStringSize
= StrSize(StringPtr
) / 2;
887 if ((DevicePathStringSize
+ (*Length
)) > FPDT_MAX_PERF_RECORD_SIZE
) {
889 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
891 DevicePathStringSize
= FPDT_MAX_PERF_RECORD_SIZE
- (*Length
);
894 if (ControllerNameStringSize
!= 0) {
895 AsciiStringPtr
= ComponentNameString
+ ControllerNameStringSize
- 1;
897 AsciiStringPtr
= ComponentNameString
;
900 UnicodeStrnToAsciiStrS(StringPtr
, DevicePathStringSize
- 1, AsciiStringPtr
, DevicePathStringSize
, &DevicePathStringSize
);
901 *Length
+= (UINT8
)DevicePathStringSize
;
906 return EFI_UNSUPPORTED
;
910 Create performance record with event description and a timestamp.
912 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
913 @param Guid - Pointer to a GUID.
914 @param String - Pointer to a string describing the measurement.
915 @param Ticker - 64-bit time stamp.
916 @param Address - Pointer to a location in memory relevant to the measurement.
917 @param PerfId - Performance identifier describing the type of measurement.
918 @param Attribute - The attribute of the measurement. According to attribute can create a start
919 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
920 or a general record for other Perf macros.
922 @retval EFI_SUCCESS - Successfully created performance record.
923 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
924 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
925 pointer or invalid PerfId.
927 @retval EFI_SUCCESS - Successfully created performance record
928 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records
929 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
930 pointer or invalid PerfId
935 IN CONST VOID
*CallerIdentifier
, OPTIONAL
936 IN CONST VOID
*Guid
, OPTIONAL
937 IN CONST CHAR8
*String
, OPTIONAL
939 IN UINT64 Address
, OPTIONAL
941 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
945 CHAR8 ModuleName
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
946 FPDT_RECORD_PTR FpdtRecordPtr
;
947 FPDT_RECORD_PTR CachedFpdtRecordPtr
;
949 CONST CHAR8
*StringPtr
;
957 ZeroMem (ModuleName
, sizeof (ModuleName
));
960 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
961 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
963 if (Attribute
!= PerfEntry
) {
965 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
966 // !!! Note: If the Perf is not the known Token used in the core but have same
967 // ID with the core Token, this case will not be supported.
968 // And in currtnt usage mode, for the unkown ID, there is a general rule:
969 // If it is start pref: the lower 4 bits of the ID should be 0.
970 // If it is end pref: the lower 4 bits of the ID should not be 0.
971 // If input ID doesn't follow the rule, we will adjust it.
973 if ((PerfId
!= 0) && (IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
974 return EFI_INVALID_PARAMETER
;
975 } else if ((PerfId
!= 0) && (!IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
976 if ((Attribute
== PerfStartEntry
) && ((PerfId
& 0x000F) != 0)) {
978 } else if ((Attribute
== PerfEndEntry
) && ((PerfId
& 0x000F) == 0)) {
981 } else if (PerfId
== 0) {
983 // Get ProgressID form the String Token.
985 Status
= GetFpdtRecordId (Attribute
, CallerIdentifier
, String
, &ProgressId
);
986 if (EFI_ERROR (Status
)) {
994 // 2. Get the buffer to store the FPDT record.
996 Status
= GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE
, &FpdtRecordPtr
);
997 if (EFI_ERROR (Status
)) {
1002 //3. Get the TimeStamp.
1005 Ticker
= GetPerformanceCounter ();
1006 TimeStamp
= GetTimeInNanoSecond (Ticker
);
1007 } else if (Ticker
== 1) {
1010 TimeStamp
= GetTimeInNanoSecond (Ticker
);
1014 // 4. Fill in the FPDT record according to different Performance Identifier.
1017 case MODULE_START_ID
:
1019 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1020 StringPtr
= ModuleName
;
1022 // Cache the offset of start image start record and use to update the start image end record if needed.
1024 if (Attribute
== PerfEntry
&& PerfId
== MODULE_START_ID
) {
1025 if (mFpdtBufferIsReported
) {
1026 mCachedLength
= mBootRecordSize
;
1028 mCachedLength
= mPerformanceLength
;
1031 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1032 FpdtRecordPtr
.GuidEvent
->Header
.Type
= FPDT_GUID_EVENT_TYPE
;
1033 FpdtRecordPtr
.GuidEvent
->Header
.Length
= sizeof (FPDT_GUID_EVENT_RECORD
);
1034 FpdtRecordPtr
.GuidEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1035 FpdtRecordPtr
.GuidEvent
->ProgressID
= PerfId
;
1036 FpdtRecordPtr
.GuidEvent
->Timestamp
= TimeStamp
;
1037 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
1038 if (CallerIdentifier
== NULL
&& PerfId
== MODULE_END_ID
&& mCachedLength
!= 0) {
1039 if (mFpdtBufferIsReported
) {
1040 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1042 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1044 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &CachedFpdtRecordPtr
.GuidEvent
->Guid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
1050 case MODULE_LOADIMAGE_START_ID
:
1051 case MODULE_LOADIMAGE_END_ID
:
1052 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1053 StringPtr
= ModuleName
;
1054 if (PerfId
== MODULE_LOADIMAGE_START_ID
) {
1057 // Cache the offset of load image start record and use to be updated by the load image end record if needed.
1059 if (CallerIdentifier
== NULL
&& Attribute
== PerfEntry
) {
1060 if (mFpdtBufferIsReported
) {
1061 mCachedLength
= mBootRecordSize
;
1063 mCachedLength
= mPerformanceLength
;
1067 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1068 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
1069 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
1070 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1071 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
1072 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
1073 FpdtRecordPtr
.GuidQwordEvent
->Qword
= mLoadImageCount
;
1074 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
1075 if (PerfId
== MODULE_LOADIMAGE_END_ID
&& mCachedLength
!= 0) {
1076 if (mFpdtBufferIsReported
) {
1077 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1079 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1081 CopyMem (&CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
));
1087 case MODULE_DB_START_ID
:
1088 case MODULE_DB_SUPPORT_START_ID
:
1089 case MODULE_DB_SUPPORT_END_ID
:
1090 case MODULE_DB_STOP_START_ID
:
1091 case MODULE_DB_STOP_END_ID
:
1092 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1093 StringPtr
= ModuleName
;
1094 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1095 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
1096 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
1097 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1098 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
1099 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
1100 FpdtRecordPtr
.GuidQwordEvent
->Qword
= Address
;
1101 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
1105 case MODULE_DB_END_ID
:
1106 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1107 StringPtr
= ModuleName
;
1108 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1109 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Type
= FPDT_GUID_QWORD_STRING_EVENT_TYPE
;
1110 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD
);;
1111 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1112 FpdtRecordPtr
.GuidQwordStringEvent
->ProgressID
= PerfId
;
1113 FpdtRecordPtr
.GuidQwordStringEvent
->Timestamp
= TimeStamp
;
1114 FpdtRecordPtr
.GuidQwordStringEvent
->Qword
= Address
;
1115 CopyMem (&FpdtRecordPtr
.GuidQwordStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordStringEvent
->Guid
));
1117 GetDeviceInfoFromHandleAndUpdateLength(CallerIdentifier
, (EFI_HANDLE
)(UINTN
)Address
, FpdtRecordPtr
.GuidQwordStringEvent
->String
, &FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Length
);
1122 case PERF_EVENTSIGNAL_START_ID
:
1123 case PERF_EVENTSIGNAL_END_ID
:
1124 case PERF_CALLBACK_START_ID
:
1125 case PERF_CALLBACK_END_ID
:
1126 if (String
== NULL
|| Guid
== NULL
) {
1127 return EFI_INVALID_PARAMETER
;
1130 if (AsciiStrLen (String
) == 0) {
1131 StringPtr
= "unknown name";
1133 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1134 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
1135 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
1136 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1137 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
1138 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
1139 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, CallerIdentifier
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
1140 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
1141 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DualGuidStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
);
1146 case PERF_FUNCTION_START_ID
:
1147 case PERF_FUNCTION_END_ID
:
1148 case PERF_INMODULE_START_ID
:
1149 case PERF_INMODULE_END_ID
:
1150 case PERF_CROSSMODULE_START_ID
:
1151 case PERF_CROSSMODULE_END_ID
:
1152 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1153 if (String
!= NULL
) {
1156 StringPtr
= ModuleName
;
1158 if (AsciiStrLen (StringPtr
) == 0) {
1159 StringPtr
= "unknown name";
1161 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1162 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1163 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1164 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1165 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1166 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1167 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1168 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1173 if (Attribute
!= PerfEntry
) {
1174 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1175 if (String
!= NULL
) {
1178 StringPtr
= ModuleName
;
1180 if (AsciiStrLen (StringPtr
) == 0) {
1181 StringPtr
= "unknown name";
1183 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1184 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1185 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1186 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1187 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1188 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1189 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1190 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1193 return EFI_INVALID_PARAMETER
;
1199 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
1201 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1202 if (StringPtr
== NULL
||PerfId
== MODULE_DB_SUPPORT_START_ID
|| PerfId
== MODULE_DB_SUPPORT_END_ID
) {
1203 return EFI_INVALID_PARAMETER
;
1205 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1206 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1207 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1208 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1209 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1212 // Cache the event guid in string event record.
1214 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1216 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1218 if (AsciiStrLen (StringPtr
) == 0) {
1219 StringPtr
= "unknown name";
1221 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1223 if ((PerfId
== MODULE_LOADIMAGE_START_ID
) || (PerfId
== MODULE_END_ID
)) {
1224 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= (UINT8
)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
)+ STRING_SIZE
);
1226 if ((PerfId
== MODULE_LOADIMAGE_END_ID
|| PerfId
== MODULE_END_ID
) && mCachedLength
!= 0) {
1227 if (mFpdtBufferIsReported
) {
1228 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1230 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1232 if (PerfId
== MODULE_LOADIMAGE_END_ID
) {
1233 DestMax
= CachedFpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1234 StringLen
= AsciiStrLen (StringPtr
);
1235 if (StringLen
>= DestMax
) {
1236 StringLen
= DestMax
-1;
1238 CopyMem (&CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
1239 AsciiStrnCpyS (CachedFpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, StringPtr
, StringLen
);
1240 } else if (PerfId
== MODULE_END_ID
) {
1241 DestMax
= FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1242 StringLen
= AsciiStrLen (CachedFpdtRecordPtr
.DynamicStringEvent
->String
);
1243 if (StringLen
>= DestMax
) {
1244 StringLen
= DestMax
-1;
1246 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
1247 AsciiStrnCpyS (FpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, CachedFpdtRecordPtr
.DynamicStringEvent
->String
, StringLen
);
1254 // 5. Update the length of the used buffer after fill in the record.
1256 if (mFpdtBufferIsReported
) {
1257 mBootRecordSize
+= FpdtRecordPtr
.RecordHeader
->Length
;
1258 mAcpiBootPerformanceTable
->Header
.Length
+= FpdtRecordPtr
.RecordHeader
->Length
;
1260 mPerformanceLength
+= FpdtRecordPtr
.RecordHeader
->Length
;
1266 Dumps all the PEI performance.
1268 @param HobStart A pointer to a Guid.
1270 This internal function dumps all the PEI performance log to the DXE performance gauge array.
1271 It retrieves the optional GUID HOB for PEI performance and then saves the performance data
1272 to DXE performance data structures.
1276 InternalGetPeiPerformance (
1280 UINT8
*FirmwarePerformanceHob
;
1281 FPDT_PEI_EXT_PERF_HEADER
*PeiPerformanceLogHeader
;
1283 EFI_HOB_GUID_TYPE
*GuidHob
;
1285 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, HobStart
);
1286 while (GuidHob
!= NULL
) {
1287 FirmwarePerformanceHob
= GET_GUID_HOB_DATA (GuidHob
);
1288 PeiPerformanceLogHeader
= (FPDT_PEI_EXT_PERF_HEADER
*)FirmwarePerformanceHob
;
1290 if (mPerformanceLength
+ PeiPerformanceLogHeader
->SizeOfAllEntries
> mMaxPerformanceLength
) {
1291 mPerformancePointer
= ReallocatePool (
1293 mPerformanceLength
+
1294 (UINTN
)PeiPerformanceLogHeader
->SizeOfAllEntries
+
1295 FIRMWARE_RECORD_BUFFER
,
1298 ASSERT (mPerformancePointer
!= NULL
);
1299 mMaxPerformanceLength
= mPerformanceLength
+
1300 (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
) +
1301 FIRMWARE_RECORD_BUFFER
;
1304 EventRec
= mPerformancePointer
+ mPerformanceLength
;
1305 CopyMem (EventRec
, FirmwarePerformanceHob
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
), (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
));
1307 // Update the used buffer size.
1309 mPerformanceLength
+= (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
);
1310 mLoadImageCount
+= PeiPerformanceLogHeader
->LoadImageCount
;
1313 // Get next performance guid hob
1315 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, GET_NEXT_HOB (GuidHob
));
1320 Report Boot Perforamnce table address as report status code.
1322 @param Event The event of notify protocol.
1323 @param Context Notify event context.
1328 ReportFpdtRecordBuffer (
1336 if (!mFpdtBufferIsReported
) {
1337 Status
= AllocateBootPerformanceTable ();
1338 if (!EFI_ERROR(Status
)) {
1339 BPDTAddr
= (UINT64
)(UINTN
)mAcpiBootPerformanceTable
;
1340 REPORT_STATUS_CODE_EX (
1342 EFI_SOFTWARE_DXE_BS_DRIVER
,
1345 &gEdkiiFpdtExtendedFirmwarePerformanceGuid
,
1351 // Set FPDT report state to TRUE.
1353 mFpdtBufferIsReported
= TRUE
;
1358 Update Boot Performance table.
1360 @param Event The event of notify protocol.
1361 @param Context Notify event context.
1366 UpdateBootPerformanceTable (
1371 VOID
*SmmBootRecordData
;
1372 UINTN SmmBootRecordDataSize
;
1374 UINT8
*FirmwarePerformanceTablePtr
;
1377 // Get SMM performance data.
1379 SmmBootRecordData
= NULL
;
1380 InternalGetSmmPerfData (&SmmBootRecordData
, &SmmBootRecordDataSize
, FALSE
);
1382 FirmwarePerformanceTablePtr
= (UINT8
*) mAcpiBootPerformanceTable
+ mAcpiBootPerformanceTable
->Header
.Length
;
1384 if (mAcpiBootPerformanceTable
->Header
.Length
+ SmmBootRecordDataSize
> mBootRecordMaxSize
) {
1385 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: No enough space to save all SMM boot performance data\n"));
1386 AppendSize
= mBootRecordMaxSize
- mAcpiBootPerformanceTable
->Header
.Length
;
1388 AppendSize
= SmmBootRecordDataSize
;
1390 if (SmmBootRecordData
!= NULL
) {
1391 CopyMem (FirmwarePerformanceTablePtr
, SmmBootRecordData
, AppendSize
);
1392 mAcpiBootPerformanceTable
->Header
.Length
+= (UINT32
) AppendSize
;
1393 mBootRecordSize
+= (UINT32
) AppendSize
;
1394 FreePool (SmmBootRecordData
);
1399 The constructor function initializes Performance infrastructure for DXE phase.
1401 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance
1402 and merges PEI performance data to DXE performance log.
1403 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
1405 @param ImageHandle The firmware allocated handle for the EFI image.
1406 @param SystemTable A pointer to the EFI System Table.
1408 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
1413 DxeCorePerformanceLibConstructor (
1414 IN EFI_HANDLE ImageHandle
,
1415 IN EFI_SYSTEM_TABLE
*SystemTable
1420 EFI_EVENT EndOfDxeEvent
;
1421 EFI_EVENT ReadyToBootEvent
;
1422 PERFORMANCE_PROPERTY
*PerformanceProperty
;
1424 if (!PerformanceMeasurementEnabled ()) {
1426 // Do not initialize performance infrastructure if not required.
1432 // Dump normal PEI performance records
1434 InternalGetPeiPerformance (GetHobList());
1437 // Install the protocol interfaces for DXE performance library instance.
1440 Status
= gBS
->InstallMultipleProtocolInterfaces (
1442 &gEdkiiPerformanceMeasurementProtocolGuid
,
1443 &mPerformanceMeasurementInterface
,
1446 ASSERT_EFI_ERROR (Status
);
1449 // Register EndOfDxe event to allocate the boot performance table and report the table address through status code.
1451 Status
= gBS
->CreateEventEx (
1454 ReportFpdtRecordBuffer
,
1456 &gEfiEndOfDxeEventGroupGuid
,
1461 // Register ReadyToBoot event to update the boot performance table for SMM performance data.
1463 Status
= gBS
->CreateEventEx (
1466 UpdateBootPerformanceTable
,
1468 &gEfiEventReadyToBootGuid
,
1472 ASSERT_EFI_ERROR (Status
);
1474 Status
= EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid
, (VOID
**) &PerformanceProperty
);
1475 if (EFI_ERROR (Status
)) {
1477 // Install configuration table for performance property.
1479 mPerformanceProperty
.Revision
= PERFORMANCE_PROPERTY_REVISION
;
1480 mPerformanceProperty
.Reserved
= 0;
1481 mPerformanceProperty
.Frequency
= GetPerformanceCounterProperties (
1482 &mPerformanceProperty
.TimerStartValue
,
1483 &mPerformanceProperty
.TimerEndValue
1485 Status
= gBS
->InstallConfigurationTable (&gPerformanceProtocolGuid
, &mPerformanceProperty
);
1486 ASSERT_EFI_ERROR (Status
);
1493 Create performance record with event description and a timestamp.
1495 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
1496 @param Guid - Pointer to a GUID.
1497 @param String - Pointer to a string describing the measurement.
1498 @param TimeStamp - 64-bit time stamp.
1499 @param Address - Pointer to a location in memory relevant to the measurement.
1500 @param Identifier - Performance identifier describing the type of measurement.
1501 @param Attribute - The attribute of the measurement. According to attribute can create a start
1502 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
1503 or a general record for other Perf macros.
1505 @retval EFI_SUCCESS - Successfully created performance record.
1506 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
1507 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1508 pointer or invalid PerfId.
1512 CreatePerformanceMeasurement (
1513 IN CONST VOID
*CallerIdentifier
,
1514 IN CONST VOID
*Guid
, OPTIONAL
1515 IN CONST CHAR8
*String
, OPTIONAL
1516 IN UINT64 TimeStamp
,
1517 IN UINT64 Address
, OPTIONAL
1518 IN UINT32 Identifier
,
1519 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
1524 Status
= EFI_SUCCESS
;
1526 if (mLockInsertRecord
) {
1527 return EFI_INVALID_PARAMETER
;
1529 mLockInsertRecord
= TRUE
;
1531 Status
= InsertFpdtRecord (CallerIdentifier
, Guid
, String
, TimeStamp
, Address
, (UINT16
)Identifier
, Attribute
);
1533 mLockInsertRecord
= FALSE
;
1539 Adds a record at the end of the performance measurement log
1540 that records the start time of a performance measurement.
1542 Adds a record to the end of the performance measurement log
1543 that contains the Handle, Token, Module and Identifier.
1544 The end time of the new record must be set to zero.
1545 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1546 If TimeStamp is zero, the start time in the record is filled in with the value
1547 read from the current time stamp.
1549 @param Handle Pointer to environment specific context used
1550 to identify the component being measured.
1551 @param Token Pointer to a Null-terminated ASCII string
1552 that identifies the component being measured.
1553 @param Module Pointer to a Null-terminated ASCII string
1554 that identifies the module being measured.
1555 @param TimeStamp 64-bit time stamp.
1556 @param Identifier 32-bit identifier. If the value is 0, the created record
1557 is same as the one created by StartPerformanceMeasurement.
1559 @retval RETURN_SUCCESS The start of the measurement was recorded.
1560 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1565 StartPerformanceMeasurementEx (
1566 IN CONST VOID
*Handle
, OPTIONAL
1567 IN CONST CHAR8
*Token
, OPTIONAL
1568 IN CONST CHAR8
*Module
, OPTIONAL
1569 IN UINT64 TimeStamp
,
1570 IN UINT32 Identifier
1573 CONST CHAR8
*String
;
1575 if (Token
!= NULL
) {
1577 } else if (Module
!= NULL
) {
1583 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfStartEntry
);
1587 Searches the performance measurement log from the beginning of the log
1588 for the first matching record that contains a zero end time and fills in a valid end time.
1590 Searches the performance measurement log from the beginning of the log
1591 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
1592 If the record can not be found then return RETURN_NOT_FOUND.
1593 If the record is found and TimeStamp is not zero,
1594 then the end time in the record is filled in with the value specified by TimeStamp.
1595 If the record is found and TimeStamp is zero, then the end time in the matching record
1596 is filled in with the current time stamp value.
1598 @param Handle Pointer to environment specific context used
1599 to identify the component being measured.
1600 @param Token Pointer to a Null-terminated ASCII string
1601 that identifies the component being measured.
1602 @param Module Pointer to a Null-terminated ASCII string
1603 that identifies the module being measured.
1604 @param TimeStamp 64-bit time stamp.
1605 @param Identifier 32-bit identifier. If the value is 0, the found record
1606 is same as the one found by EndPerformanceMeasurement.
1608 @retval RETURN_SUCCESS The end of the measurement was recorded.
1609 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1614 EndPerformanceMeasurementEx (
1615 IN CONST VOID
*Handle
, OPTIONAL
1616 IN CONST CHAR8
*Token
, OPTIONAL
1617 IN CONST CHAR8
*Module
, OPTIONAL
1618 IN UINT64 TimeStamp
,
1619 IN UINT32 Identifier
1622 CONST CHAR8
*String
;
1624 if (Token
!= NULL
) {
1626 } else if (Module
!= NULL
) {
1632 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfEndEntry
);
1636 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1637 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
1638 and then assign the Identifier with 0.
1642 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1643 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1644 and the key for the second entry in the log is returned. If the performance log is empty,
1645 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1646 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1647 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1648 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1649 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1650 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1651 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
1652 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1653 If Handle is NULL, then ASSERT().
1654 If Token is NULL, then ASSERT().
1655 If Module is NULL, then ASSERT().
1656 If StartTimeStamp is NULL, then ASSERT().
1657 If EndTimeStamp is NULL, then ASSERT().
1658 If Identifier is NULL, then ASSERT().
1660 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1661 0, then the first performance measurement log entry is retrieved.
1662 On exit, the key of the next performance log entry.
1663 @param Handle Pointer to environment specific context used to identify the component
1665 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1667 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1669 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1671 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1673 @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement
1676 @return The key for the next performance log entry (in general case).
1681 GetPerformanceMeasurementEx (
1682 IN UINTN LogEntryKey
,
1683 OUT CONST VOID
**Handle
,
1684 OUT CONST CHAR8
**Token
,
1685 OUT CONST CHAR8
**Module
,
1686 OUT UINT64
*StartTimeStamp
,
1687 OUT UINT64
*EndTimeStamp
,
1688 OUT UINT32
*Identifier
1695 Adds a record at the end of the performance measurement log
1696 that records the start time of a performance measurement.
1698 Adds a record to the end of the performance measurement log
1699 that contains the Handle, Token, and Module.
1700 The end time of the new record must be set to zero.
1701 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1702 If TimeStamp is zero, the start time in the record is filled in with the value
1703 read from the current time stamp.
1705 @param Handle Pointer to environment specific context used
1706 to identify the component being measured.
1707 @param Token Pointer to a Null-terminated ASCII string
1708 that identifies the component being measured.
1709 @param Module Pointer to a Null-terminated ASCII string
1710 that identifies the module being measured.
1711 @param TimeStamp 64-bit time stamp.
1713 @retval RETURN_SUCCESS The start of the measurement was recorded.
1714 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1719 StartPerformanceMeasurement (
1720 IN CONST VOID
*Handle
, OPTIONAL
1721 IN CONST CHAR8
*Token
, OPTIONAL
1722 IN CONST CHAR8
*Module
, OPTIONAL
1726 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1730 Searches the performance measurement log from the beginning of the log
1731 for the first matching record that contains a zero end time and fills in a valid end time.
1733 Searches the performance measurement log from the beginning of the log
1734 for the first record that matches Handle, Token, and Module and has an end time value of zero.
1735 If the record can not be found then return RETURN_NOT_FOUND.
1736 If the record is found and TimeStamp is not zero,
1737 then the end time in the record is filled in with the value specified by TimeStamp.
1738 If the record is found and TimeStamp is zero, then the end time in the matching record
1739 is filled in with the current time stamp value.
1741 @param Handle Pointer to environment specific context used
1742 to identify the component being measured.
1743 @param Token Pointer to a Null-terminated ASCII string
1744 that identifies the component being measured.
1745 @param Module Pointer to a Null-terminated ASCII string
1746 that identifies the module being measured.
1747 @param TimeStamp 64-bit time stamp.
1749 @retval RETURN_SUCCESS The end of the measurement was recorded.
1750 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1755 EndPerformanceMeasurement (
1756 IN CONST VOID
*Handle
, OPTIONAL
1757 IN CONST CHAR8
*Token
, OPTIONAL
1758 IN CONST CHAR8
*Module
, OPTIONAL
1762 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1766 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1767 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
1768 and then eliminate the Identifier.
1772 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1773 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1774 and the key for the second entry in the log is returned. If the performance log is empty,
1775 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1776 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1777 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1778 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1779 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1780 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1781 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
1782 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1783 If Handle is NULL, then ASSERT().
1784 If Token is NULL, then ASSERT().
1785 If Module is NULL, then ASSERT().
1786 If StartTimeStamp is NULL, then ASSERT().
1787 If EndTimeStamp is NULL, then ASSERT().
1789 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1790 0, then the first performance measurement log entry is retrieved.
1791 On exit, the key of the next performance log entry.
1792 @param Handle Pointer to environment specific context used to identify the component
1794 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1796 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1798 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1800 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1803 @return The key for the next performance log entry (in general case).
1808 GetPerformanceMeasurement (
1809 IN UINTN LogEntryKey
,
1810 OUT CONST VOID
**Handle
,
1811 OUT CONST CHAR8
**Token
,
1812 OUT CONST CHAR8
**Module
,
1813 OUT UINT64
*StartTimeStamp
,
1814 OUT UINT64
*EndTimeStamp
1821 Returns TRUE if the performance measurement macros are enabled.
1823 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1824 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
1826 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1827 PcdPerformanceLibraryPropertyMask is set.
1828 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1829 PcdPerformanceLibraryPropertyMask is clear.
1834 PerformanceMeasurementEnabled (
1838 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
1842 Create performance record with event description and a timestamp.
1844 @param CallerIdentifier - Image handle or pointer to caller ID GUID
1845 @param Guid - Pointer to a GUID
1846 @param String - Pointer to a string describing the measurement
1847 @param Address - Pointer to a location in memory relevant to the measurement
1848 @param Identifier - Performance identifier describing the type of measurement
1850 @retval RETURN_SUCCESS - Successfully created performance record
1851 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
1852 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1853 pointer or invalid PerfId
1858 LogPerformanceMeasurement (
1859 IN CONST VOID
*CallerIdentifier
,
1860 IN CONST VOID
*Guid
, OPTIONAL
1861 IN CONST CHAR8
*String
, OPTIONAL
1862 IN UINT64 Address
, OPTIONAL
1863 IN UINT32 Identifier
1866 return (RETURN_STATUS
)CreatePerformanceMeasurement (CallerIdentifier
, Guid
, String
, 0, Address
, Identifier
, PerfEntry
);
1870 Check whether the specified performance measurement can be logged.
1872 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
1873 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
1875 @param Type - Type of the performance measurement entry.
1877 @retval TRUE The performance measurement can be logged.
1878 @retval FALSE The performance measurement can NOT be logged.
1883 LogPerformanceMeasurementEnabled (
1888 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
1890 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {