fix(libkernel): report current thread scheduling policy in attributes #8583

Merged
Ondra97 merged 3 commits from upstream-pr/8583 into main 2026-10-20 18:14:28 +00:00
Ondra97 commented 2026-10-20 17:23:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-20T17:23:53Z.


What

scePthreadAttrGet always writes FIFO, even when scePthreadGetschedparam reports RR for the same live thread. pthread_attr_get_np leaves the destination's previous policy untouched. Both attribute queries now read the thread's existing atomic scheduling-policy metadata.

The scheduling regression checks both APIs with destinations preseeded to FIFO and RR, queries from the thread itself and from another thread, explicit and inherited creation policies, subsequent policy changes, rejected setters, and the existing SCE ESRCH result after join. The guest constants have a GUEST_ prefix because <future> brings in host scheduling macros.

The policy-copy behavior follows FreeBSD 11.4 libthr's attribute query, whose copy range includes the policy; setschedparam updates that attribute. The console result of these attribute queries has not been measured, and that limit is recorded in the library's technical debt. Host scheduling is still unaffected. This addresses CORE 01 in #8005; no title compatibility claim is made.

Tested

Windows 11 Pro 10.0.26300; AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER. WinLibs GCC 15.2.0 UCRT r7; Release with BUILD_TESTING=ON.

Base: 1b08a33b121e23a4f9e84999c233e094b5055893. Fix: ad1650686c0686bd6971eda5a7e40c74cc319279.

Metric Before (base) After (fix)
Wrong policy results in the same 8-case probe 4/8 0/8
Extended guest_pthread_schedparam regression Fails Passes

The probe uses a live guest thread, FIFO/RR settings, both attribute-query APIs and both destination policies. The committed regression also covers creation, inheritance, changes to another gated thread, and SCE ended-thread behavior. The unchanged guest_pthread_attr and guest_pthread_attr_errors tests pass before and after.

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DPython3_EXECUTABLE=C:/Python314/python.exe -DFFMPEG_PREBUILT_DIR=D:/Github/AnyPS5/build-runtime/externals/ffmpeg-9ac4cfd195f1
cmake --build build --parallel 6
ctest --test-dir build -R '^(patched_libraries|guest_thread_self|guest_pthread_(attr|attr_errors|attr_stack|schedparam|start))$' --output-on-failure
python tools/check_conventions.py --base origin/main
python tools/pr_overlap.py --branch codex/fix-pthread-attr-policy

The overlap checker reports no confirmed conflicts. I manually reviewed its incomplete shared-file comparisons: #6893 changes guard-size fields, #6044 moves the unchanged scheduling test, and the debt changes concern other entries. #8041's guard-size change also leaves the policy untouched. None supplies this fix or is a prerequisite.

No console modules or game payloads are needed by the regression. No game run was performed.

Full all-target Windows Release build passed. The final seven runtime tests passed, including loading 354 patched libraries with zero failures. The full build used a temporary alignment adjustment confined to an unrelated existing test; it was restored afterward and is absent from the submitted diff.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939662499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8583). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-20T17:23:53Z. --- ### What `scePthreadAttrGet` always writes FIFO, even when `scePthreadGetschedparam` reports RR for the same live thread. `pthread_attr_get_np` leaves the destination's previous policy untouched. Both attribute queries now read the thread's existing atomic scheduling-policy metadata. The scheduling regression checks both APIs with destinations preseeded to FIFO and RR, queries from the thread itself and from another thread, explicit and inherited creation policies, subsequent policy changes, rejected setters, and the existing SCE ESRCH result after join. The guest constants have a `GUEST_` prefix because `<future>` brings in host scheduling macros. The policy-copy behavior follows [FreeBSD 11.4 libthr's attribute query](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libthr/thread/thr_attr.c#L134-L164), whose [copy range includes the policy](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libthr/thread/thr_private.h#L244-L258); [setschedparam updates that attribute](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libthr/thread/thr_setschedparam.c#L65-L71). The console result of these attribute queries has not been measured, and that limit is recorded in the library's technical debt. Host scheduling is still unaffected. This addresses CORE 01 in #8005; no title compatibility claim is made. ### Tested Windows 11 Pro 10.0.26300; AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER. WinLibs GCC 15.2.0 UCRT r7; Release with `BUILD_TESTING=ON`. Base: `1b08a33b121e23a4f9e84999c233e094b5055893`. Fix: `ad1650686c0686bd6971eda5a7e40c74cc319279`. | Metric | Before (base) | After (fix) | |---|---|---| | Wrong policy results in the same 8-case probe | 4/8 | 0/8 | | Extended `guest_pthread_schedparam` regression | Fails | Passes | The probe uses a live guest thread, FIFO/RR settings, both attribute-query APIs and both destination policies. The committed regression also covers creation, inheritance, changes to another gated thread, and SCE ended-thread behavior. The unchanged `guest_pthread_attr` and `guest_pthread_attr_errors` tests pass before and after. ```sh cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DPython3_EXECUTABLE=C:/Python314/python.exe -DFFMPEG_PREBUILT_DIR=D:/Github/AnyPS5/build-runtime/externals/ffmpeg-9ac4cfd195f1 cmake --build build --parallel 6 ctest --test-dir build -R '^(patched_libraries|guest_thread_self|guest_pthread_(attr|attr_errors|attr_stack|schedparam|start))$' --output-on-failure python tools/check_conventions.py --base origin/main python tools/pr_overlap.py --branch codex/fix-pthread-attr-policy ``` The overlap checker reports no confirmed conflicts. I manually reviewed its incomplete shared-file comparisons: #6893 changes guard-size fields, #6044 moves the unchanged scheduling test, and the debt changes concern other entries. #8041's guard-size change also leaves the policy untouched. None supplies this fix or is a prerequisite. No console modules or game payloads are needed by the regression. No game run was performed. Full all-target Windows Release build passed. The final seven runtime tests passed, including loading 354 patched libraries with zero failures. The full build used a temporary alignment adjustment confined to an unrelated existing test; it was restored afterward and is absent from the submitted diff. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 17:38:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T17:38:16Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestPthreadSchedparam.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7530 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8255 docs/dev/debt/libkernel.md
PR 8539 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297185603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8583#issuecomment-6297185603). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T17:38:16Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestPthreadSchedparam.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `docs/dev/debt/libkernel.md` | | [PR 7464](https://www.github.com/boykopovar/AnyPS5/pull/7464) | `docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7530](https://www.github.com/boykopovar/AnyPS5/pull/7530) | `docs/dev/debt/libkernel.md` | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` | | [PR 8255](https://www.github.com/boykopovar/AnyPS5/pull/8255) | `docs/dev/debt/libkernel.md` | | [PR 8539](https://www.github.com/boykopovar/AnyPS5/pull/8539) | `docs/dev/debt/libkernel.md` |
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!8583
No description provided.