platform_bionic/libc
Mark Salyzyn 4473ccd5b0 bionic: add vdso time()
time() can be a hot call, and it currently uses __vdso_gettimeofday,
which is already pretty fast (~3 times faster than the syscall),
but with a __vdso_time call it is ~3 times even faster, in part
because __vdso_time does not require interlocking with updates,
and the read for just the seconds is atomic.  __vdso_time is
always available, whereas __vdso_gettimeofday is gated on access
to the physical timers.  arm improvement is compelling (x10),
x86 improvement is even more pronounced (x100).

[TL;DR]

w/vdso32 kernel patches, locked cores to MAX, little cores only.

BEFORE:

hikey960 vdso (aarch64):

----------------------------------------------------------------------
Benchmark                               Time           CPU Iterations
----------------------------------------------------------------------
BM_time_clock_gettime                  48 ns         48 ns   15414753
BM_time_clock_gettime_syscall         175 ns        175 ns    4062031
BM_time_clock_gettime_REALTIME         44 ns         44 ns   15897875
BM_time_clock_gettime_BOOTTIME         47 ns         47 ns   14307903
BM_time_clock_gettime_TAI             210 ns        210 ns    3341372
BM_time_clock_gettime_unsupported     100 ns        100 ns    7030649
BM_time_gettimeofday                   47 ns         47 ns   14969643
BM_time_gettimeofday_syscall          163 ns        163 ns    4283542
BM_time_time                           59 ns         59 ns   11815385

hikey960 vdso32 (aarch32):

----------------------------------------------------------------------
Benchmark                               Time           CPU Iterations
----------------------------------------------------------------------
BM_time_clock_gettime                  90 ns         90 ns    7572898
BM_time_clock_gettime_syscall         251 ns        251 ns    2763442
BM_time_clock_gettime_REALTIME         81 ns         80 ns    8699536
BM_time_clock_gettime_BOOTTIME         97 ns         97 ns    7256667
BM_time_clock_gettime_TAI             272 ns        272 ns    2570419
BM_time_clock_gettime_unsupported     160 ns        160 ns    4379819
BM_time_gettimeofday                   73 ns         73 ns    9608922
BM_time_gettimeofday_syscall          200 ns        199 ns    3527957
BM_time_time                          123 ns        123 ns    5651095

x86_64 (glibc):

--------------------------------------------------------------------
Benchmark                             Time           CPU Iterations
--------------------------------------------------------------------
BM_time_clock_gettime                  21 ns         21 ns   28873070
BM_time_clock_gettime_syscall         224 ns        224 ns    3095370
BM_time_clock_gettime_REALTIME         17 ns         17 ns   42083086
BM_time_clock_gettime_BOOTTIME        239 ns        239 ns    2924015
BM_time_clock_gettime_TAI             236 ns        236 ns    2961423
BM_time_clock_gettime_unsupported     221 ns        221 ns    3357696
BM_time_gettimeofday                 22 ns         22 ns   27975154
BM_time_gettimeofday_syscall        238 ns        238 ns    2882032
BM_time_time                          2 ns          2 ns  340354885
BM_time_time_syscall                207 ns        207 ns    3383073

imx7d_pico IOT nyc (w/arm,cpu-registers-not-fw-configured) (armv7a):
(virtual timers)

Benchmark                           Time(ns)    CPU(ns) Iterations
------------------------------------------------------------------
BM_time_clock_gettime                     20        477    1489362
BM_time_clock_gettime_syscall             20        487    1458333
BM_time_clock_gettime_REALTIME            19        464    1400000
BM_time_clock_gettime_BOOTTIME            29        700    1000000
BM_time_clock_gettime_TAI                 29        690    1000000
BM_time_clock_gettime_unsupported          9        227    3043478
BM_time_gettimeofday                      18        444    1555556
BM_time_gettimeofday_syscall              19        456    1555556
BM_time_time                              21        497    1166667

