ruby-changes:20044
From: kosaki <ko1@a...>
Date: Wed, 15 Jun 2011 01:35:01 +0900 (JST)
Subject: [ruby-changes:20044] kosaki:r32091 (trunk): * thread_pthread.c (gvl_yield): fix live lock issue on 1-2 cpus
kosaki 2011-06-15 01:31:23 +0900 (Wed, 15 Jun 2011) New Revision: 32091 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32091 Log: * thread_pthread.c (gvl_yield): fix live lock issue on 1-2 cpus system. It's additional fix for r32021. * thread_pthread.c (gvl_init): add switch_wait_cond. * thread_pthread.h (typedef struct rb_global_vm_lock_struct): ditto. Modified files: trunk/ChangeLog trunk/thread_pthread.c trunk/thread_pthread.h Index: ChangeLog =================================================================== --- ChangeLog (revision 32090) +++ ChangeLog (revision 32091) @@ -1,3 +1,10 @@ +Wed Jun 15 01:27:53 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * thread_pthread.c (gvl_yield): fix live lock issue on 1-2 cpus + system. It's additional fix for r32021. + * thread_pthread.c (gvl_init): add switch_wait_cond. + * thread_pthread.h (typedef struct rb_global_vm_lock_struct): ditto. + Tue Jun 14 23:16:22 2011 Tanaka Akira <akr@f...> * bootstraptest/runner.rb (show_progress): refine verbose mode. Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 32090) +++ thread_pthread.c (revision 32091) @@ -88,25 +88,35 @@ { native_mutex_lock(&vm->gvl.lock); + __gvl_release(vm); + /* An another thread is processing GVL yield. */ - if (vm->gvl.need_yield) { - native_mutex_unlock(&vm->gvl.lock); - return; + if (UNLIKELY(vm->gvl.wait_yield)) { + while (vm->gvl.wait_yield) + native_cond_wait(&vm->gvl.switch_wait_cond, &vm->gvl.lock); + goto acquire; } + vm->gvl.wait_yield = 1; + if (vm->gvl.waiting > 0) vm->gvl.need_yield = 1; - __gvl_release(vm); if (vm->gvl.need_yield) { /* Wait until another thread task take GVL. */ - native_cond_wait(&vm->gvl.switch_cond, &vm->gvl.lock); - } else { + while (vm->gvl.need_yield) { + native_cond_wait(&vm->gvl.switch_cond, &vm->gvl.lock); + } + } + else { native_mutex_unlock(&vm->gvl.lock); sched_yield(); native_mutex_lock(&vm->gvl.lock); } + vm->gvl.wait_yield = 0; + native_cond_broadcast(&vm->gvl.switch_wait_cond); + acquire: __gvl_acquire(vm); native_mutex_unlock(&vm->gvl.lock); } @@ -119,6 +129,7 @@ native_mutex_initialize(&vm->gvl.lock); native_cond_initialize(&vm->gvl.cond, RB_CONDATTR_CLOCK_MONOTONIC); native_cond_initialize(&vm->gvl.switch_cond, RB_CONDATTR_CLOCK_MONOTONIC); + native_cond_initialize(&vm->gvl.switch_wait_cond, RB_CONDATTR_CLOCK_MONOTONIC); vm->gvl.acquired = 0; vm->gvl.waiting = 0; vm->gvl.need_yield = 0; Index: thread_pthread.h =================================================================== --- thread_pthread.h (revision 32090) +++ thread_pthread.h (revision 32091) @@ -45,7 +45,9 @@ /* yield */ rb_thread_cond_t switch_cond; - unsigned long need_yield; + rb_thread_cond_t switch_wait_cond; + int need_yield; + int wait_yield; } rb_global_vm_lock_t; #endif /* RUBY_THREAD_PTHREAD_H */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/