Module Name:    src
Committed By:   martin
Date:           Wed Feb 15 18:58:03 UTC 2023

Modified Files:
        src/external/cddl/osnet/dist/lib/libdtrace/common [netbsd-9]: dt_subr.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1596):

        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.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.13.4.1 \
    src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c
diff -u src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.13 src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.13.4.1
--- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.13	Mon May 28 21:05:05 2018
+++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c	Wed Feb 15 18:58:02 2023
@@ -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 @@ dt_ioctl(dtrace_hdl_t *dtp, u_long val, 
 	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 @@ dt_status(dtrace_hdl_t *dtp, processorid
 	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 @@ dt_status(dtrace_hdl_t *dtp, processorid
 		else
 			return (cpu <= maxid ? 1 : -1);
 #endif
+#ifdef __NetBSD__
+		return cpu_online(cpu) ? 1 : -1;
+#endif
 	}
 
 	return (v->dtv_status(dtp->dt_varg, cpu));

Reply via email to