imx7d_pico IOT nyc (wo/arm,cpu-registers-not-fw-configured) (armv7a):
(physical timers)

Benchmark                           Time(ns)    CPU(ns) Iterations
------------------------------------------------------------------
BM_time_clock_gettime                      6        144    4666667
BM_time_clock_gettime_syscall             20        486    1400000
BM_time_clock_gettime_REALTIME             6        136    5000000
BM_time_clock_gettime_BOOTTIME             6        153    4375000
BM_time_clock_gettime_TAI                 31        760    1000000
BM_time_clock_gettime_unsupported         10        233    3043478
BM_time_gettimeofday                       6        140    5000000
BM_time_gettimeofday_syscall              19        450    1555556
BM_time_time                               9        203    3500000

AFTER:

hikey960 vdso (aarch64):

--------------------------------------------------------------------
Benchmark                             Time           CPU Iterations
--------------------------------------------------------------------
BM_time_clock_gettime                48 ns         48 ns   15414753
BM_time_clock_gettime_syscall       175 ns        175 ns    4062031
BM_time_clock_gettime_REALTIME       44 ns         44 ns   15897875
BM_time_clock_gettime_BOOTTIME       47 ns         47 ns   14307903
BM_time_clock_gettime_TAI           210 ns        210 ns    3341372
BM_time_clock_gettime_unsupported   100 ns        100 ns    7030649
BM_time_gettimeofday                 47 ns         47 ns   14975314
BM_time_gettimeofday_syscall        164 ns        164 ns    4278797
BM_time_time                         16 ns         16 ns   42932165

hikey960 vdso32 (aarch32):

--------------------------------------------------------------------
Benchmark                             Time           CPU Iterations
--------------------------------------------------------------------
BM_time_clock_gettime                90 ns         90 ns    7572898
BM_time_clock_gettime_syscall       251 ns        251 ns    2763442
BM_time_clock_gettime_REALTIME       81 ns         80 ns    8699536
BM_time_clock_gettime_BOOTTIME       97 ns         97 ns    7256667
BM_time_clock_gettime_TAI           272 ns        272 ns    2570419
BM_time_clock_gettime_unsupported   160 ns        160 ns    4379819
BM_time_gettimeofday                 73 ns         73 ns    9596230
BM_time_gettimeofday_syscall        199 ns        199 ns    3575428
BM_time_time                         35 ns         35 ns   19798801

imx7d_pico IOT nyc (w/arm,cpu-registers-not-fw-configured) (armv7a):

Benchmark                           Time(ns)    CPU(ns) Iterations
------------------------------------------------------------------
BM_time_clock_gettime                     20        477    1489362
BM_time_clock_gettime_syscall             20        487    1458333
BM_time_clock_gettime_REALTIME            19        464    1400000
BM_time_clock_gettime_BOOTTIME            29        700    1000000
BM_time_clock_gettime_TAI                 29        690    1000000
BM_time_clock_gettime_unsupported          9        227    3043478
BM_time_gettimeofday                      18        444    1555556
BM_time_gettimeofday_syscall              19        456    1555556
BM_time_time                               2         50   11666667

imx7d_pico IOT nyc (wo/arm,cpu-registers-not-fw-configured) (armv7a):

Benchmark                           Time(ns)    CPU(ns) Iterations
------------------------------------------------------------------
BM_time_clock_gettime                      6        144    4666667
BM_time_clock_gettime_syscall             20        486    1400000
BM_time_clock_gettime_REALTIME             6        136    5000000
BM_time_clock_gettime_BOOTTIME             6        153    4375000
BM_time_clock_gettime_TAI                 31        760    1000000
BM_time_clock_gettime_unsupported         10        233    3043478
BM_time_gettimeofday                       6        140    5000000
BM_time_gettimeofday_syscall              19        450    1555556
BM_time_time                               2         50   10000000

