]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/PerformanceLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / PerformanceLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides services to log the execution times and retrieve them later.\r
fb3df220 3\r
2c5b667e 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
fb3df220 6\r
fb3df220 7**/\r
8\r
9#ifndef __PERFORMANCE_LIB_H__\r
10#define __PERFORMANCE_LIB_H__\r
11\r
fc30687f 12///\r
13/// Performance library propery mask bits\r
14///\r
fb3df220 15#define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED 0x00000001\r
16\r
2c5b667e
BD
17//\r
18// Public Progress Identifiers for Event Records.\r
19//\r
2f88bd3a
MK
20#define PERF_EVENT_ID 0x00\r
21\r
22#define MODULE_START_ID 0x01\r
23#define MODULE_END_ID 0x02\r
24#define MODULE_LOADIMAGE_START_ID 0x03\r
25#define MODULE_LOADIMAGE_END_ID 0x04\r
26#define MODULE_DB_START_ID 0x05\r
27#define MODULE_DB_END_ID 0x06\r
28#define MODULE_DB_SUPPORT_START_ID 0x07\r
29#define MODULE_DB_SUPPORT_END_ID 0x08\r
30#define MODULE_DB_STOP_START_ID 0x09\r
31#define MODULE_DB_STOP_END_ID 0x0A\r
32\r
33#define PERF_EVENTSIGNAL_START_ID 0x10\r
34#define PERF_EVENTSIGNAL_END_ID 0x11\r
35#define PERF_CALLBACK_START_ID 0x20\r
36#define PERF_CALLBACK_END_ID 0x21\r
37#define PERF_FUNCTION_START_ID 0x30\r
38#define PERF_FUNCTION_END_ID 0x31\r
39#define PERF_INMODULE_START_ID 0x40\r
40#define PERF_INMODULE_END_ID 0x41\r
41#define PERF_CROSSMODULE_START_ID 0x50\r
42#define PERF_CROSSMODULE_END_ID 0x51\r
2c5b667e
BD
43\r
44//\r
45// Declare bits for PcdPerformanceLibraryPropertyMask and\r
46// also used as the Type parameter of LogPerformanceMeasurementEnabled().\r
47//\r
2f88bd3a
MK
48#define PERF_CORE_START_IMAGE 0x0002\r
49#define PERF_CORE_LOAD_IMAGE 0x0004\r
50#define PERF_CORE_DB_SUPPORT 0x0008\r
51#define PERF_CORE_DB_START 0x0010\r
52#define PERF_CORE_DB_STOP 0x0020\r
2c5b667e 53\r
2f88bd3a 54#define PERF_GENERAL_TYPE 0x0040\r
2c5b667e 55\r
fb3df220 56/**\r
9095d37b
LG
57 Creates a record for the beginning of a performance measurement.\r
58\r
fb3df220 59 Creates a record that contains the Handle, Token, and Module.\r
60 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
61 If TimeStamp is zero, then this function reads the current time stamp\r
62 and adds that time stamp value to the record as the start time.\r
63\r
64 @param Handle Pointer to environment specific context used\r
65 to identify the component being measured.\r
66 @param Token Pointer to a Null-terminated ASCII string\r
67 that identifies the component being measured.\r
68 @param Module Pointer to a Null-terminated ASCII string\r
69 that identifies the module being measured.\r
70 @param TimeStamp 64-bit time stamp.\r
71\r
72 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
73 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
8404146c 74 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
fb3df220 75\r
76**/\r
77RETURN_STATUS\r
78EFIAPI\r
79StartPerformanceMeasurement (\r
d0e2f823
MK
80 IN CONST VOID *Handle OPTIONAL,\r
81 IN CONST CHAR8 *Token OPTIONAL,\r
82 IN CONST CHAR8 *Module OPTIONAL,\r
fb3df220 83 IN UINT64 TimeStamp\r
84 );\r
85\r
86/**\r
9095d37b
LG
87 Fills in the end time of a performance measurement.\r
88\r
fb3df220 89 Looks up the record that matches Handle, Token, and Module.\r
90 If the record can not be found then return RETURN_NOT_FOUND.\r
91 If the record is found and TimeStamp is not zero,\r
92 then TimeStamp is added to the record as the end time.\r
93 If the record is found and TimeStamp is zero, then this function reads\r
94 the current time stamp and adds that time stamp value to the record as the end time.\r
fb3df220 95\r
96 @param Handle Pointer to environment specific context used\r
97 to identify the component being measured.\r
98 @param Token Pointer to a Null-terminated ASCII string\r
99 that identifies the component being measured.\r
100 @param Module Pointer to a Null-terminated ASCII string\r
101 that identifies the module being measured.\r
102 @param TimeStamp 64-bit time stamp.\r
103\r
104 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
105 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
8404146c 106 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
fb3df220 107\r
108**/\r
109RETURN_STATUS\r
110EFIAPI\r
111EndPerformanceMeasurement (\r
d0e2f823
MK
112 IN CONST VOID *Handle OPTIONAL,\r
113 IN CONST CHAR8 *Token OPTIONAL,\r
114 IN CONST CHAR8 *Module OPTIONAL,\r
fb3df220 115 IN UINT64 TimeStamp\r
116 );\r
117\r
118/**\r
9095d37b 119 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
ba14539c
SZ
120 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
121 and then eliminate the Identifier.\r
122\r
fb3df220 123 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
124 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
125 and the key for the second entry in the log is returned. If the performance log is empty,\r
126 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
127 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
128 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
129 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
130 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
131 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
132 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
133 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
134 If Handle is NULL, then ASSERT().\r
135 If Token is NULL, then ASSERT().\r
136 If Module is NULL, then ASSERT().\r
137 If StartTimeStamp is NULL, then ASSERT().\r
138 If EndTimeStamp is NULL, then ASSERT().\r
139\r
140 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
141 0, then the first performance measurement log entry is retrieved.\r
142 On exit, the key of the next performance lof entry entry.\r
143 @param Handle Pointer to environment specific context used to identify the component\r
9095d37b 144 being measured.\r
fb3df220 145 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
9095d37b 146 being measured.\r
fb3df220 147 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
148 being measured.\r
149 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
150 was started.\r
151 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
152 was ended.\r
153\r
154 @return The key for the next performance log entry (in general case).\r
155\r
156**/\r
157UINTN\r
158EFIAPI\r
159GetPerformanceMeasurement (\r
2f88bd3a
MK
160 IN UINTN LogEntryKey,\r
161 OUT CONST VOID **Handle,\r
162 OUT CONST CHAR8 **Token,\r
163 OUT CONST CHAR8 **Module,\r
164 OUT UINT64 *StartTimeStamp,\r
165 OUT UINT64 *EndTimeStamp\r
fb3df220 166 );\r
167\r
ba14539c
SZ
168/**\r
169 Creates a record for the beginning of a performance measurement.\r
170\r
171 Creates a record that contains the Handle, Token, Module and Identifier.\r
172 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
173 If TimeStamp is zero, then this function reads the current time stamp\r
174 and adds that time stamp value to the record as the start time.\r
175\r
176 @param Handle Pointer to environment specific context used\r
177 to identify the component being measured.\r
178 @param Token Pointer to a Null-terminated ASCII string\r
179 that identifies the component being measured.\r
180 @param Module Pointer to a Null-terminated ASCII string\r
181 that identifies the module being measured.\r
182 @param TimeStamp 64-bit time stamp.\r
183 @param Identifier 32-bit identifier. If the value is 0, the created record\r
184 is same as the one created by StartPerformanceMeasurement.\r
185\r
186 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
187 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
188 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
189\r
190**/\r
191RETURN_STATUS\r
192EFIAPI\r
193StartPerformanceMeasurementEx (\r
d0e2f823
MK
194 IN CONST VOID *Handle OPTIONAL,\r
195 IN CONST CHAR8 *Token OPTIONAL,\r
196 IN CONST CHAR8 *Module OPTIONAL,\r
ba14539c
SZ
197 IN UINT64 TimeStamp,\r
198 IN UINT32 Identifier\r
199 );\r
200\r
201/**\r
202 Fills in the end time of a performance measurement.\r
203\r
ef8d4170 204 Looks up the record that matches Handle, Token and Module.\r
ba14539c
SZ
205 If the record can not be found then return RETURN_NOT_FOUND.\r
206 If the record is found and TimeStamp is not zero,\r
207 then TimeStamp is added to the record as the end time.\r
208 If the record is found and TimeStamp is zero, then this function reads\r
209 the current time stamp and adds that time stamp value to the record as the end time.\r
210\r
211 @param Handle Pointer to environment specific context used\r
212 to identify the component being measured.\r
213 @param Token Pointer to a Null-terminated ASCII string\r
214 that identifies the component being measured.\r
215 @param Module Pointer to a Null-terminated ASCII string\r
216 that identifies the module being measured.\r
217 @param TimeStamp 64-bit time stamp.\r
218 @param Identifier 32-bit identifier. If the value is 0, the found record\r
219 is same as the one found by EndPerformanceMeasurement.\r
220\r
221 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
222 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
223 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
224\r
225**/\r
226RETURN_STATUS\r
227EFIAPI\r
228EndPerformanceMeasurementEx (\r
d0e2f823
MK
229 IN CONST VOID *Handle OPTIONAL,\r
230 IN CONST CHAR8 *Token OPTIONAL,\r
231 IN CONST CHAR8 *Module OPTIONAL,\r
ba14539c
SZ
232 IN UINT64 TimeStamp,\r
233 IN UINT32 Identifier\r
234 );\r
235\r
236/**\r
237 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
238 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
239 and then assign the Identifier with 0.\r
240\r
241 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
242 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
243 and the key for the second entry in the log is returned. If the performance log is empty,\r
244 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
245 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
246 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
247 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
248 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
249 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
250 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
251 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
252 If Handle is NULL, then ASSERT().\r
253 If Token is NULL, then ASSERT().\r
254 If Module is NULL, then ASSERT().\r
255 If StartTimeStamp is NULL, then ASSERT().\r
256 If EndTimeStamp is NULL, then ASSERT().\r
257 If Identifier is NULL, then ASSERT().\r
258\r
259 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
260 0, then the first performance measurement log entry is retrieved.\r
261 On exit, the key of the next performance of entry entry.\r
262 @param Handle Pointer to environment specific context used to identify the component\r
263 being measured.\r
264 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
265 being measured.\r
266 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
267 being measured.\r
268 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
269 was started.\r
270 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
271 was ended.\r
272 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
273\r
274 @return The key for the next performance log entry (in general case).\r
275\r
276**/\r
277UINTN\r
278EFIAPI\r
279GetPerformanceMeasurementEx (\r
2f88bd3a
MK
280 IN UINTN LogEntryKey,\r
281 OUT CONST VOID **Handle,\r
282 OUT CONST CHAR8 **Token,\r
283 OUT CONST CHAR8 **Module,\r
284 OUT UINT64 *StartTimeStamp,\r
285 OUT UINT64 *EndTimeStamp,\r
286 OUT UINT32 *Identifier\r
ba14539c
SZ
287 );\r
288\r
fb3df220 289/**\r
9095d37b
LG
290 Returns TRUE if the performance measurement macros are enabled.\r
291\r
fb3df220 292 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
293 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
294\r
295 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
296 PcdPerformanceLibraryPropertyMask is set.\r
297 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
298 PcdPerformanceLibraryPropertyMask is clear.\r
299\r
300**/\r
301BOOLEAN\r
302EFIAPI\r
303PerformanceMeasurementEnabled (\r
304 VOID\r
305 );\r
306\r
2c5b667e
BD
307/**\r
308 Check whether the specified performance measurement can be logged.\r
309\r
310 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
311 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
312\r
313 @param Type - Type of the performance measurement entry.\r
314\r
315 @retval TRUE The performance measurement can be logged.\r
316 @retval FALSE The performance measurement can NOT be logged.\r
317\r
318**/\r
319BOOLEAN\r
320EFIAPI\r
321LogPerformanceMeasurementEnabled (\r
2f88bd3a 322 IN CONST UINTN Type\r
2c5b667e
BD
323 );\r
324\r
325/**\r
326 Create performance record with event description.\r
327\r
328 @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
329 @param Guid - Pointer to a GUID.\r
330 Used for event signal perf and callback perf to cache the event guid.\r
331 @param String - Pointer to a string describing the measurement\r
332 @param Address - Pointer to a location in memory relevant to the measurement.\r
333 @param Identifier - Performance identifier describing the type of measurement.\r
334\r
335 @retval RETURN_SUCCESS - Successfully created performance record\r
336 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records\r
337 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
338 pointer or invalid Identifier.\r
339\r
340**/\r
341RETURN_STATUS\r
342EFIAPI\r
343LogPerformanceMeasurement (\r
d0e2f823
MK
344 IN CONST VOID *CallerIdentifier OPTIONAL,\r
345 IN CONST VOID *Guid OPTIONAL,\r
346 IN CONST CHAR8 *String OPTIONAL,\r
347 IN UINT64 Address OPTIONAL,\r
2c5b667e
BD
348 IN UINT32 Identifier\r
349 );\r
350\r
351/**\r
352 Begin Macro to measure the performance of StartImage in core.\r
353\r
354 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 355 and the BIT1 (disable PERF_CORE_START_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
356 then LogPerformanceMeasurement() is called.\r
357\r
358**/\r
359#define PERF_START_IMAGE_BEGIN(ModuleHandle) \\r
360 do { \\r
361 if (LogPerformanceMeasurementEnabled (PERF_CORE_START_IMAGE)) { \\r
362 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_START_ID); \\r
363 } \\r
364 } while (FALSE)\r
365\r
366/**\r
367 End Macro to measure the performance of StartImage in core.\r
368\r
369 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 370 and the BIT1 (disable PERF_CORE_START_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
371 then LogPerformanceMeasurement() is called.\r
372\r
373**/\r
374#define PERF_START_IMAGE_END(ModuleHandle) \\r
375 do { \\r
376 if (LogPerformanceMeasurementEnabled (PERF_CORE_START_IMAGE)) { \\r
377 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_END_ID); \\r
378 } \\r
379 } while (FALSE)\r
380\r
381/**\r
382 Begin Macro to measure the performance of LoadImage in core.\r
383\r
384 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 385 and the BIT2 (disable PERF_CORE_LOAD_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
386 then LogPerformanceMeasurement() is called.\r
387\r
388**/\r
389#define PERF_LOAD_IMAGE_BEGIN(ModuleHandle) \\r
390 do { \\r
391 if (LogPerformanceMeasurementEnabled (PERF_CORE_LOAD_IMAGE)) { \\r
392 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_LOADIMAGE_START_ID); \\r
393 } \\r
394 } while (FALSE)\r
395\r
396/**\r
397 End Macro to measure the performance of LoadImage in core.\r
398\r
399 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 400 and the BIT2 (disable PERF_CORE_LOAD_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
401 then LogPerformanceMeasurement() is called.\r
402\r
403**/\r
404#define PERF_LOAD_IMAGE_END(ModuleHandle) \\r
405 do { \\r
406 if (LogPerformanceMeasurementEnabled (PERF_CORE_LOAD_IMAGE)) { \\r
407 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_LOADIMAGE_END_ID); \\r
408 } \\r
409 } while (FALSE)\r
410\r
411/**\r
412 Start Macro to measure the performance of DriverBinding Support in core.\r
413\r
414 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 415 and the BIT3 (disable PERF_CORE_DB_SUPPORT) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
416 then LogPerformanceMeasurement() is called.\r
417\r
418**/\r
419#define PERF_DRIVER_BINDING_SUPPORT_BEGIN(ModuleHandle, ControllerHandle) \\r
420 do { \\r
421 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_SUPPORT)) { \\r
422 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_SUPPORT_START_ID); \\r
423 } \\r
424 } while (FALSE)\r
425\r
426/**\r
427 End Macro to measure the performance of DriverBinding Support in core.\r
428\r
429 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 430 and the BIT3 (disable PERF_CORE_DB_SUPPORT) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
431 then LogPerformanceMeasurement() is called.\r
432\r
433**/\r
434#define PERF_DRIVER_BINDING_SUPPORT_END(ModuleHandle, ControllerHandle) \\r
435 do { \\r
436 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_SUPPORT)) { \\r
437 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_SUPPORT_END_ID); \\r
438 } \\r
439 } while (FALSE)\r
440\r
441/**\r
442 Begin Macro to measure the performance of DriverBinding Start in core.\r
443\r
444 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 445 and the BIT4 (disable PERF_CORE_DB_START) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
446 then LogPerformanceMeasurement() is called.\r
447\r
448**/\r
449#define PERF_DRIVER_BINDING_START_BEGIN(ModuleHandle, ControllerHandle) \\r
450 do { \\r
451 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_START)) { \\r
452 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_START_ID); \\r
453 } \\r
454 } while (FALSE)\r
455\r
456/**\r
457 End Macro to measure the performance of DriverBinding Start in core.\r
458\r
459 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 460 and the BIT4 (disable PERF_CORE_DB_START) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
461 then LogPerformanceMeasurement() is called.\r
462\r
463**/\r
464#define PERF_DRIVER_BINDING_START_END(ModuleHandle, ControllerHandle) \\r
465 do { \\r
466 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_START)) { \\r
467 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_END_ID); \\r
468 } \\r
469 } while (FALSE)\r
470\r
471/**\r
472 Start Macro to measure the performance of DriverBinding Stop in core.\r
473\r
474 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 475 and the BIT5 (disable PERF_CORE_DB_STOP) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
476 then LogPerformanceMeasurement() is called.\r
477\r
478**/\r
479#define PERF_DRIVER_BINDING_STOP_BEGIN(ModuleHandle, ControllerHandle) \\r
480 do { \\r
481 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_STOP)) { \\r
482 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_STOP_START_ID); \\r
483 } \\r
484 } while (FALSE)\r
485\r
486/**\r
487 End Macro to measure the performance of DriverBinding Stop in core.\r
488\r
489 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 490 and the BIT5 (disable PERF_CORE_DB_STOP) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
491 then LogPerformanceMeasurement() is called.\r
492\r
493**/\r
494#define PERF_DRIVER_BINDING_STOP_END(ModuleHandle, ControllerHandle) \\r
495 do { \\r
496 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_STOP)) { \\r
497 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_STOP_END_ID); \\r
498 } \\r
499 } while (FALSE)\r
500\r
501/**\r
502 Macro to measure the time from power-on to this macro execution.\r
503 It can be used to log a meaningful thing which happens at a time point.\r
504\r
505 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 506 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
507 then LogPerformanceMeasurement() is called.\r
508\r
509**/\r
510#define PERF_EVENT(EventString) \\r
511 do { \\r
512 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
513 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, EventString , 0, PERF_EVENT_ID); \\r
514 } \\r
515 } while (FALSE)\r
516\r
517/**\r
a7e72294 518 Begin Macro to measure the performance of evnent signal behavior in any module.\r
2c5b667e
BD
519 The event guid will be passed with this macro.\r
520\r
521 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 522 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
523 then LogPerformanceMeasurement() is called.\r
524\r
525**/\r
526#define PERF_EVENT_SIGNAL_BEGIN(EventGuid) \\r
527 do { \\r
528 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
529 LogPerformanceMeasurement (&gEfiCallerIdGuid, EventGuid, __FUNCTION__ , 0, PERF_EVENTSIGNAL_START_ID); \\r
530 } \\r
531 } while (FALSE)\r
532\r
533/**\r
a7e72294 534 End Macro to measure the performance of evnent signal behavior in any module.\r
2c5b667e
BD
535 The event guid will be passed with this macro.\r
536\r
537 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 538 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
539 then LogPerformanceMeasurement() is called.\r
540\r
541**/\r
542#define PERF_EVENT_SIGNAL_END(EventGuid) \\r
543 do { \\r
544 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
545 LogPerformanceMeasurement (&gEfiCallerIdGuid, EventGuid, __FUNCTION__ , 0, PERF_EVENTSIGNAL_END_ID); \\r
546 } \\r
547 } while (FALSE)\r
548\r
549/**\r
a7e72294 550 Begin Macro to measure the performance of a callback function in any module.\r
2c5b667e
BD
551 The event guid which trigger the callback function will be passed with this macro.\r
552\r
553 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 554 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
555 then LogPerformanceMeasurement() is called.\r
556\r
557**/\r
558#define PERF_CALLBACK_BEGIN(TriggerGuid) \\r
559 do { \\r
560 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
561 LogPerformanceMeasurement (&gEfiCallerIdGuid, TriggerGuid, __FUNCTION__ , 0, PERF_CALLBACK_START_ID); \\r
562 } \\r
563 } while (FALSE)\r
564\r
565/**\r
a7e72294 566 End Macro to measure the performance of a callback function in any module.\r
2c5b667e
BD
567 The event guid which trigger the callback function will be passed with this macro.\r
568\r
569 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 570 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
571 then LogPerformanceMeasurement() is called.\r
572\r
573**/\r
574#define PERF_CALLBACK_END(TriggerGuid) \\r
575 do { \\r
576 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
577 LogPerformanceMeasurement (&gEfiCallerIdGuid, TriggerGuid, __FUNCTION__ , 0, PERF_CALLBACK_END_ID); \\r
578 } \\r
579 } while (FALSE)\r
580\r
581/**\r
a7e72294 582 Begin Macro to measure the performance of a general function in any module.\r
2c5b667e
BD
583\r
584 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 585 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
586 then LogPerformanceMeasurement() is called.\r
587\r
588**/\r
589#define PERF_FUNCTION_BEGIN() \\r
590 do { \\r
591 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
592 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, __FUNCTION__ , 0, PERF_FUNCTION_START_ID); \\r
593 } \\r
594 } while (FALSE)\r
595\r
596/**\r
a7e72294 597 End Macro to measure the performance of a general function in any module.\r
2c5b667e
BD
598\r
599 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 600 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
601 then LogPerformanceMeasurement() is called.\r
602\r
603**/\r
604#define PERF_FUNCTION_END() \\r
605 do { \\r
606 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
607 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, __FUNCTION__ , 0, PERF_FUNCTION_END_ID); \\r
608 } \\r
609 } while (FALSE)\r
610\r
611/**\r
a7e72294 612 Begin Macro to measure the performance of a behavior within one module.\r
2c5b667e
BD
613\r
614 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 615 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
616 then LogPerformanceMeasurement() is called.\r
617\r
618**/\r
619#define PERF_INMODULE_BEGIN(MeasurementString) \\r
620 do { \\r
621 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
622 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_INMODULE_START_ID); \\r
623 } \\r
624 } while (FALSE)\r
625\r
626/**\r
a7e72294 627 End Macro to measure the performance of a behavior within one module.\r
2c5b667e
BD
628\r
629 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 630 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
631 then LogPerformanceMeasurement() is called.\r
632\r
633**/\r
634#define PERF_INMODULE_END(MeasurementString) \\r
635 do { \\r
636 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
637 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_INMODULE_END_ID); \\r
638 } \\r
639 } while (FALSE)\r
640\r
641/**\r
a7e72294 642 Begin Macro to measure the performance of a behavior in different modules.\r
2c5b667e
BD
643 Such as the performance of PEI phase, DXE phase, BDS phase.\r
644\r
645 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 646 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
647 then LogPerformanceMeasurement() is called.\r
648\r
649**/\r
650#define PERF_CROSSMODULE_BEGIN(MeasurementString) \\r
651 do { \\r
652 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
653 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_CROSSMODULE_START_ID); \\r
654 } \\r
655 } while (FALSE)\r
656\r
657/**\r
a7e72294 658 End Macro to measure the performance of a behavior in different modules.\r
2c5b667e
BD
659 Such as the performance of PEI phase, DXE phase, BDS phase.\r
660\r
661 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
a7e72294 662 and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
2c5b667e
BD
663 then LogPerformanceMeasurement() is called.\r
664\r
665**/\r
666#define PERF_CROSSMODULE_END(MeasurementString) \\r
667 do { \\r
668 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
669 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_CROSSMODULE_END_ID); \\r
670 } \\r
671 } while (FALSE)\r
672\r
fb3df220 673/**\r
674 Macro that calls EndPerformanceMeasurement().\r
675\r
676 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
677 then EndPerformanceMeasurement() is called.\r
678\r
679**/\r
680#define PERF_END(Handle, Token, Module, TimeStamp) \\r
681 do { \\r
682 if (PerformanceMeasurementEnabled ()) { \\r
683 EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \\r
684 } \\r
685 } while (FALSE)\r
686\r
687/**\r
688 Macro that calls StartPerformanceMeasurement().\r
689\r
690 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
691 then StartPerformanceMeasurement() is called.\r
692\r
693**/\r
694#define PERF_START(Handle, Token, Module, TimeStamp) \\r
695 do { \\r
696 if (PerformanceMeasurementEnabled ()) { \\r
697 StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \\r
698 } \\r
699 } while (FALSE)\r
700\r
ba14539c
SZ
701/**\r
702 Macro that calls EndPerformanceMeasurementEx().\r
703\r
704 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
705 then EndPerformanceMeasurementEx() is called.\r
706\r
707**/\r
708#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier) \\r
709 do { \\r
710 if (PerformanceMeasurementEnabled ()) { \\r
711 EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r
712 } \\r
713 } while (FALSE)\r
714\r
715/**\r
716 Macro that calls StartPerformanceMeasurementEx().\r
717\r
718 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
719 then StartPerformanceMeasurementEx() is called.\r
720\r
721**/\r
722#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier) \\r
723 do { \\r
724 if (PerformanceMeasurementEnabled ()) { \\r
725 StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r
726 } \\r
727 } while (FALSE)\r
728\r
fb3df220 729/**\r
730 Macro that marks the beginning of performance measurement source code.\r
731\r
732 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
733 then this macro marks the beginning of source code that is included in a module.\r
734 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r
735\r
736**/\r
737#define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal\r
738\r
739/**\r
740 Macro that marks the end of performance measurement source code.\r
741\r
742 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
743 then this macro marks the end of source code that is included in a module.\r
744 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r
745\r
746**/\r
2f88bd3a 747#define PERF_CODE_END() __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE)\r
fb3df220 748\r
749/**\r
750 Macro that declares a section of performance measurement source code.\r
751\r
752 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
753 then the source code specified by Expression is included in a module.\r
754 Otherwise, the source specified by Expression is not included in a module.\r
755\r
756 @param Expression Performance measurement source code to include in a module.\r
757\r
758**/\r
759#define PERF_CODE(Expression) \\r
760 PERF_CODE_BEGIN (); \\r
761 Expression \\r
762 PERF_CODE_END ()\r
763\r
fb3df220 764#endif\r