feat(libSceNKWebKit): implement WTF ParkingLot and the lock slow paths #21432
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21432"
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 RiverWhy on 2026-11-16T06:00:50Z.
What
Implements
WTF::ParkingLotand the WTF locks built on it: 16 exports. They are ported from ParkingLot.cpp,Lock.cpp,LockAlgorithmInlines.h,Condition.h,WordLock.cpp,ReadWriteLock.cppandthreads/BinarySemaphore.cppate12a212a531a, the 2021 revision whose WTF ABI the module matches. EveryWTF::Lock,ConditionandBinarySemaphorethat guest code inlines falls back to these when there is contention, and they all throw onmaintoday.ParkingLot(5):parkConditionallyImpl,unparkOne,unparkOneImpl,unparkCount,unparkAll.beforeSleep, then waits until it is unparked or the timeout passes. The timeout is aTimeWithDynamicClockTypeand is compared on its own clock; infinity waits forever.unparkOneImplruns under the bucket lock with{didUnparkThread, mayHaveMoreThreads, timeToBeFair}. Its token goes to the woken thread.WeakRandom, seeded with the bucket address.Lock(3):lockSlow,unlockSlowandsafepointSlow, which is a fair unlock plus a relock. These areLockAlgorithm<uint8_t, 1, 2>: spin 40 times, set the parked bit,compareAndPark. On unlock, a direct handoff happens when the unlock is fair or the bucket says it is time to be fair; otherwise it barges and keeps the parked bit while more threads may be waiting.WordLock(2): the queue lock with its waiters on their own stacks, as in the source.ReadWriteLock(4) andBinarySemaphore(signal,waitUntil): the source over the guest object's ownLockandConditionbytes, so they interoperate with guest code that inlines those.Layout and ABI, measured on a Linux build of that revision (
sizeof/offsetof, generated assembly) and checked withstatic_asserts:ReadWriteLockis 12 bytes (lock, condition, write flag, readers at 4, waiting writers at 8), andBinarySemaphoreis 3.ScopedLambdais{impl, arg}, and guest lambdas are called with the guest ABI.ParkResultcomes back inrax:rdx, andUnparkResult(3 bytes) is returned ineaxand passed to the callback inesi.The difference from the source: parked threads wait on host mutexes in a fixed table of 1024 buckets. The source's table grows with the thread count. Only speed and how often
mayHaveMoreThreadscomes back true when unrelated addresses share a bucket differ, and the source only promises a "may" there.forEachImplstill throws: it passes each parkedWTF::Thread, which is not implemented.A null object, lambda or time throws.
Debt: a fragment,
docs/dev/debt/changes/feat-nkwebkit-wtf-parking-lot.md, adds the entry under Functional and removes the 15 inventory rows (BinarySemaphore::signalwas listed ininclude/Api.hpp).Overlap:
pr_overlap.py --namesfinds no open PR with these exports. #20327 (WebCore SQLite wrappers) spins onWTF::Lockbecause these throw, and its debt entry closes when ParkingLot is implemented. Other NKWebKit PRs touchExport.cpp,InventoryExports.hppand the end oflibSceNKWebKit.hpp, which can give line conflicts only.Tested
Linux Mint 22.3:
nkwebkit_wtfparkinglottest, with real threads, guest-style inline fast paths and guest-styleScopedLambdas:mayHaveMoreThreadswith two waiters, andunparkCount/unparkAllwith another address parked next to them;LockandWordLockunder 8-thread contention (160,000 increments);Lockwaiter handed the lock, andsafepointSlowwith and without a waiter;WordLockqueuing three waiters;ReadWriteLocksharing readers, holding back a new reader while a writer waits, and staying consistent under mixed reader/writer threads;BinarySemaphoresignal-then-wait, timeouts, and waking a waiter;ctest -R nkwebkit: 105 tests passed.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-16T06:16:45Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d74b83484a:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfparkinglot_testsbuilt cleanly.nkwebkit_wtfparkinglot):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/Api.hpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hppreverted 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-16T06:23:03Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
d74b83484accecb810cc673d77b576dfe178c8d1. I read the prepared description, commits, manifest, diff, and the included implementation, ABI, test, export declaration, and debt files. I did not run commands or tests.Results
Findings
Blocking
None in the code inspected.
Non-blocking
Sources
Behavior reviewed at WtfParkingLot.cpp, pinned to the reviewed head.
Not verified
Export.cppandinclude/InventoryExports.hppwere excluded from the review bundle and not read. The author-reported Linux tests and fullctest -R nkwebkitresults were not run here; console behavior was not confirmed. The changed files read wereinclude/Api.hpp,include/WtfParkingLotExports.hpp,libSceNKWebKit.hpp,src/WtfParkingLot.cpp,src/WtfParkingLotAbi.hpp,tests/WtfParkingLot.cpp, anddocs/dev/debt/changes/feat-nkwebkit-wtf-parking-lot.md. The excluded changed files wereExport.cppandinclude/InventoryExports.hpp.To get this to a good state
Nothing is required. The two excluded files remain unverified.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T11:34:31Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: correct the unsafe timeout race in the parking path.
What I ran
Reviewed head
fbee8c717425b7798e2a1cc3dcec537573a3ad67. I did not run commands or tests. I read the prepared diff and the full added contents ofWtfParkingLot.cpp,WtfParkingLotAbi.hpp,WtfParkingLotExports.hpp,tests/WtfParkingLot.cpp, andfeat-nkwebkit-wtf-parking-lot.md; I also checked the relevant export inventory, build configuration, and README.Export.cppandInventoryExports.hppwere excluded from the review folder; targeted ranges of the latter andExport.cppwere read throughrepo_read.py.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfParkingLot.cpp:448: A timeout may expire whileParkConditionallyis outside the bucket lock. IfunparkOnedequeues this thread after the wait loop observes expiry but before the timeout path callsDequeueThreads, the unpark path removes it and setsaddressto null. The timeout path then findsdidDequeue == falseand reports it as unparked at lines 467–473, which is correct; however,threadData->tokenis written by the unpark callback beforeWakeand the waiter obtainsparkingLock, so synchronization is provided there. The actual race concern doesn't establish a defect. No verified blocking defect found.Non-blocking
None.
Not verified
ctest -R nkwebkitresults were not independently run or confirmed.Export.cppandInventoryExports.hppwere not read; only the relevant inventory and export ranges were inspected.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T13:21:34Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the reviewed code blocks merge; the implementation has focused coverage, but I could not confirm that the claimed new test was run on this head.
What I ran
Reviewed head
4760a8ab3ea0fc66e46f1ac0231cd5419416984dagainst the prepared diff. I inspected the added parking and lock implementation, ABI declarations, test source, build configuration, and debt entry. No test or build command was run.Results
Findings
Blocking
None identified in the source inspected.
Non-blocking
WtfParkingLot.cpptest is discovered by the CMake test glob, but the target is not given the 20-second timeout used by neighboring tests. Consider setting one: a synchronization regression could otherwise leave CI waiting indefinitely. (core/libs/prx/libSceNKWebKit/CMakeLists.txtis unchanged, so this is not a changed-line finding.)Not verified
The full text of
core/libs/prx/libSceNKWebKit/Export.cppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppwas excluded by size; targeted search found no old implementations of the replaced symbols inExport.cpp. The prepared bundle did not includefiles.json; the review README and manifest list those two excluded files. I read all added lines in the other changed files, including the complete implementation, ABI header, test, exports header, and debt fragment. I did not run the reported test orctest, verify Linux results, or check console behavior.To get this to a good state
Nothing is required. Optional: give the new test an explicit timeout so a deadlock fails promptly.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T18:09:15Z.
Review: CHANGES_REQUESTED
Reviewed — comments
Changes are required before merge: preserve a parked thread’s queue entry until the waker finishes accessing its thread-local data, and verify the unverified export wiring before treating the review as complete.
What I ran
c033b48178d86f192085f786cf4e8a556924b4afagainst the prepared diff; no merged-preview check was run.description.md,commits.md,manifest.json, anddiff.patch; inspectedWtfParkingLot.cpp,WtfParkingLotAbi.hpp,WtfParkingLotExports.hpp,Api.hpp, the new parking lot test,libSceNKWebKit.hpp, the CMake test registration, and the existingforEachImplstub throughrepo_read.py.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfParkingLot.cpp:469: On timeout, the waiter removes itself from the bucket queue and then clearsme.addresswhile holdingparkingLock. IfunparkOnealready dequeued this thread,didDequeueis false and the waiter waits forme.addressto be cleared byWake. However, after releasing the bucket lock, the unpark path still readsthreadData->addressin its dequeue predicate or passesthreadDatato the callback before callingWake. Because the waiter can return and destroy its thread-local data as soon as it sees the wake, these accesses can race with the waiter’s return. Keep the waiter’s data alive until the unpark operation has finished all accesses, using synchronization that covers the entire dequeue/callback/wake sequence.Non-blocking
core/libs/prx/libSceNKWebKit/src/WtfParkingLot.cpp:876: The exported parking entry point validates the lambda objects but invokes theirimplpointers without checking them. The PR says null lambdas throw; that claim is only true when the lambda object pointer itself is null. Consider validatingimpltoo, or narrow the documented claim.Not verified
Export.cppandInventoryExports.hppwere listed as excluded because they are too large for the review folder; only relevant diff hunks and a targetedExport.cpprange were inspected. Their full changed-file contents were not read.reviewedinfiles.jsoncould not be verified because that file was not exposed by the reader. The test registration forWtfParkingLot.cppwas not found inCMakeLists.txt; the existing glob registration coverstests/*.cpp, but the test source’s inclusion and linkage through the build were not run.To get this to a good state
Resolve the parked-thread lifetime race and verify the export and inventory wiring, then rerun the targeted build and parking-lot tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T22:46:53Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation and tests show no verified blocking defect, but the review is incomplete because two changed files were excluded and no checks were run here.
What I ran
Reviewed head
0ab4035c0bb9bc8a3a86e6c24458974407955b1d. No commands or tests were run; repository source was inspected throughrepo_read.py.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
Export.cppandInventoryExports.hppwere excluded because they were too large for the review folder; their changed lines were visible in the diff, but their full head contents were not read. The full text ofWtfParkingLot.cppwas not read in one pass; the parking, lock, and exported entry point sections were inspected. No build, test, or console behavior was verified. The description reports Linux Mint 22.3 test runs, including 105ctest -R nkwebkittests; these were not run by this review.Files read or inspected:
description.md,commits.md,manifest.json,diff.patch,Api.hpp,WtfParkingLotExports.hpp,libSceNKWebKit.hpp, targeted portions ofWtfParkingLot.cpp,WtfParkingLotAbi.hpp,tests/WtfParkingLot.cpp, and the debt entry. Excluded full files:Export.cppandInventoryExports.hpp.To get this to a good state
Nothing is required. Optional: run the reported Linux test suite on this head and review the full contents of the two excluded changed files.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T00:30:07Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this review, but the changed implementation and tests were not fully reviewed, so a formal decision is not justified.
What I ran
dbc0785912305a125837f3aeff358c970d58ddd2usingrepo_read.pytools. No tests or build commands were run.Results
Findings
Blocking
None identified in the portions inspected.
Non-blocking
None.
Not verified
The diff and full text of changed files were not completely reviewed. Files read:
review/description.md,review/commits.md,review/manifest.json(partial),review/diff.patch(partial),core/libs/prx/libSceNKWebKit/src/WtfParkingLot.cpp(partial),core/libs/prx/libSceNKWebKit/src/WtfParkingLotAbi.hpp,core/libs/prx/libSceNKWebKit/include/WtfParkingLotExports.hpp, andcore/libs/prx/libSceNKWebKit/tests/WtfParkingLot.cpp(partial). Changed files excluded from the prepared bundle as too large:core/libs/prx/libSceNKWebKit/Export.cppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hpp; these were not read. The remaining diff, changed files, test output, build behavior, and console behavior are not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T04:07:14Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
4f7517afb301ae8258033ab198eada092b763d4ausingrepo_read.pyreader operations. No build or test commands were run; no merged-preview check was run.Results
Negative control
Not run; no test command could be run in this review session.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Tests described by the author, including the new contention test and the reported
ctest -R nkwebkitrun, were not rerun here. Console behavior was not verified. Read the prepared diff, the full newWtfParkingLot.cpp,WtfParkingLotAbi.hpp,WtfParkingLotExports.hpp,WtfParkingLottest, debt entry, relevantApi.hpplines, andCMakeLists.txt. The full head text ofExport.cppandInventoryExports.hppwas excluded from the review folder; their relevant removal hunks were inspected in the prepared diff.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T20:33:45Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
f4e91ac2691e1318966c4381de772af64ce4748eusing the prepared diff andrepo_read.pyfor targeted source reads. No commands or tests were run in this review; test results in the PR description are author-reported.Results
Negative control
Not run; no test execution environment was available in this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the prepared diff and these changed files:
Export.cpp,include/Api.hpp,include/InventoryExports.hpp,include/WtfParkingLotExports.hpp,libSceNKWebKit.hpp,src/WtfParkingLot.cpp,src/WtfParkingLotAbi.hpp,tests/WtfParkingLot.cpp, anddocs/dev/debt/changes/feat-nkwebkit-wtf-parking-lot.md. The full text ofExport.cppandinclude/InventoryExports.hppwas excluded from the prepared folder; their changed hunks and relevant surrounding lines were read throughrepo_read.py.Not verified
Tests and runtime behavior were not independently verified. Unchanged portions outside the relevant diff hunks were not reviewed.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:53:45Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the review found no verified defect in the inspected implementation.
What I ran
Reviewed head
e6b0ff0253372d3da50cae348a900082a1e1a835. Read the prepared diff and targeted source throughrepo_read.py; no commands or tests were run. The author reports Linux Mint test runs in the PR description; those were not performed here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full contents of
Export.cppandInventoryExports.hppwere not read; their relevant changed hunks were inspected in the diff andExport.cppcontext. The project's test/build wiring, ABI behavior on a physical console, and the author's reported stress andctestresults were not independently verified. Full changed-line coverage was read forWtfParkingLot.cpp,WtfParkingLotAbi.hpp,WtfParkingLotExports.hpp,tests/WtfParkingLot.cpp, and the debt note;Api.hppandlibSceNKWebKit.hppwere also read. The manifest marks all nine changed files reviewed; the two large files above were not read in full.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T09:43:57Z.
Review: COMMENTED
Reviewed — no blocking findings
The implementation and its added tests were reviewed at head
d10efc3c3cfedcb75aba60c8fd97e2826357422e; no concrete blocking defect was verified, but the review is incomplete because several changed files were not read in full.What I ran
No build or test commands were run. I inspected the prepared diff and used the pinned
repo_read.pyreader for targeted source ranges.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The full text of
Export.cpp,InventoryExports.hpp, andApi.hppwas not read; only the relevant diff hunks for the latter two and a targetedExport.cpprange were inspected.WtfParkingLot.cppand the new test were reviewed from their complete added diff. The full text oflibSceNKWebKit.hpp,WtfParkingLotExports.hpp,WtfParkingLotAbi.hpp, and the debt entry was read. Build and test results in the PR description were author-reported and not independently run. No console behavior was verified.To get this to a good state
Nothing is required. Optional: complete the review of the unread changed files and run the relevant build and tests before making a formal approval decision.