3 Copyright (c) 2004 - 2005, 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.
18 Support for performance primitives.
27 #include EFI_GUID_DEFINITION (PeiPerformanceHob)
30 // Perfomance HOB data definitions
33 #define MAX_PEI_PERF_LOG_ENTRIES 28
36 // Prototype functions
40 OUT UINT64
*TimerValue
46 EFI_PEI_SERVICES
**PeiServices
,
48 IN EFI_FFS_FILE_HEADER
*FileHeader
,
56 Log a timestamp count.
60 PeiServices - Pointer to the PEI Core Services table
62 Token - Pointer to Token Name
64 FileHeader - Pointer to the file header
66 EntryExit - Indicates start or stop measurement
68 Value - The start time or the stop time
75 EFI_HOB_GUID_TYPE
*Hob
;
76 EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*PerfHobData
;
77 PEI_PERFORMANCE_MEASURE_LOG_ENTRY
*Log
;
78 EFI_PEI_PPI_DESCRIPTOR
*PerfHobDescriptor
;
87 // Get the END time as early as possible to make it more accurate.
90 GetTimerValue (&TimeCount
);
94 // Locate the Pei Performance Log Hob.
96 Status
= (*PeiServices
)->LocatePpi (
98 &gEfiPeiPerformanceHobGuid
,
105 // If the Performance Hob was not found, build and install one.
107 if (EFI_ERROR(Status
)) {
108 Status
= PeiBuildHobGuid (
110 &gEfiPeiPerformanceHobGuid
,
111 (sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG
) +
112 ((MAX_PEI_PERF_LOG_ENTRIES
-1) *
113 sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
)) +
114 sizeof(EFI_PEI_PPI_DESCRIPTOR
)
118 ASSERT_PEI_ERROR(PeiServices
, Status
);
120 PerfHobData
= (EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*)(Hob
+1);
121 PerfHobData
->NumberOfEntries
= 0;
123 PerfHobDescriptor
= (EFI_PEI_PPI_DESCRIPTOR
*)((UINT8
*)(PerfHobData
+1) +
124 (sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
) *
125 (MAX_PEI_PERF_LOG_ENTRIES
-1)
128 PerfHobDescriptor
->Flags
= (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
129 PerfHobDescriptor
->Guid
= &gEfiPeiPerformanceHobGuid
;
130 PerfHobDescriptor
->Ppi
= NULL
;
132 (*PeiServices
)->InstallPpi (
138 PerfHobData
= (EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*)(((UINT8
*)(PerfHobDescriptor
)) -
139 ((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
) *
140 (MAX_PEI_PERF_LOG_ENTRIES
-1)
142 + sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG
)
146 if (PerfHobData
->NumberOfEntries
>= MAX_PEI_PERF_LOG_ENTRIES
) {
151 Log
= &(PerfHobData
->Log
[PerfHobData
->NumberOfEntries
]);
152 (*PeiServices
)->SetMem (Log
, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
), 0);
155 // If not NULL pointer, copy the file name
157 if (FileHeader
!= NULL
) {
158 Log
->Name
= FileHeader
->Name
;
162 // Copy the description string
164 (*PeiServices
)->CopyMem (
165 &(Log
->DescriptionString
),
167 (PEI_PERF_MAX_DESC_STRING
-1) * sizeof(UINT16
)
171 // Get the start time as late as possible to make it more accurate.
173 GetTimerValue (&TimeCount
);
176 // Record the time stamp.
179 Log
->StartTimeCount
= Value
;
181 Log
->StartTimeCount
= TimeCount
;
183 Log
->StopTimeCount
= 0;
186 // Increment the number of valid log entries.
188 PerfHobData
->NumberOfEntries
++;
192 for (Index
= PerfHobData
->NumberOfEntries
-1; Index
>= 0; Index
--) {
194 for (Index2
= 0; Index2
< PEI_PERF_MAX_DESC_STRING
; Index2
++) {
195 if (PerfHobData
->Log
[Index
].DescriptionString
[Index2
] == 0) {
196 Log
= &(PerfHobData
->Log
[Index
]);
199 if (PerfHobData
->Log
[Index
].DescriptionString
[Index2
] !=
205 if (FileHeader
!= NULL
) {
207 CheckGuid
= &(FileHeader
->Name
);
208 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
209 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
210 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
211 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
213 Log
->StopTimeCount
= Value
;
215 Log
->StopTimeCount
= TimeCount
;
221 Log
->StopTimeCount
= Value
;
223 Log
->StopTimeCount
= TimeCount
;