]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c
Changed TEMPORARY_RAM_SUPPORT_PPI to EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI.
[mirror_edk2.git] / MdeModulePkg / Library / SmmPerformanceLib / SmmPerformanceLib.c
CommitLineData
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
9 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
10This program and the accompanying materials\r
11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT 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
34PERFORMANCE_PROTOCOL *mPerformance = NULL;\r
35BOOLEAN 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
51EFI_STATUS\r
52EFIAPI\r
53SmmPerformanceLibConstructor (\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
74EFI_STATUS\r
75GetPerformanceProtocol (\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
118RETURN_STATUS\r
119EFIAPI\r
120StartPerformanceMeasurement (\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
148 If this function is called multiple times for the same record, then the end time is overwritten.\r
149\r
150 @param Handle Pointer to environment specific context used\r
151 to identify the component being measured.\r
152 @param Token Pointer to a Null-terminated ASCII string\r
153 that identifies the component being measured.\r
154 @param Module Pointer to a Null-terminated ASCII string\r
155 that identifies the module being measured.\r
156 @param TimeStamp 64-bit time stamp.\r
157\r
158 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
159 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
160\r
161**/\r
162RETURN_STATUS\r
163EFIAPI\r
164EndPerformanceMeasurement (\r
165 IN CONST VOID *Handle, OPTIONAL\r
166 IN CONST CHAR8 *Token, OPTIONAL\r
167 IN CONST CHAR8 *Module, OPTIONAL\r
168 IN UINT64 TimeStamp\r
169 )\r
170{\r
171 EFI_STATUS Status;\r
172\r
173 Status = GetPerformanceProtocol ();\r
174 if (EFI_ERROR (Status)) {\r
175 return RETURN_NOT_FOUND;\r
176 }\r
177\r
178 Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r
179\r
180 return (RETURN_STATUS) Status;\r
181}\r
182\r
183/**\r
184 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
185\r
186 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
187 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
188 and the key for the second entry in the log is returned. If the performance log is empty,\r
189 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
190 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
191 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
192 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
193 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
194 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
195 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
196 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
197 If Handle is NULL, then ASSERT().\r
198 If Token is NULL, then ASSERT().\r
199 If Module is NULL, then ASSERT().\r
200 If StartTimeStamp is NULL, then ASSERT().\r
201 If EndTimeStamp is NULL, then ASSERT().\r
202\r
203 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
204 0, then the first performance measurement log entry is retrieved.\r
205 On exit, the key of the next performance log entry.\r
206 @param Handle Pointer to environment specific context used to identify the component\r
207 being measured.\r
208 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
209 being measured.\r
210 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
211 being measured.\r
212 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
213 was started.\r
214 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
215 was ended.\r
216\r
217 @return The key for the next performance log entry (in general case).\r
218\r
219**/\r
220UINTN\r
221EFIAPI\r
222GetPerformanceMeasurement (\r
223 IN UINTN LogEntryKey,\r
224 OUT CONST VOID **Handle,\r
225 OUT CONST CHAR8 **Token,\r
226 OUT CONST CHAR8 **Module,\r
227 OUT UINT64 *StartTimeStamp,\r
228 OUT UINT64 *EndTimeStamp\r
229 )\r
230{\r
231 EFI_STATUS Status;\r
232 GAUGE_DATA_ENTRY *GaugeData;\r
233 \r
234 GaugeData = NULL;\r
235\r
236 ASSERT (Handle != NULL);\r
237 ASSERT (Token != NULL);\r
238 ASSERT (Module != NULL);\r
239 ASSERT (StartTimeStamp != NULL);\r
240 ASSERT (EndTimeStamp != NULL);\r
241\r
242 Status = GetPerformanceProtocol ();\r
243 if (EFI_ERROR (Status)) {\r
244 return 0;\r
245 }\r
246\r
247 Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);\r
248\r
249 //\r
250 // Make sure that LogEntryKey is a valid log entry key,\r
251 //\r
252 ASSERT (Status != EFI_INVALID_PARAMETER);\r
253\r
254 if (EFI_ERROR (Status)) {\r
255 //\r
256 // The LogEntryKey is the last entry (equals to the total entry number).\r
257 //\r
258 return 0;\r
259 }\r
260\r
261 ASSERT (GaugeData != NULL);\r
262\r
263 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
264 *Token = GaugeData->Token;\r
265 *Module = GaugeData->Module;\r
266 *StartTimeStamp = GaugeData->StartTimeStamp;\r
267 *EndTimeStamp = GaugeData->EndTimeStamp;\r
268\r
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
283BOOLEAN\r
284EFIAPI\r
285PerformanceMeasurementEnabled (\r
286 VOID\r
287 )\r
288{\r
289 return mPerformanceMeasurementEnabled;\r
290}\r