FROMLIST: timekeeping: Export the boot clock in snapshots

On arm64 systems, the arch timer can be accessible by both EL1 and EL2.
This means when running with nVHE or protected KVM, it is easy to
generate clock values from the hypervisor, synchronized with the kernel.

For tracing purpose, the boot clock is interesting as it doesn't stop on
suspend. Export it as part of the time snapshot. This will later allow
the hypervisor to add boot clock timestamps to its events.

Bug: 357781595
Link: https://lore.kernel.org/all/20240805173234.3542917-5-vdonnefort@google.com/
Change-Id: I18ab228d1c4e0a9684ba014b2ede87bac7087850
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2022-12-21 16:53:34 +00:00
committed by Keir Fraser
parent 530955e649
commit 0a02b0ee8a
2 changed files with 9 additions and 0 deletions
+4
View File
@@ -280,6 +280,8 @@ struct ktime_timestamps {
* @cs_id: Clocksource ID
* @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;
@@ -289,6 +291,8 @@ struct system_time_snapshot {
enum clocksource_ids cs_id;
unsigned int clock_was_set_seq;
u8 cs_was_changed_seq;
u32 mono_shift;
u32 mono_mult;
};
/**
+5
View File
@@ -1057,6 +1057,7 @@ 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;
@@ -1080,12 +1081,16 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
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);