This one is almost right... one tweak is needed I think... On Sun, Sep 17, 2023 at 10:39 PM Karim Taha <kariem.taha...@gmail.com> wrote:
> From: Kyle Evans <kev...@freebsd.org> > > Signed-off-by: Kyle Evans <kev...@freebsd.org> > Signed-off-by: Karim Taha <kariem.taha...@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 <i...@bsdimp.com>