ReactOS  0.4.14-dev-552-g2fad488
tsc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NUM_SAMPLES   4
 
#define MSR_RDTSC   0x10
 
#define KiGetIdtEntry(Pcr, Vector)   &((Pcr)->IDT[Vector])
 

Functions

void __cdecl TscCalibrationISR (void)
 
VOID NTAPI HalpInitializeTsc (void)
 

Variables

LARGE_INTEGER HalpCpuClockFrequency
 

Macro Definition Documentation

◆ KiGetIdtEntry

#define KiGetIdtEntry (   Pcr,
  Vector 
)    &((Pcr)->IDT[Vector])

Definition at line 17 of file tsc.h.

◆ MSR_RDTSC

#define MSR_RDTSC   0x10

Definition at line 6 of file tsc.h.

◆ NUM_SAMPLES

#define NUM_SAMPLES   4

Definition at line 5 of file tsc.h.

Function Documentation

◆ HalpInitializeTsc()

VOID NTAPI HalpInitializeTsc ( void  )

Definition at line 56 of file tsc.c.

57 {
59  KIDTENTRY OldIdtEntry, *IdtPointer;
60  PKPCR Pcr = KeGetPcr();
61  UCHAR RegisterA, RegisterB;
62 
63  /* Check if the CPU supports RDTSC */
64  if (!(KeGetCurrentPrcb()->FeatureBits & KF_RDTSC))
65  {
66  KeBugCheck(HAL_INITIALIZATION_FAILED);
67  }
68 
69  /* Save flags and disable interrupts */
70  Flags = __readeflags();
71  _disable();
72 
73  /* Enable the periodic interrupt in the CMOS */
74  RegisterB = HalpReadCmos(RTC_REGISTER_B);
76 
77  /* Modify register A to RTC_MODE to get SAMPLE_FREQENCY */
78  RegisterA = HalpReadCmos(RTC_REGISTER_A);
79  RegisterA = (RegisterA & 0xF0) | RTC_MODE;
80  HalpWriteCmos(RTC_REGISTER_A, RegisterA);
81 
82  /* Save old IDT entry */
83  IdtPointer = KiGetIdtEntry(Pcr, HalpRtcClockVector);
84  OldIdtEntry = *IdtPointer;
85 
86  /* Set the calibration ISR */
88 
89  /* Reset TSC value to 0 */
91 
92  /* Enable the timer interrupt */
94 
95  /* Read register C, so that the next interrupt can happen */
97 
98  /* Wait for completion */
99  _enable();
101  _disable();
102 
103  /* Disable the periodic interrupt in the CMOS */
105 
106  /* Disable the timer interrupt */
108 
109  /* Restore old IDT entry */
110  *IdtPointer = OldIdtEntry;
111 
112  /* Calculate an average, using simplified linear regression */
115 
116  /* Restore flags */
118 
119 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
BOOLEAN NTAPI HalEnableSystemInterrupt(IN ULONG Vector, IN KIRQL Irql, IN KINTERRUPT_MODE InterruptMode)
Definition: pic.c:295
#define RTC_MODE
Definition: tsc.c:23
#define _ReadWriteBarrier()
Definition: intrin_arm.h:36
#define RTC_REG_B_PI
Definition: halp.h:55
UCHAR HalpRtcClockVector
Definition: tsc.c:21
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define KF_RDTSC
Definition: ketypes.h:144
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
#define MSR_RDTSC
Definition: tsc.h:6
Definition: ke.h:280
#define KeGetPcr()
Definition: ke.h:25
UCHAR TscCalibrationPhase
Definition: tsc.c:19
VOID NTAPI HalDisableSystemInterrupt(IN ULONG Vector, IN KIRQL Irql)
Definition: pic.c:309
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define CLOCK_LEVEL
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
#define NUM_SAMPLES
Definition: tsc.h:5
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
#define RTC_REGISTER_B
Definition: halp.h:17
void __cdecl TscCalibrationISR(void)
unsigned char UCHAR
Definition: xmlstorage.h:181
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:242
#define RTC_REGISTER_C
Definition: halp.h:56
ULONG64 TscCalibrationArray[NUM_SAMPLES]
Definition: tsc.c:20
#define KiGetIdtEntry(Pcr, Vector)
Definition: tsc.h:17
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
void __cdecl _disable(void)
Definition: intrin_arm.h:365
LARGE_INTEGER HalpCpuClockFrequency
Definition: tsc.c:17
static ULONG64 DoLinearRegression(ULONG XMax, ULONG64 *ArrayY)
Definition: tsc.c:30
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by HalpCalibrateStallExecution().

◆ TscCalibrationISR()

void __cdecl TscCalibrationISR ( void  )

Referenced by HalpInitializeTsc().

Variable Documentation

◆ HalpCpuClockFrequency

LARGE_INTEGER HalpCpuClockFrequency

Definition at line 17 of file tsc.c.

Referenced by HalpCalibrateStallExecution(), HalpInitializeTsc(), and KeQueryPerformanceCounter().