Skip to contentSkip to conversation

(3/5) speedstep-centrino: move to per-CPU analyzing of CPU data

PATCH New Dominik Brodowski 1 participant 1 message Mar 15, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (3/5) speedstep-centrino: move to per-CPU analyzing of CPU data

Move the table matching into an own function; only the FEATURE_EST bit for CPU 0 is checked in module_init() directly. As cpufreq drivers aren't sticky any longer (see other pending patch), this will not change user-visible behaviour.

 arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c |  106 ++++++++++++---------- 
 1 files changed, 60 insertions(+), 46 deletions(-)
arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c +60 -46
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c linux/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -187,6 +187,45 @@
 };
 #undef CPU
 
+static int centrino_cpu_init_table(struct cpufreq_policy *policy)
+{
+	struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
+	const struct cpu_model *model;
+
+	if (!cpu_has(cpu, X86_FEATURE_EST))
+		return -ENODEV;
+
+	/* Only Intel Pentium M stepping 5 for now - add new CPUs as
+	   they appear after making sure they use PERF_CTL in the same
+	   way. */
+	if (cpu->x86_vendor != X86_VENDOR_INTEL ||
+	    cpu->x86        != 6 ||
+	    cpu->x86_model  != 9 ||
+	    cpu->x86_mask   != 5) {
+		printk(KERN_INFO PFX "found unsupported CPU with Enhanced SpeedStep: "
+		       "send /proc/cpuinfo to " MAINTAINER "\n");
+		return -ENODEV;
+	}
+
+	for(model = models; model->model_name != NULL; model++)
+		if (strcmp(cpu->x86_model_id, model->model_name) == 0)
+			break;
+	if (model->model_name == NULL) {
+		printk(KERN_INFO PFX "no support for CPU model \"%s\": "
+		       "send /proc/cpuinfo to " MAINTAINER "\n",
+		       cpu->x86_model_id);
+		return -ENOENT;
+	}
+
+	centrino_model = model;
+		
+	printk(KERN_INFO PFX "found \"%s\": max frequency: %dkHz\n",
+	       model->model_name, model->max_freq);
+
+	return 0;
+}
+
+
 /* Extract clock in kHz from PERF_CTL value */
 static unsigned extract_clock(unsigned msr)
 {
@@ -206,10 +245,30 @@
 static int centrino_cpu_init(struct cpufreq_policy *policy)
 {
 	unsigned freq;
+	unsigned l, h;
 
-	if (policy->cpu != 0 || centrino_model == NULL)
+	if (policy->cpu != 0)
 		return -ENODEV;
 
+	if (centrino_cpu_init_table(policy))
+		return -ENODEV;
+
+	/* Check to see if Enhanced SpeedStep is enabled, and try to
+	   enable it if not. */
+	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+		
+	if (!(l & (1<<16))) {
+		l |= (1<<16);
+		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
+		
+		/* check to see if it stuck */
+		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+		if (!(l & (1<<16))) {
+			printk(KERN_INFO PFX "couldn't enable Enhanced SpeedStep\n");
+			return -ENODEV;
+		}
+	}
+
 	freq = get_cur_freq();
 
 	policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
@@ -322,55 +381,10 @@
 static int __init centrino_init(void)
 {
 	struct cpuinfo_x86 *cpu = cpu_data;
-	const struct cpu_model *model;
-	unsigned l, h;
 
 	if (!cpu_has(cpu, X86_FEATURE_EST))
 		return -ENODEV;
 
-	/* Only Intel Pentium M stepping 5 for now - add new CPUs as
-	   they appear after making sure they use PERF_CTL in the same
-	   way. */
-	if (cpu->x86_vendor != X86_VENDOR_INTEL ||
-	    cpu->x86        != 6 ||
-	    cpu->x86_model  != 9 ||
-	    cpu->x86_mask   != 5) {
-		printk(KERN_INFO PFX "found unsupported CPU with Enhanced SpeedStep: "
-		       "send /proc/cpuinfo to " MAINTAINER "\n");
-		return -ENODEV;
-	}
-
-	/* Check to see if Enhanced SpeedStep is enabled, and try to
-	   enable it if not. */
-	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		
-	if (!(l & (1<<16))) {
-		l |= (1<<16);
-		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
-		
-		/* check to see if it stuck */
-		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		if (!(l & (1<<16))) {
-			printk(KERN_INFO PFX "couldn't enable Enhanced SpeedStep\n");
-			return -ENODEV;
-		}
-	}
-
-	for(model = models; model->model_name != NULL; model++)
-		if (strcmp(cpu->x86_model_id, model->model_name) == 0)
-			break;
-	if (model->model_name == NULL) {
-		printk(KERN_INFO PFX "no support for CPU model \"%s\": "
-		       "send /proc/cpuinfo to " MAINTAINER "\n",
-		       cpu->x86_model_id);
-		return -ENOENT;
-	}
-
-	centrino_model = model;
-		
-	printk(KERN_INFO PFX "found \"%s\": max frequency: %dkHz\n",
-	       model->model_name, model->max_freq);
-
 	return cpufreq_register_driver(&centrino_driver);
 }