mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: thomas.weissschuh@linutronix.de
Cc: tglx@kernel.org, luto@kernel.org, vincenzo.frascino@arm.com,
	david.laight.linux@gmail.com, zhanxusheng@xiaomi.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 0/4] vdso: Keep the CLOCK_AUX base at full precision
Date: Wed,  2 Sep 2026 11:37:57 +0800	[thread overview]
Message-ID: <20260902033801.2912699-1-zhanxusheng@xiaomi.com> (raw)

v3: https://lore.kernel.org/all/20260901020636.1821993-1-zhanxusheng@xiaomi.com

Changes in v4:

 - New 1/4 converts __iter_div_u64_rem() to OPTIMIZER_HIDE_VAR() as Thomas
   asked, so the two helpers do not diverge.  Measured on the x86 vDSO with
   clang 18: vdso64 text -64 bytes, vdso32 -112.  gcc 13 is unchanged.
   Neither compiler turns the loop into a division with the new form,
   checked at both widths.
 - 2/4 uses the macro too and drops the comment about the memory
   alternative.
 - 2/4 no longer claims the vDSO cannot link a division.  It cannot, but
   this code is on the kernel side, so that was the wrong reason.  The
   reason the loop is right is that the quotient is never more than one,
   which also answers David: there is nothing for a reciprocal multiply to
   save.
 - 3/4 drops the sentence about the advertised granularity, and says
   instead that only the sub-second field changes.
 - Continuation lines aligned under the opening paren.
 - Picked up the Reviewed-by on 3/4.

Sorry about the pace of v2 and v3.

The problem 3/4 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.

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
way, a pair of reads costing several hundred nanoseconds.  The argument
for it is the algebra in 3/4, plus a sweep over (xtime_nsec, delta) which
puts the 1 ns case at 60% for shift 24.

Zhan Xusheng (4):
  vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem()
  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   | 29 ++++++++++++++++++++++++++---
 kernel/time/vsyscall.c  | 26 ++++++++++----------------
 lib/vdso/gettimeofday.c |  2 ++
 3 files changed, 38 insertions(+), 19 deletions(-)


base-commit: 89a312991dc6e638a36adc43ccb91dbc25504c04
-- 
2.43.0


             reply	other threads:[~2026-09-02  3:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02  3:37 Zhan Xusheng [this message]
2026-09-02  3:37 ` [PATCH v4 1/4] vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem() Zhan Xusheng
2026-09-05 20:43   ` Thomas Gleixner
2026-09-02  3:37 ` [PATCH v4 2/4] vdso/math64: Add and use __iter_div64_u64_rem() Zhan Xusheng
2026-09-02 10:43   ` Thomas Weißschuh
2026-09-05 20:49   ` Thomas Gleixner
2026-09-02  3:38 ` [PATCH v4 3/4] vdso/vsyscall: Keep the CLOCK_AUX base scaled Zhan Xusheng
2026-09-02  3:38 ` [PATCH v4 4/4] vdso/gettimeofday: Assert that the clock id fits the dispatch mask Zhan Xusheng
2026-09-05 20:48   ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902033801.2912699-1-zhanxusheng@xiaomi.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=tglx@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=vincenzo.frascino@arm.com \
    --cc=zhanxusheng@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®