summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-10-13 17:43:20 +0000
committerTeresa Johnson <tejohnson@google.com>2016-10-13 17:43:20 +0000
commit7943fecee8726d6411e0bc143268df32bfe47786 (patch)
treedbed7ae36250d40cdcd6db56c691f697680edc45 /llvm/unittests/Support
parent02c3e8cb7d5140f6e39ada91ffddd1dc65edf537 (diff)
downloadbcm5719-llvm-7943fecee8726d6411e0bc143268df32bfe47786.tar.gz
bcm5719-llvm-7943fecee8726d6411e0bc143268df32bfe47786.zip
Add interface to compute number of physical cores on host system
Summary: For now I have only added support for x86_64 Linux, but other systems can be added incrementally. This is to be used for setting the default parallelism for ThinLTO backends (instead of thread::hardware_concurrency which includes hyperthreading and is too aggressive). I'll send this as a follow-on patch, and it will fall back to hardware_concurrency when the new getHostNumPhysicalCores returns -1 (when not supported for a given host system). I also added an interface to MemoryBuffer to force reading a file as a stream - this is required for /proc/cpuinfo which is a special file that looks like a normal file but appears to have 0 size. The existing readers of this file in Host.cpp are reading the first 1024 or so bytes from it, because the necessary info is near the top. But for the new functionality we need to be able to read the entire file. I can go back and change the other readers to use the new getFileAsStream as a follow-on patch since it seems much more robust. Added a unittest. Reviewers: mehdi_amini Subscribers: beanz, mgorny, llvm-commits, modocache Differential Revision: https://reviews.llvm.org/D25564 llvm-svn: 284138
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/CMakeLists.txt1
-rw-r--r--llvm/unittests/Support/Host.cpp47
2 files changed, 48 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index 25c5dec80c1..9aef7210b1f 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -19,6 +19,7 @@ add_llvm_unittest(SupportTests
ErrorTest.cpp
ErrorOrTest.cpp
FileOutputBufferTest.cpp
+ Host.cpp
LEB128Test.cpp
LineIteratorTest.cpp
LockFileManagerTest.cpp
diff --git a/llvm/unittests/Support/Host.cpp b/llvm/unittests/Support/Host.cpp
new file mode 100644
index 00000000000..1fb0bc73314
--- /dev/null
+++ b/llvm/unittests/Support/Host.cpp
@@ -0,0 +1,47 @@
+//========- unittests/Support/Host.cpp - Host.cpp tests --------------========//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Host.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Triple.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+class HostTest : public testing::Test {
+ Triple Host;
+ SmallVector<std::pair<Triple::ArchType, Triple::OSType>, 4> SupportedArchAndOSs;
+
+protected:
+ bool isSupportedArchAndOS() {
+ if (is_contained(SupportedArchAndOSs, std::make_pair(Host.getArch(), Host.getOS())))
+ return true;
+
+ return false;
+ }
+
+ HostTest() {
+ 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.
+ SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Linux));
+ }
+};
+
+TEST_F(HostTest, NumPhysicalCores) {
+ int Num = sys::getHostNumPhysicalCores();
+
+ if (isSupportedArchAndOS())
+ ASSERT_GT(Num, 0);
+ else
+ ASSERT_EQ(Num, -1);
+}
OpenPOWER on IntegriCloud