All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Additional time changes for 3.6
@ 2012-07-19  1:19 John Stultz
  2012-07-19  1:19 ` [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined John Stultz
  2012-07-19  1:19 ` [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates John Stultz
  0 siblings, 2 replies; 10+ messages in thread
From: John Stultz @ 2012-07-19  1:19 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Ingo Molnar, Richard Cochran, Prarit Bhargava,
	Thomas Gleixner

Thomas, Ingo, 

Just wanted to send out two more patches against tip/timers/core
for consideration for 3.6.

The first is Catalin's patch to make CLOCK_TICK_RATE optional and
is fairly straight forward.

The second is a patch to improve the handling of the duplicate
offs_real/wall_to_mono and  offs_boot/total_sleep_time pairs.

This second one is a result of the suspend regression in 3.5-rc7
making it clear that these value pairs have to be more carefully
handled, so by forcing all modifications use the set functions
and warning if the value pairs are ever out of sync should
avoid future mistakes.

Please take a look and let me know if you have any thoughts
or concerns on these changes.

thanks
-john


Cc: Ingo Molnar <mingo@kernel.org>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>


Catalin Marinas (1):
  jiffies: Allow CLOCK_TICK_RATE to be undefined

John Stultz (1):
  time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time
    updates

 include/linux/jiffies.h   |   10 +++--
 kernel/time/timekeeping.c |   94 ++++++++++++++++++++++++++++-----------------
 2 files changed, 66 insertions(+), 38 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined
  2012-07-19  1:19 [PATCH 0/2] Additional time changes for 3.6 John Stultz
@ 2012-07-19  1:19 ` John Stultz
  2012-07-19  9:37   ` Ingo Molnar
  2012-07-19  1:19 ` [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates John Stultz
  1 sibling, 1 reply; 10+ messages in thread
From: John Stultz @ 2012-07-19  1:19 UTC (permalink / raw)
  To: lkml
  Cc: Catalin Marinas, Andrew Morton, Ingo Molnar, Richard Cochran,
	Prarit Bhargava, Thomas Gleixner, John Stultz

From: Catalin Marinas <catalin.marinas@arm.com>

CLOCK_TICK_RATE is a legacy constant that defines the timer
device's granularity. On hardware with particularly coarse
granularity, this constant is used to reduce accumulated
time error when using jiffies as a clocksource, by calculating
the hardware's actual tick length rather then just assuming
it is 1sec/HZ.

However, for the most part this is unnecessary, as most modern
systems don't use jiffies for their clocksource, and their
tick device is sufficiently fine grained to avoid major error.

Thus, this patch allows an architecture to not define
CLOCK_TICK_RATE, in which case ACTHZ defaults to (HZ << 8).

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
[jstultz: commit log tweaks]
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/jiffies.h |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 265e2c3..a2134be 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -39,9 +39,6 @@
 # error Invalid value of HZ.
 #endif
 
-/* LATCH is used in the interval timer and ftape setup. */
-#define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
-
 /* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
  * improve accuracy by shifting LSH bits, hence calculating:
  *     (NOM << LSH) / DEN
@@ -54,8 +51,15 @@
 #define SH_DIV(NOM,DEN,LSH) (   (((NOM) / (DEN)) << (LSH))              \
                              + ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))
 
+#ifdef CLOCK_TICK_RATE
+/* LATCH is used in the interval timer and ftape setup. */
+#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
+
 /* HZ is the requested value. ACTHZ is actual HZ ("<< 8" is for accuracy) */
 #define ACTHZ (SH_DIV (CLOCK_TICK_RATE, LATCH, 8))
+#else
+#define ACTHZ (HZ << 8)
+#endif
 
 /* TICK_NSEC is the time between ticks in nsec assuming real ACTHZ */
 #define TICK_NSEC (SH_DIV (1000000UL * 1000, ACTHZ, 8))
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates
  2012-07-19  1:19 [PATCH 0/2] Additional time changes for 3.6 John Stultz
  2012-07-19  1:19 ` [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined John Stultz
@ 2012-07-19  1:19 ` John Stultz
  2012-07-19  9:33   ` Ingo Molnar
  2012-07-19 12:37   ` Prarit Bhargava
  1 sibling, 2 replies; 10+ messages in thread
From: John Stultz @ 2012-07-19  1:19 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Ingo Molnar, Peter Zijlstra, Richard Cochran,
	Prarit Bhargava, Thomas Gleixner

For performance reasons, we maintain ktime_t based duplicates of
wall_to_monotonic (offs_real) and total_sleep_time (offs_boot).

Since large problems could occur (such as the resume regression
on 3.5-rc7, or the leapsecond hrtimer issue) if these value pairs
were to be inconsistently updated, this patch this cleans up how
we modify these value pairs to ensure we are always consistent.

As a side-effect this is also more efficient as we only
caulculate the duplicate values when they are changed,
rather then every update_wall_time call.

This also provides WARN_ONs to detect if future changes break
the invariants.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c |   94 ++++++++++++++++++++++++++++-----------------
 1 file changed, 59 insertions(+), 35 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index f045cc5..0b780bd 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -65,14 +65,14 @@ struct timekeeper {
 	 * used instead.
 	 */
 	struct timespec		wall_to_monotonic;
-	/* time spent in suspend */
-	struct timespec		total_sleep_time;
-	/* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
-	struct timespec		raw_time;
 	/* Offset clock monotonic -> clock realtime */
 	ktime_t			offs_real;
+	/* time spent in suspend */
+	struct timespec		total_sleep_time;
 	/* Offset clock monotonic -> clock boottime */
 	ktime_t			offs_boot;
+	/* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
+	struct timespec		raw_time;
 	/* Seqlock for all timekeeper values */
 	seqlock_t		lock;
 };
@@ -117,6 +117,36 @@ static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
 	tk->xtime_nsec += ts->tv_nsec << tk->shift;
 }
 
+
+static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec wtm)
+{
+	struct timespec tmp;
+
+	/*
+	 * Verify consistency of: offset_real = -wall_to_monotonic
+	 * before modifying anything
+	 */
+	set_normalized_timespec(&tmp, -tk->wall_to_monotonic.tv_sec,
+					-tk->wall_to_monotonic.tv_nsec);
+	WARN_ON_ONCE(tk->offs_real.tv64 != timespec_to_ktime(tmp).tv64);
+	tk->wall_to_monotonic = wtm;
+	set_normalized_timespec(&tmp, -wtm.tv_sec, -wtm.tv_nsec);
+	tk->offs_real = timespec_to_ktime(tmp);
+}
+
+
+static void tk_set_sleep_time(struct timekeeper *tk, struct timespec t)
+{
+	/* Verify consistency before modifying */
+	WARN_ON_ONCE(tk->offs_boot.tv64 !=
+				timespec_to_ktime(tk->total_sleep_time).tv64);
+
+	tk->total_sleep_time = t;
+	tk->offs_boot = timespec_to_ktime(t);
+}
+
+
+
 /**
  * timekeeper_setup_internals - Set up internals to use clocksource clock.
  *
@@ -217,13 +247,6 @@ static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk)
 	return nsec + arch_gettimeoffset();
 }
 
-static void update_rt_offset(struct timekeeper *tk)
-{
-	struct timespec tmp, *wtm = &tk->wall_to_monotonic;
-
-	set_normalized_timespec(&tmp, -wtm->tv_sec, -wtm->tv_nsec);
-	tk->offs_real = timespec_to_ktime(tmp);
-}
 
 /* must hold write on timekeeper.lock */
 static void timekeeping_update(struct timekeeper *tk, bool clearntp)
@@ -234,7 +257,6 @@ static void timekeeping_update(struct timekeeper *tk, bool clearntp)
 		tk->ntp_error = 0;
 		ntp_clear();
 	}
-	update_rt_offset(tk);
 	xt = tk_xtime(tk);
 	update_vsyscall(&xt, &tk->wall_to_monotonic, tk->clock, tk->mult);
 }
@@ -420,8 +442,8 @@ int do_settimeofday(const struct timespec *tv)
 	ts_delta.tv_sec = tv->tv_sec - xt.tv_sec;
 	ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec;
 
-	timekeeper.wall_to_monotonic =
-			timespec_sub(timekeeper.wall_to_monotonic, ts_delta);
+	tk_set_wall_to_mono(&timekeeper,
+			timespec_sub(timekeeper.wall_to_monotonic, ts_delta));
 
 	tk_set_xtime(&timekeeper, tv);
 
@@ -456,8 +478,8 @@ int timekeeping_inject_offset(struct timespec *ts)
 
 
 	tk_xtime_add(&timekeeper, ts);
-	timekeeper.wall_to_monotonic =
-				timespec_sub(timekeeper.wall_to_monotonic, *ts);
+	tk_set_wall_to_mono(&timekeeper,
+			timespec_sub(timekeeper.wall_to_monotonic, *ts));
 
 	timekeeping_update(&timekeeper, true);
 
@@ -624,7 +646,7 @@ void __init timekeeping_init(void)
 {
 	struct clocksource *clock;
 	unsigned long flags;
-	struct timespec now, boot;
+	struct timespec now, boot, tmp;
 
 	read_persistent_clock(&now);
 	read_boot_clock(&boot);
@@ -645,23 +667,19 @@ void __init timekeeping_init(void)
 	if (boot.tv_sec == 0 && boot.tv_nsec == 0)
 		boot = tk_xtime(&timekeeper);
 
-	set_normalized_timespec(&timekeeper.wall_to_monotonic,
-				-boot.tv_sec, -boot.tv_nsec);
-	update_rt_offset(&timekeeper);
-	timekeeper.total_sleep_time.tv_sec = 0;
-	timekeeper.total_sleep_time.tv_nsec = 0;
+	set_normalized_timespec(&tmp, -boot.tv_sec, -boot.tv_nsec);
+	tk_set_wall_to_mono(&timekeeper, tmp);
+
+	tmp.tv_sec = 0;
+	tmp.tv_nsec = 0;
+	tk_set_sleep_time(&timekeeper, tmp);
+
 	write_sequnlock_irqrestore(&timekeeper.lock, flags);
 }
 
 /* time in seconds when suspend began */
 static struct timespec timekeeping_suspend_time;
 
-static void update_sleep_time(struct timespec t)
-{
-	timekeeper.total_sleep_time = t;
-	timekeeper.offs_boot = timespec_to_ktime(t);
-}
-
 /**
  * __timekeeping_inject_sleeptime - Internal function to add sleep interval
  * @delta: pointer to a timespec delta value
@@ -677,10 +695,9 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
 					"sleep delta value!\n");
 		return;
 	}
-
 	tk_xtime_add(tk, delta);
-	tk->wall_to_monotonic = timespec_sub(tk->wall_to_monotonic, *delta);
-	update_sleep_time(timespec_add(tk->total_sleep_time, *delta));
+	tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, *delta));
+	tk_set_sleep_time(tk, timespec_add(tk->total_sleep_time, *delta));
 }
 
 
@@ -1024,11 +1041,18 @@ static inline void accumulate_nsecs_to_secs(struct timekeeper *tk)
 
 		/* Figure out if its a leap sec and apply if needed */
 		leap = second_overflow(tk->xtime_sec);
-		tk->xtime_sec += leap;
-		tk->wall_to_monotonic.tv_sec -= leap;
-		if (leap)
-			clock_was_set_delayed();
+		if (unlikely(leap)) {
+			struct timespec ts;
+
+			tk->xtime_sec += leap;
 
+			ts.tv_sec = leap;
+			ts.tv_nsec = 0;
+			tk_set_wall_to_mono(tk,
+				timespec_sub(tk->wall_to_monotonic, ts));
+
+			clock_was_set_delayed();
+		}
 	}
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates
  2012-07-19  1:19 ` [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates John Stultz
@ 2012-07-19  9:33   ` Ingo Molnar
  2012-07-23 19:31     ` John Stultz
  2012-07-19 12:37   ` Prarit Bhargava
  1 sibling, 1 reply; 10+ messages in thread
From: Ingo Molnar @ 2012-07-19  9:33 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Peter Zijlstra, Richard Cochran, Prarit Bhargava, Thomas Gleixner


* John Stultz <john.stultz@linaro.org> wrote:

> For performance reasons, we maintain ktime_t based duplicates of
> wall_to_monotonic (offs_real) and total_sleep_time (offs_boot).
> 
> Since large problems could occur (such as the resume regression
> on 3.5-rc7, or the leapsecond hrtimer issue) if these value pairs
> were to be inconsistently updated, this patch this cleans up how
> we modify these value pairs to ensure we are always consistent.
> 
> As a side-effect this is also more efficient as we only
> caulculate the duplicate values when they are changed,
> rather then every update_wall_time call.

Makes sense.

> This also provides WARN_ONs to detect if future changes break
> the invariants.
> 
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Prarit Bhargava <prarit@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
>  kernel/time/timekeeping.c |   94 ++++++++++++++++++++++++++++-----------------
>  1 file changed, 59 insertions(+), 35 deletions(-)
> 
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index f045cc5..0b780bd 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -65,14 +65,14 @@ struct timekeeper {
>  	 * used instead.
>  	 */
>  	struct timespec		wall_to_monotonic;
> -	/* time spent in suspend */
> -	struct timespec		total_sleep_time;
> -	/* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
> -	struct timespec		raw_time;
>  	/* Offset clock monotonic -> clock realtime */
>  	ktime_t			offs_real;
> +	/* time spent in suspend */
> +	struct timespec		total_sleep_time;
>  	/* Offset clock monotonic -> clock boottime */
>  	ktime_t			offs_boot;
> +	/* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
> +	struct timespec		raw_time;
>  	/* Seqlock for all timekeeper values */
>  	seqlock_t		lock;
>  };
> @@ -117,6 +117,36 @@ static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
>  	tk->xtime_nsec += ts->tv_nsec << tk->shift;
>  }
>  
> +

Stray newline.

> +static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec wtm)
> +{
> +	struct timespec tmp;
> +
> +	/*
> +	 * Verify consistency of: offset_real = -wall_to_monotonic
> +	 * before modifying anything
> +	 */
> +	set_normalized_timespec(&tmp, -tk->wall_to_monotonic.tv_sec,
> +					-tk->wall_to_monotonic.tv_nsec);
> +	WARN_ON_ONCE(tk->offs_real.tv64 != timespec_to_ktime(tmp).tv64);
> +	tk->wall_to_monotonic = wtm;
> +	set_normalized_timespec(&tmp, -wtm.tv_sec, -wtm.tv_nsec);
> +	tk->offs_real = timespec_to_ktime(tmp);
> +}
> +
> +

Stray newline.

> +static void tk_set_sleep_time(struct timekeeper *tk, struct timespec t)
> +{
> +	/* Verify consistency before modifying */
> +	WARN_ON_ONCE(tk->offs_boot.tv64 !=
> +				timespec_to_ktime(tk->total_sleep_time).tv64);

asserts like this can be put into a single line - we rarely need 
to read them if they don't trigger - and making them 
non-intrusive oneliners is a bonus.

> +
> +	tk->total_sleep_time = t;
> +	tk->offs_boot = timespec_to_ktime(t);
> +}
> +
> +
> +

Stray newlines.

>  /**
>   * timekeeper_setup_internals - Set up internals to use clocksource clock.
>   *
> @@ -217,13 +247,6 @@ static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk)
>  	return nsec + arch_gettimeoffset();
>  }
>  
> -static void update_rt_offset(struct timekeeper *tk)
> -{
> -	struct timespec tmp, *wtm = &tk->wall_to_monotonic;
> -
> -	set_normalized_timespec(&tmp, -wtm->tv_sec, -wtm->tv_nsec);
> -	tk->offs_real = timespec_to_ktime(tmp);
> -}
>  
>  /* must hold write on timekeeper.lock */
>  static void timekeeping_update(struct timekeeper *tk, bool clearntp)
> @@ -234,7 +257,6 @@ static void timekeeping_update(struct timekeeper *tk, bool clearntp)
>  		tk->ntp_error = 0;
>  		ntp_clear();
>  	}
> -	update_rt_offset(tk);
>  	xt = tk_xtime(tk);
>  	update_vsyscall(&xt, &tk->wall_to_monotonic, tk->clock, tk->mult);
>  }
> @@ -420,8 +442,8 @@ int do_settimeofday(const struct timespec *tv)
>  	ts_delta.tv_sec = tv->tv_sec - xt.tv_sec;
>  	ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec;
>  
> -	timekeeper.wall_to_monotonic =
> -			timespec_sub(timekeeper.wall_to_monotonic, ts_delta);
> +	tk_set_wall_to_mono(&timekeeper,
> +			timespec_sub(timekeeper.wall_to_monotonic, ts_delta));
>  
>  	tk_set_xtime(&timekeeper, tv);
>  
> @@ -456,8 +478,8 @@ int timekeeping_inject_offset(struct timespec *ts)
>  
>  
>  	tk_xtime_add(&timekeeper, ts);
> -	timekeeper.wall_to_monotonic =
> -				timespec_sub(timekeeper.wall_to_monotonic, *ts);
> +	tk_set_wall_to_mono(&timekeeper,
> +			timespec_sub(timekeeper.wall_to_monotonic, *ts));

There's a *lot* of unnecessary ugliness here and in many other 
places in kernel/time/ due to repeating patterns of 
"timekeeper.", which gets repeated many times and blows up line 
length.

Please add this to the highest level (system call, irq handler, 
etc.) code:

	struct timekeeper *tk = &timekeeper;

and pass that down to lower levels. The tk-> pattern will be the 
obvious thing to type in typical time handling functions.

This increases readability and clarifies the data flow and might 
bring other advantages in the future.

>  	timekeeping_update(&timekeeper, true);
>  
> @@ -624,7 +646,7 @@ void __init timekeeping_init(void)
>  {
>  	struct clocksource *clock;
>  	unsigned long flags;
> -	struct timespec now, boot;
> +	struct timespec now, boot, tmp;
>  
>  	read_persistent_clock(&now);
>  	read_boot_clock(&boot);
> @@ -645,23 +667,19 @@ void __init timekeeping_init(void)
>  	if (boot.tv_sec == 0 && boot.tv_nsec == 0)
>  		boot = tk_xtime(&timekeeper);
>  
> -	set_normalized_timespec(&timekeeper.wall_to_monotonic,
> -				-boot.tv_sec, -boot.tv_nsec);
> -	update_rt_offset(&timekeeper);
> -	timekeeper.total_sleep_time.tv_sec = 0;
> -	timekeeper.total_sleep_time.tv_nsec = 0;
> +	set_normalized_timespec(&tmp, -boot.tv_sec, -boot.tv_nsec);
> +	tk_set_wall_to_mono(&timekeeper, tmp);
> +
> +	tmp.tv_sec = 0;
> +	tmp.tv_nsec = 0;
> +	tk_set_sleep_time(&timekeeper, tmp);
> +
>  	write_sequnlock_irqrestore(&timekeeper.lock, flags);
>  }
>  
>  /* time in seconds when suspend began */
>  static struct timespec timekeeping_suspend_time;
>  
> -static void update_sleep_time(struct timespec t)
> -{
> -	timekeeper.total_sleep_time = t;
> -	timekeeper.offs_boot = timespec_to_ktime(t);
> -}
> -
>  /**
>   * __timekeeping_inject_sleeptime - Internal function to add sleep interval
>   * @delta: pointer to a timespec delta value
> @@ -677,10 +695,9 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
>  					"sleep delta value!\n");
>  		return;
>  	}
> -
>  	tk_xtime_add(tk, delta);
> -	tk->wall_to_monotonic = timespec_sub(tk->wall_to_monotonic, *delta);
> -	update_sleep_time(timespec_add(tk->total_sleep_time, *delta));
> +	tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, *delta));
> +	tk_set_sleep_time(tk, timespec_add(tk->total_sleep_time, *delta));
>  }
>  
>  

Stray newline.

I see a pattern with the newlines there - and this isnt the 
first patch from you that has that problem.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined
  2012-07-19  1:19 ` [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined John Stultz
@ 2012-07-19  9:37   ` Ingo Molnar
  2012-07-23 19:37     ` John Stultz
  0 siblings, 1 reply; 10+ messages in thread
From: Ingo Molnar @ 2012-07-19  9:37 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Catalin Marinas, Andrew Morton, Richard Cochran,
	Prarit Bhargava, Thomas Gleixner


* John Stultz <john.stultz@linaro.org> wrote:

> From: Catalin Marinas <catalin.marinas@arm.com>
> 
> CLOCK_TICK_RATE is a legacy constant that defines the timer
> device's granularity. On hardware with particularly coarse
> granularity, this constant is used to reduce accumulated
> time error when using jiffies as a clocksource, by calculating
> the hardware's actual tick length rather then just assuming
> it is 1sec/HZ.
> 
> However, for the most part this is unnecessary, as most modern
> systems don't use jiffies for their clocksource, and their
> tick device is sufficiently fine grained to avoid major error.
> 
> Thus, this patch allows an architecture to not define
> CLOCK_TICK_RATE, in which case ACTHZ defaults to (HZ << 8).
> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Prarit Bhargava <prarit@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> [jstultz: commit log tweaks]
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
>  include/linux/jiffies.h |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
> index 265e2c3..a2134be 100644
> --- a/include/linux/jiffies.h
> +++ b/include/linux/jiffies.h
> @@ -39,9 +39,6 @@
>  # error Invalid value of HZ.
>  #endif
>  
> -/* LATCH is used in the interval timer and ftape setup. */
> -#define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
> -
>  /* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
>   * improve accuracy by shifting LSH bits, hence calculating:
>   *     (NOM << LSH) / DEN
> @@ -54,8 +51,15 @@
>  #define SH_DIV(NOM,DEN,LSH) (   (((NOM) / (DEN)) << (LSH))              \
>                               + ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))
>  
> +#ifdef CLOCK_TICK_RATE
> +/* LATCH is used in the interval timer and ftape setup. */
> +#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
> +
>  /* HZ is the requested value. ACTHZ is actual HZ ("<< 8" is for accuracy) */
>  #define ACTHZ (SH_DIV (CLOCK_TICK_RATE, LATCH, 8))
> +#else
> +#define ACTHZ (HZ << 8)
> +#endif

The ACTHZ naming ugliness slipped past me. 'ACT' can mean so 
many things - please improve it to something more obvious, like 
'REAL_HZ' or 'KERNEL_HZ'.

Also, we tend to write such #if/#else/#endif patterns as:

#if FOO
# define BAR 
#else
# define BAZ
#endif

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates
  2012-07-19  1:19 ` [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates John Stultz
  2012-07-19  9:33   ` Ingo Molnar
@ 2012-07-19 12:37   ` Prarit Bhargava
  1 sibling, 0 replies; 10+ messages in thread
From: Prarit Bhargava @ 2012-07-19 12:37 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Ingo Molnar, Peter Zijlstra, Richard Cochran, Thomas Gleixner



On 07/18/2012 09:19 PM, John Stultz wrote:
> For performance reasons, we maintain ktime_t based duplicates of
> wall_to_monotonic (offs_real) and total_sleep_time (offs_boot).
> 
> Since large problems could occur (such as the resume regression
> on 3.5-rc7, or the leapsecond hrtimer issue) if these value pairs
> were to be inconsistently updated, this patch this cleans up how
> we modify these value pairs to ensure we are always consistent.
> 
> As a side-effect this is also more efficient as we only
> caulculate the duplicate values when they are changed,
> rather then every update_wall_time call.
> 
> This also provides WARN_ONs to detect if future changes break
> the invariants.
> 
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Prarit Bhargava <prarit@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: John Stultz <john.stultz@linaro.org>

<snip>

> @@ -1024,11 +1041,18 @@ static inline void accumulate_nsecs_to_secs(struct timekeeper *tk)
>  
>  		/* Figure out if its a leap sec and apply if needed */
>  		leap = second_overflow(tk->xtime_sec);
> -		tk->xtime_sec += leap;
> -		tk->wall_to_monotonic.tv_sec -= leap;
> -		if (leap)
> -			clock_was_set_delayed();
> +		if (unlikely(leap)) {

I'm likely a bit behind the times with this comment ...

I thought someone did a comparison of the usage of unlikely() within the kernel
and found that it didn't really add that much.  I'm not strongly opposed to it
in anyway, it is just that I'm curious about unlikely()'s continued usage within
the kernel; does it really add anything *other* than code readability at this point?

> +			struct timespec ts;
> +
> +			tk->xtime_sec += leap;
>  
> +			ts.tv_sec = leap;
> +			ts.tv_nsec = 0;

I wonder if this is true or not when the kernel handles the leap second.  I
suppose, in theory it is ... but it might be ahead by a bit.  I guess it is
"close enough" ;)

> +			tk_set_wall_to_mono(tk,
> +				timespec_sub(tk->wall_to_monotonic, ts));
> +
> +			clock_was_set_delayed();
> +		}
>  	}
>  }
>  

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates
  2012-07-19  9:33   ` Ingo Molnar
@ 2012-07-23 19:31     ` John Stultz
  2012-07-26 12:57       ` Ingo Molnar
  0 siblings, 1 reply; 10+ messages in thread
From: John Stultz @ 2012-07-23 19:31 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: lkml, Peter Zijlstra, Richard Cochran, Prarit Bhargava, Thomas Gleixner

On 07/19/2012 02:33 AM, Ingo Molnar wrote:
> * John Stultz <john.stultz@linaro.org> wrote:
>
>> +static void tk_set_sleep_time(struct timekeeper *tk, struct timespec t)
>> +{
>> +	/* Verify consistency before modifying */
>> +	WARN_ON_ONCE(tk->offs_boot.tv64 !=
>> +				timespec_to_ktime(tk->total_sleep_time).tv64);
> asserts like this can be put into a single line - we rarely need
> to read them if they don't trigger - and making them
> non-intrusive oneliners is a bonus.

Ack.

>>   @@ -456,8 +478,8 @@ int timekeeping_inject_offset(struct timespec *ts)
>>   
>>   
>>   	tk_xtime_add(&timekeeper, ts);
>> -	timekeeper.wall_to_monotonic =
>> -				timespec_sub(timekeeper.wall_to_monotonic, *ts);
>> +	tk_set_wall_to_mono(&timekeeper,
>> +			timespec_sub(timekeeper.wall_to_monotonic, *ts));
> There's a *lot* of unnecessary ugliness here and in many other
> places in kernel/time/ due to repeating patterns of
> "timekeeper.", which gets repeated many times and blows up line
> length.
>
> Please add this to the highest level (system call, irq handler,
> etc.) code:
>
> 	struct timekeeper *tk = &timekeeper;
>
> and pass that down to lower levels. The tk-> pattern will be the
> obvious thing to type in typical time handling functions.
>
> This increases readability and clarifies the data flow and might
> bring other advantages in the future.

Sounds good. Are you ok if this is done in a follow-on patch?

> Stray newline.
>
> I see a pattern with the newlines there - and this isnt the
> first patch from you that has that problem.

Yea, I personally prefer more space between functions, so its a bad 
habit I have (and checkpatch doesn't catch). I'll try to be more 
watchful of it going forward.

thanks
-john



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined
  2012-07-19  9:37   ` Ingo Molnar
@ 2012-07-23 19:37     ` John Stultz
  2012-07-26 12:56       ` Ingo Molnar
  0 siblings, 1 reply; 10+ messages in thread
From: John Stultz @ 2012-07-23 19:37 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: lkml, Catalin Marinas, Andrew Morton, Richard Cochran,
	Prarit Bhargava, Thomas Gleixner

On 07/19/2012 02:37 AM, Ingo Molnar wrote:
> * John Stultz <john.stultz@linaro.org> wrote:
>
>> From: Catalin Marinas <catalin.marinas@arm.com>
...
>> diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
>> index 265e2c3..a2134be 100644
>> --- a/include/linux/jiffies.h
>> +++ b/include/linux/jiffies.h
>> @@ -39,9 +39,6 @@
>>   # error Invalid value of HZ.
>>   #endif
>>   
>> -/* LATCH is used in the interval timer and ftape setup. */
>> -#define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
>> -
>>   /* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
>>    * improve accuracy by shifting LSH bits, hence calculating:
>>    *     (NOM << LSH) / DEN
>> @@ -54,8 +51,15 @@
>>   #define SH_DIV(NOM,DEN,LSH) (   (((NOM) / (DEN)) << (LSH))              \
>>                                + ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))
>>   
>> +#ifdef CLOCK_TICK_RATE
>> +/* LATCH is used in the interval timer and ftape setup. */
>> +#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
>> +
>>   /* HZ is the requested value. ACTHZ is actual HZ ("<< 8" is for accuracy) */
>>   #define ACTHZ (SH_DIV (CLOCK_TICK_RATE, LATCH, 8))
>> +#else
>> +#define ACTHZ (HZ << 8)
>> +#endif
> The ACTHZ naming ugliness slipped past me. 'ACT' can mean so
> many things - please improve it to something more obvious, like
> 'REAL_HZ' or 'KERNEL_HZ'.

ACTHZ has been around for a while. ~2002 I think?

Is it ok if I do the rename in a following patch?

> Also, we tend to write such #if/#else/#endif patterns as:
>
> #if FOO
> # define BAR
> #else
> # define BAZ
> #endif
I'll fix this.

Thanks for the review
-john


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined
  2012-07-23 19:37     ` John Stultz
@ 2012-07-26 12:56       ` Ingo Molnar
  0 siblings, 0 replies; 10+ messages in thread
From: Ingo Molnar @ 2012-07-26 12:56 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Catalin Marinas, Andrew Morton, Richard Cochran,
	Prarit Bhargava, Thomas Gleixner


* John Stultz <john.stultz@linaro.org> wrote:

> On 07/19/2012 02:37 AM, Ingo Molnar wrote:
> >* John Stultz <john.stultz@linaro.org> wrote:
> >
> >>From: Catalin Marinas <catalin.marinas@arm.com>
> ...
> >>diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
> >>index 265e2c3..a2134be 100644
> >>--- a/include/linux/jiffies.h
> >>+++ b/include/linux/jiffies.h
> >>@@ -39,9 +39,6 @@
> >>  # error Invalid value of HZ.
> >>  #endif
> >>-/* LATCH is used in the interval timer and ftape setup. */
> >>-#define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
> >>-
> >>  /* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
> >>   * improve accuracy by shifting LSH bits, hence calculating:
> >>   *     (NOM << LSH) / DEN
> >>@@ -54,8 +51,15 @@
> >>  #define SH_DIV(NOM,DEN,LSH) (   (((NOM) / (DEN)) << (LSH))              \
> >>                               + ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))
> >>+#ifdef CLOCK_TICK_RATE
> >>+/* LATCH is used in the interval timer and ftape setup. */
> >>+#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */
> >>+
> >>  /* HZ is the requested value. ACTHZ is actual HZ ("<< 8" is for accuracy) */
> >>  #define ACTHZ (SH_DIV (CLOCK_TICK_RATE, LATCH, 8))
> >>+#else
> >>+#define ACTHZ (HZ << 8)
> >>+#endif
> >The ACTHZ naming ugliness slipped past me. 'ACT' can mean so
> >many things - please improve it to something more obvious, like
> >'REAL_HZ' or 'KERNEL_HZ'.
> 
> ACTHZ has been around for a while. ~2002 I think?

Time flies!

> Is it ok if I do the rename in a following patch?

Sure.

> >Also, we tend to write such #if/#else/#endif patterns as:
> >
> >#if FOO
> ># define BAR
> >#else
> ># define BAZ
> >#endif
> I'll fix this.

Thanks!

	Ingo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates
  2012-07-23 19:31     ` John Stultz
@ 2012-07-26 12:57       ` Ingo Molnar
  0 siblings, 0 replies; 10+ messages in thread
From: Ingo Molnar @ 2012-07-26 12:57 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Peter Zijlstra, Richard Cochran, Prarit Bhargava, Thomas Gleixner


* John Stultz <john.stultz@linaro.org> wrote:

> On 07/19/2012 02:33 AM, Ingo Molnar wrote:
> >* John Stultz <john.stultz@linaro.org> wrote:
> >
> >>+static void tk_set_sleep_time(struct timekeeper *tk, struct timespec t)
> >>+{
> >>+	/* Verify consistency before modifying */
> >>+	WARN_ON_ONCE(tk->offs_boot.tv64 !=
> >>+				timespec_to_ktime(tk->total_sleep_time).tv64);
> >asserts like this can be put into a single line - we rarely need
> >to read them if they don't trigger - and making them
> >non-intrusive oneliners is a bonus.
> 
> Ack.
> 
> >>  @@ -456,8 +478,8 @@ int timekeeping_inject_offset(struct timespec *ts)
> >>  	tk_xtime_add(&timekeeper, ts);
> >>-	timekeeper.wall_to_monotonic =
> >>-				timespec_sub(timekeeper.wall_to_monotonic, *ts);
> >>+	tk_set_wall_to_mono(&timekeeper,
> >>+			timespec_sub(timekeeper.wall_to_monotonic, *ts));
> >There's a *lot* of unnecessary ugliness here and in many other
> >places in kernel/time/ due to repeating patterns of
> >"timekeeper.", which gets repeated many times and blows up line
> >length.
> >
> >Please add this to the highest level (system call, irq handler,
> >etc.) code:
> >
> >	struct timekeeper *tk = &timekeeper;
> >
> >and pass that down to lower levels. The tk-> pattern will be the
> >obvious thing to type in typical time handling functions.
> >
> >This increases readability and clarifies the data flow and might
> >bring other advantages in the future.
> 
> Sounds good. Are you ok if this is done in a follow-on patch?

Yeah, sure - the code is going in the right direction in 
general, so no hurry.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-07-26 12:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19  1:19 [PATCH 0/2] Additional time changes for 3.6 John Stultz
2012-07-19  1:19 ` [PATCH 1/2] jiffies: Allow CLOCK_TICK_RATE to be undefined John Stultz
2012-07-19  9:37   ` Ingo Molnar
2012-07-23 19:37     ` John Stultz
2012-07-26 12:56       ` Ingo Molnar
2012-07-19  1:19 ` [PATCH 2/2] time: Cleanup offs_real/wall_to_mono and offs_boot/total_sleep_time updates John Stultz
2012-07-19  9:33   ` Ingo Molnar
2012-07-23 19:31     ` John Stultz
2012-07-26 12:57       ` Ingo Molnar
2012-07-19 12:37   ` Prarit Bhargava

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.