[PATCH] D92271: Implement computeHostNumHardwareThreads() for FreeBSD

Dimitry Andric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 28 15:50:05 PST 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd989ffd109b2: Implement computeHostNumHardwareThreads() for FreeBSD (authored by dim).

Changed prior to commit:
  https://reviews.llvm.org/D92271?vs=308187&id=308189#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92271

Files:
  llvm/lib/Support/Unix/Threading.inc


Index: llvm/lib/Support/Unix/Threading.inc
===================================================================
--- llvm/lib/Support/Unix/Threading.inc
+++ llvm/lib/Support/Unix/Threading.inc
@@ -28,6 +28,7 @@
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include <errno.h>
+#include <sys/cpuset.h>
 #include <sys/sysctl.h>
 #include <sys/user.h>
 #include <unistd.h>
@@ -282,7 +283,13 @@
 #include <thread>
 
 int computeHostNumHardwareThreads() {
-#ifdef __linux__
+#if defined(__FreeBSD__)
+  cpuset_t mask;
+  CPU_ZERO(&mask);
+  if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
+                         &mask) == 0)
+    return CPU_COUNT(&mask);
+#elif defined(__linux__)
   cpu_set_t Set;
   if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
     return CPU_COUNT(&Set);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92271.308189.patch
Type: text/x-patch
Size: 816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201128/ccabd189/attachment.bin>


More information about the llvm-commits mailing list