From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 9E6F54014AA; Tue, 26 May 2026 17:14:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779815662; cv=none; b=jYIhfFlyR9akjz5CH3ersmvAUsUo0Ut+TjU/VOSAbLTQaxGtmE0naIS+aIDH8tI6Opamn/VkfeILHe/7bkddjqfdJbjnQUkA+DqonRmCvTSSBZ6Pwof2D8k6aFttM/UGxtmgXZvn8h9NP1BT9FoLzW9QqpKuxTQ7RQQrJvj0/GI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779815662; c=relaxed/simple; bh=dWNNq8fiVdN+WDn5GaHOJN6Ksagnh/2Qvk/I2pZv9Mo=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=jl1ZPB8C4esoYtlgcqvffbkfeFzZANg6zSBSxp2nZ19a1Q64pGsgwtXxIxE8fu7WzDolNO966DiOwhLKVfKO/ZJoEWK6e8rInd+0+EwAAyTedeEtO8kOlKQUUN8uRDzyH4W45HGWn3M9iHaiT9PsTqekYC7TW/FOvppRioD0mMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KNQ8Fpi9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KNQ8Fpi9" Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 6C7D81F000E9; Tue, 26 May 2026 17:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779815661; bh=2Gq19z55uKjR3IXd+Mf/0eopO8jyNxR32nvzywhnfzI=; h=Date:From:To:Cc:Subject:References; b=KNQ8Fpi9iZlj3+1Cud0AjFzYzrb4qE+FuB+PtNH7FF1OlfYdHD+MTKwjSnqwDpfiG 1aP66+EKqeHTWGg3aBmH6GGysrfHyMbErmvGGpOHjeThjx+1GmwArVVMtH94mh3Fv6 DMckC587PN3NKElqHVViXVXVSzeFFCmBABt2//r2GeEaA+jWnvntM34t+FvLYgpT0+ G3XsPvZ/OmX7ebup8xGR7ONWQS2ha94Z20gNU4bbE9kV9vz7EBudIzebz8Dw8+/wDa xJe6NpVHvzzc4mmjSEhF/qXwzt0Q1/E5iLSItZI6ghRpt3V3nwlH+iGNA7wcR3mUxE 8D/Iag8nJH8Wg== Date: Tue, 26 May 2026 19:14:18 +0200 Message-ID: <20260526171223.448889379@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Cc: David Woodhouse , Miroslav Lichvar , John Stultz , Stephen Boyd , Anna-Maria Behnsen , Frederic Weisbecker , thomas.weissschuh@linutronix.de, Arthur Kiyanovski , Rodolfo Giometti , Vincent Donnefort , Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, Oliver Upton , Richard Cochran , netdev@vger.kernel.org, Takashi Iwai , Miri Korenblit , Johannes Berg , Jacob Keller , Tony Nguyen , Saeed Mahameed , Peter Hilber , "Michael S. Tsirkin" , virtualization@lists.linux.dev, linux-wireless@vger.kernel.org, linux-sound@vger.kernel.org Subject: [patch 10/24] timekeeping: Add system_counterval_t to struct system_device_crosststamp References: <20260526165826.392227559@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 --- include/linux/timekeeping.h | 28 ++++++++++++++------------ kernel/time/timekeeping.c | 46 ++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 38 deletions(-) --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -297,19 +297,6 @@ struct system_time_snapshot { }; /** - * 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; }; +/** + * 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); --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1419,6 +1419,8 @@ static bool convert_base_to_cs(struct sy return false; scv->cycles += base->offset; + /* Set the clocksource ID as scv::cycles is now clocksource based */ + scv->cs_id = cs->id; return true; } @@ -1486,11 +1488,11 @@ EXPORT_SYMBOL_GPL(ktime_real_to_base_clo /** * get_device_system_crosststamp - Synchronously capture system/device timestamp - * @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 counter + * 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 time when + * the counter value provided by the driver is before the current interval * @xtstamp: Receives simultaneously captured system and device time * * Reads a timestamp from a device and correlates it to system time @@ -1503,14 +1505,12 @@ int get_device_system_crosststamp(int (* struct system_time_snapshot *history_begin, struct system_device_crosststamp *xtstamp) { - struct system_counterval_t system_counterval = {}; + u64 syscnt_cycles, cycles, now, interval_start; struct timekeeper *tk = &tk_core.timekeeper; - u64 cycles, now, interval_start; - unsigned int clock_was_set_seq = 0; + unsigned int seq, clock_was_set_seq = 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; @@ -1520,19 +1520,20 @@ int get_device_system_crosststamp(int (* * Try to synchronously capture device time and a system * counter value calling back into the device driver */ - ret = get_time_fn(&xtstamp->device, &system_counterval, ctx); + ret = get_time_fn(&xtstamp->device, &xtstamp->sys_counter, ctx); if (ret) return ret; /* * 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 == CSID_GENERIC || - !convert_base_to_cs(&system_counterval)) + if (xtstamp->sys_counter.cs_id == CSID_GENERIC || + !convert_base_to_cs(&xtstamp->sys_counter)) return -ENODEV; - cycles = system_counterval.cycles; + + cycles = syscnt_cycles = xtstamp->sys_counter.cycles; /* * Check whether the system counter value provided by the @@ -1574,24 +1575,19 @@ int get_device_system_crosststamp(int (* * 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 != cs_was_changed_seq) return -EINVAL; - partial_history_cycles = cycles - system_counterval.cycles; + + partial_history_cycles = cycles - syscnt_cycles; total_history_cycles = cycles - history_begin->cycles; - discontinuity = - history_begin->clock_was_set_seq != clock_was_set_seq; + discontinuity = history_begin->clock_was_set_seq != clock_was_set_seq; - ret = adjust_historical_crosststamp(history_begin, - partial_history_cycles, - total_history_cycles, - discontinuity, xtstamp); - if (ret) - return ret; + ret = adjust_historical_crosststamp(history_begin, partial_history_cycles, + total_history_cycles, discontinuity, xtstamp); } - return 0; + return ret; } EXPORT_SYMBOL_GPL(get_device_system_crosststamp);