[libcxx-commits] [libcxx] [libc++] Fixed get count threads multi-CPU system with NUMA architecture (#72267) (PR #72270)

Alexandre Ganea via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 16 08:03:08 PST 2023


https://github.com/aganea requested changes to this pull request.

@GermanAizek I would strongly advise that you take a look at, and copy-paste (unfortunately) the code from `llvm/lib/Support/Windows/Threading.inc`. Things are a bit more complicated that what you've did here: you need to account for Windows OS bugs, behavior before Windows 11 & after, affinity mask provided on process startup, etc.

Additionally, you can't just change the return value of `std::thread::hardware_concurrency()` you will also need to change the behavior of how the CPU affinity mask is set when a thread starts, see `llvm::ThreadPoolStrategy::apply_thread_strategy()` and its call sites. Users calling `std::thread::hardware_concurrency()` might use this value to create the same amount of threads, assuming that they will be equally spread out to cores/hardware-threads by the OS. Before Windows 11/Window Server 2019 this assumption will be wrong without  `apply_thread_strategy()`.

You can also take a look at these patches (in this order) for more context:

8404aeb56a73ab24f9b295111de3b37a37f0b841
09158252f777c2e2f06a86b154c44abcbcf9bb74
4fcb25583c3ccbe10c4367d02086269e5fa0bb87
e66500c7749578cf5e1372d0b52781259cb1fa28


https://github.com/llvm/llvm-project/pull/72270


More information about the libcxx-commits mailing list