qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2 10/28] bsd-user: Get number of cpus.


From: Warner Losh
Subject: Re: [PATCH v2 10/28] bsd-user: Get number of cpus.
Date: Wed, 20 Sep 2023 19:19:38 +0100

This one is almost right... one tweak is needed I think...

On Sun, Sep 17, 2023 at 10:39 PM Karim Taha <kariem.taha2.7@gmail.com> wrote:
From: Kyle Evans <kevans@FreeBSD.org>

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
 bsd-user/bsd-proc.c | 23 +++++++++++++++++++++++
 bsd-user/bsd-proc.h |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c
index 19f6efe1f7..78f5b172d7 100644
--- a/bsd-user/bsd-proc.c
+++ b/bsd-user/bsd-proc.c
@@ -119,3 +119,26 @@ 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);
+    }
+#ifdef _SC_NPROCESSORS_ONLN
+    if (ncpu == -1) {
+        ncpu = sysconf(_SC_NPROCESSORS_ONLN);
+    }
+#endif

I think that the #ifdef and #endif lines can be removed. These are defined
on all version of FreeBSD, NetBSD and OpenBSD (I think also DragonFly)
in the unlikely event that it gets bsd-user support.

With that fixed,

Reviewed by: Warner Losh <imp@bsdimp.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]