learning_gem5 part2_02 gem5 调试指南

        在前面的章节中,我们介绍了如何创建一个简单的 SimObject。本章将使用 gem5 的调试支持来替代简单的标准输出打印。

        gem5 通过调试标志提供类似 printf 风格的代码跟踪/调试功能。这些标志允许每个组件拥有多个调试输出语句,而无需同时启用所有语句。在运行 gem5 时,您可以从命令行指定要启用的调试标志。

使用调试标志

        例如,在运行 simple-config-chapter 中的第一个 simple.py 脚本时,如果启用 DRAM 调试标志,将得到以下输出。注意这会向控制台生成大量输出(约 7 MB)。

build/ALL/gem5.opt --debug-flags=DRAM configs/learning_gem5/part1/simple.py | head -n 50
gem5 Simulator System.  http://gem5.org
DRAM device capacity (gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Jan  3 2017 16:03:38
gem5 started Jan  3 2017 16:09:53
gem5 executing on chinook, pid 19223
command line: build/X86/gem5.opt --debug-flags=DRAM configs/learning_gem5/part1/simple.py

Global frequency set at 1000000000000 ticks per second
      0: system.mem_ctrl: Memory capacity 536870912 (536870912) bytes
      0: system.mem_ctrl: Row buffer size 8192 bytes with 128 columns per row buffer
      0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000
Beginning simulation!
info: Entering event queue @ 0.  Starting simulation...
      0: system.mem_ctrl: recvTimingReq: request ReadReq addr 400 size 8
      0: system.mem_ctrl: Read queue limit 32, current size 0, entries needed 1
      0: system.mem_ctrl: Address: 400 Rank 0 Bank 0 Row 0
      0: system.mem_ctrl: Read queue limit 32, current size 0, entries needed 1
      0: system.mem_ctrl: Adding to read queue
      0: system.mem_ctrl: Request scheduled immediately
      0: system.mem_ctrl: Single request, going to a free rank
      0: system.mem_ctrl: Timing access to addr 400, rank/bank/row 0 0 0
      0: system.mem_ctrl: Activate at tick 0
      0: system.mem_ctrl: Activate bank 0, rank 0 at tick 0, now got 1 active
      0: system.mem_ctrl: Access to 400, ready at 46250 bus busy until 46250.
  46250: system.mem_ctrl: processRespondEvent(): Some req has reached its readyTime
  46250: system.mem_ctrl: number of read entries for rank 0 is 0
  46250: system.mem_ctrl: Responding to Address 400..   46250: system.mem_ctrl: Done
  77000: system.mem_ctrl: recvTimingReq: request ReadReq addr 400 size 8
  77000: system.mem_ctrl: Read queue limit 32, current size 0, entries needed 1
  77000: system.mem_ctrl: Address: 400 Rank 0 Bank 0 Row 0
  77000: system.mem_ctrl: Read queue limit 32, current size 0, entries needed 1
  77000: system.mem_ctrl: Adding to read queue
  77000: system.mem_ctrl: Request scheduled immediately
  77000: system.mem_ctrl: Single request, going to a free rank
  77000: system.mem_ctrl: Timing access to addr 400, rank/bank/row 0 0 0
  77000: system.mem_ctrl: Access to 400, ready at 101750 bus busy until 101750.
 101750: system.mem_ctrl: processRespondEvent(): Some req has reached its readyTime
 101750: system.mem_ctrl: number of read entries for rank 0 is 0
 101750: system.mem_ctrl: Responding to Address 400..  101750: system.mem_ctrl: Done
 132000: system.mem_ctrl: recvTimingReq: request ReadReq addr 400 size 8
 132000: system.mem_ctrl: Read queue limit 32, current size 0, entries needed 1
 132000: system.mem_ctrl: Address: 400 Rank 0 Bank 0 Row 0
 132000: system.mem_ctrl: Read queue limit 32, current size 0, entries needed 1
 132000: system.mem_ctrl: Adding to read queue
 132000: system.mem_ctrl: Request scheduled immediately
 132000: system.mem_ctrl: Single request, going to a free rank
 132000: system.mem_ctrl: Timing access to addr 400, rank/bank/row 0 0 0
 132000: system.mem_ctrl: Access to 400, ready at 156750 bus busy until 156750.
 156750: system.mem_ctrl: processRespondEvent(): Some req has reached its readyTime
 156750: system.mem_ctrl: number of read entries for rank 0 is 0

        或者,您可能希望基于 CPU 正在执行的具体指令进行调试。这时 Exec 调试标志就很有用。该标志显示模拟 CPU 如何执行每条指令的详细信息

build/ALL/gem5.opt --debug-flags=Exec configs/learning_gem5/part1/simple.py | head -n 50
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Jan  3 2017 16:03:38
gem5 started Jan  3 2017 16:11:47
gem5 executing on chinook, pid 19234
command line: build/X86/gem5.opt --debug-flags=Exec configs/learning_gem5/part1/simple.py

Global frequency set at 1000000000000 ticks per second
      0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000
warn: ClockedObject: More than one power state change request encountered within the same simulation tick
Beginning simulation!
info: Entering event queue @ 0.  Starting simulation...
  77000: system.cpu T0 : @_start    : xor   rbp, rbp
  77000: system.cpu T0 : @_start.0  :   XOR_R_R : xor   rbp, rbp, rbp : IntAlu :  D=0x0000000000000000
 132000: system.cpu T0 : @_start+3    : mov r9, rdx
 132000: system.cpu T0 : @_start+3.0  :   MOV_R_R : mov   r9, r9, rdx : IntAlu :  D=0x0000000000000000
 187000: system.cpu T0 : @_start+6    : pop rsi
 187000: system.cpu T0 : @_start+6.0  :   POP_R : ld   t1, SS:[rsp] : MemRead :  D=0x0000000000000001 A=0x7fffffffee30
 250000: system.cpu T0 : @_start+6.1  :   POP_R : addi   rsp, rsp, 0x8 : IntAlu :  D=0x00007fffffffee38
 250000: system.cpu T0 : @_start+6.2  :   POP_R : mov   rsi, rsi, t1 : IntAlu :  D=0x0000000000000001
 360000: system.cpu T0 : @_start+7    : mov rdx, rsp
 360000: system.cpu T0 : @_start+7.0  :   MOV_R_R : mov   rdx, rdx, rsp : IntAlu :  D=0x00007fffffffee38
 415000: system.cpu T0 : @_start+10    : and    rax, 0xfffffffffffffff0
 415000: system.cpu T0 : @_start+10.0  :   AND_R_I : limm   t1, 0xfffffffffffffff0 : IntAlu :  D=0xfffffffffffffff0
 415000: system.cpu T0 : @_start+10.1  :   AND_R_I : and   rsp, rsp, t1 : IntAlu :  D=0x0000000000000000
 470000: system.cpu T0 : @_start+14    : push   rax
 470000: system.cpu T0 : @_start+14.0  :   PUSH_R : st   rax, SS:[rsp + 0xfffffffffffffff8] : MemWrite :  D=0x0000000000000000 A=0x7fffffffee28
 491000: system.cpu T0 : @_start+14.1  :   PUSH_R : subi   rsp, rsp, 0x8 : IntAlu :  D=0x00007fffffffee28
 546000: system.cpu T0 : @_start+15    : push   rsp
 546000: system.cpu T0 : @_start+15.0  :   PUSH_R : st   rsp, SS:[rsp + 0xfffffffffffffff8] : MemWrite :  D=0x00007fffffffee28 A=0x7fffffffee20
 567000: system.cpu T0 : @_start+15.1  :   PUSH_R : subi   rsp, rsp, 0x8 : IntAlu :  D=0x00007fffffffee20
 622000: system.cpu T0 : @_start+16    : mov    r15, 0x40a060
 622000: system.cpu T0 : @_start+16.0  :   MOV_R_I : limm   r8, 0x40a060 : IntAlu :  D=0x000000000040a060
 732000: system.cpu T0 : @_start+23    : mov    rdi, 0x409ff0
 732000: system.cpu T0 : @_start+23.0  :   MOV_R_I : limm   rcx, 0x409ff0 : IntAlu :  D=0x0000000000409ff0
 842000: system.cpu T0 : @_start+30    : mov    rdi, 0x400274
 842000: system.cpu T0 : @_start+30.0  :   MOV_R_I : limm   rdi, 0x400274 : IntAlu :  D=0x0000000000400274
 952000: system.cpu T0 : @_start+37    : call   0x9846
 952000: system.cpu T0 : @_start+37.0  :   CALL_NEAR_I : limm   t1, 0x9846 : IntAlu :  D=0x0000000000009846
 952000: system.cpu T0 : @_start+37.1  :   CALL_NEAR_I : rdip   t7, %ctrl153,  : IntAlu :  D=0x00000000004001ba
 952000: system.cpu T0 : @_start+37.2  :   CALL_NEAR_I : st   t7, SS:[rsp + 0xfffffffffffffff8] : MemWrite :  D=0x00000000004001ba A=0x7fffffffee18
 973000: system.cpu T0 : @_start+37.3  :   CALL_NEAR_I : subi   rsp, rsp, 0x8 : IntAlu :  D=0x00007fffffffee18
 973000: system.cpu T0 : @_start+37.4  :   CALL_NEAR_I : wrip   , t7, t1 : IntAlu :
1042000: system.cpu T0 : @__libc_start_main    : push   r15
1042000: system.cpu T0 : @__libc_start_main.0  :   PUSH_R : st   r15, SS:[rsp + 0xfffffffffffffff8] : MemWrite :  D=0x0000000000000000 A=0x7fffffffee10
1063000: system.cpu T0 : @__libc_start_main.1  :   PUSH_R : subi   rsp, rsp, 0x8 : IntAlu :  D=0x00007fffffffee10
1118000: system.cpu T0 : @__libc_start_main+2    : movsxd   rax, rsi
1118000: system.cpu T0 : @__libc_start_main+2.0  :   MOVSXD_R_R : sexti   rax, rsi, 0x1f : IntAlu :  D=0x0000000000000001
1173000: system.cpu T0 : @__libc_start_main+5    : mov  r15, r9
1173000: system.cpu T0 : @__libc_start_main+5.0  :   MOV_R_R : mov   r15, r15, r9 : IntAlu :  D=0x0000000000000000
1228000: system.cpu T0 : @__libc_start_main+8    : push r14

        实际上,Exec 标志是多个调试标志的集合。您可以通过运行 gem5 的 --debug-help 参数查看这一点以及所有可用的调试标志。

build/ALL/gem5.opt --debug-help
Base Flags:
    Activity: None
    AddrRanges: None
    Annotate: State machine annotation debugging
    AnnotateQ: State machine annotation queue debugging
    AnnotateVerbose: Dump all state machine annotation details
    BaseXBar: None
    Branch: None
    Bridge: None
    CCRegs: None
    CMOS: Accesses to CMOS devices
    Cache: None
    CacheComp: None
    CachePort: None
    CacheRepl: None
    CacheTags: None
    CacheVerbose: None
    Checker: None
    Checkpoint: None
    ClockDomain: None
...
Compound Flags:
    All: Controls all debug flags. It should not be used within C++ code.
        All Base Flags
    AnnotateAll: All Annotation flags
        Annotate, AnnotateQ, AnnotateVerbose
    CacheAll: None
        Cache, CacheComp, CachePort, CacheRepl, CacheVerbose, HWPrefetch
    DiskImageAll: None
        DiskImageRead, DiskImageWrite
...
XBar: None
    BaseXBar, CoherentXBar, NoncoherentXBar, SnoopFilter

添加新的调试标志

        在前面的章节中,我们使用了简单的 std::cout 从 SimObject 进行打印。虽然在 gem5 中可以使用普通的 C/C++ I/O,但强烈不推荐这样做。因此,我们现在要替换它,改用 gem5 的调试功能。

        创建新的调试标志时,首先需要在 SConscript 文件中声明它。在包含 hello 对象代码的目录(src/learning_gem5/SConscript)的 SConscript 文件中添加以下内容。

DebugFlag('HelloExample')

        这声明了一个名为 "HelloExample" 的调试标志。现在,我们可以在 SimObject 的调试语句中使用它。

        通过在 SConscript 文件中声明标志,会自动生成一个调试头文件,使我们能够使用该调试标志。头文件位于 debug 目录中【注,编译时的 gem5/build/debug/ 目录】,名称(和大小写)与我们在 SConscript 文件中声明的相同。因此,我们需要在任何计划使用这个调试标志的文件中包含这个自动生成的头文件【注,#include 内容还未直接存在,但需要事先include进去】。

        在 hello_object.cc 文件中,我们需要包含头文件。

#include "base/trace.hh"
#include "debug/HelloExample.hh"

        现在我们已经包含了必要的头文件,让我们用调试语句替换 std::cout 调用,如下所示。

DPRINTF(HelloExample, "Created the hello object\n");

        DPRINTF 是一个 C++ 宏。第一个参数是在 SConscript 文件中声明的调试标志。由于我们在 src/learning_gem5/SConscript 文件中声明了它,因此可以使用 HelloExample 标志。其余参数是可变的,可以是您传递给 printf 语句的任何内容。

        现在,如果您重新编译 gem5 并使用 "HelloExample" 调试标志运行它,将得到以下结果。

scons build/ALL/gem5.opt
build/ALL/gem5.opt --debug-flags=HelloExample configs/learning_gem5/part2/run_hello.py
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Jan  4 2017 09:40:10
gem5 started Jan  4 2017 09:41:01
gem5 executing on chinook, pid 29078
command line: build/X86/gem5.opt --debug-flags=HelloExample configs/learning_gem5/part2/run_hello.py

Global frequency set at 1000000000000 ticks per second
      0: hello: Created the hello object
Beginning simulation!
info: Entering event queue @ 0.  Starting simulation...
Exiting @ tick 18446744073709551615 because simulate() limit reached

调试输出

        对于每个动态执行的 DPRINTF,有三项内容会输出到 stdout。首先,执行 DPRINTF 时的当前 tick。其次,调用 DPRINTF 的 SimObject 的名称。该名称通常是 Python 配置文件中的 Python 变量名。但是,该名称是 SimObject 的 name() 函数返回的任何名称。最后,您会看到传递给 DPRINTF 函数的格式字符串

        您可以使用 --debug-file 参数控制调试输出的位置。默认情况下,所有调试输出都会打印到 stdout。但是,您可以将输出重定向到任何文件。该文件相对于主要的 gem5 输出目录存储,而不是相对于当前工作目录。

使用 DPRINTF 以外的其他函数

        DPRINTF 是 gem5 中最常用的调试函数。但是,gem5 提供了许多在特定情况下有用的其他函数。所有调试函数都可以在参考文档中找到。

        这些函数类似于之前的函数:DDUMP、DPRINTF 和 DPRINTFR,但它们不接受标志作为参数。因此,只要启用了调试,这些语句就会始终打印

        所有这些函数仅在您以 "opt" 或 "debug" 模式编译 gem5 时启用。所有其他模式对上述函数使用空的占位符宏。因此,如果您想使用调试标志,必须使用 "gem5.opt" 或 "gem5.debug"。

下载代码方式:https://pan.quark.cn/s/a4b39357ea24 HTML大屏展示模板是一种用于设计具有视觉冲击力且内容充实的巨型显示屏应用的设计方案,其应用范围广泛,涵盖了数据分析、监控以及决策支持等多个领域。这些模板通常整合了HTML、CSS、JavaScript等多种技术,尤其借助ECharts等数据可视化工具以达成复杂数据的图形化呈现。以下是对相关技术细节的深入说明: 1. **可视化**:数据可视化是将抽象的数据转化为直观的图像或图表的技术手段。这种技术有助于迅速识别数据中的模式、发展趋势和异常情况,使得非专业背景的人员也能轻松理解复杂的数据信息。在大屏展示场景中,可视化通常包含折线图、柱状图、饼图、热力图、地图等多种图表形式。 2. **大数据**:大数据指的是规模庞大、增长迅速、种类多样且数据密度较低的数据集合。在HTML大屏展示中,大数据的应用旨在支持实时或近乎实时的决策制定,例如监控销售业绩、交通流量、能源消耗等关键性能指标。 3. **HTML**:超文本标记语言(HTML)构成了网页内容的基础结构,用于界定页面的布局和元素。在大屏展示模板中,HTML负责构建页面组件,例如标题、段落、图像以及图表容器等。 4. **CSS**:层叠样式表(CSS)用于调控网页的视觉风格和布局结构。在大屏模板设计中,CSS扮演着核心角色,确保设计的响应性、适应性和美观度,包括设定颜色、字体、间距、动画效果等。 5. **ECharts**:ECharts是由百度研发的一款开源JavaScript数据可视化库,能够支持多种图表类型,如折线图、柱状图、散点图等,并提供了丰富的交互特性。在大屏展示中,ECharts能够助力生成动态且交互式的数据...
内容概要:本文提出了一种基于递进事件触发框架的孤岛微电网DoS攻击容错二次协同控制方法,旨在解决通信资源受限与网络安全威胁耦合下的控制难题。该方法通过设计递进式事件触发机制,在保障系统动态性能的同时显著降低通信频率,减轻网络负载,并有效抵御拒绝服务(DoS)攻击对控制链路的干扰。结合二次协同控制策略,实现了在攻击发生时对微电网频率与电压的精准恢复,同时确保各分布式电源间的功率精确分配与电能质量稳定。通过Simulink搭建的仿真模型验证了该方法在不同攻击强度和通信约束条件下的有效性、鲁棒性与容错能力。; 适合人群:从事电力系统自动化、微电网控制、分布式能源系统、网络物理系统安全及智能电网弹性控制研究的研究生、科研人员和工程技术人员。; 使用场景及目标:①研究孤岛微电网在面临DoS攻击时的弹性控制与容错机制;②设计具有高通信效率和强安全韧性的能源互联网控制系统;③实现微电网二次控制中通信资源优化、控制性能提升与网络安全防护的多目标协同。; 阅读建议:此资源侧重于控制算法的理论设计与仿真验证,建议读者结合Simulink模型深入理解递进事件触发机制与协同控制策略的实现逻辑,重点关注系统在不同攻击场景下的动态响应特性与稳定性表现,以全面掌握其容错性能与工程应用潜力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值