Remove setaffinity of pthread for getaddrinfo

It looks like `sched_getcpu(3)` returns a strange number on some
(virtual?) environments.

I decided to remove the setaffinity mechanism because the performance
does not appear to degrade on a quick benchmark even if removed.

[Bug #20172]
This commit is contained in:
Yusuke Endoh 2024-01-10 19:52:53 +09:00 коммит произвёл David Jensenius
Родитель dff080dc41
Коммит a4890e4b90
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 3C99585F0FFC7101
2 изменённых файлов: 4 добавлений и 46 удалений

Просмотреть файл

@ -706,8 +706,6 @@ SRC
have_func("pthread_create")
have_func("pthread_detach")
have_func("pthread_attr_setaffinity_np")
have_func("sched_getcpu")
$VPATH << '$(topdir)' << '$(top_srcdir)'
create_makefile("socket")

Просмотреть файл

@ -461,7 +461,7 @@ cancel_getaddrinfo(void *ptr)
}
static int
do_pthread_create(pthread_t *th, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
do_pthread_create(pthread_t *th, void *(*start_routine) (void *), void *arg)
{
int limit = 3, ret;
do {
@ -469,7 +469,7 @@ do_pthread_create(pthread_t *th, const pthread_attr_t *attr, void *(*start_routi
//
// https://bugs.openjdk.org/browse/JDK-8268605
// https://github.com/openjdk/jdk/commit/e35005d5ce383ddd108096a3079b17cb0bcf76f1
ret = pthread_create(th, attr, start_routine, arg);
ret = pthread_create(th, 0, start_routine, arg);
} while (ret == EAGAIN && limit-- > 0);
return ret;
}
@ -489,33 +489,13 @@ start:
return EAI_MEMORY;
}
pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
free_getaddrinfo_arg(arg);
return EAI_AGAIN;
}
#if defined(HAVE_PTHREAD_ATTR_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
cpu_set_t tmp_cpu_set;
CPU_ZERO(&tmp_cpu_set);
int cpu = sched_getcpu();
if (cpu < CPU_SETSIZE) {
CPU_SET(cpu, &tmp_cpu_set);
pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &tmp_cpu_set);
}
#endif
pthread_t th;
if (do_pthread_create(&th, &attr, do_getaddrinfo, arg) != 0) {
if (do_pthread_create(&th, do_getaddrinfo, arg) != 0) {
free_getaddrinfo_arg(arg);
return EAI_AGAIN;
}
pthread_detach(th);
int r;
if ((r = pthread_attr_destroy(&attr)) != 0) {
rb_bug_errno("pthread_attr_destroy", r);
}
rb_thread_call_without_gvl2(wait_getaddrinfo, arg, cancel_getaddrinfo, arg);
int need_free = 0;
@ -721,33 +701,13 @@ start:
return EAI_MEMORY;
}
pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
free_getnameinfo_arg(arg);
return EAI_AGAIN;
}
#if defined(HAVE_PTHREAD_ATTR_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
cpu_set_t tmp_cpu_set;
CPU_ZERO(&tmp_cpu_set);
int cpu = sched_getcpu();
if (cpu < CPU_SETSIZE) {
CPU_SET(cpu, &tmp_cpu_set);
pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &tmp_cpu_set);
}
#endif
pthread_t th;
if (do_pthread_create(&th, &attr, do_getnameinfo, arg) != 0) {
if (do_pthread_create(&th, do_getnameinfo, arg) != 0) {
free_getnameinfo_arg(arg);
return EAI_AGAIN;
}
pthread_detach(th);
int r;
if ((r = pthread_attr_destroy(&attr)) != 0) {
rb_bug_errno("pthread_attr_destroy", r);
}
rb_thread_call_without_gvl2(wait_getnameinfo, arg, cancel_getnameinfo, arg);
int need_free = 0;