Use a more accurate measurement for the before sleep time

This commit is contained in:
Patrick Fontanilla 2026-06-09 18:48:55 +00:00
parent 0bc1632b51
commit 2e0f52cdfd
3 changed files with 10 additions and 13 deletions

View File

@ -221,22 +221,22 @@ void ShenandoahControlThread::run_service() {
// Wait before performing the next action. If allocation happened during this wait,
// we exit sooner, to let heuristics re-evaluate new conditions. If we are at idle,
// back off exponentially.
const double before_sleep = most_recent_wake_time;
if (heap->has_changed()) {
sleep = ShenandoahControlIntervalMin;
} else if ((before_sleep - last_sleep_adjust_time) * 1000 > ShenandoahControlIntervalAdjustPeriod){
} else if ((most_recent_wake_time - last_sleep_adjust_time) * 1000 > ShenandoahControlIntervalAdjustPeriod){
sleep = MIN2<int>(ShenandoahControlIntervalMax, MAX2(1, sleep * 2));
last_sleep_adjust_time = before_sleep;
last_sleep_adjust_time = most_recent_wake_time;
}
MonitorLocker ml(&_control_lock, Mutex::_no_safepoint_check_flag);
const double before_sleep_time = os::elapsedTime();
ml.wait(sleep);
most_recent_wake_time = os::elapsedTime();
// Record a conservative estimate of the longest anticipated sleep duration until we sample again.
double planned_sleep_interval = MIN2<int>(ShenandoahControlIntervalMax, MAX2(1, sleep * 2)) / 1000.0;
most_recent_wake_time = os::elapsedTime();
heuristics->update_should_start_query_times(most_recent_wake_time, planned_sleep_interval);
if (LogTarget(Debug, gc, thread)::is_enabled()) {
double elapsed = most_recent_wake_time - before_sleep;
double hiccup = elapsed - double(sleep);
double elapsed = most_recent_wake_time - before_sleep_time;
double hiccup = elapsed - double(sleep) / 1000.0;
if (hiccup > 0.001) {
log_debug(gc, thread)("Control Thread hiccup time: %.3fs", hiccup);
}

View File

@ -116,19 +116,17 @@ void ShenandoahRegulatorThread::regulator_sleep() {
// Wait before performing the next action. If allocation happened during this wait,
// we exit sooner, to let heuristics re-evaluate new conditions. If we are at idle,
// back off exponentially.
double before_sleep_time = _most_recent_wake_time;
if (ShenandoahHeap::heap()->has_changed()) {
_sleep = ShenandoahControlIntervalMin;
} else if ((before_sleep_time - _last_sleep_adjust_time) * 1000 > ShenandoahControlIntervalAdjustPeriod){
} else if ((_most_recent_wake_time - _last_sleep_adjust_time) * 1000 > ShenandoahControlIntervalAdjustPeriod){
_sleep = MIN2<uint>(ShenandoahControlIntervalMax, MAX2(1u, _sleep * 2));
_last_sleep_adjust_time = before_sleep_time;
_last_sleep_adjust_time = _most_recent_wake_time;
}
SuspendibleThreadSetLeaver leaver;
const double before_sleep_time = os::elapsedTime();
os::naked_short_sleep(_sleep);
double wake_time = os::elapsedTime();
_most_recent_period = wake_time - _most_recent_wake_time;
_most_recent_wake_time = wake_time;
_most_recent_wake_time = os::elapsedTime();
_young_heuristics->update_should_start_query_times(_most_recent_wake_time, double(_sleep) / 1000.0);
if (LogTarget(Debug, gc, thread)::is_enabled()) {
double elapsed = _most_recent_wake_time - before_sleep_time;

View File

@ -82,7 +82,6 @@ class ShenandoahRegulatorThread: public ConcurrentGCThread {
// duration of planned regulator sleep period, in ms
uint _sleep;
double _most_recent_wake_time;
double _most_recent_period;
double _last_sleep_adjust_time;
};