From nobody Mon Feb 9 16:06:46 2026 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 383FE21CC62; Thu, 26 Jun 2025 13:27:32 +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=1750944454; cv=none; b=A48wmNYSe0siT/kNr7LZt6/OVkz9DFC529TeB/i653fxvnFur+SlzYRIAeIKp7rQWbHLOPYoEOT6BY/JOh9hYDGjyVaK+Fc+j1TsBG2wt7m7Y6YdXlOmbNmUYpEVKSYlWHgTD3eLTBQO69yZsqZ1z74DOmrUSzaPbHVKFywepZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944454; c=relaxed/simple; bh=iPQitKJaOAw1dcX7ZOo2cTMoyJ5pc70J9AQA/1gmZz8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=GKYGfddl1zh/Ittcaz9OzKCt98UoVLY9Tzb5pMxVcp9ld3rQuozF0qkdGoMo7DLAZSxocpxOr3yieVp1Td46lkXqVPP+ftji+3A36IF9eTgIa/v6WxN0kstP9XePelWBTdHK0N0+liycbA5ywGCjeYBS5Gls/oPGR2wvCQy4BdU= 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=45OeGOvb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=E6GZZrhE; 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="45OeGOvb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E6GZZrhE" Message-ID: <20250626131708.419101339@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750944451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3g83WUkcahA98tSAvTQ+7u+GY59xMVQMWbvReg+4HxI=; b=45OeGOvbc1FQu84tfTVe0f2noUtdJYd9OuBPXbg6cB8GmCirEgGwogjyC+D9dYYo0qlTlj FBSdahHr8QXontgg1UjT/tV6dgwkbqbtIRFjHs8AbUxqywoKG/DZNWmWlwQmYbHUX0IMZR /hIfxxipeXHmkhiyj5D/2/p7VJk3sx7TCq0mwqNVSJL1WMKQyxAQQblzw3bJySGFYqcwyk NHfTyX5j7/MrAtI1IqjYJ9K/kL3GmnoL8foFJgkxM27C7CMfUykryIgzJ3nA1uayXw6kIP /cKsMCEwg/XCsX2gLDKci8qi453Nv/BqYZXXciFtBKNyAfkLlFXOZYECKyYtgg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750944451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3g83WUkcahA98tSAvTQ+7u+GY59xMVQMWbvReg+4HxI=; b=E6GZZrhErWzckN9MDzfoFmzVq1fkYY5lUJ56uKMVLqh8VpHKQQ6YLFPym0ZOSff2+iNP2D dTZ1yNIN+8+FeoDw== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , John Stultz , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Kurt Kanzenbach , Nam Cao , Antoine Tenart Subject: [patch 1/3] timekeeping: Provide ktime_get_clock_ts64() References: <20250626124327.667087805@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 26 Jun 2025 15:27:30 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" PTP implements an inline switch case for taking timestamps from various POSIX clock IDs, which already consumes quite some text space. Expanding it for auxiliary clocks really becomes too big for inlining. Provide a out of line version.=20 The function invalidates the timestamp in case the clock is invalid. The invalidation allows to implement a validation check without the need to propagate a return value through deep existing call chains. Signed-off-by: Thomas Gleixner Acked-by: John Stultz Reviewed-by: Vadim Fedorenko --- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -44,6 +44,7 @@ extern void ktime_get_ts64(struct timesp extern void ktime_get_real_ts64(struct timespec64 *tv); extern void ktime_get_coarse_ts64(struct timespec64 *ts); extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); +extern void ktime_get_clock_ts64(clockid_t id, struct timespec64 *ts); =20 /* Multigrain timestamp interfaces */ extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts); --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1636,6 +1636,40 @@ void ktime_get_raw_ts64(struct timespec6 EXPORT_SYMBOL(ktime_get_raw_ts64); =20 /** + * ktime_get_clock_ts64 - Returns time of a clock in a timespec + * @id: POSIX clock ID of the clock to read + * @ts: Pointer to the timespec64 to be set + * + * The timestamp is invalidated (@ts->sec is set to -1) if the + * clock @id is not available. + */ +void ktime_get_clock_ts64(clockid_t id, struct timespec64 *ts) +{ + /* Invalidate time stamp */ + ts->tv_sec =3D -1; + ts->tv_nsec =3D 0; + + switch (id) { + case CLOCK_REALTIME: + ktime_get_real_ts64(ts); + return; + case CLOCK_MONOTONIC: + ktime_get_ts64(ts); + return; + case CLOCK_MONOTONIC_RAW: + ktime_get_raw_ts64(ts); + return; + case CLOCK_AUX ... CLOCK_AUX_LAST: + if (IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS)) + ktime_get_aux_ts64(id, ts); + return; + default: + WARN_ON_ONCE(1); + } +} +EXPORT_SYMBOL_GPL(ktime_get_clock_ts64); + +/** * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres */ int timekeeping_valid_for_hres(void)