[PATCH] D78324: [Support][X86] Change getHostNumPhsicalCores() to return number of physical cores enabled by affinity

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 13:57:00 PDT 2020


aganea added a comment.

Check if this fixes PR45556; also if it works with `-DLLVM_ENABLE_THREADS=OFF` (it should, but who knows).



================
Comment at: llvm/lib/Support/Host.cpp:1287
   // mmapped because it appears to have 0 size.
+  cpu_set_t Set;
+  if (sched_getaffinity(0, sizeof(Set), &Set) != 0)
----------------
`cpu_set_t Affinity;` ?


================
Comment at: llvm/lib/Support/Host.cpp:1303
   int CurCoreId = -1;
   SmallSet<std::pair<int, int>, 32> UniqueItems;
+  for (StringRef Line : strs) {
----------------
Since you're here, it seems really overkill to use a Set to represent a bitfield (also, this will allocate if processors > 32). Can we have `cpu_set_t Enabled` here instead, and use `CPU_COUNT(Enabled)` at the end?


================
Comment at: llvm/lib/Support/Host.cpp:1318
+      if (CPU_ISSET(CurProcessor, &Set))
+        UniqueItems.insert(std::make_pair(CurPhysicalId, CurCoreId));
+      CurProcessor = -1;
----------------
`CPU_SET(CurProcessor, Enabled);` as suggested above?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78324/new/

https://reviews.llvm.org/D78324





More information about the llvm-commits mailing list