aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-02 21:13:50 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-02 21:13:50 +0000
commit16d521b5401d70b1eae5ae7f4c41c9755fb6c8df (patch)
tree28232c5efad9b6a3e35e90b0568849ea380fbc33 /thread_pthread.c
parentcc7fa140ab977aab981a68497993bd142dea88d1 (diff)
downloadruby-16d521b5401d70b1eae5ae7f4c41c9755fb6c8df.tar.gz
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index c8487e55f1..b095c2ef1c 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -95,14 +95,20 @@ gvl_acquire_common(rb_vm_t *vm, rb_thread_t *th)
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();