ReactOS  0.4.13-dev-73-gcfe54aa
time.c File Reference
#include "bl.h"
Include dependency graph for time.c:

Go to the source code of this file.

Functions

NTSTATUS BlpTimeMeasureTscFrequency (VOID)
 
NTSTATUS BlpTimeCalibratePerformanceCounter (VOID)
 
ULONGLONG BlTimeQueryPerformanceCounter (_Out_opt_ PLARGE_INTEGER Frequency)
 

Variables

ULONGLONG BlpTimePerformanceFrequency
 

Function Documentation

◆ BlpTimeCalibratePerformanceCounter()

NTSTATUS BlpTimeCalibratePerformanceCounter ( VOID  )

Definition at line 62 of file time.c.

65 {
66 #if defined(_M_IX86) || defined(_M_X64)
67  INT CpuInfo[4];
68 
69  /* Check if the ISVM bit it set, meaning we're in a hypervisor */
70  __cpuid(CpuInfo, 1);
71  if (CpuInfo[2] & 0x80000000)
72  {
73  /* Get the Hypervisor Identification Leaf */
74  __cpuid(CpuInfo, 0x40000001);
75 
76  /* Is this Hyper-V? */
77  if (CpuInfo[0] == '1#vH')
78  {
79  /* Get the Hypervisor Feature Identification Leaf */
80  __cpuid(CpuInfo, 0x40000003);
81 
82  /* Check if HV_X64_MSR_REFERENCE_TSC is present */
83  if (CpuInfo[3] & 0x100)
84  {
85  /* Read the TSC frequency from the MSR */
87  return STATUS_SUCCESS;
88  }
89  }
90  }
91 
92  /* On other systems, compute it */
94 #else
95  EfiPrintf(L"BlpTimeCalibratePerformanceCounter not implemented for this platform.\r\n");
97 #endif
98 }
ULONGLONG BlpTimePerformanceFrequency
Definition: time.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
int32_t INT
Definition: typedefs.h:56
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
NTSTATUS BlpTimeMeasureTscFrequency(VOID)
Definition: time.c:20
static const WCHAR L[]
Definition: oid.c:1250
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by InitializeLibrary().

◆ BlpTimeMeasureTscFrequency()

NTSTATUS BlpTimeMeasureTscFrequency ( VOID  )

Definition at line 20 of file time.c.

23 {
24 #if defined(_M_IX86) || defined(_M_X64)
25  ULONG Count;
26  INT CpuInfo[4];
27  ULONGLONG TimeStamp1, TimeStamp2, Delta;
28 
29  /* Check if the ISVM bit it set, meaning we're in a hypervisor */
30  __cpuid(CpuInfo, 1);
31  Count = CpuInfo[2] & 0x80000000 ? 10 : 1;
32 
33  /* Loop trying to get an accurate TSC */
34  do
35  {
36  /* Stall for 1us and get count 1 */
37  EfiStall(1);
38  TimeStamp1 = __rdtsc();
39 
40  /* Stall for 1000us and get count 2*/
41  EfiStall(1000);
42  TimeStamp2 = __rdtsc();
43 
44  /* Stall for 9000us and get the difference */
45  EfiStall(9000);
46  Delta = __rdtsc() - TimeStamp2;
47 
48  /* Keep going as long as the TSC is fluctuating */
49  --Count;
50  } while (((TimeStamp2 - TimeStamp1) > Delta) && (Count));
51 
52  /* Set the frequency based on the two measurements we took */
53  BlpTimePerformanceFrequency = 125 * (Delta - (TimeStamp2 - TimeStamp1)) & 0x1FFFFFFFFFFFFFF;
54  return STATUS_SUCCESS;
55 #else
56  EfiPrintf(L"BlpTimeMeasureTscFrequency not implemented for this platform.\r\n");
58 #endif
59 }
NTSTATUS EfiStall(_In_ ULONG StallTime)
Definition: firmware.c:1003
ULONGLONG BlpTimePerformanceFrequency
Definition: time.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
int32_t INT
Definition: typedefs.h:56
uint64_t ULONGLONG
Definition: typedefs.h:65
static const WCHAR L[]
Definition: oid.c:1250
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
static ULONG Delta
Definition: xboxvideo.c:28
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by BlpTimeCalibratePerformanceCounter().

◆ BlTimeQueryPerformanceCounter()

ULONGLONG BlTimeQueryPerformanceCounter ( _Out_opt_ PLARGE_INTEGER  Frequency)

Definition at line 101 of file time.c.

104 {
105 #if defined(_M_IX86) || defined(_M_X64)
106  /* Check if caller wants frequency */
107  if (Frequency)
108  {
109  /* Return it */
111  }
112 
113  /* Return the TSC value */
114  return __rdtsc();
115 #else
116  EfiPrintf(L"BlTimeQueryPerformanceCounter not implemented for this platform.\r\n");
117  return 0;
118 #endif
119 };
ULONGLONG BlpTimePerformanceFrequency
Definition: time.c:15
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
static const WCHAR L[]
Definition: oid.c:1250
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
static LARGE_INTEGER Frequency
Definition: clock.c:41
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by BlImgLoadBootApplication().

Variable Documentation

◆ BlpTimePerformanceFrequency