fix(libkernel): report machdep.tsc_freq from sysctlbyname #5387

Closed
milescoviello wants to merge 1 commit from upstream-pr/5387 into main
milescoviello commented 2026-10-13 18:30:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T18:30:53Z.


What

PS5SX2 (PPSA99203, from the homebrew catalog) reads machdep.tsc_freq with sysctlbyname at start-up. On main that name throws, which ends the title before its first frame:

[libc] unhandled exception 'St13runtime_error' thrown from 0x...
terminate called after throwing an instance of 'std::runtime_error'
  what():  sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq

FreeBSD 11.4 defines the name in sys/x86/x86/tsc.c as an unsigned 64-bit value:

SYSCTL_PROC(_machdep, OID_AUTO, tsc_freq, CTLTYPE_U64 | CTLFLAG_RW,
    0, 0, sysctl_machdep_tsc_freq, "QU", "Time Stamp Counter frequency");

sysctlbyname now answers it with the frequency sceKernelGetTscFrequency already measures. It goes through the same CopyOut as kern.sdk_version:

  • A size query reports 8 bytes.
  • A short buffer gets the partial copy and ENOMEM.
  • A write returns EPERM, as an unprivileged write to a sysctl does.

guest_system_configuration gains CheckTscFrequencySysctl, covering those three cases and that the value equals sceKernelGetTscFrequency(). The libkernel debt file records that the value is the host's measured frequency; the console's value is not checked.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 18c438b10, RTX 4070 Ti (NVIDIA 580.142):

  • With main's SystemConfiguration.cpp and the new test, guest_system_configuration aborts; with the change it passes 20/20.
  • All 342 guest_* tests pass in two runs.
  • PS5SX2 (PPSA99203, eboot.bin unwrapped from its fSELF and relinked with --to-intel --trap-sdk-syscall-stubs, see #2136):
    • With main's libraries it stops at 0 s with the lines above.
    • With this change it runs the whole 45 s run, compiling its shaders and presenting frames, with no exception.
  • tools/check_conventions.py --base upstream/main passes.

Not checked on a console.

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
  • Unblocks: PPSA99203 (PS5SX2)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4847704721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5387). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-13T18:30:53Z. --- ### What PS5SX2 (PPSA99203, from the homebrew catalog) reads `machdep.tsc_freq` with `sysctlbyname` at start-up. On `main` that name throws, which ends the title before its first frame: ``` [libc] unhandled exception 'St13runtime_error' thrown from 0x... terminate called after throwing an instance of 'std::runtime_error' what(): sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq ``` FreeBSD 11.4 defines the name in [`sys/x86/x86/tsc.c`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/x86/x86/tsc.c#L735-L736) as an unsigned 64-bit value: ```c SYSCTL_PROC(_machdep, OID_AUTO, tsc_freq, CTLTYPE_U64 | CTLFLAG_RW, 0, 0, sysctl_machdep_tsc_freq, "QU", "Time Stamp Counter frequency"); ``` `sysctlbyname` now answers it with the frequency `sceKernelGetTscFrequency` already measures. It goes through the same `CopyOut` as `kern.sdk_version`: - A size query reports 8 bytes. - A short buffer gets the partial copy and `ENOMEM`. - A write returns `EPERM`, as an unprivileged write to a sysctl does. `guest_system_configuration` gains `CheckTscFrequencySysctl`, covering those three cases and that the value equals `sceKernelGetTscFrequency()`. The libkernel debt file records that the value is the host's measured frequency; the console's value is not checked. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` 18c438b10, RTX 4070 Ti (NVIDIA 580.142): - With `main`'s `SystemConfiguration.cpp` and the new test, `guest_system_configuration` aborts; with the change it passes 20/20. - All 342 `guest_*` tests pass in two runs. - PS5SX2 (PPSA99203, `eboot.bin` unwrapped from its fSELF and relinked with `--to-intel --trap-sdk-syscall-stubs`, see #2136): - With `main`'s libraries it stops at 0 s with the lines above. - With this change it runs the whole 45 s run, compiling its shaders and presenting frames, with no exception. - `tools/check_conventions.py --base upstream/main` passes. Not checked on a console. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Unblocks: PPSA99203 (PS5SX2) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 18:38:29 +00:00 (Migrated from github.com)

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


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
#4776 core/libs/prx/libkernel/System/src/SystemConfiguration.cpp L22, L212
core/libs/tests/GuestSystemConfiguration.cpp L24
#5078 core/libs/tests/GuestSystemConfiguration.cpp L24, L262
docs/dev/debt/libkernel.md L18
#5184 core/libs/tests/GuestSystemConfiguration.cpp L262
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152564656 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5387#issuecomment-6152564656). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T18:38:29Z. --- <!-- 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 | |---|---|---|---| | #4776 | `core/libs/prx/libkernel/System/src/SystemConfiguration.cpp` [L22](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp#L22), [L212](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp#L212)<br>`core/libs/tests/GuestSystemConfiguration.cpp` [L24](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/core/libs/tests/GuestSystemConfiguration.cpp#L24) | | | | #5078 | `core/libs/tests/GuestSystemConfiguration.cpp` [L24](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/core/libs/tests/GuestSystemConfiguration.cpp#L24), [L262](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/core/libs/tests/GuestSystemConfiguration.cpp#L262)<br>`docs/dev/debt/libkernel.md` [L18](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/docs/dev/debt/libkernel.md#L18) | | | | #5184 | `core/libs/tests/GuestSystemConfiguration.cpp` [L262](https://github.com/boykopovar/AnyPS5/blob/a0f5916a293067ca840e835e58a8a55a0b764b4b/core/libs/tests/GuestSystemConfiguration.cpp#L262) | | |
milescoviello commented 2026-10-13 20:09:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T20:09:15Z.


Closing as a duplicate of #4776, which makes the same change and was opened first. I posted the PS5SX2 (PPSA99203) title evidence there.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154206398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5387#issuecomment-6154206398). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-13T20:09:15Z. --- Closing as a duplicate of #4776, which makes the same change and was opened first. I posted the PS5SX2 (PPSA99203) title evidence there. AI-assisted: yes

Pull request closed

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!5387
No description provided.