Repository navigation
fix(libkernel): wait on absolute condition deadlines beyond 71 minutes - #17286
adriadam10 merged 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The |
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4cee988c86:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_cond_timedwait_testsbuilt cleanly. - CTest (
guest_cond_timedwait):1/1 Test #4011: guest_cond_timedwait ............. Passed 0.41 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libkernel/Pthread/Posix/Common.hpp,core/libs/prx/libkernel/Pthread/src/Cond.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass. - Code reading:
- Verified pointer safety and input validation in PosixThread::AbsoluteDeadlineNanos (core/libs/prx/libkernel/Pthread/Posix/Common.hpp): confirmed !abstime || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000 rejects null pointers and invalid nanoseconds with false, triggering throw std::invalid_argument in CondOperations::AbsoluteTimedwait (Cond.cpp) which maps to POSIX_EINVAL.
- Verified expired deadline handling in PosixThread::AbsoluteDeadlineNanos (Common.hpp): past deadlines where abstime->tv_sec < now.tv_sec - 1 or remaining <= 0 correctly set *deadline = TimedWait::DeadlineNanos(0), ensuring immediate timeout (sceTimedOut / POSIX_ETIMEDOUT) without blocking.
- Verified overflow protection and horizon clamping in PosixThread::AbsoluteDeadlineNanos (Common.hpp): deadlines beyond horizonSeconds (365 days) are clamped to 1 year via TimedWait::DeadlineNanos(static_caststd::uint64_t(horizonSeconds) * 1000000ULL), preventing host std::chrono duration overflow on extreme values like INT64_MAX.
- Verified the fix for the 71.6-minute truncation in CondOperations::AbsoluteTimedwait (core/libs/prx/libkernel/Pthread/src/Cond.cpp): confirmed deadline calculation preserves 64-bit nanoseconds (std::uint64_t deadlineNanos) instead of narrowing through 32-bit KernelUseconds, correctly passing full 64-bit deadlines to waitUntil.
- Verified strict compliance with repository rules in AGENTS.md: confirmed zero comments were added to production or test code (Common.hpp, Cond.cpp, GuestCondTimedwait.cpp), no silent stubs were introduced, no untracked files were added, and conventional commit naming is respected.
- Verified test rigor and resource cleanup in core/libs/tests/GuestCondTimedwait.cpp: DistantAbsoluteDeadline thoroughly exercises 2-hour (7200 s), 1-day (86400 s), INT64_MAX, and past (-5 s) deadlines, alongside an end-to-end threaded cond wait/signal with proper mutex lock/unlock, scePthreadJoin, and cond/mutex destruction.
- Minor: please drop the
Generated withfooter from the description; the AI-assisted checkbox can stay.
Looks Good To Me
|
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.
|
|
@amazedturnip The deadline change looks right to me. On this head, Windows CI failed only on |
|
@amazedturnip Update on my earlier ask: the same two AvPlayer HTTP timeouts showed up on an unrelated test-only PR (#17433), so they look like a CI flake and not your change. No need to run them locally. |
|
Checked the 64-bit deadline arithmetic (one-year cap, expired and far-future rows), that the new |
What
pthread_cond_timedwait(andscePthreadCondTimedwaitthrough the same path) converted an absolute deadline to a remaining time in 32-bit microseconds, so a deadline more than 4294.967 s (71.6 minutes) away was waited as exactly 4294.967 s and then returnedETIMEDOUT. A guestcondition_variable::wait_untilwith a far or "forever" time point that stays parked longer than that got a spurious timeout instead of waiting for the signal.CondOperations::AbsoluteTimedwaitalready hands a 64-bit nanosecond deadline towaitUntil; only the conversion narrowed it. The newPosixThread::AbsoluteDeadlineNanos(Pthread/Posix/Common.hpp) builds that deadline directly from the guesttimespecwith the same validation, the same expired-deadline handling and the same microsecond rounding asRelativeMicroseconds. Deadlines further than one year out are capped at one year, which keeps the host condition variable's duration arithmetic away from overflow (the same reason #14228 clamps per park for ksem). POSIX definesabstimeas a 64-bittimespecand ends the wait at that time or on a signal.Out of scope, so follow-ups stay separate:
pthread_mutex_timedlock,sem_timedwaitandpthread_rwlock_timedrdlock/wrlockstill convert throughRelativeMicrosecondsbecause their sce entry points take 32-bit microseconds.Posix/Sem.cppandPosix/Rwlock.cppare also being changed by open #14103 and #14108, so they are not touched here.RelativeMicrosecondsstays for them.Depends on: none
Fixes: none
Unblocks: none
Tested
upstream/main).guest_cond_timedwaitgainsDistantAbsoluteDeadline: the new helper's deadline for now + 7200 s and now + 86400 s is within one second of that distance, a deadline atINT64_MAXseconds is more than 30 days out, a past deadline is already expired, and apthread_cond_timedwaiton now + 2 h returns 0 after a signal about 50 ms later._Cndsuites (allguest_*tests for the libkernel and libc timed-wait paths thattools/select_tests.pyselects for the changed files), 3 runs, all 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)🤖 Generated with Claude Code