TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeCoreTimerLib.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10#include <Library/BaseLib.h>
11#include <Library/TimerLib.h>
12#include <Library/DebugLib.h>
13#include <Library/EmuThunkLib.h>
15#include <Library/UefiLib.h>
16
17#include <Protocol/Timer.h>
18
30EFIAPI
32 IN UINTN MicroSeconds
33 )
34{
35 return NanoSecondDelay (MicroSeconds * 1000);
36}
37
49EFIAPI
51 IN UINTN NanoSeconds
52 )
53{
54 gEmuThunk->Sleep (NanoSeconds);
55 return NanoSeconds;
56}
57
69UINT64
70EFIAPI
72 VOID
73 )
74{
75 return gEmuThunk->QueryPerformanceCounter ();
76}
77
101UINT64
102EFIAPI
104 OUT UINT64 *StartValue OPTIONAL,
105 OUT UINT64 *EndValue OPTIONAL
106 )
107{
108 if (StartValue != NULL) {
109 *StartValue = 0ULL;
110 }
111
112 if (EndValue != NULL) {
113 *EndValue = (UINT64)-1LL;
114 }
115
116 return gEmuThunk->QueryPerformanceFrequency ();
117}
118
130UINT64
131EFIAPI
133 IN UINT64 Ticks
134 )
135{
136 UINT64 Frequency;
137 UINT64 NanoSeconds;
138 UINT64 Remainder;
139 INTN Shift;
140
142
143 //
144 // Ticks
145 // Time = --------- x 1,000,000,000
146 // Frequency
147 //
148 NanoSeconds = MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Remainder), 1000000000u);
149
150 //
151 // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit.
152 // Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
153 // i.e. highest bit set in Remainder should <= 33.
154 //
155 Shift = MAX (0, HighBitSet64 (Remainder) - 33);
156 Remainder = RShiftU64 (Remainder, (UINTN)Shift);
157 Frequency = RShiftU64 (Frequency, (UINTN)Shift);
158 NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
159
160 return NanoSeconds;
161}
UINT64 UINTN
INT64 INTN
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: RShiftU64.c:28
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
Definition: MultU64x32.c:27
UINT64 EFIAPI DivU64x64Remainder(IN UINT64 Dividend, IN UINT64 Divisor, OUT UINT64 *Remainder OPTIONAL)
INTN EFIAPI HighBitSet64(IN UINT64 Operand)
Definition: HighBitSet64.c:27
UINT64 EFIAPI GetPerformanceCounterProperties(OUT UINT64 *StartValue OPTIONAL, OUT UINT64 *EndValue OPTIONAL)
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
UINT64 EFIAPI GetPerformanceCounter(VOID)
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINTN EFIAPI NanoSecondDelay(IN UINTN NanoSeconds)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define MAX(a, b)
Definition: Base.h:992