Now that we can let an architecture override the timestamping function, it becomes desirable to ensure that, should the architecture code switch its timestamping code to sched_clock once it has been registered, the sched_clock inherits the timestamp value as its new epoch.
This ensures that the time stamps are continuous and that there is no jitter other than that introduced by the lack of quality of the timestamping clock. Signed-off-by: Marc Zyngier <marc.zyng...@arm.com> --- kernel/time/sched_clock.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 142b07619918..ee1bd449ec81 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -192,6 +192,16 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate) new_epoch = read(); cyc = cd.actual_read_sched_clock(); ns = rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & rd.sched_clock_mask, rd.mult, rd.shift); + + /* + * If the architecture has a timestamp clock, and this is the + * first time we register a new sched_clock, use the timestamp + * clock as the epoch. + */ + if (IS_ENABLED(CONFIG_ARCH_HAS_TIMESTAMP_CLOCK) && + unlikely(cd.actual_read_sched_clock == jiffy_sched_clock_read)) + ns = timestamp_clock(); + cd.actual_read_sched_clock = read; rd.read_sched_clock = read; -- 2.20.1