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