]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: BootMaintenanceManagerUiLib: remove set but unused variables
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
1 /** @file
2 Performance library instance mainly used by DxeCore.
3
4 This library provides the performance measurement interfaces and initializes performance
5 logging for DXE phase. It first initializes its private global data structure for
6 performance logging and saves the performance GUIDed HOB passed from PEI phase.
7 It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,
8 which are consumed by DxePerformanceLib to logging performance data in DXE phase.
9
10 This library is mainly used by DxeCore to start performance logging to ensure that
11 Performance Protocol is installed at the very beginning of DXE phase.
12
13 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
14 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
15 This program and the accompanying materials
16 are licensed and made available under the terms and conditions of the BSD License
17 which accompanies this distribution. The full text of the license may be found at
18 http://opensource.org/licenses/bsd-license.php
19
20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
21 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22
23 **/
24
25
26 #include "DxeCorePerformanceLibInternal.h"
27
28
29 //
30 // The data structure to hold global performance data.
31 //
32 GAUGE_DATA_HEADER *mGaugeData;
33
34 //
35 // The current maximum number of logging entries. If current number of
36 // entries exceeds this value, it will re-allocate a larger array and
37 // migration the old data to the larger array.
38 //
39 UINT32 mMaxGaugeRecords;
40
41 //
42 // The handle to install Performance Protocol instance.
43 //
44 EFI_HANDLE mHandle = NULL;
45
46 //
47 // Interfaces for Performance Protocol.
48 //
49 PERFORMANCE_PROTOCOL mPerformanceInterface = {
50 StartGauge,
51 EndGauge,
52 GetGauge
53 };
54
55 //
56 // Interfaces for PerformanceEx Protocol.
57 //
58 PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {
59 StartGaugeEx,
60 EndGaugeEx,
61 GetGaugeEx
62 };
63
64 /**
65 Searches in the gauge array with keyword Handle, Token, Module and Identifier.
66
67 This internal function searches for the gauge entry in the gauge array.
68 If there is an entry that exactly matches the given keywords
69 and its end time stamp is zero, then the index of that gauge entry is returned;
70 otherwise, the the number of gauge entries in the array is returned.
71
72 @param Handle Pointer to environment specific context used
73 to identify the component being measured.
74 @param Token Pointer to a Null-terminated ASCII string
75 that identifies the component being measured.
76 @param Module Pointer to a Null-terminated ASCII string
77 that identifies the module being measured.
78 @param Identifier 32-bit identifier.
79
80 @retval The index of gauge entry in the array.
81
82 **/
83 UINT32
84 InternalSearchForGaugeEntry (
85 IN CONST VOID *Handle, OPTIONAL
86 IN CONST CHAR8 *Token, OPTIONAL
87 IN CONST CHAR8 *Module, OPTIONAL
88 IN UINT32 Identifier
89 )
90 {
91 UINT32 Index;
92 UINT32 Index2;
93 UINT32 NumberOfEntries;
94 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;
95
96 if (Token == NULL) {
97 Token = "";
98 }
99 if (Module == NULL) {
100 Module = "";
101 }
102
103 NumberOfEntries = mGaugeData->NumberOfEntries;
104 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);
105
106 Index2 = 0;
107
108 for (Index = 0; Index < NumberOfEntries; Index++) {
109 Index2 = NumberOfEntries - 1 - Index;
110 if (GaugeEntryExArray[Index2].EndTimeStamp == 0 &&
111 (GaugeEntryExArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&
112 AsciiStrnCmp (GaugeEntryExArray[Index2].Token, Token, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&
113 AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&
114 (GaugeEntryExArray[Index2].Identifier == Identifier)) {
115 Index = Index2;
116 break;
117 }
118 }
119
120 return Index;
121 }
122
123 /**
124 Adds a record at the end of the performance measurement log
125 that records the start time of a performance measurement.
126
127 Adds a record to the end of the performance measurement log
128 that contains the Handle, Token, Module and Identifier.
129 The end time of the new record must be set to zero.
130 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
131 If TimeStamp is zero, the start time in the record is filled in with the value
132 read from the current time stamp.
133
134 @param Handle Pointer to environment specific context used
135 to identify the component being measured.
136 @param Token Pointer to a Null-terminated ASCII string
137 that identifies the component being measured.
138 @param Module Pointer to a Null-terminated ASCII string
139 that identifies the module being measured.
140 @param TimeStamp 64-bit time stamp.
141 @param Identifier 32-bit identifier. If the value is 0, the created record
142 is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.
143
144 @retval EFI_SUCCESS The data was read correctly from the device.
145 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 StartGaugeEx (
151 IN CONST VOID *Handle, OPTIONAL
152 IN CONST CHAR8 *Token, OPTIONAL
153 IN CONST CHAR8 *Module, OPTIONAL
154 IN UINT64 TimeStamp,
155 IN UINT32 Identifier
156 )
157 {
158 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;
159 UINTN GaugeDataSize;
160 GAUGE_DATA_HEADER *NewGaugeData;
161 UINTN OldGaugeDataSize;
162 GAUGE_DATA_HEADER *OldGaugeData;
163 UINT32 Index;
164
165 Index = mGaugeData->NumberOfEntries;
166 if (Index >= mMaxGaugeRecords) {
167 //
168 // Try to enlarge the scale of gauge array.
169 //
170 OldGaugeData = mGaugeData;
171 OldGaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords;
172
173 GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords * 2;
174
175 NewGaugeData = AllocateZeroPool (GaugeDataSize);
176 if (NewGaugeData == NULL) {
177 return EFI_OUT_OF_RESOURCES;
178 }
179
180 mGaugeData = NewGaugeData;
181 mMaxGaugeRecords *= 2;
182
183 //
184 // Initialize new data array and migrate old data one.
185 //
186 mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);
187
188 FreePool (OldGaugeData);
189 }
190
191 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);
192 GaugeEntryExArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;
193
194 if (Token != NULL) {
195 AsciiStrnCpyS (GaugeEntryExArray[Index].Token, DXE_PERFORMANCE_STRING_SIZE, Token, DXE_PERFORMANCE_STRING_LENGTH);
196 }
197 if (Module != NULL) {
198 AsciiStrnCpyS (GaugeEntryExArray[Index].Module, DXE_PERFORMANCE_STRING_SIZE, Module, DXE_PERFORMANCE_STRING_LENGTH);
199 }
200
201 GaugeEntryExArray[Index].EndTimeStamp = 0;
202 GaugeEntryExArray[Index].Identifier = Identifier;
203
204 if (TimeStamp == 0) {
205 TimeStamp = GetPerformanceCounter ();
206 }
207 GaugeEntryExArray[Index].StartTimeStamp = TimeStamp;
208
209 mGaugeData->NumberOfEntries++;
210
211 return EFI_SUCCESS;
212 }
213
214 /**
215 Searches the performance measurement log from the beginning of the log
216 for the first matching record that contains a zero end time and fills in a valid end time.
217
218 Searches the performance measurement log from the beginning of the log
219 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
220 If the record can not be found then return EFI_NOT_FOUND.
221 If the record is found and TimeStamp is not zero,
222 then the end time in the record is filled in with the value specified by TimeStamp.
223 If the record is found and TimeStamp is zero, then the end time in the matching record
224 is filled in with the current time stamp value.
225
226 @param Handle Pointer to environment specific context used
227 to identify the component being measured.
228 @param Token Pointer to a Null-terminated ASCII string
229 that identifies the component being measured.
230 @param Module Pointer to a Null-terminated ASCII string
231 that identifies the module being measured.
232 @param TimeStamp 64-bit time stamp.
233 @param Identifier 32-bit identifier. If the value is 0, the found record
234 is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.
235
236 @retval EFI_SUCCESS The end of the measurement was recorded.
237 @retval EFI_NOT_FOUND The specified measurement record could not be found.
238
239 **/
240 EFI_STATUS
241 EFIAPI
242 EndGaugeEx (
243 IN CONST VOID *Handle, OPTIONAL
244 IN CONST CHAR8 *Token, OPTIONAL
245 IN CONST CHAR8 *Module, OPTIONAL
246 IN UINT64 TimeStamp,
247 IN UINT32 Identifier
248 )
249 {
250 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;
251 UINT32 Index;
252
253 if (TimeStamp == 0) {
254 TimeStamp = GetPerformanceCounter ();
255 }
256
257 Index = InternalSearchForGaugeEntry (Handle, Token, Module, Identifier);
258 if (Index >= mGaugeData->NumberOfEntries) {
259 return EFI_NOT_FOUND;
260 }
261 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);
262 GaugeEntryExArray[Index].EndTimeStamp = TimeStamp;
263
264 return EFI_SUCCESS;
265 }
266
267 /**
268 Retrieves a previously logged performance measurement.
269 It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,
270 and then assign the Identifier with 0.
271
272 Retrieves the performance log entry from the performance log specified by LogEntryKey.
273 If it stands for a valid entry, then EFI_SUCCESS is returned and
274 GaugeDataEntryEx stores the pointer to that entry.
275
276 @param LogEntryKey The key for the previous performance measurement log entry.
277 If 0, then the first performance measurement log entry is retrieved.
278 @param GaugeDataEntryEx The indirect pointer to the extended gauge data entry specified by LogEntryKey
279 if the retrieval is successful.
280
281 @retval EFI_SUCCESS The GuageDataEntryEx is successfully found based on LogEntryKey.
282 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).
283 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).
284 @retval EFI_INVALIDE_PARAMETER GaugeDataEntryEx is NULL.
285
286 **/
287 EFI_STATUS
288 EFIAPI
289 GetGaugeEx (
290 IN UINTN LogEntryKey,
291 OUT GAUGE_DATA_ENTRY_EX **GaugeDataEntryEx
292 )
293 {
294 UINTN NumberOfEntries;
295 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;
296
297 NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);
298 if (LogEntryKey > NumberOfEntries) {
299 return EFI_INVALID_PARAMETER;
300 }
301 if (LogEntryKey == NumberOfEntries) {
302 return EFI_NOT_FOUND;
303 }
304
305 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);
306
307 if (GaugeDataEntryEx == NULL) {
308 return EFI_INVALID_PARAMETER;
309 }
310 *GaugeDataEntryEx = &GaugeEntryExArray[LogEntryKey];
311
312 return EFI_SUCCESS;
313 }
314
315 /**
316 Adds a record at the end of the performance measurement log
317 that records the start time of a performance measurement.
318
319 Adds a record to the end of the performance measurement log
320 that contains the Handle, Token, and Module.
321 The end time of the new record must be set to zero.
322 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
323 If TimeStamp is zero, the start time in the record is filled in with the value
324 read from the current time stamp.
325
326 @param Handle Pointer to environment specific context used
327 to identify the component being measured.
328 @param Token Pointer to a Null-terminated ASCII string
329 that identifies the component being measured.
330 @param Module Pointer to a Null-terminated ASCII string
331 that identifies the module being measured.
332 @param TimeStamp 64-bit time stamp.
333
334 @retval EFI_SUCCESS The data was read correctly from the device.
335 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.
336
337 **/
338 EFI_STATUS
339 EFIAPI
340 StartGauge (
341 IN CONST VOID *Handle, OPTIONAL
342 IN CONST CHAR8 *Token, OPTIONAL
343 IN CONST CHAR8 *Module, OPTIONAL
344 IN UINT64 TimeStamp
345 )
346 {
347 return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);
348 }
349
350 /**
351 Searches the performance measurement log from the beginning of the log
352 for the first matching record that contains a zero end time and fills in a valid end time.
353
354 Searches the performance measurement log from the beginning of the log
355 for the first record that matches Handle, Token, and Module and has an end time value of zero.
356 If the record can not be found then return EFI_NOT_FOUND.
357 If the record is found and TimeStamp is not zero,
358 then the end time in the record is filled in with the value specified by TimeStamp.
359 If the record is found and TimeStamp is zero, then the end time in the matching record
360 is filled in with the current time stamp value.
361
362 @param Handle Pointer to environment specific context used
363 to identify the component being measured.
364 @param Token Pointer to a Null-terminated ASCII string
365 that identifies the component being measured.
366 @param Module Pointer to a Null-terminated ASCII string
367 that identifies the module being measured.
368 @param TimeStamp 64-bit time stamp.
369
370 @retval EFI_SUCCESS The end of the measurement was recorded.
371 @retval EFI_NOT_FOUND The specified measurement record could not be found.
372
373 **/
374 EFI_STATUS
375 EFIAPI
376 EndGauge (
377 IN CONST VOID *Handle, OPTIONAL
378 IN CONST CHAR8 *Token, OPTIONAL
379 IN CONST CHAR8 *Module, OPTIONAL
380 IN UINT64 TimeStamp
381 )
382 {
383 return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);
384 }
385
386 /**
387 Retrieves a previously logged performance measurement.
388 It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,
389 and then eliminate the Identifier.
390
391 Retrieves the performance log entry from the performance log specified by LogEntryKey.
392 If it stands for a valid entry, then EFI_SUCCESS is returned and
393 GaugeDataEntry stores the pointer to that entry.
394
395 @param LogEntryKey The key for the previous performance measurement log entry.
396 If 0, then the first performance measurement log entry is retrieved.
397 @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey
398 if the retrieval is successful.
399
400 @retval EFI_SUCCESS The GuageDataEntry is successfully found based on LogEntryKey.
401 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).
402 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).
403 @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.
404
405 **/
406 EFI_STATUS
407 EFIAPI
408 GetGauge (
409 IN UINTN LogEntryKey,
410 OUT GAUGE_DATA_ENTRY **GaugeDataEntry
411 )
412 {
413 EFI_STATUS Status;
414 GAUGE_DATA_ENTRY_EX *GaugeEntryEx;
415
416 GaugeEntryEx = NULL;
417
418 Status = GetGaugeEx (LogEntryKey, &GaugeEntryEx);
419 if (EFI_ERROR (Status)) {
420 return Status;
421 }
422
423 if (GaugeDataEntry == NULL) {
424 return EFI_INVALID_PARAMETER;
425 }
426
427 *GaugeDataEntry = (GAUGE_DATA_ENTRY *) GaugeEntryEx;
428
429 return EFI_SUCCESS;
430 }
431
432 /**
433 Dumps all the PEI performance log to DXE performance gauge array.
434
435 This internal function dumps all the PEI performance log to the DXE performance gauge array.
436 It retrieves the optional GUID HOB for PEI performance and then saves the performance data
437 to DXE performance data structures.
438
439 **/
440 VOID
441 InternalGetPeiPerformance (
442 VOID
443 )
444 {
445 EFI_HOB_GUID_TYPE *GuidHob;
446 PEI_PERFORMANCE_LOG_HEADER *LogHob;
447 PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;
448 UINT32 *LogIdArray;
449 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;
450 UINT32 Index;
451 UINT32 NumberOfEntries;
452
453 NumberOfEntries = 0;
454 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);
455
456 //
457 // Dump PEI Log Entries to DXE Guage Data structure.
458 //
459 GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);
460 if (GuidHob != NULL) {
461 LogHob = GET_GUID_HOB_DATA (GuidHob);
462 LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (LogHob + 1);
463
464 NumberOfEntries = LogHob->NumberOfEntries;
465 for (Index = 0; Index < NumberOfEntries; Index++) {
466 GaugeEntryExArray[Index].Handle = LogEntryArray[Index].Handle;
467 AsciiStrCpyS (GaugeEntryExArray[Index].Token, DXE_PERFORMANCE_STRING_SIZE, LogEntryArray[Index].Token);
468 AsciiStrCpyS (GaugeEntryExArray[Index].Module, DXE_PERFORMANCE_STRING_SIZE, LogEntryArray[Index].Module);
469 GaugeEntryExArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;
470 GaugeEntryExArray[Index].EndTimeStamp = LogEntryArray[Index].EndTimeStamp;
471 GaugeEntryExArray[Index].Identifier = 0;
472 }
473
474 GuidHob = GetFirstGuidHob (&gPerformanceExProtocolGuid);
475 if (GuidHob != NULL) {
476 LogIdArray = GET_GUID_HOB_DATA (GuidHob);
477 for (Index = 0; Index < NumberOfEntries; Index++) {
478 GaugeEntryExArray[Index].Identifier = LogIdArray[Index];
479 }
480 }
481 }
482 mGaugeData->NumberOfEntries = NumberOfEntries;
483 }
484
485 /**
486 The constructor function initializes Performance infrastructure for DXE phase.
487
488 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance
489 and merges PEI performance data to DXE performance log.
490 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
491
492 @param ImageHandle The firmware allocated handle for the EFI image.
493 @param SystemTable A pointer to the EFI System Table.
494
495 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
496
497 **/
498 EFI_STATUS
499 EFIAPI
500 DxeCorePerformanceLibConstructor (
501 IN EFI_HANDLE ImageHandle,
502 IN EFI_SYSTEM_TABLE *SystemTable
503 )
504 {
505 EFI_STATUS Status;
506
507 if (!PerformanceMeasurementEnabled ()) {
508 //
509 // Do not initialize performance infrastructure if not required.
510 //
511 return EFI_SUCCESS;
512 }
513 //
514 // Install the protocol interfaces.
515 //
516 Status = gBS->InstallMultipleProtocolInterfaces (
517 &mHandle,
518 &gPerformanceProtocolGuid,
519 &mPerformanceInterface,
520 &gPerformanceExProtocolGuid,
521 &mPerformanceExInterface,
522 NULL
523 );
524 ASSERT_EFI_ERROR (Status);
525
526 mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?
527 PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :
528 PcdGet8 (PcdMaxPeiPerformanceLogEntries));
529
530 mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));
531 ASSERT (mGaugeData != NULL);
532
533 InternalGetPeiPerformance ();
534
535 return Status;
536 }
537
538 /**
539 Adds a record at the end of the performance measurement log
540 that records the start time of a performance measurement.
541
542 Adds a record to the end of the performance measurement log
543 that contains the Handle, Token, Module and Identifier.
544 The end time of the new record must be set to zero.
545 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
546 If TimeStamp is zero, the start time in the record is filled in with the value
547 read from the current time stamp.
548
549 @param Handle Pointer to environment specific context used
550 to identify the component being measured.
551 @param Token Pointer to a Null-terminated ASCII string
552 that identifies the component being measured.
553 @param Module Pointer to a Null-terminated ASCII string
554 that identifies the module being measured.
555 @param TimeStamp 64-bit time stamp.
556 @param Identifier 32-bit identifier. If the value is 0, the created record
557 is same as the one created by StartPerformanceMeasurement.
558
559 @retval RETURN_SUCCESS The start of the measurement was recorded.
560 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
561
562 **/
563 RETURN_STATUS
564 EFIAPI
565 StartPerformanceMeasurementEx (
566 IN CONST VOID *Handle, OPTIONAL
567 IN CONST CHAR8 *Token, OPTIONAL
568 IN CONST CHAR8 *Module, OPTIONAL
569 IN UINT64 TimeStamp,
570 IN UINT32 Identifier
571 )
572 {
573 return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);
574 }
575
576 /**
577 Searches the performance measurement log from the beginning of the log
578 for the first matching record that contains a zero end time and fills in a valid end time.
579
580 Searches the performance measurement log from the beginning of the log
581 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
582 If the record can not be found then return RETURN_NOT_FOUND.
583 If the record is found and TimeStamp is not zero,
584 then the end time in the record is filled in with the value specified by TimeStamp.
585 If the record is found and TimeStamp is zero, then the end time in the matching record
586 is filled in with the current time stamp value.
587
588 @param Handle Pointer to environment specific context used
589 to identify the component being measured.
590 @param Token Pointer to a Null-terminated ASCII string
591 that identifies the component being measured.
592 @param Module Pointer to a Null-terminated ASCII string
593 that identifies the module being measured.
594 @param TimeStamp 64-bit time stamp.
595 @param Identifier 32-bit identifier. If the value is 0, the found record
596 is same as the one found by EndPerformanceMeasurement.
597
598 @retval RETURN_SUCCESS The end of the measurement was recorded.
599 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
600
601 **/
602 RETURN_STATUS
603 EFIAPI
604 EndPerformanceMeasurementEx (
605 IN CONST VOID *Handle, OPTIONAL
606 IN CONST CHAR8 *Token, OPTIONAL
607 IN CONST CHAR8 *Module, OPTIONAL
608 IN UINT64 TimeStamp,
609 IN UINT32 Identifier
610 )
611 {
612 return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);
613 }
614
615 /**
616 Attempts to retrieve a performance measurement log entry from the performance measurement log.
617 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
618 and then assign the Identifier with 0.
619
620 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
621 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
622 and the key for the second entry in the log is returned. If the performance log is empty,
623 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
624 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
625 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
626 retrieved and an implementation specific non-zero key value that specifies the end of the performance
627 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
628 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
629 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
630 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
631 If Handle is NULL, then ASSERT().
632 If Token is NULL, then ASSERT().
633 If Module is NULL, then ASSERT().
634 If StartTimeStamp is NULL, then ASSERT().
635 If EndTimeStamp is NULL, then ASSERT().
636 If Identifier is NULL, then ASSERT().
637
638 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
639 0, then the first performance measurement log entry is retrieved.
640 On exit, the key of the next performance log entry.
641 @param Handle Pointer to environment specific context used to identify the component
642 being measured.
643 @param Token Pointer to a Null-terminated ASCII string that identifies the component
644 being measured.
645 @param Module Pointer to a Null-terminated ASCII string that identifies the module
646 being measured.
647 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
648 was started.
649 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
650 was ended.
651 @param Identifier Pointer to the 32-bit identifier that was recorded.
652
653 @return The key for the next performance log entry (in general case).
654
655 **/
656 UINTN
657 EFIAPI
658 GetPerformanceMeasurementEx (
659 IN UINTN LogEntryKey,
660 OUT CONST VOID **Handle,
661 OUT CONST CHAR8 **Token,
662 OUT CONST CHAR8 **Module,
663 OUT UINT64 *StartTimeStamp,
664 OUT UINT64 *EndTimeStamp,
665 OUT UINT32 *Identifier
666 )
667 {
668 EFI_STATUS Status;
669 GAUGE_DATA_ENTRY_EX *GaugeData;
670
671 GaugeData = NULL;
672
673 ASSERT (Handle != NULL);
674 ASSERT (Token != NULL);
675 ASSERT (Module != NULL);
676 ASSERT (StartTimeStamp != NULL);
677 ASSERT (EndTimeStamp != NULL);
678 ASSERT (Identifier != NULL);
679
680 Status = GetGaugeEx (LogEntryKey++, &GaugeData);
681
682 //
683 // Make sure that LogEntryKey is a valid log entry key,
684 //
685 ASSERT (Status != EFI_INVALID_PARAMETER);
686
687 if (EFI_ERROR (Status)) {
688 //
689 // The LogEntryKey is the last entry (equals to the total entry number).
690 //
691 return 0;
692 }
693
694 ASSERT (GaugeData != NULL);
695
696 *Handle = (VOID *) (UINTN) GaugeData->Handle;
697 *Token = GaugeData->Token;
698 *Module = GaugeData->Module;
699 *StartTimeStamp = GaugeData->StartTimeStamp;
700 *EndTimeStamp = GaugeData->EndTimeStamp;
701 *Identifier = GaugeData->Identifier;
702
703 return LogEntryKey;
704 }
705
706 /**
707 Adds a record at the end of the performance measurement log
708 that records the start time of a performance measurement.
709
710 Adds a record to the end of the performance measurement log
711 that contains the Handle, Token, and Module.
712 The end time of the new record must be set to zero.
713 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
714 If TimeStamp is zero, the start time in the record is filled in with the value
715 read from the current time stamp.
716
717 @param Handle Pointer to environment specific context used
718 to identify the component being measured.
719 @param Token Pointer to a Null-terminated ASCII string
720 that identifies the component being measured.
721 @param Module Pointer to a Null-terminated ASCII string
722 that identifies the module being measured.
723 @param TimeStamp 64-bit time stamp.
724
725 @retval RETURN_SUCCESS The start of the measurement was recorded.
726 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
727
728 **/
729 RETURN_STATUS
730 EFIAPI
731 StartPerformanceMeasurement (
732 IN CONST VOID *Handle, OPTIONAL
733 IN CONST CHAR8 *Token, OPTIONAL
734 IN CONST CHAR8 *Module, OPTIONAL
735 IN UINT64 TimeStamp
736 )
737 {
738 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
739 }
740
741 /**
742 Searches the performance measurement log from the beginning of the log
743 for the first matching record that contains a zero end time and fills in a valid end time.
744
745 Searches the performance measurement log from the beginning of the log
746 for the first record that matches Handle, Token, and Module and has an end time value of zero.
747 If the record can not be found then return RETURN_NOT_FOUND.
748 If the record is found and TimeStamp is not zero,
749 then the end time in the record is filled in with the value specified by TimeStamp.
750 If the record is found and TimeStamp is zero, then the end time in the matching record
751 is filled in with the current time stamp value.
752
753 @param Handle Pointer to environment specific context used
754 to identify the component being measured.
755 @param Token Pointer to a Null-terminated ASCII string
756 that identifies the component being measured.
757 @param Module Pointer to a Null-terminated ASCII string
758 that identifies the module being measured.
759 @param TimeStamp 64-bit time stamp.
760
761 @retval RETURN_SUCCESS The end of the measurement was recorded.
762 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
763
764 **/
765 RETURN_STATUS
766 EFIAPI
767 EndPerformanceMeasurement (
768 IN CONST VOID *Handle, OPTIONAL
769 IN CONST CHAR8 *Token, OPTIONAL
770 IN CONST CHAR8 *Module, OPTIONAL
771 IN UINT64 TimeStamp
772 )
773 {
774 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
775 }
776
777 /**
778 Attempts to retrieve a performance measurement log entry from the performance measurement log.
779 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
780 and then eliminate the Identifier.
781
782 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
783 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
784 and the key for the second entry in the log is returned. If the performance log is empty,
785 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
786 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
787 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
788 retrieved and an implementation specific non-zero key value that specifies the end of the performance
789 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
790 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
791 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
792 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
793 If Handle is NULL, then ASSERT().
794 If Token is NULL, then ASSERT().
795 If Module is NULL, then ASSERT().
796 If StartTimeStamp is NULL, then ASSERT().
797 If EndTimeStamp is NULL, then ASSERT().
798
799 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
800 0, then the first performance measurement log entry is retrieved.
801 On exit, the key of the next performance log entry.
802 @param Handle Pointer to environment specific context used to identify the component
803 being measured.
804 @param Token Pointer to a Null-terminated ASCII string that identifies the component
805 being measured.
806 @param Module Pointer to a Null-terminated ASCII string that identifies the module
807 being measured.
808 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
809 was started.
810 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
811 was ended.
812
813 @return The key for the next performance log entry (in general case).
814
815 **/
816 UINTN
817 EFIAPI
818 GetPerformanceMeasurement (
819 IN UINTN LogEntryKey,
820 OUT CONST VOID **Handle,
821 OUT CONST CHAR8 **Token,
822 OUT CONST CHAR8 **Module,
823 OUT UINT64 *StartTimeStamp,
824 OUT UINT64 *EndTimeStamp
825 )
826 {
827 UINT32 Identifier;
828 return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);
829 }
830
831 /**
832 Returns TRUE if the performance measurement macros are enabled.
833
834 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
835 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
836
837 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
838 PcdPerformanceLibraryPropertyMask is set.
839 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
840 PcdPerformanceLibraryPropertyMask is clear.
841
842 **/
843 BOOLEAN
844 EFIAPI
845 PerformanceMeasurementEnabled (
846 VOID
847 )
848 {
849 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
850 }