Skip to content

Introduce thread timer interval constants #13955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ struct rb_io;
#define COVERAGE_TARGET_ONESHOT_LINES 8
#define COVERAGE_TARGET_EVAL 16

#define THREAD_TIMER_INTERVAL_MSEC 10
#define THREAD_TIMER_INTERVAL_USEC (THREAD_TIMER_INTERVAL_MSEC * 1000)

#define RUBY_FATAL_THREAD_KILLED INT2FIX(0)
#define RUBY_FATAL_THREAD_TERMINATED INT2FIX(1)
#define RUBY_FATAL_FIBER_KILLED RB_INT2FIX(2)
Expand Down
2 changes: 1 addition & 1 deletion thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
limits_us >>= -th->priority;

if (th->status == THREAD_RUNNABLE)
th->running_time_us += 10 * 1000; // 10ms = 10_000us // TODO: use macro
th->running_time_us += THREAD_TIMER_INTERVAL_USEC;

VM_ASSERT(th->ec->cfp);
EXEC_EVENT_HOOK(th->ec, RUBY_INTERNAL_EVENT_SWITCH, th->ec->cfp->self,
Expand Down
7 changes: 4 additions & 3 deletions thread_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "internal/gc.h"
#include "internal/sanitizers.h"
#include "internal/thread.h"

#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
Expand Down Expand Up @@ -2888,7 +2889,7 @@ static int
timer_thread_set_timeout(rb_vm_t *vm)
{
#if 0
return 10; // ms
return THREAD_TIMER_INTERVAL_MSEC;
#else
int timeout = -1;

Expand All @@ -2904,7 +2905,7 @@ timer_thread_set_timeout(rb_vm_t *vm)
!ubf_threads_empty(),
(vm->ractor.sched.grq_cnt > 0));

timeout = 10; // ms
timeout = THREAD_TIMER_INTERVAL_MSEC;
vm->ractor.sched.timeslice_wait_inf = false;
}
else {
Expand All @@ -2926,7 +2927,7 @@ timer_thread_set_timeout(rb_vm_t *vm)
RUBY_DEBUG_LOG("th:%u now:%lu rel:%lu", rb_th_serial(th), (unsigned long)now, (unsigned long)hrrel);

// TODO: overflow?
timeout = (int)((hrrel + RB_HRTIME_PER_MSEC - 1) / RB_HRTIME_PER_MSEC); // ms
timeout = (int)((hrrel + RB_HRTIME_PER_MSEC - 1) / RB_HRTIME_PER_MSEC);
}
}
rb_native_mutex_unlock(&timer_th.waiting_lock);
Expand Down
4 changes: 2 additions & 2 deletions thread_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION

#include "internal/sanitizers.h"
#include "internal/thread.h"
#include <process.h>

#define TIME_QUANTUM_USEC (10 * 1000)
#define RB_CONDATTR_CLOCK_MONOTONIC 1 /* no effect */

#undef Sleep
Expand Down Expand Up @@ -774,7 +774,7 @@ timer_thread_func(void *dummy)
RUBY_DEBUG_LOG("start");
rb_w32_set_thread_description(GetCurrentThread(), L"ruby-timer-thread");
while (WaitForSingleObject(timer_thread.lock,
TIME_QUANTUM_USEC/1000) == WAIT_TIMEOUT) {
THREAD_TIMER_INTERVAL_MSEC) == WAIT_TIMEOUT) {
vm->clock++;
rb_threadptr_check_signal(vm->ractor.main_thread);
}
Expand Down
2 changes: 1 addition & 1 deletion tool/lib/test/unit/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def assert_no_warning(pat, msg = nil)

def assert_cpu_usage_low(msg = nil, pct: 0.05, wait: 1.0, stop: nil)
wait = EnvUtil.apply_timeout_scale(wait)
if wait < 0.1 # TIME_QUANTUM_USEC in thread_pthread.c
if wait < 0.1 # THREAD_TIMER_INTERVAL_USEC in thread.h
warn "test #{msg || 'assert_cpu_usage_low'} too short to be accurate"
end

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy