Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Nov 2020 19:55:24 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r367815 - head/contrib/llvm-project/llvm/lib/Support/Unix
Message-ID:  <202011181955.0AIJtOtV009806@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Wed Nov 18 19:55:24 2020
New Revision: 367815
URL: https://svnweb.freebsd.org/changeset/base/367815

Log:
  For llvm's internal function which retrieves the number of available
  "hardware threads", use cpuset_getaffinity(2) on FreeBSD, so it will
  honor processor sets configured by the cpuset(1) command.
  
  This should make it possible to avoid e.g. lld creating a huge number of
  threads on a machine with many cores, even for linking simple programs.
  
  This will also be submitted upstream.
  
  Submitted by:	mjg
  MFC after:	1 week

Modified:
  head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc

Modified: head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc
==============================================================================
--- head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc	Wed Nov 18 19:47:24 2020	(r367814)
+++ head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc	Wed Nov 18 19:55:24 2020	(r367815)
@@ -26,6 +26,10 @@
 #include <pthread_np.h> // For pthread_getthreadid_np() / pthread_set_name_np()
 #endif
 
+#if defined(__FreeBSD__)
+#include <sys/cpuset.h>
+#endif
+
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include <errno.h>
 #include <sys/sysctl.h>
@@ -282,6 +286,13 @@ SetThreadPriorityResult llvm::set_thread_priority(Thre
 #include <thread>
 
 int computeHostNumHardwareThreads() {
+#ifdef __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);
+#endif
 #ifdef __linux__
   cpu_set_t Set;
   if (sched_getaffinity(0, sizeof(Set), &Set) == 0)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202011181955.0AIJtOtV009806>