Source-Changes-HG archive

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

[src/netbsd-10]: src/external/cddl/osnet/dist/lib/libdtrace/common Pull up fo...



details:   https://anonhg.NetBSD.org/src/rev/eef4badb5702
branches:  netbsd-10
changeset: 373418:eef4badb5702
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Feb 08 14:40:23 2023 +0000

description:
Pull up following revision(s) (requested by chs in ticket #69):

        external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c: revision 1.15

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 7d8974e4df5f -r eef4badb5702 external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c
--- a/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   Mon Feb 06 16:58:34 2023 +0000
+++ b/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   Wed Feb 08 14:40:23 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