Commit a2972dd7 authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Fix GetTSC test to handle ARM64 on Win32

The recently added timer performance test for __rdtsc fails to compile
on ARM64, for obvious reasons. This change fixes the test to use the
ARM64 cycle counter when building for that platform.

The ReadCycleCounter definition was copied from base\time\time_win.cc

Bug: 893460
Change-Id: I0d891c5a197e097084a765ab66e9da1b4173b418
Reviewed-on: https://chromium-review.googlesource.com/c/1394987Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619820}
parent ffe1df92
...@@ -66,15 +66,23 @@ unsigned __stdcall RolloverTestThreadMain(void* param) { ...@@ -66,15 +66,23 @@ unsigned __stdcall RolloverTestThreadMain(void* param) {
return 0; return 0;
} }
// Measure the performance of __rdtsc so that we can compare it to the overhead #if defined(_M_ARM64) && defined(__clang__)
// of QueryPerformanceCounter. A hard-coded frequency is used because we don't #define ReadCycleCounter() _ReadStatusReg(ARM64_PMCCNTR_EL0)
// care about the accuracy of the results, we just need to do the work. #else
// The amount of work is not exactly the same as in TimeTicks::Now (some steps #define ReadCycleCounter() __rdtsc()
// are skipped) but that doesn't seem to materially affect the results. #endif
// Measure the performance of the CPU cycle counter so that we can compare it to
// the overhead of QueryPerformanceCounter. A hard-coded frequency is used
// because we don't care about the accuracy of the results, we just need to do
// the work. The amount of work is not exactly the same as in TimeTicks::Now
// (some steps are skipped) but that doesn't seem to materially affect the
// results.
TimeTicks GetTSC() { TimeTicks GetTSC() {
// Using a fake QPC frequency for test purposes. // Using a fake cycle counter frequency for test purposes.
return TimeTicks() + TimeDelta::FromMicroseconds( return TimeTicks() +
__rdtsc() * Time::kMicrosecondsPerSecond / 10000000); TimeDelta::FromMicroseconds(ReadCycleCounter() *
Time::kMicrosecondsPerSecond / 10000000);
} }
} // namespace } // namespace
...@@ -202,7 +210,7 @@ TEST(TimeTicks, TimerPerformance) { ...@@ -202,7 +210,7 @@ TEST(TimeTicks, TimerPerformance) {
std::vector<TestCase> cases; std::vector<TestCase> cases;
cases.push_back({reinterpret_cast<TestFunc>(&Time::Now), "Time::Now"}); cases.push_back({reinterpret_cast<TestFunc>(&Time::Now), "Time::Now"});
cases.push_back({&TimeTicks::Now, "TimeTicks::Now"}); cases.push_back({&TimeTicks::Now, "TimeTicks::Now"});
cases.push_back({&GetTSC, "rdtsc"}); cases.push_back({&GetTSC, "CPUCycleCounter"});
if (ThreadTicks::IsSupported()) { if (ThreadTicks::IsSupported()) {
ThreadTicks::WaitUntilInitialized(); ThreadTicks::WaitUntilInitialized();
......
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