]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiPerformanceLib/PerformanceLib.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / PeiPerformanceLib / PerformanceLib.c
1 /*++
2
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
8
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.
11
12
13 Module Name:
14
15 PerformanceLib.c
16
17 Abstract:
18
19 Support routines used by PEI_PERF_START() and PEI_PERF_END()
20
21 --*/
22
23 #include "EdkIIGluePeim.h"
24
25
26 #define MAX_PEI_PERF_LOG_ENTRIES 28
27
28
29 STATIC
30 VOID
31 InternalGetTimerValue (
32 OUT UINT64 *TimerValue
33 )
34 /*++
35
36 Routine Description:
37
38 Set TimerValue with current tick.
39
40 Arguments:
41
42 TimerValue - Timer value to be set
43
44 Returns:
45
46 EFI_SUCCESS - TimerValue is set.
47
48 --*/
49 {
50 *TimerValue = AsmReadTsc ();
51 }
52
53
54 VOID
55 EFIAPI
56 PeiPerfMeasure (
57 EFI_PEI_SERVICES **PeiServices,
58 IN UINT16 *Token,
59 IN EFI_FFS_FILE_HEADER *FileHeader,
60 IN BOOLEAN EntryExit,
61 IN UINT64 Value
62 )
63 /*++
64
65 Routine Description:
66
67 Log a timestamp count.
68
69 Arguments:
70
71 PeiServices - Pointer to the PEI Core Services table
72
73 Token - Pointer to Token Name
74
75 FileHeader - Pointer to the file header
76
77 EntryExit - Indicates start or stop measurement
78
79 Value - The start time or the stop time
80
81 Returns:
82
83 --*/
84 {
85 EFI_STATUS Status;
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;
90 UINT64 TimeCount;
91 INTN Index;
92 UINTN Index2;
93 EFI_GUID *Guid;
94 EFI_GUID *CheckGuid;
95
96 TimeCount = 0;
97 //
98 // Get the END time as early as possible to make it more accurate.
99 //
100 if (EntryExit) {
101 InternalGetTimerValue (&TimeCount);
102 }
103
104 //
105 // Locate the Pei Performance Log Hob.
106 //
107 Status = PeiServicesLocatePpi (
108 &gEfiPeiPerformanceHobGuid,
109 0,
110 &PerfHobDescriptor,
111 NULL
112 );
113
114 //
115 // If the Performance Hob was not found, build and install one.
116 //
117 if (EFI_ERROR(Status)) {
118 Hob = BuildGuidHob (
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)
124 ));
125 Hob = (VOID *)((UINTN)Hob - sizeof (EFI_HOB_GUID_TYPE));
126 ASSERT_EFI_ERROR (Status);
127
128 PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(Hob+1);
129 PerfHobData->NumberOfEntries = 0;
130
131 PerfHobDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)((UINT8 *)(PerfHobData+1) +
132 (sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
133 (MAX_PEI_PERF_LOG_ENTRIES-1)
134 )
135 );
136 PerfHobDescriptor->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
137 PerfHobDescriptor->Guid = &gEfiPeiPerformanceHobGuid;
138 PerfHobDescriptor->Ppi = NULL;
139
140 (*PeiServices)->InstallPpi (
141 PeiServices,
142 PerfHobDescriptor
143 );
144 }
145
146 PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(((UINT8 *)(PerfHobDescriptor)) -
147 ((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
148 (MAX_PEI_PERF_LOG_ENTRIES-1)
149 )
150 + sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG)
151 )
152 );
153
154 if (PerfHobData->NumberOfEntries >= MAX_PEI_PERF_LOG_ENTRIES) {
155 return;
156 }
157
158 if (!EntryExit) {
159 Log = &(PerfHobData->Log[PerfHobData->NumberOfEntries]);
160 ((*PeiServices)->SetMem) (Log, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY), 0);
161
162 //
163 // If not NULL pointer, copy the file name
164 //
165 if (FileHeader != NULL) {
166 Log->Name = FileHeader->Name;
167 }
168
169 //
170 // Copy the description string
171 //
172 ((*PeiServices)->CopyMem) (
173 &(Log->DescriptionString),
174 Token,
175 (PEI_PERF_MAX_DESC_STRING-1) * sizeof(UINT16)
176 );
177
178 //
179 // Get the start time as late as possible to make it more accurate.
180 //
181 InternalGetTimerValue (&TimeCount);
182
183 //
184 // Record the time stamp.
185 //
186 if (Value != 0) {
187 Log->StartTimeCount = Value;
188 } else {
189 Log->StartTimeCount = TimeCount;
190 }
191 Log->StopTimeCount = 0;
192
193 //
194 // Increment the number of valid log entries.
195 //
196 PerfHobData->NumberOfEntries++;
197
198 } else {
199
200 for (Index = PerfHobData->NumberOfEntries-1; Index >= 0; Index--) {
201 Log = NULL;
202 for (Index2 = 0; Index2 < PEI_PERF_MAX_DESC_STRING; Index2++) {
203 if (PerfHobData->Log[Index].DescriptionString[Index2] == 0) {
204 Log = &(PerfHobData->Log[Index]);
205 break;
206 }
207 if (PerfHobData->Log[Index].DescriptionString[Index2] !=
208 Token[Index2]) {
209 break;
210 }
211 }
212 if (Log != NULL) {
213 if (FileHeader != NULL) {
214 Guid = &(Log->Name);
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])) {
220 if (Value != 0) {
221 Log->StopTimeCount = Value;
222 } else {
223 Log->StopTimeCount = TimeCount;
224 }
225 break;
226 }
227 } else {
228 if (Value != 0) {
229 Log->StopTimeCount = Value;
230 } else {
231 Log->StopTimeCount = TimeCount;
232 }
233 break;
234 }
235 }
236 }
237
238 }
239
240 return;
241 }