From nobody Tue Oct 7 14:05:32 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4152A2882A3; Wed, 9 Jul 2025 09:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752055055; cv=none; b=UNyyHH72yM97q55key8LbxKDT3x5PXmV1P/Zq4i+54X8ciuF9Mw6l/SNq8gO86lfGo9qw8CNDqtSDxKhTa90hG1h4CbgNXK/vU45foxCw4bEG5l/smQ/KJexZXj+zD9/nY/G8KVYAz/O+/wJHyLvXcQkLeWzUuDLCZ6yKEC33Tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752055055; c=relaxed/simple; bh=7kEliuJK6TJk2KEa1L9wd8yRTrFHNua9SSoIJ4FB+kU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=GjrCshmbGYvgv6n4IrB4UEkvJRQzTHRTvsap+23kVv01nbLeQCqSH5rkQGCk7B6OdgI8GoJ3NQT3kjDV/1CH8XIqU9Kuxr+jfBsdeL7laKwY/yLHSXJz+ohfSgbTY+qThI+WtgbJJuCCPeWvRapELC5Lnrl58QD3QghzfjAUnqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=l8KBUVRS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XpapsYN6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="l8KBUVRS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XpapsYN6" Date: Wed, 09 Jul 2025 09:57:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1752055052; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yPVjDVT3lw6U4TwVpFk4dZiRTZ6/rNs3rSttUOS4QtM=; b=l8KBUVRSKR2WPqPRypCVO/tChYWn3W5K15MQ1TGrK45w2HTJRip4OIfUJHoMvuqN2Gk47u qbxqGPxGhiKgvR/bNk9B+R2buBd0e+1ozWs/hlT6oYu8SYsrFcyuPY9DFGN9UkGplS4o+0 rfA2cV6512rjvEJyumQGVy3OejWmfO5u9/zdxZ2W0eaWJQU00LIRFgQb3K4y28lPLUHlXB KYPQ2mqrQ+UAPVE7Ke/OA/mig6IU1XteS1swf3R6DlzJSy1UcWZoE7ClUCD+sLtrKRep28 NcAzKVRv+PGf/1XwrZC7jFEz01RIWtBGJwUp1NOEBg4Rum+stoBYki76xhApIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1752055052; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yPVjDVT3lw6U4TwVpFk4dZiRTZ6/rNs3rSttUOS4QtM=; b=XpapsYN6O2gpY+LhSJWa9t5L3DZ+qBh6GswIVBmcDJDWJKumJrAbVnlXouMNg5ZEhBDLpy 5wP5TDP0nj1yUYDA== From: tip-bot2 for Thomas =?utf-8?q?Wei=C3=9Fschuh?= Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/ptp] vdso/gettimeofday: Add support for auxiliary clocks Cc: thomas.weissschuh@linutronix.de, Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250701-vdso-auxclock-v1-12-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-12-df7d9f87b9b8@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <175205505093.406.6694374645305361576.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/ptp branch of tip: Commit-ID: dea57842479175fe0914e363b503ccff378ac54d Gitweb: https://git.kernel.org/tip/dea57842479175fe0914e363b503ccff3= 78ac54d Author: Thomas Wei=C3=9Fschuh AuthorDate: Tue, 01 Jul 2025 10:58:06 +02:00 Committer: Thomas Gleixner CommitterDate: Wed, 09 Jul 2025 11:52:35 +02:00 vdso/gettimeofday: Add support for auxiliary clocks Expose the auxiliary clocks through the vDSO. Architectures not using the generic vDSO time framework, namely SPARC64, are not supported. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20250701-vdso-auxclock-v1-12-df7d9f87b9b8= @linutronix.de --- include/vdso/datapage.h | 2 ++- lib/vdso/gettimeofday.c | 49 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h index f4c96d9..0253303 100644 --- a/include/vdso/datapage.h +++ b/include/vdso/datapage.h @@ -5,6 +5,7 @@ #ifndef __ASSEMBLY__ =20 #include +#include #include #include #include @@ -46,6 +47,7 @@ struct vdso_arch_data { #define VDSO_COARSE (BIT(CLOCK_REALTIME_COARSE) | \ BIT(CLOCK_MONOTONIC_COARSE)) #define VDSO_RAW (BIT(CLOCK_MONOTONIC_RAW)) +#define VDSO_AUX __GENMASK(CLOCK_AUX_LAST, CLOCK_AUX) =20 #define CS_HRES_COARSE 0 #define CS_RAW 1 diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index d9cb1d9..97aa905 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -2,6 +2,7 @@ /* * Generic userspace implementations of gettimeofday() and similar. */ +#include #include #include =20 @@ -74,7 +75,7 @@ static inline bool vdso_cycles_ok(u64 cycles) static __always_inline bool vdso_clockid_valid(clockid_t clock) { /* Check for negative values or invalid clocks */ - return likely((u32) clock < MAX_CLOCKS); + return likely((u32) clock < CLOCK_AUX_LAST); } =20 /* @@ -268,6 +269,48 @@ bool do_coarse(const struct vdso_time_data *vd, const = struct vdso_clock *vc, return true; } =20 +static __always_inline +bool do_aux(const struct vdso_time_data *vd, clockid_t clock, struct __ker= nel_timespec *ts) +{ + const struct vdso_clock *vc; + u32 seq, idx; + u64 sec, ns; + + if (!IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS)) + return false; + + idx =3D clock - CLOCK_AUX; + vc =3D &vd->aux_clock_data[idx]; + + do { + /* + * Open coded function vdso_read_begin() to handle + * VDSO_CLOCK_TIMENS. See comment in do_hres(). + */ + while ((seq =3D READ_ONCE(vc->seq)) & 1) { + if (IS_ENABLED(CONFIG_TIME_NS) && vc->clock_mode =3D=3D VDSO_CLOCKMODE_= TIMENS) { + vd =3D __arch_get_vdso_u_timens_data(vd); + vc =3D &vd->aux_clock_data[idx]; + /* Re-read from the real time data page */ + continue; + } + cpu_relax(); + } + smp_rmb(); + + /* Auxclock disabled? */ + if (vc->clock_mode =3D=3D VDSO_CLOCKMODE_NONE) + return false; + + if (!vdso_get_timestamp(vd, vc, VDSO_BASE_AUX, &sec, &ns)) + return false; + } while (unlikely(vdso_read_retry(vc, seq))); + + vdso_set_timespec(ts, sec, ns); + + return true; +} + static __always_inline bool __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t cl= ock, struct __kernel_timespec *ts) @@ -289,6 +332,8 @@ __cvdso_clock_gettime_common(const struct vdso_time_dat= a *vd, clockid_t clock, return do_coarse(vd, &vc[CS_HRES_COARSE], clock, ts); else if (msk & VDSO_RAW) vc =3D &vc[CS_RAW]; + else if (msk & VDSO_AUX) + return do_aux(vd, clock, ts); else return false; =20 @@ -433,6 +478,8 @@ bool __cvdso_clock_getres_common(const struct vdso_time= _data *vd, clockid_t cloc * Preserves the behaviour of posix_get_coarse_res(). */ ns =3D LOW_RES_NSEC; + } else if (msk & VDSO_AUX) { + ns =3D aux_clock_resolution_ns(); } else { return false; }