ReactOS  0.4.13-dev-249-gcba1a2f
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 #define NDEBUG
13 #include <debug.h>
14 
15 #include "apic.h"
16 
18 
19 /* HAL profiling variables */
24 
25 /* TIMER FUNCTIONS ************************************************************/
26 
27 VOID
28 NTAPI
30 {
31  LVT_REGISTER LvtEntry;
32  ULONGLONG TimerInterval;
33 
34  /* Calculate the Timer interval */
35  TimerInterval = HalpCpuClockFrequency.QuadPart * MicroSeconds / 1000000;
36 
37  /* Set the count interval */
38  ApicWrite(APIC_TICR, (ULONG)TimerInterval);
39 
40  /* Set to periodic */
41  LvtEntry.Long = 0;
42  LvtEntry.TimerMode = 1;
43  LvtEntry.Vector = APIC_PROFILE_VECTOR;
44  LvtEntry.Mask = 0;
45  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
46 
47 }
48 
49 VOID
50 NTAPI
52 {
53 
54  /* Initialize the TSC */
55  //HalpInitializeTsc();
56 
57  /* Set clock multiplier to 1 */
59 
61 
62 // KeSetTimeIncrement
63 }
64 
65 
66 /* PUBLIC FUNCTIONS ***********************************************************/
67 
68 VOID
69 NTAPI
71 {
73  KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] = 1; /* TODO: HACK */
74 }
75 
76 VOID
77 NTAPI
79 {
80  LVT_REGISTER LvtEntry;
81 
82  /* Only handle ProfileTime */
83  if (ProfileSource == ProfileTime)
84  {
85  /* OK, we are profiling now */
87 
88  /* Set interrupt interval */
90 
91  /* Unmask it */
92  LvtEntry.Long = 0;
93  LvtEntry.TimerMode = 1;
94  LvtEntry.Vector = APIC_PROFILE_VECTOR;
95  LvtEntry.Mask = 0;
96  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
97  }
98 }
99 
100 VOID
101 NTAPI
103 {
104  LVT_REGISTER LvtEntry;
105 
106  /* Only handle ProfileTime */
107  if (ProfileSource == ProfileTime)
108  {
109  /* We are not profiling */
111 
112  /* Mask interrupt */
113  LvtEntry.Long = 0;
114  LvtEntry.TimerMode = 1;
115  LvtEntry.Vector = APIC_PROFILE_VECTOR;
116  LvtEntry.Mask = 1;
117  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
118  }
119 }
120 
121 ULONG_PTR
122 NTAPI
124 {
125  ULONGLONG TimerInterval;
126  ULONGLONG FixedInterval;
127 
128  FixedInterval = (ULONGLONG)Interval;
129 
130  /* Check bounds */
131  if (FixedInterval < HalMinProfileInterval)
132  {
133  FixedInterval = HalMinProfileInterval;
134  }
135  else if (FixedInterval > HalMaxProfileInterval)
136  {
137  FixedInterval = HalMaxProfileInterval;
138  }
139 
140  /* Remember interval */
141  HalCurProfileInterval = FixedInterval;
142 
143  /* Recalculate interval for APIC */
144  TimerInterval = FixedInterval * KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] / HalMaxProfileInterval;
145 
146  /* Remember recalculated interval in PCR */
147  KeGetPcr()->HalReserved[HAL_PROFILING_INTERVAL] = (ULONG)TimerInterval;
148 
149  /* And set it */
150  ApicWrite(APIC_TICR, (ULONG)TimerInterval);
151 
152  return Interval;
153 }
ULONG_PTR NTAPI HalSetProfileInterval(IN ULONG_PTR Interval)
Definition: apictimer.c:123
ULONGLONG HalMaxProfileInterval
Definition: apictimer.c:23
#define IN
Definition: typedefs.h:38
enum _KPROFILE_SOURCE KPROFILE_SOURCE
#define TRUE
Definition: types.h:120
ULONG Long
Definition: apic.h:209
#define APIC_PROFILE_VECTOR
Definition: apic.h:34
VOID NTAPI ApicSetTimerInterval(ULONG MicroSeconds)
Definition: apictimer.c:29
VOID NTAPI HalStartProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
Definition: apictimer.c:78
ULONG Vector
Definition: apic.h:212
LARGE_INTEGER HalpCpuClockFrequency
Definition: tsc.c:17
#define KeGetPcr()
Definition: ke.h:25
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define APIC_TDCR
Definition: apic.h:33
ULONGLONG HalMinProfileInterval
Definition: apictimer.c:22
unsigned char BOOLEAN
DWORD Interval
Definition: netstat.c:30
uint64_t ULONGLONG
Definition: typedefs.h:65
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:272
VOID NTAPI ApicInitializeTimer(ULONG Cpu)
Definition: apictimer.c:51
ULONG Mask
Definition: apic.h:219
BOOLEAN HalIsProfiling
Definition: apictimer.c:20
ULONGLONG HalCurProfileInterval
Definition: apictimer.c:21
#define HAL_PROFILING_MULTIPLIER
Definition: halp.h:47
ULONG TimerMode
Definition: apic.h:220
VOID NTAPI HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
Definition: apictimer.c:102
#define APIC_TICR
Definition: apic.h:70
VOID NTAPI HalInitializeProfiling(VOID)
Definition: apictimer.c:70
unsigned int ULONG
Definition: retypes.h:1
#define HAL_PROFILING_INTERVAL
Definition: halp.h:46
LONGLONG QuadPart
Definition: typedefs.h:112
#define APIC_TMRLVTR
Definition: apic.h:64