diff options
author | Sigrid <ftrvxmtrx@gmail.com> | 2021-01-22 10:15:36 +0100 |
---|---|---|
committer | Sigrid <ftrvxmtrx@gmail.com> | 2021-01-22 10:15:36 +0100 |
commit | 6a78bb2e4f00581d85de1c5f9949782de3dd8933 (patch) | |
tree | b1029b39144c52684b5826caa10ac15c9d214ca0 | |
parent | 1047b53efc370ad77546337a221171777b6face1 (diff) | |
download | plan9front-6a78bb2e4f00581d85de1c5f9949782de3dd8933.tar.xz |
stats: don't query battery and temp as often when using acpi
Querying battery (or temperature) using ACPI takes quite some
resources, which makes the battery discharge faster. It doesn't make
much sense to have it queried as often either. So, when using ACPI:
1) set battery query period to 10s minimum
2) set temperature query period to 5s minimum
-rw-r--r-- | sys/src/cmd/stats.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/sys/src/cmd/stats.c b/sys/src/cmd/stats.c index ac5f9b448..e62735dc0 100644 --- a/sys/src/cmd/stats.c +++ b/sys/src/cmd/stats.c @@ -219,7 +219,9 @@ int ngraph; /* totaly number is ngraph*nmach */ double scale = 1.0; int logscale = 0; int ylabels = 0; -int sleeptime = 1000; +int sleeptime = 1000; +int batteryperiod = 1000; +int tempperiod = 1000; char *procnames[NPROC] = {"main", "input"}; @@ -625,6 +627,7 @@ initmach(Machine *m, char *name) } m->bitsybatfd = -1; if(m->batteryfd >= 0){ + batteryperiod = 10000; if(loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0)) memmove(m->batterystats, a, sizeof(m->batterystats)); }else{ @@ -636,6 +639,7 @@ initmach(Machine *m, char *name) snprint(buf, sizeof buf, "%s/dev/cputemp", mpt); m->tempfd = open(buf, OREAD); if(m->tempfd < 0){ + tempperiod = 5000; snprint(buf, sizeof buf, "%s/mnt/acpi/cputemp", mpt); m->tempfd = open(buf, OREAD); } @@ -679,7 +683,14 @@ needether(int init) int needbattery(int init) { - return init | present[Mbattery]; + static uint step = 0; + + if(++step*sleeptime >= batteryperiod){ + step = 0; + return init | present[Mbattery]; + } + + return 0; } int @@ -691,7 +702,14 @@ needsignal(int init) int needtemp(int init) { - return init | present[Mtemp]; + static uint step = 0; + + if(++step*sleeptime >= tempperiod){ + step = 0; + return init | present[Mtemp]; + } + + return 0; } void @@ -737,10 +755,12 @@ readmach(Machine *m, int init) if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){ memmove(m->netetherifstats, a, sizeof m->netetherifstats); } - if(needbattery(init) && loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0)) - memmove(m->batterystats, a, sizeof(m->batterystats)); - if(needbattery(init) && loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0)) - memmove(m->batterystats, a, sizeof(m->batterystats)); + if(needbattery(init)){ + if(loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0)) + memmove(m->batterystats, a, sizeof(m->batterystats)); + else if(loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0)) + memmove(m->batterystats, a, sizeof(m->batterystats)); + } if(needtemp(init) && loadbuf(m, &m->tempfd)) for(n=0; n < nelem(m->temp) && readnums(m, 2, a, 0); n++) m->temp[n] = a[0]; |