]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/Common/PeiLib/Perf.c
Add <FrameworkModules> in EdkModulePkg-All-Archs.fpd and MdePkg-All-Archs.fpd file...
[mirror_edk2.git] / Tools / Source / TianoTools / Common / PeiLib / Perf.c
1 /*++
2
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
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 Module Name:
13
14 Perf.c
15
16 Abstract:
17
18 Support for performance primitives.
19
20 --*/
21
22 #include "Tiano.h"
23 #include "Pei.h"
24 #include "PeiLib.h"
25 #include "PeiHob.h"
26
27 #include EFI_GUID_DEFINITION (PeiPerformanceHob)
28
29 //
30 // Perfomance HOB data definitions
31 //
32
33 #define MAX_PEI_PERF_LOG_ENTRIES 28
34
35 //
36 // Prototype functions
37 //
38 EFI_STATUS
39 GetTimerValue (
40 OUT UINT64 *TimerValue
41 );
42
43
44 VOID
45 PeiPerfMeasure (
46 EFI_PEI_SERVICES **PeiServices,
47 IN UINT16 *Token,
48 IN EFI_FFS_FILE_HEADER *FileHeader,
49 IN BOOLEAN EntryExit,
50 IN UINT64 Value
51 )
52 /*++
53
54 Routine Description:
55
56 Log a timestamp count.
57
58 Arguments:
59
60 PeiServices - Pointer to the PEI Core Services table
61
62 Token - Pointer to Token Name
63
64 FileHeader - Pointer to the file header
65
66 EntryExit - Indicates start or stop measurement
67
68 Value - The start time or the stop time
69
70 Returns:
71
72 --*/
73 {
74 EFI_STATUS Status;
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;
79 UINT64 TimeCount;
80 INTN Index;
81 UINTN Index2;
82 EFI_GUID *Guid;
83 EFI_GUID *CheckGuid;
84
85 TimeCount = 0;
86 //
87 // Get the END time as early as possible to make it more accurate.
88 //
89 if (EntryExit) {
90 GetTimerValue (&TimeCount);
91 }
92
93 //
94 // Locate the Pei Performance Log Hob.
95 //
96 Status = (*PeiServices)->LocatePpi (
97 PeiServices,
98 &gEfiPeiPerformanceHobGuid,
99 0,
100 &PerfHobDescriptor,
101 NULL
102 );
103
104 //
105 // If the Performance Hob was not found, build and install one.
106 //
107 if (EFI_ERROR(Status)) {
108 Status = PeiBuildHobGuid (
109 PeiServices,
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)
115 ),
116 &Hob
117 );
118 ASSERT_PEI_ERROR(PeiServices, Status);
119
120 PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(Hob+1);
121 PerfHobData->NumberOfEntries = 0;
122
123 PerfHobDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)((UINT8 *)(PerfHobData+1) +
124 (sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
125 (MAX_PEI_PERF_LOG_ENTRIES-1)
126 )
127 );
128 PerfHobDescriptor->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
129 PerfHobDescriptor->Guid = &gEfiPeiPerformanceHobGuid;
130 PerfHobDescriptor->Ppi = NULL;
131
132 (*PeiServices)->InstallPpi (
133 PeiServices,
134 PerfHobDescriptor
135 );
136 }
137
138 PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(((UINT8 *)(PerfHobDescriptor)) -
139 ((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
140 (MAX_PEI_PERF_LOG_ENTRIES-1)
141 )
142 + sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG)
143 )
144 );
145
146 if (PerfHobData->NumberOfEntries >= MAX_PEI_PERF_LOG_ENTRIES) {
147 return;
148 }
149
150 if (!EntryExit) {
151 Log = &(PerfHobData->Log[PerfHobData->NumberOfEntries]);
152 (*PeiServices)->SetMem (Log, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY), 0);
153
154 //
155 // If not NULL pointer, copy the file name
156 //
157 if (FileHeader != NULL) {
158 Log->Name = FileHeader->Name;
159 }
160
161 //
162 // Copy the description string
163 //
164 (*PeiServices)->CopyMem (
165 &(Log->DescriptionString),
166 Token,
167 (PEI_PERF_MAX_DESC_STRING-1) * sizeof(UINT16)
168 );
169
170 //
171 // Get the start time as late as possible to make it more accurate.
172 //
173 GetTimerValue (&TimeCount);
174
175 //
176 // Record the time stamp.
177 //
178 if (Value != 0) {
179 Log->StartTimeCount = Value;
180 } else {
181 Log->StartTimeCount = TimeCount;
182 }
183 Log->StopTimeCount = 0;
184
185 //
186 // Increment the number of valid log entries.
187 //
188 PerfHobData->NumberOfEntries++;
189
190 } else {
191
192 for (Index = PerfHobData->NumberOfEntries-1; Index >= 0; Index--) {
193 Log = NULL;
194 for (Index2 = 0; Index2 < PEI_PERF_MAX_DESC_STRING; Index2++) {
195 if (PerfHobData->Log[Index].DescriptionString[Index2] == 0) {
196 Log = &(PerfHobData->Log[Index]);
197 break;
198 }
199 if (PerfHobData->Log[Index].DescriptionString[Index2] !=
200 Token[Index2]) {
201 break;
202 }
203 }
204 if (Log != NULL) {
205 if (FileHeader != NULL) {
206 Guid = &(Log->Name);
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])) {
212 if (Value != 0) {
213 Log->StopTimeCount = Value;
214 } else {
215 Log->StopTimeCount = TimeCount;
216 }
217 break;
218 }
219 } else {
220 if (Value != 0) {
221 Log->StopTimeCount = Value;
222 } else {
223 Log->StopTimeCount = TimeCount;
224 }
225 break;
226 }
227 }
228 }
229
230 }
231
232 return;
233 }