fix(linux): process_threads() counts the process's affinity mask on Linux #1669
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1669
Loading…
Reference in a new issue
No description provided.
Delete branch "Molier/Longshot:fix/linux-process-threads"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
process_threads()(host/hos_thread.c) answered 0 ("not known") on Linux, which some callers read as "assumeevery logical processor"; on Windows it reads
GetProcessAffinityMask. On Linux it now reads the process's ownaffinity mask through
sched_getaffinity/sysconf(_SC_NPROCESSORS_ONLN), matching the Windows branch's intent (thethreads the process may actually use, not just the machine's total). To see it on
main: callprocess_threads()on Linux and get 0 regardless of
taskset/cgroup limits; readhost/hos_thread.c— there is no Linux branch at all,only
#if defined(_WIN32).Read first:
host/hos_thread.c(the new Linux branch next to the existing Windows one),tests/process_threads_test.c.Testing
Tested: Linux (Ubuntu), host compile clean (
-fsyntax-only; one pre-existing unrelated warning,unused function 'pick_cache_cores', not from this change).tests/run_all.py process_threads:tests/test_process_threads.pypasses on the rebased head. The fix's own test fails on
mainwithout this commit: run against a cleanupstream/main @ 89c3d21echeckout with onlytests/process_threads_test.candtests/test_process_threads.pycopied in,
FAIL: process_threads() has no Linux branch (GetProcessAffinityMask of the process, else sysconf _SC_NPROCESSORS_ONLN)— confirmingmainstill answers 0 on Linux.Still to test:
taskset/cgroup CPU limit (fewer logical processors than the machine has): confirmprocess_threads()now returns the limited count, not the machine's full count (by hand).Measurements
Nothing to measure: a correctness fix (a missing return value), not a performance change on its own; any thread-count
decision downstream of it (core reservation, worker counts) is unchanged in its logic, only in what count it is
fed on Linux.
Risks
A caller that already special-cased "0 means assume every core" on Linux would now get a real, possibly smaller,
count; a search of the host tree for
process_threads()call sites found none that branch on 0 specially (it isused as a plain thread/core count). Turning it off is not applicable — this restores a return value, there is no
switch.
Checklist
Ready for review
main; the title is a Conventional Commit.tests/run_all.py process_threadspasses.third_party/untouched.When it applies
tests/test_process_threads.pyfails onmainand passes here (see Testing).Assisted-by:trailers.Ready to merge
Possibly related, for context:
fix(linux): process_threads() counts the process's processors, not the calling thread'sto WIP: fix(linux): process_threads() counts the process's processors, not the calling thread's23a6c7ba528308b77174WIP: fix(linux): process_threads() counts the process's processors, not the calling thread'sto WIP: fix(linux): process_threads() counts the process's affinity mask on Linux (was 0, "not known")HumanBean referenced this pull request2026-11-19 17:34:44 +00:00
8308b7717417a3d4b5bcWIP: fix(linux): process_threads() counts the process's affinity mask on Linux (was 0, "not known")to fix(linux): process_threads() counts the process's affinity mask on LinuxRebased onto
main@89c3d21e. Applied without conflicts. Fix check as the new template asks:tests/test_process_threads.pypasses on this head and fails on a cleanmaincheckout (process_threads() has no Linux branch). This head counts the mask the posix shim captured at process start rather thansched_getaffinity(0), which on Linux is the calling thread's mask (the host takes the reserved core off game threads, so a game thread would count 14 on a 16-thread CPU). For reference,main's own log on Linux currently readssleep: ... (0 logical processors, 0: not counted ...). Out of WIP; body rewritten in the new template.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.