[llvm] 875adb4 - Host: Internalize computeHostNumPhysicalCores/computeHostNumHardwareThreads

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 23 21:09:50 PST 2022


Author: Fangrui Song
Date: 2022-11-23T21:09:45-08:00
New Revision: 875adb400754bb331d3540af67c94577ff58e8c8

URL: https://github.com/llvm/llvm-project/commit/875adb400754bb331d3540af67c94577ff58e8c8
DIFF: https://github.com/llvm/llvm-project/commit/875adb400754bb331d3540af67c94577ff58e8c8.diff

LOG: Host: Internalize computeHostNumPhysicalCores/computeHostNumHardwareThreads

Windows computeHostNumPhysicalCores is defined by Threading.cpp. Leave it
unchanged.

Added: 
    

Modified: 
    llvm/lib/Support/Host.cpp
    llvm/lib/Support/Threading.cpp
    llvm/lib/Support/Unix/Threading.inc
    llvm/lib/Support/Windows/Threading.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 6bb452a854b1a..713227c4b088c 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1580,7 +1580,7 @@ VendorSignatures getVendorSignature(unsigned *MaxLeaf) {
 // On Linux, the number of physical cores can be computed from /proc/cpuinfo,
 // using the number of unique physical/core id pairs. The following
 // implementation reads the /proc/cpuinfo format on an x86_64 system.
-int computeHostNumPhysicalCores() {
+static int computeHostNumPhysicalCores() {
   // Enabled represents the number of physical id/core id pairs with at least
   // one processor id enabled by the CPU affinity mask.
   cpu_set_t Affinity, Enabled;
@@ -1625,9 +1625,11 @@ int computeHostNumPhysicalCores() {
   return CPU_COUNT(&Enabled);
 }
 #elif defined(__linux__) && defined(__s390x__)
-int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); }
+static int computeHostNumPhysicalCores() {
+  return sysconf(_SC_NPROCESSORS_ONLN);
+}
 #elif defined(__linux__) && !defined(__ANDROID__)
-int computeHostNumPhysicalCores() {
+static int computeHostNumPhysicalCores() {
   cpu_set_t Affinity;
   if (sched_getaffinity(0, sizeof(Affinity), &Affinity) == 0)
     return CPU_COUNT(&Affinity);
@@ -1647,7 +1649,7 @@ int computeHostNumPhysicalCores() {
 }
 #elif defined(__APPLE__)
 // Gets the number of *physical cores* on the machine.
-int computeHostNumPhysicalCores() {
+static int computeHostNumPhysicalCores() {
   uint32_t count;
   size_t len = sizeof(count);
   sysctlbyname("hw.physicalcpu", &count, &len, NULL, 0);
@@ -1662,7 +1664,7 @@ int computeHostNumPhysicalCores() {
   return count;
 }
 #elif defined(__MVS__)
-int computeHostNumPhysicalCores() {
+static int computeHostNumPhysicalCores() {
   enum {
     // Byte offset of the pointer to the Communications Vector Table (CVT) in
     // the Prefixed Save Area (PSA). The table entry is a 31-bit pointer and

diff  --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp
index b14ff9549e438..bd954fd7c85aa 100644
--- a/llvm/lib/Support/Threading.cpp
+++ b/llvm/lib/Support/Threading.cpp
@@ -47,7 +47,7 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
 
 #else
 
-int computeHostNumHardwareThreads();
+static int computeHostNumHardwareThreads();
 
 unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
   int MaxThreadCount = UseHyperThreads ? computeHostNumHardwareThreads()

diff  --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 99f64b4f553d8..6a67401500317 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -290,7 +290,7 @@ SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
 
 #include <thread>
 
-int computeHostNumHardwareThreads() {
+static int computeHostNumHardwareThreads() {
 #if defined(__FreeBSD__)
   cpuset_t mask;
   CPU_ZERO(&mask);

diff  --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 11f34817dbbfc..7fa1937a2769b 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -247,7 +247,7 @@ int computeHostNumPhysicalCores() {
   return Cores;
 }
 
-int computeHostNumHardwareThreads() {
+static int computeHostNumHardwareThreads() {
   static unsigned Threads =
       aggregate(getProcessorGroups(),
                 [](const ProcessorGroup &G) { return G.UsableThreads; });


        


More information about the llvm-commits mailing list