aboutsummaryrefslogtreecommitdiff
path: root/bsd-user
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2023-09-25 21:24:07 +0300
committerWarner Losh <imp@bsdimp.com>2023-10-03 17:14:06 -0600
commitb623031ca60b23dbb8a573306495e7d99821a9af (patch)
tree3a89220e3eaf129be9bb2438daedec3ad48be567 /bsd-user
parent3f44e273ff530ae9885b64791779ced571233d1d (diff)
downloadqemu-b623031ca60b23dbb8a573306495e7d99821a9af.zip
qemu-b623031ca60b23dbb8a573306495e7d99821a9af.tar.gz
qemu-b623031ca60b23dbb8a573306495e7d99821a9af.tar.bz2
bsd-user: Get number of cpus.
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>
Diffstat (limited to 'bsd-user')
-rw-r--r--bsd-user/bsd-proc.c24
-rw-r--r--bsd-user/bsd-proc.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c
index 19f6efe..ca3c1bf 100644
--- a/bsd-user/bsd-proc.c
+++ b/bsd-user/bsd-proc.c
@@ -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;
+}
+
diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h
index 048773a..b6225e5 100644
--- a/bsd-user/bsd-proc.h
+++ b/bsd-user/bsd-proc.h
@@ -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)
{