Przeglądaj źródła

Merge pull request #7977 from ghalliday/issue14570

HPCC-14570 Allow get_cycles_now() to be inlined as getTSC()

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 9 lat temu
rodzic
commit
f15a384463
3 zmienionych plików z 20 dodań i 1 usunięć
  1. 10 0
      cmake_modules/commonSetup.cmake
  2. 2 0
      system/jlib/jdebug.cpp
  3. 8 1
      system/jlib/jdebug.hpp

+ 10 - 0
cmake_modules/commonSetup.cmake

@@ -84,6 +84,12 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
   option(GENERATE_COVERAGE_INFO "Generate coverage info for gcov" OFF)
   option(USE_SIGNED_CHAR "Build system with default char type is signed" OFF)
   option(USE_UNSIGNED_CHAR "Build system with default char type is unsigned" OFF)
+  # Generates code that is more efficient, but will cause problems if target platforms do not support it.
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" ON)
+  else()
+    option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" OFF)
+  endif()
 
   # Plugin options
   option(REMBED "Create a package with ONLY the R plugin" OFF)
@@ -254,6 +260,10 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
 
   set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DDEBUG")
 
+  IF (USE_INLINE_TSC)
+    add_definitions (-DINLINE_GET_CYCLES_NOW)
+  ENDIF()
+
   set (CMAKE_THREAD_PREFER_PTHREAD 1)
   find_package(Threads)
   IF (NOT THREADS_FOUND)

+ 2 - 0
system/jlib/jdebug.cpp

@@ -363,6 +363,7 @@ void calibrate_timing()
 }
 
 
+#if !defined(INLINE_GET_CYCLES_NOW) || !defined(HAS_GOOD_CYCLE_COUNTER)
 cycle_t jlib_decl get_cycles_now()
 {
 #if defined(_ARCH_X86_) || defined(_ARCH_X86_64_)
@@ -384,6 +385,7 @@ cycle_t jlib_decl get_cycles_now()
     gettimeofday(&tm,NULL);
     return ((cycle_t)tm.tv_sec)*1000000000L+(cycle_t)tm.tv_usec*1000L; 
 }
+#endif
 
 __int64 jlib_decl cycle_to_nanosec(cycle_t cycles)
 {

+ 8 - 1
system/jlib/jdebug.hpp

@@ -29,13 +29,14 @@ __int64 jlib_decl cycle_to_nanosec(cycle_t cycles);
 __int64 jlib_decl cycle_to_microsec(cycle_t cycles);
 __int64 jlib_decl cycle_to_millisec(cycle_t cycles);
 cycle_t jlib_decl nanosec_to_cycle(__int64 cycles);
-cycle_t jlib_decl get_cycles_now();  // equivalent to getTSC when available
 double jlib_decl getCycleToNanoScale();
 void jlib_decl display_time(const char * title, cycle_t diff);
 
 // X86 / X86_64
 #if defined(_ARCH_X86_64_) || defined(_ARCH_X86_)
 
+#define HAS_GOOD_CYCLE_COUNTER
+
 #if defined(_WIN32) && defined (_ARCH_X86_)
 #pragma warning(push)
 #pragma warning(disable:4035)
@@ -60,6 +61,12 @@ inline cycle_t getTSC() { return __rdtsc(); }
 inline cycle_t getTSC() { return 0; }
 #endif // X86
 
+#if defined(INLINE_GET_CYCLES_NOW) && defined(HAS_GOOD_CYCLE_COUNTER)
+inline cycle_t get_cycles_now() { return getTSC(); }
+#else
+cycle_t jlib_decl get_cycles_now();  // equivalent to getTSC when available
+#endif
+
 struct HardwareInfo
 {
     unsigned numCPUs;