ReactOS  0.4.15-dev-2700-g4b4ffa9
apictimer.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS HAL
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: hal/halx86/apic/apictimer.c
5  * PURPOSE: System Profiling
6  * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <hal.h>
12 #include <apic.h>
13 #define NDEBUG
14 #include <debug.h>
15 
17 
18 /* HAL profiling variables */
23 
24 /* TIMER FUNCTIONS ************************************************************/
25 
26 VOID
27 NTAPI
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 }
47 
48 VOID
49 NTAPI
51 {
52 
53  /* Initialize the TSC */
54  //HalpInitializeTsc();
55 
56  /* Set clock multiplier to 1 */
58 
60 
61 // KeSetTimeIncrement
62 }
63 
64 
65 /* PUBLIC FUNCTIONS ***********************************************************/
66 
67 VOID
68 NTAPI
70 {
72  KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] = 1; /* TODO: HACK */
73 }
74 
75 VOID
76 NTAPI
78 {
79  LVT_REGISTER LvtEntry;
80 
81  /* Only handle ProfileTime */
82  if (ProfileSource == ProfileTime)
83  {
84  /* OK, we are profiling now */
86 
87  /* Set interrupt interval */
89 
90  /* Unmask it */
91  LvtEntry.Long = 0;
92  LvtEntry.TimerMode = 1;
93  LvtEntry.Vector = APIC_PROFILE_VECTOR;
94  LvtEntry.Mask = 0;
95  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
96  }
97 }
98 
99 VOID
100 NTAPI
102 {
103  LVT_REGISTER LvtEntry;
104 
105  /* Only handle ProfileTime */
106  if (ProfileSource == ProfileTime)
107  {
108  /* We are not profiling */
110 
111  /* Mask interrupt */
112  LvtEntry.Long = 0;
113  LvtEntry.TimerMode = 1;
114  LvtEntry.Vector = APIC_PROFILE_VECTOR;
115  LvtEntry.Mask = 1;
116  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
117  }
118 }
119 
120 ULONG_PTR
121 NTAPI
123 {
124  ULONGLONG TimerInterval;
125  ULONGLONG FixedInterval;
126 
127  FixedInterval = (ULONGLONG)Interval;
128 
129  /* Check bounds */
130  if (FixedInterval < HalMinProfileInterval)
131  {
132  FixedInterval = HalMinProfileInterval;
133  }
134  else if (FixedInterval > HalMaxProfileInterval)
135  {
136  FixedInterval = HalMaxProfileInterval;
137  }
138 
139  /* Remember interval */
140  HalCurProfileInterval = FixedInterval;
141 
142  /* Recalculate interval for APIC */
143  TimerInterval = FixedInterval * KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] / HalMaxProfileInterval;
144 
145  /* Remember recalculated interval in PCR */
146  KeGetPcr()->HalReserved[HAL_PROFILING_INTERVAL] = (ULONG)TimerInterval;
147 
148  /* And set it */
149  ApicWrite(APIC_TICR, (ULONG)TimerInterval);
150 
151  return Interval;
152 }
ULONG_PTR NTAPI HalSetProfileInterval(IN ULONG_PTR Interval)
Definition: apictimer.c:122
ULONGLONG HalMaxProfileInterval
Definition: apictimer.c:22
#define IN
Definition: typedefs.h:39
VOID NTAPI ApicSetTimerInterval(ULONG MicroSeconds)
Definition: apictimer.c:28
#define TRUE
Definition: types.h:120
VOID NTAPI HalStartProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
Definition: apictimer.c:77
UINT32 Vector
Definition: apic.h:230
LARGE_INTEGER HalpCpuClockFrequency
Definition: tsc.c:16
#define KeGetPcr()
Definition: ke.h:26
#define APIC_TMRLVTR
Definition: apic.h:71
uint32_t ULONG_PTR
Definition: typedefs.h:65
UINT32 Long
Definition: apic.h:227
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define APIC_TDCR
Definition: apic.h:33
ULONGLONG HalMinProfileInterval
Definition: apictimer.c:21
unsigned char BOOLEAN
enum _KPROFILE_SOURCE KPROFILE_SOURCE
UINT32 TimerMode
Definition: apic.h:238
UINT32 Mask
Definition: apic.h:237
DWORD Interval
Definition: netstat.c:33
#define APIC_TICR
Definition: apic.h:77
uint64_t ULONGLONG
Definition: typedefs.h:67
VOID NTAPI ApicInitializeTimer(ULONG Cpu)
Definition: apictimer.c:50
BOOLEAN HalIsProfiling
Definition: apictimer.c:19
#define APIC_PROFILE_VECTOR
Definition: apic.h:50
ULONGLONG HalCurProfileInterval
Definition: apictimer.c:20
#define HAL_PROFILING_MULTIPLIER
Definition: halp.h:47
VOID NTAPI HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
Definition: apictimer.c:101
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:292
VOID NTAPI HalInitializeProfiling(VOID)
Definition: apictimer.c:69
unsigned int ULONG
Definition: retypes.h:1
#define HAL_PROFILING_INTERVAL
Definition: halp.h:46
LONGLONG QuadPart
Definition: typedefs.h:114