我要评分
获取效率
正确性
完整性
易理解

LTO+PGO Method

  1. Use BiSheng compiler to build instrumented MySQL.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    compilerPath=/home/xxxx/BiSheng       # Set the path of BiSheng compiler.
    readonly SHELL_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"  # Obtain the current path.
    options="-O3 -mcpu=tsv110 -flto=thin -fuse-ld=lld -Wl,-q "   # Set the compilation options. -flto=thin -fuse-ld=lld is related to LTO.
    pgoGenOpt="-fprofile-generate=$SHELL_PATH/pgo_gen"   # Set the PGO-generate directory. In this example, the path is set to pgo_gen.
    pgoUseOpt="-fprofile-use=$SHELL_PATH/pgo_use"        # Set the PGO-use directory. In this example, the path is set to pgo_use.
    cmake .. -DWITH_BOOST=$SHELL_PATH/boost \
          -DCMAKE_C_COMPILER=$compilerPath/bin/clang \
          -DCMAKE_CXX_COMPILER=$compilerPath/bin/clang++ -DENABLE_DOWNLOADS=1 \
          -DCMAKE_BUILD_TYPE=RELEASE \
          -DBUILD_CONFIG=mysql_release \
          -DCMAKE_INSTALL_PREFIX=$SHELL_PATH/install \
          -DCMAKE_C_FLAGS=' $options $pgoGenOpt ' \
          -DCMAKE_CXX_FLAGS=' $options $pgoGenOpt ' \
          -DCMAKE_EXE_LINKER_FLAGS=' $options $pgoGenOpt ' \
    -DCMAKE_AR='$compilerPath/bin/llvm-ar'  \      # When LTO is enabled, AR and RANLIB need to be replaced with those of BiSheng.
          -DCMAKE_RANLIB=`$compilerPath/bin/llvm-ranlib`
    
  2. Run typical benchmarks, such as sysbench and TPC-C. After the running is complete and MySQL exits, the profile is generated in the pgo_gen directory.
  3. Merge the generated profiles and convert it to the format required for PGO-use.
    1
    $compilerPath/bin/llvm-profdata merge pgo_gen --output= pgo_use
    
  4. Generate a high-performance MySQL binary file based on the collected profile.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    cmake .. -DWITH_BOOST=$SHELL_PATH/boost \
          -DCMAKE_C_COMPILER=$compilerPath/bin/clang -DCMAKE_CXX_COMPILER=$compilerPath/bin/clang++ -DENABLE_DOWNLOADS=1 \
          -DCMAKE_BUILD_TYPE=RELEASE \
          -DBUILD_CONFIG=mysql_release \
          -DCMAKE_INSTALL_PREFIX=$SHELL_PATH/install \
          -DCMAKE_C_FLAGS=' $options $pgoUseOpt ' \
          -DCMAKE_CXX_FLAGS=' $options $pgoUseOpt ' \
          -DCMAKE_EXE_LINKER_FLAGS=' $options $pgoUseOpt '\
    -DCMAKE_AR='$compilerPath/bin/llvm-ar' \        # When LTO is enabled, AR and RANLIB need to be replaced with those of BiSheng.
          -DCMAKE_RANLIB=`$compilerPath/bin/llvm-ranlib`