mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 784859 - Part 1: Use QueryPerformanceCounter directly if the machine has a stable TSC; r=bbondy
This commit is contained in:
parent
d12e45081e
commit
cdd36264b3
@ -24,6 +24,25 @@
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
static bool
|
||||
HasStableTSC()
|
||||
{
|
||||
int regs[4];
|
||||
|
||||
// detect if the Advanced Power Management feature is supported
|
||||
__cpuid(regs, 0x80000000);
|
||||
if (regs[0] < 0x80000007)
|
||||
return false;
|
||||
|
||||
__cpuid(regs, 0x80000007);
|
||||
// if bit 8 is set than TSC will run at a constant rate
|
||||
// in all ACPI P-state, C-states and T-states
|
||||
return regs[3] & (1 << 8);
|
||||
}
|
||||
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
// Log module for mozilla::TimeStamp for Windows logging...
|
||||
//
|
||||
@ -47,6 +66,8 @@ static const double kNsPerSecd = 1000000000.0;
|
||||
static const LONGLONG kNsPerSec = 1000000000;
|
||||
static const LONGLONG kNsPerMillisec = 1000000;
|
||||
|
||||
static bool sHasStableTSC = false;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Global constants
|
||||
@ -600,6 +621,8 @@ TimeStamp::Startup()
|
||||
InitThresholds();
|
||||
InitResolution();
|
||||
|
||||
sHasStableTSC = HasStableTSC();
|
||||
|
||||
LOG(("TimeStamp: initial skew is %1.2fms", mt2ms_d(sSkew)));
|
||||
|
||||
return NS_OK;
|
||||
@ -614,6 +637,9 @@ TimeStamp::Shutdown()
|
||||
TimeStamp
|
||||
TimeStamp::Now()
|
||||
{
|
||||
if (sHasStableTSC) {
|
||||
return TimeStamp(uint64_t(PerformanceCounter()));
|
||||
}
|
||||
return TimeStamp(uint64_t(CalibratedPerformanceCounter()));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user