From: Bruno Haible Date: Sun, 13 Aug 2023 23:04:36 +0000 (+0200) Subject: nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD. X-Git-Tag: v1.0~909 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e8f4ee468ea4d24fd2c8722e88c56aed3f9e0cf1;p=gnulib.git nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD. * lib/nproc.c: Do include on GNU/kFreeBSD. (num_processors_ignoring_omp): Call sysctl on GNU/kFreeBSD. * lib/physmem.c: Do include on GNU/kFreeBSD. (physmem_total, physmem_available): Call sysctl on GNU/kFreeBSD. --- diff --git a/ChangeLog b/ChangeLog index 05d4466c77..6ed28e97d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-08-13 Bruno Haible + + nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD. + * lib/nproc.c: Do include on GNU/kFreeBSD. + (num_processors_ignoring_omp): Call sysctl on GNU/kFreeBSD. + * lib/physmem.c: Do include on GNU/kFreeBSD. + (physmem_total, physmem_available): Call sysctl on GNU/kFreeBSD. + 2023-08-13 Bruno Haible physmem: Add tests. diff --git a/lib/nproc.c b/lib/nproc.c index 2740c458c1..e3de1873a9 100644 --- a/lib/nproc.c +++ b/lib/nproc.c @@ -46,7 +46,7 @@ # include #endif -#if HAVE_SYS_SYSCTL_H && ! defined __GLIBC__ +#if HAVE_SYS_SYSCTL_H && !(defined __GLIBC__ && defined __linux__) # include #endif @@ -306,7 +306,7 @@ num_processors_ignoring_omp (enum nproc_query query) /* Finally, as fallback, use the APIs that don't distinguish between NPROC_CURRENT and NPROC_ALL. */ -#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_NCPU +#if HAVE_SYSCTL && !(defined __GLIBC__ && defined __linux__) && defined HW_NCPU { /* This works on macOS, FreeBSD, NetBSD, OpenBSD. macOS 10.14 does not allow mib to be const. */ int nprocs; diff --git a/lib/physmem.c b/lib/physmem.c index f450587141..398f99b727 100644 --- a/lib/physmem.c +++ b/lib/physmem.c @@ -50,7 +50,7 @@ # include #endif -#if HAVE_SYS_SYSCTL_H && ! defined __GLIBC__ +#if HAVE_SYS_SYSCTL_H && !(defined __GLIBC__ && defined __linux__) # include #endif @@ -96,7 +96,7 @@ double physmem_total (void) { #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE - { /* This works on linux-gnu, solaris2 and cygwin. */ + { /* This works on linux-gnu, kfreebsd-gnu, solaris2, and cygwin. */ double pages = sysconf (_SC_PHYS_PAGES); double pagesize = sysconf (_SC_PAGESIZE); if (0 <= pages && 0 <= pagesize) @@ -153,8 +153,8 @@ physmem_total (void) } #endif -#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_PHYSMEM - { /* This works on *bsd and darwin. */ +#if HAVE_SYSCTL && !(defined __GLIBC__ && defined __linux__) && defined HW_PHYSMEM + { /* This works on *bsd, kfreebsd-gnu, and darwin. */ unsigned int physmem; size_t len = sizeof physmem; static int mib[2] = { CTL_HW, HW_PHYSMEM }; @@ -208,7 +208,7 @@ double physmem_available (void) { #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE - { /* This works on linux-gnu, solaris2 and cygwin. */ + { /* This works on linux-gnu, kfreebsd-gnu, solaris2, and cygwin. */ double pages = sysconf (_SC_AVPHYS_PAGES); double pagesize = sysconf (_SC_PAGESIZE); if (0 <= pages && 0 <= pagesize) @@ -267,8 +267,8 @@ physmem_available (void) } #endif -#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_USERMEM - { /* This works on *bsd and darwin. */ +#if HAVE_SYSCTL && !(defined __GLIBC__ && defined __linux__) && defined HW_USERMEM + { /* This works on *bsd, kfreebsd-gnu, and darwin. */ unsigned int usermem; size_t len = sizeof usermem; static int mib[2] = { CTL_HW, HW_USERMEM };