powerd / cpufreq question

Bartosz Fabianowski freebsd at chillt.de
Sat Apr 9 14:55:33 UTC 2011


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
-------------- next part --------------
--- 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);


More information about the freebsd-stable mailing list