Skip to content

Commit

Permalink
bsd-user: Get number of cpus.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kevans91 authored and bsdimp committed Oct 3, 2023
1 parent 3f44e27 commit b623031
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bsd-user/bsd-proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

2 changes: 2 additions & 0 deletions bsd-user/bsd-proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit b623031

Please sign in to comment.