Skip to content

fix(libkernel): inherit process affinity in new guest threads - #3447

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
sypher69:fix/thread-process-affinity-inheritance
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
sypher69:fix/thread-process-affinity-inheritance

Conversation

@sypher69

@sypher69 sypher69 commented Oct 11, 2026 •

Copy link
Copy Markdown

What

New guest threads inherit their creator's effective CPU-affinity mask when thread attributes do not explicitly specify one. Process-wide cpuset_setaffinity updates share the thread-registry lock with thread creation, so a concurrent update cannot leave a new thread with a stale mask; explicit attribute affinity remains effective. This is the follow-up documented after merged #3323 and is independent of merged #3384.

The regression initializes attributes before changing the process mask, then checks both default inheritance and an explicitly selected attribute mask. The stale-inheritance check failed before the production change and passes with it. The resolved technical-debt sentence was removed.

Tested

Linux/WSL, GCC 13.3, Release full build; commit 21f4be11 based on upstream/main 74981fabe1c0fc56b561914beb027ddc9b07d358. No title, console, or Windows run.

  • After this rebase, the affected-target rebuild succeeded with ccache disabled:

    CCACHE_DISABLE=1 cmake --build build --target guest_available_cpumask_tests guest_libc_threads_tests guest_thread_callback_abi_tests guest_thread_atexit_tests guest_pthread_barrier_tests guest_thread_self_tests guest_pthread_getname_tests guest_pthread_attr_tests guest_pthread_mutexattr_tests guest_pthread_start_tests guest_pthread_stack_tests guest_thread_cpu_clock_tests guest_pthread_sem_tests guest_pthread_cancel_tests guest_pthread_cancel_recovery_tests guest_pthread_rwlock_tests guest_pthread_key_tests guest_pthread_rename_tests guest_cpu_time_clocks_tests guest_current_cpu_tests host_thread_local_tests cpu_topology_tests --parallel 4
  • After this rebase, ctest --test-dir build --output-on-failure --no-tests=error -R '^guest_available_cpumask$' passed 1/1. In the earlier test-only phase, this regression failed before the production fix.

  • After this rebase, ctest --test-dir build --output-on-failure --no-tests=error -R '^(guest_(libc_threads|thread_callback_abi|thread_atexit|pthread_.*|thread_self|thread_cpu_clock|cpu_time_clocks|available_cpumask|current_cpu)|cpu_topology|host_thread_local)$' passed 23/23.

  • After this rebase, python3 tools/check_conventions.py --base upstream/main, git diff --check upstream/main...HEAD, and git diff --check passed.

  • Prior to this rebase, a full ctest --test-dir build --output-on-failure --no-tests=error --parallel 4 --timeout 30 run recorded 757 passed, 36 skipped, and 25 failed out of 818. The full suite has not been rerun at 21f4be11.

  • The same 25 cases were rerun under equivalent Release GCC options with ccache disabled on the earlier affinity branch and unchanged upstream/main 74c0f1bd1471967f05bba4fa1a94494dcf9f4e23: all 25 failed on both, with matching categories (14 subprocess aborts, 8 timeouts, 3 assertion failures). This shows those failures also occurred upstream in that environment; it does not establish the cause of each failure.

Windows and console behavior have not been validated.

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 in TechnicalDebt
  • 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:
  • AI-assisted:

The branch's merge base is the current upstream/main 74981fab, confirmed against GitHub. Searches found no open affinity or cpuset PR; open #3442 adds pthread_getthreadid_np in different functions and tests. No third-party code was added, so that item is inapplicable and left unchecked. Depends on: none; #3323 is already merged. AI-assisted: yes — Codex implemented and reviewed the change using the AnyPS5 contributor and Ponytail review workflows; the author remains responsible for every line.

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on Linux: build and ctest green (guest_available_cpumask passes, and fails with the non-test changes reverted). New threads now inherit the creator's mask (process mask for adopted threads) unless the attribute set one explicitly, matching FreeBSD, where threads join the creator's cpuset; the resolved TechnicalDebt sentence is removed. Merging.

@adriadam10
adriadam10 merged commit 97fbc7e into boykopovar:main Oct 11, 2026
13 of 14 checks passed
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.

2 participants