2009-10-12 03:35:35 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS HAL
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: hal/halx86/generic/profil.c
|
|
|
|
* PURPOSE: System Profiling
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2010-09-25 07:22:40 +00:00
|
|
|
* Eric Kohl
|
2009-10-12 03:35:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <hal.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2015-08-29 16:45:00 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
BOOLEAN HalpProfilingStopped = TRUE;
|
|
|
|
UCHAR HalpProfileRate = 8;
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
/*
|
2010-09-25 07:22:40 +00:00
|
|
|
* @implemented
|
2009-10-12 03:35:35 +00:00
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
|
|
|
|
{
|
2010-09-25 07:22:40 +00:00
|
|
|
UCHAR StatusB;
|
|
|
|
|
2015-08-29 16:45:00 +00:00
|
|
|
UNREFERENCED_PARAMETER(ProfileSource);
|
|
|
|
|
2010-09-25 07:22:40 +00:00
|
|
|
/* Acquire the CMOS lock */
|
2011-09-07 10:14:48 +00:00
|
|
|
HalpAcquireCmosSpinLock();
|
2010-09-25 07:22:40 +00:00
|
|
|
|
|
|
|
/* Read Status Register B */
|
|
|
|
StatusB = HalpReadCmos(RTC_REGISTER_B);
|
|
|
|
|
|
|
|
/* Disable periodic interrupts */
|
|
|
|
StatusB = StatusB & ~RTC_REG_B_PI;
|
|
|
|
|
|
|
|
/* Write new value into Status Register B */
|
|
|
|
HalpWriteCmos(RTC_REGISTER_B, StatusB);
|
|
|
|
|
2015-08-29 16:45:00 +00:00
|
|
|
HalpProfilingStopped = TRUE;
|
|
|
|
|
2010-09-25 07:22:40 +00:00
|
|
|
/* Release the CMOS lock */
|
|
|
|
HalpReleaseCmosSpinLock();
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
HalStartProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
|
|
|
|
{
|
2015-08-29 16:45:00 +00:00
|
|
|
UCHAR StatusA, StatusB;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(ProfileSource);
|
|
|
|
|
|
|
|
HalpProfilingStopped = FALSE;
|
|
|
|
|
|
|
|
/* Acquire the CMOS lock */
|
|
|
|
HalpAcquireCmosSpinLock();
|
|
|
|
|
|
|
|
/* Set the interval in Status Register A */
|
|
|
|
StatusA = HalpReadCmos(RTC_REGISTER_A);
|
|
|
|
StatusA = (StatusA & 0xF0) | HalpProfileRate;
|
|
|
|
HalpWriteCmos(RTC_REGISTER_A, StatusA);
|
|
|
|
|
|
|
|
/* Enable periodic interrupts in Status Register B */
|
|
|
|
StatusB = HalpReadCmos(RTC_REGISTER_B);
|
|
|
|
StatusB = StatusB | RTC_REG_B_PI;
|
|
|
|
HalpWriteCmos(RTC_REGISTER_B, StatusB);
|
|
|
|
|
|
|
|
/* Release the CMOS lock */
|
|
|
|
HalpReleaseCmosSpinLock();
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
ULONG_PTR
|
|
|
|
NTAPI
|
|
|
|
HalSetProfileInterval(IN ULONG_PTR Interval)
|
|
|
|
{
|
2015-08-29 16:45:00 +00:00
|
|
|
ULONG_PTR CurrentValue, NextValue;
|
|
|
|
UCHAR i;
|
|
|
|
|
|
|
|
/* Normalize interval. 122100 ns is the smallest supported */
|
|
|
|
Interval &= ~(1 << 31);
|
|
|
|
if (Interval < 1221)
|
|
|
|
Interval = 1221;
|
|
|
|
|
|
|
|
/* Highest rate value of 15 means 500 ms */
|
|
|
|
CurrentValue = 5000000;
|
|
|
|
for (i = 15; ; i--)
|
|
|
|
{
|
|
|
|
NextValue = (CurrentValue + 1) / 2;
|
|
|
|
if (Interval > CurrentValue - NextValue / 2)
|
|
|
|
break;
|
|
|
|
CurrentValue = NextValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interval as needed by RTC */
|
|
|
|
HalpProfileRate = i;
|
|
|
|
|
|
|
|
/* Reset the */
|
|
|
|
if (!HalpProfilingStopped)
|
|
|
|
{
|
|
|
|
HalStartProfileInterrupt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CurrentValue;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|