Module Name:    src
Committed By:   chs
Date:           Mon Feb  6 22:22:12 UTC 2023

Modified Files:
        src/external/cddl/osnet/dist/lib/libdtrace/common: dt_subr.c

Log Message:
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.14 -r1.15 \
    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.14 src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.15
--- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c:1.14	Sun Sep  6 21:49:32 2020
+++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c	Mon Feb  6 22:22:12 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