timekeeping: Move reset of cycle_last for tsc clocksource to tsc
authorMartin Schwidefsky <schwidefsky@de.ibm.com>
Fri, 14 Aug 2009 13:47:20 +0000 (15:47 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Sat, 15 Aug 2009 08:55:45 +0000 (10:55 +0200)
change_clocksource resets the cycle_last value to zero then sets it to
a value read from the clocksource. The reset to zero is required only
for the TSC clocksource to make the read_tsc function work after a
resume. The reason is that the TSC read function uses cycle_last to
detect backwards going TSCs. In the resume case cycle_last contains
the TSC value from the last update before the suspend. On resume the
TSC starts counting from 0 again and would trip over the cycle_last
comparison.

This is subtle and surprising. Move the reset to a resume function in
the tsc code.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <johnstul@us.ibm.com>
Cc: Daniel Walker <dwalker@fifo99.com>
LKML-Reference: <20090814134808.142191175@de.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/x86/kernel/tsc.c
kernel/time/timekeeping.c

index 71f4368b357edf2a47fd035349bfbcd8c595e882..968425422c46185036f65fc818fdceb4df7311fe 100644 (file)
@@ -744,10 +744,16 @@ static cycle_t __vsyscall_fn vread_tsc(void)
 }
 #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 |
index 016a2591d7191ef62cd902b8a32ba90569bfc073..b5673016089f7d29fe1cb4768baab17f8e1f3eca 100644 (file)
@@ -295,7 +295,6 @@ static void change_clocksource(void)
        if (old->disable)
                old->disable(old);
 
-       clock->cycle_last = 0;
        clock->cycle_last = clock->read(clock);
        clock->error = 0;
        clock->xtime_nsec = 0;