summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNARUSE, Yui <nurse@users.noreply.github.com>2024-02-04 00:47:32 +0900
committerGitHub <noreply@github.com>2024-02-03 15:47:32 +0000
commit53d4e9c4bbba077a569549a01a8263e5e8f59ee8 (patch)
treedec9792296801fd928b40be383e570956389c100
parent45064610725ddd81a5ea3775da35aa46985bc789 (diff)
merge revision(s) 1bd98c820da46a05328d2d53b8f748f28e7ee8f7: [Backport #20172] (#9798)
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] --- ext/socket/extconf.rb | 2 -- ext/socket/raddrinfo.c | 48 ++++-------------------------------------------- 2 files changed, 4 insertions(+), 46 deletions(-)
-rw-r--r--ext/socket/extconf.rb2
-rw-r--r--ext/socket/raddrinfo.c48
2 files changed, 4 insertions, 46 deletions
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 544bed5298..4e8536fc60 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -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")
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index ceaac031a2..560312741f 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -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;