ReactOS  0.4.13-dev-563-g0561610
apictimer.c File Reference
#include <hal.h>
#include <debug.h>
#include "apic.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 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 12 of file apictimer.c.

Function Documentation

◆ ApicInitializeTimer()

VOID NTAPI ApicInitializeTimer ( ULONG  Cpu)

Definition at line 51 of file apictimer.c.

52 {
53 
54  /* Initialize the TSC */
55  //HalpInitializeTsc();
56 
57  /* Set clock multiplier to 1 */
59 
61 
62 // KeSetTimeIncrement
63 }
VOID NTAPI ApicSetTimerInterval(ULONG MicroSeconds)
Definition: apictimer.c:29
#define APIC_TDCR
Definition: apic.h:33
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:272

◆ ApicSetTimerInterval()

VOID NTAPI ApicSetTimerInterval ( ULONG  MicroSeconds)

Definition at line 29 of file apictimer.c.

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 }
ULONG Long
Definition: apic.h:209
#define APIC_PROFILE_VECTOR
Definition: apic.h:34
ULONG Vector
Definition: apic.h:212
LARGE_INTEGER HalpCpuClockFrequency
Definition: tsc.c:17
uint64_t ULONGLONG
Definition: typedefs.h:65
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:272
ULONG Mask
Definition: apic.h:219
ULONG TimerMode
Definition: apic.h:220
#define APIC_TICR
Definition: apic.h:70
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:112
#define APIC_TMRLVTR
Definition: apic.h:64

Referenced by ApicInitializeTimer().

◆ HalInitializeProfiling()

VOID NTAPI HalInitializeProfiling ( VOID  )

Definition at line 70 of file apictimer.c.

71 {
73  KeGetPcr()->HalReserved[HAL_PROFILING_MULTIPLIER] = 1; /* TODO: HACK */
74 }
#define KeGetPcr()
Definition: ke.h:25
ULONGLONG HalCurProfileInterval
Definition: apictimer.c:21
#define HAL_PROFILING_MULTIPLIER
Definition: halp.h:47
#define HAL_PROFILING_INTERVAL
Definition: halp.h:46

Referenced by HalpInitProcessor().

◆ HalSetProfileInterval()

ULONG_PTR NTAPI HalSetProfileInterval ( IN ULONG_PTR  Interval)

Definition at line 123 of file apictimer.c.

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 }
ULONGLONG HalMaxProfileInterval
Definition: apictimer.c:23
#define KeGetPcr()
Definition: ke.h:25
ULONGLONG HalMinProfileInterval
Definition: apictimer.c:22
DWORD Interval
Definition: netstat.c:33
uint64_t ULONGLONG
Definition: typedefs.h:65
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:272
ULONGLONG HalCurProfileInterval
Definition: apictimer.c:21
#define HAL_PROFILING_MULTIPLIER
Definition: halp.h:47
#define APIC_TICR
Definition: apic.h:70
unsigned int ULONG
Definition: retypes.h:1
#define HAL_PROFILING_INTERVAL
Definition: halp.h:46

◆ HalStartProfileInterrupt()

VOID NTAPI HalStartProfileInterrupt ( IN KPROFILE_SOURCE  ProfileSource)

Definition at line 78 of file apictimer.c.

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 }
#define TRUE
Definition: types.h:120
ULONG Long
Definition: apic.h:209
#define APIC_PROFILE_VECTOR
Definition: apic.h:34
ULONG Vector
Definition: apic.h:212
#define KeGetPcr()
Definition: ke.h:25
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:272
ULONG Mask
Definition: apic.h:219
BOOLEAN HalIsProfiling
Definition: apictimer.c:20
ULONG TimerMode
Definition: apic.h:220
#define APIC_TICR
Definition: apic.h:70
#define HAL_PROFILING_INTERVAL
Definition: halp.h:46
#define APIC_TMRLVTR
Definition: apic.h:64

◆ HalStopProfileInterrupt()

VOID NTAPI HalStopProfileInterrupt ( IN KPROFILE_SOURCE  ProfileSource)

Definition at line 102 of file apictimer.c.

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 }
ULONG Long
Definition: apic.h:209
#define APIC_PROFILE_VECTOR
Definition: apic.h:34
ULONG Vector
Definition: apic.h:212
FORCEINLINE VOID ApicWrite(ULONG Offset, ULONG Value)
Definition: apic.h:272
ULONG Mask
Definition: apic.h:219
BOOLEAN HalIsProfiling
Definition: apictimer.c:20
ULONG TimerMode
Definition: apic.h:220
#define APIC_TMRLVTR
Definition: apic.h:64

Variable Documentation

◆ HalCurProfileInterval

ULONGLONG HalCurProfileInterval = 10000000

Definition at line 21 of file apictimer.c.

Referenced by HalInitializeProfiling(), and HalSetProfileInterval().

◆ HalIsProfiling

BOOLEAN HalIsProfiling = FALSE

Definition at line 20 of file apictimer.c.

Referenced by HalStartProfileInterrupt(), and HalStopProfileInterrupt().

◆ HalMaxProfileInterval

ULONGLONG HalMaxProfileInterval = 10000000

Definition at line 23 of file apictimer.c.

Referenced by HalSetProfileInterval().

◆ HalMinProfileInterval

ULONGLONG HalMinProfileInterval = 1000

Definition at line 22 of file apictimer.c.

Referenced by HalSetProfileInterval().

◆ HalpCpuClockFrequency

LARGE_INTEGER HalpCpuClockFrequency

Definition at line 17 of file tsc.c.

Referenced by ApicSetTimerInterval().