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
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.
23 Gets PEI the GUID HOB for PEI performance.
25 This internal function searches for the GUID HOB for PEI performance.
26 If that GUID HOB is not found, it will build a new one.
27 It returns the data area of that GUID HOB to record performance log.
29 @param Handle Pointer to environment specific context used
30 to identify the component being measured.
31 @param Token Pointer to a Null-terminated ASCII string
32 that identifies the component being measured.
33 @param Module Pointer to a Null-terminated ASCII string
34 that identifies the module being measured.
36 @retval The index of log entry in the array.
39 PEI_PERFORMANCE_LOG_HEADER
*
40 InternalGetPerformanceHobLog (
44 EFI_HOB_GUID_TYPE
*GuidHob
;
45 PEI_PERFORMANCE_LOG_HEADER
*PeiPerformanceLog
;
46 UINTN PeiPerformanceLogSize
;
48 GuidHob
= GetFirstGuidHob (&gPeiPerformanceHobGuid
);
50 if (GuidHob
!= NULL
) {
52 // PEI Performance HOB was found, then return the existing one.
54 PeiPerformanceLog
= GET_GUID_HOB_DATA (GuidHob
);
57 // PEI Performance HOB was not found, then build one.
59 PeiPerformanceLogSize
= sizeof (PEI_PERFORMANCE_LOG_HEADER
) +
60 sizeof (PEI_PERFORMANCE_LOG_ENTRY
) * PcdGet8 (PcdMaxPeiPerformanceLogEntries
);
61 PeiPerformanceLog
= BuildGuidHob (&gPeiPerformanceHobGuid
, PeiPerformanceLogSize
);
62 PeiPerformanceLog
= ZeroMem (PeiPerformanceLog
, PeiPerformanceLogSize
);
65 return PeiPerformanceLog
;
69 Searches in the log array with keyword Handle, Token and Module.
71 This internal function searches for the log entry in the log array.
72 If there is an entry that exactly matches the given key word triple
73 and its end time stamp is zero, then the index of that log entry is returned;
74 otherwise, the the number of log entries in the array is returned.
76 @param Handle Pointer to environment specific context used
77 to identify the component being measured.
78 @param Token Pointer to a Null-terminated ASCII string
79 that identifies the component being measured.
80 @param Module Pointer to a Null-terminated ASCII string
81 that identifies the module being measured.
83 @retval The index of log entry in the array.
87 InternalSearchForLogEntry (
88 IN PEI_PERFORMANCE_LOG_HEADER
*PeiPerformanceLog
,
89 IN CONST VOID
*Handle
, OPTIONAL
90 IN CONST CHAR8
*Token
, OPTIONAL
91 IN CONST CHAR8
*Module OPTIONAL
95 UINT32 NumberOfEntries
;
96 PEI_PERFORMANCE_LOG_ENTRY
*LogEntryArray
;
102 if (Module
== NULL
) {
105 NumberOfEntries
= PeiPerformanceLog
->NumberOfEntries
;
106 LogEntryArray
= (PEI_PERFORMANCE_LOG_ENTRY
*) (PeiPerformanceLog
+ 1);
108 for (Index
= 0; Index
< NumberOfEntries
; Index
++) {
109 if ((LogEntryArray
[Index
].Handle
== (EFI_PHYSICAL_ADDRESS
) (UINTN
) Handle
) &&
110 AsciiStrnCmp (LogEntryArray
[Index
].Token
, Token
, PEI_PERFORMANCE_STRING_LENGTH
) == 0 &&
111 AsciiStrnCmp (LogEntryArray
[Index
].Module
, Module
, PEI_PERFORMANCE_STRING_LENGTH
) == 0 &&
112 LogEntryArray
[Index
].EndTimeStamp
== 0
121 Creates a record for the beginning of a performance measurement.
123 Creates a record that contains the Handle, Token, and Module.
124 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
125 If TimeStamp is zero, then this function reads the current time stamp
126 and adds that time stamp value to the record as the start time.
128 @param Handle Pointer to environment specific context used
129 to identify the component being measured.
130 @param Token Pointer to a Null-terminated ASCII string
131 that identifies the component being measured.
132 @param Module Pointer to a Null-terminated ASCII string
133 that identifies the module being measured.
134 @param TimeStamp 64-bit time stamp.
136 @retval RETURN_SUCCESS The start of the measurement was recorded.
137 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
142 StartPerformanceMeasurement (
143 IN CONST VOID
*Handle
, OPTIONAL
144 IN CONST CHAR8
*Token
, OPTIONAL
145 IN CONST CHAR8
*Module
, OPTIONAL
149 PEI_PERFORMANCE_LOG_HEADER
*PeiPerformanceLog
;
150 PEI_PERFORMANCE_LOG_ENTRY
*LogEntryArray
;
153 PeiPerformanceLog
= InternalGetPerformanceHobLog ();
155 if (PeiPerformanceLog
->NumberOfEntries
>= PcdGet8 (PcdMaxPeiPerformanceLogEntries
)) {
156 return RETURN_OUT_OF_RESOURCES
;
158 Index
= PeiPerformanceLog
->NumberOfEntries
++;
159 LogEntryArray
= (PEI_PERFORMANCE_LOG_ENTRY
*) (PeiPerformanceLog
+ 1);
160 LogEntryArray
[Index
].Handle
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Handle
;
163 AsciiStrnCpy (LogEntryArray
[Index
].Token
, Token
, PEI_PERFORMANCE_STRING_LENGTH
);
165 if (Module
!= NULL
) {
166 AsciiStrnCpy (LogEntryArray
[Index
].Module
, Module
, PEI_PERFORMANCE_STRING_LENGTH
);
169 if (TimeStamp
== 0) {
170 TimeStamp
= GetPerformanceCounter ();
172 LogEntryArray
[Index
].StartTimeStamp
= TimeStamp
;
174 return RETURN_SUCCESS
;
178 Fills in the end time of a performance measurement.
180 Looks up the record that matches Handle, Token, and Module.
181 If the record can not be found then return RETURN_NOT_FOUND.
182 If the record is found and TimeStamp is not zero,
183 then TimeStamp is added to the record as the end time.
184 If the record is found and TimeStamp is zero, then this function reads
185 the current time stamp and adds that time stamp value to the record as the end time.
186 If this function is called multiple times for the same record, then the end time is overwritten.
188 @param Handle Pointer to environment specific context used
189 to identify the component being measured.
190 @param Token Pointer to a Null-terminated ASCII string
191 that identifies the component being measured.
192 @param Module Pointer to a Null-terminated ASCII string
193 that identifies the module being measured.
194 @param TimeStamp 64-bit time stamp.
196 @retval RETURN_SUCCESS The end of the measurement was recorded.
197 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
202 EndPerformanceMeasurement (
203 IN CONST VOID
*Handle
, OPTIONAL
204 IN CONST CHAR8
*Token
, OPTIONAL
205 IN CONST CHAR8
*Module
, OPTIONAL
209 PEI_PERFORMANCE_LOG_HEADER
*PeiPerformanceLog
;
210 PEI_PERFORMANCE_LOG_ENTRY
*LogEntryArray
;
213 if (TimeStamp
== 0) {
214 TimeStamp
= GetPerformanceCounter ();
217 PeiPerformanceLog
= InternalGetPerformanceHobLog ();
218 Index
= InternalSearchForLogEntry (PeiPerformanceLog
, Handle
, Token
, Module
);
219 if (Index
>= PeiPerformanceLog
->NumberOfEntries
) {
220 return RETURN_NOT_FOUND
;
222 LogEntryArray
= (PEI_PERFORMANCE_LOG_ENTRY
*) (PeiPerformanceLog
+ 1);
223 LogEntryArray
[Index
].EndTimeStamp
= TimeStamp
;
225 return RETURN_SUCCESS
;
229 Attempts to retrieve a performance measurement log entry from the performance measurement log.
231 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
232 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
233 and the key for the second entry in the log is returned. If the performance log is empty,
234 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
235 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
236 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
237 retrieved and an implementation specific non-zero key value that specifies the end of the performance
238 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
239 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
240 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
241 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
242 If Handle is NULL, then ASSERT().
243 If Token is NULL, then ASSERT().
244 If Module is NULL, then ASSERT().
245 If StartTimeStamp is NULL, then ASSERT().
246 If EndTimeStamp is NULL, then ASSERT().
248 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
249 0, then the first performance measurement log entry is retrieved.
250 On exit, the key of the next performance lof entry entry.
251 @param Handle Pointer to environment specific context used to identify the component
253 @param Token Pointer to a Null-terminated ASCII string that identifies the component
255 @param Module Pointer to a Null-terminated ASCII string that identifies the module
257 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
259 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
262 @return The key for the next performance log entry (in general case).
267 GetPerformanceMeasurement (
268 IN UINTN LogEntryKey
,
269 OUT CONST VOID
**Handle
,
270 OUT CONST CHAR8
**Token
,
271 OUT CONST CHAR8
**Module
,
272 OUT UINT64
*StartTimeStamp
,
273 OUT UINT64
*EndTimeStamp
276 PEI_PERFORMANCE_LOG_HEADER
*PeiPerformanceLog
;
277 PEI_PERFORMANCE_LOG_ENTRY
*CurrentLogEntry
;
278 PEI_PERFORMANCE_LOG_ENTRY
*LogEntryArray
;
279 UINTN NumberOfEntries
;
281 ASSERT (Handle
!= NULL
);
282 ASSERT (Token
!= NULL
);
283 ASSERT (Module
!= NULL
);
284 ASSERT (StartTimeStamp
!= NULL
);
285 ASSERT (EndTimeStamp
!= NULL
);
287 PeiPerformanceLog
= InternalGetPerformanceHobLog ();
289 NumberOfEntries
= (UINTN
) (PeiPerformanceLog
->NumberOfEntries
);
290 LogEntryArray
= (PEI_PERFORMANCE_LOG_ENTRY
*) (PeiPerformanceLog
+ 1);
292 // Make sure that LogEntryKey is a valid log entry key.
294 ASSERT (LogEntryKey
<= NumberOfEntries
);
296 if (LogEntryKey
== NumberOfEntries
) {
300 CurrentLogEntry
= &(LogEntryArray
[LogEntryKey
++]);
302 *Handle
= (VOID
*) (UINTN
) (CurrentLogEntry
->Handle
);
303 *Token
= CurrentLogEntry
->Token
;
304 *Module
= CurrentLogEntry
->Module
;
305 *StartTimeStamp
= CurrentLogEntry
->StartTimeStamp
;
306 *EndTimeStamp
= CurrentLogEntry
->EndTimeStamp
;
312 Returns TRUE if the performance measurement macros are enabled.
314 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
315 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
317 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
318 PcdPerformanceLibraryPropertyMask is set.
319 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
320 PcdPerformanceLibraryPropertyMask is clear.
325 PerformanceMeasurementEnabled (
329 return ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);