Skip to content

Commit 4b7f521

Browse files
timekeeping: Evaluate system_counterval_t.cs_id instead of .cs
Clocksource pointers can be problematic to obtain for drivers which are not clocksource drivers themselves. In particular, the RFC virtio_rtc driver [1] would require a new helper function to obtain a pointer to the ARM Generic Timer clocksource. The ptp_kvm driver also required a similar workaround. Address this by evaluating the clocksource ID, rather than the clocksource pointer, of struct system_counterval_t. By this, setting the clocksource pointer becomes unneeded, and get_device_system_crosststamp() callers will no longer need to supply clocksource pointers. All relevant clocksource drivers provide the ID, so this change is not changing the behaviour. [1] https://lore.kernel.org/lkml/20231218073849.35294-1-peter.hilber@opensynergy.com/ Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240201010453.2212371-7-peter.hilber@opensynergy.com
1 parent 9be3b2f commit 4b7f521

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

include/linux/timekeeping.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ struct system_device_crosststamp {
268268
};
269269

270270
/**
271-
* struct system_counterval_t - system counter value with the pointer to the
271+
* struct system_counterval_t - system counter value with the ID of the
272272
* corresponding clocksource
273273
* @cycles: System counter value
274-
* @cs: Clocksource corresponding to system counter value. Used by
275-
* timekeeping code to verify comparibility of two cycle values
276-
* @cs_id: Clocksource ID corresponding to system counter value. To be
277-
* used instead of cs in the future.
274+
* @cs: Clocksource corresponding to system counter value. Timekeeping
275+
* code now evaluates cs_id instead.
276+
* @cs_id: Clocksource ID corresponding to system counter value. Used by
277+
* timekeeping code to verify comparability of two cycle values.
278278
* The default ID, CSID_GENERIC, does not identify a specific
279279
* clocksource.
280280
*/

kernel/time/timekeeping.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,12 @@ int get_device_system_crosststamp(int (*get_time_fn)
12321232
return ret;
12331233

12341234
/*
1235-
* Verify that the clocksource associated with the captured
1236-
* system counter value is the same as the currently installed
1237-
* timekeeper clocksource
1235+
* Verify that the clocksource ID associated with the captured
1236+
* system counter value is the same as for the currently
1237+
* installed timekeeper clocksource
12381238
*/
1239-
if (tk->tkr_mono.clock != system_counterval.cs)
1239+
if (system_counterval.cs_id == CSID_GENERIC ||
1240+
tk->tkr_mono.clock->id != system_counterval.cs_id)
12401241
return -ENODEV;
12411242
cycles = system_counterval.cycles;
12421243

0 commit comments

Comments
 (0)