Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/fdt Change sysctl to be named after the first CPU in...



details:   https://anonhg.NetBSD.org/src/rev/3d336f3e8a85
branches:  trunk
changeset: 455084:3d336f3e8a85
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 06 11:28:24 2019 +0000

description:
Change sysctl to be named after the first CPU in the DVFS domain.

  old: machdep.cpu.frequency.*, machdep.cpufreqdt4.frequency.*
  new: machdep.cpufreq.cpu0.*, machdep.cpufreq.cpu4.*

diffstat:

 sys/dev/fdt/cpufreq_dt.c |  50 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)

diffs (117 lines):

diff -r 6d925644c39c -r 3d336f3e8a85 sys/dev/fdt/cpufreq_dt.c
--- a/sys/dev/fdt/cpufreq_dt.c  Sun Oct 06 07:36:46 2019 +0000
+++ b/sys/dev/fdt/cpufreq_dt.c  Sun Oct 06 11:28:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.8 2019/05/21 22:15:26 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.9 2019/10/06 11:28:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.8 2019/05/21 22:15:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.9 2019/10/06 11:28:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -39,6 +39,7 @@
 #include <sys/sysctl.h>
 #include <sys/queue.h>
 #include <sys/once.h>
+#include <sys/cpu.h>
 
 #include <dev/fdt/fdtvar.h>
 
@@ -250,14 +251,36 @@
        return error;
 }
 
+static struct cpu_info *
+cpufreq_dt_cpu_lookup(cpuid_t mpidr)
+{
+       CPU_INFO_ITERATOR cii;
+       struct cpu_info *ci;
+
+       for (CPU_INFO_FOREACH(cii, ci)) {
+               if (ci->ci_cpuid == mpidr)
+                       return ci;
+       }
+
+       return NULL;
+}
+
 static void
 cpufreq_dt_init_sysctl(struct cpufreq_dt_softc *sc)
 {
-       const struct sysctlnode *node, *cpunode, *freqnode;
+       const struct sysctlnode *node, *cpunode;
        struct sysctllog *cpufreq_log = NULL;
-       const char *cpunodename;
+       struct cpu_info *ci;
+       uint64_t mpidr;
        int error, i;
 
+       if (fdtbus_get_reg(sc->sc_phandle, 0, &mpidr, 0) != 0)
+               return;
+
+       ci = cpufreq_dt_cpu_lookup(mpidr);
+       if (ci == NULL)
+               return;
+
        sc->sc_freq_available = kmem_zalloc(strlen("XXXX ") * sc->sc_nopp, KM_SLEEP);
        for (i = 0; i < sc->sc_nopp; i++) {
                char buf[6];
@@ -265,28 +288,23 @@
                strcat(sc->sc_freq_available, buf);
        }
 
-       if (device_unit(sc->sc_dev) == 0)
-               cpunodename = "cpu";
-       else
-               cpunodename = device_xname(sc->sc_dev);
-
        error = sysctl_createv(&cpufreq_log, 0, NULL, &node,
            CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
            NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
        if (error)
                goto sysctl_failed;
-       error = sysctl_createv(&cpufreq_log, 0, &node, &cpunode,
-           0, CTLTYPE_NODE, cpunodename, NULL,
+       error = sysctl_createv(&cpufreq_log, 0, &node, &node,
+           0, CTLTYPE_NODE, "cpufreq", NULL,
            NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
        if (error)
                goto sysctl_failed;
-       error = sysctl_createv(&cpufreq_log, 0, &cpunode, &freqnode,
-           0, CTLTYPE_NODE, "frequency", NULL,
+       error = sysctl_createv(&cpufreq_log, 0, &node, &cpunode,
+           0, CTLTYPE_NODE, cpu_name(ci), NULL,
            NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
        if (error)
                goto sysctl_failed;
 
-       error = sysctl_createv(&cpufreq_log, 0, &freqnode, &node,
+       error = sysctl_createv(&cpufreq_log, 0, &cpunode, &node,
            CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
            cpufreq_dt_sysctl_helper, 0, (void *)sc, 0,
            CTL_CREATE, CTL_EOL);
@@ -294,7 +312,7 @@
                goto sysctl_failed;
        sc->sc_node_target = node->sysctl_num;
 
-       error = sysctl_createv(&cpufreq_log, 0, &freqnode, &node,
+       error = sysctl_createv(&cpufreq_log, 0, &cpunode, &node,
            CTLFLAG_READWRITE, CTLTYPE_INT, "current", NULL,
            cpufreq_dt_sysctl_helper, 0, (void *)sc, 0,
            CTL_CREATE, CTL_EOL);
@@ -302,7 +320,7 @@
                goto sysctl_failed;
        sc->sc_node_current = node->sysctl_num;
 
-       error = sysctl_createv(&cpufreq_log, 0, &freqnode, &node,
+       error = sysctl_createv(&cpufreq_log, 0, &cpunode, &node,
            0, CTLTYPE_STRING, "available", NULL,
            NULL, 0, sc->sc_freq_available, 0,
            CTL_CREATE, CTL_EOL);



Home | Main Index | Thread Index | Old Index