Skip to content

Conversation

JoostHouben
Copy link
Contributor

@JoostHouben JoostHouben commented Mar 15, 2025

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:
Screenshot 2025-03-15 155325

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.

On supported Windows platforms (Win11 or Server 2022), use newer APIs to
set CPU affinity correctly when there are more than 64 logical CPUs.

Fixes /Disservin#816.
@JoostHouben
Copy link
Contributor Author

Note I built the Windows binary using:

msys2_shell -defterm -here -no-start -ucrt64 -c "make -j build=release"

And the toolchain was installed from the msys2 shell using:

pacman -S mingw-w64-ucrt-x86_64-gcc

I'm not sure if the current Github workflow is configured correctly to use the UCRT. If building with a toolchain targeting an older Windows C runtime, the changes may fail to compile due to SetProcessDefaultCpuSetMasks not being defined. So the Github workflow may need to be updated.

If a maintainer approves the workflow run, I guess we will see.

@Disservin
Copy link
Owner

Wow! Thanks a lot for diagnosing this and fixing it :D

@Disservin Disservin added bug Something isn't working enhancement New feature or request labels Mar 16, 2025
@Disservin Disservin merged commit 6600ba1 into Disservin:master Mar 17, 2025
9 checks passed
@Disservin
Copy link
Owner

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting CPU affinity does not work correctly on Windows systems with >64 logical CPUs
2 participants