]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg/DxeCapsuleLibFmp: Use new Variable Lock interface
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
1 /** @file
2 Performance library instance mainly used by DxeCore.
3
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.
9
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.
12
13 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
14 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
15 SPDX-License-Identifier: BSD-2-Clause-Patent
16
17 **/
18
19
20 #include "DxeCorePerformanceLibInternal.h"
21
22 //
23 // Data for FPDT performance records.
24 //
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
29
30 BOOT_PERFORMANCE_TABLE *mAcpiBootPerformanceTable = NULL;
31 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate = {
32 {
33 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE,
34 sizeof (BOOT_PERFORMANCE_TABLE)
35 },
36 {
37 {
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
41 },
42 0, // Reserved
43 //
44 // These values will be updated at runtime.
45 //
46 0, // ResetEnd
47 0, // OsLoaderLoadImageStart
48 0, // OsLoaderStartImageStart
49 0, // ExitBootServicesEntry
50 0 // ExitBootServicesExit
51 }
52 };
53
54 typedef struct {
55 EFI_HANDLE Handle;
56 CHAR8 NameString[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];
57 EFI_GUID ModuleGuid;
58 } HANDLE_GUID_MAP;
59
60 HANDLE_GUID_MAP mCacheHandleGuidTable[CACHE_HANDLE_GUID_COUNT];
61 UINTN mCachePairCount = 0;
62
63 UINT32 mLoadImageCount = 0;
64 UINT32 mPerformanceLength = 0;
65 UINT32 mMaxPerformanceLength = 0;
66 UINT32 mBootRecordSize = 0;
67 UINT32 mBootRecordMaxSize = 0;
68 UINT32 mCachedLength = 0;
69
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;
77
78 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathToText = NULL;
79
80 //
81 // Interfaces for PerformanceMeasurement Protocol.
82 //
83 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
84 CreatePerformanceMeasurement,
85 };
86
87 PERFORMANCE_PROPERTY mPerformanceProperty;
88
89 /**
90 Return the pointer to the FPDT record in the allocated memory.
91
92 @param RecordSize The size of FPDT record.
93 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
94
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.
97 **/
98 EFI_STATUS
99 GetFpdtRecordPtr (
100 IN UINT8 RecordSize,
101 IN OUT FPDT_RECORD_PTR *FpdtRecordPtr
102 )
103 {
104 if (mFpdtBufferIsReported) {
105 //
106 // Append Boot records to the boot performance table.
107 //
108 if (mBootRecordSize + RecordSize > mBootRecordMaxSize) {
109 if (!mLackSpaceIsReported) {
110 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: No enough space to save boot records\n"));
111 mLackSpaceIsReported = TRUE;
112 }
113 return EFI_OUT_OF_RESOURCES;
114 } else {
115 //
116 // Save boot record into BootPerformance table
117 //
118 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mBootRecordSize);
119 }
120 } else {
121 //
122 // Check if pre-allocated buffer is full
123 //
124 if (mPerformanceLength + RecordSize > mMaxPerformanceLength) {
125 mPerformancePointer = ReallocatePool (
126 mPerformanceLength,
127 mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER,
128 mPerformancePointer
129 );
130 if (mPerformancePointer == NULL) {
131 return EFI_OUT_OF_RESOURCES;
132 }
133 mMaxPerformanceLength = mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER;
134 }
135 //
136 // Covert buffer to FPDT Ptr Union type.
137 //
138 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mPerformanceLength);
139 }
140 return EFI_SUCCESS;
141 }
142
143 /**
144 Check whether the Token is a known one which is uesed by core.
145
146 @param Token Pointer to a Null-terminated ASCII string
147
148 @retval TRUE Is a known one used by core.
149 @retval FALSE Not a known one.
150
151 **/
152 BOOLEAN
153 IsKnownTokens (
154 IN CONST CHAR8 *Token
155 )
156 {
157 if (Token == NULL) {
158 return FALSE;
159 }
160
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) {
171 return TRUE;
172 } else {
173 return FALSE;
174 }
175 }
176
177 /**
178 Check whether the ID is a known one which map to the known Token.
179
180 @param Identifier 32-bit identifier.
181
182 @retval TRUE Is a known one used by core.
183 @retval FALSE Not a known one.
184
185 **/
186 BOOLEAN
187 IsKnownID (
188 IN UINT32 Identifier
189 )
190 {
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) {
201 return TRUE;
202 } else {
203 return FALSE;
204 }
205 }
206
207 /**
208 Allocate buffer for Boot Performance table.
209
210 @return Status code.
211
212 **/
213 EFI_STATUS
214 AllocateBootPerformanceTable (
215 )
216 {
217 EFI_STATUS Status;
218 UINTN Size;
219 UINT8 *SmmBootRecordCommBuffer;
220 EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;
221 SMM_BOOT_RECORD_COMMUNICATE *SmmCommData;
222 UINTN CommSize;
223 UINTN BootPerformanceDataSize;
224 UINT8 *BootPerformanceData;
225 EFI_SMM_COMMUNICATION_PROTOCOL *Communication;
226 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
227 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;
228 EFI_MEMORY_DESCRIPTOR *SmmCommMemRegion;
229 UINTN Index;
230 VOID *SmmBootRecordData;
231 UINTN SmmBootRecordDataSize;
232 UINTN ReservedMemSize;
233
234 //
235 // Collect boot records from SMM drivers.
236 //
237 SmmBootRecordCommBuffer = NULL;
238 SmmCommData = NULL;
239 SmmBootRecordData = NULL;
240 SmmBootRecordDataSize = 0;
241 ReservedMemSize = 0;
242 Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);
243 if (!EFI_ERROR (Status)) {
244 //
245 // Initialize communicate buffer
246 // Get the prepared Reserved Memory Range
247 //
248 Status = EfiGetSystemConfigurationTable (
249 &gEdkiiPiSmmCommunicationRegionTableGuid,
250 (VOID **) &SmmCommRegionTable
251 );
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) {
257 break;
258 }
259 SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);
260 }
261 ASSERT (Index < SmmCommRegionTable->NumberOfEntries);
262 ASSERT (SmmCommMemRegion->PhysicalStart > 0);
263 ASSERT (SmmCommMemRegion->NumberOfPages > 0);
264 ReservedMemSize = (UINTN) SmmCommMemRegion->NumberOfPages * EFI_PAGE_SIZE;
265
266 //
267 // Check enough reserved memory space
268 //
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));
274
275 CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);
276 SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);
277 CommSize = SMM_BOOT_RECORD_COMM_SIZE;
278
279 //
280 // Get the size of boot records.
281 //
282 SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;
283 SmmCommData->BootRecordData = NULL;
284 Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
285
286 if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {
287 //
288 // Get all boot records
289 //
290 SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;
291 SmmBootRecordDataSize = SmmCommData->BootRecordSize;
292 SmmBootRecordData = AllocateZeroPool(SmmBootRecordDataSize);
293 ASSERT (SmmBootRecordData != NULL);
294 SmmCommData->BootRecordOffset = 0;
295 SmmCommData->BootRecordData = (VOID *) ((UINTN) SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);
296 SmmCommData->BootRecordSize = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;
297 while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {
298 Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
299 ASSERT_EFI_ERROR (Status);
300 ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);
301 if (SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
302 CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmCommData->BootRecordOffset);
303 } else {
304 CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
305 }
306 SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;
307 }
308 }
309 }
310 }
311 }
312
313 //
314 // Prepare memory for Boot Performance table.
315 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
316 //
317 BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mPerformanceLength + PcdGet32 (PcdExtFpdtBootRecordPadSize);
318 if (SmmCommData != NULL && SmmBootRecordData != NULL) {
319 BootPerformanceDataSize += SmmBootRecordDataSize;
320 }
321
322 //
323 // Try to allocate the same runtime buffer as last time boot.
324 //
325 ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));
326 Size = sizeof (PerformanceVariable);
327 Status = gRT->GetVariable (
328 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
329 &gEfiFirmwarePerformanceGuid,
330 NULL,
331 &Size,
332 &PerformanceVariable
333 );
334 if (!EFI_ERROR (Status)) {
335 Status = gBS->AllocatePages (
336 AllocateAddress,
337 EfiReservedMemoryType,
338 EFI_SIZE_TO_PAGES (BootPerformanceDataSize),
339 &PerformanceVariable.BootPerformanceTablePointer
340 );
341 if (!EFI_ERROR (Status)) {
342 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;
343 }
344 }
345
346 if (mAcpiBootPerformanceTable == NULL) {
347 //
348 // Fail to allocate at specified address, continue to allocate at any address.
349 //
350 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (
351 EfiReservedMemoryType,
352 EFI_SIZE_TO_PAGES (BootPerformanceDataSize)
353 );
354 if (mAcpiBootPerformanceTable != NULL) {
355 ZeroMem (mAcpiBootPerformanceTable, BootPerformanceDataSize);
356 }
357 }
358 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));
359
360 if (mAcpiBootPerformanceTable == NULL) {
361 if (SmmCommData != NULL && SmmBootRecordData != NULL) {
362 FreePool (SmmBootRecordData);
363 }
364 return EFI_OUT_OF_RESOURCES;
365 }
366
367 //
368 // Prepare Boot Performance Table.
369 //
370 BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;
371 //
372 // Fill Basic Boot record to Boot Performance Table.
373 //
374 CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));
375 BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length;
376 //
377 // Fill Boot records from boot drivers.
378 //
379 if (mPerformancePointer != NULL) {
380 CopyMem (BootPerformanceData, mPerformancePointer, mPerformanceLength);
381 mAcpiBootPerformanceTable->Header.Length += mPerformanceLength;
382 BootPerformanceData = BootPerformanceData + mPerformanceLength;
383 FreePool (mPerformancePointer);
384 mPerformancePointer = NULL;
385 mPerformanceLength = 0;
386 mMaxPerformanceLength = 0;
387 }
388 if (SmmCommData != NULL && SmmBootRecordData != NULL) {
389 //
390 // Fill Boot records from SMM drivers.
391 //
392 CopyMem (BootPerformanceData, SmmBootRecordData, SmmBootRecordDataSize);
393 FreePool (SmmBootRecordData);
394 mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize);
395 BootPerformanceData = BootPerformanceData + SmmBootRecordDataSize;
396 }
397
398 mBootRecordBuffer = (UINT8 *) mAcpiBootPerformanceTable;
399 mBootRecordSize = mAcpiBootPerformanceTable->Header.Length;
400 mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);
401
402 return EFI_SUCCESS;
403 }
404
405 /**
406 Get a human readable module name and module guid for the given image handle.
407 If module name can't be found, "" string will return.
408 If module guid can't be found, Zero Guid will return.
409
410 @param Handle Image handle or Controller handle.
411 @param NameString The ascii string will be filled into it. If not found, null string will return.
412 @param BufferSize Size of the input NameString buffer.
413 @param ModuleGuid Point to the guid buffer to store the got module guid value.
414
415 @retval EFI_SUCCESS Successfully get module name and guid.
416 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
417 @retval other value Module Name can't be got.
418 **/
419 EFI_STATUS
420 GetModuleInfoFromHandle (
421 IN EFI_HANDLE Handle,
422 OUT CHAR8 *NameString,
423 IN UINTN BufferSize,
424 OUT EFI_GUID *ModuleGuid OPTIONAL
425 )
426 {
427 EFI_STATUS Status;
428 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
429 EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
430 CHAR8 *PdbFileName;
431 EFI_GUID *TempGuid;
432 UINTN StartIndex;
433 UINTN Index;
434 INTN Count;
435 BOOLEAN ModuleGuidIsGet;
436 UINTN StringSize;
437 CHAR16 *StringPtr;
438 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
439 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
440
441 if (NameString == NULL || BufferSize == 0) {
442 return EFI_INVALID_PARAMETER;
443 }
444 //
445 // Try to get the ModuleGuid and name string form the caached array.
446 //
447 if (mCachePairCount > 0) {
448 for (Count = mCachePairCount -1; Count >= 0; Count--) {
449 if (Handle == mCacheHandleGuidTable[Count].Handle) {
450 CopyGuid (ModuleGuid, &mCacheHandleGuidTable[Count].ModuleGuid);
451 AsciiStrCpyS (NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, mCacheHandleGuidTable[Count].NameString);
452 return EFI_SUCCESS;
453 }
454 }
455 }
456
457 Status = EFI_INVALID_PARAMETER;
458 LoadedImage = NULL;
459 ModuleGuidIsGet = FALSE;
460
461 //
462 // Initialize GUID as zero value.
463 //
464 TempGuid = &gZeroGuid;
465 //
466 // Initialize it as "" string.
467 //
468 NameString[0] = 0;
469
470 if (Handle != NULL) {
471 //
472 // Try Handle as ImageHandle.
473 //
474 Status = gBS->HandleProtocol (
475 Handle,
476 &gEfiLoadedImageProtocolGuid,
477 (VOID**) &LoadedImage
478 );
479
480 if (EFI_ERROR (Status)) {
481 //
482 // Try Handle as Controller Handle
483 //
484 Status = gBS->OpenProtocol (
485 Handle,
486 &gEfiDriverBindingProtocolGuid,
487 (VOID **) &DriverBinding,
488 NULL,
489 NULL,
490 EFI_OPEN_PROTOCOL_GET_PROTOCOL
491 );
492 if (!EFI_ERROR (Status)) {
493 //
494 // Get Image protocol from ImageHandle
495 //
496 Status = gBS->HandleProtocol (
497 DriverBinding->ImageHandle,
498 &gEfiLoadedImageProtocolGuid,
499 (VOID**) &LoadedImage
500 );
501 }
502 }
503 }
504
505 if (!EFI_ERROR (Status) && LoadedImage != NULL) {
506 //
507 // Get Module Guid from DevicePath.
508 //
509 if (LoadedImage->FilePath != NULL &&
510 LoadedImage->FilePath->Type == MEDIA_DEVICE_PATH &&
511 LoadedImage->FilePath->SubType == MEDIA_PIWG_FW_FILE_DP
512 ) {
513 //
514 // Determine GUID associated with module logging performance
515 //
516 ModuleGuidIsGet = TRUE;
517 FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LoadedImage->FilePath;
518 TempGuid = &FvFilePath->FvFileName;
519 }
520
521 //
522 // Method 1 Get Module Name from PDB string.
523 //
524 PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);
525 if (PdbFileName != NULL && BufferSize > 0) {
526 StartIndex = 0;
527 for (Index = 0; PdbFileName[Index] != 0; Index++) {
528 if ((PdbFileName[Index] == '\\') || (PdbFileName[Index] == '/')) {
529 StartIndex = Index + 1;
530 }
531 }
532 //
533 // Copy the PDB file name to our temporary string.
534 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
535 //
536 for (Index = 0; Index < BufferSize - 1; Index++) {
537 NameString[Index] = PdbFileName[Index + StartIndex];
538 if (NameString[Index] == 0 || NameString[Index] == '.') {
539 NameString[Index] = 0;
540 break;
541 }
542 }
543
544 if (Index == BufferSize - 1) {
545 NameString[Index] = 0;
546 }
547 //
548 // Module Name is got.
549 //
550 goto Done;
551 }
552 }
553
554 //
555 // Method 2: Get the name string from ComponentName2 protocol
556 //
557 Status = gBS->HandleProtocol (
558 Handle,
559 &gEfiComponentName2ProtocolGuid,
560 (VOID **) &ComponentName2
561 );
562 if (!EFI_ERROR (Status)) {
563 //
564 // Get the current platform language setting
565 //
566 if (mPlatformLanguage == NULL) {
567 GetEfiGlobalVariable2 (L"PlatformLang", (VOID **) &mPlatformLanguage, NULL);
568 }
569 if (mPlatformLanguage != NULL) {
570 Status = ComponentName2->GetDriverName (
571 ComponentName2,
572 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",
573 &StringPtr
574 );
575 if (!EFI_ERROR (Status)) {
576 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {
577 NameString[Index] = (CHAR8) StringPtr[Index];
578 }
579 NameString[Index] = 0;
580 //
581 // Module Name is got.
582 //
583 goto Done;
584 }
585 }
586 }
587
588 if (ModuleGuidIsGet) {
589 //
590 // Method 3 Try to get the image's FFS UI section by image GUID
591 //
592 StringPtr = NULL;
593 StringSize = 0;
594 Status = GetSectionFromAnyFv (
595 TempGuid,
596 EFI_SECTION_USER_INTERFACE,
597 0,
598 (VOID **) &StringPtr,
599 &StringSize
600 );
601
602 if (!EFI_ERROR (Status)) {
603 //
604 // Method 3. Get the name string from FFS UI section
605 //
606 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {
607 NameString[Index] = (CHAR8) StringPtr[Index];
608 }
609 NameString[Index] = 0;
610 FreePool (StringPtr);
611 }
612 }
613
614 Done:
615 //
616 // Copy Module Guid
617 //
618 if (ModuleGuid != NULL) {
619 CopyGuid (ModuleGuid, TempGuid);
620 if (IsZeroGuid(TempGuid) && (Handle != NULL) && !ModuleGuidIsGet) {
621 // Handle is GUID
622 CopyGuid (ModuleGuid, (EFI_GUID *) Handle);
623 }
624 }
625
626 //
627 // Cache the Handle and Guid pairs.
628 //
629 if (mCachePairCount < CACHE_HANDLE_GUID_COUNT) {
630 mCacheHandleGuidTable[mCachePairCount].Handle = Handle;
631 CopyGuid (&mCacheHandleGuidTable[mCachePairCount].ModuleGuid, ModuleGuid);
632 AsciiStrCpyS (mCacheHandleGuidTable[mCachePairCount].NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, NameString);
633 mCachePairCount ++;
634 }
635
636 return Status;
637 }
638
639 /**
640 Get the FPDT record identifier.
641
642 @param Attribute The attribute of the Record.
643 PerfStartEntry: Start Record.
644 PerfEndEntry: End Record.
645 @param Handle Pointer to environment specific context used to identify the component being measured.
646 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
647 @param ProgressID On return, pointer to the ProgressID.
648
649 @retval EFI_SUCCESS Get record info successfully.
650 @retval EFI_INVALID_PARAMETER No matched FPDT record.
651
652 **/
653 EFI_STATUS
654 GetFpdtRecordId (
655 IN PERF_MEASUREMENT_ATTRIBUTE Attribute,
656 IN CONST VOID *Handle,
657 IN CONST CHAR8 *String,
658 OUT UINT16 *ProgressID
659 )
660 {
661 //
662 // Token to PerfId.
663 //
664 if (String != NULL) {
665 if (AsciiStrCmp (String, START_IMAGE_TOK) == 0) { // "StartImage:"
666 if (Attribute == PerfStartEntry) {
667 *ProgressID = MODULE_START_ID;
668 } else {
669 *ProgressID = MODULE_END_ID;
670 }
671 } else if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"
672 if (Attribute == PerfStartEntry) {
673 *ProgressID = MODULE_LOADIMAGE_START_ID;
674 } else {
675 *ProgressID = MODULE_LOADIMAGE_END_ID;
676 }
677 } else if (AsciiStrCmp (String, DRIVERBINDING_START_TOK) == 0) { // "DB:Start:"
678 if (Attribute == PerfStartEntry) {
679 *ProgressID = MODULE_DB_START_ID;
680 } else {
681 *ProgressID = MODULE_DB_END_ID;
682 }
683 } else if (AsciiStrCmp (String, DRIVERBINDING_SUPPORT_TOK) == 0) { // "DB:Support:"
684 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
685 return RETURN_UNSUPPORTED;
686 }
687 if (Attribute == PerfStartEntry) {
688 *ProgressID = MODULE_DB_SUPPORT_START_ID;
689 } else {
690 *ProgressID = MODULE_DB_SUPPORT_END_ID;
691 }
692 } else if (AsciiStrCmp (String, DRIVERBINDING_STOP_TOK) == 0) { // "DB:Stop:"
693 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
694 return RETURN_UNSUPPORTED;
695 }
696 if (Attribute == PerfStartEntry) {
697 *ProgressID = MODULE_DB_STOP_START_ID;
698 } else {
699 *ProgressID = MODULE_DB_STOP_END_ID;
700 }
701 } else if (AsciiStrCmp (String, PEI_TOK) == 0 || // "PEI"
702 AsciiStrCmp (String, DXE_TOK) == 0 || // "DXE"
703 AsciiStrCmp (String, BDS_TOK) == 0) { // "BDS"
704 if (Attribute == PerfStartEntry) {
705 *ProgressID = PERF_CROSSMODULE_START_ID;
706 } else {
707 *ProgressID = PERF_CROSSMODULE_END_ID;
708 }
709 } else { // Pref used in Modules.
710 if (Attribute == PerfStartEntry) {
711 *ProgressID = PERF_INMODULE_START_ID;
712 } else {
713 *ProgressID = PERF_INMODULE_END_ID;
714 }
715 }
716 } else if (Handle!= NULL) { // Pref used in Modules.
717 if (Attribute == PerfStartEntry) {
718 *ProgressID = PERF_INMODULE_START_ID;
719 } else {
720 *ProgressID = PERF_INMODULE_END_ID;
721 }
722 } else {
723 return EFI_INVALID_PARAMETER;
724 }
725 return EFI_SUCCESS;
726 }
727
728 /**
729 Copies the string from Source into Destination and updates Length with the
730 size of the string.
731
732 @param Destination - destination of the string copy
733 @param Source - pointer to the source string which will get copied
734 @param Length - pointer to a length variable to be updated
735
736 **/
737 VOID
738 CopyStringIntoPerfRecordAndUpdateLength (
739 IN OUT CHAR8 *Destination,
740 IN CONST CHAR8 *Source,
741 IN OUT UINT8 *Length
742 )
743 {
744 UINTN StringLen;
745 UINTN DestMax;
746
747 ASSERT (Source != NULL);
748
749 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
750 DestMax = STRING_SIZE;
751 } else {
752 DestMax = AsciiStrSize (Source);
753 if (DestMax > STRING_SIZE) {
754 DestMax = STRING_SIZE;
755 }
756 }
757 StringLen = AsciiStrLen (Source);
758 if (StringLen >= DestMax) {
759 StringLen = DestMax -1;
760 }
761
762 AsciiStrnCpyS(Destination, DestMax, Source, StringLen);
763 *Length += (UINT8)DestMax;
764
765 return;
766 }
767
768 /**
769 Get a string description for device for the given controller handle and update record
770 length. If ComponentName2 GetControllerName is supported, the value is included in the string,
771 followed by device path, otherwise just device path.
772
773 @param Handle - Image handle
774 @param ControllerHandle - Controller handle.
775 @param ComponentNameString - Pointer to a location where the string will be saved
776 @param Length - Pointer to record length to be updated
777
778 @retval EFI_SUCCESS - Successfully got string description for device
779 @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found
780
781 **/
782 EFI_STATUS
783 GetDeviceInfoFromHandleAndUpdateLength (
784 IN CONST VOID *Handle,
785 IN EFI_HANDLE ControllerHandle,
786 OUT CHAR8 *ComponentNameString,
787 IN OUT UINT8 *Length
788 )
789 {
790 EFI_DEVICE_PATH_PROTOCOL *DevicePathProtocol;
791 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
792 EFI_STATUS Status;
793 CHAR16 *StringPtr;
794 CHAR8 *AsciiStringPtr;
795 UINTN ControllerNameStringSize;
796 UINTN DevicePathStringSize;
797
798 ControllerNameStringSize = 0;
799
800 Status = gBS->HandleProtocol (
801 (EFI_HANDLE) Handle,
802 &gEfiComponentName2ProtocolGuid,
803 (VOID **) &ComponentName2
804 );
805
806 if (!EFI_ERROR(Status)) {
807 //
808 // Get the current platform language setting
809 //
810 if (mPlatformLanguage == NULL) {
811 GetEfiGlobalVariable2 (L"PlatformLang", (VOID **)&mPlatformLanguage, NULL);
812 }
813
814 Status = ComponentName2->GetControllerName (
815 ComponentName2,
816 ControllerHandle,
817 NULL,
818 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",
819 &StringPtr
820 );
821 }
822
823 if (!EFI_ERROR (Status)) {
824 //
825 // This will produce the size of the unicode string, which is twice as large as the ASCII one
826 // This must be an even number, so ok to divide by 2
827 //
828 ControllerNameStringSize = StrSize(StringPtr) / 2;
829
830 //
831 // The + 1 is because we want to add a space between the ControllerName and the device path
832 //
833 if ((ControllerNameStringSize + (*Length) + 1) > FPDT_MAX_PERF_RECORD_SIZE) {
834 //
835 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
836 //
837 ControllerNameStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length) - 1;
838 }
839
840 UnicodeStrnToAsciiStrS(StringPtr, ControllerNameStringSize - 1, ComponentNameString, ControllerNameStringSize, &ControllerNameStringSize);
841
842 //
843 // Add a space in the end of the ControllerName
844 //
845 AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;
846 *AsciiStringPtr = 0x20;
847 AsciiStringPtr++;
848 *AsciiStringPtr = 0;
849 ControllerNameStringSize++;
850
851 *Length += (UINT8)ControllerNameStringSize;
852 }
853
854 //
855 // This function returns the device path protocol from the handle specified by Handle. If Handle is
856 // NULL or Handle does not contain a device path protocol, then NULL is returned.
857 //
858 DevicePathProtocol = DevicePathFromHandle(ControllerHandle);
859
860 if (DevicePathProtocol != NULL) {
861 StringPtr = ConvertDevicePathToText (DevicePathProtocol, TRUE, FALSE);
862 if (StringPtr != NULL) {
863 //
864 // This will produce the size of the unicode string, which is twice as large as the ASCII one
865 // This must be an even number, so ok to divide by 2
866 //
867 DevicePathStringSize = StrSize(StringPtr) / 2;
868
869 if ((DevicePathStringSize + (*Length)) > FPDT_MAX_PERF_RECORD_SIZE) {
870 //
871 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
872 //
873 DevicePathStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length);
874 }
875
876 if (ControllerNameStringSize != 0) {
877 AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;
878 } else {
879 AsciiStringPtr = ComponentNameString;
880 }
881
882 UnicodeStrnToAsciiStrS(StringPtr, DevicePathStringSize - 1, AsciiStringPtr, DevicePathStringSize, &DevicePathStringSize);
883 *Length += (UINT8)DevicePathStringSize;
884 return EFI_SUCCESS;
885 }
886 }
887
888 return EFI_UNSUPPORTED;
889 }
890
891 /**
892 Create performance record with event description and a timestamp.
893
894 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
895 @param Guid - Pointer to a GUID.
896 @param String - Pointer to a string describing the measurement.
897 @param Ticker - 64-bit time stamp.
898 @param Address - Pointer to a location in memory relevant to the measurement.
899 @param PerfId - Performance identifier describing the type of measurement.
900 @param Attribute - The attribute of the measurement. According to attribute can create a start
901 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
902 or a general record for other Perf macros.
903
904 @retval EFI_SUCCESS - Successfully created performance record.
905 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
906 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
907 pointer or invalid PerfId.
908
909 @retval EFI_SUCCESS - Successfully created performance record
910 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records
911 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
912 pointer or invalid PerfId
913
914 **/
915 EFI_STATUS
916 InsertFpdtRecord (
917 IN CONST VOID *CallerIdentifier, OPTIONAL
918 IN CONST VOID *Guid, OPTIONAL
919 IN CONST CHAR8 *String, OPTIONAL
920 IN UINT64 Ticker,
921 IN UINT64 Address, OPTIONAL
922 IN UINT16 PerfId,
923 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
924 )
925 {
926 EFI_GUID ModuleGuid;
927 CHAR8 ModuleName[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];
928 FPDT_RECORD_PTR FpdtRecordPtr;
929 FPDT_RECORD_PTR CachedFpdtRecordPtr;
930 UINT64 TimeStamp;
931 CONST CHAR8 *StringPtr;
932 UINTN DestMax;
933 UINTN StringLen;
934 EFI_STATUS Status;
935 UINT16 ProgressId;
936
937 StringPtr = NULL;
938 ProgressId = 0;
939 ZeroMem (ModuleName, sizeof (ModuleName));
940
941 //
942 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
943 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
944 //
945 if (Attribute != PerfEntry) {
946 //
947 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
948 // !!! Note: If the Perf is not the known Token used in the core but have same
949 // ID with the core Token, this case will not be supported.
950 // And in currtnt usage mode, for the unkown ID, there is a general rule:
951 // If it is start pref: the lower 4 bits of the ID should be 0.
952 // If it is end pref: the lower 4 bits of the ID should not be 0.
953 // If input ID doesn't follow the rule, we will adjust it.
954 //
955 if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
956 return EFI_INVALID_PARAMETER;
957 } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
958 if ((Attribute == PerfStartEntry) && ((PerfId & 0x000F) != 0)) {
959 PerfId &= 0xFFF0;
960 } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {
961 PerfId += 1;
962 }
963 } else if (PerfId == 0) {
964 //
965 // Get ProgressID form the String Token.
966 //
967 Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &ProgressId);
968 if (EFI_ERROR (Status)) {
969 return Status;
970 }
971 PerfId = ProgressId;
972 }
973 }
974
975 //
976 // 2. Get the buffer to store the FPDT record.
977 //
978 Status = GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE, &FpdtRecordPtr);
979 if (EFI_ERROR (Status)) {
980 return Status;
981 }
982
983 //
984 //3. Get the TimeStamp.
985 //
986 if (Ticker == 0) {
987 Ticker = GetPerformanceCounter ();
988 TimeStamp = GetTimeInNanoSecond (Ticker);
989 } else if (Ticker == 1) {
990 TimeStamp = 0;
991 } else {
992 TimeStamp = GetTimeInNanoSecond (Ticker);
993 }
994
995 //
996 // 4. Fill in the FPDT record according to different Performance Identifier.
997 //
998 switch (PerfId) {
999 case MODULE_START_ID:
1000 case MODULE_END_ID:
1001 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1002 StringPtr = ModuleName;
1003 //
1004 // Cache the offset of start image start record and use to update the start image end record if needed.
1005 //
1006 if (Attribute == PerfEntry && PerfId == MODULE_START_ID) {
1007 if (mFpdtBufferIsReported) {
1008 mCachedLength = mBootRecordSize;
1009 } else {
1010 mCachedLength = mPerformanceLength;
1011 }
1012 }
1013 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1014 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;
1015 FpdtRecordPtr.GuidEvent->Header.Length = sizeof (FPDT_GUID_EVENT_RECORD);
1016 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1017 FpdtRecordPtr.GuidEvent->ProgressID = PerfId;
1018 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;
1019 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidEvent->Guid));
1020 if (CallerIdentifier == NULL && PerfId == MODULE_END_ID && mCachedLength != 0) {
1021 if (mFpdtBufferIsReported) {
1022 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);
1023 } else {
1024 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);
1025 }
1026 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &CachedFpdtRecordPtr.GuidEvent->Guid, sizeof (FpdtRecordPtr.GuidEvent->Guid));
1027 mCachedLength = 0;
1028 }
1029 }
1030 break;
1031
1032 case MODULE_LOADIMAGE_START_ID:
1033 case MODULE_LOADIMAGE_END_ID:
1034 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1035 StringPtr = ModuleName;
1036 if (PerfId == MODULE_LOADIMAGE_START_ID) {
1037 mLoadImageCount ++;
1038 //
1039 // Cache the offset of load image start record and use to be updated by the load image end record if needed.
1040 //
1041 if (CallerIdentifier == NULL && Attribute == PerfEntry) {
1042 if (mFpdtBufferIsReported) {
1043 mCachedLength = mBootRecordSize;
1044 } else {
1045 mCachedLength = mPerformanceLength;
1046 }
1047 }
1048 }
1049 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1050 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;
1051 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
1052 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1053 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;
1054 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;
1055 FpdtRecordPtr.GuidQwordEvent->Qword = mLoadImageCount;
1056 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));
1057 if (PerfId == MODULE_LOADIMAGE_END_ID && mCachedLength != 0) {
1058 if (mFpdtBufferIsReported) {
1059 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);
1060 } else {
1061 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);
1062 }
1063 CopyMem (&CachedFpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.GuidQwordEvent->Guid));
1064 mCachedLength = 0;
1065 }
1066 }
1067 break;
1068
1069 case MODULE_DB_START_ID:
1070 case MODULE_DB_SUPPORT_START_ID:
1071 case MODULE_DB_SUPPORT_END_ID:
1072 case MODULE_DB_STOP_START_ID:
1073 case MODULE_DB_STOP_END_ID:
1074 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1075 StringPtr = ModuleName;
1076 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1077 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;
1078 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
1079 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1080 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;
1081 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;
1082 FpdtRecordPtr.GuidQwordEvent->Qword = Address;
1083 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));
1084 }
1085 break;
1086
1087 case MODULE_DB_END_ID:
1088 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1089 StringPtr = ModuleName;
1090 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1091 FpdtRecordPtr.GuidQwordStringEvent->Header.Type = FPDT_GUID_QWORD_STRING_EVENT_TYPE;
1092 FpdtRecordPtr.GuidQwordStringEvent->Header.Length = sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD);;
1093 FpdtRecordPtr.GuidQwordStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1094 FpdtRecordPtr.GuidQwordStringEvent->ProgressID = PerfId;
1095 FpdtRecordPtr.GuidQwordStringEvent->Timestamp = TimeStamp;
1096 FpdtRecordPtr.GuidQwordStringEvent->Qword = Address;
1097 CopyMem (&FpdtRecordPtr.GuidQwordStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordStringEvent->Guid));
1098 if (Address != 0) {
1099 GetDeviceInfoFromHandleAndUpdateLength(CallerIdentifier, (EFI_HANDLE)(UINTN)Address, FpdtRecordPtr.GuidQwordStringEvent->String, &FpdtRecordPtr.GuidQwordStringEvent->Header.Length);
1100 }
1101 }
1102 break;
1103
1104 case PERF_EVENTSIGNAL_START_ID:
1105 case PERF_EVENTSIGNAL_END_ID:
1106 case PERF_CALLBACK_START_ID:
1107 case PERF_CALLBACK_END_ID:
1108 if (String == NULL || Guid == NULL) {
1109 return EFI_INVALID_PARAMETER;
1110 }
1111 StringPtr = String;
1112 if (AsciiStrLen (String) == 0) {
1113 StringPtr = "unknown name";
1114 }
1115 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1116 FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;
1117 FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);
1118 FpdtRecordPtr.DualGuidStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1119 FpdtRecordPtr.DualGuidStringEvent->ProgressID = PerfId;
1120 FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;
1121 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, CallerIdentifier, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));
1122 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));
1123 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);
1124 }
1125 break;
1126
1127 case PERF_EVENT_ID:
1128 case PERF_FUNCTION_START_ID:
1129 case PERF_FUNCTION_END_ID:
1130 case PERF_INMODULE_START_ID:
1131 case PERF_INMODULE_END_ID:
1132 case PERF_CROSSMODULE_START_ID:
1133 case PERF_CROSSMODULE_END_ID:
1134 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1135 if (String != NULL) {
1136 StringPtr = String;
1137 } else {
1138 StringPtr = ModuleName;
1139 }
1140 if (AsciiStrLen (StringPtr) == 0) {
1141 StringPtr = "unknown name";
1142 }
1143 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1144 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
1145 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1146 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1147 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
1148 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
1149 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
1150 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
1151 }
1152 break;
1153
1154 default:
1155 if (Attribute != PerfEntry) {
1156 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1157 if (String != NULL) {
1158 StringPtr = String;
1159 } else {
1160 StringPtr = ModuleName;
1161 }
1162 if (AsciiStrLen (StringPtr) == 0) {
1163 StringPtr = "unknown name";
1164 }
1165 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1166 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
1167 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1168 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1169 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
1170 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
1171 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
1172 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
1173 }
1174 } else {
1175 return EFI_INVALID_PARAMETER;
1176 }
1177 break;
1178 }
1179
1180 //
1181 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
1182 //
1183 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1184 if (StringPtr == NULL ||PerfId == MODULE_DB_SUPPORT_START_ID || PerfId == MODULE_DB_SUPPORT_END_ID) {
1185 return EFI_INVALID_PARAMETER;
1186 }
1187 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
1188 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1189 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1190 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
1191 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
1192 if (Guid != NULL) {
1193 //
1194 // Cache the event guid in string event record.
1195 //
1196 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
1197 } else {
1198 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
1199 }
1200 if (AsciiStrLen (StringPtr) == 0) {
1201 StringPtr = "unknown name";
1202 }
1203 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
1204
1205 if ((PerfId == MODULE_LOADIMAGE_START_ID) || (PerfId == MODULE_END_ID)) {
1206 FpdtRecordPtr.DynamicStringEvent->Header.Length = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)+ STRING_SIZE);
1207 }
1208 if ((PerfId == MODULE_LOADIMAGE_END_ID || PerfId == MODULE_END_ID) && mCachedLength != 0) {
1209 if (mFpdtBufferIsReported) {
1210 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);
1211 } else {
1212 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);
1213 }
1214 if (PerfId == MODULE_LOADIMAGE_END_ID) {
1215 DestMax = CachedFpdtRecordPtr.DynamicStringEvent->Header.Length - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1216 StringLen = AsciiStrLen (StringPtr);
1217 if (StringLen >= DestMax) {
1218 StringLen = DestMax -1;
1219 }
1220 CopyMem (&CachedFpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.DynamicStringEvent->Guid));
1221 AsciiStrnCpyS (CachedFpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StringLen);
1222 } else if (PerfId == MODULE_END_ID) {
1223 DestMax = FpdtRecordPtr.DynamicStringEvent->Header.Length - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1224 StringLen = AsciiStrLen (CachedFpdtRecordPtr.DynamicStringEvent->String);
1225 if (StringLen >= DestMax) {
1226 StringLen = DestMax -1;
1227 }
1228 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &CachedFpdtRecordPtr.DynamicStringEvent->Guid, sizeof (CachedFpdtRecordPtr.DynamicStringEvent->Guid));
1229 AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, CachedFpdtRecordPtr.DynamicStringEvent->String, StringLen);
1230 }
1231 mCachedLength = 0;
1232 }
1233 }
1234
1235 //
1236 // 5. Update the length of the used buffer after fill in the record.
1237 //
1238 if (mFpdtBufferIsReported) {
1239 mBootRecordSize += FpdtRecordPtr.RecordHeader->Length;
1240 mAcpiBootPerformanceTable->Header.Length += FpdtRecordPtr.RecordHeader->Length;
1241 } else {
1242 mPerformanceLength += FpdtRecordPtr.RecordHeader->Length;
1243 }
1244 return EFI_SUCCESS;
1245 }
1246
1247 /**
1248 Dumps all the PEI performance.
1249
1250 @param HobStart A pointer to a Guid.
1251
1252 This internal function dumps all the PEI performance log to the DXE performance gauge array.
1253 It retrieves the optional GUID HOB for PEI performance and then saves the performance data
1254 to DXE performance data structures.
1255
1256 **/
1257 VOID
1258 InternalGetPeiPerformance (
1259 VOID *HobStart
1260 )
1261 {
1262 UINT8 *FirmwarePerformanceHob;
1263 FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;
1264 UINT8 *EventRec;
1265 EFI_HOB_GUID_TYPE *GuidHob;
1266
1267 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, HobStart);
1268 while (GuidHob != NULL) {
1269 FirmwarePerformanceHob = GET_GUID_HOB_DATA (GuidHob);
1270 PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)FirmwarePerformanceHob;
1271
1272 if (mPerformanceLength + PeiPerformanceLogHeader->SizeOfAllEntries > mMaxPerformanceLength) {
1273 mPerformancePointer = ReallocatePool (
1274 mPerformanceLength,
1275 mPerformanceLength +
1276 (UINTN)PeiPerformanceLogHeader->SizeOfAllEntries +
1277 FIRMWARE_RECORD_BUFFER,
1278 mPerformancePointer
1279 );
1280 ASSERT (mPerformancePointer != NULL);
1281 mMaxPerformanceLength = mPerformanceLength +
1282 (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries) +
1283 FIRMWARE_RECORD_BUFFER;
1284 }
1285
1286 EventRec = mPerformancePointer + mPerformanceLength;
1287 CopyMem (EventRec, FirmwarePerformanceHob + sizeof (FPDT_PEI_EXT_PERF_HEADER), (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries));
1288 //
1289 // Update the used buffer size.
1290 //
1291 mPerformanceLength += (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries);
1292 mLoadImageCount += PeiPerformanceLogHeader->LoadImageCount;
1293
1294 //
1295 // Get next performance guid hob
1296 //
1297 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));
1298 }
1299 }
1300
1301 /**
1302 Report Boot Perforamnce table address as report status code.
1303
1304 @param Event The event of notify protocol.
1305 @param Context Notify event context.
1306
1307 **/
1308 VOID
1309 EFIAPI
1310 ReportFpdtRecordBuffer (
1311 IN EFI_EVENT Event,
1312 IN VOID *Context
1313 )
1314 {
1315 EFI_STATUS Status;
1316 UINT64 BPDTAddr;
1317
1318 if (!mFpdtBufferIsReported) {
1319 Status = AllocateBootPerformanceTable ();
1320 if (!EFI_ERROR(Status)) {
1321 BPDTAddr = (UINT64)(UINTN)mAcpiBootPerformanceTable;
1322 REPORT_STATUS_CODE_EX (
1323 EFI_PROGRESS_CODE,
1324 EFI_SOFTWARE_DXE_BS_DRIVER,
1325 0,
1326 NULL,
1327 &gEdkiiFpdtExtendedFirmwarePerformanceGuid,
1328 &BPDTAddr,
1329 sizeof (UINT64)
1330 );
1331 }
1332 //
1333 // Set FPDT report state to TRUE.
1334 //
1335 mFpdtBufferIsReported = TRUE;
1336 }
1337 }
1338
1339 /**
1340 The constructor function initializes Performance infrastructure for DXE phase.
1341
1342 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance
1343 and merges PEI performance data to DXE performance log.
1344 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
1345
1346 @param ImageHandle The firmware allocated handle for the EFI image.
1347 @param SystemTable A pointer to the EFI System Table.
1348
1349 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
1350
1351 **/
1352 EFI_STATUS
1353 EFIAPI
1354 DxeCorePerformanceLibConstructor (
1355 IN EFI_HANDLE ImageHandle,
1356 IN EFI_SYSTEM_TABLE *SystemTable
1357 )
1358 {
1359 EFI_STATUS Status;
1360 EFI_HANDLE Handle;
1361 EFI_EVENT ReadyToBootEvent;
1362 PERFORMANCE_PROPERTY *PerformanceProperty;
1363
1364 if (!PerformanceMeasurementEnabled ()) {
1365 //
1366 // Do not initialize performance infrastructure if not required.
1367 //
1368 return EFI_SUCCESS;
1369 }
1370
1371 //
1372 // Dump normal PEI performance records
1373 //
1374 InternalGetPeiPerformance (GetHobList());
1375
1376 //
1377 // Install the protocol interfaces for DXE performance library instance.
1378 //
1379 Handle = NULL;
1380 Status = gBS->InstallMultipleProtocolInterfaces (
1381 &Handle,
1382 &gEdkiiPerformanceMeasurementProtocolGuid,
1383 &mPerformanceMeasurementInterface,
1384 NULL
1385 );
1386 ASSERT_EFI_ERROR (Status);
1387
1388 //
1389 // Register ReadyToBoot event to report StatusCode data
1390 //
1391 Status = gBS->CreateEventEx (
1392 EVT_NOTIFY_SIGNAL,
1393 TPL_CALLBACK,
1394 ReportFpdtRecordBuffer,
1395 NULL,
1396 &gEfiEventReadyToBootGuid,
1397 &ReadyToBootEvent
1398 );
1399
1400 ASSERT_EFI_ERROR (Status);
1401
1402 Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);
1403 if (EFI_ERROR (Status)) {
1404 //
1405 // Install configuration table for performance property.
1406 //
1407 mPerformanceProperty.Revision = PERFORMANCE_PROPERTY_REVISION;
1408 mPerformanceProperty.Reserved = 0;
1409 mPerformanceProperty.Frequency = GetPerformanceCounterProperties (
1410 &mPerformanceProperty.TimerStartValue,
1411 &mPerformanceProperty.TimerEndValue
1412 );
1413 Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);
1414 ASSERT_EFI_ERROR (Status);
1415 }
1416
1417 return EFI_SUCCESS;
1418 }
1419
1420 /**
1421 Create performance record with event description and a timestamp.
1422
1423 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
1424 @param Guid - Pointer to a GUID.
1425 @param String - Pointer to a string describing the measurement.
1426 @param TimeStamp - 64-bit time stamp.
1427 @param Address - Pointer to a location in memory relevant to the measurement.
1428 @param Identifier - Performance identifier describing the type of measurement.
1429 @param Attribute - The attribute of the measurement. According to attribute can create a start
1430 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
1431 or a general record for other Perf macros.
1432
1433 @retval EFI_SUCCESS - Successfully created performance record.
1434 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
1435 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1436 pointer or invalid PerfId.
1437 **/
1438 EFI_STATUS
1439 EFIAPI
1440 CreatePerformanceMeasurement (
1441 IN CONST VOID *CallerIdentifier,
1442 IN CONST VOID *Guid, OPTIONAL
1443 IN CONST CHAR8 *String, OPTIONAL
1444 IN UINT64 TimeStamp,
1445 IN UINT64 Address, OPTIONAL
1446 IN UINT32 Identifier,
1447 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
1448 )
1449 {
1450 EFI_STATUS Status;
1451
1452 Status = EFI_SUCCESS;
1453
1454 if (mLockInsertRecord) {
1455 return EFI_INVALID_PARAMETER;
1456 }
1457 mLockInsertRecord = TRUE;
1458
1459 Status = InsertFpdtRecord (CallerIdentifier, Guid, String, TimeStamp, Address, (UINT16)Identifier, Attribute);
1460
1461 mLockInsertRecord = FALSE;
1462
1463 return Status;
1464 }
1465
1466 /**
1467 Adds a record at the end of the performance measurement log
1468 that records the start time of a performance measurement.
1469
1470 Adds a record to the end of the performance measurement log
1471 that contains the Handle, Token, Module and Identifier.
1472 The end time of the new record must be set to zero.
1473 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1474 If TimeStamp is zero, the start time in the record is filled in with the value
1475 read from the current time stamp.
1476
1477 @param Handle Pointer to environment specific context used
1478 to identify the component being measured.
1479 @param Token Pointer to a Null-terminated ASCII string
1480 that identifies the component being measured.
1481 @param Module Pointer to a Null-terminated ASCII string
1482 that identifies the module being measured.
1483 @param TimeStamp 64-bit time stamp.
1484 @param Identifier 32-bit identifier. If the value is 0, the created record
1485 is same as the one created by StartPerformanceMeasurement.
1486
1487 @retval RETURN_SUCCESS The start of the measurement was recorded.
1488 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1489
1490 **/
1491 RETURN_STATUS
1492 EFIAPI
1493 StartPerformanceMeasurementEx (
1494 IN CONST VOID *Handle, OPTIONAL
1495 IN CONST CHAR8 *Token, OPTIONAL
1496 IN CONST CHAR8 *Module, OPTIONAL
1497 IN UINT64 TimeStamp,
1498 IN UINT32 Identifier
1499 )
1500 {
1501 CONST CHAR8 *String;
1502
1503 if (Token != NULL) {
1504 String = Token;
1505 } else if (Module != NULL) {
1506 String = Module;
1507 } else {
1508 String = NULL;
1509 }
1510
1511 return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);
1512 }
1513
1514 /**
1515 Searches the performance measurement log from the beginning of the log
1516 for the first matching record that contains a zero end time and fills in a valid end time.
1517
1518 Searches the performance measurement log from the beginning of the log
1519 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
1520 If the record can not be found then return RETURN_NOT_FOUND.
1521 If the record is found and TimeStamp is not zero,
1522 then the end time in the record is filled in with the value specified by TimeStamp.
1523 If the record is found and TimeStamp is zero, then the end time in the matching record
1524 is filled in with the current time stamp value.
1525
1526 @param Handle Pointer to environment specific context used
1527 to identify the component being measured.
1528 @param Token Pointer to a Null-terminated ASCII string
1529 that identifies the component being measured.
1530 @param Module Pointer to a Null-terminated ASCII string
1531 that identifies the module being measured.
1532 @param TimeStamp 64-bit time stamp.
1533 @param Identifier 32-bit identifier. If the value is 0, the found record
1534 is same as the one found by EndPerformanceMeasurement.
1535
1536 @retval RETURN_SUCCESS The end of the measurement was recorded.
1537 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1538
1539 **/
1540 RETURN_STATUS
1541 EFIAPI
1542 EndPerformanceMeasurementEx (
1543 IN CONST VOID *Handle, OPTIONAL
1544 IN CONST CHAR8 *Token, OPTIONAL
1545 IN CONST CHAR8 *Module, OPTIONAL
1546 IN UINT64 TimeStamp,
1547 IN UINT32 Identifier
1548 )
1549 {
1550 CONST CHAR8 *String;
1551
1552 if (Token != NULL) {
1553 String = Token;
1554 } else if (Module != NULL) {
1555 String = Module;
1556 } else {
1557 String = NULL;
1558 }
1559
1560 return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);
1561 }
1562
1563 /**
1564 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1565 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
1566 and then assign the Identifier with 0.
1567
1568 !!! Not support!!!
1569
1570 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1571 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1572 and the key for the second entry in the log is returned. If the performance log is empty,
1573 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1574 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1575 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1576 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1577 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1578 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1579 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
1580 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1581 If Handle is NULL, then ASSERT().
1582 If Token is NULL, then ASSERT().
1583 If Module is NULL, then ASSERT().
1584 If StartTimeStamp is NULL, then ASSERT().
1585 If EndTimeStamp is NULL, then ASSERT().
1586 If Identifier is NULL, then ASSERT().
1587
1588 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1589 0, then the first performance measurement log entry is retrieved.
1590 On exit, the key of the next performance log entry.
1591 @param Handle Pointer to environment specific context used to identify the component
1592 being measured.
1593 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1594 being measured.
1595 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1596 being measured.
1597 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1598 was started.
1599 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1600 was ended.
1601 @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement
1602 was ended.
1603
1604 @return The key for the next performance log entry (in general case).
1605
1606 **/
1607 UINTN
1608 EFIAPI
1609 GetPerformanceMeasurementEx (
1610 IN UINTN LogEntryKey,
1611 OUT CONST VOID **Handle,
1612 OUT CONST CHAR8 **Token,
1613 OUT CONST CHAR8 **Module,
1614 OUT UINT64 *StartTimeStamp,
1615 OUT UINT64 *EndTimeStamp,
1616 OUT UINT32 *Identifier
1617 )
1618 {
1619 return 0;
1620 }
1621
1622 /**
1623 Adds a record at the end of the performance measurement log
1624 that records the start time of a performance measurement.
1625
1626 Adds a record to the end of the performance measurement log
1627 that contains the Handle, Token, and Module.
1628 The end time of the new record must be set to zero.
1629 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1630 If TimeStamp is zero, the start time in the record is filled in with the value
1631 read from the current time stamp.
1632
1633 @param Handle Pointer to environment specific context used
1634 to identify the component being measured.
1635 @param Token Pointer to a Null-terminated ASCII string
1636 that identifies the component being measured.
1637 @param Module Pointer to a Null-terminated ASCII string
1638 that identifies the module being measured.
1639 @param TimeStamp 64-bit time stamp.
1640
1641 @retval RETURN_SUCCESS The start of the measurement was recorded.
1642 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1643
1644 **/
1645 RETURN_STATUS
1646 EFIAPI
1647 StartPerformanceMeasurement (
1648 IN CONST VOID *Handle, OPTIONAL
1649 IN CONST CHAR8 *Token, OPTIONAL
1650 IN CONST CHAR8 *Module, OPTIONAL
1651 IN UINT64 TimeStamp
1652 )
1653 {
1654 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
1655 }
1656
1657 /**
1658 Searches the performance measurement log from the beginning of the log
1659 for the first matching record that contains a zero end time and fills in a valid end time.
1660
1661 Searches the performance measurement log from the beginning of the log
1662 for the first record that matches Handle, Token, and Module and has an end time value of zero.
1663 If the record can not be found then return RETURN_NOT_FOUND.
1664 If the record is found and TimeStamp is not zero,
1665 then the end time in the record is filled in with the value specified by TimeStamp.
1666 If the record is found and TimeStamp is zero, then the end time in the matching record
1667 is filled in with the current time stamp value.
1668
1669 @param Handle Pointer to environment specific context used
1670 to identify the component being measured.
1671 @param Token Pointer to a Null-terminated ASCII string
1672 that identifies the component being measured.
1673 @param Module Pointer to a Null-terminated ASCII string
1674 that identifies the module being measured.
1675 @param TimeStamp 64-bit time stamp.
1676
1677 @retval RETURN_SUCCESS The end of the measurement was recorded.
1678 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1679
1680 **/
1681 RETURN_STATUS
1682 EFIAPI
1683 EndPerformanceMeasurement (
1684 IN CONST VOID *Handle, OPTIONAL
1685 IN CONST CHAR8 *Token, OPTIONAL
1686 IN CONST CHAR8 *Module, OPTIONAL
1687 IN UINT64 TimeStamp
1688 )
1689 {
1690 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
1691 }
1692
1693 /**
1694 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1695 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
1696 and then eliminate the Identifier.
1697
1698 !!! Not support!!!
1699
1700 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1701 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1702 and the key for the second entry in the log is returned. If the performance log is empty,
1703 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1704 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1705 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1706 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1707 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1708 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1709 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
1710 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1711 If Handle is NULL, then ASSERT().
1712 If Token is NULL, then ASSERT().
1713 If Module is NULL, then ASSERT().
1714 If StartTimeStamp is NULL, then ASSERT().
1715 If EndTimeStamp is NULL, then ASSERT().
1716
1717 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1718 0, then the first performance measurement log entry is retrieved.
1719 On exit, the key of the next performance log entry.
1720 @param Handle Pointer to environment specific context used to identify the component
1721 being measured.
1722 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1723 being measured.
1724 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1725 being measured.
1726 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1727 was started.
1728 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1729 was ended.
1730
1731 @return The key for the next performance log entry (in general case).
1732
1733 **/
1734 UINTN
1735 EFIAPI
1736 GetPerformanceMeasurement (
1737 IN UINTN LogEntryKey,
1738 OUT CONST VOID **Handle,
1739 OUT CONST CHAR8 **Token,
1740 OUT CONST CHAR8 **Module,
1741 OUT UINT64 *StartTimeStamp,
1742 OUT UINT64 *EndTimeStamp
1743 )
1744 {
1745 return 0;
1746 }
1747
1748 /**
1749 Returns TRUE if the performance measurement macros are enabled.
1750
1751 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1752 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
1753
1754 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1755 PcdPerformanceLibraryPropertyMask is set.
1756 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1757 PcdPerformanceLibraryPropertyMask is clear.
1758
1759 **/
1760 BOOLEAN
1761 EFIAPI
1762 PerformanceMeasurementEnabled (
1763 VOID
1764 )
1765 {
1766 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
1767 }
1768
1769 /**
1770 Create performance record with event description and a timestamp.
1771
1772 @param CallerIdentifier - Image handle or pointer to caller ID GUID
1773 @param Guid - Pointer to a GUID
1774 @param String - Pointer to a string describing the measurement
1775 @param Address - Pointer to a location in memory relevant to the measurement
1776 @param Identifier - Performance identifier describing the type of measurement
1777
1778 @retval RETURN_SUCCESS - Successfully created performance record
1779 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
1780 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1781 pointer or invalid PerfId
1782
1783 **/
1784 RETURN_STATUS
1785 EFIAPI
1786 LogPerformanceMeasurement (
1787 IN CONST VOID *CallerIdentifier,
1788 IN CONST VOID *Guid, OPTIONAL
1789 IN CONST CHAR8 *String, OPTIONAL
1790 IN UINT64 Address, OPTIONAL
1791 IN UINT32 Identifier
1792 )
1793 {
1794 return (RETURN_STATUS)CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);
1795 }
1796
1797 /**
1798 Check whether the specified performance measurement can be logged.
1799
1800 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
1801 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
1802
1803 @param Type - Type of the performance measurement entry.
1804
1805 @retval TRUE The performance measurement can be logged.
1806 @retval FALSE The performance measurement can NOT be logged.
1807
1808 **/
1809 BOOLEAN
1810 EFIAPI
1811 LogPerformanceMeasurementEnabled (
1812 IN CONST UINTN Type
1813 )
1814 {
1815 //
1816 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
1817 //
1818 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {
1819 return TRUE;
1820 }
1821 return FALSE;
1822 }