zend_hrtime: use CLOCK_MONOTONIC instead of CLOCK_MONOTONIC_RAW - #23790
Open
nicolas-grekas wants to merge 1 commit into
Open
nicolas-grekas wants to merge 1 commit into
nicolas-grekas wants to merge 1 commit into
Conversation
CLOCK_MONOTONIC_RAW is not disciplined by NTP, so it ticks with the raw frequency error of the underlying oscillator, which is 4% under WSL2 and makes hrtime() disagree with microtime() by that much. The slew that phpGH-19221 wanted to avoid is bounded to 500ppm by the kernel and is what makes CLOCK_MONOTONIC track elapsed real time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should fix the
hrtime.phptfailure reported in GH-22508.CLOCK_MONOTONIC_RAWis not disciplined by NTP, so it ticks with the raw frequency error of the underlying oscillator. Under WSL2 here, that is 4% fast, measured over a 1s sleep:The relative uncertainty that
ext/standard/tests/hrtime/hrtime.phptcomputes goes from 0.038 back to 0.0002 with this, against the 0.05 the test allows. @mbeccati measured 0.0501 on Ubuntu 26.04 while packaging 8.6.0alpha1 and suggested raising that limit - I think the limit is fine and it is the clock that moved, but a confirmation on that box would be welcome.The adjtime/NTP slew that GH-19221 wanted to avoid is bounded to 500ppm by the kernel, and it is precisely what makes
CLOCK_MONOTONICtrack elapsed real time, which is the contract that test asserts.CLOCK_MONOTONIC_RAWis also served by the vDSO only since Linux 5.3, so on eg. RHEL 8 it costs a syscall per call.I kept the check-the-clock-once part of GH-19221, only the
_RAWpreference goes.