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
) * MAX_PEI_PERFORMANCE_LOG_ENTRIES
;
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
>= MAX_PEI_PERFORMANCE_LOG_ENTRIES
) {
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 Retrieves a previously logged performance measurement.
231 Looks up the record that matches Handle, Token, and Module.
232 If the record can not be found then return RETURN_NOT_FOUND.
233 If the record is found then the start of the measurement is returned in StartTimeStamp,
234 and the end of the measurement is returned in EndTimeStamp.
236 @param LogEntryKey The key for the previous performance measurement log entry.
237 If 0, then the first performance measurement log entry is retrieved.
238 @param Handle Pointer to environment specific context used
239 to identify the component being measured.
240 @param Token Pointer to a Null-terminated ASCII string
241 that identifies the component being measured.
242 @param Module Pointer to a Null-terminated ASCII string
243 that identifies the module being measured.
244 @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started.
245 @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended.
247 @return The key for the current performance log entry.
252 GetPerformanceMeasurement (
254 OUT CONST VOID
**Handle
,
255 OUT CONST CHAR8
**Token
,
256 OUT CONST CHAR8
**Module
,
257 OUT UINT64
*StartTimeStamp
,
258 OUT UINT64
*EndTimeStamp
261 PEI_PERFORMANCE_LOG_HEADER
*PeiPerformanceLog
;
262 PEI_PERFORMANCE_LOG_ENTRY
*CurrentLogEntry
;
263 PEI_PERFORMANCE_LOG_ENTRY
*LogEntryArray
;
264 UINTN NumberOfEntries
;
266 ASSERT (Handle
!= NULL
);
267 ASSERT (Token
!= NULL
);
268 ASSERT (Module
!= NULL
);
269 ASSERT (StartTimeStamp
!= NULL
);
270 ASSERT (EndTimeStamp
!= NULL
);
272 PeiPerformanceLog
= InternalGetPerformanceHobLog ();
274 NumberOfEntries
= (UINTN
) (PeiPerformanceLog
->NumberOfEntries
);
275 LogEntryArray
= (PEI_PERFORMANCE_LOG_ENTRY
*) (PeiPerformanceLog
+ 1);
277 // Make sure that LogEntryKey is a valid log entry key.
279 ASSERT (LogEntryKey
<= NumberOfEntries
);
281 if (LogEntryKey
== NumberOfEntries
) {
285 CurrentLogEntry
= &(LogEntryArray
[LogEntryKey
++]);
287 *Handle
= (VOID
*) (UINTN
) (CurrentLogEntry
->Handle
);
288 *Token
= CurrentLogEntry
->Token
;
289 *Module
= CurrentLogEntry
->Module
;
290 *StartTimeStamp
= CurrentLogEntry
->StartTimeStamp
;
291 *EndTimeStamp
= CurrentLogEntry
->EndTimeStamp
;
297 Returns TRUE if the performance measurement macros are enabled.
299 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
300 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
302 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
303 PcdPerformanceLibraryPropertyMask is set.
304 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
305 PcdPerformanceLibraryPropertyMask is clear.
310 PerformanceMeasurementEnabled (
314 return ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);