ubantu20.04安装gem5

avatar
作者
猴君
阅读量:0

前言

在安装gem5时,花了很长时间,主要是遇到一些奇奇怪怪的错误。在此记录一下。

参考资料

[1] https://www.gem5.org/documentation/learning_gem5/part1/building/
[2] https://blog.csdn.net/weixin_46841376/article/details/137884041

过程

  1. 安装必要的包
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev python-dev python 

这里要注意下面几个包的版本:
(1)安装gcc

sudo apt install build-essential 

这里gcc的版本最好是10+。可以用gcc --version查看其版本,不符合的调整一下。
(2)安装SCons

sudo apt install scons 

这里的SCons的版本最好是3.0+
(3)安装python

sudo apt install python3-dev 

python的版本最好是3.6+,可以使用python3 --version查看版本。
(4)安装protobuf
protobuf最好是protobuf 2.1+的版本,可以使用protoc --version查看版本号。

sudo apt install libprotobuf-dev protobuf-compiler libgoogle-perftools-dev 

(5)安装Boost

sudo apt install libboost-all-dev 
  1. 克隆gem5包
    可以用gitee的包,下载速度快一些
git clone https://gitee.com/koverlu/gem5.git 
  1. 编译安装gem5
    接下来就可以编译了。首先进入gem5目录
cd gem5 

然后开始编译

python3 `which scons` build/X86/gem5.opt -j32 

上面这句代码的-j32是指定编译时使用的并行度,即同时进行的编译任务数。这里的 32 表示将使用32个并行任务来编译 gem5。
有些文章说,32这个数字由电脑CPU的数量决定的。我电脑是64个核,使用-j64后报错了。报错信息如下:

scons: *** [build/X86/python/_m5/param_MultiperspectivePerceptron.cc] Error 134 scons: building terminated because of errors. 

这只是报错的小部分,有很多报错信息都显示Error 134。在stackoverflow上看到一条帖子,说是因为out of memory的缘故。
out of memory的解决办法目前有两种,一是增加交换区的大小【我觉得麻烦没试哈哈哈哈】二是减小编译的并行度,我把-j64改成-j32,就可以了
编译成功应该是这个样子:

 [     CXX] src/mem/ruby/system/HTMSequencer.cc -> X86/mem/ruby/system/HTMSequencer.o  [     CXX] X86/python/_m5/param_RubyHTMSequencer.cc -> .o  [     CXX] X86/python/_m5/param_DMASequencer.cc -> .o  [     CXX] src/mem/ruby/system/RubyPort.cc -> X86/mem/ruby/system/RubyPort.o  [     CXX] src/mem/ruby/system/RubyPortProxy.cc -> X86/mem/ruby/system/RubyPortProxy.o  [     CXX] src/mem/ruby/system/RubySystem.cc -> X86/mem/ruby/system/RubySystem.o  [     CXX] src/mem/ruby/system/Sequencer.cc -> X86/mem/ruby/system/Sequencer.o  [     CXX] X86/python/m5/defines.py.cc -> .o  [     CXX] X86/python/m5/info.py.cc -> .o  [     CXX] src/base/date.cc -> X86/base/date.o  [    LINK]  -> X86/gem5.opt scons: done building targets. *** Summary of Warnings *** Warning: Couldn't find HDF5 C++ libraries. Disabling HDF5 support. Warning: Header file <capstone/capstone.h> not found.          This host has no capstone library installed. Warning: Can not enable KVM, host seems to lack KVM support 

出现scons: done building targets.这句话就没问题啦~~

  1. 测试是否安装成功gem5
    在gem5的目录下新建一个hello-world.py文件,文件内容如下:
from gem5.isas import ISA from gem5.components.boards.simple_board import SimpleBoard from gem5.components.cachehierarchies.classic.no_cache import NoCache from gem5.components.memory.single_channel import SingleChannelDDR3_1600 from gem5.components.processors.simple_processor import SimpleProcessor from gem5.components.processors.cpu_types import CPUTypes from gem5.resources.resource import Resource from gem5.simulate.simulator import Simulator   # Obtain the components. cache_hierarchy = NoCache() memory = SingleChannelDDR3_1600("1GiB") processor = SimpleProcessor(cpu_type=CPUTypes.ATOMIC, isa=ISA.X86, num_cores=1)  #Add them to the board. board = SimpleBoard(     clk_freq="3GHz",     processor=processor,     memory=memory,     cache_hierarchy=cache_hierarchy, )  # Set the workload. binary = Resource("x86-hello64-static") board.set_se_binary_workload(binary)  # Setup the Simulator and run the simulation. simulator = Simulator(board=board) simulator.run()  

保存退出文件后运行下面命令:

build/X86/gem5.opt hello-world.py 

如果出现Hello World!字样则表明成功安装!

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!