【Gem5】入门准备和新手教程

本文档详细介绍了Gem5模拟器的编译、配置脚本创建以及配置带有Cache系统的流程。首先,讲解了在Ubuntu 16.04上安装依赖并编译Gem5。接着,创建了一个简单的配置脚本,模拟一个单核CPU系统,接着添加了二级缓存,并学习了如何在脚本中添加参数。最后,了解了Gem5的统计和输出信息,以及默认配置脚本的使用。
摘要由CSDN通过智能技术生成

Gem5入门

鉴于官网的一些东西已经过时,我觉得有必要专门写一个新的Gem5教程,这也是本文章的初衷!

1 编译Gem5

1.1 编译前准备

强烈建议在Ubuntu 16.04下安装编译(之前的ubuntu还需要你自己更新gcc版本),编译前通过apt管理器安装git build-essential scons python-dev swig libprotobuf-dev python-protobuf protobuf-compiler libgoogle-perftools-dev zlib1g-dev m4 mercurial这些包,关于每个包的介绍参考官网:http://www.m5sim.org/Dependencies

1.2 获取代码

下载gem5源代码文件,使用以下命令克隆:

hg clone http://repo.gem5.org/gem5

1.3 编译一个Gem5

对于每一个要模拟的ISA需要单独编译gem5。而且如果使用ruby,要为每个 cache coherence 协议单独编译。

使用scons命令来编译,在build_opts/X86中可以查看那些编译的选项,你可以自己修改,当然为了方便我们使用官方给的默认参数:

scons build/X86/gem5.opt -j4    #这里j4代表我的计算机有4个可用核心,调度更多核心能更快地编译

根据你的电脑性能,整个过程需要15~45分钟。

参考:gem5二进制类型区别

5 different binaries you can build for gem5: debug, opt, fast, prof, and perf.

这5种类型区别如下

  • debug

    Built with no optimizations and debug symbols. This binary is useful when using a debugger to debug if the variables you need to view are optimized out in the opt version of gem5. Running with debug is slow compared to the other binaries.

  • opt

    This binary is build with most optimizations on (e.g., -O3), but with debug symbols included. This binary is much faster than debug, but still contains enough debug information to be able to debug most problems.

  • fast

    Built with all optimizations on (including link-time optimizations on supported platforms) and with no debug symbols. Additionally, any asserts are removed, but panics and fatals are still included. fast is the highest performing binary, and is much smaller than opt. However, fast is only appropriate when you feel that it is unlikely your code has major bugs.

  • prof and perf

    These two binaries are build for profiling gem5. prof includes profiling information for the GNU profiler (gprof), and perf includes profiling information for the Google performance tools (gperftools).

2 创建一个简单的配置脚本

本节将模拟一个非常简单的系统,我们只有一个简单的CPU内核。该CPU内核将连接到系统内的内存总线。我们将有一个DDR3内存通道,也连接到内存总线。

2.1 Gem5配置脚本介绍

Gem5在运行前需要一个python脚本作为参数,在这个脚本文件里制定你自己的参数以按需仿真系统。

并且gem5中已经提供了许多示例配置脚本configs/examples。

本节从最简单的脚本文件开始,学习怎么构建一个配置脚本。

2.2 创建配置脚本

命令行里敲入如下命令,创建一个python文件,当然你也可以使用GUI的工具。

mkdir configs/tutorial
touch configs/tutorial/simple.py

使用编辑器打开该文件,首先需要导入m5库和编译的SimObjects:

import m5
from m5.objects import *

接下来创建第一个SimObject:我们要模拟的系统。该System对象将是我们模拟系统中所有其他对象的父对象。

system = System()

然后在这个system上设置时钟。首先设置一个时钟域,然后在这个是时钟域上设置频率,最后设置电压,不过我们不关心电压大小,用默认选项即可。

system.clk_domain = SrcClockDomain()
system.clk_domain.clock = '1GHz'
system.clk_domain.voltage_domain = VoltageDomain()

现在开始模拟内存,这里使用timing mode来模拟内存,大多数情况都要用timing,除非在fast-forwarding和 restoring from a checkpoint这两种情况。然后设置一下内存的大小。

system.mem_mode = 'timing'
  • 22
    点赞
  • 119
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值