Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 09 Apr 2011 16:39:14 +0200
From:      Bartosz Fabianowski <freebsd@chillt.de>
To:        Daniel Gerzo <danger@FreeBSD.org>
Cc:        Alexander Motin <mav@FreeBSD.org>, stable@FreeBSD.org
Subject:   Re: powerd / cpufreq question
Message-ID:  <4DA06F92.4070702@chillt.de>
In-Reply-To: <85cda6f83d328e67a552b2cd5758dbd3@rulez.sk>
References:  <4D9EEDAF.3020803@rulez.sk> <4D9EF48C.9070907@FreeBSD.org>	<e229a6a374fdd5a626c0b777752fef54@rulez.sk>	<4D9F2384.5000104@FreeBSD.org> <85cda6f83d328e67a552b2cd5758dbd3@rulez.sk>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
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

[-- Attachment #2 --]
--- 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);

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DA06F92.4070702>