Add Windows thread affinity support#338
Open
GagaLP wants to merge 1 commit into
Open
Conversation
|
Check-perf-impact results: (ae6918621b46271c2f10d6eb978fe95d) ❓ No new benchmark data submitted. ❓ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thread pinning was previously a no-op on Windows:
thread_pinneronly emitted a warning ("Thread pinning is currently not supported on Windows.") and did not apply any affinity settings, regardless of configuration.This PR adds a real implementation by introducing a small pthread/
cpu_set_tcompatibility layer (platform_specific/affinity_win32.h/.cc). The layer maps the POSIX affinity APIs already used by Celerity (sched_getaffinity/sched_setaffinity,pthread_self,pthread_get/setaffinity_np,CPU_SET/CPU_ISSET/CPU_COUNT, etc.) to their Windows equivalents (GetActiveProcessorGroupCount,GROUP_AFFINITY,SetThreadGroupAffinity).With this compatibility layer in place,
affinity_win.ccno longer requires separate pinning logic and now closely mirrors the Linux implementation. It initializes and tears down the pinning plan in the same way and pins threads to sequential cores using the same approach.One limitation to note: Windows organizes logical processors into groups of up to 64 processors, and a single
GROUP_AFFINITYmask cannot span multiple groups. If a requested core set crosses a group boundary, the layer currently emits a warning and skips pinning instead of attempting cross-group affinity. This should not affect the common case of pinning a small number of sequential cores, but remains a limitation on systems with more than 64 logical processors.Added corresponding tests in
affinity_tests.cc.