From: Dominik Brodowski <linux@brodo.de>
To: torvalds@transmeta.com, davej@suse.de
Cc: linux-kernel@vger.kernel.org, cpufreq@www.linux.org.uk
Subject: [PATCH 2.5.53] cpufreq: powernow-k6 cleanup
Date: Sun, 29 Dec 2002 00:14:34 +0100 [thread overview]
Message-ID: <20021228231434.GC1310@brodo.de> (raw)
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;
}
reply other threads:[~2002-12-28 23:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021228231434.GC1310@brodo.de \
--to=linux@brodo.de \
--cc=cpufreq@www.linux.org.uk \
--cc=davej@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.