]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Revert "cross-platform compatibility improvements"
authorAaron Gao <gzh@fb.com>
Thu, 25 May 2017 01:18:51 +0000 (18:18 -0700)
committerAaron Gao <gzh@fb.com>
Thu, 25 May 2017 01:18:51 +0000 (18:18 -0700)
This reverts commit 11c5d4741a1e11a1315d5ca644ce555e07e91f61.

15 files changed:
CMakeLists.txt
INSTALL.md
TARGETS
build_tools/build_detect_platform
include/rocksdb/iostats_context.h
include/rocksdb/perf_context.h
include/rocksdb/thread_status.h
monitoring/iostats_context.cc
monitoring/iostats_context_imp.h
monitoring/perf_context.cc
monitoring/perf_context_imp.h
monitoring/perf_level.cc
monitoring/perf_level_imp.h
util/crc32c.cc
util/thread_local.h

index dec306881cc693ba8fb634750d278a53348ca5c4..075c3ed65b3452e23fd7be0700ae246e84473fb6 100644 (file)
@@ -106,58 +106,31 @@ if(NOT WIN32)
   string(STRIP "${ROCKSDB_VERSION_MAJOR}" ROCKSDB_VERSION_MAJOR)
 endif()
 
-option(WITH_MD_LIBRARY "build with MD" ON)
-if(WIN32 AND MSVC)
-  if(WITH_MD_LIBRARY)
-    set(RUNTIME_LIBRARY "MD")
-  else()
-    set(RUNTIME_LIBRARY "MT")
+if(WIN32)
+  option(WITH_AVX2 "build with AVX2" ON)
+  if(WITH_AVX2)
+    if(MSVC)
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
+    else()
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
+    endif()
   endif()
-endif()
 
-option(PORTABLE "build a portable binary" OFF)
-option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
-if(PORTABLE)
-  # MSVC does not need a separate compiler flag to enable SSE4.2; if nmmintrin.h
-  # is available, it is available by default.
-  if(FORCE_SSE42 AND NOT MSVC)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
+  option(WITH_MD_LIBRARY "build with MD" ON)
+  if(MSVC)
+    if(WITH_MD_LIBRARY)
+      set(RUNTIME_LIBRARY "MD")
+    else()
+      set(RUNTIME_LIBRARY "MT")
+    endif()
   endif()
 else()
-  if(MSVC)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
-  else()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
+  option(WITH_SSE42 "build with SSE4.2" ON)
+  if(WITH_SSE42)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
   endif()
 endif()
 
