fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME #18197
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18197"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Galluno on 2026-11-10T19:50:26Z.
What
recvmsgon a UDP socket withSO_TIMESTAMPorSO_BINTIMEset now reports when the datagram reached the host socket, instead ofCLOCK_REALTIMEread when the host hands the datagram over.setsockoptturns on the host kernel's receive timestamp for IPv4 and IPv6 datagram sockets:SO_TIMESTAMPNSon Linux,SO_TIMESTAMPon macOS,SIO_TIMESTAMPINGon Windows.recvmsgreads such sockets with the hostrecvmsg(WSARecvMsgon Windows), computes the age of the datagram from the host timestamp and subtracts it from the guestCLOCK_REALTIME. The layout of the control messages and their truncation are unchanged.QueryPerformanceCountervalue only for software timestamps; with NIC hardware timestamps it is the NIC clock. The source is read withGetInterfaceActiveTimestampCapabilitiesover every interface: while one reports an active hardware capability, orERROR_BAD_DRIVER, the counter is not converted and the time is the one at hand-over. The socket does not tell which interface a datagram came from, so one such interface turns the conversion off for all. The answer is cached untilRegisterInterfaceTimestampConfigChangereports a change; without that function it is read for every stamped datagram. Both functions are looked up at run time, since the project's Windows target predates them.SIO_TIMESTAMPINGand its control message type are defined locally: mingw-w64 declares them only forNTDDI_WIN10_FEand later, and the project builds with_WIN32_WINNT=0x0602.guest_udpreads its lower bound before sending, since the arrival time can precede therecvmsgcall.Tested
Windows 11 Pro 10.0.26340, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, head93b74b69b8.ctest -R '^guest_(socket|udp|recvmsg|sendmsg|net)': 60 passed, 0 failed,guest_net_raw_protocolskipped.guest_udpruns on loopback, so on Windows it covers theWSARecvMsgpath and the fallback to the hand-over time for a zero counter.guest_udpalso checks the counter conversion (KernelSocketArrival::CounterAge) with fixed values: a system counter gives its age, and a counter that is not the system's, a zero counter, one ahead of the clock and an unusable frequency all give no age, which is the hand-over time.GetInterfaceActiveTimestampCapabilitieson its 42 interfaces: 3 returnedERROR_NOT_SUPPORTED, the others errors 2, 23 and 31, none reported a hardware capability. Those errors are therefore read as no hardware timestamps; only a reported capability orERROR_BAD_DRIVERturns the conversion off.Not tested: a nonzero Windows counter from a network interface, and an interface with hardware timestamps active (none available here); Linux and macOS, not built or run by me. The hosted
pipe-writemacOS jobs fail at link onNotImplementedAt_nid_no_patch, whichcore/libs/tests/PipeWrite.cppdoes not define; this PR does not touch that call.tools/pr_overlap.pycould not compare the PRs that conflict withmain, so I compared them by hand. Of those that share source files (5021, 7088, 11896, 12682, 12688, 12700, 12965, 14756, 16826) none implements these timestamps. 12104 and 17016 change lines next to this entry indocs/dev/debt/libkernel.md, not the entry itself; whichever merges second needs a trivial rebase.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-10T20:46:33Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The Windows receive path treats every reported timestamp as a QPC value, but the Winsock API also exposes NIC hardware-clock timestamps that require separate conversion.
What I ran
Reviewed head
0e4e62f69e7cb8c3abcdaa7c32d28567a5f01469against base02c52411e5b4df59e192301818182a228a9d353b; the exact head merged cleanly in the repository's merge preview. No local build or C++ test was run.Environment: Linux 6.1 x86_64, Python 3.11.2, GCC 12.2.0.
Results
pipe-writejobs failed at link time; Windows passed.Commands and recorded check output
The report records
diff_check,conventions_and_pr_template,changed_export_abi_audit,live_dependency_and_mergeability_check, andtest_quality_heuristicsas passed.build_and_compileandbuild_dependent_cpp_testswere not run. The precheck recorded the same head and base at completion.Both macOS failures report an undefined
_NotImplementedAt_nid_no_patchreferenced fromGuestSockets::PipeWriteStateinUdp.cpp. That call is unchanged and is present at the same line in the current base; no base macOS build was run, so I cannot establish whether the failure predates this PR.Negative control
No negative control was run. The relevant Windows hardware-clock path cannot be exercised by a safe local mutation on this Linux machine.
Findings
Blocking
Udp.cpplines 2391–2399, every nonzeroSO_TIMESTAMPvalue is compared withQueryPerformanceCounterand converted usingQueryPerformanceFrequency. Microsoft documents that the timestamp may instead come from a NIC hardware clock, whose frequency is device-dependent and whose value must be correlated to the system clock using hardware cross-timestamps. In that case this subtraction can discard the real timestamp or compute an invalid age, so the guest timestamp is wrong. Detect the active timestamp source and convert hardware values correctly, or fall back to hand-over time when the source is hardware. Add coverage for the chosen behavior. The PR's stated Windows loopback test sees a zero counter and therefore does not exercise this path.Non-blocking
None.
Sources
Not verified
pipe-writejobs failed in a separate pipe-write link path; I did not run a base macOS build to determine whether that failure is pre-existing.To get this to a good state
Handle hardware-clock timestamps without treating them as QPC values, and add a test for the hardware-source handling or the explicit fallback. On the new head, rerun
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 18197, the focusedguest_udptest on Windows, and the relevant hosted checks.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-10T20:51:20Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0e4e62f69e:tools/check_conventions.pypassed;git diff --checkclean.pipe-write (macos-15-intel),pipe-write (macos-15).guest_udp_testsbuilt cleanly.guest_udp,guest_udp_name_concurrency,guest_udp_disconnect_result):Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-10T21:17:37Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
93b74b69b8:tools/check_conventions.pypassed;git diff --checkclean.guest_udp_testsbuilt cleanly.guest_udp,guest_udp_name_concurrency,guest_udp_disconnect_result):Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:39:07Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
93b74b69b8:tools/check_conventions.pypassed;git diff --checkclean.pipe-write (macos-15),pipe-write (macos-15-intel),windows.guest_udp_testsbuilt cleanly.guest_udp,guest_udp_name_concurrency,guest_udp_disconnect_result):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T01:27:11Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The Windows timestamp detector treats undocumented interface-query failures as proof that QPC is the system clock, and the exact head also conflicts with current
main.What I ran
Reviewed head
93b74b69b81fe1c387f540d23bbd4259b5be3c03against currentmain073f33fa6c05de20d761443c982f42706f774341. The merge preview conflicts indocs/dev/debt/libkernel.md. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5, GCC 12.2.0.The repository precheck used base
488a446159322b43bd0e47b3ba53bcd2c3f6588a, which is behind currentmain; I did not rely on its mergeability result. I did not run a local build or C++ tests.Results
pipe-writejobs failed on the observed run; their cause was not independently reproduced here.Command output
Negative control
Not run: no Windows build or NIC test was available, so I did not force an interface-query error against the new code.
Findings
Blocking
QueryArrivalSystemCounter,ERROR_BAD_DRIVERmakes the result conservative, but every other nonzero result is skipped whilesystemremainstrue. Microsoft documentsERROR_NOT_SUPPORTEDas the result for a non-timestamp-aware adapter andERROR_BAD_DRIVERfor an unsupported timestamp configuration; it does not document the other observed errors (2,23,31) as proof that the adapter cannot supply hardware timestamps. If every interface query returns one of those errors,ArrivalSystemCounter()can still passtruetoCounterAgeand interpret a hardware-clock value as QPC. Treat an unknown query failure as “counter not known to be QPC” (age zero), while retaining the documentedERROR_NOT_SUPPORTEDcase as no hardware timestamp; add a focused test for this decision.mainindocs/dev/debt/libkernel.md. Rebase onto073f33fa6c05de20d761443c982f42706f774341, preserve both debt entries, then rerun the focused checks.Non-blocking
Sources
Not verified
main073f33fa6c05de20d761443c982f42706f774341.To get this to a good state
Fail closed for undocumented capability-query errors, add a test for that policy, and rebase while preserving the debt entry. I will re-check the same focused commands on the new head.
Pull request closed