ReactOS  0.4.15-dev-3294-ge98684e
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 "apicp.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 VOID
67 {
69 }
70 
71 
72 /* PUBLIC FUNCTIONS ***********************************************************/
73 
74 VOID
75 NTAPI
77 {
79  KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] = 1; /* TODO: HACK */
80 }
81 
82 VOID
83 NTAPI
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 }
105 
106 VOID
107 NTAPI
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 }
126 
127 ULONG_PTR
128 NTAPI
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 }
ULONG_PTR NTAPI HalSetProfileInterval(IN ULONG_PTR Interval)
Definition: apictimer.c:129
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:84
UINT32 Vector
Definition: apicp.h:266
#define FASTCALL
Definition: nt_native.h:50
LARGE_INTEGER HalpCpuClockFrequency
Definition: tsc.c:17
#define KeGetPcr()
Definition: ke.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
UINT32 Long
Definition: apicp.h:263
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:328
#define APIC_PROFILE_VECTOR
Definition: apicp.h:49
ULONGLONG HalMinProfileInterval
Definition: apictimer.c:21
unsigned char BOOLEAN
enum _KPROFILE_SOURCE KPROFILE_SOURCE
VOID FASTCALL HalpProfileInterruptHandler(_In_ PKTRAP_FRAME TrapFrame)
Definition: apictimer.c:66
#define _In_
Definition: ms_sal.h:308
UINT32 TimerMode
Definition: apicp.h:274
UINT32 Mask
Definition: apicp.h:273
DWORD Interval
Definition: netstat.c:33
uint64_t ULONGLONG
Definition: typedefs.h:67
VOID NTAPI ApicInitializeTimer(ULONG Cpu)
Definition: apictimer.c:50
BOOLEAN HalIsProfiling
Definition: apictimer.c:19
ULONGLONG HalCurProfileInterval
Definition: apictimer.c:20
#define HAL_PROFILING_MULTIPLIER
Definition: halp.h:47
VOID NTAPI HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
Definition: apictimer.c:108
VOID NTAPI HalInitializeProfiling(VOID)
Definition: apictimer.c:76
unsigned int ULONG
Definition: retypes.h:1
#define HAL_PROFILING_INTERVAL
Definition: halp.h:46
VOID NTAPI KeProfileInterruptWithSource(IN PKTRAP_FRAME TrapFrame, IN KPROFILE_SOURCE Source)
Definition: profobj.c:354
LONGLONG QuadPart
Definition: typedefs.h:114