fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME #18197

Closed
Galluno wants to merge 3 commits from upstream-pr/18197 into main
Galluno commented 2026-11-10 19:50:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Galluno on 2026-11-10T19:50:26Z.


What

recvmsg on a UDP socket with SO_TIMESTAMP or SO_BINTIME set now reports when the datagram reached the host socket, instead of CLOCK_REALTIME read when the host hands the datagram over.

  • setsockopt turns on the host kernel's receive timestamp for IPv4 and IPv6 datagram sockets: SO_TIMESTAMPNS on Linux, SO_TIMESTAMP on macOS, SIO_TIMESTAMPING on Windows.
  • recvmsg reads such sockets with the host recvmsg (WSARecvMsg on Windows), computes the age of the datagram from the host timestamp and subtracts it from the guest CLOCK_REALTIME. The layout of the control messages and their truncation are unchanged.
  • When the host gives no timestamp the time is the one at hand-over, as before. This is the case on Windows for loopback datagrams (the control message arrives with a zero counter) and before Windows 10 build 20348; the debt entry is narrowed to that.
  • On Windows the counter is a QueryPerformanceCounter value only for software timestamps; with NIC hardware timestamps it is the NIC clock. The source is read with GetInterfaceActiveTimestampCapabilities over every interface: while one reports an active hardware capability, or ERROR_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 until RegisterInterfaceTimestampConfigChange reports 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_TIMESTAMPING and its control message type are defined locally: mingw-w64 declares them only for NTDDI_WIN10_FE and later, and the project builds with _WIN32_WINNT=0x0602.
  • guest_udp reads its lower bound before sending, since the arrival time can precede the recvmsg call.

Tested

Windows 11 Pro 10.0.26340, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, head 93b74b69b8. ctest -R '^guest_(socket|udp|recvmsg|sendmsg|net)': 60 passed, 0 failed, guest_net_raw_protocol skipped.

  • guest_udp runs on loopback, so on Windows it covers the WSARecvMsg path and the fallback to the hand-over time for a zero counter.
  • guest_udp also 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.
  • A separate probe on the same machine called GetInterfaceActiveTimestampCapabilities on its 42 interfaces: 3 returned ERROR_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 or ERROR_BAD_DRIVER turns 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-write macOS jobs fail at link on NotImplementedAt_nid_no_patch, which core/libs/tests/PipeWrite.cpp does not define; this PR does not touch that call.

