mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
clocksource: Resolve cpu hotplug dead lock with TSC unstable
Martin Schwidefsky analyzed it: To register a clocksource the clocksource_mutex is acquired and if necessary timekeeping_notify is called to install the clocksource as the timekeeper clock. timekeeping_notify uses stop_machine which needs to take cpu_add_remove_lock mutex. Starting a new cpu is done with the cpu_add_remove_lock mutex held. native_cpu_up checks the tsc of the new cpu and if the tsc is no good clocksource_change_rating is called. Which needs the clocksource_mutex and the deadlock is complete. The solution is to replace the TSC via the clocksource watchdog mechanism. Mark the TSC as unstable and schedule the watchdog work so it gets removed in the watchdog thread context. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> LKML-Reference: <new-submission> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: John Stultz <johnstul@us.ibm.com>
This commit is contained in:
parent
90cba64a5f
commit
7285dd7fd3
3 changed files with 36 additions and 6 deletions
|
@ -767,12 +767,14 @@ void mark_tsc_unstable(char *reason)
|
||||||
{
|
{
|
||||||
if (!tsc_unstable) {
|
if (!tsc_unstable) {
|
||||||
tsc_unstable = 1;
|
tsc_unstable = 1;
|
||||||
printk("Marking TSC unstable due to %s\n", reason);
|
printk(KERN_INFO "Marking TSC unstable due to %s\n", reason);
|
||||||
/* Change only the rating, when not registered */
|
/* Change only the rating, when not registered */
|
||||||
if (clocksource_tsc.mult)
|
if (clocksource_tsc.mult)
|
||||||
clocksource_change_rating(&clocksource_tsc, 0);
|
clocksource_mark_unstable(&clocksource_tsc);
|
||||||
else
|
else {
|
||||||
|
clocksource_tsc.flags |= CLOCK_SOURCE_UNSTABLE;
|
||||||
clocksource_tsc.rating = 0;
|
clocksource_tsc.rating = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,6 +277,7 @@ extern struct clocksource* clocksource_get_next(void);
|
||||||
extern void clocksource_change_rating(struct clocksource *cs, int rating);
|
extern void clocksource_change_rating(struct clocksource *cs, int rating);
|
||||||
extern void clocksource_resume(void);
|
extern void clocksource_resume(void);
|
||||||
extern struct clocksource * __init __weak clocksource_default_clock(void);
|
extern struct clocksource * __init __weak clocksource_default_clock(void);
|
||||||
|
extern void clocksource_mark_unstable(struct clocksource *cs);
|
||||||
|
|
||||||
#ifdef CONFIG_GENERIC_TIME_VSYSCALL
|
#ifdef CONFIG_GENERIC_TIME_VSYSCALL
|
||||||
extern void update_vsyscall(struct timespec *ts, struct clocksource *c);
|
extern void update_vsyscall(struct timespec *ts, struct clocksource *c);
|
||||||
|
|
|
@ -149,13 +149,40 @@ static void clocksource_watchdog_work(struct work_struct *work)
|
||||||
kthread_run(clocksource_watchdog_kthread, NULL, "kwatchdog");
|
kthread_run(clocksource_watchdog_kthread, NULL, "kwatchdog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __clocksource_unstable(struct clocksource *cs)
|
||||||
|
{
|
||||||
|
cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG);
|
||||||
|
cs->flags |= CLOCK_SOURCE_UNSTABLE;
|
||||||
|
schedule_work(&watchdog_work);
|
||||||
|
}
|
||||||
|
|
||||||
static void clocksource_unstable(struct clocksource *cs, int64_t delta)
|
static void clocksource_unstable(struct clocksource *cs, int64_t delta)
|
||||||
{
|
{
|
||||||
printk(KERN_WARNING "Clocksource %s unstable (delta = %Ld ns)\n",
|
printk(KERN_WARNING "Clocksource %s unstable (delta = %Ld ns)\n",
|
||||||
cs->name, delta);
|
cs->name, delta);
|
||||||
cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG);
|
__clocksource_unstable(cs);
|
||||||
cs->flags |= CLOCK_SOURCE_UNSTABLE;
|
}
|
||||||
schedule_work(&watchdog_work);
|
|
||||||
|
/**
|
||||||
|
* clocksource_mark_unstable - mark clocksource unstable via watchdog
|
||||||
|
* @cs: clocksource to be marked unstable
|
||||||
|
*
|
||||||
|
* This function is called instead of clocksource_change_rating from
|
||||||
|
* cpu hotplug code to avoid a deadlock between the clocksource mutex
|
||||||
|
* and the cpu hotplug mutex. It defers the update of the clocksource
|
||||||
|
* to the watchdog thread.
|
||||||
|
*/
|
||||||
|
void clocksource_mark_unstable(struct clocksource *cs)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&watchdog_lock, flags);
|
||||||
|
if (!(cs->flags & CLOCK_SOURCE_UNSTABLE)) {
|
||||||
|
if (list_empty(&cs->wd_list))
|
||||||
|
list_add(&cs->wd_list, &watchdog_list);
|
||||||
|
__clocksource_unstable(cs);
|
||||||
|
}
|
||||||
|
spin_unlock_irqrestore(&watchdog_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clocksource_watchdog(unsigned long data)
|
static void clocksource_watchdog(unsigned long data)
|
||||||
|
|
Loading…
Reference in a new issue