Skip to content

Commit

Permalink
[CPUFREQ] Cleanup locking in conservative governor
Browse files Browse the repository at this point in the history
Redesign the locking inside conservative 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>
  • Loading branch information
venkatesh.pallipadi@intel.com authored and Dave Jones committed Jul 7, 2009
1 parent 5a75c82 commit ee88415
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions drivers/cpufreq/cpufreq_conservative.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ struct cpu_dbs_info_s {
unsigned int down_skip;
unsigned int requested_freq;
int cpu;
unsigned int enable: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 unsigned int dbs_enable; /* number of CPUs using this policy */

/*
* dbs_mutex protects data in dbs_tuners_ins from concurrent changes on
* different CPUs. It protects dbs_enable in governor start/stop. It also
* 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.
* different CPUs. It protects dbs_enable in governor start/stop.
*/
static DEFINE_MUTEX(dbs_mutex);

Expand Down Expand Up @@ -138,9 +141,6 @@ dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,

struct cpufreq_policy *policy;

if (!this_dbs_info->enable)
return 0;

policy = this_dbs_info->cur_policy;

/*
Expand Down Expand Up @@ -483,17 +483,12 @@ static void do_dbs_timer(struct work_struct *work)

delay -= jiffies % delay;

mutex_lock(&dbs_mutex);

if (!dbs_info->enable) {
mutex_unlock(&dbs_mutex);
return;
}
mutex_lock(&dbs_info->timer_mutex);

dbs_check_cpu(dbs_info);

queue_delayed_work_on(cpu, kconservative_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)
Expand All @@ -502,15 +497,13 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
delay -= jiffies % delay;

dbs_info->enable = 1;
INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
queue_delayed_work_on(dbs_info->cpu, kconservative_wq, &dbs_info->work,
delay);
}

static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
{
dbs_info->enable = 0;
cancel_delayed_work_sync(&dbs_info->work);
}

Expand All @@ -529,9 +522,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
if ((!cpu_online(cpu)) || (!policy->cur))
return -EINVAL;

if (this_dbs_info->enable) /* Already enabled */
break;

mutex_lock(&dbs_mutex);

rc = sysfs_create_group(&policy->kobj, &dbs_attr_group);
Expand All @@ -555,6 +545,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
this_dbs_info->down_skip = 0;
this_dbs_info->requested_freq = policy->cur;

mutex_init(&this_dbs_info->timer_mutex);
dbs_enable++;
/*
* Start the timerschedule work, when this governor
Expand Down Expand Up @@ -596,6 +587,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
mutex_lock(&dbs_mutex);
sysfs_remove_group(&policy->kobj, &dbs_attr_group);
dbs_enable--;
mutex_destroy(&this_dbs_info->timer_mutex);

/*
* Stop the timerschedule work, when this governor
Expand All @@ -611,7 +603,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
break;

case CPUFREQ_GOV_LIMITS:
mutex_lock(&dbs_mutex);
mutex_lock(&this_dbs_info->timer_mutex);
if (policy->max < this_dbs_info->cur_policy->cur)
__cpufreq_driver_target(
this_dbs_info->cur_policy,
Expand All @@ -620,7 +612,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
__cpufreq_driver_target(
this_dbs_info->cur_policy,
policy->min, CPUFREQ_RELATION_L);
mutex_unlock(&dbs_mutex);
mutex_unlock(&this_dbs_info->timer_mutex);

break;
}
Expand Down

0 comments on commit ee88415

Please sign in to comment.