Re: apmd: add on demand adjustement mode

2015-03-03 Thread Peter Hessler
That code was fixed in -current, and will be in 5.7.  Now, the kernel
does the measurements and scaling.


On 2015 Mar 02 (Mon) at 15:04:09 + (+), Jérôme Frgacic wrote:
:Hello,
:
:At present, there is no middle between cool running and automatic adjustement 
mode.
:I would suggest to add an "on demand" adjustement mode which set hw.setperf to
:maximum when CPU idle is lesser then 10% and reduce it when CPU idle is 
greater than
:30%. Also, when hw.setperf is at maximum, verification of CPU idle is slow 
down.
:
:This is based on a previous suggestion of Laurence Tratt.
:
:PS : please add me to recepient if you reply.
:

-- 
SHIFT TO THE LEFT!  SHIFT TO THE RIGHT!
POP UP, PUSH DOWN, BYTE, BYTE, BYTE!



apmd: add on demand adjustement mode

2015-03-02 Thread Jérôme Frgacic
Hello,

At present, there is no middle between cool running and automatic adjustement 
mode.
I would suggest to add an "on demand" adjustement mode which set hw.setperf to
maximum when CPU idle is lesser then 10% and reduce it when CPU idle is greater 
than
30%. Also, when hw.setperf is at maximum, verification of CPU idle is slow down.

This is based on a previous suggestion of Laurence Tratt.

PS : please add me to recepient if you reply.

Index: apm-proto.h
===
RCS file: /cvs/src/usr.sbin/apmd/apm-proto.h,v
retrieving revision 1.9
diff -u -p -r1.9 apm-proto.h
--- apm-proto.h 26 Mar 2012 20:17:45 -  1.9
+++ apm-proto.h 2 Mar 2015 14:56:34 -
@@ -38,6 +38,7 @@ enum apm_action {
SETPERF_LOW,
SETPERF_HIGH,
SETPERF_AUTO,
+   SETPERF_ONDEMAND,
SETPERF_COOL
 };
 
@@ -52,6 +53,7 @@ enum apm_perfmode {
PERF_NONE = -1,
PERF_MANUAL,
PERF_AUTO,
+   PERF_ONDEMAND,
PERF_COOL
 };
 
Index: apmd.8
===
RCS file: /cvs/src/usr.sbin/apmd/apmd.8,v
retrieving revision 1.44
diff -u -p -r1.44 apmd.8
--- apmd.8  24 Jul 2014 01:04:58 -  1.44
+++ apmd.8  2 Mar 2015 14:56:34 -
@@ -77,6 +77,16 @@ level is low.
 BIOS-initiated suspend or standby requests are
 ignored if the system is connected to line current and not running from
 batteries (user requests are still honored).
+.It Fl O
+Start
+.Nm
+in on demand performance adjustement mode.
+Set
+.Va hw.setperf
+to maximum when CPU idle is lesser than 90%, reduce it if CPU idle is
+greater than 30%. When
+.Va hw.setperf
+is at maximum, verification of CPU idle is ten times slower.
 .It Fl C
 Start
 .Nm

Index: apmd.c
===
RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.65
diff -u -p -r1.65 apmd.c
--- apmd.c  26 Jul 2014 10:48:59 -  1.65
+++ apmd.c  2 Mar 2015 14:56:34 -
@@ -76,7 +76,7 @@ int bind_socket(const char *sn);
 enum apm_state handle_client(int sock_fd, int ctl_fd);
 int  get_avg_idle_mp(int ncpu);
 int  get_avg_idle_up(void);
-void perf_status(struct apm_power_info *pinfo, int ncpu);
+long perf_status(struct apm_power_info *pinfo, int ncpu);
 void suspend(int ctl_fd);
 void stand_by(int ctl_fd);
 void hibernate(int ctl_fd);
@@ -301,13 +301,14 @@ get_avg_idle_up(void)
return avg_idle;
 }
 
-void
+long
 perf_status(struct apm_power_info *pinfo, int ncpu)
 {
int avg_idle;
int hw_perf_mib[] = {CTL_HW, HW_SETPERF};
int perf;
int forcehi = 0;
+   long timeout = 1;
size_t perf_sz = sizeof(perf);
 
if (ncpu > 1) {
@@ -330,6 +331,7 @@ perf_status(struct apm_power_info *pinfo
pinfo->battery_state == APM_BATTERY_ABSENT)
forcehi = 1;
break;
+   case PERF_ONDEMAND:
case PERF_COOL:
forcehi = 0;
break;
@@ -339,9 +341,13 @@ perf_status(struct apm_power_info *pinfo
syslog(LOG_INFO, "cannot read hw.setperf");
 
if (forcehi || (avg_idle < PERFINCTHRES && perf < PERFMAX)) {
-   perf += PERFINC;
-   if (perf > PERFMAX)
+   if (doperf == PERF_ONDEMAND) {
perf = PERFMAX;
+   } else {
+   perf += PERFINC;
+   if (perf > PERFMAX)
+   perf = PERFMAX;
+   }
setperf(perf);
} else if (avg_idle > PERFDECTHRES && perf > PERFMIN) {
perf -= PERFDEC;
@@ -349,6 +355,13 @@ perf_status(struct apm_power_info *pinfo
perf = PERFMIN;
setperf(perf);
}
+   if (doperf == PERF_ONDEMAND) {
+   if (perf == PERFMAX)
+   timeout = 9;
+   else
+   timeout = 1;
+   }
+   return timeout;
 }
 
 char socketname[MAXPATHLEN];
@@ -452,6 +465,11 @@ handle_client(int sock_fd, int ctl_fd)
reply.newstate = NORMAL;
syslog(LOG_NOTICE, "setting hw.setperf automatically");
break;
+   case SETPERF_ONDEMAND:
+   doperf = PERF_ONDEMAND;
+   reply.newstate = NORMAL;
+   syslog(LOG_NOTICE, "setting hw.setperf on demand");
+   break;
case SETPERF_COOL:
doperf = PERF_COOL;
reply.newstate = NORMAL;
@@ -525,7 +543,7 @@ main(int argc, char *argv[])
int ncpu;
size_t ncpu_sz = sizeof(ncpu);
 
-   while ((ch = getopt(argc, argv, "aACdHLsf:t:S:")) != -1)
+   while ((ch = getopt(argc, argv, "aAOCdHLsf:t:S:")) != -1)
switch(ch) {
case 'a':
noacsleep = 1;
@@ -552,6 +570,11 @@ main(int argc, cha