]> git.proxmox.com Git - mirror_qemu.git/commitdiff
bsd-user: Get number of cpus.
authorKyle Evans <kevans@FreeBSD.org>
Mon, 25 Sep 2023 18:24:07 +0000 (21:24 +0300)
committerWarner Losh <imp@bsdimp.com>
Tue, 3 Oct 2023 23:14:06 +0000 (17:14 -0600)
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Message-Id: <20230925182425.3163-11-kariem.taha2.7@gmail.com>

bsd-user/bsd-proc.c
bsd-user/bsd-proc.h

index 19f6efe1f78dc73c8ea8143ca693a289d7795520..ca3c1bf94f4a9a790c8af3358877d44f295e9946 100644 (file)
@@ -119,3 +119,27 @@ int host_to_target_waitstatus(int status)
     return status;
 }
 
+int bsd_get_ncpu(void)
+{
+    int ncpu = -1;
+    cpuset_t mask;
+
+    CPU_ZERO(&mask);
+
+    if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
+                           &mask) == 0) {
+        ncpu = CPU_COUNT(&mask);
+    }
+
+    if (ncpu == -1) {
+        ncpu = sysconf(_SC_NPROCESSORS_ONLN);
+    }
+
+    if (ncpu == -1) {
+        gemu_log("XXX Missing bsd_get_ncpu() implementation\n");
+        ncpu = 1;
+    }
+
+    return ncpu;
+}
+
index 048773a75dd6d3d5936875ee239a21341e33d233..b6225e520eae11024c858795a7328fcc83401735 100644 (file)
@@ -26,6 +26,8 @@
 #include "gdbstub/syscalls.h"
 #include "qemu/plugin.h"
 
+int bsd_get_ncpu(void);
+
 /* exit(2) */
 static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1)
 {