Skip to contentSkip to conversation

(1/4) cpufreq SMT awareness: keep affected_cpu_mask

RFC PATCH New Dominik Brodowski 1 participant 1 message Jun 18, 2004 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 (1/4) cpufreq SMT awareness: keep affected_cpu_mask

The following four patches try to upgrade the SMT or CPU-group awareness of the cpufreq core. On all SMT platforms, and possibly on some MP systems, only the frequency of some or even all CPUs can be changed at the same time. So, only register one cpufreq (k)object in these cases. In /sys/devices/system/cpu/cpuX, either the subdirectory cpufreq is found, or a link -- named "cpufreq", of course -- to the appropriate subdirectory.

Neither the UP case nor the user interface should be affected by these changes. Unfortunately, because I only own UP hardware, I couldn't test these changes for the case where they matter most:
SMT and SMP.

Dominik

Save the "affected_cpu_map" used in SMT-aware drivers in struct cpufreq_policy->(cpumask_t) cpus

 arch/i386/kernel/cpu/cpufreq/p4-clockmod.c   |   27 +++++++++++++--------------
 arch/i386/kernel/cpu/cpufreq/speedstep-ich.c |   23 ++++++++---------------
 include/linux/cpufreq.h                      |    2 ++
 3 files changed, 23 insertions(+), 29 deletions(-)
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c +13 -14
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c linux/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
@@ -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,9 @@
 	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 +132,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 +145,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);
 	}
@@ -248,6 +241,12 @@
 	policy->cpuinfo.transition_latency = 1000000; /* assumed */
 	policy->cur = stock_freq;
 
+#ifdef CONFIG_SMP
+	policy->cpus = cpu_sibling_map[policy->cpu];
+#else
+	policy->cpus = cpumask_of_cpu(policy->cpu);
+#endif
+
 	return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]);
 }
 
@@ -267,7 +266,7 @@
         affected_cpu_map = cpumask_of_cpu(cpu);
 
 	set_cpus_allowed(current, affected_cpu_map);
-        BUG_ON(!cpu_isset(smp_processor_id(), affected_cpu_map));
+	BUG_ON(smp_processor_id() != cpu);
 
 	rdmsr(MSR_IA32_THERM_CONTROL, l, h);
 
arch/i386/kernel/cpu/cpufreq/speedstep-ich.c +8 -15
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/speedstep-ich.c linux/arch/i386/kernel/cpu/cpufreq/speedstep-ich.c
@@ -241,7 +241,7 @@
 {
 	unsigned int	newstate = 0;
 	struct cpufreq_freqs freqs;
-	cpumask_t cpus_allowed, affected_cpu_map;
+	cpumask_t cpus_allowed;
 	int i;
 
 	if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], target_freq, relation, &newstate))
@@ -257,27 +257,20 @@
 
 	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
-
-	for_each_cpu_mask(i, affected_cpu_map) {
+	for_each_cpu_mask(i, policy->cpus) {
 		freqs.cpu = i;
 		cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
 	}
 
 	/* switch to physical CPU where state is to be changed */
-	set_cpus_allowed(current, affected_cpu_map);
+	set_cpus_allowed(current, policy->cpus);
 
 	speedstep_set_state(newstate);
 
 	/* allow to be run on all CPUs */
 	set_cpus_allowed(current, cpus_allowed);
 
-	for_each_cpu_mask(i, affected_cpu_map) {
+	for_each_cpu_mask(i, policy->cpus) {
 		freqs.cpu = i;
 		cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
 	}
@@ -303,7 +296,7 @@
 {
 	int		result = 0;
 	unsigned int	speed;
-	cpumask_t       cpus_allowed,affected_cpu_map;
+	cpumask_t       cpus_allowed;
 
 
 	/* capability check */
@@ -313,11 +306,11 @@
 	/* only run on CPU to be set, or on its sibling */
 	cpus_allowed = current->cpus_allowed;
 #ifdef CONFIG_SMP
-	affected_cpu_map = cpu_sibling_map[policy->cpu];
+	policy->cpus = cpu_sibling_map[policy->cpu];
 #else
-	affected_cpu_map = cpumask_of_cpu(policy->cpu);
+	policy->cpus = cpumask_of_cpu(policy->cpu);
 #endif
-	set_cpus_allowed(current, affected_cpu_map);
+	set_cpus_allowed(current, policy->cpus);
 
 	/* detect low and high frequency */
 	result = speedstep_get_freqs(speedstep_processor,
include/linux/cpufreq.h +2 -0
diff -ruN linux-original/include/linux/cpufreq.h linux/include/linux/cpufreq.h
@@ -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,6 +70,7 @@
 };
 
 struct cpufreq_policy {
+	cpumask_t		cpus;	/* affected CPUs */
 	unsigned int		cpu;    /* cpu nr */
 	struct cpufreq_cpuinfo	cpuinfo;/* see above */