Skip to content

Commit 385033b

Browse files
authored
CycleClock: Add support for Alpha architecture (#1753)
* Add support for Alpha architecture As documented, the real cycle counter is unsafe to use here, because it is a 32-bit integer which wraps every ~4s. Use gettimeofday instead, which has a limitation of a low-precision real-time-clock (~1ms), but no wrapping. Passes test suite. Support parsing /proc/cpuinfo on Alpha tabular_test: add a missing DoNotOptimize call
1 parent b7ad5e0 commit 385033b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/cycleclock.h

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
218218
uint64_t pcycle;
219219
asm volatile("%0 = C15:14" : "=r"(pcycle));
220220
return static_cast<double>(pcycle);
221+
#elif defined(__alpha__)
222+
// Alpha has a cycle counter, the PCC register, but it is an unsigned 32-bit
223+
// integer and thus wraps every ~4s, making using it for tick counts
224+
// unreliable beyond this time range. The real-time clock is low-precision,
225+
// roughtly ~1ms, but it is the only option that can reasonable count
226+
// indefinitely.
227+
struct timeval tv;
228+
gettimeofday(&tv, nullptr);
229+
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
221230
#else
222231
// The soft failover to a generic implementation is automatic only for ARM.
223232
// For other platforms the developer is expected to make an attempt to create

src/sysinfo.cc

+4
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,11 @@ int GetNumCPUs() {
513513
std::cerr << "failed to open /proc/cpuinfo\n";
514514
return -1;
515515
}
516+
#if defined(__alpha__)
517+
const std::string Key = "cpus detected";
518+
#else
516519
const std::string Key = "processor";
520+
#endif
517521
std::string ln;
518522
while (std::getline(f, ln)) {
519523
if (ln.empty()) continue;

test/user_counters_tabular_test.cc

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ ADD_CASES(TC_CSVOut, {{"%csv_header,"
6363

6464
void BM_Counters_Tabular(benchmark::State& state) {
6565
for (auto _ : state) {
66+
// This test requires a non-zero CPU time to avoid divide-by-zero
67+
auto iterations = state.iterations();
68+
benchmark::DoNotOptimize(iterations);
6669
}
6770
namespace bm = benchmark;
6871
state.counters.insert({

0 commit comments

Comments
 (0)