-
Enhancement
-
Resolution: Fixed
-
P4
-
17, 20, 21
-
b06
-
linux
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8313603 | 21.0.1 | Aleksey Shipilev | P4 | Resolved | Fixed | b06 |
JDK-8313604 | 17.0.9 | Aleksey Shipilev | P4 | Resolved | Fixed | b02 |
It looks like Linux has the "timer slack" feature that coalesces the consecutive high-resolution timer events in order to optimize CPU wakeups. The default seems to be 50us! ...and there is the prctl(PR_SET_TIMERSLACK, ...) call to adjust it. With my quick prototype that drops the timer slack to 1ns, both the Thread.sleep accuracy and TTSP durations improve by tens of microseconds.
There is a /proc/$pid/timerslack_ns interface, but it is inconvenient for two reasons: one needs to find the JVM pid and have permissions to write to /proc. I think there is a system-wide option to change timer slack, but that would affect every process in the system, which might not be a good idea.
It makes sense to provide an experimental option that tunes the per-JVM timer slack.
There is an alternative to look through every use of nanosleep and timed waits in the JDK and make sure we do something else for the delays that are lower than the timer slack. That, however, would eventually come to fighting with the jitter introduced by this OS-side event merge. We need this option to turn the timer slack off for those experiments too.
Additional bonus: if one cranks the timer slack _up_, it emulates the sleep/wait stalls and exposes the pieces of code that over-rely on sleep/wait to return quickly.
Draft PR: https://github.com/openjdk/jdk/pull/13889
- backported by
-
JDK-8313603 Linux: Provide the option to override the timer slack
- Resolved
-
JDK-8313604 Linux: Provide the option to override the timer slack
- Resolved
- relates to
-
JDK-8307782 Compensate for timed wait lags on Thread.sleep paths
- Closed
- links to
-
Commit openjdk/jdk17u-dev/735e1da1
-
Commit openjdk/jdk21u/53aceba7
-
Commit openjdk/jdk/7173c300
-
Review openjdk/jdk17u-dev/1631
-
Review openjdk/jdk21u/21
-
Review openjdk/jdk/13889