cpufreq "cpu group" awareness: add policy->cpus
PATCH 1/4 cpufreq "cpu group" awareness: add policy->cpus
Save the "affected_cpu_map" used in SMT-aware drivers in struct cpufreq_policy->(cpumask_t) cpus, and use it wherever possible. In most cases, the ->get() function is only allowed to run on one CPU [the one passed as argument] to keep code simpler, and as that code path isn't executed often, and only root can do it anyway.
Signed-off-by Dominik Brodowski <[email protected]>
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c | 32 ++++++--------- arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c | 2 arch/i386/kernel/cpu/cpufreq/speedstep-ich.c | 46 ++++++++-------------- drivers/cpufreq/cpufreq.c | 2 include/linux/cpufreq.h | 4 + 5 files changed, 37 insertions(+), 49 deletions(-)
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c +13 -19
@@ -110,7 +110,7 @@ {unsigned int newstate =DC_RESV ;struct cpufreq_freqs freqs; -cpumask_t cpus_allowed, affected_cpu_map; +cpumask_t cpus_allowed;int i;if (cpufreq_frequency_table_target (policy, &p4clockmod_table[0 ], target_freq, relation, &newstate))
@@ -122,18 +122,8 @@if (freqs.new == freqs.old)return 0 ; -/* switch to physical CPU where state is to be changed*/ - cpus_allowed = current->cpus_allowed; - -/* only run on CPU to be set, or on its sibling */ -#ifdef CONFIG_SMP - affected_cpu_map = cpu_sibling_map[policy->cpu]; -#else - affected_cpu_map =cpumask_of_cpu (policy->cpu); -#endif -/* notifiers */ -for_each_cpu_mask (i, affected_cpu_map) { +for_each_cpu_mask (i, policy->cpus) { freqs.cpu = i;cpufreq_notify_transition (&freqs,CPUFREQ_PRECHANGE ); }
@@ -141,7 +131,9 @@/* run on each logical CPU, see section 13.15.3 of IA32 Intel Architecture Software * Developer's Manual, Volume 3 */ -for_each_cpu_mask (i, affected_cpu_map) { + cpus_allowed = current->cpus_allowed; + +for_each_cpu_mask (i, policy->cpus) {cpumask_t this_cpu =cpumask_of_cpu (i);set_cpus_allowed (current, this_cpu);
@@ -152,7 +144,7 @@set_cpus_allowed (current, cpus_allowed);/* notifiers */ -for_each_cpu_mask (i, affected_cpu_map) { +for_each_cpu_mask (i, policy->cpus) { freqs.cpu = i;cpufreq_notify_transition (&freqs,CPUFREQ_POSTCHANGE ); }
@@ -219,6 +211,10 @@int cpuid =0 ;unsigned int i; +#ifdef CONFIG_SMP + policy->cpus = cpu_sibling_map[policy->cpu]; +#endif +/* Errata workaround */ cpuid = (c->x86 <<8 ) | (c->x86_model <<4 ) | c->x86_mask;switch (cpuid) {
@@ -260,14 +256,13 @@static unsigned int cpufreq_p4_get (unsigned int cpu) { -cpumask_t cpus_allowed, affected_cpu_map; +cpumask_t cpus_allowed;u32 l, h; cpus_allowed = current->cpus_allowed; - affected_cpu_map =cpumask_of_cpu (cpu); -set_cpus_allowed (current, affected_cpu_map); -BUG_ON (!cpu_isset (smp_processor_id (), affected_cpu_map)); +set_cpus_allowed (current,cpumask_of_cpu (cpu)); +BUG_ON (smp_processor_id () != cpu);rdmsr (MSR_IA32_THERM_CONTROL , l, h);
@@ -335,4 +330,3 @@late_initcall (cpufreq_p4_init);module_exit (cpufreq_p4_exit); -
arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c +1 -1
@@ -569,7 +569,7 @@* Make sure we are running on the CPU that wants to change frequency */ saved_mask = current->cpus_allowed; -set_cpus_allowed (current,cpumask_of_cpu (policy->cpu)); +set_cpus_allowed (current, policy->cpus);if (smp_processor_id () != policy->cpu) {return (-EAGAIN ); }
arch/i386/kernel/cpu/cpufreq/speedstep-ich.c +18 -28
107 lines not on this page · raw message
drivers/cpufreq/cpufreq.c +2 -0
@@ -468,6 +468,8 @@memset (policy,0 ,sizeof (struct cpufreq_policy )); policy->cpu = cpu; + policy->cpus =cpumask_of_cpu (cpu); +init_MUTEX_LOCKED (&policy->lock);init_completion (&policy->kobj_unregister);INIT_WORK (&policy->update, handle_update, (void *)(long )cpu);
include/linux/cpufreq.h +3 -1
@@ -22,6 +22,7 @@#include <linux/sysfs.h> #include <linux/completion.h> #include <linux/workqueue.h> +#include <linux/cpumask.h> #define CPUFREQ_NAME_LEN 16
@@ -69,7 +70,8 @@ };struct cpufreq_policy { -unsigned int cpu;/* cpu nr */ +cpumask_t cpus;/* affected CPUs */ +unsigned int cpu;/* cpu nr of registered CPU */ struct cpufreq_cpuinfo cpuinfo;/* see above */ unsigned int min;/* in kHz */