public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [patch 02/14] remove clocksource inline functions
       [not found] ` <20090813154159.634291990@de.ibm.com>
@ 2009-08-13 22:14   ` john stultz
  2009-08-14  8:10     ` Martin Schwidefsky
  0 siblings, 1 reply; 6+ messages in thread
From: john stultz @ 2009-08-13 22:14 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: linux-kernel, Ingo Molnar, Thomas Gleixner, Daniel Walker

On Thu, 2009-08-13 at 17:40 +0200, Martin Schwidefsky wrote:
> plain text document attachment (clocksource-inline.diff)
> From: Martin Schwidefsky <schwidefsky@de.ibm.com>
> 
> The three inline functions clocksource_read, clocksource_enable
> and clocksource_disable are simple wrappers of an indirect call
> plus the copy from and to the mult_orig value. The functions
> are exclusively used by the timekeeping code which has intimate
> knowledge of the clocksource anyway. Therefore remove the inline
> functions. No functional change.
> 
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Daniel Walker <dwalker@fifo99.com>
> Acked-by: John Stultz <johnstul@us.ibm.com>
> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
> ---
>  include/linux/clocksource.h |   58
> --------------------------------------------
>  kernel/time/timekeeping.c   |   42 +++++++++++++++++++++----------
>  2 files changed, 28 insertions(+), 72 deletions(-)
> 
> Index: linux-2.6/kernel/time/timekeeping.c
> ===================================================================
> --- linux-2.6.orig/kernel/time/timekeeping.c
> +++ linux-2.6/kernel/time/timekeeping.c
[snip]
> @@ -477,8 +492,7 @@ static int timekeeping_resume(struct sys
>  	}
>  	update_xtime_cache(0);
>  	/* re-base the last cycle value */
> -	clock->cycle_last = 0;
> -	clock->cycle_last = clocksource_read(clock);
> +	clock->cycle_last = clock->read(clock);

Minor bug here, the clearing of cycle_last has a side-effect of making
sure the TSC doesn't trip over its own cycle_last checking in the read()
function. This is part of the uglyness of the TSC pulling this internal
timeekping state to avoid minor inconsistencies, but until we find a
better way, we have to live with it.

So you'll need to preserve the cycle_last = 0 line.

thanks
-john





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

* Re: [patch 11/14] timekeeper read clock helper functions
       [not found] ` <20090813154201.810817188@de.ibm.com>
@ 2009-08-13 23:30   ` john stultz
  2009-08-14 11:12     ` Martin Schwidefsky
  0 siblings, 1 reply; 6+ messages in thread
From: john stultz @ 2009-08-13 23:30 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: linux-kernel, Ingo Molnar, Thomas Gleixner, Daniel Walker

On Thu, 2009-08-13 at 17:40 +0200, Martin Schwidefsky wrote:
> plain text document attachment (timekeeper-helper.diff)
> From: Martin Schwidefsky <schwidefsky@de.ibm.com>
> 
> Add timekeeper_read_clock_ntp and timekeeper_read_clock_raw and use
> them for getnstimeofday, ktime_get, ktime_get_ts and getrawmonotonic.
> 
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: john stultz <johnstul@us.ibm.com>
> Cc: Daniel Walker <dwalker@fifo99.com>
> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
> ---
>  kernel/time/timekeeping.c |   91 +++++++++++++++++++---------------------------
>  1 file changed, 38 insertions(+), 53 deletions(-)
> 
> Index: linux-2.6/kernel/time/timekeeping.c
> ===================================================================
> --- linux-2.6.orig/kernel/time/timekeeping.c
> +++ linux-2.6/kernel/time/timekeeping.c
> @@ -95,6 +95,40 @@ static void timekeeper_setup_internals(s
>  	timekeeper.mult = clock->mult;
>  }
> 
> +/* Timekeeper helper functions. */
> +static inline s64 timekeeping_get_ns(void)
> +{
> +	cycle_t cycle_now, cycle_delta;
> +	struct clocksource *clock;
> +
> +	/* read clocksource: */
> +	clock = timekeeper.clock;
> +	cycle_now = clock->read(clock);
> +
> +	/* calculate the delta since the last update_wall_time: */
> +	cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
> +
> +	/* return delta convert to nanoseconds using ntp adjusted mult. */
> +	return clocksource_cyc2ns(cycle_delta, timekeeper.mult,
> +				  timekeeper.shift);
> +}

