mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 17:40:34 +00:00
Rebase to Fedora 43 with clang 21.1 and libstdc++ 15. Fedora container image registry moved to registry.fedoraproject.org as it seems to be updated more regularly. Added python3-devel to the dependencies as some packages scylla-cqlsh depends on aren't yet available in the form of wheels for Python 3.14, and so have to be built locally. In any case it's better to reduce dependency on those wheels even if the ones currently missing appear eventually. Added libev-devel to the dependencies so that the python driver builds correctly even if "wheels" are not published. This reduces our dependency on the python driver's binary release schedule. Without libev-devel, TLS does not work correctly. We no long remove the clang and clang-libs packages. Doxygen started depending on clang-libs, and removing them removes doxygen, breaking the build when it looks for that. The build will still pick up the optimized clang, since /usr/local/bin is earlier in the path. We keep the clang package, since it allows us to mess a little less with the directory structure. Optimized clang binaries generates and stored in https://devpkg.scylladb.com/clang/clang-21.1.6-Fedora-43-aarch64.tar.gz https://devpkg.scylladb.com/clang/clang-21.1.6-Fedora-43-x86_64.tar.gz With ./scripts/refresh-pgo-profiles.sh, the new compiler shows a small performance improvement (instructions_per_op) in perf-simple-query: clang 21: 259353.60 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35720 insns/op, 17427 cycles/op, 0 errors) 265940.08 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35725 insns/op, 17042 cycles/op, 0 errors) 262650.01 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35720 insns/op, 17240 cycles/op, 0 errors) 262881.22 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35675 insns/op, 17222 cycles/op, 0 errors) 264898.68 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35732 insns/op, 17070 cycles/op, 0 errors) throughput: mean= 263144.72 standard-deviation=2528.69 median= 262881.22 median-absolute-deviation=1753.96 maximum=265940.08 minimum=259353.60 instructions_per_op: mean= 35714.47 standard-deviation=22.34 median= 35720.38 median-absolute-deviation=10.20 maximum=35732.14 minimum=35675.50 cpu_cycles_per_op: mean= 17200.12 standard-deviation=154.62 median= 17221.70 median-absolute-deviation=129.77 maximum=17427.33 minimum=17041.57 clang 20: 254431.39 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35883 insns/op, 17708 cycles/op, 0 errors) 259701.02 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35883 insns/op, 17351 cycles/op, 0 errors) 261166.92 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35912 insns/op, 17270 cycles/op, 0 errors) 260656.31 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35869 insns/op, 17289 cycles/op, 0 errors) 259628.13 tps ( 64.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 35946 insns/op, 17370 cycles/op, 0 errors) throughput: mean= 259116.75 standard-deviation=2698.56 median= 259701.02 median-absolute-deviation=1539.55 maximum=261166.92 minimum=254431.39 instructions_per_op: mean= 35898.42 standard-deviation=30.69 median= 35882.97 median-absolute-deviation=15.90 maximum=35945.63 minimum=35869.02 cpu_cycles_per_op: mean= 17397.49 standard-deviation=178.35 median= 17351.35 median-absolute-deviation=108.79 maximum=17707.63 minimum=17269.68 Closes scylladb/scylladb#26773
189 lines
6.4 KiB
Bash
Executable File
189 lines
6.4 KiB
Bash
Executable File
#!/bin/bash -ue
|
|
|
|
trap 'echo "error $? in $0 line $LINENO"' ERR
|
|
|
|
case "${CLANG_BUILD}" in
|
|
"SKIP")
|
|
echo "CLANG_BUILD: ${CLANG_BUILD}"
|
|
exit 0
|
|
;;
|
|
"INSTALL" | "INSTALL_FROM")
|
|
echo "CLANG_BUILD: ${CLANG_BUILD}"
|
|
if [[ -z "${CLANG_ARCHIVES}" ]]; then
|
|
echo "CLANG_ARCHIVES not specified"
|
|
exit 1
|
|
fi
|
|
;;
|
|
"")
|
|
echo "CLANG_BUILD not specified"
|
|
exit 1
|
|
;;
|
|
*)
|
|
echo "Invalid mode specified on CLANG_BUILD: ${CLANG_BUILD}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
ARCH="$(arch)"
|
|
|
|
# deserialize CLANG_ARCHIVES from string
|
|
declare -A CLANG_ARCHIVES_ARRAY=()
|
|
while IFS=":" read -r key val; do
|
|
CLANG_ARCHIVES_ARRAY["$key"]="$val"
|
|
done < <(echo "$CLANG_ARCHIVES" | tr ' ' '\n')
|
|
|
|
|
|
CLANG_ARCHIVE="${CLANG_ARCHIVES_ARRAY[${ARCH}]}"
|
|
if [[ -z ${CLANG_ARCHIVE} ]]; then
|
|
echo "CLANG_ARCHIVE not detected"
|
|
exit 1
|
|
fi
|
|
echo "CLANG_ARCHIVE: ${CLANG_ARCHIVE}"
|
|
if [[ "${ARCH}" = "x86_64" ]]; then
|
|
LLVM_TARGET_ARCH=X86
|
|
LLVM_CXX_FLAGS="-march=x86-64-v3"
|
|
elif [[ "${ARCH}" = "aarch64" ]]; then
|
|
LLVM_TARGET_ARCH=AArch64
|
|
# Based on https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/compiler-flags-across-architectures-march-mtune-and-mcpu
|
|
# and https://github.com/aws/aws-graviton-getting-started/blob/main/c-c%2B%2B.md
|
|
LLVM_CXX_FLAGS="-march=armv8.2-a+crc+crypto"
|
|
else
|
|
echo "Unsupported architecture: ${ARCH}"
|
|
exit 1
|
|
fi
|
|
|
|
SCYLLA_DIR=/mnt
|
|
CLANG_ROOT_DIR="${SCYLLA_DIR}"/clang_build
|
|
CLANG_CHECKOUT_NAME=llvm-project-"${ARCH}"
|
|
CLANG_BUILD_DIR="${CLANG_ROOT_DIR}"/"${CLANG_CHECKOUT_NAME}"
|
|
CLANG_SYSROOT_NAME=optimized_clang-"${ARCH}"
|
|
CLANG_SYSROOT_DIR="${CLANG_ROOT_DIR}"/"${CLANG_SYSROOT_NAME}"
|
|
|
|
SCYLLA_BUILD_DIR=build_profile
|
|
SCYLLA_NINJA_FILE=build_profile.ninja
|
|
SCYLLA_BUILD_DIR_FULLPATH="${SCYLLA_DIR}"/"${SCYLLA_BUILD_DIR}"
|
|
SCYLLA_NINJA_FILE_FULLPATH="${SCYLLA_DIR}"/"${SCYLLA_NINJA_FILE}"
|
|
|
|
# Which LLVM release to build in order to compile Scylla
|
|
LLVM_CLANG_TAG=21.1.6
|
|
|
|
CLANG_ARCHIVE=$(cd "${SCYLLA_DIR}" && realpath -m "${CLANG_ARCHIVE}")
|
|
|
|
CLANG_OPTS=(
|
|
-G Ninja
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
-DCMAKE_C_COMPILER="/usr/bin/clang"
|
|
-DCMAKE_CXX_COMPILER="/usr/bin/clang++"
|
|
-DLLVM_USE_LINKER="/usr/bin/ld.lld"
|
|
-DLLVM_TARGETS_TO_BUILD="${LLVM_TARGET_ARCH};WebAssembly"
|
|
-DLLVM_TARGET_ARCH="${LLVM_TARGET_ARCH}"
|
|
-DLLVM_INCLUDE_BENCHMARKS=OFF
|
|
-DLLVM_INCLUDE_EXAMPLES=OFF
|
|
-DLLVM_INCLUDE_TESTS=OFF
|
|
-DLLVM_ENABLE_BINDINGS=OFF
|
|
-DLLVM_ENABLE_PROJECTS="clang"
|
|
-DLLVM_ENABLE_RUNTIMES="compiler-rt"
|
|
-DLLVM_ENABLE_LTO=Thin
|
|
-DCLANG_DEFAULT_PIE_ON_LINUX=OFF
|
|
-DLLVM_BUILD_TOOLS=OFF
|
|
-DLLVM_VP_COUNTERS_PER_SITE=6
|
|
-DLLVM_BUILD_LLVM_DYLIB=ON
|
|
-DLLVM_LINK_LLVM_DYLIB=ON
|
|
-DCMAKE_INSTALL_PREFIX="/usr/local"
|
|
-DLLVM_LIBDIR_SUFFIX=64
|
|
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON
|
|
-DCMAKE_CXX_FLAGS="${LLVM_CXX_FLAGS}"
|
|
)
|
|
SCYLLA_OPTS=(
|
|
--date-stamp "$(date "+%Y%m%d")"
|
|
--debuginfo 1
|
|
--tests-debuginfo 1
|
|
--c-compiler="${CLANG_BUILD_DIR}/build/bin/clang"
|
|
--compiler="${CLANG_BUILD_DIR}/build/bin/clang++"
|
|
--build-dir="${SCYLLA_BUILD_DIR}"
|
|
--out="${SCYLLA_NINJA_FILE}"
|
|
--use-profile=""
|
|
)
|
|
|
|
# Utilizing LLVM_DISTRIBUTION_COMPONENTS to avoid
|
|
# installing static libraries; inspired by Gentoo
|
|
_get_distribution_components() {
|
|
local target
|
|
ninja -t targets | grep -Po 'install-\K.*(?=-stripped:)' | while read -r target; do
|
|
case $target in
|
|
clang-libraries|distribution)
|
|
continue
|
|
;;
|
|
clang-tidy-headers)
|
|
continue
|
|
;;
|
|
clang|clangd|clang-*)
|
|
;;
|
|
clang*|findAllSymbols)
|
|
continue
|
|
;;
|
|
esac
|
|
echo $target
|
|
done
|
|
}
|
|
|
|
if [[ "${CLANG_BUILD}" = "INSTALL" ]]; then
|
|
rm -rf "${CLANG_BUILD_DIR}"
|
|
rm -rf "${CLANG_SYSROOT_DIR}"
|
|
git clone https://github.com/llvm/llvm-project --branch llvmorg-"${LLVM_CLANG_TAG}" --depth=1 "${CLANG_BUILD_DIR}"
|
|
|
|
echo "[clang-stage1] build the compiler for collecting PGO profile"
|
|
cd "${CLANG_BUILD_DIR}"
|
|
|
|
rm -rf build
|
|
cmake -B build -S llvm "${CLANG_OPTS[@]}" -DLLVM_BUILD_INSTRUMENTED=IR
|
|
DISTRIBUTION_COMPONENTS=$(cd build && _get_distribution_components | paste -sd\;)
|
|
test -n "${DISTRIBUTION_COMPONENTS}"
|
|
CLANG_OPTS+=(-DLLVM_DISTRIBUTION_COMPONENTS="${DISTRIBUTION_COMPONENTS}")
|
|
cmake -B build -S llvm "${CLANG_OPTS[@]}" -DLLVM_BUILD_INSTRUMENTED=IR
|
|
ninja -C build
|
|
|
|
echo "[scylla-stage1] gather a clang profile for PGO"
|
|
rm -rf "${SCYLLA_BUILD_DIR_FULLPATH}" "${SCYLLA_NINJA_FILE_FULLPATH}"
|
|
cd "${SCYLLA_DIR}"
|
|
./configure.py "${SCYLLA_OPTS[@]}"
|
|
LLVM_PROFILE_FILE="${CLANG_BUILD_DIR}"/build/profiles/default_%p-%m.profraw ninja -f "${SCYLLA_NINJA_FILE}" compiler-training
|
|
|
|
echo "[clang-stage2] build the compiler applied PGO profile and for collecting CSPGO profile"
|
|
cd "${CLANG_BUILD_DIR}"
|
|
llvm-profdata merge "${CLANG_BUILD_DIR}"/build/profiles/default_*.profraw -output=ir.prof
|
|
rm -rf build
|
|
cmake -B build -S llvm "${CLANG_OPTS[@]}" -DLLVM_BUILD_INSTRUMENTED=CSIR -DLLVM_PROFDATA_FILE="$(realpath ir.prof)"
|
|
ninja -C build
|
|
|
|
echo "[scylla-stage2] gathering a clang profile for CSPGO"
|
|
rm -rf "${SCYLLA_BUILD_DIR_FULLPATH}" "${SCYLLA_NINJA_FILE_FULLPATH}"
|
|
cd "${SCYLLA_DIR}"
|
|
./configure.py "${SCYLLA_OPTS[@]}"
|
|
LLVM_PROFILE_FILE="${CLANG_BUILD_DIR}"/build/profiles/csir-%p-%m.profraw ninja -f "${SCYLLA_NINJA_FILE}" compiler-training
|
|
|
|
echo "[clang-stage3] build the compiler applied CSPGO profile"
|
|
cd "${CLANG_BUILD_DIR}"
|
|
llvm-profdata merge build/csprofiles/default_*.profraw -output=csir.prof
|
|
llvm-profdata merge ir.prof csir.prof -output=combined.prof
|
|
rm -rf build
|
|
# linker flags are needed for BOLT
|
|
cmake -B build -S llvm "${CLANG_OPTS[@]}" -DLLVM_PROFDATA_FILE="$(realpath combined.prof)" -DCMAKE_EXE_LINKER_FLAGS="-Wl,--emit-relocs"
|
|
ninja -C build
|
|
|
|
mkdir -p "${CLANG_SYSROOT_DIR}"
|
|
DESTDIR="${CLANG_SYSROOT_DIR}" ninja -C build install-distribution-stripped
|
|
cd "${CLANG_ROOT_DIR}"
|
|
tar -C "${CLANG_SYSROOT_NAME}" -cpzf "${CLANG_ARCHIVE}" .
|
|
fi
|
|
|
|
# make sure it is correct archive, before extracting to /
|
|
set +e
|
|
tar -tpf "${CLANG_ARCHIVE}" ./usr/local/bin/clang > /dev/null 2>&1
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "Unable to detect prebuilt clang on ${CLANG_ARCHIVE}, aborted."
|
|
exit 1
|
|
fi
|
|
set -e
|
|
tar -C / -xpzf "${CLANG_ARCHIVE}"
|