I'm writing system monitoring code for NetBSD. Right now, to get the current CPU frequency, I have to iterate through ~six machine dependent sysctl variables and check their presence, even though they return exactly the same format.
This patch addresses some low hanging fruit by changing the arch-specific variable names in the cases where you can't control independent CPUs: machdep.est.frequency.current, machdep.powernow.frequency.current, machdep.intrepid.frequency.current, machdep.loongsong.frequency.current -> machdep.cpu.frequency.current machdep.cpu.frequency.current was already in use, so software like estd checks for it. The FDT code uses machdep.cpufreq.cpuX.current to provide per-CPU control, but this isn't offered by these drivers. I can only verify that this works on a machine that previously had machdep.est.frequency.current. Is there anything the machdep.est.frequency.current naming has been kept for compatibility with that this would break? Index: sys/arch/x86/acpi/acpi_cpu_md.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/acpi/acpi_cpu_md.c,v retrieving revision 1.83 diff -u -r1.83 acpi_cpu_md.c --- sys/arch/x86/acpi/acpi_cpu_md.c 19 Mar 2020 19:55:34 -0000 1.83 +++ sys/arch/x86/acpi/acpi_cpu_md.c 7 Sep 2020 16:06:04 -0000 @@ -1003,25 +1003,8 @@ acpicpu_md_pstate_sysctl_init(void) { const struct sysctlnode *fnode, *mnode, *rnode; - const char *str; int rv; - switch (cpu_vendor) { - - case CPUVENDOR_IDT: - case CPUVENDOR_INTEL: - str = "est"; - break; - - case CPUVENDOR_AMD: - str = "powernow"; - break; - - default: - return ENODEV; - } - - rv = sysctl_createv(&acpicpu_log, 0, NULL, &rnode, CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL, NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL); @@ -1030,7 +1013,7 @@ goto fail; rv = sysctl_createv(&acpicpu_log, 0, &rnode, &mnode, - 0, CTLTYPE_NODE, str, NULL, + 0, CTLTYPE_NODE, "cpu", NULL, NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL); if (rv != 0) Index: sys/arch/x86/x86/est.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/x86/est.c,v retrieving revision 1.31 diff -u -r1.31 est.c --- sys/arch/x86/x86/est.c 1 Jun 2017 02:45:08 -0000 1.31 +++ sys/arch/x86/x86/est.c 7 Sep 2020 16:06:04 -0000 @@ -1296,11 +1296,11 @@ est_sysctl(device_t self) { struct est_softc *sc = device_private(self); - const struct sysctlnode *node, *estnode, *freqnode; + const struct sysctlnode *node, *cpunode, *freqnode; int rv; /* - * Setup the sysctl sub-tree machdep.est.* + * Setup the sysctl sub-tree machdep.cpu.* */ rv = sysctl_createv(&sc->sc_log, 0, NULL, &node, CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL, @@ -1309,14 +1309,14 @@ if (rv != 0) goto fail; - rv = sysctl_createv(&sc->sc_log, 0, &node, &estnode, - 0, CTLTYPE_NODE, "est", NULL, + rv = sysctl_createv(&sc->sc_log, 0, &node, &cpunode, + 0, CTLTYPE_NODE, "cpu", NULL, NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL); if (rv != 0) goto fail; - rv = sysctl_createv(&sc->sc_log, 0, &estnode, &freqnode, + rv = sysctl_createv(&sc->sc_log, 0, &cpunode, &freqnode, 0, CTLTYPE_NODE, "frequency", NULL, NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL); Index: sys/arch/x86/x86/powernow.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/x86/powernow.c,v retrieving revision 1.10 diff -u -r1.10 powernow.c --- sys/arch/x86/x86/powernow.c 1 Jun 2017 02:45:08 -0000 1.10 +++ sys/arch/x86/x86/powernow.c 7 Sep 2020 16:06:04 -0000 @@ -249,7 +249,7 @@ static int powernow_sysctl(device_t self) { - const struct sysctlnode *freqnode, *node, *pnownode; + const struct sysctlnode *freqnode, *node, *cpunode; struct powernow_softc *sc = device_private(self); int rv; @@ -263,14 +263,14 @@ if (rv != 0) goto fail; - rv = sysctl_createv(&sc->sc_log, 0, &node, &pnownode, - 0, CTLTYPE_NODE, "powernow", NULL, + rv = sysctl_createv(&sc->sc_log, 0, &node, &cpunode, + 0, CTLTYPE_NODE, "cpu", NULL, NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL); if (rv != 0) goto fail; - rv = sysctl_createv(&sc->sc_log, 0, &pnownode, &freqnode, + rv = sysctl_createv(&sc->sc_log, 0, &cpunode, &freqnode, 0, CTLTYPE_NODE, "frequency", NULL, NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL); Index: sys/arch/macppc/dev/obio.c =================================================================== RCS file: /cvsroot/src/sys/arch/macppc/dev/obio.c,v retrieving revision 1.46 diff -u -r1.46 obio.c --- sys/arch/macppc/dev/obio.c 8 Jun 2018 23:39:31 -0000 1.46 +++ sys/arch/macppc/dev/obio.c 7 Sep 2020 16:06:04 -0000 @@ -431,9 +431,9 @@ if (sysctl_createv(NULL, 0, NULL, &me, - CTLFLAG_READWRITE, CTLTYPE_NODE, "intrepid", NULL, NULL, + CTLFLAG_READWRITE, CTLTYPE_NODE, "cpu", NULL, NULL, 0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL) != 0) - printf("couldn't create 'intrepid' node\n"); + printf("couldn't create 'cpu' node\n"); if (sysctl_createv(NULL, 0, NULL, &freq, Index: sys/arch/evbmips/loongson/loongson_clock.c =================================================================== RCS file: /cvsroot/src/sys/arch/evbmips/loongson/loongson_clock.c,v retrieving revision 1.2 diff -u -r1.2 loongson_clock.c --- sys/arch/evbmips/loongson/loongson_clock.c 29 May 2020 12:30:40 -0000 1.2 +++ sys/arch/evbmips/loongson/loongson_clock.c 7 Sep 2020 16:06:04 -0000 @@ -110,9 +110,9 @@ /* now setup sysctl */ if (sysctl_createv(NULL, 0, NULL, &me, - CTLFLAG_READWRITE, CTLTYPE_NODE, "loongson", NULL, NULL, + CTLFLAG_READWRITE, CTLTYPE_NODE, "cpu", NULL, NULL, 0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL) != 0) - aprint_error("couldn't create 'loongson' node\n"); + aprint_error("couldn't create 'cpu' node\n"); if (sysctl_createv(NULL, 0, NULL, &freq, Index: share/man/man4/man4.x86/est.4 =================================================================== RCS file: /cvsroot/src/share/man/man4/man4.x86/est.4,v retrieving revision 1.5 diff -u -r1.5 est.4 --- share/man/man4/man4.x86/est.4 17 Feb 2017 22:10:47 -0000 1.5 +++ share/man/man4/man4.x86/est.4 7 Sep 2020 16:06:04 -0000 @@ -24,7 +24,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 17, 2017 +.Dd September 7, 2020 .Dt EST 4 .Os .Sh NAME @@ -41,13 +41,13 @@ .Xr sysctl 8 variables are available with .Nm : -.Bl -tag -width "machdep.est.frequency.available" -offset indent -.It Ic machdep.est.frequency.target +.Bl -tag -width "machdep.cpu.frequency.available" -offset indent +.It Ic machdep.cpu.frequency.target The target frequency of the .Tn CPUs . -.It Ic machdep.est.frequency.current +.It Ic machdep.cpu.frequency.current The current frequency. -.It Ic machdep.est.frequency.available +.It Ic machdep.cpu.frequency.available The frequencies recognized by .Nm . .El Index: share/man/man4/man4.x86/powernow.4 =================================================================== RCS file: /cvsroot/src/share/man/man4/man4.x86/powernow.4,v retrieving revision 1.3 diff -u -r1.3 powernow.4 --- share/man/man4/man4.x86/powernow.4 17 Feb 2017 22:10:47 -0000 1.3 +++ share/man/man4/man4.x86/powernow.4 7 Sep 2020 16:06:04 -0000 @@ -24,7 +24,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 17, 2017 +.Dd September 7, 2020 .Dt POWERNOW 4 .Os .Sh NAME @@ -46,13 +46,13 @@ .Xr sysctl 8 variables are available with .Nm : -.Bl -tag -width "machdep.powernow.frequency.available" -offset 2n -.It Ic machdep.powernow.frequency.target +.Bl -tag -width "machdep.cpu.frequency.available" -offset 2n +.It Ic machdep.cpu.frequency.target The target frequency of the .Tn CPUs . -.It Ic machdep.powernow.frequency.current +.It Ic machdep.cpu.frequency.current The current frequency. -.It Ic machdep.powernow.frequency.available +.It Ic machdep.cpu.frequency.available The available frequencies. .El .Pp