[前][次][番号順一覧][スレッド一覧]

ruby-changes:62825

From: Koichi <ko1@a...>
Date: Fri, 4 Sep 2020 14:19:08 +0900 (JST)
Subject: [ruby-changes:62825] 3b0bcaf287 (master): check multi_ractor mode at main_p

https://git.ruby-lang.org/ruby.git/commit/?id=3b0bcaf287

From 3b0bcaf2872e5ab6d2475e9cd6dd5c374d93ae0b Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Fri, 4 Sep 2020 05:51:55 +0900
Subject: check multi_ractor mode at main_p

rb_ractor_main_p() need to access to the ractor pointer in TLS.
However it is slow operation so that we need to skip this check
if it is not multi-ractor mode (!ruby_multi_ractor).

This performance regression is pointed at
https://bugs.ruby-lang.org/issues/17100#note-27

diff --git a/ractor.c b/ractor.c
index a0cd092..9a8146e 100644
--- a/ractor.c
+++ b/ractor.c
@@ -15,9 +15,12 @@ static VALUE rb_eRactorMovedError; https://github.com/ruby/ruby/blob/trunk/ractor.c#L15
 static VALUE rb_eRactorClosedError;
 static VALUE rb_cRactorMovedObject;
 
+RUBY_SYMBOL_EXPORT_BEGIN
+// to share with MJIT
 bool ruby_multi_ractor;
-static void vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *r, const char *file, int line);
+RUBY_SYMBOL_EXPORT_END
 
+static void vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *r, const char *file, int line);
 
 static void
 ASSERT_ractor_unlocking(rb_ractor_t *r)
@@ -1423,9 +1426,10 @@ rb_ractor_self(const rb_ractor_t *r) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1426
     return r->self;
 }
 
-MJIT_FUNC_EXPORTED int
-rb_ractor_main_p(void)
+MJIT_FUNC_EXPORTED bool
+rb_ractor_main_p_(void)
 {
+    VM_ASSERT(rb_multi_ractor_p());
     rb_execution_context_t *ec = GET_EC();
     return rb_ec_ractor_ptr(ec) == rb_ec_vm_ptr(ec)->ractor.main_ractor;
 }
diff --git a/ractor_pub.h b/ractor_pub.h
index 5062782..5347481 100644
--- a/ractor_pub.h
+++ b/ractor_pub.h
@@ -1,5 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ractor_pub.h#L1
+#ifndef RACTOR_PUB_INCLUDED
+#define RACTOR_PUB_INCLUDED
 
-int rb_ractor_main_p(void);
+RUBY_EXTERN bool ruby_multi_ractor;
+
+bool rb_ractor_main_p_(void);
+
+static inline bool
+rb_ractor_main_p(void)
+{
+    if (!ruby_multi_ractor) {
+        return true;
+    }
+    else {
+        return rb_ractor_main_p_();
+    }
+}
 
 bool rb_ractor_shareable_p_continue(VALUE obj);
 
@@ -31,3 +46,5 @@ void rb_ractor_stdout_set(VALUE); https://github.com/ruby/ruby/blob/trunk/ractor_pub.h#L46
 void rb_ractor_stderr_set(VALUE);
 
 RUBY_SYMBOL_EXPORT_END
+
+#endif
diff --git a/vm_sync.h b/vm_sync.h
index e9cc274..f601143 100644
--- a/vm_sync.h
+++ b/vm_sync.h
@@ -4,6 +4,7 @@ https://github.com/ruby/ruby/blob/trunk/vm_sync.h#L4
 
 #include "vm_core.h"
 #include "vm_debug.h"
+#include "ractor_pub.h"
 
 #if USE_RUBY_DEBUG_LOG
 #define LOCATION_ARGS const char *file, int line
@@ -26,8 +27,6 @@ void rb_vm_barrier(void); https://github.com/ruby/ruby/blob/trunk/vm_sync.h#L27
 void rb_vm_cond_wait(rb_vm_t *vm, rb_nativethread_cond_t *cond);
 void rb_vm_cond_timedwait(rb_vm_t *vm, rb_nativethread_cond_t *cond, unsigned long msec);
 
-extern bool ruby_multi_ractor;
-
 static inline bool
 rb_multi_ractor_p(void)
 {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]