--- powerd.c.bak 2007-06-14 04:05:11.000000000 +0900 +++ powerd.c 2008-07-01 19:04:41.000000000 +0900 @@ -190,6 +190,16 @@ } static int +read_ncpu(int *ncpu) +{ + size_t len = sizeof(*ncpu); + if (sysctlbyname("hw.ncpu", ncpu, &len, NULL, 0)) + return (-1); + + return (0); +} + +static int set_freq(int freq) { @@ -366,7 +376,7 @@ { struct timeval timeout; fd_set fdset; - int nfds; + int nfds, ncpu; struct pidfh *pfh = NULL; const char *pidfile = NULL; long idle, total; @@ -453,6 +463,9 @@ if (read_freqs(&numfreqs, &freqs, &mwatts)) err(1, "error reading supported CPU frequencies"); + if (read_ncpu(&ncpu)) + err(1, "error reading # of cpus"); + /* Run in the background unless in verbose mode. */ if (!vflag) { pid_t otherpid; @@ -592,7 +605,8 @@ if (freqs[i] == curfreq) break; } - if (idle < (total * cpu_running_mark) / 100 && + if (idle < ((total - total / ncpu) + + (total * cpu_running_mark) / (100 * ncpu)) && curfreq < freqs[0]) { i -= 2; if (i < 0) @@ -605,7 +619,8 @@ if (set_freq(freqs[i])) warn("error setting CPU frequency %d", freqs[i]); - } else if (idle > (total * cpu_idle_mark) / 100 && + } else if (idle > ((total - total / ncpu) + + (total * cpu_idle_mark) / (100 * ncpu)) && curfreq > freqs[numfreqs - 1]) { i++; if (vflag) {