On Wed, Sep 23 2020, "Ted Unangst" <t...@tedunangst.com> wrote:
> On 2020-09-23, Jeremie Courreges-Anglas wrote:
>
>> ok?
>
> Seems fine.
>
>
>> Note: I inlined the apmd(8)->apm(8) perfpolicy conversion for now, which
>> brings a question.  I find it weird that there is a special "high"
>> perfpolicy (effectively similar to perfpolicy=manual + setperf=100) but
>> no "low" perfpolicy.  Is "high" useful to anyone?
>
> If you're benchmarking or something, it's convenient to toggle between
> high and auto. There's less use for low, since that's what auto defaults to.

Well you can do auto->high easily with apm(8) -H or sysctl
hw.perfpolicy=manual hw.setperf=100.  I'm not sure a special "high"
hw.perfpolicy choice brings much value and I would appreciate a simple
"manual" vs "auto" situation.

This has an impact on documentation.  sysctl(2) doesn't mention that
setting hw.perfpolicy=high also locks hw.setperf=100.  The apm(8)
manpage only talks about -H setting hw.setperf=100.  The description for
apmd(8) -H says

  Start apmd in *manual* performance adjustment mode,
  initialising hw.setperf to 100.

which is not the whole story.  If you use apm/apmd -H you can't later
just run sysctl hw.setperf=50:

  sysctl: hw.setperf: Operation not permitted

Initially I had a diff to teach apm(8) about hw.perfpolicy="high" but
I'm not sure it's the right direction any more.  Diff below fwiw, not
looking for oks.


Index: apm/apm.c
===================================================================
RCS file: /d/cvs/src/usr.sbin/apm/apm.c,v
retrieving revision 1.37
diff -u -p -r1.37 apm.c
--- apm/apm.c   23 Sep 2020 05:50:26 -0000      1.37
+++ apm/apm.c   24 Sep 2020 20:29:49 -0000
@@ -399,7 +399,8 @@ balony:
 
                if (doperf)
                        printf("Performance adjustment mode: %s (%d MHz)\n",
-                           perf_mode(reply.perfmode), reply.cpuspeed);
+                           perfmode_to_perfpolicy(reply.perfmode),
+                           reply.cpuspeed);
                break;
        default:
                break;
Index: apmd/apm-proto.h
===================================================================
RCS file: /d/cvs/src/usr.sbin/apmd/apm-proto.h,v
retrieving revision 1.10
diff -u -p -r1.10 apm-proto.h
--- apmd/apm-proto.h    23 Sep 2020 05:50:26 -0000      1.10
+++ apmd/apm-proto.h    24 Sep 2020 20:29:49 -0000
@@ -51,6 +51,7 @@ enum apm_perfmode {
        PERF_NONE = -1,
        PERF_MANUAL,
        PERF_AUTO,
+       PERF_HIGH,
 };
 
 struct apm_command {
@@ -66,8 +67,9 @@ struct apm_reply {
        struct apm_power_info batterystate;
 };
 
-#define APMD_VNO       3
+#define APMD_VNO       4
 
 extern const char *battstate(int state);
 extern const char *ac_state(int state);
-extern const char *perf_mode(int mode);
+extern const char *perfmode_to_perfpolicy(int mode);
+extern enum apm_perfmode perfpolicy_to_perfmode(const char *);
Index: apmd/apmd.c
===================================================================
RCS file: /d/cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.98
diff -u -p -r1.98 apmd.c
--- apmd/apmd.c 24 Sep 2020 07:23:41 -0000      1.98
+++ apmd/apmd.c 24 Sep 2020 20:29:49 -0000
@@ -310,16 +310,11 @@ handle_client(int sock_fd, int ctl_fd)
                break;
        }
 
-       reply.perfmode = PERF_NONE;
-       if (sysctl(perfpol_mib, 2, perfpol, &perfpol_sz, NULL, 0) == -1)
+       if (sysctl(perfpol_mib, 2, perfpol, &perfpol_sz, NULL, 0) == -1) {
                logmsg(LOG_INFO, "cannot read hw.perfpolicy");
-       else {
-               if (strcmp(perfpol, "manual") == 0 ||
-                   strcmp(perfpol, "high") == 0) {
-                       reply.perfmode = PERF_MANUAL;
-               } else if (strcmp(perfpol, "auto") == 0)
-                       reply.perfmode = PERF_AUTO;
-       }
+               reply.perfmode = PERF_NONE;
+       } else
+               reply.perfmode = perfpolicy_to_perfmode(perfpol);
 
        if (sysctl(cpuspeed_mib, 2, &cpuspeed, &cpuspeed_sz, NULL, 0) == -1) {
                logmsg(LOG_INFO, "cannot read hw.cpuspeed");
Index: apmd/apmsubr.c
===================================================================
RCS file: /d/cvs/src/usr.sbin/apmd/apmsubr.c,v
retrieving revision 1.9
diff -u -p -r1.9 apmsubr.c
--- apmd/apmsubr.c      23 Sep 2020 05:50:26 -0000      1.9
+++ apmd/apmsubr.c      24 Sep 2020 20:29:49 -0000
@@ -31,6 +31,8 @@
 
 #include <sys/types.h>
 #include <machine/apmvar.h>
+#include <string.h>
+
 #include "apm-proto.h"
 
 const char *
@@ -72,14 +74,29 @@ ac_state(int state)
 }
 
 const char *
-perf_mode(int mode)
+perfmode_to_perfpolicy(int mode)
 {
        switch (mode) {
-       case PERF_MANUAL:
-               return "manual";
        case PERF_AUTO:
                return "auto";
+       case PERF_HIGH:
+               return "high";
+       case PERF_MANUAL:
+               return "manual";
        default:
                return "invalid";
        }
+}
+
+enum apm_perfmode
+perfpolicy_to_perfmode(const char *perfpolicy)
+{
+       if (strcmp(perfpolicy, "auto") == 0)
+               return PERF_AUTO;
+       else if (strcmp(perfpolicy, "high") == 0)
+               return PERF_HIGH;
+       else if (strcmp(perfpolicy, "manual") == 0)
+               return PERF_MANUAL;
+
+       return PERF_NONE;
 }


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to