ruby-changes:64029
From: Koichi <ko1@a...>
Date: Wed, 9 Dec 2020 01:41:02 +0900 (JST)
Subject: [ruby-changes:64029] ee194af2aa (master): re-layout rb_ractor_t
https://git.ruby-lang.org/ruby.git/commit/?id=ee194af2aa From ee194af2aa170c0cb1bfd5fed4e84259a8150ece Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Tue, 8 Dec 2020 00:42:20 +0900 Subject: re-layout rb_ractor_t separate synchronization data and ractor local data. diff --git a/ractor.c b/ractor.c index 7d4404c..4b02b3f 100644 --- a/ractor.c +++ b/ractor.c @@ -37,7 +37,7 @@ ASSERT_ractor_unlocking(rb_ractor_t *r) https://github.com/ruby/ruby/blob/trunk/ractor.c#L37 { #if RACTOR_CHECK_MODE > 0 // GET_EC is NULL in an MJIT worker - if (GET_EC() != NULL && r->locked_by == GET_RACTOR()->self) { + if (GET_EC() != NULL && r->sync.locked_by == GET_RACTOR()->self) { rb_bug("recursive ractor locking"); } #endif @@ -48,8 +48,8 @@ ASSERT_ractor_locking(rb_ractor_t *r) https://github.com/ruby/ruby/blob/trunk/ractor.c#L48 { #if RACTOR_CHECK_MODE > 0 // GET_EC is NULL in an MJIT worker - if (GET_EC() != NULL && r->locked_by != GET_RACTOR()->self) { - rp(r->locked_by); + if (GET_EC() != NULL && r->sync.locked_by != GET_RACTOR()->self) { + rp(r->sync.locked_by); rb_bug("ractor lock is not acquired."); } #endif @@ -61,11 +61,11 @@ ractor_lock(rb_ractor_t *r, const char *file, int line) https://github.com/ruby/ruby/blob/trunk/ractor.c#L61 RUBY_DEBUG_LOG2(file, line, "locking r:%u%s", r->id, GET_RACTOR() == r ? " (self)" : ""); ASSERT_ractor_unlocking(r); - rb_native_mutex_lock(&r->lock); + rb_native_mutex_lock(&r->sync.lock); #if RACTOR_CHECK_MODE > 0 if (GET_EC() != NULL) { // GET_EC is NULL in an MJIT worker - r->locked_by = GET_RACTOR()->self; + r->sync.locked_by = GET_RACTOR()->self; } #endif @@ -76,7 +76,7 @@ static void https://github.com/ruby/ruby/blob/trunk/ractor.c#L76 ractor_lock_self(rb_ractor_t *cr, const char *file, int line) { VM_ASSERT(cr == GET_RACTOR()); - VM_ASSERT(cr->locked_by != cr->self); + VM_ASSERT(cr->sync.locked_by != cr->self); ractor_lock(cr, file, line); } @@ -85,9 +85,9 @@ ractor_unlock(rb_ractor_t *r, const char *file, int line) https://github.com/ruby/ruby/blob/trunk/ractor.c#L85 { ASSERT_ractor_locking(r); #if RACTOR_CHECK_MODE > 0 - r->locked_by = Qnil; + r->sync.locked_by = Qnil; #endif - rb_native_mutex_unlock(&r->lock); + rb_native_mutex_unlock(&r->sync.lock); RUBY_DEBUG_LOG2(file, line, "r:%u%s", r->id, GET_RACTOR() == r ? " (self)" : ""); } @@ -96,7 +96,7 @@ static void https://github.com/ruby/ruby/blob/trunk/ractor.c#L96 ractor_unlock_self(rb_ractor_t *cr, const char *file, int line) { VM_ASSERT(cr == GET_RACTOR()); - VM_ASSERT(cr->locked_by == cr->self); + VM_ASSERT(cr->sync.locked_by == cr->self); ractor_unlock(cr, file, line); } @@ -109,13 +109,13 @@ static void https://github.com/ruby/ruby/blob/trunk/ractor.c#L109 ractor_cond_wait(rb_ractor_t *r) { #if RACTOR_CHECK_MODE > 0 - VALUE locked_by = r->locked_by; - r->locked_by = Qnil; + VALUE locked_by = r->sync.locked_by; + r->sync.locked_by = Qnil; #endif - rb_native_cond_wait(&r->wait.cond, &r->lock); + rb_native_cond_wait(&r->sync.cond, &r->sync.lock); #if RACTOR_CHECK_MODE > 0 - r->locked_by = locked_by; + r->sync.locked_by = locked_by; #endif } @@ -186,11 +186,11 @@ ractor_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L186 { rb_ractor_t *r = (rb_ractor_t *)ptr; - ractor_queue_mark(&r->incoming_queue); - rb_gc_mark(r->wait.taken_basket.v); - rb_gc_mark(r->wait.taken_basket.sender); - rb_gc_mark(r->wait.yielded_basket.v); - rb_gc_mark(r->wait.yielded_basket.sender); + ractor_queue_mark(&r->sync.incoming_queue); + rb_gc_mark(r->sync.wait.taken_basket.v); + rb_gc_mark(r->sync.wait.taken_basket.sender); + rb_gc_mark(r->sync.wait.yielded_basket.v); + rb_gc_mark(r->sync.wait.yielded_basket.sender); rb_gc_mark(r->loc); rb_gc_mark(r->name); rb_gc_mark(r->r_stdin); @@ -224,10 +224,10 @@ static void https://github.com/ruby/ruby/blob/trunk/ractor.c#L224 ractor_free(void *ptr) { rb_ractor_t *r = (rb_ractor_t *)ptr; - rb_native_mutex_destroy(&r->lock); - rb_native_cond_destroy(&r->wait.cond); - ractor_queue_free(&r->incoming_queue); - ractor_waiting_list_free(&r->taking_ractors); + rb_native_mutex_destroy(&r->sync.lock); + rb_native_cond_destroy(&r->sync.cond); + ractor_queue_free(&r->sync.incoming_queue); + ractor_waiting_list_free(&r->sync.taking_ractors); ractor_local_storage_free(r); ruby_xfree(r); } @@ -251,8 +251,8 @@ ractor_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L251 // TODO return sizeof(rb_ractor_t) + - ractor_queue_memsize(&r->incoming_queue) + - ractor_waiting_list_memsize(&r->taking_ractors); + ractor_queue_memsize(&r->sync.incoming_queue) + + ractor_waiting_list_memsize(&r->sync.taking_ractors); } static const rb_data_type_t ractor_data_type = { @@ -407,11 +407,11 @@ ractor_basket_accept(struct rb_ractor_basket *b) https://github.com/ruby/ruby/blob/trunk/ractor.c#L407 static VALUE ractor_try_receive(rb_execution_context_t *ec, rb_ractor_t *r) { - struct rb_ractor_queue *rq = &r->incoming_queue; + struct rb_ractor_queue *rq = &r->sync.incoming_queue; struct rb_ractor_basket basket; if (ractor_queue_deq(r, rq, &basket) == false) { - if (r->incoming_port_closed) { + if (r->sync.incoming_port_closed) { rb_raise(rb_eRactorClosedError, "The incoming port is already closed"); } else { @@ -427,11 +427,11 @@ ractor_sleep_wo_gvl(void *ptr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L427 { rb_ractor_t *cr = ptr; RACTOR_LOCK_SELF(cr); - VM_ASSERT(cr->wait.status != wait_none); - if (cr->wait.wakeup_status == wakeup_none) { + VM_ASSERT(cr->sync.wait.status != wait_none); + if (cr->sync.wait.wakeup_status == wakeup_none) { ractor_cond_wait(cr); } - cr->wait.status = wait_none; + cr->sync.wait.status = wait_none; RACTOR_UNLOCK_SELF(cr); return NULL; } @@ -442,9 +442,9 @@ ractor_sleep_interrupt(void *ptr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L442 rb_ractor_t *r = ptr; RACTOR_LOCK(r); - if (r->wait.wakeup_status == wakeup_none) { - r->wait.wakeup_status = wakeup_by_interrupt; - rb_native_cond_signal(&r->wait.cond); + if (r->sync.wait.wakeup_status == wakeup_none) { + r->sync.wait.wakeup_status = wakeup_by_interrupt; + rb_native_cond_signal(&r->sync.cond); } RACTOR_UNLOCK(r); } @@ -486,9 +486,9 @@ static void https://github.com/ruby/ruby/blob/trunk/ractor.c#L486 ractor_sleep(rb_execution_context_t *ec, rb_ractor_t *cr) { VM_ASSERT(GET_RACTOR() == cr); - VM_ASSERT(cr->wait.status != wait_none); + VM_ASSERT(cr->sync.wait.status != wait_none); // fprintf(stderr, "%s r:%p status:%s, wakeup_status:%s\n", __func__, cr, - // wait_status_str(cr->wait.status), wakeup_status_str(cr->wait.wakeup_status)); + // wait_status_str(cr->sync.wait.status), wakeup_status_str(cr->sync.wait.wakeup_status)); RACTOR_UNLOCK(cr); rb_nogvl(ractor_sleep_wo_gvl, cr, @@ -500,7 +500,7 @@ ractor_sleep(rb_execution_context_t *ec, rb_ractor_t *cr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L500 static bool ractor_sleeping_by(const rb_ractor_t *r, enum ractor_wait_status wait_status) { - return (r->wait.status & wait_status) && r->wait.wakeup_status == wakeup_none; + return (r->sync.wait.status & wait_status) && r->sync.wait.wakeup_status == wakeup_none; } static bool @@ -509,12 +509,12 @@ ractor_wakeup(rb_ractor_t *r, enum ractor_wait_status wait_status, enum ractor_w https://github.com/ruby/ruby/blob/trunk/ractor.c#L509 ASSERT_ractor_locking(r); // fprintf(stderr, "%s r:%p status:%s/%s wakeup_status:%s/%s\n", __func__, r, - // wait_status_str(r->wait.status), wait_status_str(wait_status), - // wakeup_status_str(r->wait.wakeup_status), wakeup_status_str(wakeup_status)); + // wait_status_str(r->sync.wait.status), wait_status_str(wait_status), + // wakeup_status_str(r->sync.wait.wakeup_status), wakeup_status_str(wakeup_status)); if (ractor_sleeping_by(r, wait_status)) { - r->wait.wakeup_status = wakeup_status; - rb_native_cond_signal(&r->wait.cond); + r->sync.wait.wakeup_status = wakeup_status; + rb_native_cond_signal(&r->sync.cond); return true; } else { @@ -536,12 +536,12 @@ ractor_register_taking(rb_ractor_t *r, rb_ractor_t *cr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L536 } else { // insert cr into taking list - struct rb_ractor_waiting_list *wl = &r->taking_ractors; + struct rb_ractor_waiting_list *wl = &r->sync.taking_ractors; for (int i=0; i<wl->cnt; i++) { if (wl->ractors[i] == cr) { // TODO: make it clean code. - rb_native_mutex_unlock(&r->lock); + rb_native_mutex_unlock(&r->sync.lock); rb_raise(rb_eRuntimeError, "Already another thread of same ractor is waiting."); } } @@ -564,11 +564,11 @@ ractor_register_taking(rb_ractor_t *r, rb_ractor_t *cr) https://github.com/ruby/ruby/blob/trunk/ractor.c#L564 if (retry_try) { RACTOR_LOCK(cr); { - if (cr->wait.wakeup_status == wakeup_none) { - VM_ASSERT(cr->wait.status != wait_none); + if (cr->sync.wait.wakeup_status == wakeup_none) { + VM_ASSERT(cr->sync.wait.status != wait_none); - cr->wait.wakeup_status = wakeup_by_retry; - cr->wait.status = wait_none; + cr->sync.wait.wakeup_status = wakeup_by_retry; + cr->sync.wait.status = wait_none; } (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/