diff options
author | Mark Geisert <mark@maxrnd.com> | 2025-03-18 00:53:57 -0700 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2025-03-18 10:26:40 +0100 |
commit | a7d7b9e32f8743b818cbe97dd06f3f16703c671b (patch) | |
tree | 910adb53d45b5c035f0c1a5b1ae89fa74ac4b2f3 | |
parent | f74dc93c6359d7821db4166cf03a3748983d721b (diff) | |
download | newlib-a7d7b9e32f8743b818cbe97dd06f3f16703c671b.zip newlib-a7d7b9e32f8743b818cbe97dd06f3f16703c671b.tar.gz newlib-a7d7b9e32f8743b818cbe97dd06f3f16703c671b.tar.bz2 |
Cygwin: Carry process affinity through to result
Due to deficient testing, the current code doesn't return a valid result
to users of sched_getaffinity(). The updated code carries the determined
procmask through to the generation of result cpu mask.
Recognize Windows' limitation that if the process is multi-group (i.e.,
has threads in multiple cpu groups) there is no visibility to which
processors in other groups are being used. One could remedy this by
looping through all the process' threads, but that could be expensive
so is left for future contemplation. In addition, we'd have to maintain
our own copy of each thread's current group and mask in internal overhead.
(By the way, multi-group processes are only possible on Windows systems
with more than 64 hardware threads.)
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257616.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: 641ecb07533e ("Cygwin: Implement sched_[gs]etaffinity()")
-rw-r--r-- | winsup/cygwin/release/3.6.0 | 4 | ||||
-rw-r--r-- | winsup/cygwin/sched.cc | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0 index d48ee11..ad4a6f5 100644 --- a/winsup/cygwin/release/3.6.0 +++ b/winsup/cygwin/release/3.6.0 @@ -132,3 +132,7 @@ Fixes: - Fix starving of auxiliary signal return address stack in case signal handlers bail out (longjmp/setcontext). Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257648.html + +- Fix sched_getaffinity(2) to carry determined process affinity all the way + through to the returned result. + Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257616.html diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc index 2f4fbc3..e15daad 100644 --- a/winsup/cygwin/sched.cc +++ b/winsup/cygwin/sched.cc @@ -587,9 +587,16 @@ __sched_getaffinity_sys (pid_t pid, size_t sizeof_set, cpu_set_t *set) goto done; } - KAFFINITY miscmask = groupmask (__get_cpus_per_group ()); + KAFFINITY fullmask = groupmask (__get_cpus_per_group ()); + /* if process is multi-group, we don't have processor visibility. */ + /*TODO We could provide the missing Windows visibility by book-keeping + each thread's current group and mask in our thread overhead, updating + them on sched_set_thread_affinity() calls. We could then assemble the + total mask here by looping through all threads. */ + if (groupcount > 1) + procmask = fullmask; for (int i = 0; i < groupcount; i++) - setgroup (sizeof_set, set, grouparray[i], miscmask); + setgroup (sizeof_set, set, grouparray[i], fullmask & procmask); } else status = ESRCH; |