Again, not a huge issue, but if we kept the read() out of this function
and instead passed the cycle_now value in as a argument, we could also
use this function in  timekeeping_forward_now()


thanks
-john



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

* Re: [patch 00/14] clocksource / timekeeping rework V3
       [not found] <20090813154034.613706651@de.ibm.com>
       [not found] ` <20090813154159.634291990@de.ibm.com>
       [not found] ` <20090813154201.810817188@de.ibm.com>
@ 2009-08-14  0:28 ` john stultz
  2 siblings, 0 replies; 6+ messages in thread
From: john stultz @ 2009-08-14  0:28 UTC (permalink / raw)
  To: Martin Schwidefsky; +Cc: linux-kernel, Ingo Molnar, Thomas Gleixner

On Thu, 2009-08-13 at 17:40 +0200, Martin Schwidefsky wrote:
> Greetings,
> version 3 of the clocksource / timekeeping cleanup patches. As far as
> I'm concerned this is the final version, modulo bugs and review results.
> All the things I want to have in there are done.
> 
> The latest additions are:
> 1) Change read_persistent_clock to return a struct timespec instead of
>    an unsigned long with the number of seconds.
> 2) Introduce read_boot_clock to initialize wall_to_monotonic.
> 
> The patch set is based on todays upstream tree plus the patches from
> the tip tree, if anyone wants to try them you need to pull from the
> master branch of
>     git://git.kernel.org/pub/scm/linux/kernel/git/x86/linux-2.6-tip

So I got the patch queue up and running and it's functioning correctly
on the box I tested it with (although its not a super interesting box:
TSC is unstable and it only has ACPI PM).

Although I've not been able to test changing clocksources, I assume you
gave that a whirl? I'll test that as soon as I can get access to a TSC
friendly box.

Once the "cycles_last = 0" fix is in to make sure TSC boxes work, I
think this set should be ok to go in.

thanks
-john


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

* Re: [patch 02/14] remove clocksource inline functions
  2009-08-13 22:14   ` [patch 02/14] remove clocksource inline functions john stultz
@ 2009-08-14  8:10     ` Martin Schwidefsky
  2009-08-14  8:17       ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Schwidefsky @ 2009-08-14  8:10 UTC (permalink / raw)
  To: john stultz; +Cc: linux-kernel, Ingo Molnar, Thomas Gleixner, Daniel Walker

On Thu, 13 Aug 2009 15:14:34 -0700
john stultz <johnstul@us.ibm.com> wrote:

> On Thu, 2009-08-13 at 17:40 +0200, Martin Schwidefsky wrote:
> > Index: linux-2.6/kernel/time/timekeeping.c
> > ===================================================================
> > --- linux-2.6.orig/kernel/time/timekeeping.c
> > +++ linux-2.6/kernel/time/timekeeping.c
> [snip]
> > @@ -477,8 +492,7 @@ static int timekeeping_resume(struct sys
> >  	}
> >  	update_xtime_cache(0);
> >  	/* re-base the last cycle value */
> > -	clock->cycle_last = 0;
> > -	clock->cycle_last = clocksource_read(clock);
> > +	clock->cycle_last = clock->read(clock);
> 
> Minor bug here, the clearing of cycle_last has a side-effect of making
> sure the TSC doesn't trip over its own cycle_last checking in the read()
> function. This is part of the uglyness of the TSC pulling this internal
> timeekping state to avoid minor inconsistencies, but until we find a
> better way, we have to live with it.
> 
> So you'll need to preserve the cycle_last = 0 line.

Whoa, now that is subtle. Good spotting. I would prefer to reset the 
cycle_last in a resume function though:

Index: linux-2.6/arch/x86/kernel/tsc.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/tsc.c
+++ linux-2.6/arch/x86/kernel/tsc.c
@@ -744,10 +744,16 @@ static cycle_t __vsyscall_fn vread_tsc(v
 }
 #endif

+static void resume_tsc(void)
+{
+       clocksource_tsc.cycle_last = 0;
+}
+
 static struct clocksource clocksource_tsc = {
        .name                   = "tsc",
        .rating                 = 300,
        .read                   = read_tsc,
+       .resume                 = resume_tsc,
        .mask                   = CLOCKSOURCE_MASK(64),
        .shift                  = 22,
        .flags                  = CLOCK_SOURCE_IS_CONTINUOUS |

That puts the subtlety where it belongs.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


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

* Re: [patch 02/14] remove clocksource inline functions
  2009-08-14  8:10     ` Martin Schwidefsky
