Updated on 2024-08-28 GMT+08:00

Static Acceleration

Preparations

  1. Run the following command to check whether the binary file to be optimized can be located again:
    readelf -a application | grep .rela.text
    • If the binary file contains .rela.text, the file can be located again. In this case, the application can be optimized.

    • If the binary file does not contain .rela.text, to allow BOLT to re-arrange functions (in addition to re-arranging code within functions) in your program, you need to add --emit-relocs or -q to the final link step of your application.
  2. Collect the logs when the application is running.

    After deploying and preheating the application, you can run llvm-bolt -instrument -o -instrumentation-file to configure the way how the logs are collected.

    For example, to collect logs every 30 seconds after the test.so file is executed, run the following command to save the logs to the test.log file:

    llvm-bolt tests.so -instrument -o testd.so -instrumentation-file=test.log -instrumentation-sleep-time=30 -instrumentation-no-counters-clear

    • instrument -o: indicates the new dynamic library file generated after the log collection way is configured. In this example, the newly generated dynamic library is testd.so.
    • instrumentation-file: indicates the name of the file where the logs are saved. In this example, the log file is test.log.
    • instrumentation-sleep-time: indicates the interval for collecting logs, in seconds. In this example, logs are collected every 30 seconds.
    • instrumentation-no-counters-clear: indicates that the log counter information is not cleared after each log collection to ensure that the log context is continuous.
  3. Run the application corresponding to testd.so. The run logs of the application are automatically saved in the test.log file.

    Workload Accelerator will optimize the application based on the dynamic data in the test.log file.

Procedure

  • Use the native BOLT tool to optimize the application.

    Once you have test.log ready, you can use it for optimizations with BOLT. For example, you can run the following command:

    llvm-bolt <executable> -o <executable>.bolt -data=test.log -reorder-blocks=ext-tsp -reorder-functions=hfsort -split-functions -split-all-cold -split-eh -dyno-stats

    The parameters in the command are for illustration purposes and are not the optimal combination of parameters.

  • Run the hce-wae-auto command to optimize the application.

    The hce-wae-auto command optimizes the application based on user-defined configuration file.

    The command format is hce-wae-auto [-h] [-c <Path>] [-s <Keyword>] [-e <Pattern>] [-l] [--free] Application.

    • After you run the hce-wae-auto command, the path of the generated parameter set is the same as the binary output path (/data/hce-wae-auto/hce-wae-auto.data) in the configuration file by default.
    • After you run the hce-wae-auto command, a log file is automatically generated, and its default path is /var/log/hce-wae-auto/hce-wae-auto.log.
    Table 1 Parameter description

    Parameter

    Value Required

    Value Type

    Mandatory

    Description

    -h

    No

    /

    No

    Displays command parameter help information.

    -c

    Yes

    String

    No

    Defines the configuration file path. The default path is /etc/hce-wae-auto.conf.

    -s

    Yes

    String

    No

    Defines the keyword for fuzzy search of the last parameter set.

    If there is no saved parameter set, this parameter will not take effect.

    -e

    Yes

    String

    No

    Executes the selected parameter combination based on the content of the last parameter set. A sequence number must be specified.

    • A single number specifies the parameter combination corresponding to the sequence number.
    • The colon (:) indicates the sequence number range. For example, 4:6 indicates the sequence number range from 4 to 6. :7 indicates the sequence number range is from 1 to 7. 5: indicates the sequence number range is from 5 to the last. : indicates all the sequence numbers.
    • A single number can be used together with a sequence number range (:) and separated using a comma (,). For example, 1,4:6 indicates sequence numbers 1, 4, 5, and 6.

    -l

    No

    /

    No

    Generates and prints the parameter set based on the configuration file. The command is not automatically executed and the parameter set is not saved.

    --free

    No

    /

    No

    Indicates that the validity of parameters in the configuration file is not verified.

    Workload Accelerator performs simple verification on the parameters in the configuration file to determine whether the parameters are used for optimization using BOLT. If you run the --free command, the verification is canceled and parameters that are not for optimization can be entered.

    application

    No

    /

    Yes

    Specifies the binary file to be executed. You can add a relative path or an absolute path, for example, mysqld, /usr/bin/mysqld, or /bin/mysqld.

    If the -c, -s, -e and -l parameters conflict, -s has the highest priority, followed by -l and then -e, and -c has the lowest priority.

    The following table describes some example commands.

    Example Command

    Description

    hce-wae-auto mysqld

    Reads the configuration from the default path, generates a parameter set based on configuration parameters, automatically executes the command, and saves the parameter set after the command is executed.

    hce-wae-auto mysqld -c /etc/my.conf -l

    Reads configuration parameters from the /etc/my.conf path, generates a parameter set, prints the generated command, but does not execute the command or save the parameter set.

    hce-wae-auto mysqld -c /etc/my.conf

    Reads configuration parameters from the /etc/my.conf path, generates a parameter set, automatically executes the command, and saves the parameter set after the command is executed.

    hce-wae-auto mysqld -s align

    Searches for the keyword align in fuzzy mode from the parameter set generated last time and prints the matched parameter combination.

    hce-wae-auto mysqld -e 4:6

    Selects the parameter combinations of No.4, No.5, and No.6 from the parameter set generated last time to generate a binary file.

    hce-wae-auto mysqld -e 1,4:6

    Selects the parameter combinations of No.1, No.4, No.5, and No.6 from the parameter set generated last time to generate a binary file.

    hce-wae-auto mysqld -e :

    Selects all parameter combinations from the parameter set generated last time to generate a binary file.

    hce-wae-auto mysqld -e 4:6 -l

    Selects the parameter combinations of No.4, No. 5, and No. 6 from the parameter set generated last time, prints the generated command, but does not execute the command.

    hce-wae-auto mysqld -e : -l

    Selects all parameter combinations from the parameter set generated last time, prints the generated command, but does not execute the command.

    hce-wae-auto mysqld --free

    Reads the configuration from the default path but does not verify parameters, generates a parameter set based on configuration parameters, automatically executes the command, and saves the parameter set after the command is executed.

    hce-wae-auto -h

    Displays command help information.