]>
Commit | Line | Data |
---|---|---|
d042c6e8 | 1 | /** @file\r |
2 | Performance library instance used in DXE phase to dump SMM performance data.\r | |
3 | \r | |
4 | This library instance allows a DXE driver or UEFI application to dump the SMM performance data.\r | |
5 | StartPerformanceMeasurement() and EndPerformanceMeasurement() are not implemented.\r | |
6 | \r | |
3dffec12 | 7 | Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r |
d042c6e8 | 8 | This program and the accompanying materials\r |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | \r | |
19 | #include <PiDxe.h>\r | |
20 | \r | |
21 | #include <Guid/Performance.h>\r | |
22 | \r | |
23 | #include <Library/PerformanceLib.h>\r | |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/UefiBootServicesTableLib.h>\r | |
26 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
27 | #include <Library/PcdLib.h>\r | |
28 | #include <Library/BaseMemoryLib.h>\r | |
29 | #include <Library/BaseLib.h>\r | |
30 | #include <Library/MemoryAllocationLib.h>\r | |
31 | \r | |
32 | #include <Protocol/SmmCommunication.h>\r | |
33 | \r | |
34 | #define SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof (SMM_PERF_COMMUNICATE))\r | |
35 | //\r | |
36 | // The cached performance protocol interface.\r | |
37 | //\r | |
38 | EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r | |
39 | UINT8 mSmmPerformanceBuffer[SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE];\r | |
40 | GAUGE_DATA_ENTRY *mGaugeData = NULL;\r | |
41 | UINTN mGaugeNumberOfEntries = 0;\r | |
42 | \r | |
43 | \r | |
44 | /**\r | |
45 | The constructor function caches the pointer to SMM Communication protocol.\r | |
46 | \r | |
47 | The constructor function locates Performance protocol from protocol database.\r | |
48 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r | |
49 | \r | |
50 | @retval EFI_SUCCESS Performance protocol is successfully located.\r | |
51 | @retval Other Performance protocol is not located to log performance.\r | |
52 | \r | |
53 | **/\r | |
54 | EFI_STATUS\r | |
55 | GetCommunicationProtocol (\r | |
56 | VOID\r | |
57 | )\r | |
58 | {\r | |
59 | EFI_STATUS Status;\r | |
60 | EFI_SMM_COMMUNICATION_PROTOCOL *Communication;\r | |
61 | \r | |
62 | if (mSmmCommunication != NULL) {\r | |
63 | return EFI_SUCCESS;\r | |
64 | }\r | |
65 | \r | |
66 | Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r | |
67 | if (!EFI_ERROR (Status)) {\r | |
68 | ASSERT (Communication != NULL);\r | |
69 | //\r | |
70 | // Cache SMM Communication protocol.\r | |
71 | //\r | |
72 | mSmmCommunication = Communication;\r | |
73 | }\r | |
74 | \r | |
75 | return Status;\r | |
76 | }\r | |
77 | \r | |
78 | /**\r | |
79 | Creates a record for the beginning of a performance measurement.\r | |
80 | \r | |
81 | Creates a record that contains the Handle, Token, and Module.\r | |
82 | If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r | |
83 | If TimeStamp is zero, then this function reads the current time stamp\r | |
84 | and adds that time stamp value to the record as the start time.\r | |
85 | \r | |
86 | @param Handle Pointer to environment specific context used\r | |
87 | to identify the component being measured.\r | |
88 | @param Token Pointer to a Null-terminated ASCII string\r | |
89 | that identifies the component being measured.\r | |
90 | @param Module Pointer to a Null-terminated ASCII string\r | |
91 | that identifies the module being measured.\r | |
92 | @param TimeStamp 64-bit time stamp.\r | |
93 | \r | |
94 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
95 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
96 | \r | |
97 | **/\r | |
98 | RETURN_STATUS\r | |
99 | EFIAPI\r | |
100 | StartPerformanceMeasurement (\r | |
101 | IN CONST VOID *Handle, OPTIONAL\r | |
102 | IN CONST CHAR8 *Token, OPTIONAL\r | |
103 | IN CONST CHAR8 *Module, OPTIONAL\r | |
104 | IN UINT64 TimeStamp\r | |
105 | )\r | |
106 | {\r | |
107 | return EFI_UNSUPPORTED;\r | |
108 | }\r | |
109 | \r | |
110 | /**\r | |
111 | Fills in the end time of a performance measurement.\r | |
112 | \r | |
113 | Looks up the record that matches Handle, Token, and Module.\r | |
114 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
115 | If the record is found and TimeStamp is not zero,\r | |
116 | then TimeStamp is added to the record as the end time.\r | |
117 | If the record is found and TimeStamp is zero, then this function reads\r | |
118 | the current time stamp and adds that time stamp value to the record as the end time.\r | |
d042c6e8 | 119 | \r |
120 | @param Handle Pointer to environment specific context used\r | |
121 | to identify the component being measured.\r | |
122 | @param Token Pointer to a Null-terminated ASCII string\r | |
123 | that identifies the component being measured.\r | |
124 | @param Module Pointer to a Null-terminated ASCII string\r | |
125 | that identifies the module being measured.\r | |
126 | @param TimeStamp 64-bit time stamp.\r | |
127 | \r | |
128 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
129 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
130 | \r | |
131 | **/\r | |
132 | RETURN_STATUS\r | |
133 | EFIAPI\r | |
134 | EndPerformanceMeasurement (\r | |
135 | IN CONST VOID *Handle, OPTIONAL\r | |
136 | IN CONST CHAR8 *Token, OPTIONAL\r | |
137 | IN CONST CHAR8 *Module, OPTIONAL\r | |
138 | IN UINT64 TimeStamp\r | |
139 | )\r | |
140 | {\r | |
141 | return EFI_UNSUPPORTED;\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Retrieves all previous logged performance measurement.\r | |
146 | Function will use SMM communicate protocol to get all previous SMM performance measurement data.\r | |
147 | If success, data buffer will be returned. If fail function will return NULL.\r | |
148 | \r | |
149 | @retval !NULL Get all gauge data success.\r | |
150 | @retval NULL Get all guage data failed.\r | |
151 | **/\r | |
152 | GAUGE_DATA_ENTRY*\r | |
153 | EFIAPI\r | |
154 | GetAllSmmGaugeData (VOID)\r | |
155 | {\r | |
156 | EFI_STATUS Status;\r | |
157 | EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;\r | |
158 | SMM_PERF_COMMUNICATE *SmmPerfCommData;\r | |
159 | UINTN CommSize;\r | |
160 | UINTN DataSize;\r | |
161 | \r | |
162 | if (mGaugeData != NULL) {\r | |
163 | return mGaugeData;\r | |
164 | }\r | |
165 | \r | |
166 | Status = GetCommunicationProtocol ();\r | |
167 | if (EFI_ERROR (Status)) {\r | |
168 | return NULL;\r | |
169 | }\r | |
170 | \r | |
171 | //\r | |
172 | // Initialize communicate buffer \r | |
173 | //\r | |
174 | SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)mSmmPerformanceBuffer;\r | |
175 | SmmPerfCommData = (SMM_PERF_COMMUNICATE*)SmmCommBufferHeader->Data;\r | |
176 | ZeroMem((UINT8*)SmmPerfCommData, sizeof(SMM_PERF_COMMUNICATE));\r | |
177 | \r | |
178 | CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gSmmPerformanceProtocolGuid);\r | |
179 | SmmCommBufferHeader->MessageLength = sizeof(SMM_PERF_COMMUNICATE);\r | |
180 | CommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_PERF_COMMUNICATE);\r | |
181 | \r | |
182 | //\r | |
183 | // Get totol number of SMM gauge entries\r | |
184 | //\r | |
185 | SmmPerfCommData->Function = SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER;\r | |
186 | Status = mSmmCommunication->Communicate (mSmmCommunication, mSmmPerformanceBuffer, &CommSize);\r | |
187 | ASSERT_EFI_ERROR (Status);\r | |
188 | \r | |
189 | if (EFI_ERROR (SmmPerfCommData->ReturnStatus) || SmmPerfCommData->NumberOfEntries == 0) {\r | |
190 | return NULL;\r | |
191 | }\r | |
192 | \r | |
193 | mGaugeNumberOfEntries = SmmPerfCommData->NumberOfEntries;\r | |
194 | \r | |
195 | DataSize = mGaugeNumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r | |
196 | mGaugeData = AllocateZeroPool(DataSize);\r | |
197 | ASSERT_EFI_ERROR (Status);\r | |
198 | \r | |
199 | //\r | |
200 | // Get all SMM gauge data\r | |
201 | // \r | |
202 | SmmPerfCommData->Function = SMM_PERF_FUNCTION_GET_GAUGE_DATA;\r | |
203 | SmmPerfCommData->LogEntryKey = 0;\r | |
204 | SmmPerfCommData->NumberOfEntries = mGaugeNumberOfEntries;\r | |
205 | SmmPerfCommData->GaugeData = mGaugeData;\r | |
206 | Status = mSmmCommunication->Communicate (mSmmCommunication, mSmmPerformanceBuffer, &CommSize);\r | |
207 | ASSERT_EFI_ERROR (Status);\r | |
208 | ASSERT_EFI_ERROR(SmmPerfCommData->ReturnStatus);\r | |
209 | \r | |
210 | return mGaugeData; \r | |
211 | }\r | |
212 | \r | |
213 | /**\r | |
214 | Retrieves a previously logged performance measurement.\r | |
215 | \r | |
216 | Retrieves the performance log entry from the performance log specified by LogEntryKey.\r | |
217 | If it stands for a valid entry, then EFI_SUCCESS is returned and\r | |
218 | GaugeDataEntry stores the pointer to that entry.\r | |
219 | \r | |
220 | @param LogEntryKey The key for the previous performance measurement log entry.\r | |
221 | If 0, then the first performance measurement log entry is retrieved.\r | |
222 | @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r | |
223 | if the retrieval is successful.\r | |
224 | \r | |
225 | @retval EFI_SUCCESS The GuageDataEntry is successfully found based on LogEntryKey.\r | |
226 | @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r | |
227 | @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r | |
228 | @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r | |
229 | \r | |
230 | **/\r | |
231 | EFI_STATUS\r | |
232 | EFIAPI\r | |
233 | GetGauge (\r | |
234 | IN UINTN LogEntryKey,\r | |
235 | OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r | |
236 | )\r | |
237 | {\r | |
238 | if (LogEntryKey > mGaugeNumberOfEntries) {\r | |
239 | return EFI_INVALID_PARAMETER;\r | |
240 | }\r | |
241 | if (LogEntryKey == mGaugeNumberOfEntries) {\r | |
242 | return EFI_NOT_FOUND;\r | |
243 | }\r | |
244 | \r | |
245 | if (GaugeDataEntry == NULL) {\r | |
246 | return EFI_INVALID_PARAMETER;\r | |
247 | }\r | |
248 | *GaugeDataEntry = &mGaugeData[LogEntryKey];\r | |
249 | \r | |
250 | return EFI_SUCCESS;\r | |
251 | }\r | |
252 | \r | |
253 | /**\r | |
254 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
255 | \r | |
256 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r | |
257 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
258 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
259 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
260 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
261 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
262 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
263 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
264 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
265 | the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r | |
266 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r | |
267 | If Handle is NULL, then ASSERT().\r | |
268 | If Token is NULL, then ASSERT().\r | |
269 | If Module is NULL, then ASSERT().\r | |
270 | If StartTimeStamp is NULL, then ASSERT().\r | |
271 | If EndTimeStamp is NULL, then ASSERT().\r | |
272 | \r | |
273 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
274 | 0, then the first performance measurement log entry is retrieved.\r | |
275 | On exit, the key of the next performance log entry.\r | |
276 | @param Handle Pointer to environment specific context used to identify the component\r | |
277 | being measured.\r | |
278 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
279 | being measured.\r | |
280 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
281 | being measured.\r | |
282 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
283 | was started.\r | |
284 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
285 | was ended.\r | |
286 | \r | |
287 | @return The key for the next performance log entry (in general case).\r | |
288 | \r | |
289 | **/\r | |
290 | UINTN\r | |
291 | EFIAPI\r | |
292 | GetPerformanceMeasurement (\r | |
293 | IN UINTN LogEntryKey,\r | |
294 | OUT CONST VOID **Handle,\r | |
295 | OUT CONST CHAR8 **Token,\r | |
296 | OUT CONST CHAR8 **Module,\r | |
297 | OUT UINT64 *StartTimeStamp,\r | |
298 | OUT UINT64 *EndTimeStamp\r | |
299 | )\r | |
300 | {\r | |
301 | EFI_STATUS Status;\r | |
302 | GAUGE_DATA_ENTRY *GaugeData;\r | |
303 | \r | |
304 | GaugeData = NULL;\r | |
305 | \r | |
306 | ASSERT (Handle != NULL);\r | |
307 | ASSERT (Token != NULL);\r | |
308 | ASSERT (Module != NULL);\r | |
309 | ASSERT (StartTimeStamp != NULL);\r | |
310 | ASSERT (EndTimeStamp != NULL);\r | |
311 | \r | |
312 | mGaugeData = GetAllSmmGaugeData();\r | |
313 | if (mGaugeData == NULL) {\r | |
314 | return 0;\r | |
315 | }\r | |
316 | \r | |
317 | Status = GetGauge (LogEntryKey++, &GaugeData);\r | |
318 | \r | |
319 | //\r | |
320 | // Make sure that LogEntryKey is a valid log entry key,\r | |
321 | //\r | |
322 | ASSERT (Status != EFI_INVALID_PARAMETER);\r | |
323 | \r | |
324 | if (EFI_ERROR (Status)) {\r | |
325 | //\r | |
326 | // The LogEntryKey is the last entry (equals to the total entry number).\r | |
327 | //\r | |
328 | return 0;\r | |
329 | \r | |
330 | }\r | |
331 | \r | |
332 | ASSERT (GaugeData != NULL);\r | |
333 | \r | |
334 | *Handle = (VOID *) (UINTN) GaugeData->Handle;\r | |
335 | *Token = GaugeData->Token;\r | |
336 | *Module = GaugeData->Module;\r | |
337 | *StartTimeStamp = GaugeData->StartTimeStamp;\r | |
338 | *EndTimeStamp = GaugeData->EndTimeStamp;\r | |
339 | \r | |
340 | return LogEntryKey;\r | |
341 | }\r | |
342 | \r | |
343 | /**\r | |
344 | Returns TRUE if the performance measurement macros are enabled.\r | |
345 | \r | |
346 | This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
347 | PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r | |
348 | \r | |
349 | @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
350 | PcdPerformanceLibraryPropertyMask is set.\r | |
351 | @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
352 | PcdPerformanceLibraryPropertyMask is clear.\r | |
353 | \r | |
354 | **/\r | |
355 | BOOLEAN\r | |
356 | EFIAPI\r | |
357 | PerformanceMeasurementEnabled (\r | |
358 | VOID\r | |
359 | )\r | |
360 | {\r | |
361 | return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r | |
362 | }\r |