]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
Rename PcdPlatformBusSpeed to PcdFSBClock and update help text.
[mirror_edk2.git] / EdkModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 DxePerformanceLib.c
15
16 Abstract:
17
18 Performance Library
19
20 --*/
21
22 STATIC PERFORMANCE_PROTOCOL *mPerformance = NULL;
23
24 /**
25 The constructor function caches the pointer to Performance protocol.
26
27 The constructor function locates Performance protocol from protocol database.
28 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
29
30 @retval EFI_SUCCESS Performance protocol is successfully located.
31 @retval Other Performance protocol is not located to log performance.
32
33 **/
34 EFI_STATUS
35 GetPerformanceProtocol (
36 VOID
37 )
38 {
39 EFI_STATUS Status;
40 PERFORMANCE_PROTOCOL *Performance;
41
42 if (mPerformance != NULL) {
43 return EFI_SUCCESS;
44 }
45
46 Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &Performance);
47 if (!EFI_ERROR (Status)) {
48 ASSERT (Performance != NULL);
49 //
50 // Cache performance protocol.
51 //
52 mPerformance = Performance;
53 }
54
55 return Status;
56 }
57
58 /**
59 Creates a record for the beginning of a performance measurement.
60
61 Creates a record that contains the Handle, Token, and Module.
62 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
63 If TimeStamp is zero, then this function reads the current time stamp
64 and adds that time stamp value to the record as the start time.
65
66 @param Handle Pointer to environment specific context used
67 to identify the component being measured.
68 @param Token Pointer to a Null-terminated ASCII string
69 that identifies the component being measured.
70 @param Module Pointer to a Null-terminated ASCII string
71 that identifies the module being measured.
72 @param TimeStamp 64-bit time stamp.
73
74 @retval RETURN_SUCCESS The start of the measurement was recorded.
75 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
76
77 **/
78 RETURN_STATUS
79 EFIAPI
80 StartPerformanceMeasurement (
81 IN CONST VOID *Handle, OPTIONAL
82 IN CONST CHAR8 *Token, OPTIONAL
83 IN CONST CHAR8 *Module, OPTIONAL
84 IN UINT64 TimeStamp
85 )
86 {
87 EFI_STATUS Status;
88
89 Status = GetPerformanceProtocol ();
90 if (EFI_ERROR (Status)) {
91 return RETURN_OUT_OF_RESOURCES;
92 }
93
94 Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);
95
96 return (RETURN_STATUS) Status;
97 }
98
99 /**
100 Fills in the end time of a performance measurement.
101
102 Looks up the record that matches Handle, Token, and Module.
103 If the record can not be found then return RETURN_NOT_FOUND.
104 If the record is found and TimeStamp is not zero,
105 then TimeStamp is added to the record as the end time.
106 If the record is found and TimeStamp is zero, then this function reads
107 the current time stamp and adds that time stamp value to the record as the end time.
108 If this function is called multiple times for the same record, then the end time is overwritten.
109
110 @param Handle Pointer to environment specific context used
111 to identify the component being measured.
112 @param Token Pointer to a Null-terminated ASCII string
113 that identifies the component being measured.
114 @param Module Pointer to a Null-terminated ASCII string
115 that identifies the module being measured.
116 @param TimeStamp 64-bit time stamp.
117
118 @retval RETURN_SUCCESS The end of the measurement was recorded.
119 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
120
121 **/
122 RETURN_STATUS
123 EFIAPI
124 EndPerformanceMeasurement (
125 IN CONST VOID *Handle, OPTIONAL
126 IN CONST CHAR8 *Token, OPTIONAL
127 IN CONST CHAR8 *Module, OPTIONAL
128 IN UINT64 TimeStamp
129 )
130 {
131 EFI_STATUS Status;
132
133 Status = GetPerformanceProtocol ();
134 if (EFI_ERROR (Status)) {
135 return RETURN_NOT_FOUND;
136 }
137
138 Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);
139
140 return (RETURN_STATUS) Status;
141 }
142
143 /**
144 Attempts to retrieve a performance measurement log entry from the performance measurement log.
145
146 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
147 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
148 and the key for the second entry in the log is returned. If the performance log is empty,
149 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
150 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
151 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
152 retrieved and an implementation specific non-zero key value that specifies the end of the performance
153 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
154 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
155 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
156 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
157 If Handle is NULL, then ASSERT().
158 If Token is NULL, then ASSERT().
159 If Module is NULL, then ASSERT().
160 If StartTimeStamp is NULL, then ASSERT().
161 If EndTimeStamp is NULL, then ASSERT().
162
163 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
164 0, then the first performance measurement log entry is retrieved.
165 On exit, the key of the next performance lof entry entry.
166 @param Handle Pointer to environment specific context used to identify the component
167 being measured.
168 @param Token Pointer to a Null-terminated ASCII string that identifies the component
169 being measured.
170 @param Module Pointer to a Null-terminated ASCII string that identifies the module
171 being measured.
172 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
173 was started.
174 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
175 was ended.
176
177 @return The key for the next performance log entry (in general case).
178
179 **/
180 UINTN
181 EFIAPI
182 GetPerformanceMeasurement (
183 IN UINTN LogEntryKey,
184 OUT CONST VOID **Handle,
185 OUT CONST CHAR8 **Token,
186 OUT CONST CHAR8 **Module,
187 OUT UINT64 *StartTimeStamp,
188 OUT UINT64 *EndTimeStamp
189 )
190 {
191 EFI_STATUS Status;
192 GAUGE_DATA_ENTRY *GaugeData;
193
194 ASSERT (Handle != NULL);
195 ASSERT (Token != NULL);
196 ASSERT (Module != NULL);
197 ASSERT (StartTimeStamp != NULL);
198 ASSERT (EndTimeStamp != NULL);
199
200 Status = GetPerformanceProtocol ();
201 if (EFI_ERROR (Status)) {
202 return 0;
203 }
204
205 Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);
206
207 //
208 // Make sure that LogEntryKey is a valid log entry key,
209 //
210 ASSERT (Status != EFI_INVALID_PARAMETER);
211
212 if (EFI_ERROR (Status)) {
213 //
214 // The LogEntryKey is the last entry (equals to the total entry number).
215 //
216 return 0;
217 }
218
219 ASSERT (GaugeData != NULL);
220
221 *Handle = (VOID *) (UINTN) GaugeData->Handle;
222 *Token = GaugeData->Token;
223 *Module = GaugeData->Module;
224 *StartTimeStamp = GaugeData->StartTimeStamp;
225 *EndTimeStamp = GaugeData->EndTimeStamp;
226
227 return LogEntryKey;
228 }
229
230 /**
231 Returns TRUE if the performance measurement macros are enabled.
232
233 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
234 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
235
236 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
237 PcdPerformanceLibraryPropertyMask is set.
238 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
239 PcdPerformanceLibraryPropertyMask is clear.
240
241 **/
242 BOOLEAN
243 EFIAPI
244 PerformanceMeasurementEnabled (
245 VOID
246 )
247 {
248 return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
249 }