zend_hrtime: use CLOCK_MONOTONIC instead of CLOCK_MONOTONIC_RAW - #23790
Conversation
|
@marc-mabe as the original author of #19221. |
|
95003a4 to
eb781b5
Compare
|
Right, PR updated: the variable is gone. What I meant to keep is the startup check, which lets I also retargeted to PHP-8.6: that's where the |
eb781b5 to
2c491c1
Compare
|
PR updated, the variable is back. I'll send its removal to master once this is merged up. |
|
Thanks for tracking this down, and you're right. I read the man page's note that "´CLOCK_MONOTONIC_RAW Keeping the startup check is enough. LGTM, and +1 to dropping zend_hrtime_posix_clock_id in master. |
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. zend_hrtime_posix_clock_id stays for ABI compatibility, but nothing reads it anymore.
2c491c1 to
a9b64d5
Compare
|
I just made a final adjustment to the error message, merged the latest PHP 8.6 and added NEWS. Will merge when CI is green. |
* PHP-8.6: zend_hrtime: use CLOCK_MONOTONIC instead of CLOCK_MONOTONIC_RAW (#23790)
* PHP-8.6: (61 commits) zend_hrtime: use CLOCK_MONOTONIC instead of CLOCK_MONOTONIC_RAW (php#23790) sapi/cli: Fix built-in server truncating responses after a partial write Fix phpGH-24006: Skip gh18431.phpt when libzip lacks progress callbacks (php#24009) Updated to version 2026.5 (2026e) Fix phpGH-23896: Assertion failure in zend_call_function() after a throwing deprecation NEWS ext/gd: fix undefined behavior with GIFs with problematic LZW compression data Document missing deprecation entries for PHP 8.6 (php#23972) ext/tidy: Reject tidyNode use after the document is reparsed ext/bcmath: Clear the sign of BcMath\Number results that truncate to zero Fix phpGH-23980: ZEND_ASSERT violation @ ZEND_INCLUDE_OR_EVAL (include/eval run with a pending exception) Fix phpGH-23842: skipLazyInitialization() copies unresolved constant defaults Fall back to epoll_wait when epoll_pwait2 is unavailable at runtime (php#23825) openssl: Fix memory leak by doing early salt validation ext/libxml: Keep SimpleXML children alive across reconstruction Fix phpGH-23741: pdo_dblib use-after-free of statement error state NEWS Fix property hook escape analysis causing misoptimization Fix __isset escape analysis causing misoptimization Fix memory leak when closing a statement on a killed connection ...
Nothing reads it since GH-23790, which kept it on PHP-8.6 for ABI compatibility only.
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 startup check from GH-19221, so that
zend_hrtime()doesn't need to check whatclock_gettime()returns.zend_hrtime_posix_clock_idstays for ABI compatibility even if it's now alwaysCLOCK_MONOTONIC; removing it is for master.