sched/clock, clocksource: Add optional cs::mark_unstable() method
authorThomas Gleixner <tglx@linutronix.de>
Thu, 15 Dec 2016 10:44:28 +0000 (11:44 +0100)
committerIngo Molnar <mingo@kernel.org>
Sat, 14 Jan 2017 10:29:43 +0000 (11:29 +0100)
PeterZ reported that we'd fail to mark the TSC unstable when the
clocksource watchdog finds it unsuitable.

Allow a clocksource to run a custom action when its being marked
unstable and hook up the TSC unstable code.

Reported-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/tsc.c
include/linux/clocksource.h
kernel/time/clocksource.c

index be3a49ee035650f1f1eac68c07ad0e8898c40585..c8174c815d831c109c097d0340ecd7caa67cf396 100644 (file)
@@ -1106,6 +1106,16 @@ static u64 read_tsc(struct clocksource *cs)
        return (u64)rdtsc_ordered();
 }
 
+static void tsc_cs_mark_unstable(struct clocksource *cs)
+{
+       if (tsc_unstable)
+               return;
+       tsc_unstable = 1;
+       clear_sched_clock_stable();
+       disable_sched_clock_irqtime();
+       pr_info("Marking TSC unstable due to clocksource watchdog\n");
+}
+
 /*
  * .mask MUST be CLOCKSOURCE_MASK(64). See comment above read_tsc()
  */
@@ -1118,6 +1128,7 @@ static struct clocksource clocksource_tsc = {
                                  CLOCK_SOURCE_MUST_VERIFY,
        .archdata               = { .vclock_mode = VCLOCK_TSC },
        .resume                 = tsc_resume,
+       .mark_unstable          = tsc_cs_mark_unstable,
 };
 
 void mark_tsc_unstable(char *reason)
index e315d04a2fd91ceb94948949d3affd8e12d25748..cfc75848a35d2c58ed85720fcd344fdc2c6f04ad 100644 (file)
@@ -62,6 +62,8 @@ struct module;
  * @archdata:          arch-specific data
  * @suspend:           suspend function for the clocksource, if necessary
  * @resume:            resume function for the clocksource, if necessary
+ * @mark_unstable:     Optional function to inform the clocksource driver that
+ *                     the watchdog marked the clocksource unstable
  * @owner:             module reference, must be set by clocksource in modules
  *
  * Note: This struct is not used in hotpathes of the timekeeping code
@@ -93,6 +95,7 @@ struct clocksource {
        unsigned long flags;
        void (*suspend)(struct clocksource *cs);
        void (*resume)(struct clocksource *cs);
+       void (*mark_unstable)(struct clocksource *cs);
 
        /* private: */
 #ifdef CONFIG_CLOCKSOURCE_WATCHDOG
index 665985b0a89afe88486fed0e2571771bdd4d94b5..93621ae718d391ac6a95cd561dfc22bd6dc15a18 100644 (file)
@@ -141,6 +141,10 @@ static void __clocksource_unstable(struct clocksource *cs)
 {
        cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG);
        cs->flags |= CLOCK_SOURCE_UNSTABLE;
+
+       if (cs->mark_unstable)
+               cs->mark_unstable(cs);
+
        if (finished_booting)
                schedule_work(&watchdog_work);
 }