Преглед изворни кода

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

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday пре 9 година
родитељ
комит
b291b97d82
3 измењених фајлова са 15 додато и 1 уклоњено
  1. 5 0
      cmake_modules/commonSetup.cmake
  2. 2 0
      system/jlib/jdebug.cpp
  3. 8 1
      system/jlib/jdebug.hpp

+ 5 - 0
cmake_modules/commonSetup.cmake

@@ -81,6 +81,7 @@ 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)
+  option(USE_INLINE_TSC "Inline calls to read TSC (time stamp counter)" ON)  # Generates code that is more efficient, but will cause problems if target platforms do not support it.
 
   option(WITH_PLUGINS "Enable the building of plugins" ON)
   # WITH_PLUGINS = OFF will disable all of the following, else they can be set off on a case by case basis
@@ -168,6 +169,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

@@ -358,6 +358,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_)
@@ -377,6 +378,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)
@@ -61,6 +62,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;