From: Vincent Donnefort <vdonnefort@google.com>
To: Marc Zyngier <maz@kernel.org>
Cc: rostedt@goodmis.org, mhiramat@kernel.org,
linux-trace-kernel@vger.kernel.org, oliver.upton@linux.dev,
kvmarm@lists.linux.dev, will@kernel.org, qperret@google.com,
kernel-team@android.com
Subject: Re: [RFC PATCH 04/11] timekeeping: Export the boot clock in snapshots
Date: Thu, 5 Sep 2024 14:04:25 +0100 [thread overview]
Message-ID: <ZtmsWedSRbTCEbQ-@google.com> (raw)
In-Reply-To: <865xrsyl6p.wl-maz@kernel.org>
On Thu, Aug 22, 2024 at 10:13:34AM +0100, Marc Zyngier wrote:
> On Mon, 05 Aug 2024 18:32:27 +0100,
> Vincent Donnefort <vdonnefort@google.com> wrote:
> >
> > 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.
>
> When you say "arch_timer" here, are you talking about the data
> structure describing the timer? Or about the actual *counter*, a
> system register provided by the HW?
>
> I'm not sure the architecture-specific details are massively relevant,
> given that this is an arch-agnostic change.
I meant the counter but happy to drop this entire paragraph and just keep the
following one!
>
> >
> > 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.
>
> Isn't that the actual description of the change? By getting the boot
> time as well as the parameters to compute an increment, you allow any
> subsystem able to perform a snapshot to compute a delta from boot time
> as long as they have access to the counter source.
>
> >
> > Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> >
> > diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
> > index fc12a9ba2c88..0fc6a61d64bd 100644
> > --- a/include/linux/timekeeping.h
> > +++ b/include/linux/timekeeping.h
> > @@ -275,18 +275,24 @@ 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
> > * @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;
> > 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 2fa87dcfeda9..6d0488a555a7 100644
> > --- a/kernel/time/timekeeping.c
> > +++ b/kernel/time/timekeeping.c
> > @@ -1057,9 +1057,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;
> > @@ -1074,14 +1076,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);
> >
>
> This looks good to me, but you should probably Cc the timekeeping
> maintainers (tglx, John Stultz, and Stephen Boyd).
Yep, my bad!
>
> Thanks,
>
> M.
>
> --
> Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2024-09-05 13:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 17:32 [RFC PATCH 00/11] Tracefs support for pKVM Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 01/11] ring-buffer: Check for empty ring-buffer with rb_num_of_entries() Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 02/11] ring-buffer: Introducing ring-buffer writer Vincent Donnefort
2024-08-06 20:39 ` Steven Rostedt
2024-08-13 14:21 ` Vincent Donnefort
2024-08-13 14:35 ` Steven Rostedt
2024-08-05 17:32 ` [RFC PATCH 03/11] ring-buffer: Expose buffer_data_page material Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 04/11] timekeeping: Export the boot clock in snapshots Vincent Donnefort
2024-08-22 9:13 ` Marc Zyngier
2024-09-05 13:04 ` Vincent Donnefort [this message]
2024-08-22 18:13 ` John Stultz
2024-08-22 21:41 ` Thomas Gleixner
2024-09-05 13:17 ` Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 05/11] KVM: arm64: Support unaligned fixmap in the nVHE hyp Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 06/11] KVM: arm64: Add clock support " Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 07/11] KVM: arm64: Add tracing support for the pKVM hyp Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 08/11] KVM: arm64: Add hyp tracing to tracefs Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 09/11] KVM: arm64: Add raw interface for hyp tracefs Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 10/11] KVM: arm64: Add support for hyp events Vincent Donnefort
2024-08-05 17:32 ` [RFC PATCH 11/11] KVM: arm64: Add kselftest for tracefs hyp tracefs Vincent Donnefort
2024-08-06 20:11 ` [RFC PATCH 00/11] Tracefs support for pKVM Steven Rostedt
2024-08-07 16:39 ` Vincent Donnefort
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZtmsWedSRbTCEbQ-@google.com \
--to=vdonnefort@google.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=rostedt@goodmis.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.