ondemand governor use new cpufreq rwsem locking in work callback
PATCH 1/1 ondemand governor use new cpufreq rwsem locking in work callback
Eliminate flush_workqueue in cpufreq_governor(STOP) callpath. Using flush there has a deadlock potential as in
http://uwsg.iu.edu/hypermail/linux/kernel/0611.3/1223.html
Also, cleanup the locking issues with do_dbs_timer delayed_work callback. As it changes the CPU frequency using __cpufreq_target, it needs to have policy_rwsem in write mode, which also protects it from hot plug.
drivers/cpufreq/cpufreq_ondemand.c +16 -18
@@ -437,8 +437,14 @@ static void do_dbs_timer(struct work_str delay -= jiffies % delay; -if (!dbs_info->enable) +if (lock_policy_rwsem_write (cpu) <0 )return ; + +if (!dbs_info->enable) { +unlock_policy_rwsem_write (cpu); +return ; + } +/* Common NORMAL_SAMPLE setup */ dbs_info->sample_type =DBS_NORMAL_SAMPLE ; if (!dbs_tuners_ins.powersave_bias ||
@@ -455,6 +461,7 @@ static void do_dbs_timer(struct work_str CPUFREQ_RELATION_H); }queue_delayed_work_on (cpu, kondemand_wq, &dbs_info->work, delay); +unlock_policy_rwsem_write (cpu); }static inline void dbs_timer_init (struct cpu_dbs_info_s *dbs_info)
@@ -463,6 +470,7 @@ static inline void dbs_timer_init(structint delay =usecs_to_jiffies (dbs_tuners_ins.sampling_rate); delay -= jiffies % delay; + dbs_info->enable =1 ;ondemand_powersave_bias_init (); dbs_info->sample_type =DBS_NORMAL_SAMPLE ;INIT_DELAYED_WORK_NAR (&dbs_info->work, do_dbs_timer);
@@ -474,7 +482,6 @@ static inline void dbs_timer_exit(struct { dbs_info->enable =0 ;cancel_delayed_work (&dbs_info->work); -flush_workqueue (kondemand_wq); } static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
@@ -503,21 +510,9 @@ static int cpufreq_governor_dbs(struct cmutex_lock (&dbs_mutex); dbs_enable++; -if (dbs_enable ==1 ) { - kondemand_wq =create_workqueue ("kondemand" ); -if (!kondemand_wq) { -printk (KERN_ERR -"Creation of kondemand failed\n" ); - dbs_enable--; -mutex_unlock (&dbs_mutex); -return -ENOSPC ; - } - } rc =sysfs_create_group (&policy->kobj, &dbs_attr_group);if (rc) { -if (dbs_enable ==1 ) -destroy_workqueue (kondemand_wq); dbs_enable--;mutex_unlock (&dbs_mutex);return rc;
@@ -532,7 +527,6 @@ static int cpufreq_governor_dbs(struct c j_dbs_info->prev_cpu_wall =get_jiffies_64 (); } this_dbs_info->cpu = cpu; - this_dbs_info->enable =1 ;/* * Start the timerschedule work, when this governor * is used for first time
@@ -562,9 +556,6 @@ static int cpufreq_governor_dbs(struct cdbs_timer_exit (this_dbs_info);sysfs_remove_group (&policy->kobj, &dbs_attr_group); dbs_enable--; -if (dbs_enable ==0 ) -destroy_workqueue (kondemand_wq); -mutex_unlock (&dbs_mutex);break ;
@@ -593,12 +584,18 @@ static struct cpufreq_governor cpufreq_gstatic int __init cpufreq_gov_dbs_init (void ) { + kondemand_wq =create_workqueue ("kondemand" ); +if (!kondemand_wq) { +printk (KERN_ERR "Creation of kondemand failed\n" ); +return -EFAULT ; + }return cpufreq_register_governor (&cpufreq_gov_dbs); } static void __exit cpufreq_gov_dbs_exit(void) {cpufreq_unregister_governor (&cpufreq_gov_dbs); +destroy_workqueue (kondemand_wq); }
@@ -610,3 +607,4 @@ MODULE_LICENSE("GPL");module_init (cpufreq_gov_dbs_init);module_exit (cpufreq_gov_dbs_exit); +
Re: [PATCH] cpufreq lock rewrite bugfix - Fix locking in cpufreq_get
Incremental bugfix to previous 3 patch patchset of cpufreq lock rewrite.
There was one code path in cpufreq_get, that was using the write lock in place of read and also potential recursive lock with sysfs interface of cpuinfo_cur_freq.
drivers/cpufreq/cpufreq.c +28 -18
@@ -101,6 +101,7 @@ EXPORT_SYMBOL_GPL(unlock_policy_rwsem_wr/* internal prototypes */ static int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event); +static unsigned int __cpufreq_get (unsigned int cpu);static void handle_update (struct work_struct *work);/**
@@ -488,7 +489,7 @@ store_one(scaling_max_freq,max);static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy,char *buf) { -unsigned int cur_freq =cpufreq_get (policy->cpu); +unsigned int cur_freq =__cpufreq_get (policy->cpu);if (!cur_freq)return sprintf (buf,"<unknown>" );return sprintf (buf,"%u\n" , cur_freq);
@@ -1074,25 +1075,13 @@ unsigned int cpufreq_quick_get(unsignedEXPORT_SYMBOL (cpufreq_quick_get); -/** -* cpufreq_get - get the current CPU frequency (in kHz) -* @cpu: CPU number -* -* Get the CPU current (static) CPU frequency -*/ -unsigned int cpufreq_get (unsigned int cpu) +static unsigned int __cpufreq_get (unsigned int cpu) { -struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); +struct cpufreq_policy *policy = cpufreq_cpu_data[cpu];unsigned int ret_freq =0 ; -if (!policy) -return 0 ; -if (!cpufreq_driver->get) - goto out; - -if (unlikely (lock_policy_rwsem_write (cpu))) - goto out; +return (ret_freq); ret_freq = cpufreq_driver->get (cpu);
@@ -1106,11 +1095,32 @@ unsigned int cpufreq_get(unsigned int cp } } -unlock_policy_rwsem_write (cpu); +return (ret_freq); +} + +/** +* cpufreq_get - get the current CPU frequency (in kHz) +* @cpu: CPU number +* +* Get the CPU current (static) CPU frequency +*/ +unsigned int cpufreq_get (unsigned int cpu) +{ +unsigned int ret_freq =0 ; +struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); + +if (!policy) + goto out; + +if (unlikely (lock_policy_rwsem_read (cpu))) + goto out; + + ret_freq =__cpufreq_get (cpu); + +unlock_policy_rwsem_read (cpu); out:cpufreq_cpu_put (policy); -return (ret_freq); }EXPORT_SYMBOL (cpufreq_get);