Test: bionic-unit-tests --gtest_filter=time.time
      taskset F bionic-benchmarks --bionic_xml=vdso.xml \
          --benchmark_filter='BM_time_(time*|clock_gettime*|gettimeofday*)'
Bug: 63737556
Change-Id: I81b088a12ca41a6c4733d46c5477527777138efa
2018-01-11 15:46:11 +00:00
..
arch-arm Fix SYSCALLS.TXT now clock_getres comes from the vdso. 2017-12-11 11:40:40 -08:00
arch-arm64 bionic: add vdso clock_getres 2017-12-07 09:41:48 -08:00
arch-common/bionic Give ELF notes 4-byte alignment. 2017-12-04 13:21:01 -08:00
arch-mips Fix SYSCALLS.TXT now clock_getres comes from the vdso. 2017-12-11 11:40:40 -08:00
arch-mips64 bionic: add vdso clock_getres 2017-12-07 09:41:48 -08:00
arch-x86 Fix SYSCALLS.TXT now clock_getres comes from the vdso. 2017-12-11 11:40:40 -08:00
arch-x86_64 bionic: add vdso clock_getres 2017-12-07 09:41:48 -08:00
async_safe Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched. 2017-10-25 14:28:42 -07:00
bionic bionic: add vdso time() 2018-01-11 15:46:11 +00:00
dns Improve glibc compatibility of gethostby*_r functions. 2017-10-23 17:38:35 -07:00
include Mark abs/labs/llabs as 19+ rather than 21+ 2018-01-08 17:46:27 -08:00
kernel Use in_addr in ip_mreq_source and ip_msfilter. 2017-12-14 10:07:27 -08:00
malloc_debug Fix typo in README.md for malloc_debug 2018-01-03 08:52:56 -08:00
private bionic: add vdso time() 2018-01-11 15:46:11 +00:00
seccomp Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
stdio Merge "Speed up __sfileext initialization." 2017-12-21 15:59:21 +00:00
stdlib Mark __BIONIC_WEAK_FOR_NATIVE_BRIDGE symbols 2017-10-27 10:01:46 +02:00
system_properties Split properties into their own class to make testing better 2017-12-18 15:17:55 -08:00
tools Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
tzcode Add missing includes. 2017-10-11 11:25:52 -07:00
upstream-freebsd Change ARG_MAX/_SC_ARG_MAX back to a constant. 2017-11-15 15:14:35 -08:00
upstream-netbsd libc: Add support to allow library calls to find appropriate shell executable for a process 2017-08-22 10:17:28 -07:00
upstream-openbsd bionic: add vdso time() 2018-01-11 15:46:11 +00:00
versioner-dependencies Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
Android.bp Remove obsolete workaround. 2018-01-10 11:05:19 -08:00
Android.mk
fs_config_generator.py
libc.arm.map More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libc.arm64.map More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libc.map.txt More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libc.mips.map More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libc.mips64.map More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libc.x86.map More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libc.x86_64.map More missing _unlocked <stdio.h> functions. 2017-10-31 13:23:41 -07:00
libstdc++.arm.map Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
libstdc++.arm64.map Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
libstdc++.map.txt Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
libstdc++.mips.map Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
libstdc++.mips64.map Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
libstdc++.x86.map Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
libstdc++.x86_64.map Mark new/delete as weak in the NDK stubs. 2017-07-28 11:01:33 -07:00
MODULE_LICENSE_BSD
NOTICE Make ld-android.so export linker symbols 2018-01-09 11:27:23 +01:00
SECCOMP_BLACKLIST_COMMON.TXT Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
SECCOMP_WHITELIST_APP.TXT Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
SECCOMP_WHITELIST_COMMON.TXT Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
SECCOMP_WHITELIST_GLOBAL.TXT Create global seccomp policy. 2017-07-21 20:30:21 -07:00
SECCOMP_WHITELIST_SYSTEM.TXT Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
SYSCALLS.TXT Fix SYSCALLS.TXT now clock_getres comes from the vdso. 2017-12-11 11:40:40 -08:00
version_script.txt