Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1705727

Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps
Date 2017-08-07 19:20 +0200
Message-ID <ubTR7-3eW-11@gated-at.bofh.it> (permalink)
References <ubSBI-291-27@gated-at.bofh.it> <ubTxM-2Qn-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Aug 07, 2017 at 09:52:10AM -0700, John Stultz wrote:
> On Mon, Aug 7, 2017 at 8:52 AM, Prarit Bhargava <prarit@redhat.com> wrote:
> > +u64 ktime_get_real_log_ts(u64 *offset_real)
> > +{
> > +       *offset_real = ktime_to_ns(tk_core.timekeeper.offs_real);
> > +
> > +       if (timekeeping_active)
> > +               return ktime_get_mono_fast_ns();
> > +       else
> > +               return local_clock();
> > +}
> > +
> > +u64 ktime_get_boot_log_ts(void)
> > +{
> > +       if (timekeeping_active)
> > +               return ktime_get_boot_fast_ns();
> > +       else
> > +               return local_clock();
> > +}
> 
> This feels a little tacked on and duplicative.  I'd suggest having one
> function that returns the offset_real and offset_boot or have a
> separate get_mono_log_ts() so its at least consistent.   Additionally,
> in the commit message, you call out the lack of locking between
> grabing the offs_real and calling get_mono_fast_ns(), but I worry it
> may be particularly problematic on 32bit systems, and you don't have
> any notes in the actual code about it (it looks like an oversight).
> 
> Also, when timekeeping_active flips over, and we change from local
> clock to the specified clock, do we see a discontinuity in the log? I
> know folks use to gripe about that back in the day.

Yeah, yuck, this smells. Please don't mix clocks like this.

I expect all you want is to avoid the explosion you get from calling the
fast things too early, right? Please use the below, which should result
in it returning 0.

---
 kernel/time/timekeeping.c | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index cedafa008de5..d111039e0245 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -60,8 +60,39 @@ struct tk_fast {
 	struct tk_read_base	base[2];
 };
 
-static struct tk_fast tk_fast_mono ____cacheline_aligned;
-static struct tk_fast tk_fast_raw  ____cacheline_aligned;
+/* Suspend-time cycles value for halted fast timekeeper. */
+static u64 cycles_at_suspend;
+
+static u64 dummy_clock_read(struct clocksource *cs)
+{
+	return cycles_at_suspend;
+}
+
+static struct clocksource dummy_clock = {
+	.read = dummy_clock_read,
+};
+
+static struct tk_fast tk_fast_mono ____cacheline_aligned = {
+	.base = {
+		(struct tk_read_base){
+			.clock = &dummy_clock,
+		},
+		(struct tk_read_base){
+			.clock = &dummy_clock,
+		},
+	},
+};
+
+static struct tk_fast tk_fast_raw  ____cacheline_aligned = {
+	.base = {
+		(struct tk_read_base){
+			.clock = &dummy_clock,
+		},
+		(struct tk_read_base){
+			.clock = &dummy_clock,
+		},
+	},
+};
 
 /* flag for if timekeeping is suspended */
 int __read_mostly timekeeping_suspended;
@@ -477,18 +508,6 @@ u64 notrace ktime_get_boot_fast_ns(void)
 }
 EXPORT_SYMBOL_GPL(ktime_get_boot_fast_ns);
 
-/* Suspend-time cycles value for halted fast timekeeper. */
-static u64 cycles_at_suspend;
-
-static u64 dummy_clock_read(struct clocksource *cs)
-{
-	return cycles_at_suspend;
-}
-
-static struct clocksource dummy_clock = {
-	.read = dummy_clock_read,
-};
-
 /**
  * halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
  * @tk: Timekeeper to snapshot.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps John Stultz <john.stultz@linaro.org> - 2017-08-07 19:00 +0200
  Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Peter Zijlstra <peterz@infradead.org> - 2017-08-07 19:20 +0200
  Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Prarit Bhargava <prarit@redhat.com> - 2017-08-07 20:10 +0200
    Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps John Stultz <john.stultz@linaro.org> - 2017-08-07 20:50 +0200
      Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Prarit Bhargava <prarit@redhat.com> - 2017-08-07 22:10 +0200
        Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-08-07 22:40 +0200
          Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Peter Zijlstra <peterz@infradead.org> - 2017-08-08 10:30 +0200
            Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Prarit Bhargava <prarit@redhat.com> - 2017-08-09 01:10 +0200
              Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-08-09 19:30 +0200

csiph-web