From: Daniel Wagner Date: Tue, 17 Feb 2015 09:37:44 +0100 Subject: [PATCH 281/351] thermal: Defer thermal wakups to threads Origin: https://git.kernel.org/cgit/linux/kernel/git/rt/linux-stable-rt.git/commit?id=165114700f74a8d7040fcbe78d65d5fd1e8ca582 [ Upstream commit ad2408dc248fe58536eef5b2b5734d8f9d3a280b ] On RT the spin lock in pkg_temp_thermal_platfrom_thermal_notify will call schedule while we run in irq context. [] dump_stack+0x4e/0x8f [] __schedule_bug+0xa6/0xb4 [] __schedule+0x5b4/0x700 [] schedule+0x2a/0x90 [] rt_spin_lock_slowlock+0xe5/0x2d0 [] rt_spin_lock+0x25/0x30 [] pkg_temp_thermal_platform_thermal_notify+0x45/0x134 [x86_pkg_temp_thermal] [] ? therm_throt_process+0x1b/0x160 [] intel_thermal_interrupt+0x211/0x250 [] smp_thermal_interrupt+0x21/0x40 [] thermal_interrupt+0x6d/0x80 Let's defer the work to a kthread. Signed-off-by: Daniel Wagner Signed-off-by: Steven Rostedt (VMware) [bigeasy: reoder init/denit position. TODO: flush swork on exit] Signed-off-by: Sebastian Andrzej Siewior --- drivers/thermal/x86_pkg_temp_thermal.c | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c index 1ef937d799e4..82f21fd4afb0 100644 --- a/drivers/thermal/x86_pkg_temp_thermal.c +++ b/drivers/thermal/x86_pkg_temp_thermal.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -329,7 +330,7 @@ static void pkg_thermal_schedule_work(int cpu, struct delayed_work *work) schedule_delayed_work_on(cpu, work, ms); } -static int pkg_thermal_notify(u64 msr_val) +static void pkg_thermal_notify_work(struct kthread_work *work) { int cpu = smp_processor_id(); struct pkg_device *pkgdev; @@ -348,8 +349,32 @@ static int pkg_thermal_notify(u64 msr_val) } spin_unlock_irqrestore(&pkg_temp_lock, flags); +} + +#ifdef CONFIG_PREEMPT_RT_FULL +static DEFINE_KTHREAD_WORK(notify_work, pkg_thermal_notify_work); + +static int pkg_thermal_notify(u64 msr_val) +{ + kthread_schedule_work(¬ify_work); + return 0; +} + +static void pkg_thermal_notify_flush(void) +{ + kthread_flush_work(¬ify_work); +} + +#else /* !CONFIG_PREEMPT_RT_FULL */ + +static void pkg_thermal_notify_flush(void) { } + +static int pkg_thermal_notify(u64 msr_val) +{ + pkg_thermal_notify_work(NULL); return 0; } +#endif /* CONFIG_PREEMPT_RT_FULL */ static int pkg_temp_thermal_device_add(unsigned int cpu) { @@ -548,6 +573,7 @@ static void __exit pkg_temp_thermal_exit(void) platform_thermal_package_rate_control = NULL; cpuhp_remove_state(pkg_thermal_hp_state); + pkg_thermal_notify_flush(); debugfs_remove_recursive(debugfs); kfree(packages); }