feat(libkernel): sceKernelAddTimerEvent and sceKernelDeleteTimerEvent #807
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/807"
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 adriadam10 on 2026-10-06T05:39:19Z.
What
Adds
sceKernelAddTimerEvent(57ZK+ODEXWY) andsceKernelDeleteTimerEvent(YWQFUyXIVdU), whichmaindoesn't declare at all.AddTimerEvent(eq, id, usec, udata)registers a periodicEVFILT_TIMER(-7) event withEV_CLEAR, reusing the equeue's existing timer scheduling (TriggerExpiredTimers/NextTimerWaitMicrosused by the HR timer).datais the number of expirations since the last delivery, and the timer stays registered after delivery. Calling it again on the same id keeps the expirations already counted and replaces the interval and userdata. Withusec == 0the event is ready again after every read, withdata == 1. This follows KytyPS5'sKernelAddTimerEventandTriggerExpiredTimers, and itsEventQueueLifetimeTests. prosper'spost_afteragrees on periodic firing and expirations-since-last-read indata(FreeBSD kqueueEVFILT_TIMER).DeleteTimerEventremoves theEVFILT_TIMERevent, returningENOENTif there isn't one. An unknown queue returnsEBADFfor both calls (shadPS4 and KytyPS5).usec / 1000indataand doesn't model periodic expirations, which looks like a placeholder. prosper's Delete always returns 0. I followed KytyPS5 (expirations indata) and shadPS4 (ENOENTon Delete).KernelEqueuePrivate::MonotonicNsis now public so the export uses the same clock as the queue. Re-adding only refreshes expired timers first forEVFILT_TIMER, so the HR timer behaves as before.Tested
Linux, GCC (Release and a fast dev build). I extended
guest_equeue_events(core/libs/tests/GuestEqueueEvents.cpp) with these cases:EBADFENOENT, including when only an HR timer has that iddata >= 5after 5 ms at 1 ms), and the timer is still delivered afterwardsusec == 0givesdata == 1on every readIt aborts on
main(the exports don't exist, so it doesn't link). Negative checks: each of these breaks the test:data = 1instead of accumulating, one-shot flag, no refresh before update, interval not updated on re-add, no deadline advance, zero interval counting while already triggered, and Delete using the HR filter. The fullguest_|libkernel|equeuectest set passes (119/119).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T05:48:00Z.
Progress report (
2b8f0b2→9ab637a)📈 System libraries: 86.0% (+0.01%, +2 implemented functions)
✅ 2 implemented
sceKernelAddTimerEventsceKernelDeleteTimerEventImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T05:51:39Z.
Windows CI:
guest_equeue_eventsaborted because the test assumedsleep_fornever wakes early. The test now sleeps untilsteady_clockhas advanced by at least the requested time, and only checks the exact expiration count and the empty follow-up poll when the measured elapsed time makes them deterministic (< 400 ms). The implementation is unchanged.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T09:27:38Z.
Thanks, the expiration counting and the reworked test look right to me. The test is deterministic now: every lower bound holds whatever the scheduler does, and the exact count is only checked when the elapsed time guarantees it.
One functional problem and one docs point:
sceKernelWaitEqueue(eq, ev, n, &out, nullptr)goes toWaitForEvents(ev, num, 0), which callsm_cond.Wait(lock)with no deadline (Equeue.cpp:161). Nothing signals the condition when a timer expires, so a thread waiting on a queue that only holds a timer hangs for good. Periodic timer plus infinite wait is the usual way this API is used. HRTimer has the same gap on main, but this PR makes it much easier to hit. Could themicros == 0branch useNextTimerWaitMicrosandWaitUntilthe nearest timer deadline when there is one? A test that adds a 1000 us timer and waits with a null timeout would cover it.usectaken as microseconds, re-adding an existing timer keeps the pending expiration count and restarts the period from now, andusec == 0fires on every wait. For comparison, FreeBSD 12+filt_timertouchclears pending expirations onEV_ADD. I don't know what the PS5 kernel does here, so documenting the choice seems enough.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T09:52:05Z.
Rebased on main and fixed:
NextTimerWaitMicros+WaitUntil) when the queue has one, and blocks as before otherwise. This also covers HRTimer. New test cases: a 1000 us timer and a 1 ms HRTimer, each waited on with a null timeout. Without the fix the test hangs until the 20 s ctest timeout.usectaken as microseconds, re-add keeps pending expirations and restarts the period (FreeBSD 12+filt_timertouchclears them), andusec == 0fires on every wait.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T22:02:51Z.
Thanks. After the last batch this branch conflicts with main in
docs/dev/TechnicalDebt.md. Could you rebase onto main? The code doesn't need to change.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T16:05:15Z.
Rebased onto main (
8e281fa8d). The only conflict was indocs/dev/TechnicalDebt.md. ThesceKernelAddTimerEventline stays under "Unknown function info", now next to the other libkernel entries instead of at the end of the section. Build and full ctest pass, includingguest_equeue_events.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T16:09:32Z.
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.
main)core/libs/prx/libkernel/Equeue/Equeue.cppL154core/libs/prx/libkernel/Equeue/Equeue.cppL154core/libs/prx/libkernel/Equeue/Equeue.hppL16, L65-66