feat(libkernel): implement pthread_getcpuclockid and per-thread CPU clocks #1676
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1676"
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 Recapi on 2026-10-08T16:13:45Z.
What
pthread_getcpuclockidin libkernel, andclock_gettime/clock_getresfor the clock it returns.thr_getcpuclockid.c,kern_clock_getcpuclockid2), the clock isCPUCLOCK_BIT | tid. Guest threads had no thread id, so everyPthreadPrivategets one from a registry when it is constructed (created and adopted threads) and leaves it in its destructor.clock_gettimeon that clock returns the thread's CPU time: on Linux from the host thread's CPU clock, taken on the thread when it starts or is adopted; on Windows fromGetThreadTimeson its handle. A thread that has finished or does not exist returns -1 withEINVAL, liketdfindfailing inkern_clock_gettime.clock_getreson it returns the resolution ofCLOCK_THREAD_CPUTIME_ID. Process CPU clocks (CPUCLOCK_PROCESS_BIT) throw.pthread_getcpuclockidreturnsEINVALfor a null thread andEFAULTfor a null output.Caller: PPSA99005 (blackbearreloaded/ps5-opengl v1.0.1) imports
pthread_getcpuclockid(#1578; 19 of the 34 catalog titles in the audit there). In its SDK (ps5-opengl-sdk 1.0.1) the only reference is Mesa'slibmesa_util.au_thread.c.o:util_thread_get_time_nano(src/util/u_thread.c) callspthread_getcpuclockidand thenclock_gettimeon the result, for the calling thread and for queue threads, so the clock has to work inclock_gettimetoo.Log
PPSA99005 (blackbearreloaded/ps5-opengl showcase v1.0.1), relinked on Linux (Ubuntu, GCC 15.2.0,
mainf1451396, bundledlibc.prxkept) and run in abwrapsandbox. Onmainit stops onmkstemp, as in #1578:With the open PRs for its earlier absent imports merged locally (#1978, #1869, #1656, #1729, #1613, #1714, #1482, #1650, #1872, #1641, #1685, #1859; no conflicts), the stops are:
Wh7HbV7JFqc(getrlimit, #1675)JZKw5+Wrnaw(pthread_sigmask, no PR yet)pthread_sigmaskexportnnoxZUHK+SA(pthread_getcpuclockid, #1676)Each stop is the loader's line, e.g.
./app.elf: symbol lookup error: ./app.elf: undefined symbol: Wh7HbV7JFqc. The throwawaypthread_sigmaskonly exports the NID and throws when called; it was not called before the abort.Tested
Ubuntu, Linux 7.0, GCC 15.2.0, full build with
BUILD_TESTING=ON. New testguest_thread_cpu_clock: own clock tracksCLOCK_THREAD_CPUTIME_ID, another thread's clock reads that thread and does not advance while the caller burns CPU,EINVALafter join, resolution, null arguments. Fullctest --repeat until-fail:3: 465/465 (together with #1675). Patchedlibkernel.prxexportsnnoxZUHK+SA.The project's Build workflow on the fork (Linux, Windows MinGW, relinker on Ubuntu/Windows/macOS) passes; the run is linked in a comment below. Run with PPSA99005 as above.
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 Recapi on 2026-10-08T16:57:22Z.
CI is waiting for first-time contributor approval here, so I ran the project's Build workflow (
build.yml,workflow_dispatch) on the fork for this head (942a105c): https://github.com/Recapi/AnyPS5/actions/runs/37876696314guest_thread_cpu_clockpassedguest_thread_cpu_clockpassedOverlap: no textual conflict with the open PRs that change these files (
git merge-treeagainst each; #1128 already conflicts withmain). TheEFAULTconstant is now local topthread_getcpuclockid, so it neither conflicts with nor duplicates the file-scopeGUEST_EFAULT#1922 adds toPosix/Thread.cpp.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:03:59Z.
First Windows run, since the description says it wasn't tested on Windows.
Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto
mainb7218b3ctogether with nine other small libc/libkernel PRs: #1975, #1976, #1977, #1859, #1685, #1675, #1641, #1656, #1807.guest_thread_cpu_clockpasses.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:01:15Z.
Checked against FreeBSD 11 (
thr_getcpuclockid.c,kern_clock_getcpuclockid2): same clock id layout and error returns. Full build + ctest on Linux green (guest_thread_cpu_clockpasses, and fails to link without the change); Windows MinGW run by @popcoder565 also green. Process CPU clocks throw instead of guessing, which is right. Merging.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:08:44Z.
Progress report (
f145139→942a105)➖ System libraries: 84.76% (+0.0%, +1 implemented functions)
✅ 1 implemented
pthread_getcpuclockid_nid_postfix