From 06eed650a0e4aad03b71f229e596879471daae06 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 15 Dec 2014 11:29:41 +0100 Subject: [PATCH] Optimize default compile to compilation platform by default Summary: This diff changes compile to optimize for native platform by default. This will automatically turn on crc32 optimizations for modern processors, which greatly improves rocksdb's performance. I also did some more changes to compilation documentation. Test Plan: compile with `make`, observe -march=native compile with `PORTABLE=1 make`, observe no -march=native Reviewers: sdong, rven, yhchiang, MarkCallaghan Reviewed By: MarkCallaghan Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D30225 --- HISTORY.md | 1 + INSTALL.md | 16 +++++----------- build_tools/build_detect_platform | 8 ++++++-- build_tools/fbcode_config.sh | 2 +- build_tools/mac-install-gflags.sh | 25 ------------------------- 5 files changed, 13 insertions(+), 39 deletions(-) delete mode 100755 build_tools/mac-install-gflags.sh diff --git a/HISTORY.md b/HISTORY.md index bdb3325fe..e1b9f15a1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ### Unreleased Features * Changed the LRU caching algorithm so that referenced blocks (by iterators) are never evicted +* By default we now optimize the compilation for the compilation platform (using -march=native). If you want to build portable binary, use 'PORTABLE=1' before the make command. ### 3.9.0 (12/8/2014) diff --git a/INSTALL.md b/INSTALL.md index 21e8d26f0..330f8bcbd 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,7 +2,7 @@ RocksDB's library should be able to compile without any dependency installed, although we recommend installing some compression libraries (see below). -We do depend on newer gcc with C++11 support. +We do depend on newer gcc/clang with C++11 support. There are few options when compiling RocksDB: @@ -15,9 +15,9 @@ There are few options when compiling RocksDB: * `make all` will compile our static library, and all our tools and unit tests. Our tools depend on gflags. You will need to have gflags installed to run `make all`. -* if Intel SSE instruction set is supported, set USE_SSE=" -msse -msse4.2 " to make sure -SSE4.2 is used to speed up CRC32 when calculating data checksum. - +* By default the binary we produce is optimized for the platform you're compiling on +(-march=native). If you want to build a portable binary, add 'PORTABLE=1' before +your make commands, like this: `PORTABLE=1 make static_lib` ## Dependencies @@ -76,13 +76,7 @@ SSE4.2 is used to speed up CRC32 when calculating data checksum. * Install via [homebrew](http://brew.sh/). * If you're first time developer in MacOS, you still need to run: `xcode-select --install` in your command line. * run `brew tap homebrew/dupes; brew install gcc47 --use-llvm` to install gcc 4.7 (or higher). - * Install zlib, bzip2 and snappy libraries for compression. - * Install gflags. We have included a script - `build_tools/mac-install-gflags.sh`, which should automatically install it (execute this file instead of runing using "source" command). - If you installed gflags by other means (for example, `brew install gflags`), - please set `LIBRARY_PATH` and `CPATH` accordingly. - * Please note that some of the optimizations/features are disabled in OSX. - We did not run any production workloads on it. + * run `brew install rocksdb` * **iOS**: * Run: `TARGET_OS=IOS make static_lib`. When building the project which uses rocksdb iOS library, make sure to define two important pre-processing macros: `ROCKSDB_LITE` and `IOS_CROSS_COMPILE`. diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 7abccc8cc..3b3f34037 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -308,8 +308,12 @@ if test "$USE_HDFS"; then JAVA_LDFLAGS="$JAVA_LDFLAGS $HDFS_LDFLAGS" fi -# if Intel SSE instruction set is supported, set USE_SSE=" -msse -msse4.2 " -COMMON_FLAGS="$COMMON_FLAGS $USE_SSE" +if test "$USE_SSE"; then + # if Intel SSE instruction set is supported, set USE_SSE=1 + COMMON_FLAGS="$COMMON_FLAGS -msse -msse4.2 " +elif test -z "$PORTABLE"; then + COMMON_FLAGS="$COMMON_FLAGS -march=native -mtune=native " +fi PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS" PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS" diff --git a/build_tools/fbcode_config.sh b/build_tools/fbcode_config.sh index fefd48d59..7c1ff5147 100644 --- a/build_tools/fbcode_config.sh +++ b/build_tools/fbcode_config.sh @@ -48,7 +48,7 @@ LIBUNWIND_REV=2c060e64064559905d46fd194000d61592087bdc LIBUNWIND="/mnt/gvfs/third-party2/libunwind/$LIBUNWIND_REV/1.1/gcc-4.8.1-glibc-2.17/675d945/lib/libunwind.a" # use Intel SSE support for checksum calculations -export USE_SSE=" -msse -msse4.2 " +export USE_SSE=1 BINUTILS="/mnt/gvfs/third-party2/binutils/2aff2e7b474cd3e6ab23495ad1224b7d214b9f8e/2.21.1/centos6-native/da39a3e/bin" AR="$BINUTILS/ar" diff --git a/build_tools/mac-install-gflags.sh b/build_tools/mac-install-gflags.sh deleted file mode 100755 index a245a26a8..000000000 --- a/build_tools/mac-install-gflags.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -# Install gflags for mac developers. - -set -e - -DIR=`mktemp -d /tmp/rocksdb_gflags_XXXX` - -cd $DIR -wget https://gflags.googlecode.com/files/gflags-2.0.tar.gz -tar xvfz gflags-2.0.tar.gz -cd gflags-2.0 - -./configure -make -make install - -# Add include/lib path for g++ -echo 'export LIBRARY_PATH+=":/usr/local/lib"' >> ~/.bash_profile -echo 'export CPATH+=":/usr/local/include"' >> ~/.bash_profile - -echo "" -echo "-----------------------------------------------------------------------------" -echo "| Installation Completed |" -echo "-----------------------------------------------------------------------------" -echo "Please run \`. ~/.bash_profile\` to be able to compile with gflags"