鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

普通场景源码扫描

内存一致性功能只支持在鲲鹏平台环境上运行,不支持x86平台。

本示例指导用户通过扫描源代码,识别其中的内存一致性问题,并根据该工具自动分析出的需修改的代码内容进行修改。

  • 源码规模过大可能会导致占用资源过多,建议代码量不超过10万行;每次创建 内存一致性检查 任务,都需要重新上传源码文件。
  • 多条编译命令以“;”隔开。编译命令支持make、cmake、configure、shell命令以及shell脚本,其中使用make命令时不支持make install;构建命令或者构建脚本不能对用户空间(/opt/DevKit/workspace/用户名/)之外的目录和文件进行创建或修改操作。

扫描源代码

  1. GithubGitee代码样例common获取待使用的软件源码包。

    下载的源码包为devkitdemo-main.zip,解压后的“./devkitdemo-main/Porting_advisor/testdemo/weak_consistency/common”为内存一致性静态检查的待扫描代码。

  2. 生成BC文件。
    1. 执行以下命令,扫描修改后的源码文件,并生成BC文件。
      1
      2
      cd /home/software/Porting_advisor/testdemo/weak_consistency/common/
      devkit advisor bc-gen -o /home/report -c make
      

      显示信息如下:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      Executing static memory consistency check 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_20250225061628_b7e5/bin
      Output path of object bc files: /home/report/bc-gen_20250225061628_b7e5/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-25.0.0-Linux-Kunpeng/advisor/logs/affinity/affinity.log
      
      • -o:生成BC文件的存放路径,需要有写权限。报告默认存放在当前路径下,名称默认为“模块名称_时间戳”。
      • -c:源码的构建命令。

      请下载回显信息中“Output path of linked bc files”后面路径下的“bc-gen_20250225061628_b7e5”文件夹,“bin”文件夹作为3中BC文件存放路径。

  3. 进入鲲鹏DevKit,在左侧列表中单击“亲和分析 > 内存一致性静态检查”,检查模式选择“静态检查”
    • 将common文件夹上传到服务器上的“/opt/DevKit/workspace/devadmin/affinity/weakconsistency/”下,单击源码文件存放路径的填写框,选择common下拉项。
    • 鼠标悬浮到“上传”,选择“压缩包”(上传过程中自动解压)或“文件夹”

    这里以上传文件夹方式为例,单击“文件夹”,上传common文件夹。BC文件存放路径也以上传文件夹方式为例。如图1所示。

    图1 内存一致性源码文件静态检查界面
  4. 单击“开始检查”,执行内存一致性检查任务,并得到扫描分析报告,如图2所示。
    图2 扫描分析报告

源代码内存一致性问题

单击检查报告的“查看建议源码”,查看具体的内存一致性问题所在的源码位置,如图3图4所示。

图3 源码修改建议
图4 内存一致性问题所在的源码位置

<common.c>扫描出2个内存一致性问题。在thread0中分别对共享变量x、y进行了写操作,在thread1中对共享变量x、y进行了读操作,内存一致性扫描工具识别并报告了此处可能存在内存一致性问题。