From nobody Wed Dec 22 10:06:24 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F27C41906983; Wed, 22 Dec 2021 10:06:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JJprN1sFlz4YpM; Wed, 22 Dec 2021 10:06:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 69E9B1B26D; Wed, 22 Dec 2021 10:06:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BMA6OpX092636; Wed, 22 Dec 2021 10:06:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BMA6OoW092635; Wed, 22 Dec 2021 10:06:24 GMT (envelope-from git) Date: Wed, 22 Dec 2021 10:06:24 GMT Message-Id: <202112221006.1BMA6OoW092635@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: dfff2e2d5c36 - stable/12 - 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. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: dfff2e2d5c3629ed88f3dcdce79a88653ca36f23 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640167591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t8uQs1Oklfz5mwYp0Jb4Bs5w/OckwDwmNm9qhxdJcfc=; b=GwyijqUoDrfHnXVjwDeGagX/VRBRBK/RSISvaAoR6DwW0EXK4AK1pulz5MChk3iD+VZnwH 9iauaRCSAO+1WA40ysVBD2BQzLvcTVE9QQcF8ygm9e/mG4ttbctSx0zSbjHka/7vUZt/Pw jnPCXWzOZKE3U/hGBzXcV+rKGvNVyVJs86o7vaJE3X7VL24DDopgOu1QDNnmazSnvaorJU sF19PM6OglqYid5/VUZ3ys6GT4G+XA/T9oTLxF6saHXUwNHG1MCVbzBCrOrhCewG2JQYlf FgiUeJZsLaVtvfDwKVMONNF77tv3obcCfq+T/R4fGrChChpi8fsJymzkGPFsNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640167591; a=rsa-sha256; cv=none; b=OGDRssjAW6M2/3Zi/rhjxf3pTMQPw0axrvxYxK2qigyASyvP4jY0IsGsCk16r54xS6LBoz ccpwaLhwGxIfPkNx7ZRS9h1NfSw4XVI1joYJzy/1Ln/BZrE5H/c4DVgy/U+UDf9Lpa/3RW WMMY+uOjnLdKczZjFJr8lWQP6gXJwApHKa0Xyj9v28ABI5Y3y1kK718AD0xwz4MnawJ170 psGWcDXHxt3WdBRPtv++iYq45DYYdMk/+MIaKSAr6Cx4uGXUlZUI90YAuHjQNxjg2r5oGD ATOBWVDcyZK2a2fFaHnsz570Tn7PzrUq/sUk/0C+uqo6EsO6/Zh1S603btgFMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=dfff2e2d5c3629ed88f3dcdce79a88653ca36f23 commit dfff2e2d5c3629ed88f3dcdce79a88653ca36f23 Author: Dimitry Andric AuthorDate: 2020-11-18 19:55:24 +0000 Commit: Dimitry Andric CommitDate: 2021-12-22 10:01:22 +0000 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 (cherry picked from commit 991f6e7534a9b1a99b7da711676e6714e2cf6680) --- contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc b/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc index 2d0aacabf092..df290d2262ea 100644 --- a/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc +++ b/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc @@ -26,6 +26,10 @@ #include // For pthread_getthreadid_np() / pthread_set_name_np() #endif +#if defined(__FreeBSD__) +#include +#endif + #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #include #include @@ -282,6 +286,13 @@ SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) { #include 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)