目录

Enabling Hotspot Accelerate

Linx Kit provides APIs to implement the Hotspot Accelerate function. By optimizing the hotspot code patterns during thread execution, these APIs improve the thread execution efficiency. The Hotspot Accelerate function is used to optimize the performance of specific threads and is applicable to scenarios requiring higher thread execution efficiency.

Introduction to the Hotspot Accelerate Module

For example, in the figure below, the key threads (logic and rendering threads) on the CPU exhibit periodicity at the frame level.

After identifying the source code location, you can call the relevant APIs at the entry and exit of the periodic hotspot process. The Hotspot Accelerate module then records and saves the program runtime behavior, such as branch jumps and other key information, and replays this behavior in the next frame, thereby improving thread execution efficiency.

Development Procedure

In scenarios where thread performance needs to be optimized, you can call Hotspot Accelerate APIs provided by Linx Kit to improve the thread execution efficiency. The following describes the main development procedure of the Hotspot Accelerate module:

  1. Before calling any APIs, use a profiler to identify hotspot functions or processes for subsequent optimization.
  2. Link the related dynamic library in the CMake script.
     find_library(linxkit-lib liblinx.so)
     target_link_libraries(entry PUBLIC ${linxkit-lib})
  3. After identifying the source code location of a hotspot process, call the HMS_LINX_HotspotAccelerateBegin and HMS_LINX_HotspotAccelerateEnd APIs at the entry and exit of the process, respectively, to record and replay the key behavior.
  4. Divide hotspot functions or processes into multiple contexts and apply the acceleration policy only to the most important contexts to reduce the main memory access overhead.

The following shows the complete code and steps for enabling Hotspot Accelerate:

  1. Import the header file.

    #include "LinxKit/linx_hotspot.h"
  2. Call HMS_LINX_HotspotAccelerateInit to initialize the Hotspot Accelerate module when an app process is created.

    int32_t ret = HMS_LINX_HotspotAccelerateInit();
    if (ret != 0) {
        (void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_ID, "linxkit_test", "LinxKit init error: %{public}d", ret);
    }
  3. Call HMS_LINX_HotspotAccelerateBegin to start hotspot acceleration. ctx is initialized to 0. A valid ctx will be automatically allocated by the Hotspot Accelerate API later.

    uint32_t ctx = g_ctx;
    int32_t ret = HMS_LINX_HotspotAccelerateBegin(&ctx);
    g_ctx = ctx;
    if (ret != 0) {
        (void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_ID, "linxkit_test", "LinxKit acc begin error: %{public}d", ret);
    }
  4. Call HMS_LINX_HotspotAccelerateEnd to stop hotspot acceleration and release resources when acceleration is not required.

    ret = HMS_LINX_HotspotAccelerateEnd(ctx);
    if (ret != 0) {
        (void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_ID, "linxkit_test", "LinxKit acc end error: %{public}d", ret);
    }