x86/hpet: Convert to hotplug state machine

Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20160713153335.279718463@linutronix.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Sebastian Andrzej Siewior 2016-07-13 17:16:30 +00:00 committed by Ingo Molnar
parent 7ee681b252
commit 48d7f6c715
2 changed files with 36 additions and 35 deletions

View File

@ -710,31 +710,29 @@ static void hpet_work(struct work_struct *w)
complete(&hpet_work->complete); complete(&hpet_work->complete);
} }
static int hpet_cpuhp_notify(struct notifier_block *n, static int hpet_cpuhp_online(unsigned int cpu)
unsigned long action, void *hcpu)
{ {
unsigned long cpu = (unsigned long)hcpu;
struct hpet_work_struct work; struct hpet_work_struct work;
INIT_DELAYED_WORK_ONSTACK(&work.work, hpet_work);
init_completion(&work.complete);
/* FIXME: add schedule_work_on() */
schedule_delayed_work_on(cpu, &work.work, 0);
wait_for_completion(&work.complete);
destroy_delayed_work_on_stack(&work.work);
return 0;
}
static int hpet_cpuhp_dead(unsigned int cpu)
{
struct hpet_dev *hdev = per_cpu(cpu_hpet_dev, cpu); struct hpet_dev *hdev = per_cpu(cpu_hpet_dev, cpu);
switch (action & ~CPU_TASKS_FROZEN) { if (!hdev)
case CPU_ONLINE: return 0;
INIT_DELAYED_WORK_ONSTACK(&work.work, hpet_work); free_irq(hdev->irq, hdev);
init_completion(&work.complete); hdev->flags &= ~HPET_DEV_USED;
/* FIXME: add schedule_work_on() */ per_cpu(cpu_hpet_dev, cpu) = NULL;
schedule_delayed_work_on(cpu, &work.work, 0); return 0;
wait_for_completion(&work.complete);
destroy_delayed_work_on_stack(&work.work);
break;
case CPU_DEAD:
if (hdev) {
free_irq(hdev->irq, hdev);
hdev->flags &= ~HPET_DEV_USED;
per_cpu(cpu_hpet_dev, cpu) = NULL;
}
break;
}
return NOTIFY_OK;
} }
#else #else
@ -750,11 +748,8 @@ static void hpet_reserve_msi_timers(struct hpet_data *hd)
} }
#endif #endif
static int hpet_cpuhp_notify(struct notifier_block *n, #define hpet_cpuhp_online NULL
unsigned long action, void *hcpu) #define hpet_cpuhp_dead NULL
{
return NOTIFY_OK;
}
#endif #endif
@ -931,7 +926,7 @@ int __init hpet_enable(void)
*/ */
static __init int hpet_late_init(void) static __init int hpet_late_init(void)
{ {
int cpu; int ret;
if (boot_hpet_disable) if (boot_hpet_disable)
return -ENODEV; return -ENODEV;
@ -961,16 +956,20 @@ static __init int hpet_late_init(void)
if (boot_cpu_has(X86_FEATURE_ARAT)) if (boot_cpu_has(X86_FEATURE_ARAT))
return 0; return 0;
cpu_notifier_register_begin();
for_each_online_cpu(cpu) {
hpet_cpuhp_notify(NULL, CPU_ONLINE, (void *)(long)cpu);
}
/* This notifier should be called after workqueue is ready */ /* This notifier should be called after workqueue is ready */
__hotcpu_notifier(hpet_cpuhp_notify, -20); ret = cpuhp_setup_state(CPUHP_AP_X86_HPET_ONLINE, "AP_X86_HPET_ONLINE",
cpu_notifier_register_done(); hpet_cpuhp_online, NULL);
if (ret)
return ret;
ret = cpuhp_setup_state(CPUHP_X86_HPET_DEAD, "X86_HPET_DEAD", NULL,
hpet_cpuhp_dead);
if (ret)
goto err_cpuhp;
return 0; return 0;
err_cpuhp:
cpuhp_remove_state(CPUHP_AP_X86_HPET_ONLINE);
return ret;
} }
fs_initcall(hpet_late_init); fs_initcall(hpet_late_init);

View File

@ -12,6 +12,7 @@ enum cpuhp_state {
CPUHP_PERF_BFIN, CPUHP_PERF_BFIN,
CPUHP_PERF_POWER, CPUHP_PERF_POWER,
CPUHP_PERF_SUPERH, CPUHP_PERF_SUPERH,
CPUHP_X86_HPET_DEAD,
CPUHP_WORKQUEUE_PREP, CPUHP_WORKQUEUE_PREP,
CPUHP_NOTIFY_PREPARE, CPUHP_NOTIFY_PREPARE,
CPUHP_BRINGUP_CPU, CPUHP_BRINGUP_CPU,
@ -54,6 +55,7 @@ enum cpuhp_state {
CPUHP_AP_NOTIFY_ONLINE, CPUHP_AP_NOTIFY_ONLINE,
CPUHP_AP_ONLINE_DYN, CPUHP_AP_ONLINE_DYN,
CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 30, CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 30,
CPUHP_AP_X86_HPET_ONLINE,
CPUHP_AP_ACTIVE, CPUHP_AP_ACTIVE,
CPUHP_ONLINE, CPUHP_ONLINE,
}; };