@ 2009-08-14  8:17       ` Thomas Gleixner
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Gleixner @ 2009-08-14  8:17 UTC (permalink / raw)
  To: Martin Schwidefsky; +Cc: john stultz, linux-kernel, Ingo Molnar, Daniel Walker

On Fri, 14 Aug 2009, Martin Schwidefsky wrote:
> On Thu, 13 Aug 2009 15:14:34 -0700
> john stultz <johnstul@us.ibm.com> wrote:
> > So you'll need to preserve the cycle_last = 0 line.
> 
> Whoa, now that is subtle. Good spotting. I would prefer to reset the 
> cycle_last in a resume function though:
> 
> Index: linux-2.6/arch/x86/kernel/tsc.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/kernel/tsc.c
> +++ linux-2.6/arch/x86/kernel/tsc.c
> @@ -744,10 +744,16 @@ static cycle_t __vsyscall_fn vread_tsc(v
>  }
>  #endif
> 
> +static void resume_tsc(void)
> +{
> +       clocksource_tsc.cycle_last = 0;
> +}
> +
>  static struct clocksource clocksource_tsc = {
>         .name                   = "tsc",
>         .rating                 = 300,
>         .read                   = read_tsc,
> +       .resume                 = resume_tsc,
>         .mask                   = CLOCKSOURCE_MASK(64),
>         .shift                  = 22,
>         .flags                  = CLOCK_SOURCE_IS_CONTINUOUS |
> 
> That puts the subtlety where it belongs.

Ack.

	tglx

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

* Re: [patch 11/14] timekeeper read clock helper functions
  2009-08-13 23:30   ` [patch 11/14] timekeeper read clock helper functions john stultz
@ 2009-08-14 11:12     ` Martin Schwidefsky
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Schwidefsky @ 2009-08-14 11:12 UTC (permalink / raw)
  To: john stultz; +Cc: linux-kernel, Ingo Molnar, Thomas Gleixner, Daniel Walker

On Thu, 13 Aug 2009 16:30:18 -0700
john stultz <johnstul@us.ibm.com> wrote:

> On Thu, 2009-08-13 at 17:40 +0200, Martin Schwidefsky wrote:
> > Index: linux-2.6/kernel/time/timekeeping.c
> > ===================================================================
> > --- linux-2.6.orig/kernel/time/timekeeping.c
> > +++ linux-2.6/kernel/time/timekeeping.c
> > @@ -95,6 +95,40 @@ static void timekeeper_setup_internals(s
> >  	timekeeper.mult = clock->mult;
> >  }
> > 
> > +/* Timekeeper helper functions. */
> > +static inline s64 timekeeping_get_ns(void)
> > +{
> > +	cycle_t cycle_now, cycle_delta;
> > +	struct clocksource *clock;
> > +
> > +	/* read clocksource: */
> > +	clock = timekeeper.clock;
> > +	cycle_now = clock->read(clock);
> > +
> > +	/* calculate the delta since the last update_wall_time: */
> > +	cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
> > +
> > +	/* return delta convert to nanoseconds using ntp adjusted mult. */
> > +	return clocksource_cyc2ns(cycle_delta, timekeeper.mult,
> > +				  timekeeper.shift);
> > +}
> 
> Again, not a huge issue, but if we kept the read() out of this function
> and instead passed the cycle_now value in as a argument, we could also
> use this function in  timekeeping_forward_now()

I actually tested how the code would look like if I do that. Didn't like
the result. The thing is that timekeeping_get_ns is a helper that is
supposed to reduce the number of lines you need in the caller. If you
push clock->read(clock) call back into the caller it doesn't help much ..

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


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

end of thread, other threads:[~2009-08-14 11:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20090813154034.613706651@de.ibm.com>
     [not found] ` <20090813154159.634291990@de.ibm.com>
2009-08-13 22:14   ` [patch 02/14] remove clocksource inline functions john stultz
2009-08-14  8:10     ` Martin Schwidefsky
2009-08-14  8:17       ` Thomas Gleixner
     [not found] ` <20090813154201.810817188@de.ibm.com>
2009-08-13 23:30   ` [patch 11/14] timekeeper read clock helper functions john stultz
2009-08-14 11:12     ` Martin Schwidefsky
2009-08-14  0:28 ` [patch 00/14] clocksource / timekeeping rework V3 john stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox