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})
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})
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
"-DROCKSDB_MALLOC_USABLE_SIZE",
"-DROCKSDB_RANGESYNC_PRESENT",
"-DROCKSDB_SCHED_GETCPU_PRESENT",
- "-DROCKSDB_SUPPORT_THREAD_LOCAL",
"-DOS_LINUX",
# Flags to enable libs we include
"-DSNAPPY",
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
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"
#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.
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
#include <stdint.h>
#include <string>
-#include "port/port.h"
#include "rocksdb/perf_level.h"
namespace rocksdb {
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();
#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
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;
#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) \
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)
#define IOSTATS_TIMER_GUARD(metric)
-#endif // ROCKSDB_SUPPORT_THREAD_LOCAL
+#endif // IOS_CROSS_COMPILE
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_;
#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;
}
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;
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)
//
#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) {
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
#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 {
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;
}
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
*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**)>
}
bool IsFastCrc32Supported() {
-#if defined(__SSE4_2__) || defined(_WIN64)
+#ifdef __SSE4_2__
+ return isSSE42();
+#elif defined(_WIN64)
return isSSE42();
#else
return false;
#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