From abe4cbb1a6ea180d446c06ccb5e9732fd0522462 Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Wed, 21 Dec 2022 16:53:34 +0000 Subject: [PATCH] ANDROID: timekeeping: Export the boot clock in snapshots The boot clock is interesting for tracing purpose as it doesn't stop on device suspend. Exporting it intends to let the nVHE hypervisor for the arm64 architecture to "replicate" that clock and allow event synchronization with the host. Replicating implies to know the current slope. Bug: 229972309 Change-Id: Iefb6ffc433dac82297401f9acdff9758cc1b6a89 Signed-off-by: Vincent Donnefort --- include/linux/timekeeping.h | 6 ++++++ kernel/time/timekeeping.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 78a98bdff76d..309e10ea8cf9 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -239,17 +239,23 @@ struct ktime_timestamps { * counter value * @cycles: Clocksource counter value to produce the system times * @real: Realtime system time + * @boot: Boot time * @raw: Monotonic raw system time * @clock_was_set_seq: The sequence number of clock was set events * @cs_was_changed_seq: The sequence number of clocksource change events + * @mono_shift: The monotonic clock slope shift + * @mono_mult: The monotonic clock slope mult */ struct system_time_snapshot { u64 cycles; ktime_t real; + ktime_t boot; ktime_t raw; enum clocksource_ids cs_id; unsigned int clock_was_set_seq; u8 cs_was_changed_seq; + u32 mono_shift; + u32 mono_mult; }; /** diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 916ca8547c9a..476898e15b8c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1039,9 +1039,11 @@ noinstr time64_t __ktime_get_real_seconds(void) void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot) { struct timekeeper *tk = &tk_core.timekeeper; + u32 mono_mult, mono_shift; unsigned int seq; ktime_t base_raw; ktime_t base_real; + ktime_t base_boot; u64 nsec_raw; u64 nsec_real; u64 now; @@ -1056,14 +1058,21 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot) systime_snapshot->clock_was_set_seq = tk->clock_was_set_seq; base_real = ktime_add(tk->tkr_mono.base, tk_core.timekeeper.offs_real); + base_boot = ktime_add(tk->tkr_mono.base, + tk_core.timekeeper.offs_boot); base_raw = tk->tkr_raw.base; nsec_real = timekeeping_cycles_to_ns(&tk->tkr_mono, now); nsec_raw = timekeeping_cycles_to_ns(&tk->tkr_raw, now); + mono_mult = tk->tkr_mono.mult; + mono_shift = tk->tkr_mono.shift; } while (read_seqcount_retry(&tk_core.seq, seq)); systime_snapshot->cycles = now; systime_snapshot->real = ktime_add_ns(base_real, nsec_real); + systime_snapshot->boot = ktime_add_ns(base_boot, nsec_real); systime_snapshot->raw = ktime_add_ns(base_raw, nsec_raw); + systime_snapshot->mono_shift = mono_shift; + systime_snapshot->mono_mult = mono_mult; } EXPORT_SYMBOL_GPL(ktime_get_snapshot);