]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: Clean up source files
[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 This program and the accompanying materials
16 are licensed and made available under the terms and conditions of the BSD License
17 which accompanies this distribution. The full text of the license may be found at
18 http://opensource.org/licenses/bsd-license.php
19
20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
21 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22
23 **/
24
25
26 #include "DxeCorePerformanceLibInternal.h"
27
28 //
29 // Data for FPDT performance records.
30 //
31 #define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
32 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
33 #define FIRMWARE_RECORD_BUFFER 0x10000
34 #define CACHE_HANDLE_GUID_COUNT 0x800
35
36 BOOT_PERFORMANCE_TABLE *mAcpiBootPerformanceTable = NULL;
37 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate = {
38 {
39 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE,
40 sizeof (BOOT_PERFORMANCE_TABLE)
41 },
42 {
43 {
44 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT, // Type
45 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD), // Length
46 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT // Revision
47 },
48 0, // Reserved
49 //
50 // These values will be updated at runtime.
51 //
52 0, // ResetEnd
53 0, // OsLoaderLoadImageStart
54 0, // OsLoaderStartImageStart
55 0, // ExitBootServicesEntry
56 0 // ExitBootServicesExit
57 }
58 };
59
60 typedef struct {
61 EFI_HANDLE Handle;
62 CHAR8 NameString[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];
63 EFI_GUID ModuleGuid;
64 } HANDLE_GUID_MAP;
65
66 HANDLE_GUID_MAP mCacheHandleGuidTable[CACHE_HANDLE_GUID_COUNT];
67 UINTN mCachePairCount = 0;
68
69 UINT32 mLoadImageCount = 0;
70 UINT32 mPerformanceLength = 0;
71 UINT32 mMaxPerformanceLength = 0;
72 UINT32 mBootRecordSize = 0;
73 UINT32 mBootRecordMaxSize = 0;
74 UINT32 mCachedLength = 0;
75
76 BOOLEAN mFpdtBufferIsReported = FALSE;
77 BOOLEAN mLackSpaceIsReported = FALSE;
78 CHAR8 *mPlatformLanguage = NULL;
79 UINT8 *mPerformancePointer = NULL;
80 UINT8 *mBootRecordBuffer = NULL;
81 BOOLEAN mLockInsertRecord = FALSE;
82 CHAR8 *mDevicePathString = NULL;
83
84 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathToText = NULL;
85
86 //
87 // Interfaces for PerformanceMeasurement Protocol.
88 //
89 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
90 CreatePerformanceMeasurement,
91 };
92
93 PERFORMANCE_PROPERTY mPerformanceProperty;
94
95 /**
96 Return the pointer to the FPDT record in the allocated memory.
97
98 @param RecordSize The size of FPDT record.
99 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
100
101 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
102 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
103 **/
104 EFI_STATUS
105 GetFpdtRecordPtr (
106 IN UINT8 RecordSize,
107 IN OUT FPDT_RECORD_PTR *FpdtRecordPtr
108 )
109 {
110 if (mFpdtBufferIsReported) {
111 //
112 // Append Boot records to the boot performance table.
113 //
114 if (mBootRecordSize + RecordSize > mBootRecordMaxSize) {
115 if (!mLackSpaceIsReported) {
116 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: No enough space to save boot records\n"));
117 mLackSpaceIsReported = TRUE;
118 }
119 return EFI_OUT_OF_RESOURCES;
120 } else {
121 //
122 // Save boot record into BootPerformance table
123 //
124 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mBootRecordSize);
125 }
126 } else {
127 //
128 // Check if pre-allocated buffer is full
129 //
130 if (mPerformanceLength + RecordSize > mMaxPerformanceLength) {
131 mPerformancePointer = ReallocatePool (
132 mPerformanceLength,
133 mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER,
134 mPerformancePointer
135 );
136 if (mPerformancePointer == NULL) {
137 return EFI_OUT_OF_RESOURCES;
138 }
139 mMaxPerformanceLength = mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER;
140 }
141 //
142 // Covert buffer to FPDT Ptr Union type.
143 //
144 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mPerformanceLength);
145 }
146 return EFI_SUCCESS;
147 }
148
149 /**
150 Check whether the Token is a known one which is uesed by core.
151
152 @param Token Pointer to a Null-terminated ASCII string
153
154 @retval TRUE Is a known one used by core.
155 @retval FALSE Not a known one.
156
157 **/
158 BOOLEAN
159 IsKnownTokens (
160 IN CONST CHAR8 *Token
161 )
162 {
163 if (Token == NULL) {
164 return FALSE;
165 }
166
167 if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
168 AsciiStrCmp (Token, PEI_TOK) == 0 ||
169 AsciiStrCmp (Token, DXE_TOK) == 0 ||
170 AsciiStrCmp (Token, BDS_TOK) == 0 ||
171 AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
172 AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||
173 AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||
174 AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||
175 AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||
176 AsciiStrCmp (Token, PEIM_TOK) == 0) {
177 return TRUE;
178 } else {
179 return FALSE;
180 }
181 }
182
183 /**
184 Check whether the ID is a known one which map to the known Token.
185
186 @param Identifier 32-bit identifier.
187
188 @retval TRUE Is a known one used by core.
189 @retval FALSE Not a known one.
190
191 **/
192 BOOLEAN
193 IsKnownID (
194 IN UINT32 Identifier
195 )
196 {
197 if (Identifier == MODULE_START_ID ||
198 Identifier == MODULE_END_ID ||
199 Identifier == MODULE_LOADIMAGE_START_ID ||
200 Identifier == MODULE_LOADIMAGE_END_ID ||
201 Identifier == MODULE_DB_START_ID ||
202 Identifier == MODULE_DB_END_ID ||
203 Identifier == MODULE_DB_SUPPORT_START_ID ||
204 Identifier == MODULE_DB_SUPPORT_END_ID ||
205 Identifier == MODULE_DB_STOP_START_ID ||
206 Identifier == MODULE_DB_STOP_END_ID) {
207 return TRUE;
208 } else {
209 return FALSE;
210 }
211 }
212
213 /**
214 Allocate buffer for Boot Performance table.
215
216 @return Status code.
217
218 **/
219 EFI_STATUS
220 AllocateBootPerformanceTable (
221 )
222 {
223 EFI_STATUS Status;
224 UINTN Size;
225 UINT8 *SmmBootRecordCommBuffer;
226 EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;
227 SMM_BOOT_RECORD_COMMUNICATE *SmmCommData;
228 UINTN CommSize;
229 UINTN BootPerformanceDataSize;
230 UINT8 *BootPerformanceData;
231 EFI_SMM_COMMUNICATION_PROTOCOL *Communication;
232 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
233 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;
234 EFI_MEMORY_DESCRIPTOR *SmmCommMemRegion;
235 UINTN Index;
236 VOID *SmmBootRecordData;
237 UINTN SmmBootRecordDataSize;
238 UINTN ReservedMemSize;
239
240 //
241 // Collect boot records from SMM drivers.
242 //
243 SmmBootRecordCommBuffer = NULL;
244 SmmCommData = NULL;
245 SmmBootRecordData = NULL;
246 SmmBootRecordDataSize = 0;
247 ReservedMemSize = 0;
248 Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);
249 if (!EFI_ERROR (Status)) {
250 //
251 // Initialize communicate buffer
252 // Get the prepared Reserved Memory Range
253 //
254 Status = EfiGetSystemConfigurationTable (
255 &gEdkiiPiSmmCommunicationRegionTableGuid,
256 (VOID **) &SmmCommRegionTable
257 );
258 if (!EFI_ERROR (Status)) {
259 ASSERT (SmmCommRegionTable != NULL);
260 SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) (SmmCommRegionTable + 1);
261 for (Index = 0; Index < SmmCommRegionTable->NumberOfEntries; Index ++) {
262 if (SmmCommMemRegion->Type == EfiConventionalMemory) {
263 break;
264 }
265 SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);
266 }
267 ASSERT (Index < SmmCommRegionTable->NumberOfEntries);
268 ASSERT (SmmCommMemRegion->PhysicalStart > 0);
269 ASSERT (SmmCommMemRegion->NumberOfPages > 0);
270 ReservedMemSize = (UINTN) SmmCommMemRegion->NumberOfPages * EFI_PAGE_SIZE;
271
272 //
273 // Check enough reserved memory space
274 //
275 if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {
276 SmmBootRecordCommBuffer = (VOID *) (UINTN) SmmCommMemRegion->PhysicalStart;
277 SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer;
278 SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data;
279 ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE));
280
281 CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);
282 SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);
283 CommSize = SMM_BOOT_RECORD_COMM_SIZE;
284
285 //
286 // Get the size of boot records.
287 //
288 SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;
289 SmmCommData->BootRecordData = NULL;
290 Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
291
292 if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {
293 //
294 // Get all boot records
295 //
296 SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;
297 SmmBootRecordDataSize = SmmCommData->BootRecordSize;
298 SmmBootRecordData = AllocateZeroPool(SmmBootRecordDataSize);
299 ASSERT (SmmBootRecordData != NULL);
300 SmmCommData->BootRecordOffset = 0;
301 SmmCommData->BootRecordData = (VOID *) ((UINTN) SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);
302 SmmCommData->BootRecordSize = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;
303 while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {
304 Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
305 ASSERT_EFI_ERROR (Status);
306 ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);
307 if (SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
308 CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmCommData->BootRecordOffset);
309 } else {
310 CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
311 }
312 SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;
313 }
314 }
315 }
316 }
317 }
318
319 //
320 // Prepare memory for Boot Performance table.
321 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
322 //
323 BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mPerformanceLength + PcdGet32 (PcdExtFpdtBootRecordPadSize);
324 if (SmmCommData != NULL && SmmBootRecordData != NULL) {
325 BootPerformanceDataSize += SmmBootRecordDataSize;
326 }
327
328 //
329 // Try to allocate the same runtime buffer as last time boot.
330 //
331 ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));
332 Size = sizeof (PerformanceVariable);
333 Status = gRT->GetVariable (
334 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
335 &gEfiFirmwarePerformanceGuid,
336 NULL,
337 &Size,
338 &PerformanceVariable
339 );
340 if (!EFI_ERROR (Status)) {
341 Status = gBS->AllocatePages (
342 AllocateAddress,
343 EfiReservedMemoryType,
344 EFI_SIZE_TO_PAGES (BootPerformanceDataSize),
345 &PerformanceVariable.BootPerformanceTablePointer
346 );
347 if (!EFI_ERROR (Status)) {
348 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;
349 }
350 }
351
352 if (mAcpiBootPerformanceTable == NULL) {
353 //
354 // Fail to allocate at specified address, continue to allocate at any address.
355 //
356 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (
357 EfiReservedMemoryType,
358 EFI_SIZE_TO_PAGES (BootPerformanceDataSize)
359 );
360 if (mAcpiBootPerformanceTable != NULL) {
361 ZeroMem (mAcpiBootPerformanceTable, BootPerformanceDataSize);
362 }
363 }
364 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));
365
366 if (mAcpiBootPerformanceTable == NULL) {
367 if (SmmCommData != NULL && SmmBootRecordData != NULL) {
368 FreePool (SmmBootRecordData);
369 }
370 return EFI_OUT_OF_RESOURCES;
371 }
372
373 //
374 // Prepare Boot Performance Table.
375 //
376 BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;
377 //
378 // Fill Basic Boot record to Boot Performance Table.
379 //
380 CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));
381 BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length;
382 //
383 // Fill Boot records from boot drivers.
384 //
385 if (mPerformancePointer != NULL) {
386 CopyMem (BootPerformanceData, mPerformancePointer, mPerformanceLength);
387 mAcpiBootPerformanceTable->Header.Length += mPerformanceLength;
388 BootPerformanceData = BootPerformanceData + mPerformanceLength;
389 FreePool (mPerformancePointer);
390 mPerformancePointer = NULL;
391 mPerformanceLength = 0;
392 mMaxPerformanceLength = 0;
393 }
394 if (SmmCommData != NULL && SmmBootRecordData != NULL) {
395 //
396 // Fill Boot records from SMM drivers.
397 //
398 CopyMem (BootPerformanceData, SmmBootRecordData, SmmBootRecordDataSize);
399 FreePool (SmmBootRecordData);
400 mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize);
401 BootPerformanceData = BootPerformanceData + SmmBootRecordDataSize;
402 }
403
404 mBootRecordBuffer = (UINT8 *) mAcpiBootPerformanceTable;
405 mBootRecordSize = mAcpiBootPerformanceTable->Header.Length;
406 mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);
407
408 return EFI_SUCCESS;
409 }
410
411 /**
412 Get a human readable module name and module guid for the given image handle.
413 If module name can't be found, "" string will return.
414 If module guid can't be found, Zero Guid will return.
415
416 @param Handle Image handle or Controller handle.
417 @param NameString The ascii string will be filled into it. If not found, null string will return.
418 @param BufferSize Size of the input NameString buffer.
419 @param ModuleGuid Point to the guid buffer to store the got module guid value.
420
421 @retval EFI_SUCCESS Successfully get module name and guid.
422 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
423 @retval other value Module Name can't be got.
424 **/
425 EFI_STATUS
426 GetModuleInfoFromHandle (
427 IN EFI_HANDLE Handle,
428 OUT CHAR8 *NameString,
429 IN UINTN BufferSize,
430 OUT EFI_GUID *ModuleGuid OPTIONAL
431 )
432 {
433 EFI_STATUS Status;
434 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
435 EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
436 CHAR8 *PdbFileName;
437 EFI_GUID *TempGuid;
438 UINTN StartIndex;
439 UINTN Index;
440 INTN Count;
441 BOOLEAN ModuleGuidIsGet;
442 UINTN StringSize;
443 CHAR16 *StringPtr;
444 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
445 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
446
447 if (NameString == NULL || BufferSize == 0) {
448 return EFI_INVALID_PARAMETER;
449 }
450 //
451 // Try to get the ModuleGuid and name string form the caached array.
452 //
453 if (mCachePairCount > 0) {
454 for (Count = mCachePairCount -1; Count >= 0; Count--) {
455 if (Handle == mCacheHandleGuidTable[Count].Handle) {
456 CopyGuid (ModuleGuid, &mCacheHandleGuidTable[Count].ModuleGuid);
457 AsciiStrCpyS (NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, mCacheHandleGuidTable[Count].NameString);
458 return EFI_SUCCESS;
459 }
460 }
461 }
462
463 Status = EFI_INVALID_PARAMETER;
464 LoadedImage = NULL;
465 ModuleGuidIsGet = FALSE;
466
467 //
468 // Initialize GUID as zero value.
469 //
470 TempGuid = &gZeroGuid;
471 //
472 // Initialize it as "" string.
473 //
474 NameString[0] = 0;
475
476 if (Handle != NULL) {
477 //
478 // Try Handle as ImageHandle.
479 //
480 Status = gBS->HandleProtocol (
481 Handle,
482 &gEfiLoadedImageProtocolGuid,
483 (VOID**) &LoadedImage
484 );
485
486 if (EFI_ERROR (Status)) {
487 //
488 // Try Handle as Controller Handle
489 //
490 Status = gBS->OpenProtocol (
491 Handle,
492 &gEfiDriverBindingProtocolGuid,
493 (VOID **) &DriverBinding,
494 NULL,
495 NULL,
496 EFI_OPEN_PROTOCOL_GET_PROTOCOL
497 );
498 if (!EFI_ERROR (Status)) {
499 //
500 // Get Image protocol from ImageHandle
501 //
502 Status = gBS->HandleProtocol (
503 DriverBinding->ImageHandle,
504 &gEfiLoadedImageProtocolGuid,
505 (VOID**) &LoadedImage
506 );
507 }
508 }
509 }
510
511 if (!EFI_ERROR (Status) && LoadedImage != NULL) {
512 //
513 // Get Module Guid from DevicePath.
514 //
515 if (LoadedImage->FilePath != NULL &&
516 LoadedImage->FilePath->Type == MEDIA_DEVICE_PATH &&
517 LoadedImage->FilePath->SubType == MEDIA_PIWG_FW_FILE_DP
518 ) {
519 //
520 // Determine GUID associated with module logging performance
521 //
522 ModuleGuidIsGet = TRUE;
523 FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LoadedImage->FilePath;
524 TempGuid = &FvFilePath->FvFileName;
525 }
526
527 //
528 // Method 1 Get Module Name from PDB string.
529 //
530 PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);
531 if (PdbFileName != NULL && BufferSize > 0) {
532 StartIndex = 0;
533 for (Index = 0; PdbFileName[Index] != 0; Index++) {
534 if ((PdbFileName[Index] == '\\') || (PdbFileName[Index] == '/')) {
535 StartIndex = Index + 1;
536 }
537 }
538 //
539 // Copy the PDB file name to our temporary string.
540 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
541 //
542 for (Index = 0; Index < BufferSize - 1; Index++) {
543 NameString[Index] = PdbFileName[Index + StartIndex];
544 if (NameString[Index] == 0 || NameString[Index] == '.') {
545 NameString[Index] = 0;
546 break;
547 }
548 }
549
550 if (Index == BufferSize - 1) {
551 NameString[Index] = 0;
552 }
553 //
554 // Module Name is got.
555 //
556 goto Done;
557 }
558 }
559
560 //
561 // Method 2: Get the name string from ComponentName2 protocol
562 //
563 Status = gBS->HandleProtocol (
564 Handle,
565 &gEfiComponentName2ProtocolGuid,
566 (VOID **) &ComponentName2
567 );
568 if (!EFI_ERROR (Status)) {
569 //
570 // Get the current platform language setting
571 //
572 if (mPlatformLanguage == NULL) {
573 GetEfiGlobalVariable2 (L"PlatformLang", (VOID **) &mPlatformLanguage, NULL);
574 }
575 if (mPlatformLanguage != NULL) {
576 Status = ComponentName2->GetDriverName (
577 ComponentName2,
578 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",
579 &StringPtr
580 );
581 if (!EFI_ERROR (Status)) {
582 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {
583 NameString[Index] = (CHAR8) StringPtr[Index];
584 }
585 NameString[Index] = 0;
586 //
587 // Module Name is got.
588 //
589 goto Done;
590 }
591 }
592 }
593
594 if (ModuleGuidIsGet) {
595 //
596 // Method 3 Try to get the image's FFS UI section by image GUID
597 //
598 StringPtr = NULL;
599 StringSize = 0;
600 Status = GetSectionFromAnyFv (
601 TempGuid,
602 EFI_SECTION_USER_INTERFACE,
603 0,
604 (VOID **) &StringPtr,
605 &StringSize
606 );
607
608 if (!EFI_ERROR (Status)) {
609 //
610 // Method 3. Get the name string from FFS UI section
611 //
612 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {
613 NameString[Index] = (CHAR8) StringPtr[Index];
614 }
615 NameString[Index] = 0;
616 FreePool (StringPtr);
617 }
618 }
619
620 Done:
621 //
622 // Copy Module Guid
623 //
624 if (ModuleGuid != NULL) {
625 CopyGuid (ModuleGuid, TempGuid);
626 if (IsZeroGuid(TempGuid) && (Handle != NULL) && !ModuleGuidIsGet) {
627 // Handle is GUID
628 CopyGuid (ModuleGuid, (EFI_GUID *) Handle);
629 }
630 }
631
632 //
633 // Cache the Handle and Guid pairs.
634 //
635 if (mCachePairCount < CACHE_HANDLE_GUID_COUNT) {
636 mCacheHandleGuidTable[mCachePairCount].Handle = Handle;
637 CopyGuid (&mCacheHandleGuidTable[mCachePairCount].ModuleGuid, ModuleGuid);
638 AsciiStrCpyS (mCacheHandleGuidTable[mCachePairCount].NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, NameString);
639 mCachePairCount ++;
640 }
641
642 return Status;
643 }
644
645 /**
646 Get the FPDT record identifier.
647
648 @param Attribute The attribute of the Record.
649 PerfStartEntry: Start Record.
650 PerfEndEntry: End Record.
651 @param Handle Pointer to environment specific context used to identify the component being measured.
652 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
653 @param ProgressID On return, pointer to the ProgressID.
654
655 @retval EFI_SUCCESS Get record info successfully.
656 @retval EFI_INVALID_PARAMETER No matched FPDT record.
657
658 **/
659 EFI_STATUS
660 GetFpdtRecordId (
661 IN PERF_MEASUREMENT_ATTRIBUTE Attribute,
662 IN CONST VOID *Handle,
663 IN CONST CHAR8 *String,
664 OUT UINT16 *ProgressID
665 )
666 {
667 //
668 // Token to PerfId.
669 //
670 if (String != NULL) {
671 if (AsciiStrCmp (String, START_IMAGE_TOK) == 0) { // "StartImage:"
672 if (Attribute == PerfStartEntry) {
673 *ProgressID = MODULE_START_ID;
674 } else {
675 *ProgressID = MODULE_END_ID;
676 }
677 } else if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"
678 if (Attribute == PerfStartEntry) {
679 *ProgressID = MODULE_LOADIMAGE_START_ID;
680 } else {
681 *ProgressID = MODULE_LOADIMAGE_END_ID;
682 }
683 } else if (AsciiStrCmp (String, DRIVERBINDING_START_TOK) == 0) { // "DB:Start:"
684 if (Attribute == PerfStartEntry) {
685 *ProgressID = MODULE_DB_START_ID;
686 } else {
687 *ProgressID = MODULE_DB_END_ID;
688 }
689 } else if (AsciiStrCmp (String, DRIVERBINDING_SUPPORT_TOK) == 0) { // "DB:Support:"
690 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
691 return RETURN_UNSUPPORTED;
692 }
693 if (Attribute == PerfStartEntry) {
694 *ProgressID = MODULE_DB_SUPPORT_START_ID;
695 } else {
696 *ProgressID = MODULE_DB_SUPPORT_END_ID;
697 }
698 } else if (AsciiStrCmp (String, DRIVERBINDING_STOP_TOK) == 0) { // "DB:Stop:"
699 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
700 return RETURN_UNSUPPORTED;
701 }
702 if (Attribute == PerfStartEntry) {
703 *ProgressID = MODULE_DB_STOP_START_ID;
704 } else {
705 *ProgressID = MODULE_DB_STOP_END_ID;
706 }
707 } else if (AsciiStrCmp (String, PEI_TOK) == 0 || // "PEI"
708 AsciiStrCmp (String, DXE_TOK) == 0 || // "DXE"
709 AsciiStrCmp (String, BDS_TOK) == 0) { // "BDS"
710 if (Attribute == PerfStartEntry) {
711 *ProgressID = PERF_CROSSMODULE_START_ID;
712 } else {
713 *ProgressID = PERF_CROSSMODULE_END_ID;
714 }
715 } else { // Pref used in Modules.
716 if (Attribute == PerfStartEntry) {
717 *ProgressID = PERF_INMODULE_START_ID;
718 } else {
719 *ProgressID = PERF_INMODULE_END_ID;
720 }
721 }
722 } else if (Handle!= NULL) { // Pref used in Modules.
723 if (Attribute == PerfStartEntry) {
724 *ProgressID = PERF_INMODULE_START_ID;
725 } else {
726 *ProgressID = PERF_INMODULE_END_ID;
727 }
728 } else {
729 return EFI_INVALID_PARAMETER;
730 }
731 return EFI_SUCCESS;
732 }
733
734 /**
735 Copies the string from Source into Destination and updates Length with the
736 size of the string.
737
738 @param Destination - destination of the string copy
739 @param Source - pointer to the source string which will get copied
740 @param Length - pointer to a length variable to be updated
741
742 **/
743 VOID
744 CopyStringIntoPerfRecordAndUpdateLength (
745 IN OUT CHAR8 *Destination,
746 IN CONST CHAR8 *Source,
747 IN OUT UINT8 *Length
748 )
749 {
750 UINTN StringLen;
751 UINTN DestMax;
752
753 ASSERT (Source != NULL);
754
755 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
756 DestMax = STRING_SIZE;
757 } else {
758 DestMax = AsciiStrSize (Source);
759 if (DestMax > STRING_SIZE) {
760 DestMax = STRING_SIZE;
761 }
762 }
763 StringLen = AsciiStrLen (Source);
764 if (StringLen >= DestMax) {
765 StringLen = DestMax -1;
766 }
767
768 AsciiStrnCpyS(Destination, DestMax, Source, StringLen);
769 *Length += (UINT8)DestMax;
770
771 return;
772 }
773
774 /**
775 Get a string description for device for the given controller handle and update record
776 length. If ComponentName2 GetControllerName is supported, the value is included in the string,
777 followed by device path, otherwise just device path.
778
779 @param Handle - Image handle
780 @param ControllerHandle - Controller handle.
781 @param ComponentNameString - Pointer to a location where the string will be saved
782 @param Length - Pointer to record length to be updated
783
784 @retval EFI_SUCCESS - Successfully got string description for device
785 @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found
786
787 **/
788 EFI_STATUS
789 GetDeviceInfoFromHandleAndUpdateLength (
790 IN CONST VOID *Handle,
791 IN EFI_HANDLE ControllerHandle,
792 OUT CHAR8 *ComponentNameString,
793 IN OUT UINT8 *Length
794 )
795 {
796 EFI_DEVICE_PATH_PROTOCOL *DevicePathProtocol;
797 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
798 EFI_STATUS Status;
799 CHAR16 *StringPtr;
800 CHAR8 *AsciiStringPtr;
801 UINTN ControllerNameStringSize;
802 UINTN DevicePathStringSize;
803
804 ControllerNameStringSize = 0;
805
806 Status = gBS->HandleProtocol (
807 (EFI_HANDLE) Handle,
808 &gEfiComponentName2ProtocolGuid,
809 (VOID **) &ComponentName2
810 );
811
812 if (!EFI_ERROR(Status)) {
813 //
814 // Get the current platform language setting
815 //
816 if (mPlatformLanguage == NULL) {
817 GetEfiGlobalVariable2 (L"PlatformLang", (VOID **)&mPlatformLanguage, NULL);
818 }
819
820 Status = ComponentName2->GetControllerName (
821 ComponentName2,
822 ControllerHandle,
823 NULL,
824 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",
825 &StringPtr
826 );
827 }
828
829 if (!EFI_ERROR (Status)) {
830 //
831 // This will produce the size of the unicode string, which is twice as large as the ASCII one
832 // This must be an even number, so ok to divide by 2
833 //
834 ControllerNameStringSize = StrSize(StringPtr) / 2;
835
836 //
837 // The + 1 is because we want to add a space between the ControllerName and the device path
838 //
839 if ((ControllerNameStringSize + (*Length) + 1) > FPDT_MAX_PERF_RECORD_SIZE) {
840 //
841 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
842 //
843 ControllerNameStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length) - 1;
844 }
845
846 UnicodeStrToAsciiStrS(StringPtr, ComponentNameString, ControllerNameStringSize);
847
848 //
849 // Add a space in the end of the ControllerName
850 //
851 AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;
852 *AsciiStringPtr = 0x20;
853 AsciiStringPtr++;
854 *AsciiStringPtr = 0;
855 ControllerNameStringSize++;
856
857 *Length += (UINT8)ControllerNameStringSize;
858 }
859
860 //
861 // This function returns the device path protocol from the handle specified by Handle. If Handle is
862 // NULL or Handle does not contain a device path protocol, then NULL is returned.
863 //
864 DevicePathProtocol = DevicePathFromHandle(ControllerHandle);
865
866 if (DevicePathProtocol != NULL) {
867 StringPtr = ConvertDevicePathToText (DevicePathProtocol, TRUE, FALSE);
868 if (StringPtr != NULL) {
869 //
870 // This will produce the size of the unicode string, which is twice as large as the ASCII one
871 // This must be an even number, so ok to divide by 2
872 //
873 DevicePathStringSize = StrSize(StringPtr) / 2;
874
875 if ((DevicePathStringSize + (*Length)) > FPDT_MAX_PERF_RECORD_SIZE) {
876 //
877 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
878 //
879 DevicePathStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length);
880 }
881
882 if (ControllerNameStringSize != 0) {
883 AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;
884 } else {
885 AsciiStringPtr = ComponentNameString;
886 }
887
888 UnicodeStrToAsciiStrS(StringPtr, AsciiStringPtr, DevicePathStringSize);
889 *Length += (UINT8)DevicePathStringSize;
890 return EFI_SUCCESS;
891 }
892 }
893
894 return EFI_UNSUPPORTED;
895 }
896
897 /**
898 Create performance record with event description and a timestamp.
899
900 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
901 @param Guid - Pointer to a GUID.
902 @param String - Pointer to a string describing the measurement.
903 @param Ticker - 64-bit time stamp.
904 @param Address - Pointer to a location in memory relevant to the measurement.
905 @param PerfId - Performance identifier describing the type of measurement.
906 @param Attribute - The attribute of the measurement. According to attribute can create a start
907 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
908 or a general record for other Perf macros.
909
910 @retval EFI_SUCCESS - Successfully created performance record.
911 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
912 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
913 pointer or invalid PerfId.
914
915 @retval EFI_SUCCESS - Successfully created performance record
916 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records
917 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
918 pointer or invalid PerfId
919
920 **/
921 EFI_STATUS
922 InsertFpdtRecord (
923 IN CONST VOID *CallerIdentifier, OPTIONAL
924 IN CONST VOID *Guid, OPTIONAL
925 IN CONST CHAR8 *String, OPTIONAL
926 IN UINT64 Ticker,
927 IN UINT64 Address, OPTIONAL
928 IN UINT16 PerfId,
929 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
930 )
931 {
932 EFI_GUID ModuleGuid;
933 CHAR8 ModuleName[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];
934 FPDT_RECORD_PTR FpdtRecordPtr;
935 FPDT_RECORD_PTR CachedFpdtRecordPtr;
936 UINT64 TimeStamp;
937 CONST CHAR8 *StringPtr;
938 UINTN DestMax;
939 UINTN StringLen;
940 EFI_STATUS Status;
941 UINT16 ProgressId;
942
943 StringPtr = NULL;
944 ProgressId = 0;
945 ZeroMem (ModuleName, sizeof (ModuleName));
946
947 //
948 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
949 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
950 //
951 if (Attribute != PerfEntry) {
952 //
953 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
954 // !!! Note: If the Perf is not the known Token used in the core but have same
955 // ID with the core Token, this case will not be supported.
956 // And in currtnt usage mode, for the unkown ID, there is a general rule:
957 // If it is start pref: the lower 4 bits of the ID should be 0.
958 // If it is end pref: the lower 4 bits of the ID should not be 0.
959 // If input ID doesn't follow the rule, we will adjust it.
960 //
961 if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
962 return EFI_INVALID_PARAMETER;
963 } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
964 if ((Attribute == PerfStartEntry) && ((PerfId & 0x000F) != 0)) {
965 PerfId &= 0xFFF0;
966 } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {
967 PerfId += 1;
968 }
969 } else if (PerfId == 0) {
970 //
971 // Get ProgressID form the String Token.
972 //
973 Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &ProgressId);
974 if (EFI_ERROR (Status)) {
975 return Status;
976 }
977 PerfId = ProgressId;
978 }
979 }
980
981 //
982 // 2. Get the buffer to store the FPDT record.
983 //
984 Status = GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE, &FpdtRecordPtr);
985 if (EFI_ERROR (Status)) {
986 return Status;
987 }
988
989 //
990 //3. Get the TimeStamp.
991 //
992 if (Ticker == 0) {
993 Ticker = GetPerformanceCounter ();
994 TimeStamp = GetTimeInNanoSecond (Ticker);
995 } else if (Ticker == 1) {
996 TimeStamp = 0;
997 } else {
998 TimeStamp = GetTimeInNanoSecond (Ticker);
999 }
1000
1001 //
1002 // 4. Fill in the FPDT record according to different Performance Identifier.
1003 //
1004 switch (PerfId) {
1005 case MODULE_START_ID:
1006 case MODULE_END_ID:
1007 GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1008 StringPtr = ModuleName;
1009 //
1010 // Cache the offset of start image start record and use to update the start image end record if needed.
1011 //
1012 if (Attribute == PerfEntry && PerfId == MODULE_START_ID) {
1013 if (mFpdtBufferIsReported) {
1014 mCachedLength = mBootRecordSize;
1015 } else {
1016 mCachedLength = mPerformanceLength;
1017 }
1018 }
1019 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1020 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;
1021 FpdtRecordPtr.GuidEvent->Header.Length = sizeof (FPDT_GUID_EVENT_RECORD);
1022 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1023 FpdtRecordPtr.GuidEvent->ProgressID = PerfId;
1024 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;
1025 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidEvent->Guid));
1026 if (CallerIdentifier == NULL && PerfId == MODULE_END_ID && mCachedLength != 0) {
1027 if (mFpdtBufferIsReported) {
1028 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);
1029 } else {
1030 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);
1031 }
1032 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &CachedFpdtRecordPtr.GuidEvent->Guid, sizeof (FpdtRecordPtr.GuidEvent->Guid));
1033 mCachedLength = 0;
1034 }
1035 }
1036 break;
1037
1038 case MODULE_LOADIMAGE_START_ID:
1039 case MODULE_LOADIMAGE_END_ID:
1040 GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1041 StringPtr = ModuleName;
1042 if (PerfId == MODULE_LOADIMAGE_START_ID) {
1043 mLoadImageCount ++;
1044 //
1045 // Cache the offset of load image start record and use to be updated by the load image end record if needed.
1046 //
1047 if (CallerIdentifier == NULL && Attribute == PerfEntry) {
1048 if (mFpdtBufferIsReported) {
1049 mCachedLength = mBootRecordSize;
1050 } else {
1051 mCachedLength = mPerformanceLength;
1052 }
1053 }
1054 }
1055 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1056 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;
1057 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
1058 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1059 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;
1060 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;
1061 FpdtRecordPtr.GuidQwordEvent->Qword = mLoadImageCount;
1062 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));
1063 if (PerfId == MODULE_LOADIMAGE_END_ID && mCachedLength != 0) {
1064 if (mFpdtBufferIsReported) {
1065 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);
1066 } else {
1067 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);
1068 }
1069 CopyMem (&CachedFpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.GuidQwordEvent->Guid));
1070 mCachedLength = 0;
1071 }
1072 }
1073 break;
1074
1075 case MODULE_DB_START_ID:
1076 case MODULE_DB_SUPPORT_START_ID:
1077 case MODULE_DB_SUPPORT_END_ID:
1078 case MODULE_DB_STOP_START_ID:
1079 case MODULE_DB_STOP_END_ID:
1080 GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1081 StringPtr = ModuleName;
1082 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1083 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;
1084 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
1085 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1086 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;
1087 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;
1088 FpdtRecordPtr.GuidQwordEvent->Qword = Address;
1089 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));
1090 }
1091 break;
1092
1093 case MODULE_DB_END_ID:
1094 GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1095 StringPtr = ModuleName;
1096 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1097 FpdtRecordPtr.GuidQwordStringEvent->Header.Type = FPDT_GUID_QWORD_STRING_EVENT_TYPE;
1098 FpdtRecordPtr.GuidQwordStringEvent->Header.Length = sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD);;
1099 FpdtRecordPtr.GuidQwordStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1100 FpdtRecordPtr.GuidQwordStringEvent->ProgressID = PerfId;
1101 FpdtRecordPtr.GuidQwordStringEvent->Timestamp = TimeStamp;
1102 FpdtRecordPtr.GuidQwordStringEvent->Qword = Address;
1103 CopyMem (&FpdtRecordPtr.GuidQwordStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordStringEvent->Guid));
1104 if (Address != 0) {
1105 GetDeviceInfoFromHandleAndUpdateLength(CallerIdentifier, (EFI_HANDLE)(UINTN)Address, FpdtRecordPtr.GuidQwordStringEvent->String, &FpdtRecordPtr.GuidQwordStringEvent->Header.Length);
1106 }
1107 }
1108 break;
1109
1110 case PERF_EVENTSIGNAL_START_ID:
1111 case PERF_EVENTSIGNAL_END_ID:
1112 case PERF_CALLBACK_START_ID:
1113 case PERF_CALLBACK_END_ID:
1114 if (String == NULL) {
1115 return EFI_INVALID_PARAMETER;
1116 }
1117 //
1118 // Cache the event guid in string event record when PcdEdkiiFpdtStringRecordEnableOnly == TRUE
1119 //
1120 CopyGuid (&ModuleGuid, Guid);
1121 StringPtr = String;
1122 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1123 FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;
1124 FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);
1125 FpdtRecordPtr.DualGuidStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1126 FpdtRecordPtr.DualGuidStringEvent->ProgressID = PerfId;
1127 FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;
1128 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, CallerIdentifier, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));
1129 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));
1130 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);
1131 }
1132 break;
1133
1134 case PERF_EVENT_ID:
1135 case PERF_FUNCTION_START_ID:
1136 case PERF_FUNCTION_END_ID:
1137 case PERF_INMODULE_START_ID:
1138 case PERF_INMODULE_END_ID:
1139 case PERF_CROSSMODULE_START_ID:
1140 case PERF_CROSSMODULE_END_ID:
1141 GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1142 if (String != NULL) {
1143 StringPtr = String;
1144 } else {
1145 StringPtr = ModuleName;
1146 }
1147 if (AsciiStrLen (StringPtr) == 0) {
1148 StringPtr = "unknown name";
1149 }
1150 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1151 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
1152 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1153 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1154 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
1155 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
1156 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
1157 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
1158 }
1159 break;
1160
1161 default:
1162 if (Attribute != PerfEntry) {
1163 GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);
1164 if (String != NULL) {
1165 StringPtr = String;
1166 } else {
1167 StringPtr = ModuleName;
1168 }
1169 if (AsciiStrLen (StringPtr) == 0) {
1170 StringPtr = "unknown name";
1171 }
1172 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1173 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
1174 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1175 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1176 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
1177 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
1178 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
1179 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
1180 }
1181 } else {
1182 return EFI_INVALID_PARAMETER;
1183 }
1184 break;
1185 }
1186
1187 //
1188 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
1189 //
1190 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
1191 if (StringPtr == NULL ||PerfId == MODULE_DB_SUPPORT_START_ID || PerfId == MODULE_DB_SUPPORT_END_ID) {
1192 return EFI_INVALID_PARAMETER;
1193 }
1194 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
1195 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
1196 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
1197 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
1198 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
1199 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
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 }