Skip to content

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

Closed
milescoviello wants to merge 1 commit into
boykopovar:mainfrom
milescoviello:fix/sysctl-tsc-freq
Closed

milescoviello wants to merge 1 commit into
boykopovar:mainfrom
milescoviello:fix/sysctl-tsc-freq

Conversation

@milescoviello

Copy link
Copy Markdown
Contributor

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 18c438b, 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 Relinker: seven catalog homebrew titles stop on raw FreeBSD syscall stubs from the ps5-payload-dev SDK libc #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

PS5SX2 (PPSA99203) reads machdep.tsc_freq at start-up, and main
throws "sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq",
which ends the title before its first frame.

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, through the same CopyOut as kern.sdk_version: a size
query reports 8 bytes, a short buffer gets the partial copy and ENOMEM,
and a write returns EPERM, as an unprivileged write to a sysctl does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

@milescoviello

Copy link
Copy Markdown
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant