Skip to content

Commit 12907fb

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
sched/clock, clocksource: Add optional cs::mark_unstable() method
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>
1 parent cb42c9a commit 12907fb

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

arch/x86/kernel/tsc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,16 @@ static u64 read_tsc(struct clocksource *cs)
11061106
return (u64)rdtsc_ordered();
11071107
}
11081108

1109+
static void tsc_cs_mark_unstable(struct clocksource *cs)
1110+
{
1111+
if (tsc_unstable)
1112+
return;
1113+
tsc_unstable = 1;
1114+
clear_sched_clock_stable();
1115+
disable_sched_clock_irqtime();
1116+
pr_info("Marking TSC unstable due to clocksource watchdog\n");
1117+
}
1118+
11091119
/*
11101120
* .mask MUST be CLOCKSOURCE_MASK(64). See comment above read_tsc()
11111121
*/
@@ -1118,6 +1128,7 @@ static struct clocksource clocksource_tsc = {
11181128
CLOCK_SOURCE_MUST_VERIFY,
11191129
.archdata = { .vclock_mode = VCLOCK_TSC },
11201130
.resume = tsc_resume,
1131+
.mark_unstable = tsc_cs_mark_unstable,
11211132
};
11221133

11231134
void mark_tsc_unstable(char *reason)

include/linux/clocksource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct module;
6262
* @archdata: arch-specific data
6363
* @suspend: suspend function for the clocksource, if necessary
6464
* @resume: resume function for the clocksource, if necessary
65+
* @mark_unstable: Optional function to inform the clocksource driver that
66+
* the watchdog marked the clocksource unstable
6567
* @owner: module reference, must be set by clocksource in modules
6668
*
6769
* Note: This struct is not used in hotpathes of the timekeeping code
@@ -93,6 +95,7 @@ struct clocksource {
9395
unsigned long flags;
9496
void (*suspend)(struct clocksource *cs);
9597
void (*resume)(struct clocksource *cs);
98+
void (*mark_unstable)(struct clocksource *cs);
9699

97100
/* private: */
98101
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG

kernel/time/clocksource.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ static void __clocksource_unstable(struct clocksource *cs)
141141
{
142142
cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG);
143143
cs->flags |= CLOCK_SOURCE_UNSTABLE;
144+
145+
if (cs->mark_unstable)
146+
cs->mark_unstable(cs);
147+
144148
if (finished_booting)
145149
schedule_work(&watchdog_work);
146150
}

0 commit comments

Comments
 (0)