feat(libkernel): report machdep.tsc_freq from sysctlbyname #4776

Merged
babyhuey merged 1 commit from upstream-pr/4776 into main 2026-10-14 01:09:32 +00:00
babyhuey commented 2026-10-12 21:30:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T21:30:29Z.


What

sysctlbyname("machdep.tsc_freq") used to throw unsupported name machdep.tsc_freq. It now reports the TSC frequency as a 64-bit value, as FreeBSD 11's sysctl_machdep_tsc_freq does. The value is the host TSC rate that sceKernelGetTscFrequency already measures.

  • FreeBSD registers it with OID_AUTO, so it has no fixed MIB and is only answered by name.
  • Reads use the existing CopyOut: a null buffer reports the 8-byte length, and a short buffer gets a truncated copy and ENOMEM.
  • FreeBSD lets root write it to retune the TSC timecounter. AnyPS5 can't, so a write returns EPERM. That difference is recorded in docs/dev/debt/libkernel.md.

The current PS5SX2 build (PPSA99203, catalog vk-285-163) reads it into a 64-bit value at start-up. If the call fails or the value is 100 MHz or less, it measures the TSC with rdtsc itself, so it only needs the call not to throw. Its older build (vk-285-162) didn't read it.

Tested

On the PR head d39cb2c6 (rebased onto main 7e181fcc after #4667 merged), Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release:

  • guest_system_configuration passes 5/5 (--repeat until-fail:5) on both. The new check covers the length query, a read equal to sceKernelGetTscFrequency(), truncation with ENOMEM and a write with EPERM.
  • No warnings in SystemConfiguration.cpp or GuestSystemConfiguration.cpp.

PS5SX2 vk-285-163 with --trap-sdk-syscall-stubs (#3804):

  • On plain main 7e181fcc it starts running, then throws sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq (Windows exits 0xC0000409; Linux shows the same throw). gdb on an earlier main showed machdep.tsc_freq is its first sysctlbyname call.
  • With this PR, on Windows it keeps running past the 60 s limit and draws its frontend at 59.94 fps (window title FPS counter), asking for a PS2 BIOS in /data/PCSX2/bios. On Linux it gets past both sysctls and stops at the headless DisplayWindow Vulkan throw, as far as a headless run gets.

check_conventions.py 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 (#4530 and #4667 have merged; PS5SX2 stops here on main)
  • Unblocks: PPSA99203 #4850
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4835215998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T21:30:29Z. --- ### What `sysctlbyname("machdep.tsc_freq")` used to throw `unsupported name machdep.tsc_freq`. It now reports the TSC frequency as a 64-bit value, as FreeBSD 11's [`sysctl_machdep_tsc_freq`](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/sys/x86/x86/tsc.c#L658-L676) does. The value is the host TSC rate that `sceKernelGetTscFrequency` already measures. - FreeBSD registers it with `OID_AUTO`, so it has no fixed MIB and is only answered by name. - Reads use the existing `CopyOut`: a null buffer reports the 8-byte length, and a short buffer gets a truncated copy and `ENOMEM`. - FreeBSD lets root write it to retune the TSC timecounter. AnyPS5 can't, so a write returns `EPERM`. That difference is recorded in `docs/dev/debt/libkernel.md`. The current PS5SX2 build (PPSA99203, catalog vk-285-163) reads it into a 64-bit value at start-up. If the call fails or the value is 100 MHz or less, it measures the TSC with `rdtsc` itself, so it only needs the call not to throw. Its older build (vk-285-162) didn't read it. ### Tested On the PR head d39cb2c6 (rebased onto `main` 7e181fcc after #4667 merged), Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release: - `guest_system_configuration` passes 5/5 (`--repeat until-fail:5`) on both. The new check covers the length query, a read equal to `sceKernelGetTscFrequency()`, truncation with `ENOMEM` and a write with `EPERM`. - No warnings in `SystemConfiguration.cpp` or `GuestSystemConfiguration.cpp`. PS5SX2 vk-285-163 with `--trap-sdk-syscall-stubs` (#3804): - On plain `main` 7e181fcc it starts running, then throws `sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq` (Windows exits 0xC0000409; Linux shows the same throw). gdb on an earlier `main` showed `machdep.tsc_freq` is its first `sysctlbyname` call. - With this PR, on Windows it keeps running past the 60 s limit and draws its frontend at 59.94 fps (window title FPS counter), asking for a PS2 BIOS in `/data/PCSX2/bios`. On Linux it gets past both sysctls and stops at the headless `DisplayWindow` Vulkan throw, as far as a headless run gets. `check_conventions.py` 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 (#4530 and #4667 have merged; PS5SX2 stops here on `main`) - [x] Unblocks: PPSA99203 #4850 - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 02:24:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T02:24:56Z.


Windows test: head 49b9952b7 merged onto current main 2a55cfe1e (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_system_configuration: guest_system_configuration passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6136839512 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776#issuecomment-6136839512). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T02:24:56Z. --- Windows test: head `49b9952b7` merged onto current `main` `2a55cfe1e` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `guest_system_configuration`: guest_system_configuration passed (1 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
babyhuey commented 2026-10-13 03:23:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T03:23:56Z.


Where this leads for PS5SX2 (PPSA99203, vk-285-163): with this PR and #4667 on main c13dc7e6, Windows 11 (RTX 3080, WinLibs GCC 15.2), it gets through its start-up and renders its frontend at 59.94 fps. It shows No PS2 BIOS found ... and waits for the user's BIOS and games. Details are in #4850.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137492337 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776#issuecomment-6137492337). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-13T03:23:56Z. --- Where this leads for PS5SX2 (PPSA99203, vk-285-163): with this PR and #4667 on `main` c13dc7e6, Windows 11 (RTX 3080, WinLibs GCC 15.2), it gets through its start-up and renders its frontend at 59.94 fps. It shows `No PS2 BIOS found ...` and waits for the user's BIOS and games. Details are in #4850.
nicolasfalesy commented 2026-10-13 06:04:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T06:04:58Z.


Linux test with a display (Arch, Intel Xe on Mesa 26.2.2 ANV, GCC 16.2.1, Release), head d39cb2c62 on main 7e181fcc3: guest_system_configuration passes. PS5SX2 (PPSA99203, vk-285-163, relinked with --to-intel --trap-sdk-syscall-stubs) on plain main throws sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq. With this PR it runs the full 60 s under Xwayland and draws its frontend: the "No PS2 BIOS found" banner and "No games in /data/PCSX2/games", the same screen as the Windows run above. So on Linux it also gets past the headless DisplayWindow stop once a display is there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139374516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776#issuecomment-6139374516). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T06:04:58Z. --- Linux test with a display (Arch, Intel Xe on Mesa 26.2.2 ANV, GCC 16.2.1, Release), head `d39cb2c62` on `main` 7e181fcc3: `guest_system_configuration` passes. PS5SX2 (PPSA99203, vk-285-163, relinked with `--to-intel --trap-sdk-syscall-stubs`) on plain `main` throws `sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq`. With this PR it runs the full 60 s under Xwayland and draws its frontend: the "No PS2 BIOS found" banner and "No games in /data/PCSX2/games", the same screen as the Windows run above. So on Linux it also gets past the headless `DisplayWindow` stop once a display is there.
github-actions[bot] commented 2026-10-13 14:17:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T14:17: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
#5187 docs/dev/debt/libkernel.md L140-141
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147626804 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776#issuecomment-6147626804). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T14:17: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 | |---|---|---|---| | #5187 | `docs/dev/debt/libkernel.md` [L140-141](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/docs/dev/debt/libkernel.md#L140-L141) | | |
adriadam10 commented 2026-10-13 15:59:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:59:08Z.


Checked the PR merged onto main: guest_system_configuration passes and fails without the change. sceKernelGetTscFrequency exists, reads go through CopyOut, the write case and the debt line are in the right place. The only red test, guest_current_cpu, is in a file this PR doesn't touch. Windows/Linux runs by @xXPBSXx and @nicolasfalesy agree; merging once the Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149672680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776#issuecomment-6149672680). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T15:59:08Z. --- Checked the PR merged onto main: `guest_system_configuration` passes and fails without the change. `sceKernelGetTscFrequency` exists, reads go through `CopyOut`, the write case and the debt line are in the right place. The only red test, `guest_current_cpu`, is in a file this PR doesn't touch. Windows/Linux runs by @xXPBSXx and @nicolasfalesy agree; merging once the Windows build is green.
milescoviello commented 2026-10-13 20:09:08 +00:00 (Migrated from github.com)

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


A title that needs this: PS5SX2 (PPSA99203, from the homebrew catalog) reads machdep.tsc_freq at start-up. On Linux (Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti), on main 18c438b10 it stops at 0 s:

[libc] unhandled exception 'St13runtime_error' thrown from 0x...
  what():  sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq

With the same sysctlbyname change it runs the whole 45 s run, compiling shaders and presenting frames, with no exception. I opened the same fix as #5387 without seeing this one first, so I'm closing mine in favour of this PR.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154204096 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4776#issuecomment-6154204096). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-13T20:09:08Z. --- A title that needs this: PS5SX2 (PPSA99203, from the homebrew catalog) reads `machdep.tsc_freq` at start-up. On Linux (Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti), on `main` 18c438b10 it stops at 0 s: ``` [libc] unhandled exception 'St13runtime_error' thrown from 0x... what(): sysctlbyname_nid_postfix: unsupported name machdep.tsc_freq ``` With the same `sysctlbyname` change it runs the whole 45 s run, compiling shaders and presenting frames, with no exception. I opened the same fix as #5387 without seeing this one first, so I'm closing mine in favour of this PR. AI-assisted: yes
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!4776
No description provided.