ruby-changes:51950
From: normal <ko1@a...>
Date: Fri, 3 Aug 2018 06:13:56 +0900 (JST)
Subject: [ruby-changes:51950] normal:r64165 (trunk): thread_pthread.c (gvl_acquire_common): persist timeout across calls
normal 2018-08-03 06:13:50 +0900 (Fri, 03 Aug 2018) New Revision: 64165 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64165 Log: thread_pthread.c (gvl_acquire_common): persist timeout across calls Reuse old expiration time if the previous native_cond_timedwait did not return ETIMEDOUT. This should improve timeslice accuracy for Timeout.timeout rubyspec without causing excessive wakeups on uncontended GVL acquisition. cf. http://ci.rvm.jp/results/trunk-gc-asserts@silicon-docker/1180486 http://ci.rvm.jp/results/trunk-gc-asserts@silicon-docker/1184623 Modified files: trunk/thread_pthread.c Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 64164) +++ thread_pthread.c (revision 64165) @@ -95,14 +95,20 @@ gvl_acquire_common(rb_vm_t *vm, rb_threa https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L95 list_add_tail(&vm->gvl.waitq, &nd->ubf_list); do { if (!vm->gvl.timer) { - struct timespec ts = { 0, TIME_QUANTUM_USEC * 1000 }; + static struct timespec ts; + static int err = ETIMEDOUT; + /* * become designated timer thread to kick vm->gvl.acquired - * periodically + * periodically. Continue on old timeout if it expired: */ - ts = native_cond_timeout(&nd->cond.gvlq, ts); + if (err == ETIMEDOUT) { + ts.tv_sec = 0; + ts.tv_nsec = TIME_QUANTUM_USEC * 1000; + ts = native_cond_timeout(&nd->cond.gvlq, ts); + } vm->gvl.timer = th; - native_cond_timedwait(&nd->cond.gvlq, &vm->gvl.lock, &ts); + err = native_cond_timedwait(&nd->cond.gvlq, &vm->gvl.lock, &ts); vm->gvl.timer = 0; ubf_wakeup_all_threads(); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/