fix(libSceNKWebKit): read WTF::CPUTime::forCurrentThread from the guest thread clock #20139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20139"
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 MatteoSid on 2026-11-14T17:40:16Z.
What
WTF::CPUTime::forCurrentThread()in libSceNKWebKit (_ZN3WTF7CPUTime16forCurrentThreadEv, NIDGrn1GRcWJio) read the host thread's CPU time and returned 0 when the host could not answer:GetThreadTimes;clock_gettime(CLOCK_THREAD_CPUTIME_ID), converted withtv_nsec * 1e-9.The PS5 11.x port builds
posix/CPUTimePOSIX.cpp(PlatformPlayStation.cmake). ItsCPUTime::forCurrentThreaddoes three things:clock_gettime(CLOCK_THREAD_CPUTIME_ID), which is 14 on FreeBSD;RELEASE_ASSERTs that the call succeeded;Seconds(tv_sec) + Seconds::fromNanoseconds(tv_nsec).fromNanosecondsdivides by 1000 three times.WebKit c55364d53f97 has the same body in
unix/CPUTimeUnix.cpp.Changes:
WtfTime.cppto the newsrc/WtfCpuTime.cpp, which starts with aDerived fromline and the CPUTimePOSIX.cpp notice copied verbatim.clock_gettime(14). On Linux, guest libkernel maps clock 14 to the host'sCLOCK_THREAD_CPUTIME_ID; on Windows it uses the thread's user plus kernel time (CpuTimeNanos). It converts the result asfromNanosecondsdoes.RELEASE_ASSERTcrashes, instead of returning 0.CpuTimeClockForTest_nid_no_patch, like the sysconf hooks of #20053 and #20100.WtfTime.cpp. Only the old function is removed, away from the hunks of #20125, #19380 and #14478.docs/dev/debt/changes/fix-nkwebkit-cputime.md(#17217), a new "WTF::CPUTime::forCurrentThread" entry in the Functional section says the guest answers with the host thread's CPU time, not the console's.CPUTime::forCurrentThreadis dropped from the "WTF host services" line, which #20125 and #20152 rewrote before they merged. The line now ends "... and random values come from the host, not the console".Reachability: the export takes no arguments, so any module that imports it from libSceNKWebKit reaches it directly. In the pinned tree its caller is JSC's watchdog:
Watchdog::startTimersets the CPU deadline from it when script enters a VM that has a time limit.Watchdog::shouldTerminatecompares it with that deadline each time the timer fires.JSContextGroupSetExecutionTimeLimit, which libSceNKWebKit exports (src/JscContext.cpp). TheJSC_watchdogoption arms it too (VM.cpp).Which console modules import this NID has not been checked against a dump.
Tested
Linux (Ubuntu 24.04 container, GCC 13.3), Release,
-DBUILD_TESTING=ON, on head5859eadde4, which mergesmain2db3a6bf65, including #20152. Head917e604ff3only adds a clean merge ofmain6a86d4d1a9and moves the debt changes to the fragment;tools/debt_fold.py --checkpasses on it. Builtcore/libs/libs/libSceNKWebKit.prxand every libSceNKWebKit test target.ctest -R 'nkwebkit|^public_headers$'passes 84 of 84.The new
nkwebkit_wtfcputime(tests/WtfCpuTime.cpp) drives the export throughCpuTimeClockForTest_nid_no_patch. The hook replaces theclock_gettimequery, andnullptrrestores guestclock_gettime_nid_postfix. The test checks:fromNanosecondsresults, which differ fromtv_nsec * 1e-9and fromtv_nsec / 1e9;steady_clock, and requires the increase.The existing
nkwebkit_wtfcheck (forCurrentThread() >= 0) still passes. Guest libkernel'sguest_cpu_time_clocks,guest_thread_cpu_clock,guest_freebsd_clocksandguest_kernel_clockpass on the same build.nkwebkit_wtfcputimepassed 50 of 50 repeats, and 20 of 20 runs pinned to one CPU with four busy loops on it.Negative controls on
db9b19b210, one at a time, in the Docker build. Each makesnkwebkit_wtfcputimefail (no build failures), and the restored tree passes:Earlier controls, on
6ae911cc5c, also failed the test: main's export body inWtfTime.cpp(host thread clock, 0 on failure),tv_nsec * 1e-9,tv_nsec / 1e9,tv_secdropped, a failed read not thrown, and a hook that cannot restore the guest clock.nm -Don the patchedlibSceNKWebKit.prxlistsGrn1GRcWJio0x20 bytes afterCpuTimeClockForTest_nid_no_patch, whereWtfCpuTime.cpp.oplaces_ZN3WTF7CPUTime16forCurrentThreadEv, and the hook keeps its_nid_no_patchname.tools/check_conventions.py --base origin/main --head HEADpasses, andgit diff --check origin/mainis clean.Overlap:
forCurrentThread. Our #20125 (wall and monotonic clocks) and #20152 (local time zone) touched the same "WTF host services" line and are both merged; this branch includes them.WtfTime.cpphunk is at line 324, and its debt changes are in its own fragment, which folds after them.git merge-treewith #14478, #17272 and #19380 also shows no conflicts. #19103 conflicts only inExport.cppandInventoryExports.hpp, which this PR does not touch.tools/pr_overlap.py --branchfound no overlap. It could not compare 23 PRs on the debt file; none of them touchesforCurrentThreador thepageSize,numberOfProcessorCoresorramSizeentries.No title tested.
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 PrivacyOnion on 2026-11-14T17:44:03Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
6ae911cc5c:tools/check_conventions.pypassed;git diff --checkclean.jsc_wtf_cpu_time_testsbuilt cleanly.jsc_wtf_cpu_time):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T18:08:07Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make guest clock ID 14 resolve to the current thread’s CPU clock on supported hosts.
What I ran
Reviewed head
fc5c85ec743acc4d306fb9df5a7218d39c62516b. I read the prepared description, commits, diff, manifest, all included changed source and test files, and targeted guest clock implementation context. No tests or build commands were run.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfCpuTime.cpp:60queries guest clock ID 14, but the guestclock_gettimepath checksIsCpuClock(clockId)before dispatching the ordinary clock IDs.IsCpuClocktests whether the CPU clock bit is set; literal 14 does not have that bit. The subsequent validation therefore rejects 14 as an invalid clock, so the new export throws on every guest-clock read instead of returning thread CPU time. Route this ID to the guest thread CPU clock implementation (or encode the ID as required by that dispatch) and add a test that exercises the actual guest clock path.Non-blocking
None.
Not verified
The full text of
docs/dev/debt/libSceNKWebKit.mdwas excluded as too large; its changed lines were inspected in the prepared diff. No build, tests, console behavior, or title imports were verified. The description reports test results from a prior head, not this reviewed head.To get this to a good state
Fix the clock ID dispatch so this export obtains the current thread’s guest CPU clock, then rerun the relevant build and tests on the new head.
Continued review (pass 2)
The two previously unread added debt lines accurately document the host-backed behavior and the new CPU time export; no blocking defect is evident in this continuation pass.
What I ran
Read
review/description.md,review/commits.md,review/manifest.json, the debt-file hunk inreview/diff.patch, anddocs/dev/debt/libSceNKWebKit.mdlines 123–140 at the pinned head. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The implementation and tests were not reread in this continuation pass. The added CPU time entry's behavior claims therefore rely on the prior review's inspection and the PR description; console behavior remains unverified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T18:13:46Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
fc5c85ec74:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfcputime_testsbuilt cleanly.nkwebkit_wtfcputime):core/libs/prx/libSceNKWebKit/src/WtfTime.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T18:36:46Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
db9b19b210:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfcputime_testsbuilt cleanly.nkwebkit_wtfcputime):core/libs/prx/libSceNKWebKit/src/WtfTime.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T19:04:38Z.
Review: COMMENTED
Reviewed — no blocking findings
The implementation reads guest clock 14 and converts its result as intended; source collection and focused test wiring are present, but I could not run checks in this review environment.
What I ran
Reviewed head
db9b19b21028bb27e84a4a1028f8b7b53470a7b8using the prepared diff and pinned repository reader. No build, test, or merged-preview command was run.Results
Negative control
Not run; no test execution was available.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the added clock implementation, its test, the removed implementation hunk, CMake source and test collection, the guest clock implementation, the export declaration, and the affected technical-debt entries at the pinned head.
Not verified
Build and test results reported in the PR description were not independently verified. Console behavior and which console modules import this NID were not verified. All changed files listed in the manifest were read for the relevant hunks; the debt file was read around both changed lines, not in full. No other files were excluded from this review.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T19:07:48Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
5859eadde4:tools/check_conventions.pypassed;git diff --checkclean.jsc_wtf_cpu_time_testsbuilt cleanly.jsc_wtf_cpu_time):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T19:08:13Z.
Review: COMMENTED
Reviewed — no blocking findings
The implementation and its changed lines were inspected at head
5859eadde40ec812ecf16ca8793c66c927fe0857; no concrete blocking defect was found, but tests were not run in this review.What I ran
Read the prepared diff and manifest, then inspected the changed implementation, test, debt entry, build registration, and guest clock implementation through
repo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Linux build, test suite, repeated runs, and negative controls were not independently run. The changed files were
core/libs/prx/libSceNKWebKit/src/WtfCpuTime.cpp,core/libs/prx/libSceNKWebKit/src/WtfTime.cpp,core/libs/prx/libSceNKWebKit/tests/WtfCpuTime.cpp, anddocs/dev/debt/libSceNKWebKit.md; each was read, with the debt file accessed through the repository reader because it was excluded from the review folder.To get this to a good state
Nothing is required. The implementation's host-independent conversion, guest clock selection, failure handling, and test target registration were inspected; running the reported checks on this head would provide independent verification.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T20:51:22Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
917e604ff3:tools/check_conventions.pypassed;git diff --checkclean.jsc_wtf_cpu_time_testsbuilt cleanly.jsc_wtf_cpu_time):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T21:27:58Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and tests provide evidence for the guest thread clock behavior on the reported Linux build, while console behavior remains unverified.
What I ran
Reviewed head
917e604ff3de161c21ddd1c628bc840d2e248d88usingrepo_read.pyagainst the prepared review bundle and pinned repository. No commands or tests were run during this review. The description reports Linux build and test results; those were not independently run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceNKWebKit/src/WtfCpuTime.cpp,core/libs/prx/libSceNKWebKit/src/WtfTime.cpp,core/libs/prx/libSceNKWebKit/tests/WtfCpuTime.cpp, anddocs/dev/debt/changes/fix-nkwebkit-cputime.md. No changed files were excluded in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T21:18:05Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
917e604ff3:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfcputime_testsbuilt cleanly.nkwebkit_wtfcputime):core/libs/prx/libSceNKWebKit/src/WtfTime.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me