mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1426513, part 3 - Remove CPU and TimeTicks::HighResNow. r=jld
CPU is only used on Windows, for TimeTicks::HighResNow, but the latter is not used, so remove them all. MozReview-Commit-ID: CvV1gMrVRA5 --HG-- extra : rebase_source : 60ddcf6ea5542f4526a23d739a2fe754219e5b9f
This commit is contained in:
parent
52848c69fb
commit
7b5bcc482d
@ -35,7 +35,6 @@ UNIFIED_SOURCES += [
|
||||
if os_win:
|
||||
SOURCES += [
|
||||
'src/base/condition_variable_win.cc',
|
||||
'src/base/cpu.cc',
|
||||
'src/base/file_util_win.cc',
|
||||
'src/base/lock_impl_win.cc',
|
||||
'src/base/message_pump_win.cc',
|
||||
|
@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/cpu.h"
|
||||
#include <intrin.h>
|
||||
#include <string>
|
||||
|
||||
namespace base {
|
||||
|
||||
CPU::CPU()
|
||||
: type_(0),
|
||||
family_(0),
|
||||
model_(0),
|
||||
stepping_(0),
|
||||
ext_model_(0),
|
||||
ext_family_(0),
|
||||
cpu_vendor_("unknown") {
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void CPU::Initialize() {
|
||||
int cpu_info[4] = {-1};
|
||||
char cpu_string[0x20];
|
||||
|
||||
// __cpuid with an InfoType argument of 0 returns the number of
|
||||
// valid Ids in CPUInfo[0] and the CPU identification string in
|
||||
// the other three array elements. The CPU identification string is
|
||||
// not in linear order. The code below arranges the information
|
||||
// in a human readable form.
|
||||
//
|
||||
// More info can be found here:
|
||||
// http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
|
||||
__cpuid(cpu_info, 0);
|
||||
int num_ids = cpu_info[0];
|
||||
memset(cpu_string, 0, sizeof(cpu_string));
|
||||
*(reinterpret_cast<int*>(cpu_string)) = cpu_info[1];
|
||||
*(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3];
|
||||
*(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2];
|
||||
|
||||
// Interpret CPU feature information.
|
||||
if (num_ids > 0) {
|
||||
__cpuid(cpu_info, 1);
|
||||
stepping_ = cpu_info[0] & 0xf;
|
||||
model_ = (cpu_info[0] >> 4) & 0xf;
|
||||
family_ = (cpu_info[0] >> 8) & 0xf;
|
||||
type_ = (cpu_info[0] >> 12) & 0x3;
|
||||
ext_model_ = (cpu_info[0] >> 16) & 0xf;
|
||||
ext_family_ = (cpu_info[0] >> 20) & 0xff;
|
||||
cpu_vendor_ = cpu_string;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace base
|
@ -1,44 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef BASE_CPU_H_
|
||||
#define BASE_CPU_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace base {
|
||||
|
||||
// Query information about the processor.
|
||||
class CPU {
|
||||
public:
|
||||
// Constructor
|
||||
CPU();
|
||||
|
||||
// Accessors for CPU information.
|
||||
const std::string& vendor_name() const { return cpu_vendor_; }
|
||||
int stepping() const { return stepping_; }
|
||||
int model() const { return model_; }
|
||||
int family() const { return family_; }
|
||||
int type() const { return type_; }
|
||||
int extended_model() const { return ext_model_; }
|
||||
int extended_family() const { return ext_family_; }
|
||||
|
||||
private:
|
||||
// Query the processor for CPUID information.
|
||||
void Initialize();
|
||||
|
||||
int type_; // process type
|
||||
int family_; // family of the processor
|
||||
int model_; // model of processor
|
||||
int stepping_; // processor revision number
|
||||
int ext_model_;
|
||||
int ext_family_;
|
||||
std::string cpu_vendor_;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_CPU_H_
|
@ -395,12 +395,6 @@ class TimeTicks {
|
||||
// on hardware/operating system configuration.
|
||||
static TimeTicks Now();
|
||||
|
||||
// Returns a platform-dependent high-resolution tick count. Implementation
|
||||
// is hardware dependent and may or may not return sub-millisecond
|
||||
// resolution. THIS CALL IS GENERALLY MUCH MORE EXPENSIVE THAN Now() AND
|
||||
// SHOULD ONLY BE USED WHEN IT IS REALLY NEEDED.
|
||||
static TimeTicks HighResNow();
|
||||
|
||||
// Returns true if this object has not been initialized.
|
||||
bool is_null() const {
|
||||
return ticks_ == 0;
|
||||
|
@ -197,9 +197,4 @@ TimeTicks TimeTicks::Now() {
|
||||
return TimeTicks(absolute_micro);
|
||||
}
|
||||
|
||||
// static
|
||||
TimeTicks TimeTicks::HighResNow() {
|
||||
return Now();
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "base/basictypes.h"
|
||||
#include "base/lock.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/cpu.h"
|
||||
#include "base/singleton.h"
|
||||
#include "mozilla/Casting.h"
|
||||
|
||||
@ -256,105 +255,6 @@ class NowSingleton {
|
||||
DISALLOW_COPY_AND_ASSIGN(NowSingleton);
|
||||
};
|
||||
|
||||
// Overview of time counters:
|
||||
// (1) CPU cycle counter. (Retrieved via RDTSC)
|
||||
// The CPU counter provides the highest resolution time stamp and is the least
|
||||
// expensive to retrieve. However, the CPU counter is unreliable and should not
|
||||
// be used in production. Its biggest issue is that it is per processor and it
|
||||
// is not synchronized between processors. Also, on some computers, the counters
|
||||
// will change frequency due to thermal and power changes, and stop in some
|
||||
// states.
|
||||
//
|
||||
// (2) QueryPerformanceCounter (QPC). The QPC counter provides a high-
|
||||
// resolution (100 nanoseconds) time stamp but is comparatively more expensive
|
||||
// to retrieve. What QueryPerformanceCounter actually does is up to the HAL.
|
||||
// (with some help from ACPI).
|
||||
// According to http://blogs.msdn.com/oldnewthing/archive/2005/09/02/459952.aspx
|
||||
// in the worst case, it gets the counter from the rollover interrupt on the
|
||||
// programmable interrupt timer. In best cases, the HAL may conclude that the
|
||||
// RDTSC counter runs at a constant frequency, then it uses that instead. On
|
||||
// multiprocessor machines, it will try to verify the values returned from
|
||||
// RDTSC on each processor are consistent with each other, and apply a handful
|
||||
// of workarounds for known buggy hardware. In other words, QPC is supposed to
|
||||
// give consistent result on a multiprocessor computer, but it is unreliable in
|
||||
// reality due to bugs in BIOS or HAL on some, especially old computers.
|
||||
// With recent updates on HAL and newer BIOS, QPC is getting more reliable but
|
||||
// it should be used with caution.
|
||||
//
|
||||
// (3) System time. The system time provides a low-resolution (typically 10ms
|
||||
// to 55 milliseconds) time stamp but is comparatively less expensive to
|
||||
// retrieve and more reliable.
|
||||
class HighResNowSingleton {
|
||||
public:
|
||||
HighResNowSingleton()
|
||||
: ticks_per_microsecond_(0.0),
|
||||
skew_(0) {
|
||||
InitializeClock();
|
||||
|
||||
// On Athlon X2 CPUs (e.g. model 15) QueryPerformanceCounter is
|
||||
// unreliable. Fallback to low-res clock.
|
||||
base::CPU cpu;
|
||||
if (cpu.vendor_name() == "AuthenticAMD" && cpu.family() == 15)
|
||||
DisableHighResClock();
|
||||
}
|
||||
|
||||
bool IsUsingHighResClock() {
|
||||
return ticks_per_microsecond_ != 0.0;
|
||||
}
|
||||
|
||||
void DisableHighResClock() {
|
||||
ticks_per_microsecond_ = 0.0;
|
||||
}
|
||||
|
||||
TimeDelta Now() {
|
||||
// Our maximum tolerance for QPC drifting.
|
||||
const int kMaxTimeDrift = 50 * Time::kMicrosecondsPerMillisecond;
|
||||
|
||||
if (IsUsingHighResClock()) {
|
||||
int64_t now = UnreliableNow();
|
||||
|
||||
// Verify that QPC does not seem to drift.
|
||||
DCHECK(now - ReliableNow() - skew_ < kMaxTimeDrift);
|
||||
|
||||
return TimeDelta::FromMicroseconds(now);
|
||||
}
|
||||
|
||||
// Just fallback to the slower clock.
|
||||
return Singleton<NowSingleton>::get()->Now();
|
||||
}
|
||||
|
||||
private:
|
||||
// Synchronize the QPC clock with GetSystemTimeAsFileTime.
|
||||
void InitializeClock() {
|
||||
LARGE_INTEGER ticks_per_sec = {{0}};
|
||||
if (!QueryPerformanceFrequency(&ticks_per_sec))
|
||||
return; // Broken, we don't guarantee this function works.
|
||||
ticks_per_microsecond_ = static_cast<float>(ticks_per_sec.QuadPart) /
|
||||
static_cast<float>(Time::kMicrosecondsPerSecond);
|
||||
|
||||
skew_ = UnreliableNow() - ReliableNow();
|
||||
}
|
||||
|
||||
// Get the number of microseconds since boot in a reliable fashion
|
||||
int64_t UnreliableNow() {
|
||||
LARGE_INTEGER now;
|
||||
QueryPerformanceCounter(&now);
|
||||
return static_cast<int64_t>(now.QuadPart / ticks_per_microsecond_);
|
||||
}
|
||||
|
||||
// Get the number of microseconds since boot in a reliable fashion
|
||||
int64_t ReliableNow() {
|
||||
return Singleton<NowSingleton>::get()->Now().InMicroseconds();
|
||||
}
|
||||
|
||||
// Cached clock frequency -> microseconds. This assumes that the clock
|
||||
// frequency is faster than one microsecond (which is 1MHz, should be OK).
|
||||
float ticks_per_microsecond_; // 0 indicates QPF failed and we're broken.
|
||||
int64_t skew_; // Skew between lo-res and hi-res clocks (for debugging).
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(HighResNowSingleton);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
@ -369,8 +269,3 @@ TimeTicks::TickFunctionType TimeTicks::SetMockTickFunction(
|
||||
TimeTicks TimeTicks::Now() {
|
||||
return TimeTicks() + Singleton<NowSingleton>::get()->Now();
|
||||
}
|
||||
|
||||
// static
|
||||
TimeTicks TimeTicks::HighResNow() {
|
||||
return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user