I just noticed this thread a day after my own fight with powerd and load percentages that did not seem to make any sense.

The patch I came up with is attached. It modifies powerd to use the load percentage of the busiest core. This reduces the range of values back to 0%...100% also for multi-core systems.

On my Core i7 setup here, the change seems to work well.

- Bartosz
--- powerd.c.old        2011-04-07 17:30:58.000000000 +0200
+++ powerd.c    2011-04-07 17:38:28.000000000 +0200
@@ -128,7 +128,7 @@
        static long *cp_times = NULL, *cp_times_old = NULL;
        static int ncpus = 0;
        size_t cp_times_len;
-       int error, cpu, i, total;
+       int error, cpu, i, total, max;
 
        if (cp_times == NULL) {
                cp_times_len = 0;
@@ -151,7 +151,7 @@
                return (error);
                
        if (load) {
-               *load = 0;
+               max = 0;
                for (cpu = 0; cpu < ncpus; cpu++) {
                        total = 0;
                        for (i = 0; i < CPUSTATES; i++) {
@@ -160,9 +160,12 @@
                        }
                        if (total == 0)
                                continue;
-                       *load += 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] - 
+                       total = 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] - 
                            cp_times_old[cpu * CPUSTATES + CP_IDLE]) * 100 / 
total;
+                       if (total > max)
+                               max = total;
                }
+               *load = max;
        }
 
        memcpy(cp_times_old, cp_times, cp_times_len);
_______________________________________________
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"

Reply via email to