Skip to content

clock_gettime_ns and x86-64 optimizations

Andy Lutomirski lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4Add clock_gettime_ns syscallarch/x86/include/asm/unistd_64.h include/linux/syscalls.h include/linux/time.h +1 more+40 -05 replies
2/4x86-64: Add __vdso_clock_gettime_ns vsyscallarch/x86/vdso/vclock_gettime.c arch/x86/vdso/vdso.lds.S+61 -160 replies
3/4x86-64: Optimize vdso clock_gettimearch/x86/include/asm/vgtod.h arch/x86/kernel/vsyscall_64.c arch/x86/vdso/vclock_gettime.c+89 -460 replies
4/4x86-64: Inline vdso clock_gettime helpersarch/x86/vdso/vclock_gettime.c+9 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] clock_gettime_ns and x86-64 optimizations

On x86-64, clock_gettime is so fast that the overhead converting to and from nanoseconds is non-negligible. clock_gettime_ns is a different and faster interface.

Patch 1 adds the syscall and wires it up on x86-64. Patch 2 implements the corresponding vdso entry on x86-64. Patch 3 optimizes the vdso call, and patch 4 is a trivial change that speeds up the vdso clock_gettime and clock_gettime_ns implementations.

The vdso timings are (on an 800MHz Sandy Bridge mobile):

Basic implementation:

realtime 77.4ns
monotonic 79.2ns
realtime_coarse 18.1ns
monotonic_coarse 22.0ns

realtime_ns 84.9ns
monotonic_ns 85.1ns
realtime_coarse_ns 19.49
monotonic_coarse_ns 27.32

Optimized implementation:

realtime 78.5ns
monotonic 77.4ns [a little faster -- maybe significant] realtime_coarse 18.4ns
monotonic_coarse 19.4ns

realtime_ns 77.85ns [a nice improvement]
monotonic_ns 77.75ns [ditto]
realtime_coarse_ns 18.2ns
monotonic_coarse_ns 18.2ns [a lot faster]

Inlined (patch 4): [everything is improved]

realtime 73.4ns
monotonic 72.1ns
realtime_coarse 13.2ns
monotonic_coarse 15.8ns

realtime_ns 73.15ns
monotonic_ns 72.1ns
realtime_coarse_ns 14.1ns
monotonic_coarse_ns 15.6ns

This being the middle of the holidays, I reserve the right to have made mistakes.

For the git-inclined, this series is at
https://git.kernel.org/?p=linux/kernel/git/luto/linux.git;a=shortlog;h=refs/heads/timing/clock_gettime_ns/patch_v1

Andy Lutomirski (4):
Add clock_gettime_ns syscall
x86-64: Add __vdso_clock_gettime_ns vsyscall
x86-64: Optimize vdso clock_gettime
x86-64: Inline vdso clock_gettime helpers

 arch/x86/include/asm/unistd_64.h |    2 +
 arch/x86/include/asm/vgtod.h     |   21 ++++--
 arch/x86/kernel/vsyscall_64.c    |   25 +++++++-
 arch/x86/vdso/vclock_gettime.c   |  136 ++++++++++++++++++++++++++------------
 arch/x86/vdso/vdso.lds.S         |    7 ++
 include/linux/syscalls.h         |    3 +
 include/linux/time.h             |    5 ++
 kernel/posix-timers.c            |   30 ++++++++
 8 files changed, 179 insertions(+), 50 deletions(-)
Signature · 1 line
1.7.7.4