Date: Thu, 3 Dec 2020 19:29:19 +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: r368309 - head/contrib/llvm-project/llvm/lib/Support/Unix Message-ID: <202012031929.0B3JTJjn095895@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dim Date: Thu Dec 3 19:29:18 2020 New Revision: 368309 URL: https://svnweb.freebsd.org/changeset/base/368309 Log: Merge commit d989ffd10 from llvm git (by Dimitry Andric): Implement computeHostNumHardwareThreads() for FreeBSD This retrieves CPU affinity via FreeBSD's cpuset(2) API, and makes LLVM respect affinity settings configured by the user via the cpuset(1) command. In particular, this allows to reduce the number of threads used on machines with high core counts, which can interact badly with parallelized build systems. This is particularly noticable with lld, which spawns lots of threads even for linking e.g. hello_world! This fix is related to PR48193, but does not adress the more fundamental problem, which is that LLVM by default grabs as many CPUs and/or threads as possible. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D92271 Originally 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 Thu Dec 3 19:26:21 2020 (r368308) +++ head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc Thu Dec 3 19:29:18 2020 (r368309) @@ -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 @@ SetThreadPriorityResult llvm::set_thread_priority(Thre #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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012031929.0B3JTJjn095895>