Skip to content

Commit

Permalink
Makefile: check sse4.2 for tikv targets (#4314)
Browse files Browse the repository at this point in the history
* Makefile: check sse4.2 for tikv targets

Signed-off-by: Neil Shen <overvenus@gmail.com>
  • Loading branch information
overvenus committed Mar 5, 2019
1 parent e462c0a commit 0c2d142
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -61,15 +61,15 @@ build:
cargo build --features "${ENABLE_FEATURES}"

ctl:
@cargo build --release --features "${ENABLE_FEATURES}" --bin tikv-ctl
cargo build --release --features "${ENABLE_FEATURES}" --bin tikv-ctl
@mkdir -p ${BIN_PATH}
@cp -f ${CARGO_TARGET_DIR}/release/tikv-ctl ${BIN_PATH}/

run:
cargo run --features "${ENABLE_FEATURES}" --bin tikv-server

release:
@cargo build --release --features "${ENABLE_FEATURES}"
cargo build --release --features "${ENABLE_FEATURES}"
@mkdir -p ${BIN_PATH}
@cp -f ${CARGO_TARGET_DIR}/release/tikv-ctl ${CARGO_TARGET_DIR}/release/tikv-server ${CARGO_TARGET_DIR}/release/tikv-importer ${BIN_PATH}/

Expand Down Expand Up @@ -104,6 +104,7 @@ test:
cargo test --features "${ENABLE_FEATURES},mem-profiling" ${EXTRA_CARGO_ARGS} --bin tikv-server -- --nocapture --ignored; \
fi
bash etc/check-bins-for-jemalloc.sh
bash etc/check-sse4_2.sh

bench:
LOG_LEVEL=ERROR RUST_BACKTRACE=1 cargo bench --all --features "${ENABLE_FEATURES}" -- --nocapture
Expand Down
59 changes: 59 additions & 0 deletions etc/check-sse4_2.sh
@@ -0,0 +1,59 @@
#!/bin/bash
#
# This script makes sure that the tikv-server executables in the target
# directory enables intel® sse4.2 extensions. It is suitable to run as part of
# CI.

dirs="./target/debug ./target/release"

errors=0

# These need to check sse4.2.
targets="tikv-server tikv-importer"

if [[ "`uname`" != "Linux" ]]; then
echo "skipping sse4.2 check - not on Linux"
exit 0
fi

echo "checking bins for sse4.2"

for dir in $dirs; do
for file in $targets; do

dirfile="$dir/$file"
if [[ -x "$dirfile" && ! -d "$dirfile" ]]; then

echo "checking binary $dirfile for sse4.2"

# RocksDB uses sse4.2 in the `Fast_CRC32` function
fast_crc32=$(nm "$dirfile" | grep -o " _.*Fast_CRC32.*")
if [[ ! $fast_crc32 ]]; then
echo "error: $dirfile does not contain rocksdb::crc32c::Fast_CRC32 function"
errors=1
continue
fi

# Make sure the `Fast_CRC32` uses the sse4.2 instruction `crc32`
# f2.*0f 38 is the opcode of `crc32`, see Intel® SSE4 Programming Reference
found=0
for sym in $fast_crc32; do
echo $sym
if [[ `gdb -batch -ex "disass/r $sym" $dirfile 2> /dev/null | grep ">:.*f2.*0f 38.*crc32"` ]]; then
found=1
break
fi
done
if [[ "$found" -ne 1 ]]; then
echo "error: $dirfile does not enable sse4.2"
errors=1
fi
fi
done
done

if [[ "$errors" -ne 0 ]]; then
echo "some binaries do not enable sse4.2"
echo "fix this by building tikv with ROCKSDB_SYS_SSE=1"
exit 1
fi

0 comments on commit 0c2d142

Please sign in to comment.