]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
MdeModulePkg/DxeCapsuleLibFmp: Use new Variable Lock interface
[mirror_edk2.git] / MdeModulePkg / Library / PeiPerformanceLib / PeiPerformanceLib.c
... / ...
CommitLineData
1/** @file\r
2 Performance library instance used in PEI phase.\r
3\r
4 This file implements all APIs in Performance Library class in MdePkg. It creates\r
5 performance logging GUIDed HOB on the first performance logging and then logs the\r
6 performance data to the GUIDed HOB. Due to the limitation of temporary RAM, the maximum\r
7 number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries or\r
8 PcdMaxPeiPerformanceLogEntries16.\r
9\r
10Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
11(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
12SPDX-License-Identifier: BSD-2-Clause-Patent\r
13\r
14**/\r
15\r
16\r
17#include <PiPei.h>\r
18\r
19#include <Guid/ExtendedFirmwarePerformance.h>\r
20#include <Guid/PerformanceMeasurement.h>\r
21\r
22#include <Library/PerformanceLib.h>\r
23#include <Library/DebugLib.h>\r
24#include <Library/HobLib.h>\r
25#include <Library/BaseLib.h>\r
26#include <Library/TimerLib.h>\r
27#include <Library/PcdLib.h>\r
28#include <Library/BaseMemoryLib.h>\r
29\r
30#define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
31#define PEI_MAX_RECORD_SIZE (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + STRING_SIZE)\r
32\r
33\r
34/**\r
35 Return the pointer to the FPDT record in the allocated memory.\r
36\r
37 @param RecordSize The size of FPDT record.\r
38 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.\r
39 @param PeiPerformanceLogHeader Pointer to the header of the PEI Performance records in the GUID Hob.\r
40\r
41 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.\r
42 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.\r
43**/\r
44EFI_STATUS\r
45GetFpdtRecordPtr (\r
46 IN UINT8 RecordSize,\r
47 IN OUT FPDT_RECORD_PTR *FpdtRecordPtr,\r
48 IN OUT FPDT_PEI_EXT_PERF_HEADER **PeiPerformanceLogHeader\r
49)\r
50{\r
51 UINT16 PeiPerformanceLogEntries;\r
52 UINTN PeiPerformanceSize;\r
53 UINT8 *PeiFirmwarePerformance;\r
54 EFI_HOB_GUID_TYPE *GuidHob;\r
55\r
56 //\r
57 // Get the number of PeiPerformanceLogEntries form PCD.\r
58 //\r
59 PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
60 PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
61 PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
62\r
63 //\r
64 // Create GUID HOB Data.\r
65 //\r
66 GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);\r
67 PeiFirmwarePerformance = NULL;\r
68 while (GuidHob != NULL) {\r
69 //\r
70 // PEI Performance HOB was found, then return the existing one.\r
71 //\r
72 PeiFirmwarePerformance = (UINT8*)GET_GUID_HOB_DATA (GuidHob);\r
73 *PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
74 if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize > (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {\r
75 (*PeiPerformanceLogHeader)->HobIsFull = TRUE;\r
76 }\r
77 if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize <= (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {\r
78 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + (*PeiPerformanceLogHeader)->SizeOfAllEntries);\r
79 break;\r
80 }\r
81 //\r
82 // Previous HOB is used, then find next one.\r
83 //\r
84 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
85 }\r
86\r
87 if (GuidHob == NULL) {\r
88 //\r
89 // PEI Performance HOB was not found, then build one.\r
90 //\r
91 PeiPerformanceSize = sizeof (FPDT_PEI_EXT_PERF_HEADER) +\r
92 PEI_MAX_RECORD_SIZE * PeiPerformanceLogEntries;\r
93 PeiFirmwarePerformance = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);\r
94 if (PeiFirmwarePerformance != NULL) {\r
95 ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);\r
96 (*PeiPerformanceLogHeader) = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
97 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));\r
98 }\r
99 }\r
100\r
101 if (PeiFirmwarePerformance == NULL) {\r
102 //\r
103 // there is no enough resource to store performance data\r
104 //\r
105 return EFI_OUT_OF_RESOURCES;\r
106 }\r
107\r
108 return EFI_SUCCESS;\r
109}\r
110\r
111/**\r
112Check whether the Token is a known one which is uesed by core.\r
113\r
114@param Token Pointer to a Null-terminated ASCII string\r
115\r
116@retval TRUE Is a known one used by core.\r
117@retval FALSE Not a known one.\r
118\r
119**/\r
120BOOLEAN\r
121IsKnownTokens (\r
122 IN CONST CHAR8 *Token\r
123 )\r
124{\r
125 if (Token == NULL) {\r
126 return FALSE;\r
127 }\r
128\r
129 if (AsciiStrCmp (Token, SEC_TOK) == 0 ||\r
130 AsciiStrCmp (Token, PEI_TOK) == 0 ||\r
131 AsciiStrCmp (Token, DXE_TOK) == 0 ||\r
132 AsciiStrCmp (Token, BDS_TOK) == 0 ||\r
133 AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||\r
134 AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||\r
135 AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||\r
136 AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||\r
137 AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||\r
138 AsciiStrCmp (Token, PEIM_TOK) == 0) {\r
139 return TRUE;\r
140 } else {\r
141 return FALSE;\r
142 }\r
143}\r
144\r
145/**\r
146Check whether the ID is a known one which map to the known Token.\r
147\r
148@param Identifier 32-bit identifier.\r
149\r
150@retval TRUE Is a known one used by core.\r
151@retval FALSE Not a known one.\r
152\r
153**/\r
154BOOLEAN\r
155IsKnownID (\r
156 IN UINT32 Identifier\r
157 )\r
158{\r
159 if (Identifier == MODULE_START_ID ||\r
160 Identifier == MODULE_END_ID ||\r
161 Identifier == MODULE_LOADIMAGE_START_ID ||\r
162 Identifier == MODULE_LOADIMAGE_END_ID ||\r
163 Identifier == MODULE_DB_START_ID ||\r
164 Identifier == MODULE_DB_END_ID ||\r
165 Identifier == MODULE_DB_SUPPORT_START_ID ||\r
166 Identifier == MODULE_DB_SUPPORT_END_ID ||\r
167 Identifier == MODULE_DB_STOP_START_ID ||\r
168 Identifier == MODULE_DB_STOP_END_ID) {\r
169 return TRUE;\r
170 } else {\r
171 return FALSE;\r
172 }\r
173}\r
174\r
175/**\r
176 Get the FPDT record identifier.\r
177\r
178 @param Attribute The attribute of the Record.\r
179 PerfStartEntry: Start Record.\r
180 PerfEndEntry: End Record.\r
181 @param Handle Pointer to environment specific context used to identify the component being measured.\r
182 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.\r
183 @param ProgressID On return, pointer to the ProgressID.\r
184\r
185 @retval EFI_SUCCESS Get record info successfully.\r
186 @retval EFI_INVALID_PARAMETER No matched FPDT record.\r
187\r
188**/\r
189EFI_STATUS\r
190GetFpdtRecordId (\r
191 IN BOOLEAN Attribute,\r
192 IN CONST VOID *Handle,\r
193 IN CONST CHAR8 *String,\r
194 OUT UINT16 *ProgressID\r
195 )\r
196{\r
197 //\r
198 // Get the ProgressID based on the Token.\r
199 // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.\r
200 //\r
201 if (String != NULL) {\r
202 if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"\r
203 if (Attribute == PerfStartEntry) {\r
204 *ProgressID = MODULE_LOADIMAGE_START_ID;\r
205 } else {\r
206 *ProgressID = MODULE_LOADIMAGE_END_ID;\r
207 }\r
208 } else if (AsciiStrCmp (String, SEC_TOK) == 0 || // "SEC"\r
209 AsciiStrCmp (String, PEI_TOK) == 0) { // "PEI"\r
210 if (Attribute == PerfStartEntry) {\r
211 *ProgressID = PERF_CROSSMODULE_START_ID;\r
212 } else {\r
213 *ProgressID = PERF_CROSSMODULE_END_ID;\r
214 }\r
215 } else if (AsciiStrCmp (String, PEIM_TOK) == 0) { // "PEIM"\r
216 if (Attribute == PerfStartEntry) {\r
217 *ProgressID = MODULE_START_ID;\r
218 } else {\r
219 *ProgressID = MODULE_END_ID;\r
220 }\r
221 } else { //Pref used in Modules.\r
222 if (Attribute == PerfStartEntry) {\r
223 *ProgressID = PERF_INMODULE_START_ID;\r
224 } else {\r
225 *ProgressID = PERF_INMODULE_END_ID;\r
226 }\r
227 }\r
228 } else if (Handle != NULL) { //Pref used in Modules.\r
229 if (Attribute == PerfStartEntry) {\r
230 *ProgressID = PERF_INMODULE_START_ID;\r
231 } else {\r
232 *ProgressID = PERF_INMODULE_END_ID;\r
233 }\r
234 } else {\r
235 return EFI_INVALID_PARAMETER;\r
236 }\r
237\r
238 return EFI_SUCCESS;\r
239}\r
240\r
241/**\r
242 Copies the string from Source into Destination and updates Length with the\r
243 size of the string.\r
244\r
245 @param Destination - destination of the string copy\r
246 @param Source - pointer to the source string which will get copied\r
247 @param Length - pointer to a length variable to be updated\r
248\r
249**/\r
250VOID\r
251CopyStringIntoPerfRecordAndUpdateLength (\r
252 IN OUT CHAR8 *Destination,\r
253 IN CONST CHAR8 *Source,\r
254 IN OUT UINT8 *Length\r
255 )\r
256{\r
257 UINTN StringLen;\r
258 UINTN DestMax;\r
259\r
260 ASSERT (Source != NULL);\r
261\r
262 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
263 DestMax = STRING_SIZE;\r
264 } else {\r
265 DestMax = AsciiStrSize (Source);\r
266 if (DestMax > STRING_SIZE) {\r
267 DestMax = STRING_SIZE;\r
268 }\r
269 }\r
270 StringLen = AsciiStrLen (Source);\r
271 if (StringLen >= DestMax) {\r
272 StringLen = DestMax -1;\r
273 }\r
274\r
275 AsciiStrnCpyS(Destination, DestMax, Source, StringLen);\r
276 *Length += (UINT8)DestMax;\r
277\r
278 return;\r
279}\r
280\r
281\r
282/**\r
283 Convert PEI performance log to FPDT String boot record.\r
284\r
285 @param CallerIdentifier - Image handle or pointer to caller ID GUID.\r
286 @param Guid - Pointer to a GUID.\r
287 @param String - Pointer to a string describing the measurement.\r
288 @param Ticker - 64-bit time stamp.\r
289 @param Address - Pointer to a location in memory relevant to the measurement.\r
290 @param PerfId - Performance identifier describing the type of measurement.\r
291 @param Attribute - The attribute of the measurement. According to attribute can create a start\r
292 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
293 or a general record for other Perf macros.\r
294\r
295 @retval EFI_SUCCESS - Successfully created performance record.\r
296 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.\r
297 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
298 pointer or invalid PerfId.\r
299\r
300**/\r
301EFI_STATUS\r
302InsertFpdtRecord (\r
303 IN CONST VOID *CallerIdentifier, OPTIONAL\r
304 IN CONST VOID *Guid, OPTIONAL\r
305 IN CONST CHAR8 *String, OPTIONAL\r
306 IN UINT64 Ticker,\r
307 IN UINT64 Address, OPTIONAL\r
308 IN UINT16 PerfId,\r
309 IN PERF_MEASUREMENT_ATTRIBUTE Attribute\r
310 )\r
311{\r
312 FPDT_RECORD_PTR FpdtRecordPtr;\r
313 CONST VOID *ModuleGuid;\r
314 CONST CHAR8 *StringPtr;\r
315 EFI_STATUS Status;\r
316 UINT64 TimeStamp;\r
317 FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;\r
318\r
319 StringPtr = NULL;\r
320 FpdtRecordPtr.RecordHeader = NULL;\r
321 PeiPerformanceLogHeader = NULL;\r
322\r
323 //\r
324 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.\r
325 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.\r
326 //\r
327 if (Attribute != PerfEntry) {\r
328 //\r
329 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.\r
330 // !!! Note: If the Perf is not the known Token used in the core but have same\r
331 // ID with the core Token, this case will not be supported.\r
332 // And in currtnt usage mode, for the unkown ID, there is a general rule:\r
333 // If it is start pref: the lower 4 bits of the ID should be 0.\r
334 // If it is end pref: the lower 4 bits of the ID should not be 0.\r
335 // If input ID doesn't follow the rule, we will adjust it.\r
336 //\r
337 if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
338 return EFI_UNSUPPORTED;\r
339 } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
340 if (Attribute == PerfStartEntry && ((PerfId & 0x000F) != 0)) {\r
341 PerfId &= 0xFFF0;\r
342 } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {\r
343 PerfId += 1;\r
344 }\r
345 } else if (PerfId == 0) {\r
346 Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &PerfId);\r
347 if (EFI_ERROR (Status)) {\r
348 return Status;\r
349 }\r
350 }\r
351 }\r
352\r
353 //\r
354 // 2. Get the buffer to store the FPDT record.\r
355 //\r
356 Status = GetFpdtRecordPtr (PEI_MAX_RECORD_SIZE, &FpdtRecordPtr, &PeiPerformanceLogHeader);\r
357 if (EFI_ERROR (Status)) {\r
358 return Status;\r
359 }\r
360\r
361 //\r
362 // 3 Get the TimeStamp.\r
363 //\r
364 if (Ticker == 0) {\r
365 Ticker = GetPerformanceCounter ();\r
366 TimeStamp = GetTimeInNanoSecond (Ticker);\r
367 } else if (Ticker == 1) {\r
368 TimeStamp = 0;\r
369 } else {\r
370 TimeStamp = GetTimeInNanoSecond (Ticker);\r
371 }\r
372\r
373 //\r
374 // 4.Get the ModuleGuid.\r
375 //\r
376 if (CallerIdentifier != NULL) {\r
377 ModuleGuid = CallerIdentifier;\r
378 } else {\r
379 ModuleGuid = &gEfiCallerIdGuid;\r
380 }\r
381\r
382 //\r
383 // 5. Fill in the FPDT record according to different Performance Identifier.\r
384 //\r
385 switch (PerfId) {\r
386 case MODULE_START_ID:\r
387 case MODULE_END_ID:\r
388 StringPtr = PEIM_TOK;\r
389 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
390 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;\r
391 FpdtRecordPtr.GuidEvent->Header.Length = sizeof (FPDT_GUID_EVENT_RECORD);\r
392 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
393 FpdtRecordPtr.GuidEvent->ProgressID = PerfId;\r
394 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;\r
395 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
396 }\r
397 break;\r
398\r
399 case MODULE_LOADIMAGE_START_ID:\r
400 case MODULE_LOADIMAGE_END_ID:\r
401 StringPtr = LOAD_IMAGE_TOK;\r
402 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
403 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;\r
404 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
405 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
406 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;\r
407 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;\r
408 if (PerfId == MODULE_LOADIMAGE_START_ID) {\r
409 PeiPerformanceLogHeader->LoadImageCount++;\r
410 }\r
411 FpdtRecordPtr.GuidQwordEvent->Qword = PeiPerformanceLogHeader->LoadImageCount;\r
412 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
413 }\r
414 break;\r
415\r
416 case PERF_EVENTSIGNAL_START_ID:\r
417 case PERF_EVENTSIGNAL_END_ID:\r
418 case PERF_CALLBACK_START_ID:\r
419 case PERF_CALLBACK_END_ID:\r
420 if (String == NULL || Guid == NULL) {\r
421 return EFI_INVALID_PARAMETER;\r
422 }\r
423 StringPtr = String;\r
424 if (AsciiStrLen (String) == 0) {\r
425 StringPtr = "unknown name";\r
426 }\r
427 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
428 FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;\r
429 FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);\r
430 FpdtRecordPtr.DualGuidStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
431 FpdtRecordPtr.DualGuidStringEvent->ProgressID = PerfId;\r
432 FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;\r
433 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, ModuleGuid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));\r
434 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));\r
435 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);\r
436 }\r
437 break;\r
438\r
439 case PERF_EVENT_ID:\r
440 case PERF_FUNCTION_START_ID:\r
441 case PERF_FUNCTION_END_ID:\r
442 case PERF_INMODULE_START_ID:\r
443 case PERF_INMODULE_END_ID:\r
444 case PERF_CROSSMODULE_START_ID:\r
445 case PERF_CROSSMODULE_END_ID:\r
446 if (String != NULL && AsciiStrLen (String) != 0) {\r
447 StringPtr = String;\r
448 } else {\r
449 StringPtr = "unknown name";\r
450 }\r
451 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
452 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
453 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
454 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
455 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
456 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
457 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
458 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
459 }\r
460 break;\r
461\r
462 default:\r
463 if (Attribute != PerfEntry) {\r
464 if (String != NULL && AsciiStrLen (String) != 0) {\r
465 StringPtr = String;\r
466 } else {\r
467 StringPtr = "unknown name";\r
468 }\r
469 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
470 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
471 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
472 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
473 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
474 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
475 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
476 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
477 }\r
478 } else {\r
479 return EFI_INVALID_PARAMETER;\r
480 }\r
481 break;\r
482 }\r
483\r
484 //\r
485 // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.\r
486 //\r
487 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
488 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
489 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
490 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
491 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
492 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
493 if (Guid != NULL) {\r
494 //\r
495 // Cache the event guid in string event record.\r
496 //\r
497 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (EFI_GUID));\r
498 } else {\r
499 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
500 }\r
501 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
502 }\r
503\r
504 //\r
505 // 6. Update the length of the used buffer after fill in the record.\r
506 //\r
507 PeiPerformanceLogHeader->SizeOfAllEntries += FpdtRecordPtr.RecordHeader->Length;\r
508\r
509 return EFI_SUCCESS;\r
510}\r
511\r
512/**\r
513 Creates a record for the beginning of a performance measurement.\r
514\r
515 If TimeStamp is zero, then this function reads the current time stamp\r
516 and adds that time stamp value to the record as the start time.\r
517\r
518 If TimeStamp is one, then this function reads 0 as the start time.\r
519\r
520 If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
521\r
522 @param Handle Pointer to environment specific context used\r
523 to identify the component being measured.\r
524 @param Token Pointer to a Null-terminated ASCII string\r
525 that identifies the component being measured.\r
526 @param Module Pointer to a Null-terminated ASCII string\r
527 that identifies the module being measured.\r
528 @param TimeStamp 64-bit time stamp.\r
529 @param Identifier 32-bit identifier. If the value is 0, the created record\r
530 is same as the one created by StartPerformanceMeasurement.\r
531\r
532 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
533 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
534\r
535**/\r
536RETURN_STATUS\r
537EFIAPI\r
538StartPerformanceMeasurementEx (\r
539 IN CONST VOID *Handle, OPTIONAL\r
540 IN CONST CHAR8 *Token, OPTIONAL\r
541 IN CONST CHAR8 *Module, OPTIONAL\r
542 IN UINT64 TimeStamp,\r
543 IN UINT32 Identifier\r
544 )\r
545{\r
546 CONST CHAR8 *String;\r
547\r
548 if (Token != NULL) {\r
549 String = Token;\r
550 } else if (Module != NULL) {\r
551 String = Module;\r
552 } else {\r
553 String = NULL;\r
554 }\r
555\r
556 return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfStartEntry);\r
557\r
558}\r
559\r
560/**\r
561\r
562 Creates a record for the end of a performance measurement.\r
563\r
564 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
565 If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
566 If the TimeStamp is one, then this function reads 0 as the end time.\r
567\r
568 @param Handle Pointer to environment specific context used\r
569 to identify the component being measured.\r
570 @param Token Pointer to a Null-terminated ASCII string\r
571 that identifies the component being measured.\r
572 @param Module Pointer to a Null-terminated ASCII string\r
573 that identifies the module being measured.\r
574 @param TimeStamp 64-bit time stamp.\r
575 @param Identifier 32-bit identifier. If the value is 0, the found record\r
576 is same as the one found by EndPerformanceMeasurement.\r
577\r
578 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
579 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
580\r
581**/\r
582RETURN_STATUS\r
583EFIAPI\r
584EndPerformanceMeasurementEx (\r
585 IN CONST VOID *Handle, OPTIONAL\r
586 IN CONST CHAR8 *Token, OPTIONAL\r
587 IN CONST CHAR8 *Module, OPTIONAL\r
588 IN UINT64 TimeStamp,\r
589 IN UINT32 Identifier\r
590 )\r
591{\r
592 CONST CHAR8 *String;\r
593\r
594 if (Token != NULL) {\r
595 String = Token;\r
596 } else if (Module != NULL) {\r
597 String = Module;\r
598 } else {\r
599 String = NULL;\r
600 }\r
601\r
602 return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfEndEntry);\r
603}\r
604\r
605/**\r
606 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
607 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
608 and then assign the Identifier with 0.\r
609\r
610 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
611 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
612 and the key for the second entry in the log is returned. If the performance log is empty,\r
613 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
614 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
615 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
616 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
617 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
618 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
619 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
620 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
621 If Handle is NULL, then ASSERT().\r
622 If Token is NULL, then ASSERT().\r
623 If Module is NULL, then ASSERT().\r
624 If StartTimeStamp is NULL, then ASSERT().\r
625 If EndTimeStamp is NULL, then ASSERT().\r
626 If Identifier is NULL, then ASSERT().\r
627\r
628 !!!NOT Support yet!!!\r
629\r
630 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
631 0, then the first performance measurement log entry is retrieved.\r
632 On exit, the key of the next performance of entry entry.\r
633 @param Handle Pointer to environment specific context used to identify the component\r
634 being measured.\r
635 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
636 being measured.\r
637 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
638 being measured.\r
639 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
640 was started.\r
641 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
642 was ended.\r
643 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
644\r
645 @return The key for the next performance log entry (in general case).\r
646\r
647**/\r
648UINTN\r
649EFIAPI\r
650GetPerformanceMeasurementEx (\r
651 IN UINTN LogEntryKey,\r
652 OUT CONST VOID **Handle,\r
653 OUT CONST CHAR8 **Token,\r
654 OUT CONST CHAR8 **Module,\r
655 OUT UINT64 *StartTimeStamp,\r
656 OUT UINT64 *EndTimeStamp,\r
657 OUT UINT32 *Identifier\r
658 )\r
659{\r
660 return 0;\r
661}\r
662\r
663/**\r
664 Creates a record for the beginning of a performance measurement.\r
665\r
666 If TimeStamp is zero, then this function reads the current time stamp\r
667 and adds that time stamp value to the record as the start time.\r
668\r
669 If TimeStamp is one, then this function reads 0 as the start time.\r
670\r
671 If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
672\r
673\r
674 @param Handle Pointer to environment specific context used\r
675 to identify the component being measured.\r
676 @param Token Pointer to a Null-terminated ASCII string\r
677 that identifies the component being measured.\r
678 @param Module Pointer to a Null-terminated ASCII string\r
679 that identifies the module being measured.\r
680 @param TimeStamp 64-bit time stamp.\r
681\r
682 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
683 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
684\r
685**/\r
686RETURN_STATUS\r
687EFIAPI\r
688StartPerformanceMeasurement (\r
689 IN CONST VOID *Handle, OPTIONAL\r
690 IN CONST CHAR8 *Token, OPTIONAL\r
691 IN CONST CHAR8 *Module, OPTIONAL\r
692 IN UINT64 TimeStamp\r
693 )\r
694{\r
695 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
696}\r
697\r
698/**\r
699\r
700 Creates a record for the end of a performance measurement.\r
701\r
702 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
703 If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
704 If the TimeStamp is one, then this function reads 0 as the end time.\r
705\r
706 @param Handle Pointer to environment specific context used\r
707 to identify the component being measured.\r
708 @param Token Pointer to a Null-terminated ASCII string\r
709 that identifies the component being measured.\r
710 @param Module Pointer to a Null-terminated ASCII string\r
711 that identifies the module being measured.\r
712 @param TimeStamp 64-bit time stamp.\r
713\r
714 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
715 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
716\r
717**/\r
718RETURN_STATUS\r
719EFIAPI\r
720EndPerformanceMeasurement (\r
721 IN CONST VOID *Handle, OPTIONAL\r
722 IN CONST CHAR8 *Token, OPTIONAL\r
723 IN CONST CHAR8 *Module, OPTIONAL\r
724 IN UINT64 TimeStamp\r
725 )\r
726{\r
727 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
728}\r
729\r
730/**\r
731 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
732 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
733 and then eliminate the Identifier.\r
734\r
735 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
736 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
737 and the key for the second entry in the log is returned. If the performance log is empty,\r
738 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
739 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
740 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
741 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
742 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
743 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
744 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
745 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
746 If Handle is NULL, then ASSERT().\r
747 If Token is NULL, then ASSERT().\r
748 If Module is NULL, then ASSERT().\r
749 If StartTimeStamp is NULL, then ASSERT().\r
750 If EndTimeStamp is NULL, then ASSERT().\r
751\r
752 NOT Support yet.\r
753\r
754 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
755 0, then the first performance measurement log entry is retrieved.\r
756 On exit, the key of the next performance of entry entry.\r
757 @param Handle Pointer to environment specific context used to identify the component\r
758 being measured.\r
759 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
760 being measured.\r
761 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
762 being measured.\r
763 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
764 was started.\r
765 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
766 was ended.\r
767\r
768 @return The key for the next performance log entry (in general case).\r
769\r
770**/\r
771UINTN\r
772EFIAPI\r
773GetPerformanceMeasurement (\r
774 IN UINTN LogEntryKey,\r
775 OUT CONST VOID **Handle,\r
776 OUT CONST CHAR8 **Token,\r
777 OUT CONST CHAR8 **Module,\r
778 OUT UINT64 *StartTimeStamp,\r
779 OUT UINT64 *EndTimeStamp\r
780 )\r
781{\r
782 return 0;\r
783}\r
784\r
785/**\r
786 Returns TRUE if the performance measurement macros are enabled.\r
787\r
788 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
789 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
790\r
791 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
792 PcdPerformanceLibraryPropertyMask is set.\r
793 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
794 PcdPerformanceLibraryPropertyMask is clear.\r
795\r
796**/\r
797BOOLEAN\r
798EFIAPI\r
799PerformanceMeasurementEnabled (\r
800 VOID\r
801 )\r
802{\r
803 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
804}\r
805\r
806/**\r
807 Create performance record with event description and a timestamp.\r
808\r
809 @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
810 @param Guid - Pointer to a GUID\r
811 @param String - Pointer to a string describing the measurement\r
812 @param Address - Pointer to a location in memory relevant to the measurement\r
813 @param Identifier - Performance identifier describing the type of measurement\r
814\r
815 @retval RETURN_SUCCESS - Successfully created performance record\r
816 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records\r
817 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
818 pointer or invalid PerfId\r
819\r
820**/\r
821RETURN_STATUS\r
822EFIAPI\r
823LogPerformanceMeasurement (\r
824 IN CONST VOID *CallerIdentifier,\r
825 IN CONST VOID *Guid, OPTIONAL\r
826 IN CONST CHAR8 *String, OPTIONAL\r
827 IN UINT64 Address, OPTIONAL\r
828 IN UINT32 Identifier\r
829 )\r
830{\r
831 return (RETURN_STATUS)InsertFpdtRecord (CallerIdentifier, Guid, String, 0, Address, (UINT16)Identifier, PerfEntry);\r
832}\r
833\r
834/**\r
835 Check whether the specified performance measurement can be logged.\r
836\r
837 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
838 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
839\r
840 @param Type - Type of the performance measurement entry.\r
841\r
842 @retval TRUE The performance measurement can be logged.\r
843 @retval FALSE The performance measurement can NOT be logged.\r
844\r
845**/\r
846BOOLEAN\r
847EFIAPI\r
848LogPerformanceMeasurementEnabled (\r
849 IN CONST UINTN Type\r
850 )\r
851{\r
852 //\r
853 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
854 //\r
855 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {\r
856 return TRUE;\r
857 }\r
858 return FALSE;\r
859}\r