Add Windows support for CPU affinity for >64 CPUs. #817
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On supported Windows platforms (Win11 or Server 2022), use newer APIs to set CPU affinity correctly when there are more than 64 logical CPUs.
Resolves #816, at least for those newer Windows platforms.
With this change, running concurrency 64 on a 7980X (64 cores, 128 SMT threads) on Windows 11 and enabling CPU affinity now results in the expected CPU utilization:

As you can see, the first logical CPU of each of the 64 physical cores is now being utilized. This results in better and more consistent performance.
I've also validated that the app still works on Windows 10 (where
SetProcessDefaultCpuSetMasks
is not available), both with and without setting CPU affinity. Note that the Windows 10 system is a 4 core / 8 thread machine. I don't think testing on a >64 thread Windows 10 system is required.