[PATCH] D25585: Add interface for querying physical hardware concurrency

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 17:23:07 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL284180: Add interface for querying physical hardware concurrency (authored by tejohnson).

Changed prior to commit:
  https://reviews.llvm.org/D25585?vs=74597&id=74604#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25585

Files:
  llvm/trunk/include/llvm/Support/Threading.h
  llvm/trunk/lib/Support/Threading.cpp
  llvm/trunk/unittests/Support/CMakeLists.txt
  llvm/trunk/unittests/Support/Threading.cpp


Index: llvm/trunk/lib/Support/Threading.cpp
===================================================================
--- llvm/trunk/lib/Support/Threading.cpp
+++ llvm/trunk/lib/Support/Threading.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Atomic.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/thread.h"
 #include <cassert>
@@ -116,3 +117,10 @@
 }
 
 #endif
+
+unsigned llvm::hardware_physical_concurrency() {
+  int NumPhysical = sys::getHostNumPhysicalCores();
+  if (NumPhysical == -1)
+    return thread::hardware_concurrency();
+  return NumPhysical;
+}
Index: llvm/trunk/unittests/Support/Threading.cpp
===================================================================
--- llvm/trunk/unittests/Support/Threading.cpp
+++ llvm/trunk/unittests/Support/Threading.cpp
@@ -0,0 +1,25 @@
+//===- unittests/Threading.cpp - Thread 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/Threading.h"
+#include "llvm/Support/thread.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(Threading, PhysicalConcurrency) {
+  auto Num = hardware_physical_concurrency();
+  // Since Num is unsigned this will also catch us trying to
+  // return -1.
+  ASSERT_LE(Num, thread::hardware_concurrency());
+}
+
+} // end anon namespace
Index: llvm/trunk/unittests/Support/CMakeLists.txt
===================================================================
--- llvm/trunk/unittests/Support/CMakeLists.txt
+++ llvm/trunk/unittests/Support/CMakeLists.txt
@@ -40,6 +40,7 @@
   StringPool.cpp
   SwapByteOrderTest.cpp
   TargetParserTest.cpp
+  Threading.cpp
   ThreadLocalTest.cpp
   ThreadPool.cpp
   TimerTest.cpp
Index: llvm/trunk/include/llvm/Support/Threading.h
===================================================================
--- llvm/trunk/include/llvm/Support/Threading.h
+++ llvm/trunk/include/llvm/Support/Threading.h
@@ -115,6 +115,10 @@
     TsanHappensAfter(&flag);
 #endif
   }
+
+  /// Get the amount of currency based on physical cores, if available for the
+  /// host system, otherwise falls back to thread::hardware_concurrency().
+  unsigned hardware_physical_concurrency();
 }
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25585.74604.patch
Type: text/x-patch
Size: 2506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161014/132dfd72/attachment.bin>


More information about the llvm-commits mailing list