cpufreq: 1/4 SMT awareness: save cpumask_t cpus
PATCH 1/1 cpufreq: 1/4 SMT awareness: save cpumask_t 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.
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c | 28 ++++--------- 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, 33 insertions(+), 49 deletions(-)
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c +9 -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 ); }
@@ -260,14 +252,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 +326,3 @@late_initcall (cpufreq_p4_init);module_exit (cpufreq_p4_exit); -
arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c +1 -1
@@ -564,7 +564,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
@@ -471,6 +471,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 */
[RFC][CFT] Re: [PATCH] cpufreq: SMT awareness
Actually, these are [RFC] and [CFT] first, as I can't test them myself.
Sorry,
Dominik
Hi Dominik,
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c line 261
Quoted 13 lines · Dominik Brodowski
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.arch/i386/kernel/cpu/cpufreq/p4-clockmod.c +2
-3cpus_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);
I was poking around here today to fix p4-clockmod with hotplug cpu, something like the following should do;
set_cpus_allowed(current, cpumask_of_cpu(cpu));preempt_disable();
if (smp_processor_id() != cpu) {
preempt_enable();
return;
}rdmsr(...);
preempt_enable();
But that aside (i'll send a patch for it and Cc you), does this patchset cover the case on SMT systems where one logical cpu is idle and the whole physical package gets throttled. We should only be programming both logical cpus when we're increasing the clock frequency and only one at a time on idle. Beat me if this is covered by your patch but i couldn't find where.
Thanks,
Zwane