summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-10-19 22:36:07 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-10-19 22:36:07 +0000
commitdb46b7d217ed4462a4a02d0111e25593287dfcf1 (patch)
tree5e52b92a22b14963c0b4def8bbf8263a41aca7bf /llvm
parent3cb2a1e8d1b80633ead8d8a0abc8733bfaaede59 (diff)
downloadbcm5719-llvm-db46b7d217ed4462a4a02d0111e25593287dfcf1.tar.gz
bcm5719-llvm-db46b7d217ed4462a4a02d0111e25593287dfcf1.zip
Add computeHostNumPhysicalCores() implementation for Darwin
Differential Revision: https://reviews.llvm.org/D25800 llvm-svn: 284656
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Support/Host.cpp19
-rw-r--r--llvm/unittests/Support/Host.cpp5
2 files changed, 22 insertions, 2 deletions
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index e4a9b504a76..dd19eee15f6 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1234,6 +1234,25 @@ static int computeHostNumPhysicalCores() {
}
return UniqueItems.size();
}
+#elif defined(__APPLE__) && defined(__x86_64__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+// Gets the number of *physical cores* on the machine.
+static int computeHostNumPhysicalCores() {
+ uint32_t count;
+ size_t len = sizeof(count);
+ sysctlbyname("hw.physicalcpu", &count, &len, NULL, 0);
+ if (count < 1) {
+ int nm[2];
+ nm[0] = CTL_HW;
+ nm[1] = HW_AVAILCPU;
+ sysctl(nm, 2, &count, &len, NULL, 0);
+ if (count < 1)
+ return -1;
+ }
+ return count;
+}
#else
// On other systems, return -1 to indicate unknown.
static int computeHostNumPhysicalCores() { return -1; }
diff --git a/llvm/unittests/Support/Host.cpp b/llvm/unittests/Support/Host.cpp
index 1fb0bc73314..934a6049542 100644
--- a/llvm/unittests/Support/Host.cpp
+++ b/llvm/unittests/Support/Host.cpp
@@ -31,9 +31,10 @@ protected:
Host.setTriple(Triple::normalize(sys::getProcessTriple()));
// Initially this is only testing detection of the number of
- // physical cores, which is currently only supported for
- // x86_64 Linux.
+ // physical cores, which is currently only supported/tested for
+ // x86_64 Linux and Darwin.
SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Linux));
+ SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Darwin));
}
};
OpenPOWER on IntegriCloud