TianoCore EDK2 master
Loading...
Searching...
No Matches
FirmwarePerformancePei.c
Go to the documentation of this file.
1
13#include <PiPei.h>
14
17
19#include <Guid/Performance.h>
21
23#include <Library/BaseLib.h>
24#include <Library/DebugLib.h>
25#include <Library/TimerLib.h>
27#include <Library/LockBoxLib.h>
28#include <Library/PcdLib.h>
29#include <Library/HobLib.h>
30
52EFIAPI
54 IN CONST EFI_PEI_SERVICES **PeiServices,
55 IN EFI_STATUS_CODE_TYPE CodeType,
57 IN UINT32 Instance,
58 IN CONST EFI_GUID *CallerId,
60 )
61{
62 EFI_STATUS Status;
63 UINT64 CurrentTime;
64 UINTN VarSize;
65 EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer;
66 S3_PERFORMANCE_TABLE *AcpiS3PerformanceTable;
67 EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD *AcpiS3ResumeRecord;
68 UINT64 S3ResumeTotal;
70 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD *AcpiS3SuspendRecord;
71 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariableServices;
72 UINT8 *BootPerformanceTable;
73 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
74 EFI_HOB_GUID_TYPE *GuidHob;
75 FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;
76 UINT8 *FirmwarePerformanceData;
77 UINT8 *FirmwarePerformanceTablePtr;
78
79 //
80 // Check whether status code is what we are interested in.
81 //
82 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) ||
83 (Value != (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_OS_WAKE)))
84 {
85 return EFI_UNSUPPORTED;
86 }
87
88 //
89 // Retrieve current time as early as possible.
90 //
92
93 //
94 // Update S3 Resume Performance Record.
95 //
96 S3PerformanceTablePointer = 0;
97 VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
98 Status = RestoreLockBox (&gFirmwarePerformanceS3PointerGuid, &S3PerformanceTablePointer, &VarSize);
99 ASSERT_EFI_ERROR (Status);
100
101 AcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *)(UINTN)S3PerformanceTablePointer;
102 ASSERT (AcpiS3PerformanceTable != NULL);
103 if (AcpiS3PerformanceTable->Header.Signature != EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE) {
104 DEBUG ((DEBUG_ERROR, "FPDT S3 performance data in ACPI memory get corrupted\n"));
105 return EFI_ABORTED;
106 }
107
108 AcpiS3ResumeRecord = &AcpiS3PerformanceTable->S3Resume;
109 AcpiS3ResumeRecord->FullResume = CurrentTime;
110 //
111 // Calculate average S3 resume time.
112 //
113 S3ResumeTotal = MultU64x32 (AcpiS3ResumeRecord->AverageResume, AcpiS3ResumeRecord->ResumeCount);
114 AcpiS3ResumeRecord->ResumeCount++;
115 if (AcpiS3ResumeRecord->ResumeCount > 0) {
116 AcpiS3ResumeRecord->AverageResume = DivU64x32 (S3ResumeTotal + AcpiS3ResumeRecord->FullResume, AcpiS3ResumeRecord->ResumeCount);
117 DEBUG ((DEBUG_INFO, "\nFPDT: S3 Resume Performance - AverageResume = 0x%x\n", AcpiS3ResumeRecord->AverageResume));
118 } else {
119 DEBUG ((DEBUG_ERROR, "\nFPDT: S3 ResumeCount reaches the MAX_UINT32 value. S3 ResumeCount record reset to Zero."));
120 }
121
122 DEBUG ((DEBUG_INFO, "FPDT: S3 Resume Performance - ResumeCount = 0x%x\n", AcpiS3ResumeRecord->ResumeCount));
123 DEBUG ((DEBUG_INFO, "FPDT: S3 Resume Performance - FullResume = 0x%x\n", AcpiS3ResumeRecord->FullResume));
124
125 //
126 // Update S3 Suspend Performance Record.
127 //
128 AcpiS3SuspendRecord = &AcpiS3PerformanceTable->S3Suspend;
129 VarSize = sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD);
130 ZeroMem (&S3SuspendRecord, sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD));
131 Status = RestoreLockBox (
132 &gEfiFirmwarePerformanceGuid,
133 &S3SuspendRecord,
134 &VarSize
135 );
136 ASSERT_EFI_ERROR (Status);
137
138 AcpiS3SuspendRecord->SuspendStart = S3SuspendRecord.SuspendStart;
139 AcpiS3SuspendRecord->SuspendEnd = S3SuspendRecord.SuspendEnd;
140
141 DEBUG ((DEBUG_INFO, "FPDT: S3 Suspend Performance - SuspendStart = %ld\n", AcpiS3SuspendRecord->SuspendStart));
142 DEBUG ((DEBUG_INFO, "FPDT: S3 Suspend Performance - SuspendEnd = %ld\n", AcpiS3SuspendRecord->SuspendEnd));
143
144 Status = PeiServicesLocatePpi (
145 &gEfiPeiReadOnlyVariable2PpiGuid,
146 0,
147 NULL,
148 (VOID **)&VariableServices
149 );
150 ASSERT_EFI_ERROR (Status);
151
152 //
153 // Update S3 boot records into the basic boot performance table.
154 //
155 VarSize = sizeof (PerformanceVariable);
156 Status = VariableServices->GetVariable (
157 VariableServices,
158 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
159 &gEfiFirmwarePerformanceGuid,
160 NULL,
161 &VarSize,
162 &PerformanceVariable
163 );
164 if (EFI_ERROR (Status)) {
165 return Status;
166 }
167
168 BootPerformanceTable = (UINT8 *)(UINTN)PerformanceVariable.BootPerformanceTablePointer;
169
170 //
171 // Dump PEI boot records
172 //
173 FirmwarePerformanceTablePtr = (BootPerformanceTable + sizeof (BOOT_PERFORMANCE_TABLE));
174 GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);
175 while (GuidHob != NULL) {
176 FirmwarePerformanceData = GET_GUID_HOB_DATA (GuidHob);
177 PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)FirmwarePerformanceData;
178
179 CopyMem (FirmwarePerformanceTablePtr, FirmwarePerformanceData + sizeof (FPDT_PEI_EXT_PERF_HEADER), (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries));
180
181 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));
182
183 FirmwarePerformanceTablePtr += (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries);
184 }
185
186 //
187 // Update Table length.
188 //
189 ((BOOT_PERFORMANCE_TABLE *)BootPerformanceTable)->Header.Length = (UINT32)((UINTN)FirmwarePerformanceTablePtr - (UINTN)BootPerformanceTable);
190
191 return EFI_SUCCESS;
192}
193
206EFIAPI
208 IN EFI_PEI_FILE_HANDLE FileHandle,
209 IN CONST EFI_PEI_SERVICES **PeiServices
210 )
211{
212 EFI_STATUS Status;
213 EFI_PEI_RSC_HANDLER_PPI *RscHandler;
214
215 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
216 //
217 // S3 resume - register status code listener for OS wake vector.
218 //
219 Status = PeiServicesLocatePpi (
220 &gEfiPeiRscHandlerPpiGuid,
221 0,
222 NULL,
223 (VOID **)&RscHandler
224 );
225 ASSERT_EFI_ERROR (Status);
226
227 Status = RscHandler->Register (FpdtStatusCodeListenerPei);
228 ASSERT_EFI_ERROR (Status);
229 }
230
231 return EFI_SUCCESS;
232}
UINT64 UINTN
#define EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE
Definition: Acpi50.h:1240
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
UINT64 EFIAPI GetPerformanceCounter(VOID)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
Definition: MultU64x32.c:27
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI FirmwarePerformancePeiEntryPoint(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI FpdtStatusCodeListenerPei(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_STATUS_CODE_TYPE CodeType, IN EFI_STATUS_CODE_VALUE Value, IN UINT32 Instance, IN CONST EFI_GUID *CallerId, IN CONST EFI_STATUS_CODE_DATA *Data)
RETURN_STATUS EFIAPI RestoreLockBox(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
UINT32 EFI_STATUS_CODE_VALUE
Definition: PiStatusCode.h:67
#define EFI_PROGRESS_CODE
Definition: PiStatusCode.h:43
UINT32 EFI_STATUS_CODE_TYPE
Definition: PiStatusCode.h:24
#define EFI_STATUS_CODE_TYPE_MASK
Definition: PiStatusCode.h:32
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_PHYSICAL_ADDRESS BootPerformanceTablePointer
Pointer to Boot Performance Table.
Definition: Base.h:213
EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD S3Suspend
Basic S3 Suspend performance record.
EFI_ACPI_5_0_FPDT_PERFORMANCE_TABLE_HEADER Header
Common ACPI table header.
EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD S3Resume
Basic S3 Resume performance record.