TianoCore EDK2 master
Loading...
Searching...
No Matches
SmmPerformanceLib.c
Go to the documentation of this file.
1
15
17#include <Library/DebugLib.h>
19#include <Library/PcdLib.h>
21
22//
23// The cached SMM Performance Protocol and SMM PerformanceEx Protocol interface.
24EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL *mPerformanceMeasurement = NULL;
25BOOLEAN mPerformanceMeasurementEnabled;
26VOID *mPerformanceLibExitBootServicesRegistration;
27
39EFIAPI
41 IN CONST EFI_GUID *Protocol,
42 IN VOID *Interface,
43 IN EFI_HANDLE Handle
44 )
45{
46 //
47 // Disable performance measurement after ExitBootServices because
48 // 1. Performance measurement might impact SMI latency at runtime;
49 // 2. Performance log is copied to non SMRAM at ReadyToBoot so runtime performance
50 // log is not useful.
51 //
52 mPerformanceMeasurementEnabled = FALSE;
53
54 return EFI_SUCCESS;
55}
56
67EFIAPI
69 IN EFI_HANDLE ImageHandle,
70 IN EFI_SYSTEM_TABLE *SystemTable
71 )
72{
73 EFI_STATUS Status;
74
75 mPerformanceMeasurementEnabled = (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
76
77 Status = gSmst->SmmRegisterProtocolNotify (
78 &gEdkiiSmmExitBootServicesProtocolGuid,
80 &mPerformanceLibExitBootServicesRegistration
81 );
82 ASSERT_EFI_ERROR (Status);
83
84 return Status;
85}
86
96EFIAPI
98 IN EFI_HANDLE ImageHandle,
99 IN EFI_SYSTEM_TABLE *SystemTable
100 )
101{
102 EFI_STATUS Status;
103
104 //
105 // Unregister SmmExitBootServices notification.
106 //
107 Status = gSmst->SmmRegisterProtocolNotify (
108 &gEdkiiSmmExitBootServicesProtocolGuid,
109 NULL,
110 &mPerformanceLibExitBootServicesRegistration
111 );
112 ASSERT_EFI_ERROR (Status);
113
114 return Status;
115}
116
128 VOID
129 )
130{
131 EFI_STATUS Status;
132 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL *PerformanceMeasurement;
133
134 if (mPerformanceMeasurement != NULL) {
135 return EFI_SUCCESS;
136 }
137
138 Status = gSmst->SmmLocateProtocol (&gEdkiiSmmPerformanceMeasurementProtocolGuid, NULL, (VOID **)&PerformanceMeasurement);
139 if (!EFI_ERROR (Status)) {
140 ASSERT (PerformanceMeasurement != NULL);
141 //
142 // Cache PerformanceMeasurement Protocol.
143 //
144 mPerformanceMeasurement = PerformanceMeasurement;
145 return EFI_SUCCESS;
146 }
147
148 return EFI_NOT_FOUND;
149}
150
173RETURN_STATUS
174EFIAPI
176 IN CONST VOID *Handle OPTIONAL,
177 IN CONST CHAR8 *Token OPTIONAL,
178 IN CONST CHAR8 *Module OPTIONAL,
179 IN UINT64 TimeStamp,
180 IN UINT32 Identifier
181 )
182{
183 EFI_STATUS Status;
184 CONST CHAR8 *String;
185
187 if (EFI_ERROR (Status)) {
188 return RETURN_NOT_FOUND;
189 }
190
191 if (Token != NULL) {
192 String = Token;
193 } else if (Module != NULL) {
194 String = Module;
195 } else {
196 String = NULL;
197 }
198
199 if (mPerformanceMeasurement != NULL) {
200 Status = mPerformanceMeasurement->CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);
201 } else {
202 ASSERT (FALSE);
203 }
204
205 return (RETURN_STATUS)Status;
206}
207
232RETURN_STATUS
233EFIAPI
235 IN CONST VOID *Handle OPTIONAL,
236 IN CONST CHAR8 *Token OPTIONAL,
237 IN CONST CHAR8 *Module OPTIONAL,
238 IN UINT64 TimeStamp,
239 IN UINT32 Identifier
240 )
241{
242 EFI_STATUS Status;
243 CONST CHAR8 *String;
244
246 if (EFI_ERROR (Status)) {
247 return RETURN_NOT_FOUND;
248 }
249
250 if (Token != NULL) {
251 String = Token;
252 } else if (Module != NULL) {
253 String = Module;
254 } else {
255 String = NULL;
256 }
257
258 if (mPerformanceMeasurement != NULL) {
259 Status = mPerformanceMeasurement->CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);
260 } else {
261 ASSERT (FALSE);
262 }
263
264 return (RETURN_STATUS)Status;
265}
266
308UINTN
309EFIAPI
311 IN UINTN LogEntryKey,
312 OUT CONST VOID **Handle,
313 OUT CONST CHAR8 **Token,
314 OUT CONST CHAR8 **Module,
315 OUT UINT64 *StartTimeStamp,
316 OUT UINT64 *EndTimeStamp,
317 OUT UINT32 *Identifier
318 )
319{
320 return 0;
321}
322
343RETURN_STATUS
344EFIAPI
346 IN CONST VOID *Handle OPTIONAL,
347 IN CONST CHAR8 *Token OPTIONAL,
348 IN CONST CHAR8 *Module OPTIONAL,
349 IN UINT64 TimeStamp
350 )
351{
352 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
353}
354
377RETURN_STATUS
378EFIAPI
380 IN CONST VOID *Handle OPTIONAL,
381 IN CONST CHAR8 *Token OPTIONAL,
382 IN CONST CHAR8 *Module OPTIONAL,
383 IN UINT64 TimeStamp
384 )
385{
386 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
387}
388
428UINTN
429EFIAPI
431 IN UINTN LogEntryKey,
432 OUT CONST VOID **Handle,
433 OUT CONST CHAR8 **Token,
434 OUT CONST CHAR8 **Module,
435 OUT UINT64 *StartTimeStamp,
436 OUT UINT64 *EndTimeStamp
437 )
438{
439 return 0;
440}
441
454BOOLEAN
455EFIAPI
457 VOID
458 )
459{
460 return mPerformanceMeasurementEnabled;
461}
462
478RETURN_STATUS
479EFIAPI
481 IN CONST VOID *CallerIdentifier,
482 IN CONST VOID *Guid OPTIONAL,
483 IN CONST CHAR8 *String OPTIONAL,
484 IN UINT64 Address OPTIONAL,
485 IN UINT32 Identifier
486 )
487{
488 EFI_STATUS Status;
489
491 if (EFI_ERROR (Status)) {
493 }
494
495 if (mPerformanceMeasurement != NULL) {
496 Status = mPerformanceMeasurement->CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);
497 } else {
498 ASSERT (FALSE);
499 }
500
501 return (RETURN_STATUS)Status;
502}
503
516BOOLEAN
517EFIAPI
519 IN CONST UINTN Type
520 )
521{
522 //
523 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
524 //
525 if (PerformanceMeasurementEnabled () && ((PcdGet8 (PcdPerformanceLibraryPropertyMask) & Type) == 0)) {
526 return TRUE;
527 }
528
529 return FALSE;
530}
UINT64 UINTN
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_NOT_FOUND
Definition: Base.h:1142
#define RETURN_OUT_OF_RESOURCES
Definition: Base.h:1114
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
EFI_SMM_SYSTEM_TABLE2 * gSmst
EFI_STATUS GetPerformanceMeasurementProtocol(VOID)
RETURN_STATUS EFIAPI EndPerformanceMeasurementEx(IN CONST VOID *Handle OPTIONAL, IN CONST CHAR8 *Token OPTIONAL, IN CONST CHAR8 *Module OPTIONAL, IN UINT64 TimeStamp, IN UINT32 Identifier)
UINTN EFIAPI GetPerformanceMeasurement(IN UINTN LogEntryKey, OUT CONST VOID **Handle, OUT CONST CHAR8 **Token, OUT CONST CHAR8 **Module, OUT UINT64 *StartTimeStamp, OUT UINT64 *EndTimeStamp)
RETURN_STATUS EFIAPI StartPerformanceMeasurementEx(IN CONST VOID *Handle OPTIONAL, IN CONST CHAR8 *Token OPTIONAL, IN CONST CHAR8 *Module OPTIONAL, IN UINT64 TimeStamp, IN UINT32 Identifier)
RETURN_STATUS EFIAPI LogPerformanceMeasurement(IN CONST VOID *CallerIdentifier, IN CONST VOID *Guid OPTIONAL, IN CONST CHAR8 *String OPTIONAL, IN UINT64 Address OPTIONAL, IN UINT32 Identifier)
EFI_STATUS EFIAPI SmmPerformanceLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
BOOLEAN EFIAPI LogPerformanceMeasurementEnabled(IN CONST UINTN Type)
BOOLEAN EFIAPI PerformanceMeasurementEnabled(VOID)
UINTN EFIAPI GetPerformanceMeasurementEx(IN UINTN LogEntryKey, OUT CONST VOID **Handle, OUT CONST CHAR8 **Token, OUT CONST CHAR8 **Module, OUT UINT64 *StartTimeStamp, OUT UINT64 *EndTimeStamp, OUT UINT32 *Identifier)
EFI_STATUS EFIAPI SmmPerformanceLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
RETURN_STATUS EFIAPI EndPerformanceMeasurement(IN CONST VOID *Handle OPTIONAL, IN CONST CHAR8 *Token OPTIONAL, IN CONST CHAR8 *Module OPTIONAL, IN UINT64 TimeStamp)
RETURN_STATUS EFIAPI StartPerformanceMeasurement(IN CONST VOID *Handle OPTIONAL, IN CONST CHAR8 *Token OPTIONAL, IN CONST CHAR8 *Module OPTIONAL, IN UINT64 TimeStamp)
EFI_STATUS EFIAPI SmmPerformanceLibExitBootServicesCallback(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213