D-FOT User Guide ​

Overview ​

Dynamic Feedback-directed Optimization Tool (D-FOT) is a dynamic feedback-directed optimization framework. It aims to enable fully automatic and non-intrusive feedback-directed optimization for applications, comprehensively improving the usability and performance of this feature. The framework is planned to support two types of dynamic optimizations: startup time optimization and runtime optimization. Currently, startup time optimization has been implemented based on the oeAware online tuning framework. Startup time optimization: During application running, sampling and feedback-directed optimization are automatically performed. Once optimization is complete, the optimized version automatically takes over the next startup. You do not need to modify the startup procedure, and the optimized version is automatically started after the application is restarted. Runtime optimization: During application running, sampling and feedback-directed optimization are automatically performed. You do not need to restart the application, and no user intervention is required throughout the process. The optimized version can be enabled after only a few interruptions.

Software Architecture Description ​

This framework consists of the following modules:

  • libkperf-based sampling data processing
  • sysboost-based startup takeover and binary optimization feature enablement
  • llvm-bolt-based binary feedback-directed optimization
  • Implementation of the oeAware tuning plugin dfot_tuner_sysboost

Dependency Items ​

OS requirements: Currently, only openEuler 22.03 LTS SP4 is supported. The following dependent components can be installed using yum.

ComponentCode RepositoryBranch or VersionDescription
oeAware-managerhttps://atomgit.com/openeuler/oeAware-manageropenEuler-22.03-LTS-SP4 v2.0.0-3Online transparent service tuning framework
libkperfhttps://atomgit.com/openeuler/libkperfopenEuler-22.03-LTS-SP4 v1.2-2Lightweight in-memory collection tool
sysboosthttps://atomgit.com/openeuler/sysboostopenEuler-22.03-LTS-SP4Microarchitecture tuning tool
llvm-bolthttps://atomgit.com/src-openeuler/llvm-boltopenEuler-22.03-LTS-SP4 17.0.6-12Binary optimizer

Procedure ​

Prerequisites for Applications to Be Optimized ​

  1. The binary to be optimized must contain relocation information. For self-compiled software, the -Wl,-q linker option must be added during compilation. For example, for MySQL, add cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_C_LINK_FLAGS="-Wl,-q" -DCMAKE_CXX_LINK_FLAGS="-Wl,-q". For openEuler software packages, the relocation package of the corresponding application will be provided and can be directly installed.
  2. Check whether the target binary contains relocation information: When the -Wl,-q linker option is effective, the binary will include RELA sections. You can check this using readelf -SW /path/to/bin. For example, in MySQL, before adding the option, only the .rela.dyn and .rela.plt sections exist. After option addition, more than 10 RELA sections appear, including .rela.text and .rela.eh_frame. If -Wl,-q is not effective, when manual perf sampling and perf2bolt are performed or llvm-bolt is used to perform optimization (with or without sysboost), the alarm BOLT-WARNING: non-relocation mode for AArch64 is not fully supported is reported.

D-FOT Preparations ​

Install D-FOT using yum or build it from the source code using the following commands. (If libkperf or oeAware-manager is also built from the source code, you need to specify the library and include path when running cmake.)

shell
# Install dependency packages.
yum install boost-devel log4cplus-devel numactl-devel libkperf-devel oeAware-manager-devel
# Download the source code and compile it.
git clone https://atomgit.com/openeuler/D-FOT.git
cd D-FOT
mkdir build && cd build
cmake ../ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_SKIP_RPATH=TRUE
make -j`nproc`
cd ..

cp build/libdfot.so /lib64/oeAware-plugin/
chmod 440 /lib64/oeAware-plugin/libdfot.so
mkdir -p /etc/dfot/
cp configs/dfot.ini /etc/dfot/

Configuration Modification ​

Modify /etc/dfot/dfot.ini. The configuration items can be set according to the following description. Public configuration: [general]

