[powerd] mode adaptive2

Bruno Ducrot ducrot at poupinou.org
Mon Apr 25 10:21:09 PDT 2005


Hi,

This algorithm give me some interesting behaviour.  There is
some trouble especially with max frequency setting which may
need to be improved somehow.  Also, it's very likely it fail
if min frequency is too low (but I think its more a problem
with kernel).

After solving those issues, I'll introduce some adaptive
filters.


Index: powerd.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/powerd/powerd.c,v
retrieving revision 1.6
diff -u -p -r1.6 powerd.c
--- powerd.c	10 Apr 2005 20:42:55 -0000	1.6
+++ powerd.c	25 Apr 2005 16:57:42 -0000
@@ -48,9 +48,13 @@ __FBSDID("$FreeBSD: src/usr.sbin/powerd/
 #define DEFAULT_IDLE_PERCENT	90
 #define DEFAULT_POLL_INTERVAL	500	/* Poll interval in milliseconds */
 
+
+#define DELTA_MAX		2
+
 enum modes_t {
 	MODE_MIN,
 	MODE_ADAPTIVE,
+	MODE_ADAPTIVE2,
 	MODE_MAX,
 };
 
@@ -229,6 +233,8 @@ parse_mode(char *arg, int *mode, int ch)
 		*mode = MODE_MAX;
 	else if (strcmp(arg, "adaptive") == 0)
 		*mode = MODE_ADAPTIVE;
+	else if (strcmp(arg, "adaptive2") == 0)
+		*mode = MODE_ADAPTIVE2;
 	else
 		errx(1, "bad option: -%c %s", (char)ch, optarg);
 }
@@ -417,6 +423,46 @@ main(int argc, char * argv[])
 		if (read_usage_times(&idle, &total))
 			err(1, "read_usage_times");
 
+		if (mode == MODE_ADAPTIVE2) {
+			if (100 * idle <= DELTA_MAX * total &&
+			    curfreq < freqs[0]) {
+				if (vflag)
+					printf("idle time <= %d%%, increasing "
+					    "clock speed from %d MHz to %d "
+					    "MHz\n",
+					    DELTA_MAX, curfreq, freqs[0]);
+
+				if (set_freq(freqs[0]))
+					err(1, "error setting CPU frequency %d",
+					    freqs[0]);
+			} else if (curfreq > freqs[numfreqs - 1]) {
+				for (i = 0; i < numfreqs; i++) {
+					if (freqs[i] == curfreq)
+						break;
+				}
+				if (idle < total * freqs[i + 1] / freqs[i])
+					continue;
+
+				if (vflag)
+					printf("idle time >= %d%%, ",
+					    100 * freqs[i + 1] / freqs[i]);
+				for (i = 0; i < numfreqs - 1; i++) {
+					if (freqs[i] <=
+					    curfreq * (total - idle) / total)
+						break;
+				}
+				if (vflag) {
+					printf("decreasing clock speed "
+					    "from %d MHz to %d MHz\n",
+					    curfreq, freqs[i]);
+				}
+				if (set_freq(freqs[i]))
+					err(1, "error setting CPU frequency %d",
+					    freqs[i]);
+			}
+			continue;
+		}
+
 		/*
 		 * If we're idle less than the active mark, jump the CPU to
 		 * its fastest speed if we're not there yet.  If we're idle


-- 
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.


More information about the freebsd-acpi mailing list