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

cpumask: Use optimized CPUMASK_ALLOC macros in the centrino_target

  * Use the CPUMASK_ALLOC macros in the centrino_target() function.
Signed-off-by: default avatarMike Travis <travis@sgi.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 77586c2b
...@@ -442,6 +442,13 @@ static int centrino_verify (struct cpufreq_policy *policy) ...@@ -442,6 +442,13 @@ static int centrino_verify (struct cpufreq_policy *policy)
* *
* Sets a new CPUFreq policy. * Sets a new CPUFreq policy.
*/ */
struct allmasks {
cpumask_t online_policy_cpus;
cpumask_t saved_mask;
cpumask_t set_mask;
cpumask_t covered_cpus;
};
static int centrino_target (struct cpufreq_policy *policy, static int centrino_target (struct cpufreq_policy *policy,
unsigned int target_freq, unsigned int target_freq,
unsigned int relation) unsigned int relation)
...@@ -449,48 +456,55 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -449,48 +456,55 @@ static int centrino_target (struct cpufreq_policy *policy,
unsigned int newstate = 0; unsigned int newstate = 0;
unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu; unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu;
struct cpufreq_freqs freqs; struct cpufreq_freqs freqs;
cpumask_t online_policy_cpus;
cpumask_t saved_mask;
cpumask_t set_mask;
cpumask_t covered_cpus;
int retval = 0; int retval = 0;
unsigned int j, k, first_cpu, tmp; unsigned int j, k, first_cpu, tmp;
CPUMASK_ALLOC(allmasks);
if (unlikely(centrino_model[cpu] == NULL)) CPUMASK_VAR(online_policy_cpus, allmasks);
return -ENODEV; CPUMASK_VAR(saved_mask, allmasks);
CPUMASK_VAR(set_mask, allmasks);
CPUMASK_VAR(covered_cpus, allmasks);
if (unlikely(allmasks == NULL))
return -ENOMEM;
if (unlikely(centrino_model[cpu] == NULL)) {
retval = -ENODEV;
goto out;
}
if (unlikely(cpufreq_frequency_table_target(policy, if (unlikely(cpufreq_frequency_table_target(policy,
centrino_model[cpu]->op_points, centrino_model[cpu]->op_points,
target_freq, target_freq,
relation, relation,
&newstate))) { &newstate))) {
return -EINVAL; retval = -EINVAL;
goto out;
} }
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
/* cpufreq holds the hotplug lock, so we are safe from here on */ /* cpufreq holds the hotplug lock, so we are safe from here on */
cpus_and(online_policy_cpus, cpu_online_map, policy->cpus); cpus_and(*online_policy_cpus, cpu_online_map, policy->cpus);
#else #else
online_policy_cpus = policy->cpus; *online_policy_cpus = policy->cpus;
#endif #endif
saved_mask = current->cpus_allowed; *saved_mask = current->cpus_allowed;
first_cpu = 1; first_cpu = 1;
cpus_clear(covered_cpus); cpus_clear(*covered_cpus);
for_each_cpu_mask_nr(j, online_policy_cpus) { for_each_cpu_mask_nr(j, *online_policy_cpus) {
/* /*
* Support for SMP systems. * Support for SMP systems.
* Make sure we are running on CPU that wants to change freq * Make sure we are running on CPU that wants to change freq
*/ */
cpus_clear(set_mask); cpus_clear(*set_mask);
if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
cpus_or(set_mask, set_mask, online_policy_cpus); cpus_or(*set_mask, *set_mask, *online_policy_cpus);
else else
cpu_set(j, set_mask); cpu_set(j, *set_mask);
set_cpus_allowed_ptr(current, &set_mask); set_cpus_allowed_ptr(current, set_mask);
preempt_disable(); preempt_disable();
if (unlikely(!cpu_isset(smp_processor_id(), set_mask))) { if (unlikely(!cpu_isset(smp_processor_id(), *set_mask))) {
dprintk("couldn't limit to CPUs in this domain\n"); dprintk("couldn't limit to CPUs in this domain\n");
retval = -EAGAIN; retval = -EAGAIN;
if (first_cpu) { if (first_cpu) {
...@@ -518,7 +532,7 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -518,7 +532,7 @@ static int centrino_target (struct cpufreq_policy *policy,
dprintk("target=%dkHz old=%d new=%d msr=%04x\n", dprintk("target=%dkHz old=%d new=%d msr=%04x\n",
target_freq, freqs.old, freqs.new, msr); target_freq, freqs.old, freqs.new, msr);
for_each_cpu_mask_nr(k, online_policy_cpus) { for_each_cpu_mask_nr(k, *online_policy_cpus) {
freqs.cpu = k; freqs.cpu = k;
cpufreq_notify_transition(&freqs, cpufreq_notify_transition(&freqs,
CPUFREQ_PRECHANGE); CPUFREQ_PRECHANGE);
...@@ -537,11 +551,11 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -537,11 +551,11 @@ static int centrino_target (struct cpufreq_policy *policy,
break; break;
} }
cpu_set(j, covered_cpus); cpu_set(j, *covered_cpus);
preempt_enable(); preempt_enable();
} }
for_each_cpu_mask_nr(k, online_policy_cpus) { for_each_cpu_mask_nr(k, *online_policy_cpus) {
freqs.cpu = k; freqs.cpu = k;
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
} }
...@@ -554,10 +568,10 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -554,10 +568,10 @@ static int centrino_target (struct cpufreq_policy *policy,
* Best effort undo.. * Best effort undo..
*/ */
if (!cpus_empty(covered_cpus)) { if (!cpus_empty(*covered_cpus)) {
cpumask_of_cpu_ptr_declare(new_mask); cpumask_of_cpu_ptr_declare(new_mask);
for_each_cpu_mask_nr(j, covered_cpus) { for_each_cpu_mask_nr(j, *covered_cpus) {
cpumask_of_cpu_ptr_next(new_mask, j); cpumask_of_cpu_ptr_next(new_mask, j);
set_cpus_allowed_ptr(current, new_mask); set_cpus_allowed_ptr(current, new_mask);
wrmsr(MSR_IA32_PERF_CTL, oldmsr, h); wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
...@@ -567,19 +581,22 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -567,19 +581,22 @@ static int centrino_target (struct cpufreq_policy *policy,
tmp = freqs.new; tmp = freqs.new;
freqs.new = freqs.old; freqs.new = freqs.old;
freqs.old = tmp; freqs.old = tmp;
for_each_cpu_mask_nr(j, online_policy_cpus) { for_each_cpu_mask_nr(j, *online_policy_cpus) {
freqs.cpu = j; freqs.cpu = j;
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
} }
} }
set_cpus_allowed_ptr(current, &saved_mask); set_cpus_allowed_ptr(current, saved_mask);
return 0; retval = 0;
goto out;
migrate_end: migrate_end:
preempt_enable(); preempt_enable();
set_cpus_allowed_ptr(current, &saved_mask); set_cpus_allowed_ptr(current, saved_mask);
return 0; out:
CPUMASK_FREE(allmasks);
return retval;
} }
static struct freq_attr* centrino_attr[] = { static struct freq_attr* centrino_attr[] = {
......
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