]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Implement userspace gettimeofday(2) with HPET timecounter.
authorkib <kib@FreeBSD.org>
Wed, 17 Aug 2016 09:52:09 +0000 (09:52 +0000)
committerkib <kib@FreeBSD.org>
Wed, 17 Aug 2016 09:52:09 +0000 (09:52 +0000)
commite56264ca1709ba14b8c3ff6f3f8f784a8614ed25
treedb867e059f8908dd66ad19036e60c82be1dd7629
parent591244e54cb6d1c29539b975d9010b1a33e30082
Implement userspace gettimeofday(2) with HPET timecounter.

Right now, userspace (fast) gettimeofday(2) on x86 only works for
RDTSC.  For older machines, like Core2, where RDTSC is not C2/C3
invariant, and which fall to HPET hardware, this means that the call
has both the penalty of the syscall and of the uncached hw behind the
QPI or PCIe connection to the sought bridge.  Nothing can me done
against the access latency, but the syscall overhead can be removed.
System already provides mappable /dev/hpetX devices, which gives
straight access to the HPET registers page.

Add yet another algorithm to the x86 'vdso' timehands. Libc is updated
to handle both RDTSC and HPET.  For HPET, the index of the hpet device
to mmap is passed from kernel to userspace, index might be changed and
libc invalidates its mapping as needed.

Remove cpu_fill_vdso_timehands() KPI, instead require that
timecounters which can be used from userspace, to provide
tc_fill_vdso_timehands{,32}() methods.  Merge i386 and amd64
libc/<arch>/sys/__vdso_gettc.c into one source file in the new
libc/x86/sys location.  __vdso_gettc() internal interface is changed
to move timecounter algorithm detection into the MD code.

Measurements show that RDTSC even with the syscall overhead is faster
than userspace HPET access.  But still, userspace HPET is three-four
times faster than syscall HPET on several Core2 and SandyBridge
machines.

Tested by: Howard Su <howard0su@gmail.com>
Sponsored by: The FreeBSD Foundation
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D7473
24 files changed:
lib/libc/Makefile
lib/libc/aarch64/sys/__vdso_gettc.c
lib/libc/amd64/sys/Makefile.inc
lib/libc/amd64/sys/__vdso_gettc.c [deleted file]
lib/libc/arm/sys/__vdso_gettc.c
lib/libc/i386/sys/Makefile.inc
lib/libc/sys/__vdso_gettimeofday.c
lib/libc/sys/trivial-vdso_tc.c
lib/libc/x86/sys/Makefile.inc [new file with mode: 0644]
lib/libc/x86/sys/__vdso_gettc.c [moved from lib/libc/i386/sys/__vdso_gettc.c with 57% similarity]
sys/arm/arm/generic_timer.c
sys/arm/arm/machdep.c
sys/arm/include/md_var.h
sys/arm/include/vdso.h
sys/arm64/arm64/machdep.c
sys/arm64/include/md_var.h
sys/arm64/include/vdso.h
sys/dev/acpica/acpi_hpet.c
sys/dev/acpica/acpi_hpet.h
sys/kern/kern_tc.c
sys/sys/timetc.h
sys/sys/vdso.h
sys/x86/include/vdso.h
sys/x86/x86/tsc.c