* lib/nproc.c (num_processors_via_affinity_mask): Retry
with larger affinity masks if CPU_ALLOC_SIZE is available.
+2024-11-11 Florian Weimer <fweimer@redhat.com>
+
+ nproc: Use affinity mask even on systems with more than 1024 CPUs.
+ * lib/nproc.c (num_processors_via_affinity_mask): Retry
+ with larger affinity masks if CPU_ALLOC_SIZE is available.
+
2024-11-11 Bruno Haible <bruno@clisp.org>
acl-permissions: Define the inline functions in this module.
#include <config.h>
#include "nproc.h"
+#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
return count;
}
}
+#elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC \
+ && defined CPU_ALLOC_SIZE /* glibc >= 2.6 */
+ {
+ unsigned int alloc_count = 1024;
+ while (1)
+ {
+ cpu_set_t *set = CPU_ALLOC (alloc_count);
+ if (set == NULL)
+ return 0;
+ unsigned int size = CPU_ALLOC_SIZE (alloc_count);
+ if (sched_getaffinity (0, size, set) == 0)
+ {
+ unsigned int count = CPU_COUNT_S (size, set);
+ CPU_FREE (set);
+ return count;
+ }
+ if (errno != EINVAL)
+ {
+ CPU_FREE (set);
+ return 0;
+ }
+ CPU_FREE (set);
+ alloc_count *= 2;
+ if (alloc_count == 0)
+ return 0;
+ }
+ }
#elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC /* glibc >= 2.3.4 */
{
cpu_set_t set;