ReactOS 0.4.16-dev-87-g3dfbe52
apictimer.c File Reference
#include <hal.h>
#include "apicp.h"
#include <debug.h>
Include dependency graph for apictimer.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI ApicSetTimerInterval (ULONG MicroSeconds)
 
VOID NTAPI ApicInitializeTimer (ULONG Cpu)
 
VOID FASTCALL HalpProfileInterruptHandler (_In_ PKTRAP_FRAME TrapFrame)
 
VOID NTAPI HalInitializeProfiling (VOID)
 
VOID NTAPI HalStartProfileInterrupt (IN KPROFILE_SOURCE ProfileSource)
 
VOID NTAPI HalStopProfileInterrupt (IN KPROFILE_SOURCE ProfileSource)
 
ULONG_PTR NTAPI HalSetProfileInterval (IN ULONG_PTR Interval)
 

Variables

LARGE_INTEGER HalpCpuClockFrequency
 
BOOLEAN HalIsProfiling = FALSE
 
ULONGLONG HalCurProfileInterval = 10000000
 
ULONGLONG HalMinProfileInterval = 1000
 
ULONGLONG HalMaxProfileInterval = 10000000
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file apictimer.c.

Function Documentation

◆ ApicInitializeTimer()

VOID NTAPI ApicInitializeTimer ( ULONG  Cpu)

Definition at line 50 of file apictimer.c.

51{
52
53 /* Initialize the TSC */
54 //HalpInitializeTsc();
55
56 /* Set clock multiplier to 1 */
58
60
61// KeSetTimeIncrement
62}
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:323
@ TIMER_DV_DivideBy1
Definition: apicp.h:183
@ APIC_TDCR
Definition: apicp.h:104
VOID NTAPI ApicSetTimerInterval(ULONG MicroSeconds)
Definition: apictimer.c:28

◆ ApicSetTimerInterval()

VOID NTAPI ApicSetTimerInterval ( ULONG  MicroSeconds)

Definition at line 28 of file apictimer.c.

29{
30 LVT_REGISTER LvtEntry;
31 ULONGLONG TimerInterval;
32
33 /* Calculate the Timer interval */
34 TimerInterval = HalpCpuClockFrequency.QuadPart * MicroSeconds / 1000000;
35
36 /* Set the count interval */
37 ApicWrite(APIC_TICR, (ULONG)TimerInterval);
38
39 /* Set to periodic */
40 LvtEntry.Long = 0;
41 LvtEntry.TimerMode = 1;
42 LvtEntry.Vector = APIC_PROFILE_VECTOR;
43 LvtEntry.Mask = 0;
44 ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
45
46}
#define APIC_PROFILE_VECTOR
Definition: apicp.h:50
@ APIC_TICR
Definition: apicp.h:102
@ APIC_TMRLVTR
Definition: apicp.h:96
LARGE_INTEGER HalpCpuClockFrequency
Definition: tsc.c:17
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
UINT32 TimerMode
Definition: apicp.h:275
UINT32 Long
Definition: apicp.h:264
UINT32 Vector
Definition: apicp.h:267
UINT32 Mask
Definition: apicp.h:274

Referenced by ApicInitializeTimer().

◆ HalInitializeProfiling()

VOID NTAPI HalInitializeProfiling ( VOID  )

Definition at line 76 of file apictimer.c.

77{
79 KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] = 1; /* TODO: HACK */
80}
ULONGLONG HalCurProfileInterval
Definition: apictimer.c:20
#define HAL_PROFILING_MULTIPLIER
Definition: halp.h:55
#define HAL_PROFILING_INTERVAL
Definition: halp.h:54
#define KeGetPcr()
Definition: ketypes.h:81

Referenced by HalpInitProcessor().

◆ HalpProfileInterruptHandler()

VOID FASTCALL HalpProfileInterruptHandler ( _In_ PKTRAP_FRAME  TrapFrame)

Definition at line 66 of file apictimer.c.

