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