]>
Commit | Line | Data |
---|---|---|
8dbae30d | 1 | /** @file\r |
857dfc45 | 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. \r | |
a0afd019 | 8 | \r |
cd5ebaa0 HT |
9 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r |
10 | This program and the accompanying materials\r | |
a0afd019 | 11 | are licensed and made available under the terms and conditions of the BSD License\r |
12 | which accompanies this distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php\r | |
14 | \r | |
15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
17 | \r | |
8dbae30d | 18 | **/\r |
a0afd019 | 19 | \r |
ed7748fe | 20 | \r |
a0afd019 | 21 | #include <PiPei.h>\r |
ed7748fe | 22 | \r |
ee0961f7 | 23 | #include <Guid/Performance.h>\r |
ed7748fe | 24 | \r |
a0afd019 | 25 | #include <Library/PerformanceLib.h>\r |
26 | #include <Library/DebugLib.h>\r | |
27 | #include <Library/HobLib.h>\r | |
28 | #include <Library/BaseLib.h>\r | |
29 | #include <Library/TimerLib.h>\r | |
30 | #include <Library/PcdLib.h>\r | |
31 | #include <Library/BaseMemoryLib.h>\r | |
32 | \r | |
33 | \r | |
34 | /**\r | |
35 | Gets PEI the GUID HOB for PEI performance.\r | |
36 | \r | |
37 | This internal function searches for the GUID HOB for PEI performance.\r | |
38 | If that GUID HOB is not found, it will build a new one.\r | |
39 | It returns the data area of that GUID HOB to record performance log.\r | |
40 | \r | |
41 | @param Handle Pointer to environment specific context used\r | |
42 | to identify the component being measured.\r | |
43 | @param Token Pointer to a Null-terminated ASCII string\r | |
44 | that identifies the component being measured.\r | |
45 | @param Module Pointer to a Null-terminated ASCII string\r | |
46 | that identifies the module being measured.\r | |
47 | \r | |
48 | @retval The index of log entry in the array.\r | |
49 | \r | |
50 | **/\r | |
a0afd019 | 51 | PEI_PERFORMANCE_LOG_HEADER *\r |
52 | InternalGetPerformanceHobLog (\r | |
53 | VOID\r | |
54 | )\r | |
55 | {\r | |
56 | EFI_HOB_GUID_TYPE *GuidHob;\r | |
57 | PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r | |
58 | UINTN PeiPerformanceLogSize;\r | |
59 | \r | |
ee0961f7 | 60 | GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);\r |
a0afd019 | 61 | \r |
62 | if (GuidHob != NULL) {\r | |
63 | //\r | |
64 | // PEI Performance HOB was found, then return the existing one.\r | |
65 | //\r | |
66 | PeiPerformanceLog = GET_GUID_HOB_DATA (GuidHob);\r | |
67 | } else {\r | |
68 | //\r | |
69 | // PEI Performance HOB was not found, then build one.\r | |
70 | //\r | |
71 | PeiPerformanceLogSize = sizeof (PEI_PERFORMANCE_LOG_HEADER) +\r | |
72 | sizeof (PEI_PERFORMANCE_LOG_ENTRY) * PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r | |
ee0961f7 | 73 | PeiPerformanceLog = BuildGuidHob (&gPerformanceProtocolGuid, PeiPerformanceLogSize);\r |
a0afd019 | 74 | PeiPerformanceLog = ZeroMem (PeiPerformanceLog, PeiPerformanceLogSize);\r |
75 | }\r | |
76 | \r | |
77 | return PeiPerformanceLog;\r | |
78 | }\r | |
79 | \r | |
80 | /**\r | |
81 | Searches in the log array with keyword Handle, Token and Module.\r | |
82 | \r | |
83 | This internal function searches for the log entry in the log array.\r | |
84 | If there is an entry that exactly matches the given key word triple\r | |
85 | and its end time stamp is zero, then the index of that log entry is returned;\r | |
86 | otherwise, the the number of log entries in the array is returned.\r | |
87 | \r | |
74935bd7 | 88 | @param PeiPerformanceLog Pointer to the data structure containing PEI \r |
89 | performance data.\r | |
a0afd019 | 90 | @param Handle Pointer to environment specific context used\r |
91 | to identify the component being measured.\r | |
92 | @param Token Pointer to a Null-terminated ASCII string\r | |
93 | that identifies the component being measured.\r | |
94 | @param Module Pointer to a Null-terminated ASCII string\r | |
95 | that identifies the module being measured.\r | |
96 | \r | |
97 | @retval The index of log entry in the array.\r | |
98 | \r | |
99 | **/\r | |
a0afd019 | 100 | UINT32\r |
101 | InternalSearchForLogEntry (\r | |
102 | IN PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog,\r | |
103 | IN CONST VOID *Handle, OPTIONAL\r | |
104 | IN CONST CHAR8 *Token, OPTIONAL\r | |
105 | IN CONST CHAR8 *Module OPTIONAL\r | |
106 | )\r | |
107 | {\r | |
108 | UINT32 Index;\r | |
109 | UINT32 NumberOfEntries;\r | |
110 | PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r | |
111 | \r | |
112 | \r | |
113 | if (Token == NULL) {\r | |
114 | Token = "";\r | |
115 | }\r | |
116 | if (Module == NULL) {\r | |
117 | Module = "";\r | |
118 | }\r | |
119 | NumberOfEntries = PeiPerformanceLog->NumberOfEntries;\r | |
120 | LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r | |
121 | \r | |
122 | for (Index = 0; Index < NumberOfEntries; Index++) {\r | |
123 | if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r | |
124 | AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r | |
125 | AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r | |
126 | LogEntryArray[Index].EndTimeStamp == 0\r | |
127 | ) {\r | |
128 | break;\r | |
129 | }\r | |
130 | }\r | |
131 | return Index;\r | |
132 | }\r | |
133 | \r | |
134 | /**\r | |
135 | Creates a record for the beginning of a performance measurement.\r | |
136 | \r | |
137 | Creates a record that contains the Handle, Token, and Module.\r | |
138 | If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r | |
139 | If TimeStamp is zero, then this function reads the current time stamp\r | |
140 | and adds that time stamp value to the record as the start time.\r | |
141 | \r | |
142 | @param Handle Pointer to environment specific context used\r | |
143 | to identify the component being measured.\r | |
144 | @param Token Pointer to a Null-terminated ASCII string\r | |
145 | that identifies the component being measured.\r | |
146 | @param Module Pointer to a Null-terminated ASCII string\r | |
147 | that identifies the module being measured.\r | |
148 | @param TimeStamp 64-bit time stamp.\r | |
149 | \r | |
150 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
151 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
152 | \r | |
153 | **/\r | |
154 | RETURN_STATUS\r | |
155 | EFIAPI\r | |
156 | StartPerformanceMeasurement (\r | |
157 | IN CONST VOID *Handle, OPTIONAL\r | |
158 | IN CONST CHAR8 *Token, OPTIONAL\r | |
159 | IN CONST CHAR8 *Module, OPTIONAL\r | |
160 | IN UINT64 TimeStamp\r | |
161 | )\r | |
162 | {\r | |
163 | PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r | |
164 | PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r | |
165 | UINT32 Index;\r | |
166 | \r | |
167 | PeiPerformanceLog = InternalGetPerformanceHobLog ();\r | |
168 | \r | |
169 | if (PeiPerformanceLog->NumberOfEntries >= PcdGet8 (PcdMaxPeiPerformanceLogEntries)) {\r | |
170 | return RETURN_OUT_OF_RESOURCES;\r | |
171 | }\r | |
172 | Index = PeiPerformanceLog->NumberOfEntries++;\r | |
173 | LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r | |
174 | LogEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r | |
175 | \r | |
176 | if (Token != NULL) {\r | |
177 | AsciiStrnCpy (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH);\r | |
178 | }\r | |
179 | if (Module != NULL) {\r | |
180 | AsciiStrnCpy (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH);\r | |
181 | }\r | |
182 | \r | |
183 | if (TimeStamp == 0) {\r | |
184 | TimeStamp = GetPerformanceCounter ();\r | |
185 | }\r | |
186 | LogEntryArray[Index].StartTimeStamp = TimeStamp;\r | |
187 | \r | |
188 | return RETURN_SUCCESS;\r | |
189 | }\r | |
190 | \r | |
191 | /**\r | |
192 | Fills in the end time of a performance measurement.\r | |
193 | \r | |
194 | Looks up the record that matches Handle, Token, and Module.\r | |
195 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
196 | If the record is found and TimeStamp is not zero,\r | |
197 | then TimeStamp is added to the record as the end time.\r | |
198 | If the record is found and TimeStamp is zero, then this function reads\r | |
199 | the current time stamp and adds that time stamp value to the record as the end time.\r | |
200 | If this function is called multiple times for the same record, then the end time is overwritten.\r | |
201 | \r | |
202 | @param Handle Pointer to environment specific context used\r | |
203 | to identify the component being measured.\r | |
204 | @param Token Pointer to a Null-terminated ASCII string\r | |
205 | that identifies the component being measured.\r | |
206 | @param Module Pointer to a Null-terminated ASCII string\r | |
207 | that identifies the module being measured.\r | |
208 | @param TimeStamp 64-bit time stamp.\r | |
209 | \r | |
210 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
211 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
212 | \r | |
213 | **/\r | |
214 | RETURN_STATUS\r | |
215 | EFIAPI\r | |
216 | EndPerformanceMeasurement (\r | |
217 | IN CONST VOID *Handle, OPTIONAL\r | |
218 | IN CONST CHAR8 *Token, OPTIONAL\r | |
219 | IN CONST CHAR8 *Module, OPTIONAL\r | |
220 | IN UINT64 TimeStamp\r | |
221 | )\r | |
222 | {\r | |
223 | PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r | |
224 | PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r | |
225 | UINT32 Index;\r | |
226 | \r | |
227 | if (TimeStamp == 0) {\r | |
228 | TimeStamp = GetPerformanceCounter ();\r | |
229 | }\r | |
230 | \r | |
231 | PeiPerformanceLog = InternalGetPerformanceHobLog ();\r | |
232 | Index = InternalSearchForLogEntry (PeiPerformanceLog, Handle, Token, Module);\r | |
233 | if (Index >= PeiPerformanceLog->NumberOfEntries) {\r | |
234 | return RETURN_NOT_FOUND;\r | |
235 | }\r | |
236 | LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r | |
237 | LogEntryArray[Index].EndTimeStamp = TimeStamp;\r | |
238 | \r | |
239 | return RETURN_SUCCESS;\r | |
240 | }\r | |
241 | \r | |
242 | /**\r | |
243 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
244 | \r | |
245 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r | |
246 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
247 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
248 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
249 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
250 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
251 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
252 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
253 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
254 | the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r | |
255 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r | |
256 | If Handle is NULL, then ASSERT().\r | |
257 | If Token is NULL, then ASSERT().\r | |
258 | If Module is NULL, then ASSERT().\r | |
259 | If StartTimeStamp is NULL, then ASSERT().\r | |
260 | If EndTimeStamp is NULL, then ASSERT().\r | |
261 | \r | |
262 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
263 | 0, then the first performance measurement log entry is retrieved.\r | |
264 | On exit, the key of the next performance lof entry entry.\r | |
265 | @param Handle Pointer to environment specific context used to identify the component\r | |
266 | being measured.\r | |
267 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
268 | being measured.\r | |
269 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
270 | being measured.\r | |
271 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
272 | was started.\r | |
273 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
274 | was ended.\r | |
275 | \r | |
276 | @return The key for the next performance log entry (in general case).\r | |
277 | \r | |
278 | **/\r | |
279 | UINTN\r | |
280 | EFIAPI\r | |
281 | GetPerformanceMeasurement (\r | |
282 | IN UINTN LogEntryKey,\r | |
283 | OUT CONST VOID **Handle,\r | |
284 | OUT CONST CHAR8 **Token,\r | |
285 | OUT CONST CHAR8 **Module,\r | |
286 | OUT UINT64 *StartTimeStamp,\r | |
287 | OUT UINT64 *EndTimeStamp\r | |
288 | )\r | |
289 | {\r | |
290 | PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r | |
291 | PEI_PERFORMANCE_LOG_ENTRY *CurrentLogEntry;\r | |
292 | PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r | |
293 | UINTN NumberOfEntries;\r | |
294 | \r | |
295 | ASSERT (Handle != NULL);\r | |
296 | ASSERT (Token != NULL);\r | |
297 | ASSERT (Module != NULL);\r | |
298 | ASSERT (StartTimeStamp != NULL);\r | |
299 | ASSERT (EndTimeStamp != NULL);\r | |
300 | \r | |
301 | PeiPerformanceLog = InternalGetPerformanceHobLog ();\r | |
302 | \r | |
303 | NumberOfEntries = (UINTN) (PeiPerformanceLog->NumberOfEntries);\r | |
304 | LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r | |
305 | //\r | |
306 | // Make sure that LogEntryKey is a valid log entry key.\r | |
307 | //\r | |
308 | ASSERT (LogEntryKey <= NumberOfEntries);\r | |
309 | \r | |
310 | if (LogEntryKey == NumberOfEntries) {\r | |
311 | return 0;\r | |
312 | }\r | |
313 | \r | |
314 | CurrentLogEntry = &(LogEntryArray[LogEntryKey++]);\r | |
315 | \r | |
316 | *Handle = (VOID *) (UINTN) (CurrentLogEntry->Handle);\r | |
317 | *Token = CurrentLogEntry->Token;\r | |
318 | *Module = CurrentLogEntry->Module;\r | |
319 | *StartTimeStamp = CurrentLogEntry->StartTimeStamp;\r | |
320 | *EndTimeStamp = CurrentLogEntry->EndTimeStamp;\r | |
321 | \r | |
322 | return LogEntryKey;\r | |
323 | }\r | |
324 | \r | |
325 | /**\r | |
326 | Returns TRUE if the performance measurement macros are enabled.\r | |
327 | \r | |
328 | This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
329 | PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r | |
330 | \r | |
331 | @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
332 | PcdPerformanceLibraryPropertyMask is set.\r | |
333 | @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
334 | PcdPerformanceLibraryPropertyMask is clear.\r | |
335 | \r | |
336 | **/\r | |
337 | BOOLEAN\r | |
338 | EFIAPI\r | |
339 | PerformanceMeasurementEnabled (\r | |
340 | VOID\r | |
341 | )\r | |
342 | {\r | |
343 | return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r | |
344 | }\r |