Rate This Document
Findability
Accuracy
Completeness
Readability

AutoFDO (Sampling)

Different from instrumentation-based FDO, AutoFDO uses perf to collect program running information, uses the create_gcov tool to parse the sampling information from perf to the profile required by the compiler, and uses the -fauto-profile option to read the profile to complete optimization. The -fprofile-correction option is used to enable the MCF algorithm to smooth the basic block count imbalance caused by sampling.

Application Scenarios

Scenarios where versions are frequently released and the entire system needs to be deployed in the production environment.

Usage

1
2
3
4
5
6
7
8
# Compile an executable file with debugging information.
gcc -O3 -g -o test_prof test.c
# Use perf to collect profile data.
perf record -e br_retired -- ./test_prof
# Use create_gcov to resolve perf.data to a .gcov file.
create_gcov --binary=./test_prof --profile=perf.data --gcov=test.gcov --gcov_version=2
# Use gcov to compile profiling data to generate a new executable file.
gcc -O3 -fauto-profile=test.gcov test.c -o test_autofdo
  • By default, the converted profile is saved in the current path. You can set -fauto-bolt=PATH to specify a path for saving the BOLT profile, for example, -fauto-bolt=/tmp.
  • In the kernel FDO scenario, the gcov-tool can be used to combine instrumentation-based FDO files to generate a high-performance kernel that improves performance in multiple scenarios.
  • When the instrumentation-based FDO is used to optimize multi-thread applications, you are advised to use -fprofile-generate[=path]. You can also add -fprofile-update=atomic to generate more accurate data.
  • In scenarios where instrumentation-based FDO is used to optimize applications, -fprofile-correction can be used to automatically correct some profile data, and -Wno-error=coverage-mismatch -Wno-error=missing-profile can be used to mask errors reported when the profile cannot be matched or does not exist.

Typical Application Enabling Methods

  1. Applications built using CMake, such as MySQL and RocksDB
    1
    2
    3
    # Build a baseline version with relocation information.
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_C_FLAGS="-Wl,-q" -DCMAKE_CXX_FLAGS="-Wl,-q" -DCMAKE_C_LINK_FLAGS="-Wl,-q" -DCMAKE_CXX_LINK_FLAGS="-Wl,-q" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-q"
    # Use AutoBOLT to build an optimized version.
    
  2. Applications built using Make, such as Redis and Memcached
    1
    2
    3
    4
    # Build a baseline version with relocation information.
    make CFLAGS="-Wl,-q" CXXFLAGS="-Wl,-q"
    # Build an optimized version.
    make CFLAGS="-fprofile-use=./profile -fauto-bolt -fbolt-target=redis-server -Wl,-q -Wno-missing-profile" LDFLAGS="-Wl,-q"
    

Performance Boosts for Typical Applications

Application Name

MySQL

openGauss

Nginx

Ceph

Redis

kernel

Performance Improvement

+15%

+5%

+15%

+7%

+5%

+5%

GCC 12 currently does not support PIE or SO optimization.