Skip to content

timer refactor regresses absl under arm user-mode

bd8e9ddf appears to have regressed the logic here: https://github.com/abseil/abseil-cpp/blob/bf891a1c975345cca95c122a9810a86d4541bf06/absl/base/internal/unscaledcycleclock.cc#L112

Minimal repo:

#include <stdint.h>
#include <stdio.h>

double frequency() {
  uint64_t aarch64_timer_frequency;
  asm volatile("mrs %0, cntfrq_el0" : "=r"(aarch64_timer_frequency));
  return aarch64_timer_frequency;
}

int main(int argc, char** argv) {
  double f = frequency();
  printf("f=%f\n", f);
  return 0;
}

At bd8e9ddf:

./build/qemu-aarch64 ~/a.out 
f=0.000000
pefoley@pefoley:~/qemu$ ./build/qemu-aarch64 -version
qemu-aarch64 version 9.0.50 (v9.0.0-277-gbd8e9ddf6f-dirty)

At dcc5c018 (the previous commit):

pefoley@pefoley:~/qemu$ ./build/qemu-aarch64 ~/a.out 
f=62500000.000000
pefoley@pefoley:~/qemu$ ./build/qemu-aarch64 -version
qemu-aarch64 version 9.0.50 (v9.0.0-276-gdcc5c018c7-dirty)

(dirty because I had to locally apply 27a8d899 to compile with modern glibc).

Also reproduces at v10.1.0:

pefoley@pefoley:~/qemu$ ./build/qemu-aarch64 ~/a.out 
f=0.000000
pefoley@pefoley:~/qemu$ ./build/qemu-aarch64 -version
qemu-aarch64 version 10.1.0 (v10.1.0)
Edited by Peter Foley
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information