Skip to contentSkip to conversation

remove special-handling of longrun

RFC New Dominik Brodowski 1 participant 1 message Nov 4, 2003 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

RFC 1/1 remove special-handling of longrun

[Note: this is definitely nothing for 2.6.0-testX]

- Remove the current ->setpolicy implementation.
- A cpufreq driver should be able to define a

	->target function if the CPU can be set to a specific operating frequency,

or a ->range function if the CPU can be set to an area of operating
frequencies, where the CPU decides on its own which one to chose.
- Also "->target" CPUfreq implementations may be able to provide a generic "economy" / "performance" / "burst" / ... mode, and such setting is best done as an extra sysfs parameter. So, move the longrun operating mode setting to such an extra sysfs file.

Dominik

arch/i386/kernel/cpu/cpufreq/longrun.c +60 -29
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/longrun.c linux/arch/i386/kernel/cpu/cpufreq/longrun.c
@@ -16,8 +16,6 @@
 #include <asm/processor.h>
 #include <asm/timex.h>
 
-static struct cpufreq_driver	longrun_driver;
-
 /**
  * longrun_{low,high}_freq is needed for the conversion of cpufreq kHz 
  * values into per cent values. In TMTA microcode, the following is valid:
@@ -30,19 +28,12 @@
  * longrun_get_policy - get the current LongRun policy
  * @policy: struct cpufreq_policy where current policy is written into
  *
- * Reads the current LongRun policy by access to MSR_TMTA_LONGRUN_FLAGS
- * and MSR_TMTA_LONGRUN_CTRL
+ * Reads the current LongRun policy by access to MSR_TMTA_LONGRUN_CTRL
  */
 static void longrun_get_policy(struct cpufreq_policy *policy)
 {
 	u32 msr_lo, msr_hi;
 
-	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-	if (msr_lo & 0x01)
-		policy->policy = CPUFREQ_POLICY_PERFORMANCE;
-	else
-		policy->policy = CPUFREQ_POLICY_POWERSAVE;
-	
 	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
 	msr_lo &= 0x0000007F;
 	msr_hi &= 0x0000007F;
@@ -80,18 +71,6 @@
 	if (pctg_lo > pctg_hi)
 		pctg_lo = pctg_hi;
 
-	/* performance or economy mode */
-	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-	msr_lo &= 0xFFFFFFFE;
-	switch (policy->policy) {
-	case CPUFREQ_POLICY_PERFORMANCE:
-		msr_lo |= 0x00000001;
-		break;
-	case CPUFREQ_POLICY_POWERSAVE:
-		break;
-	}
-	wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-
 	/* lower and upper boundary */
 	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
 	msr_lo &= 0xFFFFFF80;
@@ -112,18 +91,13 @@
  */
 static int longrun_verify_policy(struct cpufreq_policy *policy)
 {
-	if (!policy)
+	if (!policy || !(policy->cpu != 0))
 		return -EINVAL;
 
-	policy->cpu = 0;
 	cpufreq_verify_within_limits(policy, 
 		policy->cpuinfo.min_freq, 
 		policy->cpuinfo.max_freq);
 
-	if ((policy->policy != CPUFREQ_POLICY_POWERSAVE) &&
-	    (policy->policy != CPUFREQ_POLICY_PERFORMANCE))
-		return -EINVAL;
-
 	return 0;
 }
 
@@ -243,12 +217,69 @@
 }
 
 
+/*
+ * The TMTA CPU can be put into two modes: economy mode or
+ * performance mode.
+ */
+
+static ssize_t show_longrun_mode (struct cpufreq_policy *policy, char *buf)
+{
+
+	u32 msr_lo, msr_hi;
+
+	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
+	if (msr_lo & 0x01)
+		return sprintf(buf, "performance\n");
+	else
+		return sprintf(buf, "economy\n");
+}
+
+static ssize_t store_longrun_mode (struct cpufreq_policy * policy, 
+				   const char *buf, size_t count) 
+{
+	u32 mode = 0xFF;
+	u32 msr_lo, msr_hi;
+
+	if (count < 7)
+		return -EINVAL;
+
+	if (!strnicmp(buf,"performance",7))
+		mode = 0x01;
+	if (!strnicmp(buf,"economy",7))
+		mode = 0x00;
+
+	if (mode == 0xFF)
+		return -EINVAL;
+
+	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
+
+	msr_lo &= 0xFFFFFFFE;
+	msr_lo |= mode;
+
+	wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
+
+	return count;
+}
+
+
+struct freq_attr longrun_mode_attr = {
+	.attr = { .name = "lognrun_mode", .mode = 0644 },
+	.show = show_longrun_mode,
+	.store = store_longrun_mode,
+};
+
+static struct freq_attr* longrun_attr[] = {
+	&longrun_mode_attr,
+	NULL,
+};
+
 static struct cpufreq_driver longrun_driver = {
 	.verify 	= longrun_verify_policy,
-	.setpolicy 	= longrun_set_policy,
+	.range		= longrun_set_policy,
 	.init		= longrun_cpu_init,
 	.name		= "longrun",
 	.owner		= THIS_MODULE,
+	.attr		= longrun_attr,
 };
 
 
