Source-Changes-HG archive

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

[src/trunk]: src/external/cddl/osnet/dist/lib/libdtrace/common dtrace: re-fix...



details:   https://anonhg.NetBSD.org/src/rev/35b1dfeb92b5
branches:  trunk
changeset: 373395:35b1dfeb92b5
user:      chs <chs%NetBSD.org@localhost>
date:      Mon Feb 06 22:22:12 2023 +0000

description:
dtrace: re-fix aggregations to report from all online CPUs

Reapply the fix to dt_status() from rev 1.10
("Don't return success when the target CPU is offline")
which was lost in rev 1.12 ("sync with FreeBSD").
The FreeBSD version that we have been using since then does run on NetBSD
but always reports that CPU 0 is online and all other CPUs are offline,
because the sysctl that it uses does not exist on NetBSD.

diffstat:

 external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c |  32 ++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)

diffs (63 lines):

diff -r 0db34bccb4c6 -r 35b1dfeb92b5 external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c
--- a/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   Mon Feb 06 21:20:58 2023 +0000
+++ b/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   Mon Feb 06 22:22:12 2023 +0000
@@ -49,6 +49,11 @@
 #include <libgen.h>
 #include <limits.h>
 #include <stdint.h>
+#ifdef __NetBSD__
+#include <sys/cpuio.h>
+#include <stdbool.h>
+#include <paths.h>
+#endif
 
 #include <dt_impl.h>
 
@@ -501,6 +506,27 @@
        return (-1);
 }
 
+#ifdef __NetBSD__
+static bool
+cpu_online(processorid_t cpu)
+{
+       cpustate_t cs;
+       int fd, online = false;
+
+       if ((fd = open(_PATH_CPUCTL, O_RDONLY)) < 0)
+               return false;
+
+       cs.cs_id = cpu;
+       if (ioctl(fd, IOC_CPU_GETSTATE, &cs) == 0) {
+               if (cs.cs_online)
+                       online = true;
+       }
+
+       close(fd);
+       return online;
+}
+#endif
+
 int
 dt_status(dtrace_hdl_t *dtp, processorid_t cpu)
 {
@@ -509,7 +535,8 @@
        if (v == NULL) {
 #ifdef illumos
                return (p_online(cpu, P_STATUS));
-#else
+#endif
+#ifdef __FreeBSD__
                int maxid = 0;
                size_t len = sizeof(maxid);
                if (sysctlbyname("kern.smp.maxid", &maxid, &len, NULL, 0) != 0)
@@ -517,6 +544,9 @@
                else
                        return (cpu <= maxid ? 1 : -1);
 #endif
+#ifdef __NetBSD__
+               return cpu_online(cpu) ? 1 : -1;
+#endif
        }
 
        return (v->dtv_status(dtp->dt_varg, cpu));



Home | Main Index | Thread Index | Old Index