From 211999ac6a07d06f69f8f3ce30bb0461d4f001fa Mon Sep 17 00:00:00 2001 From: janwas Date: Mon, 28 May 2007 16:50:08 +0000 Subject: [PATCH] fixes to timer impls: pmt: support ACPI 1.0 table name qpc: just use wcpu_ClockFrequency, can't fail tsc: do ia32_Init first This was SVN commit r5111. --- source/lib/sysdep/win/whrt/pmt.cpp | 6 ++++-- source/lib/sysdep/win/whrt/qpc.cpp | 10 ++-------- source/lib/sysdep/win/whrt/tsc.cpp | 3 +++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/source/lib/sysdep/win/whrt/pmt.cpp b/source/lib/sysdep/win/whrt/pmt.cpp index bc4689ac35..5164521b85 100644 --- a/source/lib/sysdep/win/whrt/pmt.cpp +++ b/source/lib/sysdep/win/whrt/pmt.cpp @@ -37,7 +37,8 @@ LibError CounterPMT::Activate() return ERR::FAIL; // NOWARN (no Administrator privileges) if(!acpi_Init()) WARN_RETURN(ERR::FAIL); - const FADT* fadt = (const FADT*)acpi_GetTable("FADT"); + // (note: it's called FADT, but the signature is "FACP") + const FADT* fadt = (const FADT*)acpi_GetTable("FACP"); if(!fadt) WARN_RETURN(ERR::NO_SYS); m_portAddress = u16_from_larger(fadt->pmTimerPortAddress); @@ -73,7 +74,8 @@ u64 CounterPMT::Counter() const **/ uint CounterPMT::CounterBits() const { - const FADT* fadt = (const FADT*)acpi_GetTable("FADT"); + // (see previous acpi_GetTable call) + const FADT* fadt = (const FADT*)acpi_GetTable("FACP"); debug_assert(fadt); // Activate made sure FADT is available const uint counterBits = (fadt->flags & TMR_VAL_EXT)? 32 : 24; return counterBits; diff --git a/source/lib/sysdep/win/whrt/qpc.cpp b/source/lib/sysdep/win/whrt/qpc.cpp index cf9ac938a3..30d11e3680 100644 --- a/source/lib/sysdep/win/whrt/qpc.cpp +++ b/source/lib/sysdep/win/whrt/qpc.cpp @@ -68,18 +68,12 @@ bool CounterQPC::IsSafe() const // therefore considered unsafe and recognized by comparing frequency // against the CPU clock. - const double cpuClockFrequency = wcpu_ClockFrequency(); - // failed for some reason => can't tell if RDTSC is being used - // => assume unsafe - if(cpuClockFrequency == 0.0) - return false; - // QPC frequency matches the CPU clock => it uses RDTSC => unsafe. - if(IsSimilarMagnitude(m_frequency, cpuClockFrequency)) + if(IsSimilarMagnitude(m_frequency, wcpu_ClockFrequency())) return false; // unconfirmed reports indicate QPC sometimes uses 1/3 of the // CPU clock frequency, so check that as well. - if(IsSimilarMagnitude(m_frequency, cpuClockFrequency/3)) + if(IsSimilarMagnitude(m_frequency, wcpu_ClockFrequency()/3)) return false; // otherwise: it's apparently using the HPET => safe. diff --git a/source/lib/sysdep/win/whrt/tsc.cpp b/source/lib/sysdep/win/whrt/tsc.cpp index 20792fe2ee..2730de2d64 100644 --- a/source/lib/sysdep/win/whrt/tsc.cpp +++ b/source/lib/sysdep/win/whrt/tsc.cpp @@ -95,6 +95,8 @@ static LibError InitPerCpuTscStates(double cpuClockFrequency) LibError CounterTSC::Activate() { + ia32_Init(); + if(!ia32_cap(IA32_CAP_TSC)) return ERR::NO_SYS; // NOWARN (CPU doesn't support RDTSC) @@ -104,6 +106,7 @@ LibError CounterTSC::Activate() void CounterTSC::Shutdown() { + ia32_Shutdown(); } bool CounterTSC::IsSafe() const