This one is almost right... one tweak is needed I think...
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,