-set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
-include(CheckCXXSourceCompiles)
-CHECK_CXX_SOURCE_COMPILES("
-#include <cstdint>
-#include <nmmintrin.h>
-int main() {
-  volatile uint32_t x = _mm_crc32_u32(0, 0);
-}
-" HAVE_SSE42)
-if(HAVE_SSE42)
-  add_definitions(-DHAVE_SSE42)
-elseif(FORCE_SSE42)
-  message(FATAL_ERROR "FORCE_SSE42=ON but unable to compile with SSE4.2 enabled")
-endif()
-
-CHECK_CXX_SOURCE_COMPILES("
-#if defined(_MSC_VER) && !defined(__thread)
-#define __thread __declspec(thread)
-#endif
-int main() {
-  static __thread int tls;
-}
-" HAVE_THREAD_LOCAL)
-if(HAVE_THREAD_LOCAL)
-  add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
-endif()
-
 set(BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/build_version.cc)
 configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY)
 add_library(build_version OBJECT ${BUILD_VERSION_CC})
@@ -548,7 +521,7 @@ if(WIN32)
   set(SYSTEM_LIBS ${SYSTEM_LIBS} Shlwapi.lib Rpcrt4.lib)
   set(LIBS ${ROCKSDB_STATIC_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
 else()
-  set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
+  set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT} rt)
   set(LIBS ${ROCKSDB_SHARED_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
 
   add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES})
index cb791638135d203edd7d060e64b61ccba3d6d3f3..ce371d47177272141251a78927100f670334b564 100644 (file)
@@ -21,11 +21,9 @@ depend on gflags. You will need to have gflags installed to run `make all`. This
 use binaries compiled by `make all` in production.
 
 * By default the binary we produce is optimized for the platform you're compiling on
-(`-march=native` or the equivalent). SSE4.2 will thus be enabled automatically if your
-CPU supports it. To print a warning if your CPU does not support SSE4.2, build with
-`USE_SSE=1 make static_lib` or, if using CMake, `cmake -DFORCE_SSE42=ON`. If you want
-to build a portable binary, add `PORTABLE=1` before your make commands, like this:
-`PORTABLE=1 make static_lib`.
+(-march=native or the equivalent). If you want to build a portable binary, add 'PORTABLE=1' before
+your make commands, like this: `PORTABLE=1 make static_lib`. If you want to build a binary that
+makes use of SSE4, add 'USE_SSE=1' before your make commands, like this: `USE_SSE=1 make static_lib`.
 
 ## Dependencies
 
diff --git a/TARGETS b/TARGETS
index 29d5669630c054c270afd72826f55b9f2151c6d9..04ee7c7928b0a59115278f1b8ac891b1331293a2 100644 (file)
--- a/TARGETS
+++ b/TARGETS
@@ -11,7 +11,6 @@ rocksdb_compiler_flags = [
   "-DROCKSDB_MALLOC_USABLE_SIZE",
   "-DROCKSDB_RANGESYNC_PRESENT",
   "-DROCKSDB_SCHED_GETCPU_PRESENT",
-  "-DROCKSDB_SUPPORT_THREAD_LOCAL",
   "-DOS_LINUX",
   # Flags to enable libs we include
   "-DSNAPPY",
index 440c6a5e39f85059ab2a4d2e1fe09b954a25ed18..139841a3dcc71de84f9900b662cd7404e232f975 100755 (executable)
@@ -442,8 +442,14 @@ if test "$USE_HDFS"; then
   JAVA_LDFLAGS="$JAVA_LDFLAGS $HDFS_LDFLAGS"
 fi
 
+if [ "$TARGET_OS" = FreeBSD -a "$TARGET_ARCHITECTURE" = i386 ]; then
+  # Intel SSE instructions breaks compilation on FreeBSD i386
+  unset USE_SSE
+fi
+
 if test "$USE_SSE"; then
-  COMMON_FLAGS="$COMMON_FLAGS -msse4.2"
+  # if Intel SSE instruction set is supported, set USE_SSE=1
+  COMMON_FLAGS="$COMMON_FLAGS -msse -msse4.2 "
 elif test -z "$PORTABLE"; then
   if test -n "`echo $TARGET_ARCHITECTURE | grep ^ppc64`"; then
     # Tune for this POWER processor, treating '+' models as base models
@@ -456,36 +462,6 @@ elif test -z "$PORTABLE"; then
   fi
 fi
 
-$CXX $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
-  #include <cstdint>
-  #include <nmmintrin.h>
-  int main() {
-    volatile uint32_t x = _mm_crc32_u32(0, 0);
-  }
-EOF
-if [ "$?" = 0 ]; then
-  COMMON_FLAGS="$COMMON_FLAGS -DHAVE_SSE42"
-elif test "$USE_SSE"; then
-  echo "warning: USE_SSE specified but compiler could not use SSE intrinsics, disabling"
-fi
-
-# iOS doesn't support thread-local storage, but this check would erroneously
-# succeed because the cross-compiler flags are added by the Makefile, not this
-# script.
-if [ "$PLATFORM" != IOS ]; then
-  $CXX $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
-  #if defined(_MSC_VER) && !defined(__thread)
-  #define __thread __declspec(thread)
-  #endif
-  int main() {
-    static __thread int tls;
-  }
-EOF
-  if [ "$?" = 0 ]; then
-    COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_SUPPORT_THREAD_LOCAL"
-  fi
-fi
-
 PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
 PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
 
index 7be3afa591171dbbf68b0693488d8f24fa9736d4..d9880136edce8cdaa1a5c2cc7bb7faa013a97506 100644 (file)
@@ -7,7 +7,6 @@
 #include <stdint.h>
 #include <string>
 
-#include "port/port.h"
 #include "rocksdb/perf_level.h"
 
 // A thread local context for gathering io-stats efficiently and transparently.
@@ -47,8 +46,12 @@ struct IOStatsContext {
   uint64_t logger_nanos;
 };
 
-#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
+#ifndef IOS_CROSS_COMPILE
+# ifdef _MSC_VER
+extern __declspec(thread) IOStatsContext iostats_context;
+# else
 extern __thread IOStatsContext iostats_context;
-#endif
+# endif
+#endif  // IOS_CROSS_COMPILE
 
 }  // namespace rocksdb
index e3c86c39cbe1045666a333b1a0836c9ae2c60f20..76a5cac680219b098e3706c67f0e08c152197aa4 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdint.h>
 #include <string>
 
-#include "port/port.h"
 #include "rocksdb/perf_level.h"
 
 namespace rocksdb {
@@ -151,8 +150,10 @@ struct PerfContext {
   uint64_t env_new_logger_nanos;
 };
 
-#if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
+#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
 extern PerfContext perf_context;
+#elif defined(_MSC_VER)
+extern __declspec(thread) PerfContext perf_context;
 #else
   #if defined(OS_SOLARIS)
     PerfContext *getPerfContext();
index 294c6cb3b5864e9bd3805d8a3ead00639e1c24f2..9bac253a6e6312da299ac9183765fcf0adbe811b 100644 (file)
@@ -22,7 +22,8 @@
 
 #if !defined(ROCKSDB_LITE) && \
     !defined(NROCKSDB_THREAD_STATUS) && \
-    defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
+    !defined(OS_MACOSX) && \
+    !defined(IOS_CROSS_COMPILE)
 #define ROCKSDB_USING_THREAD_STATUS
 #endif
 
index 0bcc99afd9abceaa1ccc4168f50c0adf6988506a..e9970e1f7e2953bc11a72362e3fd160940a5ecf9 100644 (file)
@@ -9,9 +9,13 @@
 
 namespace rocksdb {
 
-#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
+#ifndef IOS_CROSS_COMPILE
+# ifdef _MSC_VER
+__declspec(thread) IOStatsContext iostats_context;
+# else
 __thread IOStatsContext iostats_context;
-#endif
+# endif
+#endif  // IOS_CROSS_COMPILE
 
 void IOStatsContext::Reset() {
   thread_pool_id = Env::Priority::TOTAL;
index b787c70dfaeb7d41d6591472d2dbadb58a2406d3..4758f39fce62b30228063e899e4c0bac65a084ef 100644 (file)
@@ -9,7 +9,7 @@
 #include "monitoring/perf_step_timer.h"
 #include "rocksdb/iostats_context.h"
 
-#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
+#ifndef IOS_CROSS_COMPILE
 
 // increment a specific counter by the specified value
 #define IOSTATS_ADD(metric, value)     \
@@ -41,7 +41,7 @@
   PerfStepTimer iostats_step_timer_ ## metric(&(iostats_context.metric));  \
   iostats_step_timer_ ## metric.Start();
 
-#else  // ROCKSDB_SUPPORT_THREAD_LOCAL
+#else  // IOS_CROSS_COMPILE
 
 #define IOSTATS_ADD(metric, value)
 #define IOSTATS_ADD_IF_POSITIVE(metric, value)
@@ -53,4 +53,4 @@
 
 #define IOSTATS_TIMER_GUARD(metric)
 
-#endif  // ROCKSDB_SUPPORT_THREAD_LOCAL
+#endif  // IOS_CROSS_COMPILE
index 65158c769db4ebef4e1d34cff424f613ddd0fb2b..2fdcde506322651b21376957f7d080837301e0c8 100644 (file)
 
 namespace rocksdb {
 
-#if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
+#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
   PerfContext perf_context;
+#elif defined(_MSC_VER)
+  __declspec(thread) PerfContext perf_context;
 #else
   #if defined(OS_SOLARIS)
     __thread PerfContext perf_context_;
@@ -22,7 +24,7 @@ namespace rocksdb {
 #endif
 
 void PerfContext::Reset() {
-#if !defined(NPERF_CONTEXT) && defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
+#if !defined(NPERF_CONTEXT) && !defined(IOS_CROSS_COMPILE)
   user_key_comparison_count = 0;
   block_cache_hit_count = 0;
   block_read_count = 0;
@@ -96,7 +98,7 @@ void PerfContext::Reset() {
   }
 
 std::string PerfContext::ToString(bool exclude_zero_counters) const {
-#if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
+#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
   return "";
 #else
   std::ostringstream ss;
index 1b9ac2f40f29709a55524bd835fec1e0119974b8..104f0a8e5c15ebb52b674414f73fccaa66ffb382 100644 (file)
@@ -12,7 +12,7 @@
 
 namespace rocksdb {
 
-#if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
+#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
 
 #define PERF_TIMER_GUARD(metric)
 #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition)
index 32c8ed392e90f2138cc55c68ef3125927d4c8d6e..d04725f04bceed502b0047e91a135eb45b76199f 100644 (file)
@@ -7,14 +7,16 @@
 //
 
 #include <assert.h>
+#include <sstream>
 #include "monitoring/perf_level_imp.h"
+#include "port/port.h"
 
 namespace rocksdb {
 
-#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
-__thread PerfLevel perf_level = kEnableCount;
-#else
+#if defined(IOS_CROSS_COMPILE)
 PerfLevel perf_level = kEnableCount;
+#else
+__thread PerfLevel perf_level = kEnableCount;
 #endif
 
 void SetPerfLevel(PerfLevel level) {
index 46f701e5d77b84a2109ea4c7a78ca2e8c3c1e071..ab02f9d724efd5b87b5dc747df3eaa9ef40d0b8e 100644 (file)
 
 namespace rocksdb {
 
-#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
-extern __thread PerfLevel perf_level;
-#else
+#if defined(IOS_CROSS_COMPILE)
 extern PerfLevel perf_level;
+#else
+extern __thread PerfLevel perf_level;
 #endif
 
 }  // namespace rocksdb
index a171b409e2ca9bba4ab3e756289e00a8e8229051..c2334d673a131aafef77bce1c83b0ddb3915ba02 100644 (file)
 #include "util/crc32c.h"
 
 #include <stdint.h>
-#ifdef HAVE_SSE42
+#ifdef __SSE4_2__
 #include <nmmintrin.h>
 #endif
+#if defined(_WIN64)
+#ifdef __AVX2__
+#include <nmmintrin.h>
+#endif
+#endif
 #include "util/coding.h"
 
 namespace rocksdb {
@@ -293,12 +298,21 @@ static inline uint32_t LE_LOAD32(const uint8_t *p) {
   return DecodeFixed32(reinterpret_cast<const char*>(p));
 }
 
-#if defined(HAVE_SSE42) && (defined(__LP64__) || defined(_WIN64))
+#ifdef __SSE4_2__
+#ifdef __LP64__
 static inline uint64_t LE_LOAD64(const uint8_t *p) {
   return DecodeFixed64(reinterpret_cast<const char*>(p));
 }
 #endif
+#endif
 
+#if defined(_WIN64)
+#ifdef __AVX2__
+static inline uint64_t LE_LOAD64(const uint8_t *p) {
+  return DecodeFixed64(reinterpret_cast<const char*>(p));
+}
+#endif
+#endif
 static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
   uint32_t c = static_cast<uint32_t>(*l ^ LE_LOAD32(*p));
   *p += 4;
@@ -316,9 +330,8 @@ static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
 }
 
 static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) {
-#ifndef HAVE_SSE42
-  Slow_CRC32(l, p);
-#elif defined(__LP64__) || defined(_WIN64)
+#ifdef __SSE4_2__
+#ifdef __LP64__
   *l = _mm_crc32_u64(*l, LE_LOAD64(*p));
   *p += 8;
 #else
@@ -327,6 +340,16 @@ static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) {
   *l = _mm_crc32_u32(static_cast<unsigned int>(*l), LE_LOAD32(*p));
   *p += 4;
 #endif
+#elif defined(_WIN64)
+#ifdef __AVX2__
+  *l = _mm_crc32_u64(*l, LE_LOAD64(*p));
+  *p += 8;
+#else
+  Slow_CRC32(l, p);
+#endif
+#else
+  Slow_CRC32(l, p);
+#endif
 }
 
 template<void (*CRC32)(uint64_t*, uint8_t const**)>
@@ -395,7 +418,9 @@ static inline Function Choose_Extend() {
 }
 
 bool IsFastCrc32Supported() {
-#if defined(__SSE4_2__) || defined(_WIN64)
+#ifdef __SSE4_2__
+  return isSSE42();
+#elif defined(_WIN64)
   return isSSE42();
 #else
   return false;
index 1f2fa46899ddee3f4e800230f414b755b3fab590..3befddc8a06a70ebbc1ed5083b9f12c3369816cd 100644 (file)
 #include "util/autovector.h"
 #include "port/port.h"
 
+#ifndef ROCKSDB_SUPPORT_THREAD_LOCAL
+#  if defined(OS_WIN) || defined(OS_MACOSX) || defined(IOS_CROSS_COMPILE)
+#    define ROCKSDB_SUPPORT_THREAD_LOCAL 0
+#  else
+#    define ROCKSDB_SUPPORT_THREAD_LOCAL 1
+#  endif
+#endif
+
 namespace rocksdb {
 
 // Cleanup function that will be called for a stored thread local