feat(libkernel): report _SC_CLK_TCK through sysconf #5185

Merged
p3n1cillin merged 1 commit from upstream-pr/5185 into main 2026-10-14 01:22:07 +00:00
p3n1cillin commented 2026-10-13 14:09:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:09:55Z.


What

Once PS5MC (PPSA99420, Kodi 22, catalog release) gets past mimalloc (#5184), its embedded Python fails while importing posix, and Kodi exits:

[stderr]   File "<frozen importlib._bootstrap_external>", line 38, in <module>
[stderr] RuntimeError: cannot read ticks_per_second
critical <general>: XBPython: Python initialization failed in _PyImport_InitExternal: external importer setup failed (exit code 0); Python add-ons are unavailable
critical <general>: CServiceManager::InitStageTwo: Unable to initialize the python binding modules
ERROR: Unable to create application. Exiting

CPython raises "cannot read ticks_per_second" when sysconf(_SC_CLK_TCK) is below 1. AnyPS5's sysconf returned -1 with EINVAL for _SC_CLK_TCK (3), since it knew only the page size, the processor counts and the physical pages.

sysconf(_SC_CLK_TCK) now returns 128: FreeBSD's sysconf returns CLK_TCK, which time.h defines as 128, and _SC_CLK_TCK is 3 in FreeBSD's unistd.h. AnyPS5 has no times() that reports ticks at another rate. The console's value is not checked; this is recorded under Unknown function info in docs/dev/debt/libkernel.md.

Tested

  • PS5MC PPSA99420 on Windows 11 (MinGW GCC 15.2.0), on main 3faa9cb40 with #4379, #4374, #4383, #5183 and #5184, and without the host's HOME (Git Bash sets it; the guest environment is seeded from the host, and Kodi then puts its profile under the host home). Before, it exits as above about 3 s in. After, Python's posix import gets further and Kodi stops on ioctl FIOCLEX (#5186); with that too, Kodi creates its GUI and runs for the whole 90 s run.
  • guest_system_configuration checks sysconf(3) == 128 with errno unchanged. All 125 libkernel tests pass on Windows; Linux was not built locally.
  • python tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none to build; PS5MC reaches it with #4379, #4374, #4383, #5183 and #5184
  • Unblocks: Python in PS5MC (PPSA99420)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4844515415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5185). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T14:09:55Z. --- ### What Once PS5MC (PPSA99420, Kodi 22, catalog release) gets past mimalloc (#5184), its embedded Python fails while importing `posix`, and Kodi exits: ``` [stderr] File "<frozen importlib._bootstrap_external>", line 38, in <module> [stderr] RuntimeError: cannot read ticks_per_second critical <general>: XBPython: Python initialization failed in _PyImport_InitExternal: external importer setup failed (exit code 0); Python add-ons are unavailable critical <general>: CServiceManager::InitStageTwo: Unable to initialize the python binding modules ERROR: Unable to create application. Exiting ``` CPython raises "cannot read ticks_per_second" when `sysconf(_SC_CLK_TCK)` is below 1. AnyPS5's `sysconf` returned -1 with `EINVAL` for `_SC_CLK_TCK` (3), since it knew only the page size, the processor counts and the physical pages. `sysconf(_SC_CLK_TCK)` now returns 128: FreeBSD's [`sysconf`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/gen/sysconf.c#L100-L101) returns `CLK_TCK`, which [`time.h`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/include/time.h#L48-L54) defines as 128, and `_SC_CLK_TCK` is 3 in FreeBSD's `unistd.h`. AnyPS5 has no `times()` that reports ticks at another rate. The console's value is not checked; this is recorded under Unknown function info in `docs/dev/debt/libkernel.md`. ### Tested - PS5MC PPSA99420 on Windows 11 (MinGW GCC 15.2.0), on `main` `3faa9cb40` with #4379, #4374, #4383, #5183 and #5184, and without the host's `HOME` (Git Bash sets it; the guest environment is seeded from the host, and Kodi then puts its profile under the host home). Before, it exits as above about 3 s in. After, Python's `posix` import gets further and Kodi stops on `ioctl` `FIOCLEX` (#5186); with that too, Kodi creates its GUI and runs for the whole 90 s run. - `guest_system_configuration` checks `sysconf(3) == 128` with `errno` unchanged. All 125 libkernel tests pass on Windows; Linux was not built locally. - `python tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none to build; PS5MC reaches it with #4379, #4374, #4383, #5183 and #5184 - [x] Unblocks: Python in PS5MC (PPSA99420) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
p3n1cillin commented 2026-10-13 14:34:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:34:47Z.


Linux run: Ubuntu in WSL2, GCC 15.2.0, Ninja Release, BUILD_TESTING=ON, full build of a local test head 838d4fd85. That head is main 3faa9cb40 with this PR, my other open libkernel PRs (#5013, #5061, #5078, #5098, #5183–#5187, #5191) and the open PRs the catalog titles need (#4377, #4379, #4374, #4383, #3798, #4467, #4863, #4105). All 123 libkernel and 69 libc tests pass, including guest_system_configuration, guest_getrlimit, guest_kernel_fcntl, guest_freebsd_clocks, guest_kernel_sys and guest_filesystem. Not built alone on Linux; no title run on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147991411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5185#issuecomment-6147991411). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T14:34:47Z. --- Linux run: Ubuntu in WSL2, GCC 15.2.0, Ninja Release, `BUILD_TESTING=ON`, full build of a local test head `838d4fd85`. That head is `main` `3faa9cb40` with this PR, my other open libkernel PRs (#5013, #5061, #5078, #5098, #5183–#5187, #5191) and the open PRs the catalog titles need (#4377, #4379, #4374, #4383, #3798, #4467, #4863, #4105). All 123 libkernel and 69 libc tests pass, including `guest_system_configuration`, `guest_getrlimit`, `guest_kernel_fcntl`, `guest_freebsd_clocks`, `guest_kernel_sys` and `guest_filesystem`. Not built alone on Linux; no title run on Linux.
github-actions[bot] commented 2026-10-13 18:37:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T18:37:54Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
#5275 docs/dev/debt/libkernel.md L17
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152554693 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5185#issuecomment-6152554693). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T18:37:54Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5275 | `docs/dev/debt/libkernel.md` [L17](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/docs/dev/debt/libkernel.md#L17) | | |
coltken95 commented 2026-10-13 18:48:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:48:22Z.


Tested on Linux x86-64 (Release build), with this PR alone (72a685b90) merged into main 9d0a41d5a:

  • With the PR: guest_system_configuration passes.
  • With main's sources and the PR's test: guest_system_configuration aborts.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152740793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5185#issuecomment-6152740793). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T18:48:22Z. --- Tested on Linux x86-64 (Release build), with this PR alone (72a685b90) merged into main 9d0a41d5a: - With the PR: `guest_system_configuration` passes. - With main's sources and the PR's test: `guest_system_configuration` aborts. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5185
No description provided.