[PATCH 2.5.53] cpufreq: powernow-k6 cleanup

Dominik Brodowski (linux@brodo.de)
Sun, 29 Dec 2002 00:14:34 +0100


Clean up searching for best frequency, and add one safety check.

diff -ru 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-12-25 17:45:52.000000000 +0100
+++ linux/arch/i386/kernel/cpu/cpufreq/powernow-k6.c 2002-12-27 11:32:21.000000000 +0100
@@ -144,6 +144,9 @@

policy->max = clock_ratio[j] * busfreq;

+ cpufreq_verify_within_limits(policy, (20 * busfreq),
+ (max_multiplier * busfreq));
+
return 0;
}

@@ -156,53 +159,44 @@
*/
static int powernow_k6_setpolicy (struct cpufreq_policy *policy)
{
- unsigned int number_states = 0;
- unsigned int i, j=4;
+ unsigned int i;
+ unsigned int optimal;

- if (!powernow_driver)
+ if (!powernow_driver || !policy || policy->cpu)
return -EINVAL;

- for (i=0; i<8; i++)
- if ((policy->min <= (busfreq * clock_ratio[i])) &&
- (policy->max >= (busfreq * clock_ratio[i])))
- {
- number_states++;
- j = i;
- }
-
- if (number_states == 1) {
- /* if only one state is within the limit borders, it
- is easily detected and set */
- powernow_k6_set_state(j);
- return 0;
- }
-
- /* more than one state within limit */
- switch (policy->policy) {
+ switch(policy->policy) {
case CPUFREQ_POLICY_POWERSAVE:
- j = 6;
- for (i=0; i<8; i++)
- if ((policy->min <= (busfreq * clock_ratio[i])) &&
- (policy->max >= (busfreq * clock_ratio[i])) &&
- (clock_ratio[i] < clock_ratio[j]))
- j = i;
+ optimal = 6;
break;
case CPUFREQ_POLICY_PERFORMANCE:
- j = 4;
- for (i=0; i<8; i++)
- if ((policy->min <= (busfreq * clock_ratio[i])) &&
- (policy->max >= (busfreq * clock_ratio[i])) &&
- (clock_ratio[i] > clock_ratio[j]))
- j = i;
+ optimal = max_multiplier;
break;
default:
return -EINVAL;
}

- if (clock_ratio[i] > max_multiplier)
- return -EINVAL;
+ for (i=0;i<8;i++) {
+ unsigned int freq = busfreq * clock_ratio[i];
+ if (clock_ratio[i] > max_multiplier)
+ continue;
+ if ((freq > policy->max) ||
+ (freq < policy->min))
+ continue;
+ switch(policy->policy) {
+ case CPUFREQ_POLICY_POWERSAVE:
+ if (freq < (clock_ratio[optimal] * busfreq))
+ optimal = i;
+ break;
+ case CPUFREQ_POLICY_PERFORMANCE:
+ if (freq > (clock_ratio[optimal] * busfreq))
+ optimal = i;
+ break;
+ }
+ }
+
+ powernow_k6_set_state(optimal);

- powernow_k6_set_state(j);
return 0;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/