mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread_pthread.c: reduce ubf_timer arming for non-signal wakeups
We do not need to rely on SIGVTALRM for non-sighandler wakeups. This will reduce spurious wakeups in cases where sigwait_fd is not grabbed again, soon. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
960ef493a4
commit
3872ea814c
2 changed files with 24 additions and 11 deletions
|
@ -1162,6 +1162,10 @@ waitpid_nogvl(void *x)
|
||||||
/* another thread calling rb_sigwait_sleep will process
|
/* another thread calling rb_sigwait_sleep will process
|
||||||
* signals for us */
|
* signals for us */
|
||||||
if (SIGCHLD_LOSSY) {
|
if (SIGCHLD_LOSSY) {
|
||||||
|
/*
|
||||||
|
* XXX this may not be needed anymore with new GVL
|
||||||
|
* and sigwait_fd usage
|
||||||
|
*/
|
||||||
rb_thread_wakeup_timer_thread(0);
|
rb_thread_wakeup_timer_thread(0);
|
||||||
}
|
}
|
||||||
rb_native_cond_wait(w->cond, &th->interrupt_lock);
|
rb_native_cond_wait(w->cond, &th->interrupt_lock);
|
||||||
|
|
|
@ -247,7 +247,7 @@ gvl_acquire_common(rb_vm_t *vm, rb_thread_t *th)
|
||||||
vm->gvl.acquired = th;
|
vm->gvl.acquired = th;
|
||||||
if (!vm->gvl.timer) {
|
if (!vm->gvl.timer) {
|
||||||
if (!designate_timer_thread(vm) && !ubf_threads_empty()) {
|
if (!designate_timer_thread(vm) && !ubf_threads_empty()) {
|
||||||
rb_thread_wakeup_timer_thread(0);
|
rb_thread_wakeup_timer_thread(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1327,7 +1327,7 @@ ubf_select(void *ptr)
|
||||||
rb_native_mutex_lock(&vm->gvl.lock);
|
rb_native_mutex_lock(&vm->gvl.lock);
|
||||||
if (!vm->gvl.timer) {
|
if (!vm->gvl.timer) {
|
||||||
if (!designate_timer_thread(vm)) {
|
if (!designate_timer_thread(vm)) {
|
||||||
rb_thread_wakeup_timer_thread(0);
|
rb_thread_wakeup_timer_thread(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_native_mutex_unlock(&vm->gvl.lock);
|
rb_native_mutex_unlock(&vm->gvl.lock);
|
||||||
|
@ -1416,7 +1416,8 @@ static void
|
||||||
ubf_timer_arm(rb_pid_t current) /* async signal safe */
|
ubf_timer_arm(rb_pid_t current) /* async signal safe */
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_POSIX
|
#if UBF_TIMER == UBF_TIMER_POSIX
|
||||||
if (timer_posix.owner == current && !ATOMIC_CAS(timer_posix.armed, 0, 1)) {
|
if ((!current || timer_posix.owner == current) &&
|
||||||
|
!ATOMIC_CAS(timer_posix.armed, 0, 1)) {
|
||||||
struct itimerspec it;
|
struct itimerspec it;
|
||||||
|
|
||||||
it.it_interval.tv_sec = it.it_value.tv_sec = 0;
|
it.it_interval.tv_sec = it.it_value.tv_sec = 0;
|
||||||
|
@ -1446,7 +1447,7 @@ ubf_timer_arm(rb_pid_t current) /* async signal safe */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif UBF_TIMER == UBF_TIMER_PTHREAD
|
#elif UBF_TIMER == UBF_TIMER_PTHREAD
|
||||||
if (current == timer_pthread.owner) {
|
if (!current || current == timer_pthread.owner) {
|
||||||
if (ATOMIC_EXCHANGE(timer_pthread.armed, 1) == 0)
|
if (ATOMIC_EXCHANGE(timer_pthread.armed, 1) == 0)
|
||||||
rb_thread_wakeup_timer_thread_fd(timer_pthread.low[1]);
|
rb_thread_wakeup_timer_thread_fd(timer_pthread.low[1]);
|
||||||
}
|
}
|
||||||
|
@ -1456,8 +1457,19 @@ ubf_timer_arm(rb_pid_t current) /* async signal safe */
|
||||||
void
|
void
|
||||||
rb_thread_wakeup_timer_thread(int sig)
|
rb_thread_wakeup_timer_thread(int sig)
|
||||||
{
|
{
|
||||||
|
rb_pid_t current;
|
||||||
|
|
||||||
|
/* non-sighandler path */
|
||||||
|
if (sig <= 0) {
|
||||||
|
rb_thread_wakeup_timer_thread_fd(signal_self_pipe.normal[1]);
|
||||||
|
if (sig < 0) {
|
||||||
|
ubf_timer_arm(0);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* must be safe inside sighandler, so no mutex */
|
/* must be safe inside sighandler, so no mutex */
|
||||||
rb_pid_t current = getpid();
|
current = getpid();
|
||||||
if (signal_self_pipe.owner_process == current) {
|
if (signal_self_pipe.owner_process == current) {
|
||||||
rb_thread_wakeup_timer_thread_fd(signal_self_pipe.normal[1]);
|
rb_thread_wakeup_timer_thread_fd(signal_self_pipe.normal[1]);
|
||||||
|
|
||||||
|
@ -1465,7 +1477,7 @@ rb_thread_wakeup_timer_thread(int sig)
|
||||||
* system_working check is required because vm and main_thread are
|
* system_working check is required because vm and main_thread are
|
||||||
* freed during shutdown
|
* freed during shutdown
|
||||||
*/
|
*/
|
||||||
if (sig && system_working > 0) {
|
if (system_working > 0) {
|
||||||
volatile rb_execution_context_t *ec;
|
volatile rb_execution_context_t *ec;
|
||||||
rb_vm_t *vm = GET_VM();
|
rb_vm_t *vm = GET_VM();
|
||||||
rb_thread_t *mth;
|
rb_thread_t *mth;
|
||||||
|
@ -1486,9 +1498,6 @@ rb_thread_wakeup_timer_thread(int sig)
|
||||||
ubf_timer_arm(current);
|
ubf_timer_arm(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sig == 0 && system_working > 0) {
|
|
||||||
ubf_timer_arm(current);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue