OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
GopPerf.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16#include <Guid/AppleFile.h>
17#include <Library/BaseMemoryLib.h>
18#include <Library/DebugLib.h>
19#include <Library/PrintLib.h>
20#include <Library/MemoryAllocationLib.h>
23#include <Library/OcMiscLib.h>
24#include <Library/OcFileLib.h>
25#include <Library/TimerLib.h>
26#include <Library/UefiApplicationEntryPoint.h>
27#include <Library/UefiBootServicesTableLib.h>
28#include <Library/UefiRuntimeServicesTableLib.h>
29#include <Library/UefiLib.h>
30#include <Protocol/DevicePath.h>
31#include <Protocol/GraphicsOutput.h>
32
33#define NUM_COLORS 5
34#define NUM_BLITS 200
35
36STATIC UINT32 mColors[NUM_COLORS] = {
37 0xFFFFFFFF,
38 0xFFFFFF00,
39 0xFFFF00FF,
40 0xFF00FFFF,
41 0xFF0000FF,
42};
43
44STATIC
45EFI_STATUS
47 VOID
48 )
49{
50 EFI_STATUS Status;
51 EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
52 VOID *Pools[NUM_COLORS];
53 UINTN Index;
54 UINTN Index2;
55 UINT64 PerfStart;
56 UINT64 PerfResult;
57 UINT64 FrameTimeNs;
58 UINT64 FpMs;
59 UINT64 Fps;
60 UINT64 Remainder;
61 EFI_TPL OldTpl;
62 BOOLEAN HasInterrupts;
63
65 gST->ConsoleOutHandle,
67 (VOID **)&Gop
68 );
69 if (EFI_ERROR (Status)) {
70 DEBUG ((DEBUG_WARN, "GPF: No GOP - %r\n", Status));
71 return Status;
72 }
73
74 if ((Gop->Mode == NULL) || (Gop->Mode->Info == NULL)) {
75 DEBUG ((DEBUG_WARN, "GPF: Invalid GOP\n"));
76 return EFI_INVALID_PARAMETER;
77 }
78
79 if ( (Gop->Mode->Info->HorizontalResolution == 0)
80 || (Gop->Mode->Info->VerticalResolution == 0))
81 {
82 DEBUG ((DEBUG_WARN, "GPF: Empty resolution on GOP\n"));
83 return EFI_UNSUPPORTED;
84 }
85
86 for (Index = 0; Index < NUM_COLORS; ++Index) {
87 Pools[Index] = AllocatePool (
88 Gop->Mode->Info->HorizontalResolution * Gop->Mode->Info->VerticalResolution * sizeof (UINT32)
89 );
90 ASSERT (Pools[Index] != NULL);
91 SetMem32 (
92 Pools[Index],
93 Gop->Mode->Info->HorizontalResolution * Gop->Mode->Info->VerticalResolution * sizeof (UINT32),
94 mColors[Index]
95 );
96 }
97
98 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
99 HasInterrupts = SaveAndDisableInterrupts ();
100
101 PerfStart = GetPerformanceCounter ();
102
103 for (Index = 0; Index < NUM_BLITS; ++Index) {
104 for (Index2 = 0; Index2 < NUM_COLORS; ++Index2) {
105 Gop->Blt (
106 Gop,
107 Pools[Index2],
108 EfiBltBufferToVideo,
109 0,
110 0,
111 0,
112 0,
113 Gop->Mode->Info->HorizontalResolution,
114 Gop->Mode->Info->VerticalResolution,
115 0
116 );
117 }
118 }
119
120 PerfResult = GetPerformanceCounter () - PerfStart;
121
122 if (HasInterrupts) {
124 }
125
126 gBS->RestoreTPL (OldTpl);
127
128 if (GetTimeInNanoSecond (PerfResult) != 0) {
129 FrameTimeNs = DivU64x64Remainder (
130 GetTimeInNanoSecond (PerfResult),
131 (UINT64)NUM_BLITS * NUM_COLORS,
132 NULL
133 );
134
135 FpMs = DivU64x64Remainder (1000000000ULL * 1000ULL, FrameTimeNs, NULL);
136 Fps = DivU64x64Remainder (FpMs, 1000, &Remainder);
137
138 DEBUG ((
139 DEBUG_WARN,
140 "GPF: Total blits %Lu on %ux%u over %Lu ms, about %Lu.%03Lu FPS, %Lu ms TPF\n",
141 (UINT64)NUM_BLITS * NUM_COLORS,
142 Gop->Mode->Info->HorizontalResolution,
143 Gop->Mode->Info->VerticalResolution,
144 DivU64x64Remainder (GetTimeInNanoSecond (PerfResult), 1000000ULL, NULL),
145 Fps,
146 Remainder,
147 DivU64x64Remainder (FrameTimeNs, 1000000, NULL)
148 ));
149 } else {
150 DEBUG ((DEBUG_WARN, "GPF: Unable to measure time\n"));
151 }
152
153 for (Index = 0; Index < NUM_COLORS; ++Index) {
154 FreePool (Pools[Index]);
155 }
156
157 return EFI_SUCCESS;
158}
159
160EFI_STATUS
161EFIAPI
163 IN EFI_HANDLE ImageHandle,
164 IN EFI_SYSTEM_TABLE *SystemTable
165 )
166{
167 //
168 // 1. Disable watchdog timer.
169 //
170 gBS->SetWatchdogTimer (0, 0, 0, NULL);
171
172 //
173 // 2. Run test.
174 //
176
177 return EFI_SUCCESS;
178}
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition GopPerf.c:162
#define NUM_COLORS
Definition GopPerf.c:33
#define NUM_BLITS
Definition GopPerf.c:34
STATIC UINT32 mColors[NUM_COLORS]
Definition GopPerf.c:36
STATIC EFI_STATUS PerfConsoleGop(VOID)
Definition GopPerf.c:46
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
EFI_STATUS OcHandleProtocolFallback(IN EFI_HANDLE Handle, IN EFI_GUID *Protocol, OUT VOID **Interface)
EFI_GUID gEfiGraphicsOutputProtocolGuid
UINT64 EFIAPI DivU64x64Remainder(IN UINT64 Dividend, IN UINT64 Divisor, OUT UINT64 *Remainder OPTIONAL)
Definition UserMath.c:59
VOID EFIAPI EnableInterrupts(VOID)
Definition UserMisc.c:38
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
UINT64 EFIAPI GetPerformanceCounter(VOID)
#define ASSERT(x)
Definition coder.h:55