Configuration ItemValue RangeAvailableDescription
LOG_LEVEL<FATAL, ERROR, WARN, INFO, DEBUG>YesLog level for the optimization service. Levels in the value range are listed in descending order of severity, and the default value is INFO. Note that a lower level produces more log output.
COLLECTOR_SAMPLING_STRATEGY0NoSampling policy.
0 indicates that low-frequency sampling is continuously performed after the plugin is enabled.
1 indicates that the monitoring thread is started when the plugin is enabled. Sampling is performed only when the load reaches the threshold.
Currently, the sampling process is controlled by oeAware, and only 0 is supported.
COLLECTOR_HIGH_LOAD_THRESHOLD[0, cpus*100]NoApplication CPU usage threshold (HIGH_LOAD_THRESHOLD) for triggering sampling. This parameter is available only when sampling policy is set to 1. Currently, this parameter is not supported.
COLLECTOR_SAMPLING_PERIOD100NoInterval at which the collector runs, in milliseconds. The collector runs once every COLLECTOR_SAMPLING_PERIOD ms. Currently, this parameter is uniformly configured by oeAware.
COLLECTOR_SAMPLING_FREQ100NoSampling frequency. Sampling is performed COLLECTOR_SAMPLING_FREQ times per second. Currently, this parameter is uniformly configured by oeAware.
COLLECTOR_DATA_AGING_TIMEDetermined based on actual requirementsYesAging time of sampling data, in milliseconds. When the time difference between the current data and the earliest data reaches the threshold, the accumulated sampling data is discarded.
TUNER_TOOL["sysboost"]NoBinary optimizer. Currently, only sysboost is supported.
TUNER_CHECK_PERIOD[10, max]YesInterval for optimization plugin check, in milliseconds. The plugin periodically checks whether the internally collected data meets the conditions for a new round of optimization. There is no upper limit, but do not set it too large to avoid delayed optimization. The default value is 1000.
TUNER_PROFILE_DIRDetermined based on actual requirementsYesLocation where the sampling data is stored. The profile file is named in format [app_name]_[full_path_hash]_[threshold].profile.
TUNER_OPTIMIZING_STRATEGY[0, 1]YesOptimization policy. 0 indicates that the optimization is performed only once, and 1 indicates that the optimization can be performed for multiple times as long as the sampling information is updated.
TUNER_OPTIMIZING_CONDITION0NoCondition for triggering optimization. 0 indicates that the optimization starts immediately after the application exits. 1 indicates that the optimization is performed when the load is low. 2 indicates that the optimization is performed when the application exits and the load is low. Currently, only 0 is supported.
Application configuration: [app]
Configuration ItemValue RangeAvailableDescription
FULL_PATHDetermined based on actual requirementsYesAbsolute path of the application binary file.
DEFAULT_PROFILEDetermined based on actual requirementsYesDefault profile file of the application, which is used to enable binary optimization during cold start. If there is no such file, leave it empty.
COLLECTOR_DUMP_DATA_THRESHOLD[10000, max]YesRow count threshold for exporting sampling data to the profile. A larger value indicates more samples to be collected before the export occurs. Determine this value based on the actual application and test scenario. For MySQL, the reference value is 65000.
BOLT_DIR/usr/binNoBOLT tool path. If this parameter is left empty, the default value /usr/bin is used. $\{BOLT_DIR}/perf2bolt and $\{BOLT_DIR}/llvm-bolt are invoked internally.
This parameter is determined by sysboost.
BOLT_OPTIONSDetermined based on actual requirementsYesBOLT optimization option. This option can be configured to override the built-in default option for specific optimization.
UPDATE_DEBUG_INFO[0, 1]YesWhether to update the debugging information synchronously during optimization. 1 indicates that the debugging information is updated, and 0 indicates that the debugging information is not updated. Note that updating the debugging information will take extra time.

Plugin Usage ​

See https://atomgit.com/openeuler/oeAware-manager/tree/master/docs.

If D-FOT is installed using yum, you can directly run the following commands to enable plugin instances:

shell
# Restart the oeAware service.
systemctl restart oeaware
# Enable the collection plugin.
oeawarectl -e pmu_sampling_collector
# Enable the feedback-directed optimization tuning plugin.
oeawarectl -e dfot_tuner_sysboost

# Disable the two plugins.
oeawarectl -d pmu_sampling_collector
oeawarectl -d dfot_tuner_sysboost

If D-FOT is built from the source code, copy libdfot.so to the default plugin directory /lib64/oeAware-plugin/ of oeAware, and then load and activate the plugin instance. Note that the permission of the plugin must be 440:

shell
# Restart the oeAware service (the plugins in /lib64/oeAware-plugin/ are automatically loaded).
systemctl restart oeaware
# Alternatively, do not restart the service and manually run oeawarectl to load the plugin.
oeawarectl -l libdfot.so
# Then, perform the preceding enable operations.

For other operations, see the oeAware user manual.

Example ​

The following uses the TPCC test scenario of mysql-8.0.25 as an example:

shell
# 1. Prepare the environment.
yum install libkperf oeaware-manager sysboost llvm-bolt D-FOT

# 2. Build MySQL.
# -Wl,-q is mandatory for optimization. -fPIE and -Wl,-zmax-page-size=0x200000 -Wl,-zcommon-page-size=0x200000 are optional. They are mandatory if sysboost huge page preloading optimization is required.
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_C_FLAGS="-fPIE" -DCMAKE_CXX_FLAGS="-fPIE" -DCMAKE_C_LINK_FLAGS="-Wl,-q -Wl,-zmax-page-size=0x200000 -Wl,-zcommon-page-size=0x200000 -pie" -DCMAKE_CXX_LINK_FLAGS="-Wl,-q -Wl,-zmax-page-size=0x200000 -Wl,-zcommon-page-size=0x200000 -pie"

# 3. Start oeAware and the optimization plugins.
# Fill in /etc/dfot/dfot.ini based on the actual application information, and then run the following commands.
systemctl start sysboost
systemctl start oeaware
oeawarectl -e pmu_sampling_collector
oeawarectl -e dfot_tuner_sysboost

# 4. Run the TPCC test.
...

# 5. Restart MySQL.
# You can check /etc/dfot/dfot.log in advance to determine whether optimization has been performed. After the application is restarted, the optimized version is used.

Constraints ​

  1. Due to the limitations of the sysboost implementation, D-FOT cannot be used in virtualization scenarios (KVM virtual machines: supported but live migration is not supported; Docker containers: not supported).
  2. The target application to be optimized must include relocation information.
  3. When D-FOT is used as the oeAware tuning plugin, the fixed sampling frequency of the current oeAware collection plugin pmu_sampling_collector is 100, which may cause a long sampling time (for reference, the default sampling frequency of perf is 4000).

Future Plans ​

  • [ ] Virtualization scenario support
  • [ ] Runtime optimization support
  • [ ] Enhanced binary optimization