drivers/cpufreq/cpufreq.c +28 -44

145 lines not on this page · raw message

drivers/cpufreq/proc_intf.c +2 -15
diff -ruN linux-original/drivers/cpufreq/proc_intf.c linux/drivers/cpufreq/proc_intf.c
@@ -39,7 +39,6 @@
 
 	policy->min = 0;
 	policy->max = 0;
-	policy->policy = 0;
 	policy->cpu = CPUFREQ_ALL_CPUS;
 
 	if (sscanf(input_string, "%d:%d:%d:%15s", &cpu, &min, &max, str_governor) == 4) 
@@ -82,7 +81,7 @@
 	return -EINVAL;
 
 scan_policy:
-	result = cpufreq_parse_governor(str_governor, &policy->policy, &policy->governor);
+	result = cpufreq_parse_governor(str_governor, &policy->governor);
 
 	return result;
 }
@@ -126,19 +125,7 @@
 
 		p += sprintf(p, "CPU%3d    %9d kHz (%3d %%)  -  %9d kHz (%3d %%)  -  ",
 			     i , policy.min, min_pctg, policy.max, max_pctg);
-		if (policy.policy) {
-			switch (policy.policy) {
-				case CPUFREQ_POLICY_POWERSAVE:
-				p += sprintf(p, "powersave\n");
-				break;	
-			case CPUFREQ_POLICY_PERFORMANCE:
-				p += sprintf(p, "performance\n");
-				break;
-			default:
-				p += sprintf(p, "INVALID\n");
-				break;
-			} 
-		} else
+		if (policy.governor)
 			p += snprintf(p, CPUFREQ_NAME_LEN, "%s\n", policy.governor->name);
 	}
 end:
include/linux/cpufreq.h +7 -13
diff -ruN linux-original/include/linux/cpufreq.h linux/include/linux/cpufreq.h
@@ -37,12 +37,7 @@
 
 
 /* if (cpufreq_driver->target) exists, the ->governor decides what frequency
- * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
- * two generic policies are available:
- */
-
-#define CPUFREQ_POLICY_POWERSAVE	(1)
-#define CPUFREQ_POLICY_PERFORMANCE	(2)
+ * within the limits is used.  */
 
 /* Frequency values here are CPU kHz so that hardware which doesn't run 
  * with some frequencies can complain without having to guess what per 
@@ -63,7 +58,6 @@
 struct cpufreq_real_policy {
 	unsigned int		min;    /* in kHz */
 	unsigned int		max;    /* in kHz */
-        unsigned int		policy; /* see above */
 	struct cpufreq_governor	*governor; /* see below */
 };
 
@@ -73,12 +67,12 @@
 
 	unsigned int		min;    /* in kHz */
 	unsigned int		max;    /* in kHz */
-	unsigned int		cur;    /* in kHz, only needed if cpufreq
-					 * governors are used */
-        unsigned int		policy; /* see above */
+
+	/* the following two entries are only valid if ->target is used */
+	unsigned int		cur;    /* in kHz */
 	struct cpufreq_governor	*governor; /* see below */
 
- 	struct semaphore	lock;   /* CPU ->setpolicy or ->target may
+ 	struct semaphore	lock;   /* CPU ->range or ->target may
 					   only be called once a time */
 
 	struct cpufreq_real_policy	user_policy;
@@ -181,7 +175,7 @@
 	int	(*verify)	(struct cpufreq_policy *policy);
 
 	/* define one out of two */
-	int	(*setpolicy)	(struct cpufreq_policy *policy);
+	int	(*range)	(struct cpufreq_policy *policy);
 	int	(*target)	(struct cpufreq_policy *policy,
 				 unsigned int target_freq,
 				 unsigned int relation);
@@ -229,7 +223,7 @@
 int cpufreq_update_policy(unsigned int cpu);
 
 /* the proc_intf.c needs this */
-int cpufreq_parse_governor (char *str_governor, unsigned int *policy, struct cpufreq_governor **governor);
+int cpufreq_parse_governor (char *str_governor, struct cpufreq_governor **governor);
 
 #if defined(CONFIG_CPU_FREQ_GOV_USERSPACE) || defined(CONFIG_CPU_FREQ_GOV_USERSPACE_MODULE)
 /*********************************************************************

_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq