Commit 6810b548 authored by Andi Kleen's avatar Andi Kleen Committed by Linus Torvalds

[PATCH] x86_64: Move ondemand timer into own work queue

Taking the cpu hotplug semaphore in a normal events workqueue
is unsafe because other tasks can wait for any workqueues with
it hold. This results in a deadlock.

Move the DBS timer into its own work queue which is not
affected by other work queue flushes to avoid this.

Has been acked by Venkatesh.

Cc: venkatesh.pallipadi@intel.com
Cc: cpufreq@lists.linux.org.uk
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ac71d12c
...@@ -74,6 +74,8 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */ ...@@ -74,6 +74,8 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */
static DEFINE_MUTEX (dbs_mutex); static DEFINE_MUTEX (dbs_mutex);
static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); static DECLARE_WORK (dbs_work, do_dbs_timer, NULL);
static struct workqueue_struct *dbs_workq;
struct dbs_tuners { struct dbs_tuners {
unsigned int sampling_rate; unsigned int sampling_rate;
unsigned int sampling_down_factor; unsigned int sampling_down_factor;
...@@ -364,7 +366,7 @@ static void do_dbs_timer(void *data) ...@@ -364,7 +366,7 @@ static void do_dbs_timer(void *data)
mutex_lock(&dbs_mutex); mutex_lock(&dbs_mutex);
for_each_online_cpu(i) for_each_online_cpu(i)
dbs_check_cpu(i); dbs_check_cpu(i);
schedule_delayed_work(&dbs_work, queue_delayed_work(dbs_workq, &dbs_work,
usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
mutex_unlock(&dbs_mutex); mutex_unlock(&dbs_mutex);
} }
...@@ -372,15 +374,21 @@ static void do_dbs_timer(void *data) ...@@ -372,15 +374,21 @@ static void do_dbs_timer(void *data)
static inline void dbs_timer_init(void) static inline void dbs_timer_init(void)
{ {
INIT_WORK(&dbs_work, do_dbs_timer, NULL); INIT_WORK(&dbs_work, do_dbs_timer, NULL);
schedule_delayed_work(&dbs_work, if (!dbs_workq)
dbs_workq = create_singlethread_workqueue("ondemand");
if (!dbs_workq) {
printk(KERN_ERR "ondemand: Cannot initialize kernel thread\n");
return;
}
queue_delayed_work(dbs_workq, &dbs_work,
usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
return; return;
} }
static inline void dbs_timer_exit(void) static inline void dbs_timer_exit(void)
{ {
cancel_delayed_work(&dbs_work); if (dbs_workq)
return; cancel_rearming_delayed_workqueue(dbs_workq, &dbs_work);
} }
static int cpufreq_governor_dbs(struct cpufreq_policy *policy, static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
...@@ -489,8 +497,12 @@ static int __init cpufreq_gov_dbs_init(void) ...@@ -489,8 +497,12 @@ static int __init cpufreq_gov_dbs_init(void)
static void __exit cpufreq_gov_dbs_exit(void) static void __exit cpufreq_gov_dbs_exit(void)
{ {
/* Make sure that the scheduled work is indeed not running */ /* Make sure that the scheduled work is indeed not running.
flush_scheduled_work(); Assumes the timer has been cancelled first. */
if (dbs_workq) {
flush_workqueue(dbs_workq);
destroy_workqueue(dbs_workq);
}
cpufreq_unregister_governor(&cpufreq_gov_dbs); cpufreq_unregister_governor(&cpufreq_gov_dbs);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment