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