From nobody Mon Jun 8 03:20:51 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 CD0B53D8125; Tue, 2 Jun 2026 09:46:09 +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=1780393571; cv=none; b=loc7/xrCqapr2fP3QzEkBHXF3yUd89MgOd7NjHckpGcKLzbR20qCft+AIdDU76YP1BeFSc81kW6D8iczQ2aFnvRYd3rHj4lSm9tJxrX3RMSpkGmApE76iUZozLt4TMnVGAvh2s/yDCk8D/3qna3r18L6f13zUJAUF7AigzLdcRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780393571; c=relaxed/simple; bh=hmK+r9gvUaPfN8XJl02Ej7RBYCdDzdAnnRPAqwPtOCM=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=UY+c2MGJO+NvZM5AgrhindYLfc34hAFGFekQ4NvehJH2gfC9IXSe/Sj3f6OuANYKLHamI1aZwW/vxG7etvRdsFkgKX7Clx0OA7ewLVlpSLAkmV6vA1oC7ajCoelg8pBAgWhxwnIDMtOz+LFRWPgZFdXgtJ4bk8ZybfRTlsFvxcY= 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=fUVWrAeu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GVvqTRPH; 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="fUVWrAeu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GVvqTRPH" Date: Tue, 02 Jun 2026 09:46:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780393568; 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=iumejuLuiZ9MY69OQ4iHJP5apT74WxrNhC+lFGg+d8U=; b=fUVWrAeuHGNdfGIDGEfrjPE48qPZKhUocAVJHx1zkzYEw4HhO2EFgv7BIdGFCPFiEuuzNI RloadTpCVa5Kyhiqm6XByVlASSdTfRoEZ3e40QksJv2FaWPl6P0m8Arh3xjy5bFo3zHesS uWTUE32pCrJ0b41OzF7MQiU7r0Z7NtlSUBpgu4ez8jmD3Q4lwMyk/MV6OjYDmq9oq0Ko3C bzBi14wns6L3c3D0t17Ie/TwXDawZLLiN8EvHR4dARDqDnqDiDZhRrCtiCgrrN0FVRDVC1 AulKdz+gn/2ZSDZlxytp8Wxs1G+TWosYyQxAy2Of4bXR9RuZuwNpN/5MTCBC8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780393568; 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=iumejuLuiZ9MY69OQ4iHJP5apT74WxrNhC+lFGg+d8U=; b=GVvqTRPH5ofuktmq5QiyByLYEMS9wSexr5fCmkoQXHyDDuJbsc8JHuOzgLDKoHVEWVqKaO Edia0rFt/8zeBHAQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/ptp] timekeeping: Add system_counterval_t to struct system_device_crosststamp Cc: Thomas Gleixner , David Woodhouse , Arthur Kiyanovski , Jacob Keller , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260529195557.429406675@kernel.org> References: <20260529195557.429406675@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178039356706.2140988.608582715643341573.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: 44e3ae4396f982f84a24d8c7d2b8f613a78ef34a Gitweb: https://git.kernel.org/tip/44e3ae4396f982f84a24d8c7d2b8f613a= 78ef34a Author: Thomas Gleixner AuthorDate: Fri, 29 May 2026 22:00:28 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00 timekeeping: Add system_counterval_t to struct system_device_crosststamp An upcoming extension to the PTP IOCTL requires to return the system counter value and the clocksource ID to user space. get_device_system_crosststamp()= has this information already. Extend struct system_device_crosststamp with a system_counterval_t member and fill in the data. Signed-off-by: Thomas Gleixner Tested-by: David Woodhouse Tested-by: Arthur Kiyanovski Reviewed-by: David Woodhouse Reviewed-by: Jacob Keller Link: https://patch.msgid.link/20260529195557.429406675@kernel.org --- include/linux/timekeeping.h | 28 +++++++++++----------- kernel/time/timekeeping.c | 46 ++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index eb64c90..3867db6 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -297,19 +297,6 @@ struct system_time_snapshot { }; =20 /** - * struct system_device_crosststamp - system/device cross-timestamp - * (synchronized capture) - * @device: Device time - * @sys_realtime: Realtime simultaneous with device time - * @sys_monoraw: Monotonic raw simultaneous with device time - */ -struct system_device_crosststamp { - ktime_t device; - ktime_t sys_realtime; - ktime_t sys_monoraw; -}; - -/** * struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value @@ -325,6 +312,21 @@ struct system_counterval_t { bool use_nsecs; }; =20 +/** + * struct system_device_crosststamp - system/device cross-timestamp + * (synchronized capture) + * @device: Device time + * @sys_counter: Clocksource counter value simultaneous with device time + * @sys_realtime: Realtime simultaneous with device time + * @sys_monoraw: Monotonic raw simultaneous with device time + */ +struct system_device_crosststamp { + ktime_t device; + struct system_counterval_t sys_counter; + ktime_t sys_realtime; + ktime_t sys_monoraw; +}; + extern bool ktime_real_to_base_clock(ktime_t treal, enum clocksource_ids base_id, u64 *cycles); extern bool timekeeping_clocksource_has_base(enum clocksource_ids id); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index e43aa11..372179f 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1418,6 +1418,8 @@ static bool convert_base_to_cs(struct system_counterv= al_t *scv) return false; =20 scv->cycles +=3D base->offset; + /* Set the clocksource ID as scv::cycles is now clocksource based */ + scv->cs_id =3D cs->id; return true; } =20 @@ -1485,11 +1487,11 @@ EXPORT_SYMBOL_GPL(ktime_real_to_base_clock); =20 /** * get_device_system_crosststamp - Synchronously capture system/device tim= estamp - * @get_time_fn: Callback to get simultaneous device time and - * system counter from the device driver + * @get_time_fn: Callback to get simultaneous device time and system count= er + * from the device driver * @ctx: Context passed to get_time_fn() - * @history_begin: Historical reference point used to interpolate system - * time when counter provided by the driver is before the current interval + * @history_begin: Historical reference point used to interpolate system t= ime when + * the counter value provided by the driver is before the current interv= al * @xtstamp: Receives simultaneously captured system and device time * * Reads a timestamp from a device and correlates it to system time @@ -1502,14 +1504,12 @@ int get_device_system_crosststamp(int (*get_time_fn) struct system_time_snapshot *history_begin, struct system_device_crosststamp *xtstamp) { - struct system_counterval_t system_counterval =3D {}; + u64 syscnt_cycles, cycles, now, interval_start; struct timekeeper *tk =3D &tk_core.timekeeper; - u64 cycles, now, interval_start; - unsigned int clock_was_set_seq =3D 0; + unsigned int seq, clock_was_set_seq =3D 0; ktime_t base_real, base_raw; u64 nsec_real, nsec_raw; u8 cs_was_changed_seq; - unsigned int seq; bool do_interp; int ret; =20 @@ -1519,19 +1519,20 @@ int get_device_system_crosststamp(int (*get_time_fn) * Try to synchronously capture device time and a system * counter value calling back into the device driver */ - ret =3D get_time_fn(&xtstamp->device, &system_counterval, ctx); + ret =3D get_time_fn(&xtstamp->device, &xtstamp->sys_counter, ctx); if (ret) return ret; =20 /* * Verify that the clocksource ID associated with the captured * system counter value is the same as for the currently - * installed timekeeper clocksource + * installed timekeeper clocksource and convert to it. */ - if (system_counterval.cs_id =3D=3D CSID_GENERIC || - !convert_base_to_cs(&system_counterval)) + if (xtstamp->sys_counter.cs_id =3D=3D CSID_GENERIC || + !convert_base_to_cs(&xtstamp->sys_counter)) return -ENODEV; - cycles =3D system_counterval.cycles; + + cycles =3D syscnt_cycles =3D xtstamp->sys_counter.cycles; =20 /* * Check whether the system counter value provided by the @@ -1573,24 +1574,19 @@ int get_device_system_crosststamp(int (*get_time_fn) * clocksource change */ if (!history_begin || - !timestamp_in_interval(history_begin->cycles, - cycles, system_counterval.cycles) || + !timestamp_in_interval(history_begin->cycles, cycles, syscnt_cycles)= || history_begin->cs_was_changed_seq !=3D cs_was_changed_seq) return -EINVAL; - partial_history_cycles =3D cycles - system_counterval.cycles; + + partial_history_cycles =3D cycles - syscnt_cycles; total_history_cycles =3D cycles - history_begin->cycles; - discontinuity =3D - history_begin->clock_was_set_seq !=3D clock_was_set_seq; + discontinuity =3D history_begin->clock_was_set_seq !=3D clock_was_set_se= q; =20 - ret =3D adjust_historical_crosststamp(history_begin, - partial_history_cycles, - total_history_cycles, - discontinuity, xtstamp); - if (ret) - return ret; + ret =3D adjust_historical_crosststamp(history_begin, partial_history_cyc= les, + total_history_cycles, discontinuity, xtstamp); } =20 - return 0; + return ret; } EXPORT_SYMBOL_GPL(get_device_system_crosststamp); =20