bionic: add vdso clock_getres
clock_getres() should not be a hot call, nevertheless it is
~6-7 times faster for supported clock ids if it uses
__vdso_clock_getres if available. There is a 3% performance
penalty for unsupported clock ids via __vdso_clock_getres with
respect to a direct syscall.
[TL;DR]
w/vdso32 kernel patches, locked cores to MAX, little cores only.
BEFORE:
hikey960 vdso (aarch64):
----------------------------------------------------------------------
Benchmark Time CPU Iterations
----------------------------------------------------------------------
BM_time_clock_getres 126 ns 126 ns 5577874
BM_time_clock_getres_syscall 127 ns 127 ns 5505016
BM_time_clock_getres_REALTIME 126 ns 126 ns 5574682
BM_time_clock_getres_BOOTTIME 126 ns 126 ns 5575237
BM_time_clock_getres_TAI 126 ns 126 ns 5576810
BM_time_clock_getres_unsupported 128 ns 128 ns 5480189
hikey960 vdso32 (aarch32):
----------------------------------------------------------------------
Benchmark Time CPU Iterations
----------------------------------------------------------------------
BM_time_clock_getres 199 ns 199 ns 3508708
BM_time_clock_getres_syscall 220 ns 220 ns 3184676
BM_time_clock_getres_REALTIME 199 ns 199 ns 3509697
BM_time_clock_getres_BOOTTIME 199 ns 199 ns 3513551
BM_time_clock_getres_TAI 200 ns 199 ns 3512412
BM_time_clock_getres_unsupported 196 ns 196 ns 3575609
x86_64 (glibc):
---------------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------------
BM_time_clock_getres 252 ns 252 ns 2370263
BM_time_clock_getres_syscall 215 ns 215 ns 3287497
BM_time_clock_getres_REALTIME 214 ns 214 ns 3294228
BM_time_clock_getres_BOOTTIME 213 ns 213 ns 3277519
BM_time_clock_getres_TAI 213 ns 213 ns 3294991
BM_time_clock_getres_unsupported 206 ns 206 ns 3450654
imx7d_pico IOT nyc (w/arm,cpu-registers-not-fw-configured) (armv7a):
(Virtual Timers)
Benchmark Time(ns) CPU(ns) Iterations
------------------------------------------------------------------
BM_time_clock_getres 16 345 2000000
BM_time_clock_getres_syscall 16 339 2121212
BM_time_clock_getres_REALTIME 17 350 2058824
BM_time_clock_getres_BOOTTIME 17 345 2000000
BM_time_clock_getres_TAI 16 350 2000000
BM_time_clock_getres_unsupported 13 284 2500000
AFTER:
hikey960 vdso (aarch64):
---------------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------------
BM_time_clock_getres 18 ns 18 ns 37880389
BM_time_clock_getres_syscall 127 ns 127 ns 5520029
BM_time_clock_getres_REALTIME 18 ns 18 ns 37879962
BM_time_clock_getres_BOOTTIME 19 ns 18 ns 37878361
BM_time_clock_getres_TAI 131 ns 131 ns 5368484
BM_time_clock_getres_unsupported 97 ns 97 ns 7182864
hikey960 vdso32 (aarch32):
---------------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------------
BM_time_clock_getres 36 ns 36 ns 19205240
BM_time_clock_getres_syscall 212 ns 212 ns 3297100
BM_time_clock_getres_REALTIME 36 ns 36 ns 19219109
BM_time_clock_getres_BOOTTIME 36 ns 36 ns 19222490
BM_time_clock_getres_TAI 206 ns 206 ns 3402868
BM_time_clock_getres_unsupported 159 ns 159 ns 4409492
imx7d_pico IOT nyc (wo/arm,cpu-registers-not-fw-configured) (armv7a):
(Physical Timers)
Benchmark Time(ns) CPU(ns) Iterations
------------------------------------------------------------------
BM_time_clock_getres 2 48 14000000
BM_time_clock_getres_syscall 14 335 2058824
BM_time_clock_getres_REALTIME 2 49 14583333
BM_time_clock_getres_BOOTTIME 2 48 14000000
BM_time_clock_getres_TAI 14 350 2058824
BM_time_clock_getres_unsupported 8 203 3500000
Test: taskset F \
/data/benchmarktest{64}/bionic-benchmarks/bionic-benchmarks \
--bionic_xml=vdso.xml --benchmark_filter=BM_time_clock_getres*
Bug: 63737556
Change-Id: I80c0a5106625d76720287f715fcf145d2aad1705
diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp
index 969c39f..00d6490 100644
--- a/libc/bionic/vdso.cpp
+++ b/libc/bionic/vdso.cpp
@@ -42,6 +42,15 @@
return __clock_gettime(clock_id, tp);
}
+int clock_getres(int clock_id, timespec* tp) {
+ auto vdso_clock_getres = reinterpret_cast<decltype(&clock_getres)>(
+ __libc_globals->vdso[VDSO_CLOCK_GETRES].fn);
+ if (__predict_true(vdso_clock_getres)) {
+ return vdso_return(vdso_clock_getres(clock_id, tp));
+ }
+ return __clock_getres(clock_id, tp);
+}
+
int gettimeofday(timeval* tv, struct timezone* tz) {
auto vdso_gettimeofday = reinterpret_cast<decltype(&gettimeofday)>(
__libc_globals->vdso[VDSO_GETTIMEOFDAY].fn);
@@ -54,6 +63,7 @@
void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args) {
auto&& vdso = globals->vdso;
vdso[VDSO_CLOCK_GETTIME] = { VDSO_CLOCK_GETTIME_SYMBOL, nullptr };
+ vdso[VDSO_CLOCK_GETRES] = { VDSO_CLOCK_GETRES_SYMBOL, nullptr };
vdso[VDSO_GETTIMEOFDAY] = { VDSO_GETTIMEOFDAY_SYMBOL, nullptr };
// Do we have a vdso?