cpufreq: powernow-k6 cleanup

cpufreq: powernow-k6 cleanup

Post by Dominik Brodowsk » Mon, 30 Dec 2002 01:20:11



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

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

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

  */
 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

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. [PATCH][TRIVIAL] cpufreq/powernow-k6.c : eliminate unused variable

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or
higher.
# This patch includes the following deltas:
#                  ChangeSet    1.1427  -> 1.1428
#       arch/i386/kernel/cpu/cpufreq/powernow-k6.c      1.14    -> 1.15  
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------

# Eliminate a compile-time warning.
# --------------------------------------------
#
diff -Nru a/arch/i386/kernel/cpu/cpufreq/powernow-k6.c
b/arch/i386/kernel/cpu/cpufreq/powernow-k6.c
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k6.c        Thu May 29 09:57:14
2003
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k6.c        Thu May 29 09:57:14

 static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
 {
-       struct cpuinfo_x86 *c = cpu_data;
        unsigned int i;

        if (policy->cpu != 0)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Gimmick mode

3. fix warning: unused variable powernow-k6.c

4. Looking for equiv. of DEC umount -f for SUN machines

5. 2.4.19-pre10-ac1: Hardcoded cpu_khz in powernow-k6.c

6. Getting Java Plugins to work with Linux

7. PowerNow!, cpufreq, and swsusp

8. How do I change the root password

9. [RESEND] cpufreq: move /proc/cpufreq interface code to drivers/cpufreq

10. cpufreq: cleanups

11. cpufreq: Intel SpeedStep driver update & cleanup (Petri Koistinen)

12. cpufreq: minor cleanups

13. cpufreq: longhaul cleanup