]>
Commit | Line | Data |
---|---|---|
d042c6e8 | 1 | /** @file\r |
2 | Performance Library used in SMM phase.\r | |
3 | \r | |
4 | This library instance provides infrastructure for SMM drivers to log performance\r | |
5 | data. It consumes SMM Performance Protocol published by SmmCorePerformanceLib\r | |
6 | to log performance data. If Performance Protocol is not available, it does not log any\r | |
7 | performance information.\r | |
8 | \r | |
3dffec12 | 9 | Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r |
d042c6e8 | 10 | This program and the accompanying materials\r |
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 | |
18 | **/\r | |
19 | \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/SmmServicesTableLib.h>\r | |
26 | #include <Library/PcdLib.h>\r | |
27 | #include <Library/BaseMemoryLib.h>\r | |
28 | \r | |
29 | #include <Protocol/SmmCommunication.h>\r | |
30 | \r | |
31 | //\r | |
32 | // The cached performance protocol interface.\r | |
33 | //\r | |
34 | PERFORMANCE_PROTOCOL *mPerformance = NULL;\r | |
35 | BOOLEAN mPerformanceMeasurementEnabled;\r | |
36 | \r | |
37 | \r | |
38 | /**\r | |
39 | The constructor function initializes Performance infrastructure for DXE phase.\r | |
40 | \r | |
41 | The constructor function publishes Performance protocol, allocates memory to log DXE performance\r | |
42 | and merges PEI performance data to DXE performance log.\r | |
43 | It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r | |
44 | \r | |
45 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
46 | @param SystemTable A pointer to the EFI System Table.\r | |
47 | \r | |
48 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
49 | \r | |
50 | **/\r | |
51 | EFI_STATUS\r | |
52 | EFIAPI\r | |
53 | SmmPerformanceLibConstructor (\r | |
54 | IN EFI_HANDLE ImageHandle,\r | |
55 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
56 | )\r | |
57 | {\r | |
58 | \r | |
59 | mPerformanceMeasurementEnabled = (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r | |
60 | \r | |
61 | return EFI_SUCCESS;\r | |
62 | }\r | |
63 | \r | |
64 | /**\r | |
65 | The constructor function caches the pointer to Performance protocol.\r | |
66 | \r | |
67 | The constructor function locates SMM erformance protocol from the SMM protocol database.\r | |
68 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r | |
69 | \r | |
70 | @retval EFI_SUCCESS Performance protocol is successfully located.\r | |
71 | @retval Other Performance protocol is not located to log performance.\r | |
72 | \r | |
73 | **/\r | |
74 | EFI_STATUS\r | |
75 | GetPerformanceProtocol (\r | |
76 | VOID\r | |
77 | )\r | |
78 | {\r | |
79 | EFI_STATUS Status;\r | |
80 | PERFORMANCE_PROTOCOL *Performance;\r | |
81 | \r | |
82 | if (mPerformance != NULL) {\r | |
83 | return EFI_SUCCESS;\r | |
84 | }\r | |
85 | \r | |
86 | Status = gSmst->SmmLocateProtocol (&gSmmPerformanceProtocolGuid, NULL, (VOID **) &Performance);\r | |
87 | if (!EFI_ERROR (Status)) {\r | |
88 | ASSERT (Performance != NULL);\r | |
89 | //\r | |
90 | // Cache performance protocol.\r | |
91 | //\r | |
92 | mPerformance = Performance;\r | |
93 | }\r | |
94 | \r | |
95 | return Status;\r | |
96 | }\r | |
97 | \r | |
98 | /**\r | |
99 | Creates a record for the beginning of a performance measurement.\r | |
100 | \r | |
101 | Creates a record that contains the Handle, Token, and Module.\r | |
102 | If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r | |
103 | If TimeStamp is zero, then this function reads the current time stamp\r | |
104 | and adds that time stamp value to the record as the start time.\r | |
105 | \r | |
106 | @param Handle Pointer to environment specific context used\r | |
107 | to identify the component being measured.\r | |
108 | @param Token Pointer to a Null-terminated ASCII string\r | |
109 | that identifies the component being measured.\r | |
110 | @param Module Pointer to a Null-terminated ASCII string\r | |
111 | that identifies the module being measured.\r | |
112 | @param TimeStamp 64-bit time stamp.\r | |
113 | \r | |
114 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
115 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
116 | \r | |
117 | **/\r | |
118 | RETURN_STATUS\r | |
119 | EFIAPI\r | |
120 | StartPerformanceMeasurement (\r | |
121 | IN CONST VOID *Handle, OPTIONAL\r | |
122 | IN CONST CHAR8 *Token, OPTIONAL\r | |
123 | IN CONST CHAR8 *Module, OPTIONAL\r | |
124 | IN UINT64 TimeStamp\r | |
125 | )\r | |
126 | {\r | |
127 | EFI_STATUS Status;\r | |
128 | \r | |
129 | Status = GetPerformanceProtocol ();\r | |
130 | if (EFI_ERROR (Status)) {\r | |
131 | return RETURN_OUT_OF_RESOURCES;\r | |
132 | }\r | |
133 | \r | |
134 | Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);\r | |
135 | \r | |
136 | return (RETURN_STATUS) Status;\r | |
137 | }\r | |
138 | \r | |
139 | /**\r | |
140 | Fills in the end time of a performance measurement.\r | |
141 | \r | |
142 | Looks up the record that matches Handle, Token, and Module.\r | |
143 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
144 | If the record is found and TimeStamp is not zero,\r | |
145 | then TimeStamp is added to the record as the end time.\r | |
146 | If the record is found and TimeStamp is zero, then this function reads\r | |
147 | the current time stamp and adds that time stamp value to the record as the end time.\r | |
d042c6e8 | 148 | \r |
149 | @param Handle Pointer to environment specific context used\r | |
150 | to identify the component being measured.\r | |
151 | @param Token Pointer to a Null-terminated ASCII string\r | |
152 | that identifies the component being measured.\r | |
153 | @param Module Pointer to a Null-terminated ASCII string\r | |
154 | that identifies the module being measured.\r | |
155 | @param TimeStamp 64-bit time stamp.\r | |
156 | \r | |
157 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
158 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
159 | \r | |
160 | **/\r | |
161 | RETURN_STATUS\r | |
162 | EFIAPI\r | |
163 | EndPerformanceMeasurement (\r | |
164 | IN CONST VOID *Handle, OPTIONAL\r | |
165 | IN CONST CHAR8 *Token, OPTIONAL\r | |
166 | IN CONST CHAR8 *Module, OPTIONAL\r | |
167 | IN UINT64 TimeStamp\r | |
168 | )\r | |
169 | {\r | |
170 | EFI_STATUS Status;\r | |
171 | \r | |
172 | Status = GetPerformanceProtocol ();\r | |
173 | if (EFI_ERROR (Status)) {\r | |
174 | return RETURN_NOT_FOUND;\r | |
175 | }\r | |
176 | \r | |
177 | Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r | |
178 | \r | |
179 | return (RETURN_STATUS) Status;\r | |
180 | }\r | |
181 | \r | |
182 | /**\r | |
183 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
184 | \r | |
185 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r | |
186 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
187 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
188 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
189 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
190 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
191 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
192 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
193 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
194 | the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r | |
195 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r | |
196 | If Handle is NULL, then ASSERT().\r | |
197 | If Token is NULL, then ASSERT().\r | |
198 | If Module is NULL, then ASSERT().\r | |
199 | If StartTimeStamp is NULL, then ASSERT().\r | |
200 | If EndTimeStamp is NULL, then ASSERT().\r | |
201 | \r | |
202 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
203 | 0, then the first performance measurement log entry is retrieved.\r | |
204 | On exit, the key of the next performance log entry.\r | |
205 | @param Handle Pointer to environment specific context used to identify the component\r | |
206 | being measured.\r | |
207 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
208 | being measured.\r | |
209 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
210 | being measured.\r | |
211 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
212 | was started.\r | |
213 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
214 | was ended.\r | |
215 | \r | |
216 | @return The key for the next performance log entry (in general case).\r | |
217 | \r | |
218 | **/\r | |
219 | UINTN\r | |
220 | EFIAPI\r | |
221 | GetPerformanceMeasurement (\r | |
222 | IN UINTN LogEntryKey,\r | |
223 | OUT CONST VOID **Handle,\r | |
224 | OUT CONST CHAR8 **Token,\r | |
225 | OUT CONST CHAR8 **Module,\r | |
226 | OUT UINT64 *StartTimeStamp,\r | |
227 | OUT UINT64 *EndTimeStamp\r | |
228 | )\r | |
229 | {\r | |
230 | EFI_STATUS Status;\r | |
231 | GAUGE_DATA_ENTRY *GaugeData;\r | |
232 | \r | |
233 | GaugeData = NULL;\r | |
234 | \r | |
235 | ASSERT (Handle != NULL);\r | |
236 | ASSERT (Token != NULL);\r | |
237 | ASSERT (Module != NULL);\r | |
238 | ASSERT (StartTimeStamp != NULL);\r | |
239 | ASSERT (EndTimeStamp != NULL);\r | |
240 | \r | |
241 | Status = GetPerformanceProtocol ();\r | |
242 | if (EFI_ERROR (Status)) {\r | |
243 | return 0;\r | |
244 | }\r | |
245 | \r | |
246 | Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);\r | |
247 | \r | |
248 | //\r | |
249 | // Make sure that LogEntryKey is a valid log entry key,\r | |
250 | //\r | |
251 | ASSERT (Status != EFI_INVALID_PARAMETER);\r | |
252 | \r | |
253 | if (EFI_ERROR (Status)) {\r | |
254 | //\r | |
255 | // The LogEntryKey is the last entry (equals to the total entry number).\r | |
256 | //\r | |
257 | return 0;\r | |
258 | }\r | |
259 | \r | |
260 | ASSERT (GaugeData != NULL);\r | |
261 | \r | |
262 | *Handle = (VOID *) (UINTN) GaugeData->Handle;\r | |
263 | *Token = GaugeData->Token;\r | |
264 | *Module = GaugeData->Module;\r | |
265 | *StartTimeStamp = GaugeData->StartTimeStamp;\r | |
266 | *EndTimeStamp = GaugeData->EndTimeStamp;\r | |
267 | \r | |
ae373a56 | 268 | return LogEntryKey;\r |
d042c6e8 | 269 | }\r |
270 | \r | |
271 | /**\r | |
272 | Returns TRUE if the performance measurement macros are enabled.\r | |
273 | \r | |
274 | This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
275 | PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r | |
276 | \r | |
277 | @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
278 | PcdPerformanceLibraryPropertyMask is set.\r | |
279 | @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
280 | PcdPerformanceLibraryPropertyMask is clear.\r | |
281 | \r | |
282 | **/\r | |
283 | BOOLEAN\r | |
284 | EFIAPI\r | |
285 | PerformanceMeasurementEnabled (\r | |
286 | VOID\r | |
287 | )\r | |
288 | {\r | |
289 | return mPerformanceMeasurementEnabled;\r | |
290 | }\r |