3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 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.
19 Support routines used by PEI_PERF_START() and PEI_PERF_END()
23 #include "EdkIIGluePeim.h"
26 #define MAX_PEI_PERF_LOG_ENTRIES 28
31 InternalGetTimerValue (
32 OUT UINT64
*TimerValue
38 Set TimerValue with current tick.
42 TimerValue - Timer value to be set
46 EFI_SUCCESS - TimerValue is set.
50 *TimerValue
= AsmReadTsc ();
57 EFI_PEI_SERVICES
**PeiServices
,
59 IN EFI_FFS_FILE_HEADER
*FileHeader
,
67 Log a timestamp count.
71 PeiServices - Pointer to the PEI Core Services table
73 Token - Pointer to Token Name
75 FileHeader - Pointer to the file header
77 EntryExit - Indicates start or stop measurement
79 Value - The start time or the stop time
86 EFI_HOB_GUID_TYPE
*Hob
;
87 EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*PerfHobData
;
88 PEI_PERFORMANCE_MEASURE_LOG_ENTRY
*Log
;
89 EFI_PEI_PPI_DESCRIPTOR
*PerfHobDescriptor
;
98 // Get the END time as early as possible to make it more accurate.
101 InternalGetTimerValue (&TimeCount
);
105 // Locate the Pei Performance Log Hob.
107 Status
= PeiServicesLocatePpi (
108 &gEfiPeiPerformanceHobGuid
,
115 // If the Performance Hob was not found, build and install one.
117 if (EFI_ERROR(Status
)) {
119 &gEfiPeiPerformanceHobGuid
,
120 (sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG
) +
121 ((MAX_PEI_PERF_LOG_ENTRIES
-1) *
122 sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
)) +
123 sizeof(EFI_PEI_PPI_DESCRIPTOR
)
125 Hob
= (VOID
*)((UINTN
)Hob
- sizeof (EFI_HOB_GUID_TYPE
));
126 ASSERT_EFI_ERROR (Status
);
128 PerfHobData
= (EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*)(Hob
+1);
129 PerfHobData
->NumberOfEntries
= 0;
131 PerfHobDescriptor
= (EFI_PEI_PPI_DESCRIPTOR
*)((UINT8
*)(PerfHobData
+1) +
132 (sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
) *
133 (MAX_PEI_PERF_LOG_ENTRIES
-1)
136 PerfHobDescriptor
->Flags
= (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
137 PerfHobDescriptor
->Guid
= &gEfiPeiPerformanceHobGuid
;
138 PerfHobDescriptor
->Ppi
= NULL
;
140 (*PeiServices
)->InstallPpi (
146 PerfHobData
= (EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*)(((UINT8
*)(PerfHobDescriptor
)) -
147 ((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
) *
148 (MAX_PEI_PERF_LOG_ENTRIES
-1)
150 + sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG
)
154 if (PerfHobData
->NumberOfEntries
>= MAX_PEI_PERF_LOG_ENTRIES
) {
159 Log
= &(PerfHobData
->Log
[PerfHobData
->NumberOfEntries
]);
160 ((*PeiServices
)->SetMem
) (Log
, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
), 0);
163 // If not NULL pointer, copy the file name
165 if (FileHeader
!= NULL
) {
166 Log
->Name
= FileHeader
->Name
;
170 // Copy the description string
172 ((*PeiServices
)->CopyMem
) (
173 &(Log
->DescriptionString
),
175 (PEI_PERF_MAX_DESC_STRING
-1) * sizeof(UINT16
)
179 // Get the start time as late as possible to make it more accurate.
181 InternalGetTimerValue (&TimeCount
);
184 // Record the time stamp.
187 Log
->StartTimeCount
= Value
;
189 Log
->StartTimeCount
= TimeCount
;
191 Log
->StopTimeCount
= 0;
194 // Increment the number of valid log entries.
196 PerfHobData
->NumberOfEntries
++;
200 for (Index
= PerfHobData
->NumberOfEntries
-1; Index
>= 0; Index
--) {
202 for (Index2
= 0; Index2
< PEI_PERF_MAX_DESC_STRING
; Index2
++) {
203 if (PerfHobData
->Log
[Index
].DescriptionString
[Index2
] == 0) {
204 Log
= &(PerfHobData
->Log
[Index
]);
207 if (PerfHobData
->Log
[Index
].DescriptionString
[Index2
] !=
213 if (FileHeader
!= NULL
) {
215 CheckGuid
= &(FileHeader
->Name
);
216 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
217 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
218 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
219 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
221 Log
->StopTimeCount
= Value
;
223 Log
->StopTimeCount
= TimeCount
;
229 Log
->StopTimeCount
= Value
;
231 Log
->StopTimeCount
= TimeCount
;