ReactOS  0.4.15-dev-980-ge160524
timer.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for timer.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI HalpInitializeClock (VOID)
 
VOID NTAPI HalCalibratePerformanceCounter (IN volatile PLONG Count, IN ULONGLONG NewCount)
 
ULONG NTAPI HalSetTimeIncrement (IN ULONG Increment)
 
VOID NTHALAPI KeStallExecutionProcessor (ULONG USec)
 

Variables

BOOLEAN HalpClockSetMSRate
 
ULONG HalpCurrentTimeIncrement
 
ULONG HalpCurrentRollOver
 
ULONG HalpNextMSRate = 14
 
ULONG HalpLargestClockMS = 15
 
LARGE_INTEGER HalpRolloverTable [15]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file timer.c.

Function Documentation

◆ HalCalibratePerformanceCounter()

VOID NTAPI HalCalibratePerformanceCounter ( IN volatile PLONG  Count,
IN ULONGLONG  NewCount 
)

Definition at line 84 of file timer.c.

86 {
87  ULONG Flags = 0;
88 
89  /* Disable interrupts */
90  Flags = __readmsr();
91  _disable();
92 
93  /* Do a decrement for this CPU */
95 
96  /* Wait for other CPUs */
97  while (*Count);
98 
99  /* Restore interrupts if they were previously enabled */
100  __writemsr(Flags);
101 }
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1173
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1

◆ HalpInitializeClock()

VOID NTAPI HalpInitializeClock ( VOID  )

Definition at line 46 of file timer.c.

47 {
48  //PKPRCB Prcb = KeGetCurrentPrcb();
50  USHORT RollOver;
51  ULONG Flags = 0;
52 
53  /* Get increment and rollover for the largest time clock ms possible */
55  RollOver = (USHORT)HalpRolloverTable[HalpLargestClockMS - 1].LowPart;
56 
57  /* Set the maximum and minimum increment with the kernel */
60 
61  /* Disable interrupts */
62  Flags = __readmsr();
63  _disable();
64 
65  /* Set the rollover */
67  __outbyte(TIMER_DATA_PORT0, RollOver & 0xFF);
68  __outbyte(TIMER_DATA_PORT0, RollOver >> 8);
69 
70  /* Restore interrupts if they were previously enabled */
72 
73  /* Save rollover and return */
74  HalpCurrentRollOver = RollOver;
75 }
VOID NTAPI KeSetTimeIncrement(IN ULONG MaxIncrement, IN ULONG MinIncrement)
Definition: ntoskrnl.c:42
#define TIMER_MD2
Definition: halp.h:26
PPC_QUAL void __outbyte(unsigned long const Port, const unsigned char Data)
Definition: intrin_ppc.h:605
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define TIMER_CONTROL_PORT
Definition: halp.h:22
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
LARGE_INTEGER HalpRolloverTable[15]
Definition: timer.c:23
ULONG HalpCurrentRollOver
Definition: timer.c:19
#define TIMER_DATA_PORT0
Definition: halp.h:23
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
unsigned short USHORT
Definition: pedump.c:61
ULONG HalpCurrentTimeIncrement
Definition: timer.c:25
#define TIMER_BOTH
Definition: halp.h:25
void __cdecl _disable(void)
Definition: intrin_arm.h:365
ULONG HalpLargestClockMS
Definition: timer.c:21
unsigned int ULONG
Definition: retypes.h:1
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
#define TIMER_SC0
Definition: halp.h:24

◆ HalSetTimeIncrement()

ULONG NTAPI HalSetTimeIncrement ( IN ULONG  Increment)

Definition at line 108 of file timer.c.

109 {
110  /* Round increment to ms */
111  Increment /= 10000;
112 
113  /* Normalize between our minimum (1 ms) and maximum (variable) setting */
115  if (Increment <= 0) Increment = 1;
116 
117  /* Set the rate and tell HAL we want to change it */
120 
121  /* Return the increment */
123 }
#define TRUE
Definition: types.h:120
BOOLEAN HalpClockSetMSRate
Definition: timer.c:17
ULONG HalpNextMSRate
Definition: timer.c:20
LARGE_INTEGER HalpRolloverTable[15]
Definition: timer.c:23
ULONG HalpLargestClockMS
Definition: timer.c:21
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42

◆ KeStallExecutionProcessor()

VOID NTHALAPI KeStallExecutionProcessor ( ULONG  USec)

Definition at line 127 of file timer.c.

128 {
130  LARGE_INTEGER Timebase, Remainder;
131  Timebase.QuadPart = 1000000;
132  Freq.QuadPart *= USec;
133  End = RtlLargeIntegerDivide(Freq, Timebase, &Remainder);
134  End.QuadPart += Start.QuadPart;
135  while(End.QuadPart > __rdtsc());
136 }
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
NTSYSAPI ULONGLONG WINAPI RtlLargeIntegerDivide(ULONGLONG, ULONGLONG, ULONGLONG *)
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
Definition: partlist.h:33
#define Freq
Definition: deflate.h:79
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046

Variable Documentation

◆ HalpClockSetMSRate

BOOLEAN HalpClockSetMSRate

Definition at line 17 of file timer.c.

Referenced by HalSetTimeIncrement().

◆ HalpCurrentRollOver

ULONG HalpCurrentRollOver

Definition at line 19 of file timer.c.

Referenced by HalpInitializeClock(), and KeQueryPerformanceCounter().

◆ HalpCurrentTimeIncrement

ULONG HalpCurrentTimeIncrement

Definition at line 18 of file timer.c.

◆ HalpLargestClockMS

ULONG HalpLargestClockMS = 15

Definition at line 21 of file timer.c.

Referenced by HalpInitializeClock(), and HalSetTimeIncrement().

◆ HalpNextMSRate

ULONG HalpNextMSRate = 14

Definition at line 20 of file timer.c.

Referenced by HalSetTimeIncrement().

◆ HalpRolloverTable

LARGE_INTEGER HalpRolloverTable[15]
Initial value:
=
{
{{1197, 10032}},
{{2394, 20064}},
{{3591, 30096}},
{{4767, 39952}},
{{5964, 49984}},
{{7161, 60016}},
{{8358, 70048}},
{{9555, 80080}},
{{10731, 89936}},
{{11949, 100144}},
{{13125, 110000}},
{{14322, 120032}},
{{15519, 130064}},
{{16695, 139920}},
{{17892, 149952}}
}

Definition at line 23 of file timer.c.

Referenced by HalpInitializeClock(), and HalSetTimeIncrement().