+2023-08-13 Bruno Haible <bruno@clisp.org>
+
+ nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD.
+ * lib/nproc.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
+ (num_processors_ignoring_omp): Call sysctl on GNU/kFreeBSD.
+ * lib/physmem.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
+ (physmem_total, physmem_available): Call sysctl on GNU/kFreeBSD.
+
2023-08-13 Bruno Haible <bruno@clisp.org>
physmem: Add tests.
# include <sys/param.h>
#endif
-#if HAVE_SYS_SYSCTL_H && ! defined __GLIBC__
+#if HAVE_SYS_SYSCTL_H && !(defined __GLIBC__ && defined __linux__)
# include <sys/sysctl.h>
#endif
/* 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;
# include <sys/param.h>
#endif
-#if HAVE_SYS_SYSCTL_H && ! defined __GLIBC__
+#if HAVE_SYS_SYSCTL_H && !(defined __GLIBC__ && defined __linux__)
# include <sys/sysctl.h>
#endif
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)
}
#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 };
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)
}
#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 };