Rate This Document
Findability
Accuracy
Completeness
Readability

Source Code Scans in Common Scenarios

The memory consistency check function is available only on the Kunpeng platform and not available on the x86 platform.

This sample explains how to identify memory inconsistency issues through source code scanning, and modify the code based on the suggestions provided by the tool.

  • Large-scale source code may consume too many resources. It is recommended that the code volume not exceed 100,000 lines. Each time you create a memory consistency check task, upload the source file again.
  • Separate compilation commands with semicolons (;). The make, cmake, configure, and shell commands and shell scripts can be used for compilation. The make install command is not supported. The build command or build script cannot be used to create or modify directories or files that are not in the user space (/opt/DevKit/workspace/username/).

Scanning the Source Code

  1. Download the sample code common from GitHub or Gitee to obtain the software source package.

    The downloaded source package is devkitdemo-main.zip. The ./devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common file extracted from the package is the code to be scanned for static memory consistency check.

  2. Generate a BC file.
    1. Scan the updated source file and generate a BC file.
      1
      2
      cd /home/software/Porting_advisor/testdemo/weak_consistency/common/
      devkit advisor bc-gen -o /home/report -c make
      

      Command output:

      Executing bc gen task, please wait...
      Current progress: ###### [20%]
      Start to get the compile database
      Current progress: ################ [50%]
      Start to generate the BC files
      Current progress: ################################# [100%]
      Configuration:
          Generate BC files path: /home/report
          Compile command: make
          Threads: The threads is not set, using the half number of cores.
          Task Timeout Interval: The timeout period is not set.
          Log level: info
      
      Summary:
          Scanned all source files, there are 1 linked BC files and 1 object BC files generated.
      
      For the detail information, please check:
      Output path of linked BC files: /home/report/bc-gen_20250526023122_8a68/bin
      Output path of object BC files: /home/report/bc-gen_20250526023122_8a68/object
      
      There are 0 linked BC files fail to be generated. For the causes of the failure to generate all the BC files and their intermediates, please check:
      Log path: /opt/DevKit-CLI-x.x.x-Linux-Kunpeng/advisor/logs/affinity/affinity.log
      • -o: Path for storing the generated BC file. You must have the write permission on the path. By default, the report is saved in the current path and is named in the format of Module name_Timestamp.
      • -c: Builds source code.

      Download the bc-gen_20250526023122_8a68 folder in the path next to Output path of linked BC files in the command output. The bin folder is used to store the BC file in 3.

  3. Log in to the Kunpeng DevKit. In the navigation tree, choose Affinity Analyzer > Static Memory Consistency Check. Set Check Mode to Static check.

    Click Select Folder next to Source File Path and upload the common folder. Click Select Folder next to BC File Path and upload the bin folder. See Figure 1.

    Figure 1 Memory consistency static check
  4. Click Check to check the memory consistency. A check report is displayed. See Figure 2.
    Figure 2 Check report

Source Code Memory Inconsistency Issues

In the memory consistency check report, click View Suggested Source Code to view the source code location where a memory inconsistency issue occurs. See Figure 3 and Figure 4.

Figure 3 Source code modification suggestion
Figure 4 Location of memory inconsistency issues

Two memory inconsistency issues are detected in the common.c file. thread0 writes the shared variables x and y, and thread1 reads the shared variables x and y. The memory consistency scan tool identifies and reports these possible memory inconsistency issues.