3 Copyright (c) 2004 - 2008, 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.
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
47 EFI_PEI_SERVICES
**PeiServices
,
49 IN EFI_FFS_FILE_HEADER
*FileHeader
,
57 Log a timestamp count.
61 PeiServices - Pointer to the PEI Core Services table
63 Token - Pointer to Token Name
65 FileHeader - Pointer to the file header
67 EntryExit - Indicates start or stop measurement
69 Value - The start time or the stop time
76 EFI_HOB_GUID_TYPE
*Hob
;
77 EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*PerfHobData
;
78 PEI_PERFORMANCE_MEASURE_LOG_ENTRY
*Log
;
79 EFI_PEI_PPI_DESCRIPTOR
*PerfHobDescriptor
;
88 // Get the END time as early as possible to make it more accurate.
91 GetTimerValue (&TimeCount
);
95 // Locate the Pei Performance Log Hob.
97 Status
= (*PeiServices
)->LocatePpi (
99 &gEfiPeiPerformanceHobGuid
,
106 // If the Performance Hob was not found, build and install one.
108 if (EFI_ERROR(Status
)) {
109 Status
= PeiBuildHobGuid (
111 &gEfiPeiPerformanceHobGuid
,
112 (sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG
) +
113 ((MAX_PEI_PERF_LOG_ENTRIES
-1) *
114 sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
)) +
115 sizeof(EFI_PEI_PPI_DESCRIPTOR
)
119 ASSERT_PEI_ERROR((CONST EFI_PEI_SERVICES
**) PeiServices
, Status
);
121 PerfHobData
= (EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*)(Hob
+1);
122 PerfHobData
->NumberOfEntries
= 0;
124 PerfHobDescriptor
= (EFI_PEI_PPI_DESCRIPTOR
*)((UINT8
*)(PerfHobData
+1) +
125 (sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
) *
126 (MAX_PEI_PERF_LOG_ENTRIES
-1)
129 PerfHobDescriptor
->Flags
= (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
130 PerfHobDescriptor
->Guid
= &gEfiPeiPerformanceHobGuid
;
131 PerfHobDescriptor
->Ppi
= NULL
;
133 (*PeiServices
)->InstallPpi (
139 PerfHobData
= (EFI_HOB_GUID_DATA_PERFORMANCE_LOG
*)(((UINT8
*)(PerfHobDescriptor
)) -
140 ((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
) *
141 (MAX_PEI_PERF_LOG_ENTRIES
-1)
143 + sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG
)
147 if (PerfHobData
->NumberOfEntries
>= MAX_PEI_PERF_LOG_ENTRIES
) {
152 Log
= &(PerfHobData
->Log
[PerfHobData
->NumberOfEntries
]);
153 (*PeiServices
)->SetMem (Log
, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY
), 0);
156 // If not NULL pointer, copy the file name
158 if (FileHeader
!= NULL
) {
159 Log
->Name
= FileHeader
->Name
;
163 // Copy the description string
165 (*PeiServices
)->CopyMem (
166 &(Log
->DescriptionString
),
168 (PEI_PERF_MAX_DESC_STRING
-1) * sizeof(UINT16
)
172 // Get the start time as late as possible to make it more accurate.
174 GetTimerValue (&TimeCount
);
177 // Record the time stamp.
180 Log
->StartTimeCount
= Value
;
182 Log
->StartTimeCount
= TimeCount
;
184 Log
->StopTimeCount
= 0;
187 // Increment the number of valid log entries.
189 PerfHobData
->NumberOfEntries
++;
193 for (Index
= PerfHobData
->NumberOfEntries
-1; Index
>= 0; Index
--) {
195 for (Index2
= 0; Index2
< PEI_PERF_MAX_DESC_STRING
; Index2
++) {
196 if (PerfHobData
->Log
[Index
].DescriptionString
[Index2
] == 0) {
197 Log
= &(PerfHobData
->Log
[Index
]);
200 if (PerfHobData
->Log
[Index
].DescriptionString
[Index2
] !=
206 if (FileHeader
!= NULL
) {
208 CheckGuid
= &(FileHeader
->Name
);
209 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
210 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
211 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
212 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
214 Log
->StopTimeCount
= Value
;
216 Log
->StopTimeCount
= TimeCount
;
222 Log
->StopTimeCount
= Value
;
224 Log
->StopTimeCount
= TimeCount
;