Repository navigation
fix(libkernel): wake POSIX sleep for thread cancellation - #6908
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Linux run of this head, plus a check of the other sleeps. Setup: head
Two things the PR does not cover:
Not checked: Windows and macOS, and PS5 hardware. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes |
b3268be to
5715567
Compare
|
Thanks for updating the debt line in Setup: head
The new debt line matches what I measured for So for the probe I changed the test locally: the sleeper calls Two earlier probe runs that kept Probe edit (usleep; the sceKernelUsleep one differs only in the name)-static constexpr auto ObservationLimit = std::chrono::seconds(3);
+static constexpr auto ObservationLimit = std::chrono::seconds(15);
+int APS5_VABI usleep_nid_postfix(unsigned int);
- Require(sleep_nid_postfix(seconds) == 0);
+ Require(usleep_nid_postfix(seconds * 1000000u) == 0);
- if (!pending) wasSleeping = WaitForSleep(thread);
+ if (!pending) { std::this_thread::sleep_for(std::chrono::seconds(1)); wasSleeping = true; }Heads-up on #6540: the debt commit now conflicts with #6540 in Not checked: Windows and macOS, and PS5 hardware. The other four sleeps in the debt line ( Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes |
|
Windows run, since both runs so far are Linux-only. On Windows the two registered environments exercise different Windows 11 10.0.26200.9711, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. Head 5715567 merged onto main b51c65d:
Control: same build with only Not checked: macOS, a title, and runs under load. AI-assisted: yes |
5715567 to
f4d68f2
Compare
|
Rebased onto current main: the only conflict was the adjacent Thread cancellation line in |
What
A cancellation request sent after a guest enters POSIX
sleep(10)cannot wake the hostsleep_for; cancellation is delivered only when the ten seconds expire. A thread joining that sleeper remains blocked too.Register the wait with the existing guest cancellation mechanism and keep the original monotonic deadline across notifications. Destroy the local wait state before delivering cancellation. Normal completion still returns zero, and disabled cancellation leaves the sleep running to its deadline.
This follows FreeBSD 11.4:
sleepdelegates to interposednanosleep, whose libthr wrapper enters a cancellable blocking syscall. The change is limited to POSIXsleep; #6658 changes a separate short GPU polling sleep path inTime.cpp.usleep,sceKernelUsleep,nanosleep,_nanosleep,sceKernelNanosleepandsceKernelSleepstill check cancellation only before and after their host sleep. Interrupting those waits is follow-up work. The Thread cancellation entry indocs/dev/debt/libkernel.mdnow records that boundary.Tested
Earlier native validation at
b3268beaa823f7e4bd87d805bb72a4594193afda: Linux x86-64, GCC 13.3.0, normal CMake Release build with pinned submodules, rebuilding the actual libc and libkernel libraries. No GPU or retail title was used.d9b696ddbbwith the final regression fixture: both blocked cancellation cases fail after the original ten-second sleep, while all six normal, disabled-cancellation and pending-zero-sleep controls pass.APS5_COARSE_TIMED_WAITS=1environments are registered; on Linux both use its existing condition-variable backend.This feedback revision updates the technical-debt entry and the description, and refreshes the branch onto main
f3263dfbf3565b414800c3e2e0d19fda3aca7577. The POSIXsleepfix and its regression fixture are unchanged fromb3268beaa823f7e4bd87d805bb72a4594193afda. The debt wording was checked against the actualCancellableSleepcall paths; conventions and whitespace checks pass.Fresh verification at
571556754e754bf097145c736fa0b5c2116dc717: Linux x86-64, GCC 13.3, Release. An isolated CMake wrapper includes the actual production libc/libkernel CMake files and pinned zstd/ZArchive sources, rebuilding both libraries and four real test executables without reused objects. All 12 focused CTests pass in 2.02 seconds: eight sleep cases plus nanosleep, cancellation and two recovery cases. Dynamic-library resolution confirms that the tests load the newly built scratch libraries. This is a scoped native build, not a full project build.No Windows or macOS runtime validation. Full hosted runtime builds require collaborator dispatch under the current contribution policy.
Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository