aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/powerd
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2010-06-16 15:09:45 +0000
committerAlexander Motin <mav@FreeBSD.org>2010-06-16 15:09:45 +0000
commit773b251c07fafbcd18e029da6fb640e167b79e43 (patch)
tree817e56770e5e8dbc1b8239f1e2681f10d4bc6dc4 /usr.sbin/powerd
parent9279d32a6412f0a528cba287d76bd8246322133d (diff)
downloadsrc-773b251c07fafbcd18e029da6fb640e167b79e43.tar.gz
src-773b251c07fafbcd18e029da6fb640e167b79e43.zip
Freq sysctls are quite heavy due to set of malloc()/free() calls. Avoid
reading current frequency on every period. Instead do it only after changing and periodically from time to time if somebody else change it. Also dynamically decrease sampling frequency up to 4 times on inactivity,
Notes
Notes: svn path=/head/; revision=209234
Diffstat (limited to 'usr.sbin/powerd')
-rw-r--r--usr.sbin/powerd/powerd.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/usr.sbin/powerd/powerd.c b/usr.sbin/powerd/powerd.c
index b4ba05d7a963..7192bddbbe95 100644
--- a/usr.sbin/powerd/powerd.c
+++ b/usr.sbin/powerd/powerd.c
@@ -435,7 +435,7 @@ main(int argc, char * argv[])
struct pidfh *pfh = NULL;
const char *pidfile = NULL;
int freq, curfreq, initfreq, *freqs, i, j, *mwatts, numfreqs, load;
- int ch, mode, mode_ac, mode_battery, mode_none;
+ int ch, mode, mode_ac, mode_battery, mode_none, idle, to;
uint64_t mjoules_used;
size_t len;
@@ -548,9 +548,11 @@ main(int argc, char * argv[])
signal(SIGINT, handle_sigs);
signal(SIGTERM, handle_sigs);
- freq = initfreq = get_freq();
+ freq = initfreq = curfreq = get_freq();
+ i = get_freq_id(curfreq, freqs, numfreqs);
if (freq < 1)
freq = 1;
+ idle = 0;
/* Main loop. */
for (;;) {
FD_ZERO(&fdset);
@@ -560,8 +562,14 @@ main(int argc, char * argv[])
} else {
nfds = 0;
}
- timeout.tv_sec = poll_ival / 1000000;
- timeout.tv_usec = poll_ival % 1000000;
+ if (mode == MODE_HIADAPTIVE || idle < 120)
+ to = poll_ival;
+ else if (idle < 360)
+ to = poll_ival * 2;
+ else
+ to = poll_ival * 4;
+ timeout.tv_sec = to / 1000000;
+ timeout.tv_usec = to % 1000000;
select(nfds, &fdset, NULL, &fdset, &timeout);
/* If the user requested we quit, print some statistics. */
@@ -590,11 +598,12 @@ main(int argc, char * argv[])
}
/* Read the current frequency. */
- if ((curfreq = get_freq()) == 0)
- continue;
-
- i = get_freq_id(curfreq, freqs, numfreqs);
-
+ if (idle % 32 == 0) {
+ if ((curfreq = get_freq()) == 0)
+ continue;
+ i = get_freq_id(curfreq, freqs, numfreqs);
+ }
+ idle++;
if (vflag) {
/* Keep a sum of all power actually used. */
if (mwatts[i] != -1)
@@ -611,6 +620,7 @@ main(int argc, char * argv[])
"changing frequency to %d MHz\n",
modes[acline_status], freq);
}
+ idle = 0;
if (set_freq(freq) != 0) {
warn("error setting CPU freq %d",
freq);
@@ -629,6 +639,7 @@ main(int argc, char * argv[])
"changing frequency to %d MHz\n",
modes[acline_status], freq);
}
+ idle = 0;
if (set_freq(freq) != 0) {
warn("error setting CPU freq %d",
freq);
@@ -689,6 +700,7 @@ main(int argc, char * argv[])
" speed from %d MHz to %d MHz\n",
freqs[i], freqs[j]);
}
+ idle = 0;
if (set_freq(freqs[j]))
warn("error setting CPU frequency %d",
freqs[j]);