3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halx86/generic/profil.c
5 * PURPOSE: System Profiling
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
10 /* INCLUDES ******************************************************************/
16 /* GLOBALS *******************************************************************/
18 BOOLEAN HalpProfilingStopped
= TRUE
;
19 UCHAR HalpProfileRate
= 8;
21 /* FUNCTIONS *****************************************************************/
28 HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource
)
32 UNREFERENCED_PARAMETER(ProfileSource
);
34 /* Acquire the CMOS lock */
35 HalpAcquireCmosSpinLock();
37 /* Read Status Register B */
38 StatusB
= HalpReadCmos(RTC_REGISTER_B
);
40 /* Disable periodic interrupts */
41 StatusB
= StatusB
& ~RTC_REG_B_PI
;
43 /* Write new value into Status Register B */
44 HalpWriteCmos(RTC_REGISTER_B
, StatusB
);
46 HalpProfilingStopped
= TRUE
;
48 /* Release the CMOS lock */
49 HalpReleaseCmosSpinLock();
57 HalStartProfileInterrupt(IN KPROFILE_SOURCE ProfileSource
)
59 UCHAR StatusA
, StatusB
;
61 UNREFERENCED_PARAMETER(ProfileSource
);
63 HalpProfilingStopped
= FALSE
;
65 /* Acquire the CMOS lock */
66 HalpAcquireCmosSpinLock();
68 /* Set the interval in Status Register A */
69 StatusA
= HalpReadCmos(RTC_REGISTER_A
);
70 StatusA
= (StatusA
& 0xF0) | HalpProfileRate
;
71 HalpWriteCmos(RTC_REGISTER_A
, StatusA
);
73 /* Enable periodic interrupts in Status Register B */
74 StatusB
= HalpReadCmos(RTC_REGISTER_B
);
75 StatusB
= StatusB
| RTC_REG_B_PI
;
76 HalpWriteCmos(RTC_REGISTER_B
, StatusB
);
78 /* Release the CMOS lock */
79 HalpReleaseCmosSpinLock();
87 HalSetProfileInterval(IN ULONG_PTR Interval
)
89 ULONG_PTR CurrentValue
, NextValue
;
92 /* Normalize interval. 122100 ns is the smallest supported */
93 Interval
&= ~(1 << 31);
97 /* Highest rate value of 15 means 500 ms */
98 CurrentValue
= 5000000;
101 NextValue
= (CurrentValue
+ 1) / 2;
102 if (Interval
> CurrentValue
- NextValue
/ 2)
104 CurrentValue
= NextValue
;
107 /* Interval as needed by RTC */
111 if (!HalpProfilingStopped
)
113 HalStartProfileInterrupt(0);