All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] vdso: Keep the CLOCK_AUX base at full precision
@ 2026-09-01  2:06 Zhan Xusheng
  2026-09-01  2:06 ` [PATCH v3 1/3] vdso/math64: Add and use __iter_div64_u64_rem() Zhan Xusheng
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Zhan Xusheng @ 2026-09-01  2:06 UTC (permalink / raw)
  To: tglx, luto, vincenzo.frascino
  Cc: thomas.weissschuh, david.laight.linux, linux-kernel, zhanxusheng

v1: https://lore.kernel.org/all/20260831125557.1490398-1-zhanxusheng@xiaomi.com
v2 went out before David's mail arrived.  It touched only the call sites,
so both of his remarks about the helper applied to it unchanged.

Changes in v3:

 - The quotient is a u32, as David suggested and as the u32-divisor
   version already returns.  vsyscall.o loses 16 bytes of text on x86-64
   and the loop drops from 36 to 28 instructions on 32-bit gcc.
 - The barrier keeps the value in a register instead of offering a memory
   alternative.  David asked whether clang makes a mess of "+rm": it does,
   it takes the memory alternative and spills inside the loop, on 64-bit
   as well.  Both forms still stop the loop becoming a division, checked
   for gcc and clang at both widths.
 - Fixes: tag on 2/3.

Changes in v2, from Thomas' review of 1/3:

 - Drop the nsec_per_sec local and spell the divisor out at each site.
 - Store the remainder straight into the basetime, as the coarse clocks
   already do.  That also makes the copy of the CLOCK_MONOTONIC values for
   CLOCK_BOOTTIME take sec and nsec from the same place rather than one
   from the basetime and one from a local left over from the division.
   Not a codegen win: gcc emits the same instructions either way.
 - Keep "vdso_ts->sec = sec;" on its own line under the copy comment.
 - Picked up the Reviewed-by on 3/3, which is unchanged.

__iter_div_u64_rem() has the same "+rm" barrier, and it sits on the
clock_gettime() path through vdso_set_timespec().  Converting it is worth
64 bytes of vdso64 text and 112 of vdso32 built with clang 18; gcc is
indifferent.  It is not in this series because it also has users in
arch/x86/kvm, timespec64_add_ns() and lib/math/div64.c.  Say the word and
I will send it.

The problem 2/3 fixes: the CLOCK_AUX basetime is shifted down to
nanoseconds and back up, which drops the fractional nanoseconds of
xtime_nsec, so the vDSO floors the base and the cycle delta separately
where ktime_get_aux() floors their sum.  The vDSO reading ends up 0 or
1 ns below the syscall for the same clock, and clock_getres() advertises
1 ns for these clocks.

Checked under QEMU with an auxiliary clock enabled through
/sys/kernel/time/aux_clocks/0/aux_clock_enable, comparing CLOCK_AUX via
the vDSO against the raw syscall at offset 0, at +5.123456789 s, and with
offs_aux driven negative.  The two agree within read latency in all three,
and over 100000 interleaved pairs each the vDSO reading is never ahead of a
syscall reading taken after it.  The 1 ns bias itself is not measurable
that way, a pair of reads costing several hundred nanoseconds.  The
argument for it is the algebra in 2/3, plus a sweep over
(xtime_nsec, delta) which puts the 1 ns case at 60% for shift 24.

Zhan Xusheng (3):
  vdso/math64: Add and use __iter_div64_u64_rem()
  vdso/vsyscall: Keep the CLOCK_AUX base scaled
  vdso/gettimeofday: Assert that the clock id fits the dispatch mask

 include/vdso/math64.h   | 22 ++++++++++++++++++++++
 kernel/time/vsyscall.c  | 28 ++++++++++++----------------
 lib/vdso/gettimeofday.c |  2 ++
 3 files changed, 36 insertions(+), 16 deletions(-)


base-commit: abdf623ddb75b24659018d3952d8f61937306ae5
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-09-01 13:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-01  2:06 [PATCH v3 0/3] vdso: Keep the CLOCK_AUX base at full precision Zhan Xusheng
2026-09-01  2:06 ` [PATCH v3 1/3] vdso/math64: Add and use __iter_div64_u64_rem() Zhan Xusheng
2026-09-01  8:35   ` Thomas Weißschuh
2026-09-01 12:48     ` David Laight
2026-09-01 13:05       ` Thomas Weißschuh
2026-09-01  2:06 ` [PATCH v3 2/3] vdso/vsyscall: Keep the CLOCK_AUX base scaled Zhan Xusheng
2026-09-01  8:42   ` Thomas Weißschuh
2026-09-01  2:06 ` [PATCH v3 3/3] vdso/gettimeofday: Assert that the clock id fits the dispatch mask Zhan Xusheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.