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

锁保护场景源码扫描

被锁保护的共享变量内存一致性检查在普通场景源码扫描的基础上,当共享变量完全被锁保护时,静态扫描工具的互斥锁分析模块会过滤该共享变量,最终的报告中没有这两个共享变量相关的语句。

扫描源代码

  1. GitHubGitee代码样例lock获取待使用的软件源码包。在服务器端查看源代码,如图1所示。

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

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

      显示信息如下:

      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_20250526023145_9aa4/bin
      Output path of object bc files: /home/report/bc-gen_20250526023145_9aa4/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.1.RC1-Linux-Kunpeng/advisor/logs/affinity/affinity.log
      • -o:生成BC文件的存放路径,需要有写权限。报告默认存放在当前路径下,名称默认为“模块名称_时间戳”。
      • -c:源码的构建命令。

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

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

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

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

    <lock.c>文件是被锁保护的共享变量内存一致性源码文件,是在普通场景源码扫描的基础上,实现的共享变量完全被锁保护时,静态扫描工具的互斥锁分析模块过滤该共享变量,最终的报告里没有这两个共享变量相关的语句,内存一致性扫描不出需要修改的内容,也就是不存在内存一致性问题。