[CPUFREQ] Cleanup locking in ondemand governor

Redesign the locking inside ondemand driver. Make dbs_mutex handle all the
global state changes inside the driver and invent a new percpu mutex
to serialize percpu timer and frequency limit change.

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Dave Jones <davej@redhat.com>
This commit is contained in:
venkatesh.pallipadi@intel.com 2009-07-02 17:08:32 -07:00 коммит произвёл Dave Jones
Родитель 37c90e8887
Коммит 5a75c82828
1 изменённых файлов: 27 добавлений и 35 удалений

Просмотреть файл

@ -70,8 +70,13 @@ struct cpu_dbs_info_s {
unsigned int freq_lo_jiffies; unsigned int freq_lo_jiffies;
unsigned int freq_hi_jiffies; unsigned int freq_hi_jiffies;
int cpu; int cpu;
unsigned int enable:1, unsigned int sample_type:1;
sample_type:1; /*
* percpu mutex that serializes governor limit change with
* do_dbs_timer invocation. We do not want do_dbs_timer to run
* when user is changing the governor or limits.
*/
struct mutex timer_mutex;
}; };
static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
@ -79,9 +84,7 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */
/* /*
* dbs_mutex protects data in dbs_tuners_ins from concurrent changes on * dbs_mutex protects data in dbs_tuners_ins from concurrent changes on
* different CPUs. It protects dbs_enable in governor start/stop. It also * different CPUs. It protects dbs_enable in governor start/stop.
* serializes governor limit_change with do_dbs_timer. We do not want
* do_dbs_timer to run when user is changing the governor or limits.
*/ */
static DEFINE_MUTEX(dbs_mutex); static DEFINE_MUTEX(dbs_mutex);
@ -187,13 +190,18 @@ static unsigned int powersave_bias_target(struct cpufreq_policy *policy,
return freq_hi; return freq_hi;
} }
static void ondemand_powersave_bias_init_cpu(int cpu)
{
struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, cpu);
dbs_info->freq_table = cpufreq_frequency_get_table(cpu);
dbs_info->freq_lo = 0;
}
static void ondemand_powersave_bias_init(void) static void ondemand_powersave_bias_init(void)
{ {
int i; int i;
for_each_online_cpu(i) { for_each_online_cpu(i) {
struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, i); ondemand_powersave_bias_init_cpu(i);
dbs_info->freq_table = cpufreq_frequency_get_table(i);
dbs_info->freq_lo = 0;
} }
} }
@ -235,12 +243,10 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
unsigned int input; unsigned int input;
int ret; int ret;
ret = sscanf(buf, "%u", &input); ret = sscanf(buf, "%u", &input);
if (ret != 1)
return -EINVAL;
mutex_lock(&dbs_mutex); mutex_lock(&dbs_mutex);
if (ret != 1) {
mutex_unlock(&dbs_mutex);
return -EINVAL;
}
dbs_tuners_ins.sampling_rate = max(input, min_sampling_rate); dbs_tuners_ins.sampling_rate = max(input, min_sampling_rate);
mutex_unlock(&dbs_mutex); mutex_unlock(&dbs_mutex);
@ -254,13 +260,12 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
int ret; int ret;
ret = sscanf(buf, "%u", &input); ret = sscanf(buf, "%u", &input);
mutex_lock(&dbs_mutex);
if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
input < MIN_FREQUENCY_UP_THRESHOLD) { input < MIN_FREQUENCY_UP_THRESHOLD) {
mutex_unlock(&dbs_mutex);
return -EINVAL; return -EINVAL;
} }
mutex_lock(&dbs_mutex);
dbs_tuners_ins.up_threshold = input; dbs_tuners_ins.up_threshold = input;
mutex_unlock(&dbs_mutex); mutex_unlock(&dbs_mutex);
@ -358,9 +363,6 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
struct cpufreq_policy *policy; struct cpufreq_policy *policy;
unsigned int j; unsigned int j;
if (!this_dbs_info->enable)
return;
this_dbs_info->freq_lo = 0; this_dbs_info->freq_lo = 0;
policy = this_dbs_info->cur_policy; policy = this_dbs_info->cur_policy;
@ -488,13 +490,7 @@ static void do_dbs_timer(struct work_struct *work)
int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
delay -= jiffies % delay; delay -= jiffies % delay;
mutex_lock(&dbs_info->timer_mutex);
mutex_lock(&dbs_mutex);
if (!dbs_info->enable) {
mutex_unlock(&dbs_mutex);
return;
}
/* Common NORMAL_SAMPLE setup */ /* Common NORMAL_SAMPLE setup */
dbs_info->sample_type = DBS_NORMAL_SAMPLE; dbs_info->sample_type = DBS_NORMAL_SAMPLE;
@ -511,7 +507,7 @@ static void do_dbs_timer(struct work_struct *work)
dbs_info->freq_lo, CPUFREQ_RELATION_H); dbs_info->freq_lo, CPUFREQ_RELATION_H);
} }
queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work, delay); queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work, delay);
mutex_unlock(&dbs_mutex); mutex_unlock(&dbs_info->timer_mutex);
} }
static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info) static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
@ -520,8 +516,6 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate); int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
delay -= jiffies % delay; delay -= jiffies % delay;
dbs_info->enable = 1;
ondemand_powersave_bias_init();
dbs_info->sample_type = DBS_NORMAL_SAMPLE; dbs_info->sample_type = DBS_NORMAL_SAMPLE;
INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer); INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work, queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work,
@ -530,7 +524,6 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
{ {
dbs_info->enable = 0;
cancel_delayed_work_sync(&dbs_info->work); cancel_delayed_work_sync(&dbs_info->work);
} }
@ -549,19 +542,15 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
if ((!cpu_online(cpu)) || (!policy->cur)) if ((!cpu_online(cpu)) || (!policy->cur))
return -EINVAL; return -EINVAL;
if (this_dbs_info->enable) /* Already enabled */
break;
mutex_lock(&dbs_mutex); mutex_lock(&dbs_mutex);
dbs_enable++;
rc = sysfs_create_group(&policy->kobj, &dbs_attr_group); rc = sysfs_create_group(&policy->kobj, &dbs_attr_group);
if (rc) { if (rc) {
dbs_enable--;
mutex_unlock(&dbs_mutex); mutex_unlock(&dbs_mutex);
return rc; return rc;
} }
dbs_enable++;
for_each_cpu(j, policy->cpus) { for_each_cpu(j, policy->cpus) {
struct cpu_dbs_info_s *j_dbs_info; struct cpu_dbs_info_s *j_dbs_info;
j_dbs_info = &per_cpu(cpu_dbs_info, j); j_dbs_info = &per_cpu(cpu_dbs_info, j);
@ -575,6 +564,8 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
} }
} }
this_dbs_info->cpu = cpu; this_dbs_info->cpu = cpu;
ondemand_powersave_bias_init_cpu(cpu);
mutex_init(&this_dbs_info->timer_mutex);
/* /*
* Start the timerschedule work, when this governor * Start the timerschedule work, when this governor
* is used for first time * is used for first time
@ -602,20 +593,21 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
mutex_lock(&dbs_mutex); mutex_lock(&dbs_mutex);
sysfs_remove_group(&policy->kobj, &dbs_attr_group); sysfs_remove_group(&policy->kobj, &dbs_attr_group);
mutex_destroy(&this_dbs_info->timer_mutex);
dbs_enable--; dbs_enable--;
mutex_unlock(&dbs_mutex); mutex_unlock(&dbs_mutex);
break; break;
case CPUFREQ_GOV_LIMITS: case CPUFREQ_GOV_LIMITS:
mutex_lock(&dbs_mutex); mutex_lock(&this_dbs_info->timer_mutex);
if (policy->max < this_dbs_info->cur_policy->cur) if (policy->max < this_dbs_info->cur_policy->cur)
__cpufreq_driver_target(this_dbs_info->cur_policy, __cpufreq_driver_target(this_dbs_info->cur_policy,
policy->max, CPUFREQ_RELATION_H); policy->max, CPUFREQ_RELATION_H);
else if (policy->min > this_dbs_info->cur_policy->cur) else if (policy->min > this_dbs_info->cur_policy->cur)
__cpufreq_driver_target(this_dbs_info->cur_policy, __cpufreq_driver_target(this_dbs_info->cur_policy,
policy->min, CPUFREQ_RELATION_L); policy->min, CPUFREQ_RELATION_L);
mutex_unlock(&dbs_mutex); mutex_unlock(&this_dbs_info->timer_mutex);
break; break;
} }
return 0; return 0;