This patch moves some basic per-CPU static information (minimum frequency,
maximum frequency and maximum transition latency) into a struct
cpufreq_cpuinfo. This offers a much cleaner struct cpufreq_driver and
struct cpufreq_policy.
Dominik
diff -ruN linux-original/arch/arm/mach-integrator/cpu.c linux/arch/arm/mach-integrator/cpu.c
--- linux-original/arch/arm/mach-integrator/cpu.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/arm/mach-integrator/cpu.c 2002-12-13 15:44:26.000000000 +0100
@@ -77,8 +77,8 @@
{
struct vco vco;
- if (policy->max > policy->max_cpu_freq)
- policy->max = policy->max_cpu_freq;
+ if (policy->max > policy->cpuinfo.max_freq)
+ policy->max = policy->cpuinfo.max_freq;
if (policy->max < 12000)
policy->max = 12000;
@@ -148,7 +148,9 @@
static struct cpufreq_policy integrator_policy = {
.cpu = 0,
.policy = CPUFREQ_POLICY_POWERSAVE,
- .max_cpu_freq = 160000,
+ .cpuinfo.max_cpu_freq = 160000,
+ .cpuinfo.min_cpu_freq = 12000,
+ .cpuinfo.transition_latency = CPUFREQ_ETERNAL,
};
static struct cpufreq_driver integrator_driver = {
@@ -197,7 +199,9 @@
policies[cpu].cpu = cpu;
policies[cpu].policy = CPUFREQ_POLICY_POWERSAVE,
- policies[cpu].max_cpu_freq = 160000;
+ policies[cpu].cpuinfo.max_freq = 160000;
+ policies[cpu].cpuinfo.min_freq = 12000;
+ policies[cpu].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
policies[cpu].min =
policies[cpu].max = vco_to_freq(vco, 1);
}
@@ -205,8 +209,6 @@
set_cpus_allowed(current, cpus_allowed);
#ifdef CONFIG_CPU_FREQ
- for (cpu=0; cpu<NR_CPUS; cpu++)
- integrator_driver.cpu_min_freq[cpu] = 12000;
integrator_driver.policy = policies;
cpufreq_register(&integrator_driver);
#else
diff -ruN linux-original/arch/arm/mach-sa1100/cpu-sa1100.c linux/arch/arm/mach-sa1100/cpu-sa1100.c
--- linux-original/arch/arm/mach-sa1100/cpu-sa1100.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/arm/mach-sa1100/cpu-sa1100.c 2002-12-13 15:25:38.000000000 +0100
@@ -203,14 +203,15 @@
static struct cpufreq_policy sa1100_policy = {
.cpu = 0,
.policy = CPUFREQ_POLICY_POWERSAVE,
- .max_cpu_freq = 287000,
+ .cpuinfo.max_freq = 287000,
+ .cpuinfo.min_freq = 59000,
+ .cpuinfo.transition_latency = CPUFREQ_ETERNAL,
};
static struct cpufreq_driver sa1100_driver = {
.verify = sa11x0_verify_speed,
.setpolicy = sa1100_setspeed,
.policy = &sa1100_policy,
- .cpu_min_freq[0]= 59000,
};
static int __init sa1100_dram_init(void)
diff -ruN linux-original/arch/arm/mach-sa1100/cpu-sa1110.c linux/arch/arm/mach-sa1100/cpu-sa1110.c
--- linux-original/arch/arm/mach-sa1100/cpu-sa1110.c 2002-12-13 14:41:27.000000000 +0100
+++ linux/arch/arm/mach-sa1100/cpu-sa1110.c 2002-12-13 15:27:01.000000000 +0100
@@ -298,14 +298,15 @@
static struct cpufreq_policy sa1110_policy = {
.cpu = 0,
.policy = CPUFREQ_POLICY_POWERSAVE,
- .max_cpu_freq = 287000,
+ .cpuinfo.max_freq = 287000,
+ .cpuinfo.min_freq = 59000,
+ .cpuinfo.transition_latency = CPUFREQ_ETERNAL,
};
static struct cpufreq_driver sa1110_driver = {
.verify = sa11x0_verify_speed,
.setpolicy = sa1110_setspeed,
.policy = &sa1110_policy,
- .cpu_min_freq = { 59000, },
};
static int __init sa1110_clk_init(void)
diff -ruN linux-original/arch/arm/mach-sa1100/generic.c linux/arch/arm/mach-sa1100/generic.c
--- linux-original/arch/arm/mach-sa1100/generic.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/arm/mach-sa1100/generic.c 2002-12-13 15:22:36.000000000 +0100
@@ -69,8 +69,8 @@
*/
int sa11x0_verify_speed(struct cpufreq_policy *policy)
{
- if (policy->max > policy->max_cpu_freq)
- policy->max = policy->max_cpu_freq;
+ if (policy->max > policy->cpuinfo.max_freq)
+ policy->max = policy->cpuinfo.max_freq;
policy->max = cclk_frequency_100khz[sa11x0_freq_to_ppcr(policy->max)] * 100;
policy->min = policy->max;
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/elanfreq.c linux/arch/i386/kernel/cpu/cpufreq/elanfreq.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/elanfreq.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/elanfreq.c 2002-12-13 15:01:35.000000000 +0100
@@ -296,7 +296,6 @@
max_freq = elanfreq_get_cpu_frequency();
#ifdef CONFIG_CPU_FREQ_24_API
- driver->cpu_min_freq[0] = 1000;
driver->cpu_cur_freq[0] = elanfreq_get_cpu_frequency();
#endif
@@ -307,7 +306,9 @@
driver->policy[0].min = 1000;
driver->policy[0].max = max_freq;
driver->policy[0].policy = CPUFREQ_POLICY_PERFORMANCE;
- driver->policy[0].max_cpu_freq = max_freq;
+ driver->policy[0].cpuinfo.max_freq = max_freq;
+ driver->policy[0].cpuinfo.min_freq = min_freq;
+ driver->policy[0].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
elanfreq_driver = driver;
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/longhaul.c linux/arch/i386/kernel/cpu/cpufreq/longhaul.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/longhaul.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/longhaul.c 2002-12-13 15:03:20.000000000 +0100
@@ -779,7 +779,6 @@
driver->policy = (struct cpufreq_policy *) (driver + 1);
#ifdef CONFIG_CPU_FREQ_24_API
- driver->cpu_min_freq[0] = (unsigned int) lowest_speed;
driver->cpu_cur_freq[0] = currentspeed;
#endif
@@ -790,7 +789,9 @@
driver->policy[0].min = (unsigned int) lowest_speed;
driver->policy[0].max = (unsigned int) highest_speed;
driver->policy[0].policy = CPUFREQ_POLICY_PERFORMANCE;
- driver->policy[0].max_cpu_freq = (unsigned int) highest_speed;
+ driver->policy[0].cpuinfo.min_freq = (unsigned int) lowest_speed;
+ driver->policy[0].cpuinfo.max_freq = (unsigned int) highest_speed;
+ driver->policy[0].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
longhaul_driver = driver;
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/longrun.c linux/arch/i386/kernel/cpu/cpufreq/longrun.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/longrun.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/longrun.c 2002-12-13 15:06:32.000000000 +0100
@@ -121,8 +121,9 @@
return -EINVAL;
policy->cpu = 0;
- cpufreq_verify_within_limits(policy, 0,
- longrun_driver->policy[0].max_cpu_freq);
+ cpufreq_verify_within_limits(policy,
+ longrun_driver->policy[0].cpuinfo.min_freq,
+ longrun_driver->policy[0].cpuinfo.max_freq);
return 0;
}
@@ -247,12 +248,13 @@
kfree(driver);
return -EIO;
}
- driver->policy[0].max_cpu_freq = longrun_high_freq;
+ driver->policy[0].cpuinfo.min_freq = longrun_low_freq;
+ driver->policy[0].cpuinfo.max_freq = longrun_high_freq;
+ driver->policy[0].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
longrun_get_policy(&driver->policy[0]);
#ifdef CONFIG_CPU_FREQ_24_API
- driver->cpu_min_freq[0] = longrun_low_freq;
driver->cpu_cur_freq[0] = longrun_high_freq; /* dummy value */
#endif
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c linux/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c 2002-12-13 15:04:26.000000000 +0100
@@ -257,7 +257,6 @@
#ifdef CONFIG_CPU_FREQ_24_API
for (i=0;i<NR_CPUS;i++) {
- driver->cpu_min_freq[i] = stock_freq / 8;
driver->cpu_cur_freq[i] = stock_freq;
}
#endif
@@ -272,7 +271,10 @@
driver->policy[i].min = stock_freq / 8;
driver->policy[i].max = stock_freq;
driver->policy[i].policy = CPUFREQ_POLICY_PERFORMANCE;
- driver->policy[i].max_cpu_freq = stock_freq;
+ driver->policy[i].cpuinfo.min_freq = driver->policy[i].min;
+ driver->policy[i].cpuinfo.max_freq = stock_freq;
+ driver->policy[i].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
+
driver->policy[i].cpu = i;
}
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/powernow-k6.c linux/arch/i386/kernel/cpu/cpufreq/powernow-k6.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/powernow-k6.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/powernow-k6.c 2002-12-13 15:04:49.000000000 +0100
@@ -242,7 +242,6 @@
driver->policy = (struct cpufreq_policy *) (driver + 1);
#ifdef CONFIG_CPU_FREQ_24_API
- driver->cpu_min_freq[0] = busfreq * 20;
driver->cpu_cur_freq[0] = busfreq * max_multiplier;
#endif
@@ -253,7 +252,9 @@
driver->policy[0].min = busfreq * 20;
driver->policy[0].max = busfreq * max_multiplier;
driver->policy[0].policy = CPUFREQ_POLICY_PERFORMANCE;
- driver->policy[0].max_cpu_freq = busfreq * max_multiplier;
+ driver->policy[0].cpuinfo.max_freq = busfreq * max_multiplier;
+ driver->policy[0].cpuinfo.min_freq = busfreq * 20;
+ driver->policy[0].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
powernow_driver = driver;
diff -ruN linux-original/arch/i386/kernel/cpu/cpufreq/speedstep.c linux/arch/i386/kernel/cpu/cpufreq/speedstep.c
--- linux-original/arch/i386/kernel/cpu/cpufreq/speedstep.c 2002-11-23 09:08:56.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/speedstep.c 2002-12-13 15:05:14.000000000 +0100
@@ -693,7 +693,6 @@
driver->policy = (struct cpufreq_policy *) (driver + 1);
#ifdef CONFIG_CPU_FREQ_24_API
- driver->cpu_min_freq[0] = speedstep_low_freq;
driver->cpu_cur_freq[0] = speed;
#endif
@@ -703,7 +702,10 @@
driver->policy[0].cpu = 0;
driver->policy[0].min = speedstep_low_freq;
driver->policy[0].max = speedstep_high_freq;
- driver->policy[0].max_cpu_freq = speedstep_high_freq;
+ driver->policy[0].cpuinfo.min_freq = speedstep_low_freq;
+ driver->policy[0].cpuinfo.max_freq = speedstep_high_freq;
+ driver->policy[0].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
+
driver->policy[0].policy = (speed == speedstep_low_freq) ?
CPUFREQ_POLICY_POWERSAVE : CPUFREQ_POLICY_PERFORMANCE;
diff -ruN linux-original/drivers/acpi/processor.c linux/drivers/acpi/processor.c
--- linux-original/drivers/acpi/processor.c 2002-12-13 14:41:28.000000000 +0100
+++ linux/drivers/acpi/processor.c 2002-12-13 15:11:27.000000000 +0100
@@ -1849,10 +1849,15 @@
#ifdef CONFIG_CPU_FREQ_24_API
for (i=0;i<NR_CPUS;i++) {
driver->cpu_cur_freq[0] = pr->performance.states[current_state].core_frequency * 1000;
- driver->cpu_min_freq[0] = pr->performance.states[pr->performance.state_count - 1].core_frequency * 1000;
}
#endif
+ /* detect highest transition latency */
+ for (i=0;i<pr->performance.state_count;i++) {
+ if (pr->performance.states[i].transition_latency > driver->policy[0].cpuinfo.transition_latency)
+ driver->policy[0].cpuinfo.transition_latency = pr->performance.states[i].transition_latency;
+ }
+
driver->verify = &acpi_cpufreq_verify;
driver->setpolicy = &acpi_cpufreq_setpolicy;
@@ -1860,7 +1865,9 @@
driver->policy[i].cpu = pr->id;
driver->policy[i].min = pr->performance.states[pr->performance.state_count - 1].core_frequency * 1000;
driver->policy[i].max = pr->performance.states[pr->limit.state.px].core_frequency * 1000;
- driver->policy[i].max_cpu_freq = pr->performance.states[0].core_frequency * 1000;
+ driver->policy[i].cpuinfo.max_freq = pr->performance.states[0].core_frequency * 1000;
+ driver->policy[i].cpuinfo.min_freq = pr->performance.states[pr->performance.state_count - 1].core_frequency * 1000;
+ driver->policy[i].cpuinfo.transition_latency = driver->policy[0].cpuinfo.transition_latency;
driver->policy[i].policy = ( pr->performance.states[current_state].core_frequency * 1000 == driver->policy[i].max) ?
CPUFREQ_POLICY_PERFORMANCE : CPUFREQ_POLICY_POWERSAVE;
}
diff -ruN linux-original/include/linux/cpufreq.h linux/include/linux/cpufreq.h
--- linux-original/include/linux/cpufreq.h 2002-11-23 09:09:03.000000000 +0100
+++ linux/include/linux/cpufreq.h 2002-12-13 14:50:53.000000000 +0100
@@ -37,15 +37,26 @@
#define CPUFREQ_POLICY_POWERSAVE (1)
#define CPUFREQ_POLICY_PERFORMANCE (2)
-/* values here are CPU kHz so that hardware which doesn't run with some
- * frequencies can complain without having to guess what per cent / per
- * mille means. */
+/* Frequency values here are CPU kHz so that hardware which doesn't run
+ * with some frequencies can complain without having to guess what per
+ * cent / per mille means.
+ * Maximum transition latency is in nanoseconds - if it's unknown,
+ * CPUFREQ_ETERNAL shall be used.
+ */
+
+#define CPUFREQ_ETERNAL (-1)
+struct cpufreq_cpuinfo {
+ unsigned int max_freq;
+ unsigned int min_freq;
+ unsigned int transition_latency;
+};
+
struct cpufreq_policy {
unsigned int cpu; /* cpu nr or CPUFREQ_ALL_CPUS */
unsigned int min; /* in kHz */
unsigned int max; /* in kHz */
unsigned int policy; /* see above */
- unsigned int max_cpu_freq; /* for information */
+ struct cpufreq_cpuinfo cpuinfo; /* see above */
};
#define CPUFREQ_ADJUST (0)
@@ -116,7 +127,6 @@
#endif
/* 2.4. compatible API */
#ifdef CONFIG_CPU_FREQ_24_API
- unsigned int cpu_min_freq[NR_CPUS];
unsigned int cpu_cur_freq[NR_CPUS];
#endif
};
diff -ruN linux-original/kernel/cpufreq.c linux/kernel/cpufreq.c
--- linux-original/kernel/cpufreq.c 2002-11-23 09:09:03.000000000 +0100
+++ linux/kernel/cpufreq.c 2002-12-13 15:07:23.000000000 +0100
@@ -119,8 +119,8 @@
if (sscanf(input_string, "%d%%%d%%%d%%%s", &cpu, &min, &max, policy_string) == 4)
{
if (!cpufreq_get_policy(¤t_policy, cpu)) {
- policy->min = (min * current_policy.max_cpu_freq) / 100;
- policy->max = (max * current_policy.max_cpu_freq) / 100;
+ policy->min = (min * current_policy.cpuinfo.max_freq) / 100;
+ policy->max = (max * current_policy.cpuinfo.max_freq) / 100;
policy->cpu = cpu;
result = 0;
goto scan_policy;
@@ -138,8 +138,8 @@
if (sscanf(input_string, "%d%%%d%%%s", &min, &max, policy_string) == 3)
{
if (!cpufreq_get_policy(¤t_policy, cpu)) {
- policy->min = (min * current_policy.max_cpu_freq) / 100;
- policy->max = (max * current_policy.max_cpu_freq) / 100;
+ policy->min = (min * current_policy.cpuinfo.max_freq) / 100;
+ policy->max = (max * current_policy.cpuinfo.max_freq) / 100;
result = 0;
goto scan_policy;
}
@@ -229,11 +229,11 @@
cpufreq_get_policy(&policy, i);
- if (!policy.max_cpu_freq)
+ if (!policy.cpuinfo.max_freq)
continue;
- min_pctg = (policy.min * 100) / policy.max_cpu_freq;
- max_pctg = (policy.max * 100) / policy.max_cpu_freq;
+ min_pctg = (policy.min * 100) / policy.cpuinfo.max_freq;
+ max_pctg = (policy.max * 100) / policy.cpuinfo.max_freq;
p += sprintf(p, "CPU%3d %9d kHz (%3d %%) - %9d kHz (%3d %%) - ",
i , policy.min, min_pctg, policy.max, max_pctg);
@@ -279,6 +279,7 @@
int result = 0;
char proc_string[42] = {'\0'};
struct cpufreq_policy policy;
+ unsigned int i = 0;
if ((count > sizeof(proc_string) - 1))
@@ -293,7 +294,17 @@
if (result)
return -EFAULT;
- cpufreq_set_policy(&policy);
+ if (policy.cpu == CPUFREQ_ALL_CPUS)
+ {
+ for (i=0; i<NR_CPUS; i++)
+ {
+ policy.cpu = i;
+ if (cpu_online(i))
+ cpufreq_set_policy(&policy);
+ }
+ }
+ else
+ cpufreq_set_policy(&policy);
return count;
}
@@ -811,7 +822,9 @@
policy->min = cpufreq_driver->policy[cpu].min;
policy->max = cpufreq_driver->policy[cpu].max;
policy->policy = cpufreq_driver->policy[cpu].policy;
- policy->max_cpu_freq = cpufreq_driver->policy[cpu].max_cpu_freq;
+ policy->cpuinfo.max_freq = cpufreq_driver->policy[cpu].cpuinfo.max_freq;
+ policy->cpuinfo.min_freq = cpufreq_driver->policy[cpu].cpuinfo.min_freq;
+ policy->cpuinfo.transition_latency = cpufreq_driver->policy[cpu].cpuinfo.transition_latency;
policy->cpu = cpu;
up(&cpufreq_driver_sem);
@@ -835,16 +848,14 @@
down(&cpufreq_driver_sem);
if (!cpufreq_driver || !cpufreq_driver->verify ||
!cpufreq_driver->setpolicy || !policy ||
- (policy->cpu > NR_CPUS)) {
+ (policy->cpu >= NR_CPUS) || (!cpu_online(policy->cpu))) {
up(&cpufreq_driver_sem);
return -EINVAL;
}
- if (policy->cpu == CPUFREQ_ALL_CPUS)
- policy->max_cpu_freq = cpufreq_driver->policy[0].max_cpu_freq;
- else
- policy->max_cpu_freq = cpufreq_driver->policy[policy->cpu].max_cpu_freq;
-
+ policy->cpuinfo.max_freq = cpufreq_driver->policy[policy->cpu].cpuinfo.max_freq;
+ policy->cpuinfo.min_freq = cpufreq_driver->policy[policy->cpu].cpuinfo.min_freq;
+ policy->cpuinfo.transition_latency = cpufreq_driver->policy[policy->cpu].cpuinfo.transition_latency;
/* verify the cpu speed can be set within this limit */
ret = cpufreq_driver->verify(policy);
@@ -1039,8 +1050,8 @@
down(&cpufreq_driver_sem);
for (i=0; i<NR_CPUS; i++)
{
- cpu_min_freq[i] = driver_data->cpu_min_freq[i];
- cpu_max_freq[i] = driver_data->policy[i].max_cpu_freq;
+ cpu_min_freq[i] = driver_data->policy[i].cpuinfo.min_freq;
+ cpu_max_freq[i] = driver_data->policy[i].cpuinfo.max_freq;
cpu_cur_freq[i] = driver_data->cpu_cur_freq[i];
}
up(&cpufreq_driver_sem);