]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
MdeModulePkg/SmmCorePerformanceLib:Track FPDT record in SMM phase
[mirror_edk2.git] / MdeModulePkg / Library / SmmCorePerformanceLib / SmmCorePerformanceLib.c
1 /** @file
2 Performance library instance used by SMM Core.
3
4 This library provides the performance measurement interfaces and initializes performance
5 logging for the SMM phase.
6 It initializes SMM phase performance logging by publishing the SMM Performance and PerformanceEx Protocol,
7 which is consumed by SmmPerformanceLib to logging performance data in SMM phase.
8
9 This library is mainly used by SMM Core to start performance logging to ensure that
10 SMM Performance and PerformanceEx Protocol are installed at the very beginning of SMM phase.
11
12 Caution: This module requires additional review when modified.
13 This driver will have external input - performance data and communicate buffer in SMM mode.
14 This external input must be validated carefully to avoid security issue like
15 buffer overflow, integer overflow.
16
17 SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.
18
19 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
20 This program and the accompanying materials
21 are licensed and made available under the terms and conditions of the BSD License
22 which accompanies this distribution. The full text of the license may be found at
23 http://opensource.org/licenses/bsd-license.php
24
25 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
26 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27
28 **/
29
30
31 #include "SmmCorePerformanceLibInternal.h"
32
33 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
34 #define FIRMWARE_RECORD_BUFFER 0x1000
35 #define CACHE_HANDLE_GUID_COUNT 0x100
36
37 SMM_BOOT_PERFORMANCE_TABLE *mSmmBootPerformanceTable = NULL;
38
39 typedef struct {
40 EFI_HANDLE Handle;
41 CHAR8 NameString[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];
42 EFI_GUID ModuleGuid;
43 } HANDLE_GUID_MAP;
44
45 HANDLE_GUID_MAP mCacheHandleGuidTable[CACHE_HANDLE_GUID_COUNT];
46 UINTN mCachePairCount = 0;
47
48 UINT32 mPerformanceLength = 0;
49 UINT32 mMaxPerformanceLength = 0;
50 BOOLEAN mFpdtDataIsReported = FALSE;
51 BOOLEAN mLackSpaceIsReport = FALSE;
52 CHAR8 *mPlatformLanguage = NULL;
53 SPIN_LOCK mSmmFpdtLock;
54 PERFORMANCE_PROPERTY mPerformanceProperty;
55
56 //
57 // Interfaces for SMM Performance Protocol.
58 //
59 PERFORMANCE_PROTOCOL mPerformanceInterface = {
60 StartGauge,
61 EndGauge,
62 GetGauge
63 };
64
65 //
66 // Interfaces for SMM PerformanceEx Protocol.
67 //
68 PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {
69 StartGaugeEx,
70 EndGaugeEx,
71 GetGaugeEx
72 };
73
74 /**
75 Check whether the Token is a known one which is uesed by core.
76
77 @param Token Pointer to a Null-terminated ASCII string
78
79 @retval TRUE Is a known one used by core.
80 @retval FALSE Not a known one.
81
82 **/
83 BOOLEAN
84 IsKnownTokens (
85 IN CONST CHAR8 *Token
86 )
87 {
88 if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
89 AsciiStrCmp (Token, PEI_TOK) == 0 ||
90 AsciiStrCmp (Token, DXE_TOK) == 0 ||
91 AsciiStrCmp (Token, BDS_TOK) == 0 ||
92 AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
93 AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||
94 AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||
95 AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||
96 AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||
97 AsciiStrCmp (Token, PEIM_TOK) == 0) {
98 return TRUE;
99 } else {
100 return FALSE;
101 }
102 }
103
104 /**
105 Check whether the ID is a known one which map to the known Token.
106
107 @param Identifier 32-bit identifier.
108
109 @retval TRUE Is a known one used by core.
110 @retval FALSE Not a known one.
111
112 **/
113 BOOLEAN
114 IsKnownID (
115 IN UINT32 Identifier
116 )
117 {
118 if (Identifier == MODULE_START_ID ||
119 Identifier == MODULE_END_ID ||
120 Identifier == MODULE_LOADIMAGE_START_ID ||
121 Identifier == MODULE_LOADIMAGE_END_ID ||
122 Identifier == MODULE_DB_START_ID ||
123 Identifier == MODULE_DB_END_ID ||
124 Identifier == MODULE_DB_SUPPORT_START_ID ||
125 Identifier == MODULE_DB_SUPPORT_END_ID ||
126 Identifier == MODULE_DB_STOP_START_ID ||
127 Identifier == MODULE_DB_STOP_END_ID) {
128 return TRUE;
129 } else {
130 return FALSE;
131 }
132 }
133
134 /**
135 Get the FPDT record info.
136
137 @param IsStart TRUE if the performance log is start log.
138 @param Handle Pointer to environment specific context used
139 to identify the component being measured.
140 @param Token Pointer to a Null-terminated ASCII string
141 that identifies the component being measured.
142 @param Module Pointer to a Null-terminated ASCII string
143 that identifies the module being measured.
144 @param RecordInfo On return, pointer to the info of the record.
145 @param UseModuleName Only useful for FPDT_DYNAMIC_STRING_EVENT_TYPE, indicate that whether need use
146 Module name to fill the string field in the FPDT_DYNAMIC_STRING_EVENT_RECORD.
147
148 @retval EFI_SUCCESS Get record info successfully.
149 @retval EFI_UNSUPPORTED No matched FPDT record.
150
151 **/
152 EFI_STATUS
153 GetFpdtRecordInfo (
154 IN BOOLEAN IsStart,
155 IN CONST VOID *Handle,
156 IN CONST CHAR8 *Token,
157 IN CONST CHAR8 *Module,
158 OUT FPDT_BASIC_RECORD_INFO *RecordInfo,
159 IN OUT BOOLEAN *UseModuleName
160 )
161 {
162 UINT16 RecordType;
163 UINTN StringSize;
164
165 RecordType = FPDT_DYNAMIC_STRING_EVENT_TYPE;
166
167 //
168 // Token to Type and Id.
169 //
170 if (Token != NULL) {
171 if (AsciiStrCmp (Token, START_IMAGE_TOK) == 0) { // "StartImage:"
172 *UseModuleName = TRUE;
173 RecordType = FPDT_GUID_EVENT_TYPE;
174 if (IsStart) {
175 RecordInfo->ProgressID = MODULE_START_ID;
176 } else {
177 RecordInfo->ProgressID = MODULE_END_ID;
178 }
179 } else if (AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"
180 *UseModuleName = TRUE;
181 RecordType = FPDT_GUID_QWORD_EVENT_TYPE;
182 if (IsStart) {
183 RecordInfo->ProgressID = MODULE_LOADIMAGE_START_ID;
184 } else {
185 RecordInfo->ProgressID = MODULE_LOADIMAGE_END_ID;
186 }
187 } else { // Pref used in Modules
188 if (IsStart) {
189 RecordInfo->ProgressID = PERF_INMODULE_START_ID;
190 } else {
191 RecordInfo->ProgressID = PERF_INMODULE_END_ID;
192 }
193 }
194 } else if (Handle != NULL || Module != NULL) { // Pref used in Modules
195 if (IsStart) {
196 RecordInfo->ProgressID = PERF_INMODULE_START_ID;
197 } else {
198 RecordInfo->ProgressID = PERF_INMODULE_END_ID;
199 }
200 } else {
201 return EFI_UNSUPPORTED;
202 }
203
204 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
205 RecordType = FPDT_DYNAMIC_STRING_EVENT_TYPE;
206 RecordInfo->RecordSize = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE;
207 } else {
208 switch (RecordType) {
209 case FPDT_GUID_EVENT_TYPE:
210 RecordInfo->RecordSize = sizeof (FPDT_GUID_EVENT_RECORD);
211 break;
212
213 case FPDT_DYNAMIC_STRING_EVENT_TYPE:
214 if (*UseModuleName) {
215 StringSize = STRING_SIZE;
216 } else if (Token != NULL) {
217 StringSize = AsciiStrSize (Token);
218 } else if (Module != NULL) {
219 StringSize = AsciiStrSize (Module);
220 } else {
221 StringSize = STRING_SIZE;
222 }
223 if (StringSize > STRING_SIZE) {
224 StringSize = STRING_SIZE;
225 }
226 RecordInfo->RecordSize = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + StringSize);
227 break;
228
229 case FPDT_GUID_QWORD_EVENT_TYPE:
230 RecordInfo->RecordSize = (UINT8)sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
231 break;
232
233 default:
234 //
235 // Record type is unsupported in SMM phase.
236 //
237 return EFI_UNSUPPORTED;
238 }
239 }
240
241 RecordInfo->Type = RecordType;
242 return EFI_SUCCESS;
243 }
244
245 /**
246 Get a human readable module name and module guid for the given image handle.
247 If module name can't be found, "" string will return.
248 If module guid can't be found, Zero Guid will return.
249
250 @param Handle Image handle or Controller handle.
251 @param NameString The ascii string will be filled into it. If not found, null string will return.
252 @param BufferSize Size of the input NameString buffer.
253 @param ModuleGuid Point to the guid buffer to store the got module guid value.
254
255 @retval EFI_SUCCESS Successfully get module name and guid.
256 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
257 @retval other value Module Name can't be got.
258 **/
259 EFI_STATUS
260 EFIAPI
261 GetModuleInfoFromHandle (
262 IN EFI_HANDLE Handle,
263 OUT CHAR8 *NameString,
264 IN UINTN BufferSize,
265 OUT EFI_GUID *ModuleGuid OPTIONAL
266 )
267 {
268 EFI_STATUS Status;
269 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
270 EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
271 CHAR8 *PdbFileName;
272 EFI_GUID *TempGuid;
273 UINTN StartIndex;
274 UINTN Index;
275 INTN Count;
276 BOOLEAN ModuleGuidIsGet;
277 UINTN StringSize;
278 CHAR16 *StringPtr;
279 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
280
281 if (NameString == NULL || BufferSize == 0) {
282 return EFI_INVALID_PARAMETER;
283 }
284
285 //
286 // Try to get the ModuleGuid and name string form the caached array.
287 //
288 if (mCachePairCount > 0) {
289 for (Count = mCachePairCount - 1; Count >= 0; Count--) {
290 if (Handle == mCacheHandleGuidTable[Count].Handle) {
291 CopyGuid (ModuleGuid, &mCacheHandleGuidTable[Count].ModuleGuid);
292 AsciiStrCpyS (NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, mCacheHandleGuidTable[Count].NameString);
293 return EFI_SUCCESS;
294 }
295 }
296 }
297
298 Status = EFI_INVALID_PARAMETER;
299 LoadedImage = NULL;
300 ModuleGuidIsGet = FALSE;
301
302 //
303 // Initialize GUID as zero value.
304 //
305 TempGuid = &gZeroGuid;
306 //
307 // Initialize it as "" string.
308 //
309 NameString[0] = 0;
310
311 if (Handle != NULL) {
312 //
313 // Try Handle as ImageHandle.
314 //
315 Status = gBS->HandleProtocol (
316 Handle,
317 &gEfiLoadedImageProtocolGuid,
318 (VOID**) &LoadedImage
319 );
320
321 if (EFI_ERROR (Status)) {
322 //
323 // Try Handle as Controller Handle
324 //
325 Status = gBS->OpenProtocol (
326 Handle,
327 &gEfiDriverBindingProtocolGuid,
328 (VOID **) &DriverBinding,
329 NULL,
330 NULL,
331 EFI_OPEN_PROTOCOL_GET_PROTOCOL
332 );
333 if (!EFI_ERROR (Status)) {
334 //
335 // Get Image protocol from ImageHandle
336 //
337 Status = gBS->HandleProtocol (
338 DriverBinding->ImageHandle,
339 &gEfiLoadedImageProtocolGuid,
340 (VOID**) &LoadedImage
341 );
342 }
343 }
344 }
345
346 if (!EFI_ERROR (Status) && LoadedImage != NULL) {
347 //
348 // Get Module Guid from DevicePath.
349 //
350 if (LoadedImage->FilePath != NULL &&
351 LoadedImage->FilePath->Type == MEDIA_DEVICE_PATH &&
352 LoadedImage->FilePath->SubType == MEDIA_PIWG_FW_FILE_DP
353 ) {
354 //
355 // Determine GUID associated with module logging performance
356 //
357 ModuleGuidIsGet = TRUE;
358 FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LoadedImage->FilePath;
359 TempGuid = &FvFilePath->FvFileName;
360 }
361
362 //
363 // Method 1 Get Module Name from PDB string.
364 //
365 PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);
366 if (PdbFileName != NULL && BufferSize > 0) {
367 StartIndex = 0;
368 for (Index = 0; PdbFileName[Index] != 0; Index++) {
369 if ((PdbFileName[Index] == '\\') || (PdbFileName[Index] == '/')) {
370 StartIndex = Index + 1;
371 }
372 }
373 //
374 // Copy the PDB file name to our temporary string.
375 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
376 //
377 for (Index = 0; Index < BufferSize - 1; Index++) {
378 NameString[Index] = PdbFileName[Index + StartIndex];
379 if (NameString[Index] == 0 || NameString[Index] == '.') {
380 NameString[Index] = 0;
381 break;
382 }
383 }
384
385 if (Index == BufferSize - 1) {
386 NameString[Index] = 0;
387 }
388 //
389 // Module Name is got.
390 //
391 goto Done;
392 }
393 }
394
395 if (ModuleGuidIsGet) {
396 //
397 // Method 2 Try to get the image's FFS UI section by image GUID
398 //
399 StringPtr = NULL;
400 StringSize = 0;
401 Status = GetSectionFromAnyFv (
402 TempGuid,
403 EFI_SECTION_USER_INTERFACE,
404 0,
405 (VOID **) &StringPtr,
406 &StringSize
407 );
408
409 if (!EFI_ERROR (Status)) {
410 //
411 // Method 3. Get the name string from FFS UI section
412 //
413 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {
414 NameString[Index] = (CHAR8) StringPtr[Index];
415 }
416 NameString[Index] = 0;
417 FreePool (StringPtr);
418 }
419 }
420
421 Done:
422 //
423 // Copy Module Guid
424 //
425 if (ModuleGuid != NULL) {
426 CopyGuid (ModuleGuid, TempGuid);
427 if (IsZeroGuid(TempGuid) && (Handle != NULL) && !ModuleGuidIsGet) {
428 // Handle is GUID
429 CopyGuid (ModuleGuid, (EFI_GUID *) Handle);
430 }
431 }
432
433 //
434 // Cache the Handle and Guid pairs.
435 //
436 if (mCachePairCount < CACHE_HANDLE_GUID_COUNT) {
437 mCacheHandleGuidTable[mCachePairCount].Handle = Handle;
438 CopyGuid (&mCacheHandleGuidTable[mCachePairCount].ModuleGuid, ModuleGuid);
439 AsciiStrCpyS (mCacheHandleGuidTable[mCachePairCount].NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, NameString);
440 mCachePairCount ++;
441 }
442
443 return Status;
444 }
445
446 /**
447 Add performance log to FPDT boot record table.
448
449 @param IsStart TRUE if the performance log is start log.
450 @param Handle Pointer to environment specific context used
451 to identify the component being measured.
452 @param Token Pointer to a Null-terminated ASCII string
453 that identifies the component being measured.
454 @param Module Pointer to a Null-terminated ASCII string
455 that identifies the module being measured.
456 @param Ticker 64-bit time stamp.
457 @param Identifier 32-bit identifier. If the value is 0, the created record
458 is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.
459
460 @retval EFI_SUCCESS Add FPDT boot record.
461 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.
462 @retval EFI_UNSUPPORTED No matched FPDT record.
463
464 **/
465 EFI_STATUS
466 InsertFpdtMeasurement (
467 IN BOOLEAN IsStart,
468 IN CONST VOID *Handle, OPTIONAL
469 IN CONST CHAR8 *Token, OPTIONAL
470 IN CONST CHAR8 *Module, OPTIONAL
471 IN UINT64 Ticker,
472 IN UINT32 Identifier
473 )
474 {
475 EFI_GUID ModuleGuid;
476 CHAR8 ModuleName[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];
477 EFI_STATUS Status;
478 FPDT_RECORD_PTR FpdtRecordPtr;
479 UINT64 TimeStamp;
480 FPDT_BASIC_RECORD_INFO RecordInfo;
481 UINTN DestMax;
482 UINTN StrLength;
483 CONST CHAR8 *StringPtr;
484 BOOLEAN UseModuleName;
485
486 StringPtr = NULL;
487 UseModuleName = FALSE;
488 ZeroMem (ModuleName, sizeof (ModuleName));
489
490 //
491 // Get record info includes type, size, ProgressID.
492 //
493 Status = GetFpdtRecordInfo (IsStart, Handle, Token, Module, &RecordInfo, &UseModuleName);
494 if (EFI_ERROR (Status)) {
495 return Status;
496 }
497
498 //
499 // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.
500 // !!! Note: If the Pref is not the known Token used in the core but have same
501 // ID with the core Token, this case will not be supported.
502 // And in currtnt usage mode, for the unkown ID, there is a general rule:
503 // If it is start pref: the lower 4 bits of the ID should be 0.
504 // If it is end pref: the lower 4 bits of the ID should not be 0.
505 // If input ID doesn't follow the rule, we will adjust it.
506 //
507 if ((Identifier != 0) && (IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {
508 return EFI_UNSUPPORTED;
509 } else if ((Identifier != 0) && (!IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {
510 if (IsStart && ((Identifier & 0x000F) != 0)) {
511 Identifier &= 0xFFF0;
512 } else if ((!IsStart) && ((Identifier & 0x000F) == 0)) {
513 Identifier += 1;
514 }
515 RecordInfo.ProgressID = (UINT16)Identifier;
516 }
517
518 if (mFpdtDataIsReported) {
519 //
520 // Append Boot records after Smm boot performance records have been reported.
521 //
522 if (mPerformanceLength + RecordInfo.RecordSize > mMaxPerformanceLength) {
523 if (!mLackSpaceIsReport) {
524 DEBUG ((DEBUG_INFO, "SmmCorePerformanceLib: No enough space to save boot records\n"));
525 mLackSpaceIsReport = TRUE;
526 }
527 return EFI_OUT_OF_RESOURCES;
528 } else {
529 //
530 // Covert buffer to FPDT Ptr Union type.
531 //
532 FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)((UINT8*)mSmmBootPerformanceTable + mSmmBootPerformanceTable->Header.Length);
533 }
534 } else {
535 //
536 // Check if pre-allocated buffer is full
537 //
538 if (mPerformanceLength + RecordInfo.RecordSize > mMaxPerformanceLength) {
539 mSmmBootPerformanceTable = ReallocatePool (
540 mPerformanceLength,
541 mPerformanceLength + sizeof (SMM_BOOT_PERFORMANCE_TABLE) + RecordInfo.RecordSize + FIRMWARE_RECORD_BUFFER,
542 mSmmBootPerformanceTable
543 );
544
545 if (mSmmBootPerformanceTable == NULL) {
546 return EFI_OUT_OF_RESOURCES;
547 }
548 mSmmBootPerformanceTable->Header.Length = sizeof (SMM_BOOT_PERFORMANCE_TABLE) + mPerformanceLength;
549 mMaxPerformanceLength = mPerformanceLength + sizeof (SMM_BOOT_PERFORMANCE_TABLE) + RecordInfo.RecordSize + FIRMWARE_RECORD_BUFFER;
550 }
551 //
552 // Covert buffer to FPDT Ptr Union type.
553 //
554 FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)((UINT8*)mSmmBootPerformanceTable + mSmmBootPerformanceTable->Header.Length);
555 }
556 FpdtRecordPtr.RecordHeader->Length = 0;
557
558 //
559 // Get the TimeStamp.
560 //
561 if (Ticker == 0) {
562 Ticker = GetPerformanceCounter ();
563 TimeStamp = GetTimeInNanoSecond (Ticker);
564 } else if (Ticker == 1) {
565 TimeStamp = 0;
566 } else {
567 TimeStamp = GetTimeInNanoSecond (Ticker);
568 }
569
570 //
571 // Get the ModuleName and ModuleGuid form the handle.
572 //
573 GetModuleInfoFromHandle ((EFI_HANDLE *)Handle, ModuleName, sizeof (ModuleName), &ModuleGuid);
574
575 //
576 // Fill in the record information.
577 //
578 switch (RecordInfo.Type) {
579 case FPDT_GUID_EVENT_TYPE:
580 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;
581 FpdtRecordPtr.GuidEvent->Header.Length = RecordInfo.RecordSize;
582 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;
583 FpdtRecordPtr.GuidEvent->ProgressID = RecordInfo.ProgressID;
584 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;
585 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidEvent->Guid));
586 break;
587
588 case FPDT_DYNAMIC_STRING_EVENT_TYPE:
589 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;
590 FpdtRecordPtr.DynamicStringEvent->Header.Length = RecordInfo.RecordSize;
591 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
592 FpdtRecordPtr.DynamicStringEvent->ProgressID = RecordInfo.ProgressID;
593 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
594 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
595
596 if (UseModuleName) {
597 StringPtr = ModuleName;
598 } else if (Token != NULL) {
599 StringPtr = Token;
600 } else if (Module != NULL) {
601 StringPtr = Module;
602 } else if (ModuleName != NULL) {
603 StringPtr = ModuleName;
604 }
605 if (StringPtr != NULL && AsciiStrLen (StringPtr) != 0) {
606 StrLength = AsciiStrLen (StringPtr);
607 DestMax = (RecordInfo.RecordSize - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)) / sizeof (CHAR8);
608 if (StrLength >= DestMax) {
609 StrLength = DestMax -1;
610 }
611 AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StrLength);
612 } else {
613 AsciiStrCpyS (FpdtRecordPtr.DynamicStringEvent->String, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, "unknown name");
614 }
615 break;
616
617 case FPDT_GUID_QWORD_EVENT_TYPE:
618 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;
619 FpdtRecordPtr.GuidQwordEvent->Header.Length = RecordInfo.RecordSize;
620 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
621 FpdtRecordPtr.GuidQwordEvent->ProgressID = RecordInfo.ProgressID;
622 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;
623 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));
624 break;
625
626 default:
627 //
628 // Record is not supported in current SMM phase, return EFI_UNSUPPORTED
629 //
630 return EFI_UNSUPPORTED;
631 }
632
633 //
634 // Update the cached FPDT record buffer.
635 //
636 mPerformanceLength += FpdtRecordPtr.RecordHeader->Length;
637 mSmmBootPerformanceTable->Header.Length += FpdtRecordPtr.RecordHeader->Length;
638
639 return EFI_SUCCESS;
640 }
641
642 /**
643 Adds a record at the end of the performance measurement log
644 that records the start time of a performance measurement.
645
646 Adds a record to the end of the performance measurement log
647 that contains the Handle, Token, Module and Identifier.
648 The end time of the new record must be set to zero.
649 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
650 If TimeStamp is zero, the start time in the record is filled in with the value
651 read from the current time stamp.
652
653 @param Handle Pointer to environment specific context used
654 to identify the component being measured.
655 @param Token Pointer to a Null-terminated ASCII string
656 that identifies the component being measured.
657 @param Module Pointer to a Null-terminated ASCII string
658 that identifies the module being measured.
659 @param TimeStamp 64-bit time stamp.
660 @param Identifier 32-bit identifier. If the value is 0, the created record
661 is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.
662
663 @retval EFI_SUCCESS The data was read correctly from the device.
664 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.
665
666 **/
667 EFI_STATUS
668 EFIAPI
669 StartGaugeEx (
670 IN CONST VOID *Handle, OPTIONAL
671 IN CONST CHAR8 *Token, OPTIONAL
672 IN CONST CHAR8 *Module, OPTIONAL
673 IN UINT64 TimeStamp,
674 IN UINT32 Identifier
675 )
676 {
677 EFI_STATUS Status;
678
679 AcquireSpinLock (&mSmmFpdtLock);
680
681 Status = InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);
682
683 ReleaseSpinLock (&mSmmFpdtLock);
684
685 return Status;
686 }
687
688 /**
689 Searches the performance measurement log from the beginning of the log
690 for the first matching record that contains a zero end time and fills in a valid end time.
691
692 Searches the performance measurement log from the beginning of the log
693 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
694 If the record can not be found then return EFI_NOT_FOUND.
695 If the record is found and TimeStamp is not zero,
696 then the end time in the record is filled in with the value specified by TimeStamp.
697 If the record is found and TimeStamp is zero, then the end time in the matching record
698 is filled in with the current time stamp value.
699
700 @param Handle Pointer to environment specific context used
701 to identify the component being measured.
702 @param Token Pointer to a Null-terminated ASCII string
703 that identifies the component being measured.
704 @param Module Pointer to a Null-terminated ASCII string
705 that identifies the module being measured.
706 @param TimeStamp 64-bit time stamp.
707 @param Identifier 32-bit identifier. If the value is 0, the found record
708 is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.
709
710 @retval EFI_SUCCESS The end of the measurement was recorded.
711 @retval EFI_NOT_FOUND The specified measurement record could not be found.
712
713 **/
714 EFI_STATUS
715 EFIAPI
716 EndGaugeEx (
717 IN CONST VOID *Handle, OPTIONAL
718 IN CONST CHAR8 *Token, OPTIONAL
719 IN CONST CHAR8 *Module, OPTIONAL
720 IN UINT64 TimeStamp,
721 IN UINT32 Identifier
722 )
723 {
724 EFI_STATUS Status;
725
726 AcquireSpinLock (&mSmmFpdtLock);
727
728 Status = InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);
729
730 ReleaseSpinLock (&mSmmFpdtLock);
731
732 return Status;
733 }
734
735 /**
736 Retrieves a previously logged performance measurement.
737 It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,
738 and then assign the Identifier with 0.
739
740 !!! Not Support!!!
741
742 Retrieves the performance log entry from the performance log specified by LogEntryKey.
743 If it stands for a valid entry, then EFI_SUCCESS is returned and
744 GaugeDataEntryEx stores the pointer to that entry.
745
746 @param LogEntryKey The key for the previous performance measurement log entry.
747 If 0, then the first performance measurement log entry is retrieved.
748 @param GaugeDataEntryEx The indirect pointer to the extended gauge data entry specified by LogEntryKey
749 if the retrieval is successful.
750
751 @retval EFI_SUCCESS The GuageDataEntryEx is successfully found based on LogEntryKey.
752 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).
753 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).
754 @retval EFI_INVALIDE_PARAMETER GaugeDataEntryEx is NULL.
755
756 **/
757 EFI_STATUS
758 EFIAPI
759 GetGaugeEx (
760 IN UINTN LogEntryKey,
761 OUT GAUGE_DATA_ENTRY_EX **GaugeDataEntryEx
762 )
763 {
764 return EFI_UNSUPPORTED;
765 }
766
767 /**
768 Adds a record at the end of the performance measurement log
769 that records the start time of a performance measurement.
770
771 Adds a record to the end of the performance measurement log
772 that contains the Handle, Token, and Module.
773 The end time of the new record must be set to zero.
774 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
775 If TimeStamp is zero, the start time in the record is filled in with the value
776 read from the current time stamp.
777
778 @param Handle Pointer to environment specific context used
779 to identify the component being measured.
780 @param Token Pointer to a Null-terminated ASCII string
781 that identifies the component being measured.
782 @param Module Pointer to a Null-terminated ASCII string
783 that identifies the module being measured.
784 @param TimeStamp 64-bit time stamp.
785
786 @retval EFI_SUCCESS The data was read correctly from the device.
787 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.
788
789 **/
790 EFI_STATUS
791 EFIAPI
792 StartGauge (
793 IN CONST VOID *Handle, OPTIONAL
794 IN CONST CHAR8 *Token, OPTIONAL
795 IN CONST CHAR8 *Module, OPTIONAL
796 IN UINT64 TimeStamp
797 )
798 {
799 return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);
800 }
801
802 /**
803 Searches the performance measurement log from the beginning of the log
804 for the first matching record that contains a zero end time and fills in a valid end time.
805
806 Searches the performance measurement log from the beginning of the log
807 for the first record that matches Handle, Token, and Module and has an end time value of zero.
808 If the record can not be found then return EFI_NOT_FOUND.
809 If the record is found and TimeStamp is not zero,
810 then the end time in the record is filled in with the value specified by TimeStamp.
811 If the record is found and TimeStamp is zero, then the end time in the matching record
812 is filled in with the current time stamp value.
813
814 @param Handle Pointer to environment specific context used
815 to identify the component being measured.
816 @param Token Pointer to a Null-terminated ASCII string
817 that identifies the component being measured.
818 @param Module Pointer to a Null-terminated ASCII string
819 that identifies the module being measured.
820 @param TimeStamp 64-bit time stamp.
821
822 @retval EFI_SUCCESS The end of the measurement was recorded.
823 @retval EFI_NOT_FOUND The specified measurement record could not be found.
824
825 **/
826 EFI_STATUS
827 EFIAPI
828 EndGauge (
829 IN CONST VOID *Handle, OPTIONAL
830 IN CONST CHAR8 *Token, OPTIONAL
831 IN CONST CHAR8 *Module, OPTIONAL
832 IN UINT64 TimeStamp
833 )
834 {
835 return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);
836 }
837
838 /**
839 Retrieves a previously logged performance measurement.
840 It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,
841 and then eliminate the Identifier.
842
843 !!! Not Support!!!
844
845 Retrieves the performance log entry from the performance log specified by LogEntryKey.
846 If it stands for a valid entry, then EFI_SUCCESS is returned and
847 GaugeDataEntry stores the pointer to that entry.
848
849 @param LogEntryKey The key for the previous performance measurement log entry.
850 If 0, then the first performance measurement log entry is retrieved.
851 @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey
852 if the retrieval is successful.
853
854 @retval EFI_SUCCESS The GuageDataEntry is successfully found based on LogEntryKey.
855 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).
856 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).
857 @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.
858
859 **/
860 EFI_STATUS
861 EFIAPI
862 GetGauge (
863 IN UINTN LogEntryKey,
864 OUT GAUGE_DATA_ENTRY **GaugeDataEntry
865 )
866 {
867 return EFI_UNSUPPORTED;
868 }
869
870
871 /**
872 SmmReadyToBoot protocol notification event handler.
873
874 @param Protocol Points to the protocol's unique identifier
875 @param Interface Points to the interface instance
876 @param Handle The handle on which the interface was installed
877
878 @retval EFI_SUCCESS SmmReadyToBootCallback runs successfully
879
880 **/
881 EFI_STATUS
882 EFIAPI
883 SmmReportFpdtRecordData (
884 IN CONST EFI_GUID *Protocol,
885 IN VOID *Interface,
886 IN EFI_HANDLE Handle
887 )
888 {
889 UINT64 SmmBPDTddr;
890
891 if (!mFpdtDataIsReported && mSmmBootPerformanceTable != NULL) {
892 SmmBPDTddr = (UINT64)(UINTN)mSmmBootPerformanceTable;
893 REPORT_STATUS_CODE_EX (
894 EFI_PROGRESS_CODE,
895 EFI_SOFTWARE_SMM_DRIVER,
896 0,
897 NULL,
898 &gEdkiiFpdtExtendedFirmwarePerformanceGuid,
899 &SmmBPDTddr,
900 sizeof (UINT64)
901 );
902 //
903 // Set FPDT report state to TRUE.
904 //
905 mFpdtDataIsReported = TRUE;
906 }
907 return EFI_SUCCESS;
908 }
909
910 /**
911 SmmBase2 protocol notify callback function, when SMST and SMM memory service get initialized
912 this function is callbacked to initialize the Smm Performance Lib
913
914 @param Event The event of notify protocol.
915 @param Context Notify event context.
916
917 **/
918 VOID
919 EFIAPI
920 InitializeSmmCorePerformanceLib (
921 IN EFI_EVENT Event,
922 IN VOID *Context
923 )
924 {
925 EFI_HANDLE Handle;
926 EFI_STATUS Status;
927 VOID *SmmReadyToBootRegistration;
928 PERFORMANCE_PROPERTY *PerformanceProperty;
929
930 //
931 // Initialize spin lock
932 //
933 InitializeSpinLock (&mSmmFpdtLock);
934
935 //
936 // Install the protocol interfaces for SMM performance library instance.
937 //
938 Handle = NULL;
939 Status = gSmst->SmmInstallProtocolInterface (
940 &Handle,
941 &gSmmPerformanceProtocolGuid,
942 EFI_NATIVE_INTERFACE,
943 &mPerformanceInterface
944 );
945 ASSERT_EFI_ERROR (Status);
946 Status = gSmst->SmmInstallProtocolInterface (
947 &Handle,
948 &gSmmPerformanceExProtocolGuid,
949 EFI_NATIVE_INTERFACE,
950 &mPerformanceExInterface
951 );
952 ASSERT_EFI_ERROR (Status);
953
954 Status = gSmst->SmmRegisterProtocolNotify (
955 &gEdkiiSmmReadyToBootProtocolGuid,
956 SmmReportFpdtRecordData,
957 &SmmReadyToBootRegistration
958 );
959 Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);
960 if (EFI_ERROR (Status)) {
961 //
962 // Install configuration table for performance property.
963 //
964 mPerformanceProperty.Revision = PERFORMANCE_PROPERTY_REVISION;
965 mPerformanceProperty.Reserved = 0;
966 mPerformanceProperty.Frequency = GetPerformanceCounterProperties (
967 &mPerformanceProperty.TimerStartValue,
968 &mPerformanceProperty.TimerEndValue
969 );
970 Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);
971 ASSERT_EFI_ERROR (Status);
972 }
973 }
974
975 /**
976 The constructor function initializes the Performance Measurement Enable flag and
977 registers SmmBase2 protocol notify callback.
978 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
979
980 @param ImageHandle The firmware allocated handle for the EFI image.
981 @param SystemTable A pointer to the EFI System Table.
982
983 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
984
985 **/
986 EFI_STATUS
987 EFIAPI
988 SmmCorePerformanceLibConstructor (
989 IN EFI_HANDLE ImageHandle,
990 IN EFI_SYSTEM_TABLE *SystemTable
991 )
992 {
993 EFI_STATUS Status;
994 EFI_EVENT Event;
995 VOID *Registration;
996
997 if (!PerformanceMeasurementEnabled ()) {
998 //
999 // Do not initialize performance infrastructure if not required.
1000 //
1001 return EFI_SUCCESS;
1002 }
1003
1004 //
1005 // Create the events to do the library init.
1006 //
1007 Status = gBS->CreateEvent (
1008 EVT_NOTIFY_SIGNAL,
1009 TPL_CALLBACK,
1010 InitializeSmmCorePerformanceLib,
1011 NULL,
1012 &Event
1013 );
1014 ASSERT_EFI_ERROR (Status);
1015
1016 //
1017 // Register for protocol notifications on this event
1018 //
1019 Status = gBS->RegisterProtocolNotify (
1020 &gEfiSmmBase2ProtocolGuid,
1021 Event,
1022 &Registration
1023 );
1024
1025 ASSERT_EFI_ERROR (Status);
1026
1027 return EFI_SUCCESS;
1028 }
1029
1030 /**
1031 Adds a record at the end of the performance measurement log
1032 that records the start time of a performance measurement.
1033
1034 Adds a record to the end of the performance measurement log
1035 that contains the Handle, Token, Module and Identifier.
1036 The end time of the new record must be set to zero.
1037 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1038 If TimeStamp is zero, the start time in the record is filled in with the value
1039 read from the current time stamp.
1040
1041 @param Handle Pointer to environment specific context used
1042 to identify the component being measured.
1043 @param Token Pointer to a Null-terminated ASCII string
1044 that identifies the component being measured.
1045 @param Module Pointer to a Null-terminated ASCII string
1046 that identifies the module being measured.
1047 @param TimeStamp 64-bit time stamp.
1048 @param Identifier 32-bit identifier. If the value is 0, the created record
1049 is same as the one created by StartPerformanceMeasurement.
1050
1051 @retval RETURN_SUCCESS The start of the measurement was recorded.
1052 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1053
1054 **/
1055 RETURN_STATUS
1056 EFIAPI
1057 StartPerformanceMeasurementEx (
1058 IN CONST VOID *Handle, OPTIONAL
1059 IN CONST CHAR8 *Token, OPTIONAL
1060 IN CONST CHAR8 *Module, OPTIONAL
1061 IN UINT64 TimeStamp,
1062 IN UINT32 Identifier
1063 )
1064 {
1065 return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);
1066 }
1067
1068 /**
1069 Searches the performance measurement log from the beginning of the log
1070 for the first matching record that contains a zero end time and fills in a valid end time.
1071
1072 Searches the performance measurement log from the beginning of the log
1073 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
1074 If the record can not be found then return RETURN_NOT_FOUND.
1075 If the record is found and TimeStamp is not zero,
1076 then the end time in the record is filled in with the value specified by TimeStamp.
1077 If the record is found and TimeStamp is zero, then the end time in the matching record
1078 is filled in with the current time stamp value.
1079
1080 @param Handle Pointer to environment specific context used
1081 to identify the component being measured.
1082 @param Token Pointer to a Null-terminated ASCII string
1083 that identifies the component being measured.
1084 @param Module Pointer to a Null-terminated ASCII string
1085 that identifies the module being measured.
1086 @param TimeStamp 64-bit time stamp.
1087 @param Identifier 32-bit identifier. If the value is 0, the found record
1088 is same as the one found by EndPerformanceMeasurement.
1089
1090 @retval RETURN_SUCCESS The end of the measurement was recorded.
1091 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1092
1093 **/
1094 RETURN_STATUS
1095 EFIAPI
1096 EndPerformanceMeasurementEx (
1097 IN CONST VOID *Handle, OPTIONAL
1098 IN CONST CHAR8 *Token, OPTIONAL
1099 IN CONST CHAR8 *Module, OPTIONAL
1100 IN UINT64 TimeStamp,
1101 IN UINT32 Identifier
1102 )
1103 {
1104 return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);
1105 }
1106
1107 /**
1108 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1109 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
1110 and then assign the Identifier with 0.
1111
1112 !!! Not Support!!!
1113
1114 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1115 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1116 and the key for the second entry in the log is returned. If the performance log is empty,
1117 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1118 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1119 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1120 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1121 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1122 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1123 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
1124 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1125 If Handle is NULL, then ASSERT().
1126 If Token is NULL, then ASSERT().
1127 If Module is NULL, then ASSERT().
1128 If StartTimeStamp is NULL, then ASSERT().
1129 If EndTimeStamp is NULL, then ASSERT().
1130 If Identifier is NULL, then ASSERT().
1131
1132 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1133 0, then the first performance measurement log entry is retrieved.
1134 On exit, the key of the next performance log entry.
1135 @param Handle Pointer to environment specific context used to identify the component
1136 being measured.
1137 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1138 being measured.
1139 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1140 being measured.
1141 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1142 was started.
1143 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1144 was ended.
1145 @param Identifier Pointer to the 32-bit identifier that was recorded.
1146
1147 @return The key for the next performance log entry (in general case).
1148
1149 **/
1150 UINTN
1151 EFIAPI
1152 GetPerformanceMeasurementEx (
1153 IN UINTN LogEntryKey,
1154 OUT CONST VOID **Handle,
1155 OUT CONST CHAR8 **Token,
1156 OUT CONST CHAR8 **Module,
1157 OUT UINT64 *StartTimeStamp,
1158 OUT UINT64 *EndTimeStamp,
1159 OUT UINT32 *Identifier
1160 )
1161 {
1162 return 0;
1163 }
1164
1165 /**
1166 Adds a record at the end of the performance measurement log
1167 that records the start time of a performance measurement.
1168
1169 Adds a record to the end of the performance measurement log
1170 that contains the Handle, Token, and Module.
1171 The end time of the new record must be set to zero.
1172 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1173 If TimeStamp is zero, the start time in the record is filled in with the value
1174 read from the current time stamp.
1175
1176 @param Handle Pointer to environment specific context used
1177 to identify the component being measured.
1178 @param Token Pointer to a Null-terminated ASCII string
1179 that identifies the component being measured.
1180 @param Module Pointer to a Null-terminated ASCII string
1181 that identifies the module being measured.
1182 @param TimeStamp 64-bit time stamp.
1183
1184 @retval RETURN_SUCCESS The start of the measurement was recorded.
1185 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1186
1187 **/
1188 RETURN_STATUS
1189 EFIAPI
1190 StartPerformanceMeasurement (
1191 IN CONST VOID *Handle, OPTIONAL
1192 IN CONST CHAR8 *Token, OPTIONAL
1193 IN CONST CHAR8 *Module, OPTIONAL
1194 IN UINT64 TimeStamp
1195 )
1196 {
1197 return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);
1198 }
1199
1200 /**
1201 Searches the performance measurement log from the beginning of the log
1202 for the first matching record that contains a zero end time and fills in a valid end time.
1203
1204 Searches the performance measurement log from the beginning of the log
1205 for the first record that matches Handle, Token, and Module and has an end time value of zero.
1206 If the record can not be found then return RETURN_NOT_FOUND.
1207 If the record is found and TimeStamp is not zero,
1208 then the end time in the record is filled in with the value specified by TimeStamp.
1209 If the record is found and TimeStamp is zero, then the end time in the matching record
1210 is filled in with the current time stamp value.
1211
1212 @param Handle Pointer to environment specific context used
1213 to identify the component being measured.
1214 @param Token Pointer to a Null-terminated ASCII string
1215 that identifies the component being measured.
1216 @param Module Pointer to a Null-terminated ASCII string
1217 that identifies the module being measured.
1218 @param TimeStamp 64-bit time stamp.
1219
1220 @retval RETURN_SUCCESS The end of the measurement was recorded.
1221 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1222
1223 **/
1224 RETURN_STATUS
1225 EFIAPI
1226 EndPerformanceMeasurement (
1227 IN CONST VOID *Handle, OPTIONAL
1228 IN CONST CHAR8 *Token, OPTIONAL
1229 IN CONST CHAR8 *Module, OPTIONAL
1230 IN UINT64 TimeStamp
1231 )
1232 {
1233 return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);
1234 }
1235
1236 /**
1237 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1238 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
1239 and then eliminate the Identifier.
1240
1241 !!! Not Support!!!
1242
1243 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1244 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1245 and the key for the second entry in the log is returned. If the performance log is empty,
1246 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1247 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1248 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1249 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1250 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1251 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1252 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
1253 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1254 If Handle is NULL, then ASSERT().
1255 If Token is NULL, then ASSERT().
1256 If Module is NULL, then ASSERT().
1257 If StartTimeStamp is NULL, then ASSERT().
1258 If EndTimeStamp is NULL, then ASSERT().
1259
1260 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1261 0, then the first performance measurement log entry is retrieved.
1262 On exit, the key of the next performance log entry.
1263 @param Handle Pointer to environment specific context used to identify the component
1264 being measured.
1265 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1266 being measured.
1267 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1268 being measured.
1269 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1270 was started.
1271 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1272 was ended.
1273
1274 @return The key for the next performance log entry (in general case).
1275
1276 **/
1277 UINTN
1278 EFIAPI
1279 GetPerformanceMeasurement (
1280 IN UINTN LogEntryKey,
1281 OUT CONST VOID **Handle,
1282 OUT CONST CHAR8 **Token,
1283 OUT CONST CHAR8 **Module,
1284 OUT UINT64 *StartTimeStamp,
1285 OUT UINT64 *EndTimeStamp
1286 )
1287 {
1288 return 0;
1289 }
1290
1291 /**
1292 Returns TRUE if the performance measurement macros are enabled.
1293
1294 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1295 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
1296
1297 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1298 PcdPerformanceLibraryPropertyMask is set.
1299 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1300 PcdPerformanceLibraryPropertyMask is clear.
1301
1302 **/
1303 BOOLEAN
1304 EFIAPI
1305 PerformanceMeasurementEnabled (
1306 VOID
1307 )
1308 {
1309 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
1310 }