Ubuntu 上安装和运行 Gem5 仿真器

安装 Gem5

  1. 安装依赖库 打开终端,输入以下命令安装必要的依赖库:

    sudo apt-get install build-essential git m4 scons zlib1g zlib1g-dev libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev python-dev python
    
  2. 下载 Gem5 源代码 在终端中输入以下命令下载 Gem5 源代码:

    git clone https://gem5.googlesource.com/public/gem5
    
  3. 进入 Gem5 目录

    cd gem5
    
  4. 编译 Gem5 输入以下命令编译 Gem5:

    scons build/X86/gem5.opt -j4
    

    说明:-j4 参数代表使用 4 个线程进行编译,可以根据自己的电脑配置进行调整。

编译并运行 Gem5

  1. 创建配置文件目录

    mkdir my_gem5_configs
    cd my_gem5_configs
    cp ../configs/example/se.py .
    
  2. 修改配置文件

    vim se.py
    

    使用 vim 等编辑器打开配置文件 se.py,修改参数为:

    import m5
    from m5.objects import *
    
    m5.util.addToPath('../')
    m5.util.addToPath('../../')
    
    binary = '../tests/test-progs/hello/bin/x86/linux/hello'
    cpu_type = 'AtomicSimpleCPU'
    caches = 'no'
    mem_mode = 'atomic'
    
    m5.ticks.setGlobalFrequency('1GHz')
    
    system = System(cpu = globals()[cpu_type]())
    
    system.membus = SystemXBar()
    
    system.cpu.icache = Cache(size='64kB')
    system.cpu.dcache = Cache(size='64kB')
    
    system.cpu.icache.connectCPU(system.cpu)
    system.cpu.dcache.connectCPU(system.cpu)
    
    system.cpu.icache.connectBus(system.membus)
    system.cpu.dcache.connectBus(system.membus)
    
    system.membus = SystemXBar()
    
    system.mem_ctrl = DDR3_1600_8x8()
    system.mem_ctrl.range = system.mem_ranges[0]
    system.mem_ctrl.port = system.membus.master
    
    system.cpu.workload = SEWorkload.init_compatible(binary)
    system.cpu.createThreads()
    
    root = Root(full_system = False, system = system)
    
    m5.instantiate()
    
    print('Beginning simulation!')
    exit_event = m5.simulate()
    print('Exiting @ tick {} because {}'.format(m5.curTick(), exit_event.getCause()))
    

    说明:这个配置文件的作用是加载一个测试程序,该程序输出 'Hello World'。其中 cpu_type 指定使用的 CPU 类型,caches 指定是否启用缓存,mem_mode 指定内存模式。

  3. 运行 Gem5

    ../build/X86/gem5.opt --debug-flags=ProtocolTrace configs/example/se.py
    

    说明:该命令将启动 Gem5,并使用配置文件 se.py 进行模拟,--debug-flags=ProtocolTrace 参数表示启用协议跟踪功能,可以输出更详细的模拟信息。


原文地址: http://www.cveoy.top/t/topic/ox83 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录