tools/pr_overlap.py could not compare the PRs that conflict with main, 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 in docs/dev/debt/libkernel.md, not the entry itself; whichever merges second needs a trivial rebase.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5247844763 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18197). Originally posted by [Galluno](https://github.com/Galluno) on 2026-11-10T19:50:26Z. --- ### What `recvmsg` on a UDP socket with `SO_TIMESTAMP` or `SO_BINTIME` set now reports when the datagram reached the host socket, instead of `CLOCK_REALTIME` read when the host hands the datagram over. - `setsockopt` turns on the host kernel's receive timestamp for IPv4 and IPv6 datagram sockets: `SO_TIMESTAMPNS` on Linux, `SO_TIMESTAMP` on macOS, `SIO_TIMESTAMPING` on Windows. - `recvmsg` reads such sockets with the host `recvmsg` (`WSARecvMsg` on Windows), computes the age of the datagram from the host timestamp and subtracts it from the guest `CLOCK_REALTIME`. The layout of the control messages and their truncation are unchanged. - When the host gives no timestamp the time is the one at hand-over, as before. This is the case on Windows for loopback datagrams (the control message arrives with a zero counter) and before Windows 10 build 20348; the debt entry is narrowed to that. - On Windows the counter is a `QueryPerformanceCounter` value only for software timestamps; with NIC hardware timestamps it is the NIC clock. The source is read with `GetInterfaceActiveTimestampCapabilities` over every interface: while one reports an active hardware capability, or `ERROR_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 until `RegisterInterfaceTimestampConfigChange` reports 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_TIMESTAMPING` and its control message type are defined locally: mingw-w64 declares them only for `NTDDI_WIN10_FE` and later, and the project builds with `_WIN32_WINNT=0x0602`. - `guest_udp` reads its lower bound before sending, since the arrival time can precede the `recvmsg` call. ### Tested Windows 11 Pro 10.0.26340, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, head `93b74b69b8`. `ctest -R '^guest_(socket|udp|recvmsg|sendmsg|net)'`: 60 passed, 0 failed, `guest_net_raw_protocol` skipped. - `guest_udp` runs on loopback, so on Windows it covers the `WSARecvMsg` path and the fallback to the hand-over time for a zero counter. - `guest_udp` also 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. - A separate probe on the same machine called `GetInterfaceActiveTimestampCapabilities` on its 42 interfaces: 3 returned `ERROR_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 or `ERROR_BAD_DRIVER` turns 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-write` macOS jobs fail at link on `NotImplementedAt_nid_no_patch`, which `core/libs/tests/PipeWrite.cpp` does not define; this PR does not touch that call. `tools/pr_overlap.py` could not compare the PRs that conflict with `main`, 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 in `docs/dev/debt/libkernel.md`, not the entry itself; whichever merges second needs a trivial rebase. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-10 20:46:33 +00:00 (Migrated from github.com)

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 0e4e62f69e7cb8c3abcdaa7c32d28567a5f01469 against base 02c52411e5b4df59e192301818182a228a9d353b; 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.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 18197 --output-dir /tmp/anyps5-review-18197-current
gh pr checks 18197 -R boykopovar/AnyPS5

Results

Check Result Note
Diff, conventions, ABI audit and test heuristics passed No-build checks passed on the exact head and base.
Merge preview passed Clean against the base above.
Local build and C++ tests not run No local build was needed to identify the Windows clock-source mismatch.
Hosted CI failed Both macOS pipe-write jobs failed at link time; Windows passed.
Commands and recorded check output
/tmp/anyps5-review-18197-current/report.md
/tmp/anyps5-review-18197-current/report.json
Conclusion: checks incomplete

The report records diff_check, conventions_and_pr_template, changed_export_abi_audit, live_dependency_and_mergeability_check, and test_quality_heuristics as passed. build_and_compile and build_dependent_cpp_tests were not run. The precheck recorded the same head and base at completion.

windows: completed, success
pipe-write (macos-15): completed, failure
pipe-write (macos-15-intel): completed, failure
Other build jobs: skipped

Both macOS failures report an undefined _NotImplementedAt_nid_no_patch referenced from GuestSockets::PipeWriteState in Udp.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

  • Windows NIC hardware timestamps are interpreted in the wrong clock domain. At Udp.cpp lines 2391–2399, every nonzero SO_TIMESTAMP value is compared with QueryPerformanceCounter and converted using QueryPerformanceFrequency. 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

  • Windows NIC receive timestamps with a nonzero counter; the PR says its Windows loopback test did not produce one.
  • Linux and macOS builds or runtime behavior. The two hosted macOS pipe-write jobs failed in a separate pipe-write link path; I did not run a base macOS build to determine whether that failure is pre-existing.
  • Console behavior or a physical PS5 run.

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 focused guest_udp test on Windows, and the relevant hosted checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5849076731 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18197#pullrequestreview-5849076731). Originally posted by [MarcZX10](https://github.com/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 `0e4e62f69e7cb8c3abcdaa7c32d28567a5f01469` against base `02c52411e5b4df59e192301818182a228a9d353b`; 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. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 18197 --output-dir /tmp/anyps5-review-18197-current gh pr checks 18197 -R boykopovar/AnyPS5 ``` ## Results | Check | Result | Note | |---|---|---| | Diff, conventions, ABI audit and test heuristics | passed | No-build checks passed on the exact head and base. | | Merge preview | passed | Clean against the base above. | | Local build and C++ tests | not run | No local build was needed to identify the Windows clock-source mismatch. | | Hosted CI | failed | Both macOS `pipe-write` jobs failed at link time; Windows passed. | <details> <summary>Commands and recorded check output</summary> ```text /tmp/anyps5-review-18197-current/report.md /tmp/anyps5-review-18197-current/report.json Conclusion: checks incomplete ``` The report records `diff_check`, `conventions_and_pr_template`, `changed_export_abi_audit`, `live_dependency_and_mergeability_check`, and `test_quality_heuristics` as passed. `build_and_compile` and `build_dependent_cpp_tests` were not run. The precheck recorded the same head and base at completion. ```text windows: completed, success pipe-write (macos-15): completed, failure pipe-write (macos-15-intel): completed, failure Other build jobs: skipped ``` Both macOS failures report an undefined `_NotImplementedAt_nid_no_patch` referenced from `GuestSockets::PipeWriteState` in `Udp.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. </details> ## 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 - **Windows NIC hardware timestamps are interpreted in the wrong clock domain.** At `Udp.cpp` lines 2391–2399, every nonzero `SO_TIMESTAMP` value is compared with `QueryPerformanceCounter` and converted using `QueryPerformanceFrequency`. 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 - [Changed Windows timestamp conversion at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/0e4e62f69e7cb8c3abcdaa7c32d28567a5f01469/core/libs/prx/libkernel/Socket/src/Udp.cpp#L2391-L2399) - [Microsoft Winsock timestamping: timestamp source and receive conversion](https://learn.microsoft.com/en-us/windows/win32/winsock/winsock-timestamping) - [Microsoft packet timestamping: active interface capabilities and hardware cross-timestamps](https://learn.microsoft.com/en-us/windows/win32/iphlp/packet-timestamping) ## Not verified - Windows NIC receive timestamps with a nonzero counter; the PR says its Windows loopback test did not produce one. - Linux and macOS builds or runtime behavior. The two hosted macOS `pipe-write` jobs failed in a separate pipe-write link path; I did not run a base macOS build to determine whether that failure is pre-existing. - Console behavior or a physical PS5 run. ## 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 focused `guest_udp` test on Windows, and the relevant hosted checks.
PrivacyOnion commented 2026-11-10 20:51:20 +00:00 (Migrated from github.com)

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:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • GitHub CI: failing check(s): pipe-write (macos-15-intel), pipe-write (macos-15).
  • Build: guest_udp_tests built cleanly.
  • CTest (guest_udp, guest_udp_name_concurrency, guest_udp_disconnect_result):
    1/3 Test #4393: guest_udp_name_concurrency .......***Not Run   0.00 sec
    2/3 Test #4394: guest_udp_disconnect_result ......***Not Run   0.00 sec
    3/3 Test #4392: guest_udp ........................   Passed    0.60 sec
    33% tests passed, 2 tests failed out of 3
    
    The following tests FAILED:
    
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5849147127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18197#pullrequestreview-5849147127). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-10T20:51:20Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `0e4e62f69e`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **GitHub CI**: failing check(s): `pipe-write (macos-15-intel)`, `pipe-write (macos-15)`. - **Build**: `guest_udp_tests` built cleanly. - **CTest** (`guest_udp`, `guest_udp_name_concurrency`, `guest_udp_disconnect_result`): ``` 1/3 Test #4393: guest_udp_name_concurrency .......***Not Run 0.00 sec 2/3 Test #4394: guest_udp_disconnect_result ......***Not Run 0.00 sec 3/3 Test #4392: guest_udp ........................ Passed 0.60 sec 33% tests passed, 2 tests failed out of 3 ``` ``` The following tests FAILED: ``` - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-10 21:17:37 +00:00 (Migrated from github.com)

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:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_udp_tests built cleanly.
  • CTest (guest_udp, guest_udp_name_concurrency, guest_udp_disconnect_result):
    1/3 Test #4393: guest_udp_name_concurrency .......***Not Run   0.00 sec
    2/3 Test #4394: guest_udp_disconnect_result ......***Not Run   0.00 sec
    3/3 Test #4392: guest_udp ........................   Passed    0.62 sec
    33% tests passed, 2 tests failed out of 3
    
    The following tests FAILED:
    
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5849586116 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18197#pullrequestreview-5849586116). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-10T21:17:37Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `93b74b69b8`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_udp_tests` built cleanly. - **CTest** (`guest_udp`, `guest_udp_name_concurrency`, `guest_udp_disconnect_result`): ``` 1/3 Test #4393: guest_udp_name_concurrency .......***Not Run 0.00 sec 2/3 Test #4394: guest_udp_disconnect_result ......***Not Run 0.00 sec 3/3 Test #4392: guest_udp ........................ Passed 0.62 sec 33% tests passed, 2 tests failed out of 3 ``` ``` The following tests FAILED: ``` - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-11 18:39:07 +00:00 (Migrated from github.com)

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:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • GitHub CI: failing check(s): pipe-write (macos-15), pipe-write (macos-15-intel), windows.
  • Build: guest_udp_tests built cleanly.
  • CTest (guest_udp, guest_udp_name_concurrency, guest_udp_disconnect_result):
    1/3 Test #4394: guest_udp_disconnect_result ......   Passed    0.03 sec
    2/3 Test #4393: guest_udp_name_concurrency .......   Passed    0.27 sec
    3/3 Test #4392: guest_udp ........................   Passed    0.60 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: the tests still pass with the change reverted, so they do not cover it
  • Code reading:
    • core/libs/prx/libkernel/Socket/include/SocketArrivalAge.hpp: Verified KernelSocketArrival::CounterAge for division-by-zero (rate == 0), counter reversal (arrived > current), null counter (arrived == 0), overflow guards (rate > UINT64_MAX / Second, elapsed / rate > LongestSeconds), and nanosecond scaling precision.
    • core/libs/prx/libkernel/Socket/src/SocketOptions.cpp: Verified SetSocketLevelOption activates SO_TIMESTAMPNS on Linux, SO_TIMESTAMP on macOS, and SIO_TIMESTAMPING via _WSAIOW(IOC_VENDOR, 235) on Windows for IPv4 and IPv6 datagram sockets, and disables host timestamping when both GuestTimestamp and GuestBinaryTime are cleared.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified ReceiveStamped safely parses ancillary control messages (SCM_TIMESTAMPNS on Linux, SCM_TIMESTAMP on macOS, 0x300A on Windows) with bounds checks against CMSG_LEN/WSA_CMSG_LEN, avoids host clock skew via std::maxstd::int64_t(0, ...), and handles WSAEMSGSIZE datagram truncation.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified QueryArrivalSystemCounter and ArrivalSystemCounter dynamically query GetInterfaceActiveTimestampCapabilities and RegisterInterfaceTimestampConfigChange from iphlpapi.dll, handle ERROR_BAD_DRIVER and active hardware flags, free MIB tables with FreeMibTable, and guard state with std::mutex and std::atomic.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified ArrivalTimestamps correctly borrows seconds when nanosecond remainder is negative, formats 32-byte records for SCM_BINTIME (type 4) and SCM_TIMESTAMP (type 2) under SOL_SOCKET (0xffff), and restricts binary timestamps to IPv4.
    • core/libs/tests/GuestUdp.cpp & docs/dev/debt/libkernel.md: Verified CheckArrivalCounterAge covers boundary and overflow inputs, CheckArrivalTimestamps samples baseline time before transmission, and docs/dev/debt/libkernel.md accurately documents the Windows loopback/pre-20348 fallback debt.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5863734953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18197#pullrequestreview-5863734953). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T18:39:07Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `93b74b69b8`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **GitHub CI**: failing check(s): `pipe-write (macos-15)`, `pipe-write (macos-15-intel)`, `windows`. - **Build**: `guest_udp_tests` built cleanly. - **CTest** (`guest_udp`, `guest_udp_name_concurrency`, `guest_udp_disconnect_result`): ``` 1/3 Test #4394: guest_udp_disconnect_result ...... Passed 0.03 sec 2/3 Test #4393: guest_udp_name_concurrency ....... Passed 0.27 sec 3/3 Test #4392: guest_udp ........................ Passed 0.60 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: the tests still pass with the change reverted, so they do not cover it - **Code reading**: - core/libs/prx/libkernel/Socket/include/SocketArrivalAge.hpp: Verified KernelSocketArrival::CounterAge for division-by-zero (rate == 0), counter reversal (arrived > current), null counter (arrived == 0), overflow guards (rate > UINT64_MAX / Second, elapsed / rate > LongestSeconds), and nanosecond scaling precision. - core/libs/prx/libkernel/Socket/src/SocketOptions.cpp: Verified SetSocketLevelOption activates SO_TIMESTAMPNS on Linux, SO_TIMESTAMP on macOS, and SIO_TIMESTAMPING via _WSAIOW(IOC_VENDOR, 235) on Windows for IPv4 and IPv6 datagram sockets, and disables host timestamping when both GuestTimestamp and GuestBinaryTime are cleared. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified ReceiveStamped safely parses ancillary control messages (SCM_TIMESTAMPNS on Linux, SCM_TIMESTAMP on macOS, 0x300A on Windows) with bounds checks against CMSG_LEN/WSA_CMSG_LEN, avoids host clock skew via std::max<std::int64_t>(0, ...), and handles WSAEMSGSIZE datagram truncation. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified QueryArrivalSystemCounter and ArrivalSystemCounter dynamically query GetInterfaceActiveTimestampCapabilities and RegisterInterfaceTimestampConfigChange from iphlpapi.dll, handle ERROR_BAD_DRIVER and active hardware flags, free MIB tables with FreeMibTable, and guard state with std::mutex and std::atomic. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified ArrivalTimestamps correctly borrows seconds when nanosecond remainder is negative, formats 32-byte records for SCM_BINTIME (type 4) and SCM_TIMESTAMP (type 2) under SOL_SOCKET (0xffff), and restricts binary timestamps to IPv4. - core/libs/tests/GuestUdp.cpp & docs/dev/debt/libkernel.md: Verified CheckArrivalCounterAge covers boundary and overflow inputs, CheckArrivalTimestamps samples baseline time before transmission, and docs/dev/debt/libkernel.md accurately documents the Windows loopback/pre-20348 fallback debt. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
MarcZX10 commented 2026-11-12 01:27:11 +00:00 (Migrated from github.com)

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 93b74b69b81fe1c387f540d23bbd4259b5be3c03 against current main 073f33fa6c05de20d761443c982f42706f774341. The merge preview conflicts in docs/dev/debt/libkernel.md. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5, GCC 12.2.0.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 18197 --output-dir /tmp/anyps5-pr-precheck-18197
git diff --check refs/review/session-20261112-18197/main-latest...93b74b69b81fe1c387f540d23bbd4259b5be3c03
python3 tools/check_conventions.py --base refs/review/session-20261112-18197/main-latest --head 93b74b69b81fe1c387f540d23bbd4259b5be3c03 --title "fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME" --body /tmp/anyps5-pr18197-body.md
git merge-tree --write-tree refs/review/session-20261112-18197/main-latest 93b74b69b81fe1c387f540d23bbd4259b5be3c03
gh pr checks 18197 --repo boykopovar/AnyPS5

The repository precheck used base 488a446159322b43bd0e47b3ba53bcd2c3f6588a, which is behind current main; I did not rely on its mergeability result. I did not run a local build or C++ tests.

Results

Check Result Note
Diff check passed No whitespace errors.
Conventions passed Current-head conventions pass against the refreshed base.
Merge preview failed Conflict in the libkernel debt entry.
Hosted CI failed Windows and both macOS pipe-write jobs failed on the observed run; their cause was not independently reproduced here.
Windows counter-error behavior failed Unrecognized query errors can leave the system-counter flag true.
Command output
$ git diff --check refs/review/session-20261112-18197/main-latest...93b74b69b81fe1c387f540d23bbd4259b5be3c03
(no output; exit 0)

$ python3 tools/check_conventions.py --base refs/review/session-20261112-18197/main-latest --head 93b74b69b81fe1c387f540d23bbd4259b5be3c03 --title "fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME" --body /tmp/anyps5-pr18197-body.md
All conventions checks passed.

$ git merge-tree --write-tree refs/review/session-20261112-18197/main-latest 93b74b69b81fe1c387f540d23bbd4259b5be3c03
14aad8bbb3dbb5f877ce207db4bb9f1d8eba828e
100644 8f806ec0bb7f3760cb8f9947a0184d322e529286 1 docs/dev/debt/libkernel.md
100644 a82dec87e778d604a20fc1a7aa32821de627577c 2 docs/dev/debt/libkernel.md
100644 319b5546ebbf3f3f951d409c8cec08c9cefaca85 3 docs/dev/debt/libkernel.md
Auto-merging docs/dev/debt/libkernel.md
CONFLICT (content): Merge conflict in docs/dev/debt/libkernel.md

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

  • In QueryArrivalSystemCounter, ERROR_BAD_DRIVER makes the result conservative, but every other nonzero result is skipped while system remains true. Microsoft documents ERROR_NOT_SUPPORTED as the result for a non-timestamp-aware adapter and ERROR_BAD_DRIVER for 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 pass true to CounterAge and interpret a hardware-clock value as QPC. Treat an unknown query failure as “counter not known to be QPC” (age zero), while retaining the documented ERROR_NOT_SUPPORTED case as no hardware timestamp; add a focused test for this decision.
  • The head conflicts with current main in docs/dev/debt/libkernel.md. Rebase onto 073f33fa6c05de20d761443c982f42706f774341, preserve both debt entries, then rerun the focused checks.

Non-blocking

  • The Linux runs reported in the discussion exercise the Linux timestamp path; they do not exercise this Windows interface-capability decision.

Sources

Not verified

  • I did not reproduce the Windows NIC query errors or run the new path on Windows.
  • The repository precheck's base snapshot was stale; the merge conflict above was independently reproduced against current main 073f33fa6c05de20d761443c982f42706f774341.
  • No local build, Windows test, or console test was run.

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5867628620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18197#pullrequestreview-5867628620). Originally posted by [MarcZX10](https://github.com/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 `93b74b69b81fe1c387f540d23bbd4259b5be3c03` against current `main` `073f33fa6c05de20d761443c982f42706f774341`. The merge preview conflicts in `docs/dev/debt/libkernel.md`. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5, GCC 12.2.0. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 18197 --output-dir /tmp/anyps5-pr-precheck-18197 git diff --check refs/review/session-20261112-18197/main-latest...93b74b69b81fe1c387f540d23bbd4259b5be3c03 python3 tools/check_conventions.py --base refs/review/session-20261112-18197/main-latest --head 93b74b69b81fe1c387f540d23bbd4259b5be3c03 --title "fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME" --body /tmp/anyps5-pr18197-body.md git merge-tree --write-tree refs/review/session-20261112-18197/main-latest 93b74b69b81fe1c387f540d23bbd4259b5be3c03 gh pr checks 18197 --repo boykopovar/AnyPS5 ``` The repository precheck used base `488a446159322b43bd0e47b3ba53bcd2c3f6588a`, which is behind current `main`; I did not rely on its mergeability result. I did not run a local build or C++ tests. ## Results | Check | Result | Note | |---|---|---| | Diff check | passed | No whitespace errors. | | Conventions | passed | Current-head conventions pass against the refreshed base. | | Merge preview | failed | Conflict in the libkernel debt entry. | | Hosted CI | failed | Windows and both macOS `pipe-write` jobs failed on the observed run; their cause was not independently reproduced here. | | Windows counter-error behavior | failed | Unrecognized query errors can leave the system-counter flag true. | <details> <summary>Command output</summary> ```text $ git diff --check refs/review/session-20261112-18197/main-latest...93b74b69b81fe1c387f540d23bbd4259b5be3c03 (no output; exit 0) $ python3 tools/check_conventions.py --base refs/review/session-20261112-18197/main-latest --head 93b74b69b81fe1c387f540d23bbd4259b5be3c03 --title "fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME" --body /tmp/anyps5-pr18197-body.md All conventions checks passed. $ git merge-tree --write-tree refs/review/session-20261112-18197/main-latest 93b74b69b81fe1c387f540d23bbd4259b5be3c03 14aad8bbb3dbb5f877ce207db4bb9f1d8eba828e 100644 8f806ec0bb7f3760cb8f9947a0184d322e529286 1 docs/dev/debt/libkernel.md 100644 a82dec87e778d604a20fc1a7aa32821de627577c 2 docs/dev/debt/libkernel.md 100644 319b5546ebbf3f3f951d409c8cec08c9cefaca85 3 docs/dev/debt/libkernel.md Auto-merging docs/dev/debt/libkernel.md CONFLICT (content): Merge conflict in docs/dev/debt/libkernel.md ``` </details> ## 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 - In `QueryArrivalSystemCounter`, `ERROR_BAD_DRIVER` makes the result conservative, but every other nonzero result is skipped while `system` remains `true`. Microsoft documents `ERROR_NOT_SUPPORTED` as the result for a non-timestamp-aware adapter and `ERROR_BAD_DRIVER` for 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 pass `true` to `CounterAge` and interpret a hardware-clock value as QPC. Treat an unknown query failure as “counter not known to be QPC” (age zero), while retaining the documented `ERROR_NOT_SUPPORTED` case as no hardware timestamp; add a focused test for this decision. - The head conflicts with current `main` in `docs/dev/debt/libkernel.md`. Rebase onto `073f33fa6c05de20d761443c982f42706f774341`, preserve both debt entries, then rerun the focused checks. ### Non-blocking - The Linux runs reported in the discussion exercise the Linux timestamp path; they do not exercise this Windows interface-capability decision. ## Sources - [Windows API return values](https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getinterfaceactivetimestampcapabilities) - [Current Windows counter-classification code](https://github.com/boykopovar/AnyPS5/blob/93b74b69b81fe1c387f540d23bbd4259b5be3c03/core/libs/prx/libkernel/Socket/src/Udp.cpp#L2375-L2390) - [Debt entry on the reviewed head](https://github.com/boykopovar/AnyPS5/blob/93b74b69b81fe1c387f540d23bbd4259b5be3c03/docs/dev/debt/libkernel.md) - [Current-main branch-up-to-date rule](https://github.com/boykopovar/AnyPS5/blob/073f33fa6c05de20d761443c982f42706f774341/CONTRIBUTING.md#L59-L63) ## Not verified - I did not reproduce the Windows NIC query errors or run the new path on Windows. - The repository precheck's base snapshot was stale; the merge conflict above was independently reproduced against current `main` `073f33fa6c05de20d761443c982f42706f774341`. - No local build, Windows test, or console test was run. ## 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!18197
No description provided.