Also check for pthread_getaffinity_np

GNU/Hurd has the cpuset types and macros, but no pthread_getaffinity_np
yet.
This commit is contained in:
Faidon Liambotis 2023-05-16 17:03:44 +02:00 committed by Samuel Thibault
parent 989914670d
commit 17ae5b5747
3 changed files with 23 additions and 4 deletions

View file

@ -1963,6 +1963,15 @@ dnl Check if we have dlsym support.
fi
fi
dnl Check if pthread_getaffinity_np exists (does not on GNU Hurd)
AC_CHECK_FUNC([pthread_getaffinity_np],
[have_pthread_getaffinity_np="1"],
[have_pthread_getaffinity_np="0"]
)
if test "x$have_pthread_getaffinity_np" = "x1" ; then
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP], [ ])
fi
JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
dnl Check whether clock_gettime(2) is in libc or librt.

View file

@ -116,7 +116,7 @@ set_current_thread_affinity(int cpu) {
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY) || defined(JEMALLOC_HAVE_PTHREAD_SETAFFINITY_NP)
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
cpu_set_t cpuset;
#else
#elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
# ifndef __NetBSD__
cpuset_t cpuset;
# else
@ -124,16 +124,20 @@ set_current_thread_affinity(int cpu) {
# endif
#endif
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY) || defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
#ifndef __NetBSD__
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
#else
cpuset = cpuset_create();
#endif
#else
return 1;
#endif
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
return (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset) != 0);
#else
#elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
# ifndef __NetBSD__
int ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset_t),
&cpuset);

View file

@ -747,8 +747,11 @@ malloc_ncpus(void) {
# endif
# if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
sched_getaffinity(0, sizeof(set), &set);
# else
# elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
pthread_getaffinity_np(pthread_self(), sizeof(set), &set);
# else
CPU_ZERO(&set);
CPU_SET(0, &set);
# endif
result = CPU_COUNT(&set);
}
@ -784,8 +787,11 @@ malloc_cpu_count_is_deterministic()
# endif /* __FreeBSD__ */
# if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
sched_getaffinity(0, sizeof(set), &set);
# else /* !JEMALLOC_HAVE_SCHED_SETAFFINITY */
# elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
pthread_getaffinity_np(pthread_self(), sizeof(set), &set);
# else
CPU_ZERO(&set);
CPU_SET(0, &set);
# endif /* JEMALLOC_HAVE_SCHED_SETAFFINITY */
long cpu_affinity = CPU_COUNT(&set);
if (cpu_affinity != cpu_conf) {