Commit b38868aa authored by Mike Travis's avatar Mike Travis Committed by Ingo Molnar

NR_CPUS: Replace NR_CPUS in cpufreq userspace routines

  * Replace arrays sized by NR_CPUS with percpu variables.

    Prior reference: http://marc.info/?l=linux-kernel&m=120251421825989&w=4
    Subject:    [PATCH 1/4] cpufreq: change cpu freq tables to per_cpu variables
    From:       Mike Travis <travis () sgi ! com>
    Date:       2008-02-08 23:37:39
Signed-off-by: default avatarMike Travis <travis@sgi.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 94a1e869
...@@ -30,16 +30,18 @@ ...@@ -30,16 +30,18 @@
/** /**
* A few values needed by the userspace governor * A few values needed by the userspace governor
*/ */
static unsigned int cpu_max_freq[NR_CPUS]; static DEFINE_PER_CPU(unsigned int, cpu_max_freq);
static unsigned int cpu_min_freq[NR_CPUS]; static DEFINE_PER_CPU(unsigned int, cpu_min_freq);
static unsigned int cpu_cur_freq[NR_CPUS]; /* current CPU freq */ static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */
static unsigned int cpu_set_freq[NR_CPUS]; /* CPU freq desired by userspace */ static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by
static unsigned int cpu_is_managed[NR_CPUS]; userspace */
static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
static DEFINE_MUTEX (userspace_mutex); static DEFINE_MUTEX (userspace_mutex);
static int cpus_using_userspace_governor; static int cpus_using_userspace_governor;
#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) #define dprintk(msg...) \
cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg)
/* keep track of frequency transitions */ /* keep track of frequency transitions */
static int static int
...@@ -48,12 +50,12 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, ...@@ -48,12 +50,12 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
{ {
struct cpufreq_freqs *freq = data; struct cpufreq_freqs *freq = data;
if (!cpu_is_managed[freq->cpu]) if (!per_cpu(cpu_is_managed, freq->cpu))
return 0; return 0;
dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n",
freq->cpu, freq->new); freq->cpu, freq->new);
cpu_cur_freq[freq->cpu] = freq->new; per_cpu(cpu_cur_freq, freq->cpu) = freq->new;
return 0; return 0;
} }
...@@ -77,15 +79,15 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) ...@@ -77,15 +79,15 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
mutex_lock(&userspace_mutex); mutex_lock(&userspace_mutex);
if (!cpu_is_managed[policy->cpu]) if (!per_cpu(cpu_is_managed, policy->cpu))
goto err; goto err;
cpu_set_freq[policy->cpu] = freq; per_cpu(cpu_set_freq, policy->cpu) = freq;
if (freq < cpu_min_freq[policy->cpu]) if (freq < per_cpu(cpu_min_freq, policy->cpu))
freq = cpu_min_freq[policy->cpu]; freq = per_cpu(cpu_min_freq, policy->cpu);
if (freq > cpu_max_freq[policy->cpu]) if (freq > per_cpu(cpu_max_freq, policy->cpu))
freq = cpu_max_freq[policy->cpu]; freq = per_cpu(cpu_max_freq, policy->cpu);
/* /*
* We're safe from concurrent calls to ->target() here * We're safe from concurrent calls to ->target() here
...@@ -104,7 +106,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) ...@@ -104,7 +106,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
{ {
return sprintf(buf, "%u\n", cpu_cur_freq[policy->cpu]); return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu));
} }
static int cpufreq_governor_userspace(struct cpufreq_policy *policy, static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
...@@ -127,12 +129,17 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, ...@@ -127,12 +129,17 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
} }
cpus_using_userspace_governor++; cpus_using_userspace_governor++;
cpu_is_managed[cpu] = 1; per_cpu(cpu_is_managed, cpu) = 1;
cpu_min_freq[cpu] = policy->min; per_cpu(cpu_min_freq, cpu) = policy->min;
cpu_max_freq[cpu] = policy->max; per_cpu(cpu_max_freq, cpu) = policy->max;
cpu_cur_freq[cpu] = policy->cur; per_cpu(cpu_cur_freq, cpu) = policy->cur;
cpu_set_freq[cpu] = policy->cur; per_cpu(cpu_set_freq, cpu) = policy->cur;
dprintk("managing cpu %u started (%u - %u kHz, currently %u kHz)\n", cpu, cpu_min_freq[cpu], cpu_max_freq[cpu], cpu_cur_freq[cpu]); dprintk("managing cpu %u started "
"(%u - %u kHz, currently %u kHz)\n",
cpu,
per_cpu(cpu_min_freq, cpu),
per_cpu(cpu_max_freq, cpu),
per_cpu(cpu_cur_freq, cpu));
mutex_unlock(&userspace_mutex); mutex_unlock(&userspace_mutex);
break; break;
...@@ -145,34 +152,34 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, ...@@ -145,34 +152,34 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
CPUFREQ_TRANSITION_NOTIFIER); CPUFREQ_TRANSITION_NOTIFIER);
} }
cpu_is_managed[cpu] = 0; per_cpu(cpu_is_managed, cpu) = 0;
cpu_min_freq[cpu] = 0; per_cpu(cpu_min_freq, cpu) = 0;
cpu_max_freq[cpu] = 0; per_cpu(cpu_max_freq, cpu) = 0;
cpu_set_freq[cpu] = 0; per_cpu(cpu_set_freq, cpu) = 0;
dprintk("managing cpu %u stopped\n", cpu); dprintk("managing cpu %u stopped\n", cpu);
mutex_unlock(&userspace_mutex); mutex_unlock(&userspace_mutex);
break; break;
case CPUFREQ_GOV_LIMITS: case CPUFREQ_GOV_LIMITS:
mutex_lock(&userspace_mutex); mutex_lock(&userspace_mutex);
dprintk("limit event for cpu %u: %u - %u kHz," dprintk("limit event for cpu %u: %u - %u kHz, "
"currently %u kHz, last set to %u kHz\n", "currently %u kHz, last set to %u kHz\n",
cpu, policy->min, policy->max, cpu, policy->min, policy->max,
cpu_cur_freq[cpu], cpu_set_freq[cpu]); per_cpu(cpu_cur_freq, cpu),
if (policy->max < cpu_set_freq[cpu]) { per_cpu(cpu_set_freq, cpu));
if (policy->max < per_cpu(cpu_set_freq, cpu)) {
__cpufreq_driver_target(policy, policy->max, __cpufreq_driver_target(policy, policy->max,
CPUFREQ_RELATION_H); CPUFREQ_RELATION_H);
} } else if (policy->min > per_cpu(cpu_set_freq, cpu)) {
else if (policy->min > cpu_set_freq[cpu]) {
__cpufreq_driver_target(policy, policy->min, __cpufreq_driver_target(policy, policy->min,
CPUFREQ_RELATION_L); CPUFREQ_RELATION_L);
} } else {
else { __cpufreq_driver_target(policy,
__cpufreq_driver_target(policy, cpu_set_freq[cpu], per_cpu(cpu_set_freq, cpu),
CPUFREQ_RELATION_L); CPUFREQ_RELATION_L);
} }
cpu_min_freq[cpu] = policy->min; per_cpu(cpu_min_freq, cpu) = policy->min;
cpu_max_freq[cpu] = policy->max; per_cpu(cpu_max_freq, cpu) = policy->max;
cpu_cur_freq[cpu] = policy->cur; per_cpu(cpu_cur_freq, cpu) = policy->cur;
mutex_unlock(&userspace_mutex); mutex_unlock(&userspace_mutex);
break; break;
} }
......
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