Commit a2737d3c authored by Gaurav Dhol's avatar Gaurav Dhol Committed by Commit Bot

Support CPU cycle counter on ARM64

ARM64 CPUs don't use __rdtsc to get the CPU cycle counter because that
is an x86/x64 specific instruction. This change updates ThreadTicks to
use the appropriate counter on ARM64 builds on Win32.

Bug: 893460
Change-Id: Ia9679aa8d560f887c5a787b9e6f333ceed9d1192
Reviewed-on: https://chromium-review.googlesource.com/c/1301577Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609467}
parent 91445a3f
......@@ -277,6 +277,7 @@ Gajendra Singh <wxjg68@motorola.com>
Ganesh Borle <ganesh.borle@samsung.com>
Gao Chun <chun.gao@intel.com>
Gao Chun <gaochun.dev@gmail.com>
Gaurav Dhol <gaurav.dhol@einfochips.com>
Gautham Banasandra <gautham.bangalore@gmail.com>
George Adams <geoada@amazon.com>
George Joseph <kottackal.george@gmail.com>
......@@ -980,8 +981,7 @@ Zsolt Borbely <zsborbely.u-szeged@partner.samsung.com>
Rajesh Mahindra <rmahindra@uber.com>
Yuan-Pin Yu <yjames@uber.com>
Vinoth Chandar <vinoth@uber.com>
Zheng Xu <zxu@kobo.com>
Gaurav Dhol <gaurav.dhol@einfochips.com>
Zheng Xu <zxu@kobo.com>
ACCESS CO., LTD. <*@access-company.com>
Akamai Inc. <*@akamai.com>
......
......@@ -650,6 +650,12 @@ void ThreadTicks::WaitUntilInitializedWin() {
::Sleep(10);
}
#if defined(_M_ARM64) && defined(__clang__)
#define ReadCycleCounter() _ReadStatusReg(ARM64_PMCCNTR_EL0)
#else
#define ReadCycleCounter() __rdtsc()
#endif
double ThreadTicks::TSCTicksPerSecond() {
DCHECK(IsSupported());
......@@ -670,12 +676,13 @@ double ThreadTicks::TSCTicksPerSecond() {
// The first time that this function is called, make an initial reading of the
// TSC and the performance counter.
static const uint64_t tsc_initial = __rdtsc();
static const uint64_t tsc_initial = ReadCycleCounter();
static const uint64_t perf_counter_initial = QPCNowRaw();
// Make a another reading of the TSC and the performance counter every time
// that this function is called.
uint64_t tsc_now = __rdtsc();
uint64_t tsc_now = ReadCycleCounter();
uint64_t perf_counter_now = QPCNowRaw();
// Reset the thread priority.
......@@ -709,6 +716,7 @@ double ThreadTicks::TSCTicksPerSecond() {
return tsc_ticks_per_second;
}
#undef ReadCycleCounter
// static
TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) {
return TimeTicks() + QPCValueToTimeDelta(qpc_value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment