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
19 #include "DxeCorePerformanceLibInternal.h"
22 // Data for FPDT performance records.
24 #define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
25 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
26 #define FIRMWARE_RECORD_BUFFER 0x10000
27 #define CACHE_HANDLE_GUID_COUNT 0x800
29 BOOT_PERFORMANCE_TABLE
*mAcpiBootPerformanceTable
= NULL
;
30 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate
= {
32 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE
,
33 sizeof (BOOT_PERFORMANCE_TABLE
)
37 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT
, // Type
38 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD
), // Length
39 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT
// Revision
43 // These values will be updated at runtime.
46 0, // OsLoaderLoadImageStart
47 0, // OsLoaderStartImageStart
48 0, // ExitBootServicesEntry
49 0 // ExitBootServicesExit
55 CHAR8 NameString
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
59 HANDLE_GUID_MAP mCacheHandleGuidTable
[CACHE_HANDLE_GUID_COUNT
];
60 UINTN mCachePairCount
= 0;
62 UINT32 mLoadImageCount
= 0;
63 UINT32 mPerformanceLength
= 0;
64 UINT32 mMaxPerformanceLength
= 0;
65 UINT32 mBootRecordSize
= 0;
66 UINTN mBootRecordMaxSize
= 0;
67 UINT32 mCachedLength
= 0;
69 BOOLEAN mFpdtBufferIsReported
= FALSE
;
70 BOOLEAN mLackSpaceIsReported
= FALSE
;
71 CHAR8
*mPlatformLanguage
= NULL
;
72 UINT8
*mPerformancePointer
= NULL
;
73 UINT8
*mBootRecordBuffer
= NULL
;
74 BOOLEAN mLockInsertRecord
= FALSE
;
75 CHAR8
*mDevicePathString
= NULL
;
77 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*mDevicePathToText
= NULL
;
80 // Interfaces for PerformanceMeasurement Protocol.
82 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface
= {
83 CreatePerformanceMeasurement
,
86 PERFORMANCE_PROPERTY mPerformanceProperty
;
89 Return the pointer to the FPDT record in the allocated memory.
91 @param RecordSize The size of FPDT record.
92 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
94 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
95 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
100 IN OUT FPDT_RECORD_PTR
*FpdtRecordPtr
103 if (mFpdtBufferIsReported
) {
105 // Append Boot records to the boot performance table.
107 if (mBootRecordSize
+ RecordSize
> mBootRecordMaxSize
) {
108 if (!mLackSpaceIsReported
) {
109 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: No enough space to save boot records\n"));
110 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
;
134 mMaxPerformanceLength
= mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
;
138 // Covert buffer to FPDT Ptr Union type.
140 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mPerformanceLength
);
147 Check whether the Token is a known one which is uesed by core.
149 @param Token Pointer to a Null-terminated ASCII string
151 @retval TRUE Is a known one used by core.
152 @retval FALSE Not a known one.
157 IN CONST CHAR8
*Token
164 if ((AsciiStrCmp (Token
, SEC_TOK
) == 0) ||
165 (AsciiStrCmp (Token
, PEI_TOK
) == 0) ||
166 (AsciiStrCmp (Token
, DXE_TOK
) == 0) ||
167 (AsciiStrCmp (Token
, BDS_TOK
) == 0) ||
168 (AsciiStrCmp (Token
, DRIVERBINDING_START_TOK
) == 0) ||
169 (AsciiStrCmp (Token
, DRIVERBINDING_SUPPORT_TOK
) == 0) ||
170 (AsciiStrCmp (Token
, DRIVERBINDING_STOP_TOK
) == 0) ||
171 (AsciiStrCmp (Token
, LOAD_IMAGE_TOK
) == 0) ||
172 (AsciiStrCmp (Token
, START_IMAGE_TOK
) == 0) ||
173 (AsciiStrCmp (Token
, PEIM_TOK
) == 0))
182 Check whether the ID is a known one which map to the known Token.
184 @param Identifier 32-bit identifier.
186 @retval TRUE Is a known one used by core.
187 @retval FALSE Not a known one.
195 if ((Identifier
== MODULE_START_ID
) ||
196 (Identifier
== MODULE_END_ID
) ||
197 (Identifier
== MODULE_LOADIMAGE_START_ID
) ||
198 (Identifier
== MODULE_LOADIMAGE_END_ID
) ||
199 (Identifier
== MODULE_DB_START_ID
) ||
200 (Identifier
== MODULE_DB_END_ID
) ||
201 (Identifier
== MODULE_DB_SUPPORT_START_ID
) ||
202 (Identifier
== MODULE_DB_SUPPORT_END_ID
) ||
203 (Identifier
== MODULE_DB_STOP_START_ID
) ||
204 (Identifier
== MODULE_DB_STOP_END_ID
))
213 This internal function dumps all the SMM performance data and size.
215 @param SmmPerfData Smm Performance data. The buffer contain the SMM perf data is allocated by this function and caller needs to free it.
216 @param SmmPerfDataSize Smm Performance data size.
217 @param SkipGetPerfData Skip to get performance data, just get the size.
221 InternalGetSmmPerfData (
222 OUT VOID
**SmmPerfData
,
223 OUT UINTN
*SmmPerfDataSize
,
224 IN BOOLEAN SkipGetPerfData
228 UINT8
*SmmBootRecordCommBuffer
;
229 EFI_SMM_COMMUNICATE_HEADER
*SmmCommBufferHeader
;
230 SMM_BOOT_RECORD_COMMUNICATE
*SmmCommData
;
232 EFI_SMM_COMMUNICATION_PROTOCOL
*Communication
;
233 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*SmmCommRegionTable
;
234 EFI_MEMORY_DESCRIPTOR
*SmmCommMemRegion
;
236 VOID
*SmmBootRecordData
;
237 UINTN SmmBootRecordDataSize
;
238 UINTN ReservedMemSize
;
241 // Collect boot records from SMM drivers.
243 SmmBootRecordCommBuffer
= NULL
;
245 SmmBootRecordData
= NULL
;
247 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**)&Communication
);
248 if (!EFI_ERROR (Status
)) {
250 // Initialize communicate buffer
251 // Get the prepared Reserved Memory Range
253 Status
= EfiGetSystemConfigurationTable (
254 &gEdkiiPiSmmCommunicationRegionTableGuid
,
255 (VOID
**)&SmmCommRegionTable
257 if (!EFI_ERROR (Status
)) {
258 ASSERT (SmmCommRegionTable
!= NULL
);
259 SmmCommMemRegion
= (EFI_MEMORY_DESCRIPTOR
*)(SmmCommRegionTable
+ 1);
260 for (Index
= 0; Index
< SmmCommRegionTable
->NumberOfEntries
; Index
++) {
261 if (SmmCommMemRegion
->Type
== EfiConventionalMemory
) {
265 SmmCommMemRegion
= (EFI_MEMORY_DESCRIPTOR
*)((UINT8
*)SmmCommMemRegion
+ SmmCommRegionTable
->DescriptorSize
);
268 ASSERT (Index
< SmmCommRegionTable
->NumberOfEntries
);
269 ASSERT (SmmCommMemRegion
->PhysicalStart
> 0);
270 ASSERT (SmmCommMemRegion
->NumberOfPages
> 0);
271 ReservedMemSize
= (UINTN
)SmmCommMemRegion
->NumberOfPages
* EFI_PAGE_SIZE
;
274 // Check enough reserved memory space
276 if (ReservedMemSize
> SMM_BOOT_RECORD_COMM_SIZE
) {
277 SmmBootRecordCommBuffer
= (VOID
*)(UINTN
)SmmCommMemRegion
->PhysicalStart
;
278 SmmCommBufferHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)SmmBootRecordCommBuffer
;
279 SmmCommData
= (SMM_BOOT_RECORD_COMMUNICATE
*)SmmCommBufferHeader
->Data
;
280 ZeroMem ((UINT8
*)SmmCommData
, sizeof (SMM_BOOT_RECORD_COMMUNICATE
));
282 CopyGuid (&SmmCommBufferHeader
->HeaderGuid
, &gEfiFirmwarePerformanceGuid
);
283 SmmCommBufferHeader
->MessageLength
= sizeof (SMM_BOOT_RECORD_COMMUNICATE
);
284 CommSize
= SMM_BOOT_RECORD_COMM_SIZE
;
287 // Get the size of boot records.
289 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE
;
290 SmmCommData
->BootRecordData
= NULL
;
291 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
293 if (!EFI_ERROR (Status
) && !EFI_ERROR (SmmCommData
->ReturnStatus
) && (SmmCommData
->BootRecordSize
!= 0)) {
294 if (SkipGetPerfData
) {
295 *SmmPerfDataSize
= SmmCommData
->BootRecordSize
;
300 // Get all boot records
302 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET
;
303 SmmBootRecordDataSize
= SmmCommData
->BootRecordSize
;
304 SmmBootRecordData
= AllocateZeroPool (SmmBootRecordDataSize
);
305 ASSERT (SmmBootRecordData
!= NULL
);
306 SmmCommData
->BootRecordOffset
= 0;
307 SmmCommData
->BootRecordData
= (VOID
*)((UINTN
)SmmCommMemRegion
->PhysicalStart
+ SMM_BOOT_RECORD_COMM_SIZE
);
308 SmmCommData
->BootRecordSize
= ReservedMemSize
- SMM_BOOT_RECORD_COMM_SIZE
;
309 while (SmmCommData
->BootRecordOffset
< SmmBootRecordDataSize
) {
310 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
311 ASSERT_EFI_ERROR (Status
);
312 ASSERT_EFI_ERROR (SmmCommData
->ReturnStatus
);
313 if (SmmCommData
->BootRecordOffset
+ SmmCommData
->BootRecordSize
> SmmBootRecordDataSize
) {
314 CopyMem ((UINT8
*)SmmBootRecordData
+ SmmCommData
->BootRecordOffset
, SmmCommData
->BootRecordData
, SmmBootRecordDataSize
- SmmCommData
->BootRecordOffset
);
316 CopyMem ((UINT8
*)SmmBootRecordData
+ SmmCommData
->BootRecordOffset
, SmmCommData
->BootRecordData
, SmmCommData
->BootRecordSize
);
319 SmmCommData
->BootRecordOffset
= SmmCommData
->BootRecordOffset
+ SmmCommData
->BootRecordSize
;
322 *SmmPerfData
= SmmBootRecordData
;
323 *SmmPerfDataSize
= SmmBootRecordDataSize
;
331 Allocate buffer for Boot Performance table.
337 AllocateBootPerformanceTable (
343 UINTN BootPerformanceDataSize
;
344 UINT8
*BootPerformanceData
;
345 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
346 UINTN SmmBootRecordDataSize
;
348 SmmBootRecordDataSize
= 0;
351 // Get SMM performance data size at the point of EndOfDxe in order to allocate the boot performance table.
352 // Will Get all the data at ReadyToBoot.
354 InternalGetSmmPerfData (NULL
, &SmmBootRecordDataSize
, TRUE
);
357 // Prepare memory for Boot Performance table.
358 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
360 BootPerformanceDataSize
= sizeof (BOOT_PERFORMANCE_TABLE
) + mPerformanceLength
+ SmmBootRecordDataSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
363 // Try to allocate the same runtime buffer as last time boot.
365 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
366 Size
= sizeof (PerformanceVariable
);
367 Status
= gRT
->GetVariable (
368 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
369 &gEfiFirmwarePerformanceGuid
,
374 if (!EFI_ERROR (Status
)) {
375 Status
= gBS
->AllocatePages (
377 EfiReservedMemoryType
,
378 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
),
379 &PerformanceVariable
.BootPerformanceTablePointer
381 if (!EFI_ERROR (Status
)) {
382 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*)(UINTN
)PerformanceVariable
.BootPerformanceTablePointer
;
386 if (mAcpiBootPerformanceTable
== NULL
) {
388 // Fail to allocate at specified address, continue to allocate at any address.
390 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*)AllocatePeiAccessiblePages (
391 EfiReservedMemoryType
,
392 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
)
394 if (mAcpiBootPerformanceTable
!= NULL
) {
395 ZeroMem (mAcpiBootPerformanceTable
, BootPerformanceDataSize
);
399 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable
));
401 if (mAcpiBootPerformanceTable
== NULL
) {
402 return EFI_OUT_OF_RESOURCES
;
406 // Prepare Boot Performance Table.
408 BootPerformanceData
= (UINT8
*)mAcpiBootPerformanceTable
;
410 // Fill Basic Boot record to Boot Performance Table.
412 CopyMem (mAcpiBootPerformanceTable
, &mBootPerformanceTableTemplate
, sizeof (mBootPerformanceTableTemplate
));
413 BootPerformanceData
= BootPerformanceData
+ mAcpiBootPerformanceTable
->Header
.Length
;
415 // Fill Boot records from boot drivers.
417 if (mPerformancePointer
!= NULL
) {
418 CopyMem (BootPerformanceData
, mPerformancePointer
, mPerformanceLength
);
419 mAcpiBootPerformanceTable
->Header
.Length
+= mPerformanceLength
;
420 BootPerformanceData
= BootPerformanceData
+ mPerformanceLength
;
421 FreePool (mPerformancePointer
);
422 mPerformancePointer
= NULL
;
423 mPerformanceLength
= 0;
424 mMaxPerformanceLength
= 0;
427 mBootRecordBuffer
= (UINT8
*)mAcpiBootPerformanceTable
;
428 mBootRecordSize
= mAcpiBootPerformanceTable
->Header
.Length
;
429 mBootRecordMaxSize
= BootPerformanceDataSize
;
435 Get a human readable module name and module guid for the given image handle.
436 If module name can't be found, "" string will return.
437 If module guid can't be found, Zero Guid will return.
439 @param Handle Image handle or Controller handle.
440 @param NameString The ascii string will be filled into it. If not found, null string will return.
441 @param BufferSize Size of the input NameString buffer.
442 @param ModuleGuid Point to the guid buffer to store the got module guid value.
444 @retval EFI_SUCCESS Successfully get module name and guid.
445 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
446 @retval other value Module Name can't be got.
449 GetModuleInfoFromHandle (
450 IN EFI_HANDLE Handle
,
451 OUT CHAR8
*NameString
,
453 OUT EFI_GUID
*ModuleGuid OPTIONAL
457 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
458 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
464 BOOLEAN ModuleGuidIsGet
;
467 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
468 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
470 if ((NameString
== NULL
) || (BufferSize
== 0)) {
471 return EFI_INVALID_PARAMETER
;
475 // Try to get the ModuleGuid and name string form the caached array.
477 if (mCachePairCount
> 0) {
478 for (Count
= mCachePairCount
-1; Count
>= 0; Count
--) {
479 if (Handle
== mCacheHandleGuidTable
[Count
].Handle
) {
480 CopyGuid (ModuleGuid
, &mCacheHandleGuidTable
[Count
].ModuleGuid
);
481 AsciiStrCpyS (NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, mCacheHandleGuidTable
[Count
].NameString
);
487 Status
= EFI_INVALID_PARAMETER
;
489 ModuleGuidIsGet
= FALSE
;
492 // Initialize GUID as zero value.
494 TempGuid
= &gZeroGuid
;
496 // Initialize it as "" string.
500 if (Handle
!= NULL
) {
502 // Try Handle as ImageHandle.
504 Status
= gBS
->HandleProtocol (
506 &gEfiLoadedImageProtocolGuid
,
507 (VOID
**)&LoadedImage
510 if (EFI_ERROR (Status
)) {
512 // Try Handle as Controller Handle
514 Status
= gBS
->OpenProtocol (
516 &gEfiDriverBindingProtocolGuid
,
517 (VOID
**)&DriverBinding
,
520 EFI_OPEN_PROTOCOL_GET_PROTOCOL
522 if (!EFI_ERROR (Status
)) {
524 // Get Image protocol from ImageHandle
526 Status
= gBS
->HandleProtocol (
527 DriverBinding
->ImageHandle
,
528 &gEfiLoadedImageProtocolGuid
,
529 (VOID
**)&LoadedImage
535 if (!EFI_ERROR (Status
) && (LoadedImage
!= NULL
)) {
537 // Get Module Guid from DevicePath.
539 if ((LoadedImage
->FilePath
!= NULL
) &&
540 (LoadedImage
->FilePath
->Type
== MEDIA_DEVICE_PATH
) &&
541 (LoadedImage
->FilePath
->SubType
== MEDIA_PIWG_FW_FILE_DP
)
545 // Determine GUID associated with module logging performance
547 ModuleGuidIsGet
= TRUE
;
548 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)LoadedImage
->FilePath
;
549 TempGuid
= &FvFilePath
->FvFileName
;
553 // Method 1 Get Module Name from PDB string.
555 PdbFileName
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
556 if ((PdbFileName
!= NULL
) && (BufferSize
> 0)) {
558 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
559 if ((PdbFileName
[Index
] == '\\') || (PdbFileName
[Index
] == '/')) {
560 StartIndex
= Index
+ 1;
565 // Copy the PDB file name to our temporary string.
566 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
568 for (Index
= 0; Index
< BufferSize
- 1; Index
++) {
569 NameString
[Index
] = PdbFileName
[Index
+ StartIndex
];
570 if ((NameString
[Index
] == 0) || (NameString
[Index
] == '.')) {
571 NameString
[Index
] = 0;
576 if (Index
== BufferSize
- 1) {
577 NameString
[Index
] = 0;
581 // Module Name is got.
588 // Method 2: Get the name string from ComponentName2 protocol
590 Status
= gBS
->HandleProtocol (
592 &gEfiComponentName2ProtocolGuid
,
593 (VOID
**)&ComponentName2
595 if (!EFI_ERROR (Status
)) {
597 // Get the current platform language setting
599 if (mPlatformLanguage
== NULL
) {
600 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&mPlatformLanguage
, NULL
);
603 if (mPlatformLanguage
!= NULL
) {
604 Status
= ComponentName2
->GetDriverName (
606 mPlatformLanguage
!= NULL
? mPlatformLanguage
: "en-US",
609 if (!EFI_ERROR (Status
)) {
610 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
611 NameString
[Index
] = (CHAR8
)StringPtr
[Index
];
614 NameString
[Index
] = 0;
616 // Module Name is got.
623 if (ModuleGuidIsGet
) {
625 // Method 3 Try to get the image's FFS UI section by image GUID
629 Status
= GetSectionFromAnyFv (
631 EFI_SECTION_USER_INTERFACE
,
637 if (!EFI_ERROR (Status
)) {
639 // Method 3. Get the name string from FFS UI section
641 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
642 NameString
[Index
] = (CHAR8
)StringPtr
[Index
];
645 NameString
[Index
] = 0;
646 FreePool (StringPtr
);
654 if (ModuleGuid
!= NULL
) {
655 CopyGuid (ModuleGuid
, TempGuid
);
656 if (IsZeroGuid (TempGuid
) && (Handle
!= NULL
) && !ModuleGuidIsGet
) {
658 CopyGuid (ModuleGuid
, (EFI_GUID
*)Handle
);
663 // Cache the Handle and Guid pairs.
665 if (mCachePairCount
< CACHE_HANDLE_GUID_COUNT
) {
666 mCacheHandleGuidTable
[mCachePairCount
].Handle
= Handle
;
667 CopyGuid (&mCacheHandleGuidTable
[mCachePairCount
].ModuleGuid
, ModuleGuid
);
668 AsciiStrCpyS (mCacheHandleGuidTable
[mCachePairCount
].NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, NameString
);
676 Get the FPDT record identifier.
678 @param Attribute The attribute of the Record.
679 PerfStartEntry: Start Record.
680 PerfEndEntry: End Record.
681 @param Handle Pointer to environment specific context used to identify the component being measured.
682 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
683 @param ProgressID On return, pointer to the ProgressID.
685 @retval EFI_SUCCESS Get record info successfully.
686 @retval EFI_INVALID_PARAMETER No matched FPDT record.
691 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
,
692 IN CONST VOID
*Handle
,
693 IN CONST CHAR8
*String
,
694 OUT UINT16
*ProgressID
700 if (String
!= NULL
) {
701 if (AsciiStrCmp (String
, START_IMAGE_TOK
) == 0) {
703 if (Attribute
== PerfStartEntry
) {
704 *ProgressID
= MODULE_START_ID
;
706 *ProgressID
= MODULE_END_ID
;
708 } else if (AsciiStrCmp (String
, LOAD_IMAGE_TOK
) == 0) {
710 if (Attribute
== PerfStartEntry
) {
711 *ProgressID
= MODULE_LOADIMAGE_START_ID
;
713 *ProgressID
= MODULE_LOADIMAGE_END_ID
;
715 } else if (AsciiStrCmp (String
, DRIVERBINDING_START_TOK
) == 0) {
717 if (Attribute
== PerfStartEntry
) {
718 *ProgressID
= MODULE_DB_START_ID
;
720 *ProgressID
= MODULE_DB_END_ID
;
722 } else if (AsciiStrCmp (String
, DRIVERBINDING_SUPPORT_TOK
) == 0) {
724 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
725 return RETURN_UNSUPPORTED
;
728 if (Attribute
== PerfStartEntry
) {
729 *ProgressID
= MODULE_DB_SUPPORT_START_ID
;
731 *ProgressID
= MODULE_DB_SUPPORT_END_ID
;
733 } else if (AsciiStrCmp (String
, DRIVERBINDING_STOP_TOK
) == 0) {
735 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
736 return RETURN_UNSUPPORTED
;
739 if (Attribute
== PerfStartEntry
) {
740 *ProgressID
= MODULE_DB_STOP_START_ID
;
742 *ProgressID
= MODULE_DB_STOP_END_ID
;
744 } else if ((AsciiStrCmp (String
, PEI_TOK
) == 0) || // "PEI"
745 (AsciiStrCmp (String
, DXE_TOK
) == 0) || // "DXE"
746 (AsciiStrCmp (String
, BDS_TOK
) == 0)) // "BDS"
748 if (Attribute
== PerfStartEntry
) {
749 *ProgressID
= PERF_CROSSMODULE_START_ID
;
751 *ProgressID
= PERF_CROSSMODULE_END_ID
;
754 // Pref used in Modules.
755 if (Attribute
== PerfStartEntry
) {
756 *ProgressID
= PERF_INMODULE_START_ID
;
758 *ProgressID
= PERF_INMODULE_END_ID
;
761 } else if (Handle
!= NULL
) {
762 // Pref used in Modules.
763 if (Attribute
== PerfStartEntry
) {
764 *ProgressID
= PERF_INMODULE_START_ID
;
766 *ProgressID
= PERF_INMODULE_END_ID
;
769 return EFI_INVALID_PARAMETER
;
776 Copies the string from Source into Destination and updates Length with the
779 @param Destination - destination of the string copy
780 @param Source - pointer to the source string which will get copied
781 @param Length - pointer to a length variable to be updated
785 CopyStringIntoPerfRecordAndUpdateLength (
786 IN OUT CHAR8
*Destination
,
787 IN CONST CHAR8
*Source
,
794 ASSERT (Source
!= NULL
);
796 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
797 DestMax
= STRING_SIZE
;
799 DestMax
= AsciiStrSize (Source
);
800 if (DestMax
> STRING_SIZE
) {
801 DestMax
= STRING_SIZE
;
805 StringLen
= AsciiStrLen (Source
);
806 if (StringLen
>= DestMax
) {
807 StringLen
= DestMax
-1;
810 AsciiStrnCpyS (Destination
, DestMax
, Source
, StringLen
);
811 *Length
+= (UINT8
)DestMax
;
817 Get a string description for device for the given controller handle and update record
818 length. If ComponentName2 GetControllerName is supported, the value is included in the string,
819 followed by device path, otherwise just device path.
821 @param Handle - Image handle
822 @param ControllerHandle - Controller handle.
823 @param ComponentNameString - Pointer to a location where the string will be saved
824 @param Length - Pointer to record length to be updated
826 @retval EFI_SUCCESS - Successfully got string description for device
827 @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found
831 GetDeviceInfoFromHandleAndUpdateLength (
832 IN CONST VOID
*Handle
,
833 IN EFI_HANDLE ControllerHandle
,
834 OUT CHAR8
*ComponentNameString
,
838 EFI_DEVICE_PATH_PROTOCOL
*DevicePathProtocol
;
839 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
842 CHAR8
*AsciiStringPtr
;
843 UINTN ControllerNameStringSize
;
844 UINTN DevicePathStringSize
;
846 ControllerNameStringSize
= 0;
848 Status
= gBS
->HandleProtocol (
850 &gEfiComponentName2ProtocolGuid
,
851 (VOID
**)&ComponentName2
854 if (!EFI_ERROR (Status
)) {
856 // Get the current platform language setting
858 if (mPlatformLanguage
== NULL
) {
859 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&mPlatformLanguage
, NULL
);
862 Status
= ComponentName2
->GetControllerName (
866 mPlatformLanguage
!= NULL
? mPlatformLanguage
: "en-US",
871 if (!EFI_ERROR (Status
)) {
873 // This will produce the size of the unicode string, which is twice as large as the ASCII one
874 // This must be an even number, so ok to divide by 2
876 ControllerNameStringSize
= StrSize (StringPtr
) / 2;
879 // The + 1 is because we want to add a space between the ControllerName and the device path
881 if ((ControllerNameStringSize
+ (*Length
) + 1) > FPDT_MAX_PERF_RECORD_SIZE
) {
883 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
885 ControllerNameStringSize
= FPDT_MAX_PERF_RECORD_SIZE
- (*Length
) - 1;
888 UnicodeStrnToAsciiStrS (StringPtr
, ControllerNameStringSize
- 1, ComponentNameString
, ControllerNameStringSize
, &ControllerNameStringSize
);
891 // Add a space in the end of the ControllerName
893 AsciiStringPtr
= ComponentNameString
+ ControllerNameStringSize
- 1;
894 *AsciiStringPtr
= 0x20;
897 ControllerNameStringSize
++;
899 *Length
+= (UINT8
)ControllerNameStringSize
;
903 // This function returns the device path protocol from the handle specified by Handle. If Handle is
904 // NULL or Handle does not contain a device path protocol, then NULL is returned.
906 DevicePathProtocol
= DevicePathFromHandle (ControllerHandle
);
908 if (DevicePathProtocol
!= NULL
) {
909 StringPtr
= ConvertDevicePathToText (DevicePathProtocol
, TRUE
, FALSE
);
910 if (StringPtr
!= NULL
) {
912 // This will produce the size of the unicode string, which is twice as large as the ASCII one
913 // This must be an even number, so ok to divide by 2
915 DevicePathStringSize
= StrSize (StringPtr
) / 2;
917 if ((DevicePathStringSize
+ (*Length
)) > FPDT_MAX_PERF_RECORD_SIZE
) {
919 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
921 DevicePathStringSize
= FPDT_MAX_PERF_RECORD_SIZE
- (*Length
);
924 if (ControllerNameStringSize
!= 0) {
925 AsciiStringPtr
= ComponentNameString
+ ControllerNameStringSize
- 1;
927 AsciiStringPtr
= ComponentNameString
;
930 UnicodeStrnToAsciiStrS (StringPtr
, DevicePathStringSize
- 1, AsciiStringPtr
, DevicePathStringSize
, &DevicePathStringSize
);
931 *Length
+= (UINT8
)DevicePathStringSize
;
936 return EFI_UNSUPPORTED
;
940 Create performance record with event description and a timestamp.
942 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
943 @param Guid - Pointer to a GUID.
944 @param String - Pointer to a string describing the measurement.
945 @param Ticker - 64-bit time stamp.
946 @param Address - Pointer to a location in memory relevant to the measurement.
947 @param PerfId - Performance identifier describing the type of measurement.
948 @param Attribute - The attribute of the measurement. According to attribute can create a start
949 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
950 or a general record for other Perf macros.
952 @retval EFI_SUCCESS - Successfully created performance record.
953 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
954 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
955 pointer or invalid PerfId.
957 @retval EFI_SUCCESS - Successfully created performance record
958 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records
959 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
960 pointer or invalid PerfId
965 IN CONST VOID
*CallerIdentifier OPTIONAL
,
966 IN CONST VOID
*Guid OPTIONAL
,
967 IN CONST CHAR8
*String OPTIONAL
,
969 IN UINT64 Address OPTIONAL
,
971 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
975 CHAR8 ModuleName
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
976 FPDT_RECORD_PTR FpdtRecordPtr
;
977 FPDT_RECORD_PTR CachedFpdtRecordPtr
;
979 CONST CHAR8
*StringPtr
;
987 ZeroMem (ModuleName
, sizeof (ModuleName
));
990 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
991 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
993 if (Attribute
!= PerfEntry
) {
995 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
996 // !!! Note: If the Perf is not the known Token used in the core but have same
997 // ID with the core Token, this case will not be supported.
998 // And in currtnt usage mode, for the unkown ID, there is a general rule:
999 // If it is start pref: the lower 4 bits of the ID should be 0.
1000 // If it is end pref: the lower 4 bits of the ID should not be 0.
1001 // If input ID doesn't follow the rule, we will adjust it.
1003 if ((PerfId
!= 0) && (IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
1004 return EFI_INVALID_PARAMETER
;
1005 } else if ((PerfId
!= 0) && (!IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
1006 if ((Attribute
== PerfStartEntry
) && ((PerfId
& 0x000F) != 0)) {
1008 } else if ((Attribute
== PerfEndEntry
) && ((PerfId
& 0x000F) == 0)) {
1011 } else if (PerfId
== 0) {
1013 // Get ProgressID form the String Token.
1015 Status
= GetFpdtRecordId (Attribute
, CallerIdentifier
, String
, &ProgressId
);
1016 if (EFI_ERROR (Status
)) {
1020 PerfId
= ProgressId
;
1025 // 2. Get the buffer to store the FPDT record.
1027 Status
= GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE
, &FpdtRecordPtr
);
1028 if (EFI_ERROR (Status
)) {
1033 // 3. Get the TimeStamp.
1036 Ticker
= GetPerformanceCounter ();
1037 TimeStamp
= GetTimeInNanoSecond (Ticker
);
1038 } else if (Ticker
== 1) {
1041 TimeStamp
= GetTimeInNanoSecond (Ticker
);
1045 // 4. Fill in the FPDT record according to different Performance Identifier.
1048 case MODULE_START_ID
:
1050 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1051 StringPtr
= ModuleName
;
1053 // Cache the offset of start image start record and use to update the start image end record if needed.
1055 if ((Attribute
== PerfEntry
) && (PerfId
== MODULE_START_ID
)) {
1056 if (mFpdtBufferIsReported
) {
1057 mCachedLength
= mBootRecordSize
;
1059 mCachedLength
= mPerformanceLength
;
1063 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1064 FpdtRecordPtr
.GuidEvent
->Header
.Type
= FPDT_GUID_EVENT_TYPE
;
1065 FpdtRecordPtr
.GuidEvent
->Header
.Length
= sizeof (FPDT_GUID_EVENT_RECORD
);
1066 FpdtRecordPtr
.GuidEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1067 FpdtRecordPtr
.GuidEvent
->ProgressID
= PerfId
;
1068 FpdtRecordPtr
.GuidEvent
->Timestamp
= TimeStamp
;
1069 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
1070 if ((CallerIdentifier
== NULL
) && (PerfId
== MODULE_END_ID
) && (mCachedLength
!= 0)) {
1071 if (mFpdtBufferIsReported
) {
1072 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1074 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1077 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &CachedFpdtRecordPtr
.GuidEvent
->Guid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
1084 case MODULE_LOADIMAGE_START_ID
:
1085 case MODULE_LOADIMAGE_END_ID
:
1086 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1087 StringPtr
= ModuleName
;
1088 if (PerfId
== MODULE_LOADIMAGE_START_ID
) {
1091 // Cache the offset of load image start record and use to be updated by the load image end record if needed.
1093 if ((CallerIdentifier
== NULL
) && (Attribute
== PerfEntry
)) {
1094 if (mFpdtBufferIsReported
) {
1095 mCachedLength
= mBootRecordSize
;
1097 mCachedLength
= mPerformanceLength
;
1102 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1103 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
1104 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
1105 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1106 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
1107 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
1108 FpdtRecordPtr
.GuidQwordEvent
->Qword
= mLoadImageCount
;
1109 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
1110 if ((PerfId
== MODULE_LOADIMAGE_END_ID
) && (mCachedLength
!= 0)) {
1111 if (mFpdtBufferIsReported
) {
1112 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1114 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1117 CopyMem (&CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
));
1124 case MODULE_DB_START_ID
:
1125 case MODULE_DB_SUPPORT_START_ID
:
1126 case MODULE_DB_SUPPORT_END_ID
:
1127 case MODULE_DB_STOP_START_ID
:
1128 case MODULE_DB_STOP_END_ID
:
1129 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1130 StringPtr
= ModuleName
;
1131 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1132 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
1133 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
1134 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1135 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
1136 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
1137 FpdtRecordPtr
.GuidQwordEvent
->Qword
= Address
;
1138 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
1143 case MODULE_DB_END_ID
:
1144 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1145 StringPtr
= ModuleName
;
1146 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1147 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Type
= FPDT_GUID_QWORD_STRING_EVENT_TYPE
;
1148 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD
);
1149 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1150 FpdtRecordPtr
.GuidQwordStringEvent
->ProgressID
= PerfId
;
1151 FpdtRecordPtr
.GuidQwordStringEvent
->Timestamp
= TimeStamp
;
1152 FpdtRecordPtr
.GuidQwordStringEvent
->Qword
= Address
;
1153 CopyMem (&FpdtRecordPtr
.GuidQwordStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordStringEvent
->Guid
));
1155 GetDeviceInfoFromHandleAndUpdateLength (CallerIdentifier
, (EFI_HANDLE
)(UINTN
)Address
, FpdtRecordPtr
.GuidQwordStringEvent
->String
, &FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Length
);
1161 case PERF_EVENTSIGNAL_START_ID
:
1162 case PERF_EVENTSIGNAL_END_ID
:
1163 case PERF_CALLBACK_START_ID
:
1164 case PERF_CALLBACK_END_ID
:
1165 if ((String
== NULL
) || (Guid
== NULL
)) {
1166 return EFI_INVALID_PARAMETER
;
1170 if (AsciiStrLen (String
) == 0) {
1171 StringPtr
= "unknown name";
1174 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1175 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
1176 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
1177 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1178 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
1179 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
1180 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, CallerIdentifier
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
1181 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
1182 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DualGuidStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
);
1188 case PERF_FUNCTION_START_ID
:
1189 case PERF_FUNCTION_END_ID
:
1190 case PERF_INMODULE_START_ID
:
1191 case PERF_INMODULE_END_ID
:
1192 case PERF_CROSSMODULE_START_ID
:
1193 case PERF_CROSSMODULE_END_ID
:
1194 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1195 if (String
!= NULL
) {
1198 StringPtr
= ModuleName
;
1201 if (AsciiStrLen (StringPtr
) == 0) {
1202 StringPtr
= "unknown name";
1205 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1206 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1207 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1208 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1209 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1210 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1211 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1212 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1218 if (Attribute
!= PerfEntry
) {
1219 GetModuleInfoFromHandle ((EFI_HANDLE
)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1220 if (String
!= NULL
) {
1223 StringPtr
= ModuleName
;
1226 if (AsciiStrLen (StringPtr
) == 0) {
1227 StringPtr
= "unknown name";
1230 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1231 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1232 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1233 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1234 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1235 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1236 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1237 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1240 return EFI_INVALID_PARAMETER
;
1247 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
1249 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1250 if ((StringPtr
== NULL
) || (PerfId
== MODULE_DB_SUPPORT_START_ID
) || (PerfId
== MODULE_DB_SUPPORT_END_ID
)) {
1251 return EFI_INVALID_PARAMETER
;
1254 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1255 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1256 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1257 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1258 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1261 // Cache the event guid in string event record.
1263 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1265 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1268 if (AsciiStrLen (StringPtr
) == 0) {
1269 StringPtr
= "unknown name";
1272 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1274 if ((PerfId
== MODULE_LOADIMAGE_START_ID
) || (PerfId
== MODULE_END_ID
)) {
1275 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= (UINT8
)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
)+ STRING_SIZE
);
1278 if (((PerfId
== MODULE_LOADIMAGE_END_ID
) || (PerfId
== MODULE_END_ID
)) && (mCachedLength
!= 0)) {
1279 if (mFpdtBufferIsReported
) {
1280 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1282 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1285 if (PerfId
== MODULE_LOADIMAGE_END_ID
) {
1286 DestMax
= CachedFpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1287 StringLen
= AsciiStrLen (StringPtr
);
1288 if (StringLen
>= DestMax
) {
1289 StringLen
= DestMax
-1;
1292 CopyMem (&CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
1293 AsciiStrnCpyS (CachedFpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, StringPtr
, StringLen
);
1294 } else if (PerfId
== MODULE_END_ID
) {
1295 DestMax
= FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1296 StringLen
= AsciiStrLen (CachedFpdtRecordPtr
.DynamicStringEvent
->String
);
1297 if (StringLen
>= DestMax
) {
1298 StringLen
= DestMax
-1;
1301 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
1302 AsciiStrnCpyS (FpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, CachedFpdtRecordPtr
.DynamicStringEvent
->String
, StringLen
);
1310 // 5. Update the length of the used buffer after fill in the record.
1312 if (mFpdtBufferIsReported
) {
1313 mBootRecordSize
+= FpdtRecordPtr
.RecordHeader
->Length
;
1314 mAcpiBootPerformanceTable
->Header
.Length
+= FpdtRecordPtr
.RecordHeader
->Length
;
1316 mPerformanceLength
+= FpdtRecordPtr
.RecordHeader
->Length
;
1323 Dumps all the PEI performance.
1325 @param HobStart A pointer to a Guid.
1327 This internal function dumps all the PEI performance log to the DXE performance gauge array.
1328 It retrieves the optional GUID HOB for PEI performance and then saves the performance data
1329 to DXE performance data structures.
1333 InternalGetPeiPerformance (
1337 UINT8
*FirmwarePerformanceHob
;
1338 FPDT_PEI_EXT_PERF_HEADER
*PeiPerformanceLogHeader
;
1340 EFI_HOB_GUID_TYPE
*GuidHob
;
1342 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, HobStart
);
1343 while (GuidHob
!= NULL
) {
1344 FirmwarePerformanceHob
= GET_GUID_HOB_DATA (GuidHob
);
1345 PeiPerformanceLogHeader
= (FPDT_PEI_EXT_PERF_HEADER
*)FirmwarePerformanceHob
;
1347 if (mPerformanceLength
+ PeiPerformanceLogHeader
->SizeOfAllEntries
> mMaxPerformanceLength
) {
1348 mPerformancePointer
= ReallocatePool (
1350 mPerformanceLength
+
1351 (UINTN
)PeiPerformanceLogHeader
->SizeOfAllEntries
+
1352 FIRMWARE_RECORD_BUFFER
,
1355 ASSERT (mPerformancePointer
!= NULL
);
1356 mMaxPerformanceLength
= mPerformanceLength
+
1357 (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
) +
1358 FIRMWARE_RECORD_BUFFER
;
1361 EventRec
= mPerformancePointer
+ mPerformanceLength
;
1362 CopyMem (EventRec
, FirmwarePerformanceHob
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
), (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
));
1364 // Update the used buffer size.
1366 mPerformanceLength
+= (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
);
1367 mLoadImageCount
+= PeiPerformanceLogHeader
->LoadImageCount
;
1370 // Get next performance guid hob
1372 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, GET_NEXT_HOB (GuidHob
));
1377 Report Boot Perforamnce table address as report status code.
1379 @param Event The event of notify protocol.
1380 @param Context Notify event context.
1385 ReportFpdtRecordBuffer (
1393 if (!mFpdtBufferIsReported
) {
1394 Status
= AllocateBootPerformanceTable ();
1395 if (!EFI_ERROR (Status
)) {
1396 BPDTAddr
= (UINT64
)(UINTN
)mAcpiBootPerformanceTable
;
1397 REPORT_STATUS_CODE_EX (
1399 EFI_SOFTWARE_DXE_BS_DRIVER
,
1402 &gEdkiiFpdtExtendedFirmwarePerformanceGuid
,
1409 // Set FPDT report state to TRUE.
1411 mFpdtBufferIsReported
= TRUE
;
1416 Update Boot Performance table.
1418 @param Event The event of notify protocol.
1419 @param Context Notify event context.
1424 UpdateBootPerformanceTable (
1429 VOID
*SmmBootRecordData
;
1430 UINTN SmmBootRecordDataSize
;
1432 UINT8
*FirmwarePerformanceTablePtr
;
1434 SmmBootRecordDataSize
= 0;
1437 // Get SMM performance data.
1439 SmmBootRecordData
= NULL
;
1440 InternalGetSmmPerfData (&SmmBootRecordData
, &SmmBootRecordDataSize
, FALSE
);
1442 FirmwarePerformanceTablePtr
= (UINT8
*)mAcpiBootPerformanceTable
+ mAcpiBootPerformanceTable
->Header
.Length
;
1444 if (mAcpiBootPerformanceTable
->Header
.Length
+ SmmBootRecordDataSize
> mBootRecordMaxSize
) {
1445 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: No enough space to save all SMM boot performance data\n"));
1446 AppendSize
= mBootRecordMaxSize
- mAcpiBootPerformanceTable
->Header
.Length
;
1448 AppendSize
= SmmBootRecordDataSize
;
1451 if (SmmBootRecordData
!= NULL
) {
1452 CopyMem (FirmwarePerformanceTablePtr
, SmmBootRecordData
, AppendSize
);
1453 mAcpiBootPerformanceTable
->Header
.Length
+= (UINT32
)AppendSize
;
1454 mBootRecordSize
+= (UINT32
)AppendSize
;
1455 FreePool (SmmBootRecordData
);
1460 The constructor function initializes Performance infrastructure for DXE phase.
1462 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance
1463 and merges PEI performance data to DXE performance log.
1464 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
1466 @param ImageHandle The firmware allocated handle for the EFI image.
1467 @param SystemTable A pointer to the EFI System Table.
1469 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
1474 DxeCorePerformanceLibConstructor (
1475 IN EFI_HANDLE ImageHandle
,
1476 IN EFI_SYSTEM_TABLE
*SystemTable
1481 EFI_EVENT EndOfDxeEvent
;
1482 EFI_EVENT ReadyToBootEvent
;
1483 PERFORMANCE_PROPERTY
*PerformanceProperty
;
1485 if (!PerformanceMeasurementEnabled ()) {
1487 // Do not initialize performance infrastructure if not required.
1493 // Dump normal PEI performance records
1495 InternalGetPeiPerformance (GetHobList ());
1498 // Install the protocol interfaces for DXE performance library instance.
1501 Status
= gBS
->InstallMultipleProtocolInterfaces (
1503 &gEdkiiPerformanceMeasurementProtocolGuid
,
1504 &mPerformanceMeasurementInterface
,
1507 ASSERT_EFI_ERROR (Status
);
1510 // Register EndOfDxe event to allocate the boot performance table and report the table address through status code.
1512 Status
= gBS
->CreateEventEx (
1515 ReportFpdtRecordBuffer
,
1517 &gEfiEndOfDxeEventGroupGuid
,
1522 // Register ReadyToBoot event to update the boot performance table for SMM performance data.
1524 Status
= gBS
->CreateEventEx (
1527 UpdateBootPerformanceTable
,
1529 &gEfiEventReadyToBootGuid
,
1533 ASSERT_EFI_ERROR (Status
);
1535 Status
= EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid
, (VOID
**)&PerformanceProperty
);
1536 if (EFI_ERROR (Status
)) {
1538 // Install configuration table for performance property.
1540 mPerformanceProperty
.Revision
= PERFORMANCE_PROPERTY_REVISION
;
1541 mPerformanceProperty
.Reserved
= 0;
1542 mPerformanceProperty
.Frequency
= GetPerformanceCounterProperties (
1543 &mPerformanceProperty
.TimerStartValue
,
1544 &mPerformanceProperty
.TimerEndValue
1546 Status
= gBS
->InstallConfigurationTable (&gPerformanceProtocolGuid
, &mPerformanceProperty
);
1547 ASSERT_EFI_ERROR (Status
);
1554 Create performance record with event description and a timestamp.
1556 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
1557 @param Guid - Pointer to a GUID.
1558 @param String - Pointer to a string describing the measurement.
1559 @param TimeStamp - 64-bit time stamp.
1560 @param Address - Pointer to a location in memory relevant to the measurement.
1561 @param Identifier - Performance identifier describing the type of measurement.
1562 @param Attribute - The attribute of the measurement. According to attribute can create a start
1563 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
1564 or a general record for other Perf macros.
1566 @retval EFI_SUCCESS - Successfully created performance record.
1567 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
1568 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1569 pointer or invalid PerfId.
1573 CreatePerformanceMeasurement (
1574 IN CONST VOID
*CallerIdentifier
,
1575 IN CONST VOID
*Guid OPTIONAL
,
1576 IN CONST CHAR8
*String OPTIONAL
,
1577 IN UINT64 TimeStamp
,
1578 IN UINT64 Address OPTIONAL
,
1579 IN UINT32 Identifier
,
1580 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
1585 Status
= EFI_SUCCESS
;
1587 if (mLockInsertRecord
) {
1588 return EFI_INVALID_PARAMETER
;
1591 mLockInsertRecord
= TRUE
;
1593 Status
= InsertFpdtRecord (CallerIdentifier
, Guid
, String
, TimeStamp
, Address
, (UINT16
)Identifier
, Attribute
);
1595 mLockInsertRecord
= FALSE
;
1601 Adds a record at the end of the performance measurement log
1602 that records the start time of a performance measurement.
1604 Adds a record to the end of the performance measurement log
1605 that contains the Handle, Token, Module and Identifier.
1606 The end time of the new record must be set to zero.
1607 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1608 If TimeStamp is zero, the start time in the record is filled in with the value
1609 read from the current time stamp.
1611 @param Handle Pointer to environment specific context used
1612 to identify the component being measured.
1613 @param Token Pointer to a Null-terminated ASCII string
1614 that identifies the component being measured.
1615 @param Module Pointer to a Null-terminated ASCII string
1616 that identifies the module being measured.
1617 @param TimeStamp 64-bit time stamp.
1618 @param Identifier 32-bit identifier. If the value is 0, the created record
1619 is same as the one created by StartPerformanceMeasurement.
1621 @retval RETURN_SUCCESS The start of the measurement was recorded.
1622 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1627 StartPerformanceMeasurementEx (
1628 IN CONST VOID
*Handle OPTIONAL
,
1629 IN CONST CHAR8
*Token OPTIONAL
,
1630 IN CONST CHAR8
*Module OPTIONAL
,
1631 IN UINT64 TimeStamp
,
1632 IN UINT32 Identifier
1635 CONST CHAR8
*String
;
1637 if (Token
!= NULL
) {
1639 } else if (Module
!= NULL
) {
1645 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfStartEntry
);
1649 Searches the performance measurement log from the beginning of the log
1650 for the first matching record that contains a zero end time and fills in a valid end time.
1652 Searches the performance measurement log from the beginning of the log
1653 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
1654 If the record can not be found then return RETURN_NOT_FOUND.
1655 If the record is found and TimeStamp is not zero,
1656 then the end time in the record is filled in with the value specified by TimeStamp.
1657 If the record is found and TimeStamp is zero, then the end time in the matching record
1658 is filled in with the current time stamp value.
1660 @param Handle Pointer to environment specific context used
1661 to identify the component being measured.
1662 @param Token Pointer to a Null-terminated ASCII string
1663 that identifies the component being measured.
1664 @param Module Pointer to a Null-terminated ASCII string
1665 that identifies the module being measured.
1666 @param TimeStamp 64-bit time stamp.
1667 @param Identifier 32-bit identifier. If the value is 0, the found record
1668 is same as the one found by EndPerformanceMeasurement.
1670 @retval RETURN_SUCCESS The end of the measurement was recorded.
1671 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1676 EndPerformanceMeasurementEx (
1677 IN CONST VOID
*Handle OPTIONAL
,
1678 IN CONST CHAR8
*Token OPTIONAL
,
1679 IN CONST CHAR8
*Module OPTIONAL
,
1680 IN UINT64 TimeStamp
,
1681 IN UINT32 Identifier
1684 CONST CHAR8
*String
;
1686 if (Token
!= NULL
) {
1688 } else if (Module
!= NULL
) {
1694 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfEndEntry
);
1698 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1699 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
1700 and then assign the Identifier with 0.
1704 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1705 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1706 and the key for the second entry in the log is returned. If the performance log is empty,
1707 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1708 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1709 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1710 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1711 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1712 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1713 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
1714 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1715 If Handle is NULL, then ASSERT().
1716 If Token is NULL, then ASSERT().
1717 If Module is NULL, then ASSERT().
1718 If StartTimeStamp is NULL, then ASSERT().
1719 If EndTimeStamp is NULL, then ASSERT().
1720 If Identifier is NULL, then ASSERT().
1722 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1723 0, then the first performance measurement log entry is retrieved.
1724 On exit, the key of the next performance log entry.
1725 @param Handle Pointer to environment specific context used to identify the component
1727 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1729 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1731 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1733 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1735 @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement
1738 @return The key for the next performance log entry (in general case).
1743 GetPerformanceMeasurementEx (
1744 IN UINTN LogEntryKey
,
1745 OUT CONST VOID
**Handle
,
1746 OUT CONST CHAR8
**Token
,
1747 OUT CONST CHAR8
**Module
,
1748 OUT UINT64
*StartTimeStamp
,
1749 OUT UINT64
*EndTimeStamp
,
1750 OUT UINT32
*Identifier
1757 Adds a record at the end of the performance measurement log
1758 that records the start time of a performance measurement.
1760 Adds a record to the end of the performance measurement log
1761 that contains the Handle, Token, and Module.
1762 The end time of the new record must be set to zero.
1763 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1764 If TimeStamp is zero, the start time in the record is filled in with the value
1765 read from the current time stamp.
1767 @param Handle Pointer to environment specific context used
1768 to identify the component being measured.
1769 @param Token Pointer to a Null-terminated ASCII string
1770 that identifies the component being measured.
1771 @param Module Pointer to a Null-terminated ASCII string
1772 that identifies the module being measured.
1773 @param TimeStamp 64-bit time stamp.
1775 @retval RETURN_SUCCESS The start of the measurement was recorded.
1776 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1781 StartPerformanceMeasurement (
1782 IN CONST VOID
*Handle OPTIONAL
,
1783 IN CONST CHAR8
*Token OPTIONAL
,
1784 IN CONST CHAR8
*Module OPTIONAL
,
1788 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1792 Searches the performance measurement log from the beginning of the log
1793 for the first matching record that contains a zero end time and fills in a valid end time.
1795 Searches the performance measurement log from the beginning of the log
1796 for the first record that matches Handle, Token, and Module and has an end time value of zero.
1797 If the record can not be found then return RETURN_NOT_FOUND.
1798 If the record is found and TimeStamp is not zero,
1799 then the end time in the record is filled in with the value specified by TimeStamp.
1800 If the record is found and TimeStamp is zero, then the end time in the matching record
1801 is filled in with the current time stamp value.
1803 @param Handle Pointer to environment specific context used
1804 to identify the component being measured.
1805 @param Token Pointer to a Null-terminated ASCII string
1806 that identifies the component being measured.
1807 @param Module Pointer to a Null-terminated ASCII string
1808 that identifies the module being measured.
1809 @param TimeStamp 64-bit time stamp.
1811 @retval RETURN_SUCCESS The end of the measurement was recorded.
1812 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1817 EndPerformanceMeasurement (
1818 IN CONST VOID
*Handle OPTIONAL
,
1819 IN CONST CHAR8
*Token OPTIONAL
,
1820 IN CONST CHAR8
*Module OPTIONAL
,
1824 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1828 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1829 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
1830 and then eliminate the Identifier.
1834 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1835 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1836 and the key for the second entry in the log is returned. If the performance log is empty,
1837 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1838 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1839 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1840 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1841 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1842 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1843 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
1844 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1845 If Handle is NULL, then ASSERT().
1846 If Token is NULL, then ASSERT().
1847 If Module is NULL, then ASSERT().
1848 If StartTimeStamp is NULL, then ASSERT().
1849 If EndTimeStamp is NULL, then ASSERT().
1851 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1852 0, then the first performance measurement log entry is retrieved.
1853 On exit, the key of the next performance log entry.
1854 @param Handle Pointer to environment specific context used to identify the component
1856 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1858 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1860 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1862 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1865 @return The key for the next performance log entry (in general case).
1870 GetPerformanceMeasurement (
1871 IN UINTN LogEntryKey
,
1872 OUT CONST VOID
**Handle
,
1873 OUT CONST CHAR8
**Token
,
1874 OUT CONST CHAR8
**Module
,
1875 OUT UINT64
*StartTimeStamp
,
1876 OUT UINT64
*EndTimeStamp
1883 Returns TRUE if the performance measurement macros are enabled.
1885 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1886 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
1888 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1889 PcdPerformanceLibraryPropertyMask is set.
1890 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1891 PcdPerformanceLibraryPropertyMask is clear.
1896 PerformanceMeasurementEnabled (
1900 return (BOOLEAN
)((PcdGet8 (PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
1904 Create performance record with event description and a timestamp.
1906 @param CallerIdentifier - Image handle or pointer to caller ID GUID
1907 @param Guid - Pointer to a GUID
1908 @param String - Pointer to a string describing the measurement
1909 @param Address - Pointer to a location in memory relevant to the measurement
1910 @param Identifier - Performance identifier describing the type of measurement
1912 @retval RETURN_SUCCESS - Successfully created performance record
1913 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
1914 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1915 pointer or invalid PerfId
1920 LogPerformanceMeasurement (
1921 IN CONST VOID
*CallerIdentifier
,
1922 IN CONST VOID
*Guid OPTIONAL
,
1923 IN CONST CHAR8
*String OPTIONAL
,
1924 IN UINT64 Address OPTIONAL
,
1925 IN UINT32 Identifier
1928 return (RETURN_STATUS
)CreatePerformanceMeasurement (CallerIdentifier
, Guid
, String
, 0, Address
, Identifier
, PerfEntry
);
1932 Check whether the specified performance measurement can be logged.
1934 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
1935 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
1937 @param Type - Type of the performance measurement entry.
1939 @retval TRUE The performance measurement can be logged.
1940 @retval FALSE The performance measurement can NOT be logged.
1945 LogPerformanceMeasurementEnabled (
1950 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
1952 if (PerformanceMeasurementEnabled () && ((PcdGet8 (PcdPerformanceLibraryPropertyMask
) & Type
) == 0)) {