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
--- a/ipc/chromium/moz.build
+++ b/ipc/chromium/moz.build
@@ -30,17 +30,16 @@ UNIFIED_SOURCES += [
'src/chrome/common/chrome_switches.cc',
'src/chrome/common/ipc_channel.cc',
'src/chrome/common/ipc_message.cc',
]
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',
'src/base/object_watcher.cc',
'src/base/platform_thread_win.cc',
'src/base/process_util_win.cc',
'src/base/rand_util_win.cc',
'src/base/shared_memory_win.cc',
deleted file mode 100644
--- a/ipc/chromium/src/base/cpu.cc
+++ /dev/null
@@ -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
deleted file mode 100644
--- a/ipc/chromium/src/base/cpu.h
+++ /dev/null
@@ -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_
--- a/ipc/chromium/src/base/time.h
+++ b/ipc/chromium/src/base/time.h
@@ -390,22 +390,16 @@ class TimeTicks {
TimeTicks() : ticks_(0) {
}
// Platform-dependent tick count representing "right now."
// The resolution of this clock is ~1-15ms. Resolution varies depending
// 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;
}
// Returns the internal numeric value of the TimeTicks object.
int64_t ToInternalValue() const {
return ticks_;
--- a/ipc/chromium/src/base/time_mac.cc
+++ b/ipc/chromium/src/base/time_mac.cc
@@ -114,14 +114,9 @@ TimeTicks TimeTicks::Now() {
// Don't bother with the rollover handling that the Windows version does.
// With numer and denom = 1 (the expected case), the 64-bit absolute time
// reported in nanoseconds is enough to last nearly 585 years.
return TimeTicks(absolute_micro);
}
-// static
-TimeTicks TimeTicks::HighResNow() {
- return Now();
-}
-
} // namespace base
--- a/ipc/chromium/src/base/time_posix.cc
+++ b/ipc/chromium/src/base/time_posix.cc
@@ -192,14 +192,9 @@ TimeTicks TimeTicks::Now() {
#else // _POSIX_MONOTONIC_CLOCK
#error No usable tick clock function on this platform.
#endif // _POSIX_MONOTONIC_CLOCK
return TimeTicks(absolute_micro);
}
-// static
-TimeTicks TimeTicks::HighResNow() {
- return Now();
-}
-
} // namespace base
--- a/ipc/chromium/src/base/time_win.cc
+++ b/ipc/chromium/src/base/time_win.cc
@@ -40,17 +40,16 @@
#pragma comment(lib, "winmm.lib")
#include <windows.h>
#include <mmsystem.h>
#include "base/basictypes.h"
#include "base/lock.h"
#include "base/logging.h"
-#include "base/cpu.h"
#include "base/singleton.h"
#include "mozilla/Casting.h"
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
using mozilla::BitwiseCast;
@@ -251,126 +250,22 @@ class NowSingleton {
private:
Lock lock_; // To protected last_seen_ and rollover_.
TimeDelta rollover_; // Accumulation of time lost due to rollover.
DWORD last_seen_; // The last timeGetTime value we saw, to detect rollover.
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
TimeTicks::TickFunctionType TimeTicks::SetMockTickFunction(
TickFunctionType ticker) {
TickFunctionType old = tick_function;
tick_function = ticker;
return old;
}
// static
TimeTicks TimeTicks::Now() {
return TimeTicks() + Singleton<NowSingleton>::get()->Now();
}
-
-// static
-TimeTicks TimeTicks::HighResNow() {
- return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now();
-}