67{
69}
@ ProfileTime
Definition: winternl.h:2123
VOID NTAPI KeProfileInterruptWithSource(IN PKTRAP_FRAME TrapFrame, IN KPROFILE_SOURCE Source)
Definition: profobj.c:354

◆ HalSetProfileInterval()

ULONG_PTR NTAPI HalSetProfileInterval ( IN ULONG_PTR  Interval)

Definition at line 129 of file apictimer.c.

130{
131 ULONGLONG TimerInterval;
132 ULONGLONG FixedInterval;
133
134 FixedInterval = (ULONGLONG)Interval;
135
136 /* Check bounds */
137 if (FixedInterval < HalMinProfileInterval)
138 {
139 FixedInterval = HalMinProfileInterval;
140 }
141 else if (FixedInterval > HalMaxProfileInterval)
142 {
143 FixedInterval = HalMaxProfileInterval;
144 }
145
146 /* Remember interval */
147 HalCurProfileInterval = FixedInterval;
148
149 /* Recalculate interval for APIC */
150 TimerInterval = FixedInterval * KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] / HalMaxProfileInterval;
151
152 /* Remember recalculated interval in PCR */
153 KeGetPcr()->HalReserved[HAL_PROFILING_INTERVAL] = (ULONG)TimerInterval;
154
155 /* And set it */
156 ApicWrite(APIC_TICR, (ULONG)TimerInterval);
157
158 return Interval;
159}
ULONGLONG HalMaxProfileInterval
Definition: apictimer.c:22
ULONGLONG HalMinProfileInterval
Definition: apictimer.c:21
DWORD Interval
Definition: netstat.c:30

◆ HalStartProfileInterrupt()

VOID NTAPI HalStartProfileInterrupt ( IN KPROFILE_SOURCE  ProfileSource)

Definition at line 84 of file apictimer.c.

85{
86 LVT_REGISTER LvtEntry;
87
88 /* Only handle ProfileTime */
89 if (ProfileSource == ProfileTime)
90 {
91 /* OK, we are profiling now */
93
94 /* Set interrupt interval */
96
97 /* Unmask it */
98 LvtEntry.Long = 0;
99 LvtEntry.TimerMode = 1;
100 LvtEntry.Vector = APIC_PROFILE_VECTOR;
101 LvtEntry.Mask = 0;
102 ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
103 }
104}
BOOLEAN HalIsProfiling
Definition: apictimer.c:19
#define TRUE
Definition: types.h:120

◆ HalStopProfileInterrupt()

VOID NTAPI HalStopProfileInterrupt ( IN KPROFILE_SOURCE  ProfileSource)

Definition at line 108 of file apictimer.c.

109{
110 LVT_REGISTER LvtEntry;
111
112 /* Only handle ProfileTime */
113 if (ProfileSource == ProfileTime)
114 {
115 /* We are not profiling */
117
118 /* Mask interrupt */
119 LvtEntry.Long = 0;
120 LvtEntry.TimerMode = 1;
121 LvtEntry.Vector = APIC_PROFILE_VECTOR;
122 LvtEntry.Mask = 1;
123 ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
124 }
125}
#define FALSE
Definition: types.h:117

Variable Documentation

◆ HalCurProfileInterval

ULONGLONG HalCurProfileInterval = 10000000

Definition at line 20 of file apictimer.c.

Referenced by HalInitializeProfiling(), and HalSetProfileInterval().

◆ HalIsProfiling

BOOLEAN HalIsProfiling = FALSE

Definition at line 19 of file apictimer.c.

Referenced by HalStartProfileInterrupt(), and HalStopProfileInterrupt().

◆ HalMaxProfileInterval

ULONGLONG HalMaxProfileInterval = 10000000

Definition at line 22 of file apictimer.c.

Referenced by HalSetProfileInterval().

◆ HalMinProfileInterval

ULONGLONG HalMinProfileInterval = 1000

Definition at line 21 of file apictimer.c.

Referenced by HalSetProfileInterval().

◆ HalpCpuClockFrequency

LARGE_INTEGER HalpCpuClockFrequency
extern

Definition at line 17 of file tsc.c.

Referenced by ApicSetTimerInterval().