Ubuntu20.04搭建gem5并运行helloworld

相关资料

  1. gem5官网
  2. 知乎-计算机体系结构-gem5模拟器入门
  3. gem5:Hello World Tutorial

一、安装gem5

1.下载依赖

sudo apt install build-essential git m4 scons zlib1g zlib1g-dev \
    libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev \
    python3-dev python-is-python3 libboost-all-dev pkg-config

从github或gitee上拷贝gem5代码

git clone https://gitee.com/koverlu/gem5.git

拷贝完成后,会多一个gem5的目录我们进入该目录,在执行对应的构建命令。这里构建的是X86架构,如果要构建ARM或其他架构同理

cd gem5
scons build/X86/gem5.opt -j9

构建完成后,如果没有错误,说明构建成功。在gem5目录下会多一个名为build的目录。

二、运行helloworld

在安装完gem5的环境后,我们可以编写对应的helloworld程序进行测试。在根目录下(gem5目录下),新建一个名为hello-world.py的python文件。

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()

这个例子演示了一个最简单的环境,没有Cache,CPU直连主存。值得一提的是,官方文档上给的helloworld示例有问题,SimpleProcessor函数需要有三个参数,还需要指定ISA,在最上方也需要引入from gem5.isas import ISA。否则执行会报错。

使用如下命令运行该程序,如果输出Hello World!,则说明成功.

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

相关推荐

  1. Ubuntu20.04gem5运行helloworld

    2024-04-24 19:52:03       36 阅读
  2. 【ESP32】Ubuntu2004espressif

    2024-04-24 19:52:03       51 阅读
  3. Ubuntu2204ceph17

    2024-04-24 19:52:03       20 阅读
  4. UbuntuRP2040开发环境-1

    2024-04-24 19:52:03       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-24 19:52:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-24 19:52:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-24 19:52:03       82 阅读
  4. Python语言-面向对象

    2024-04-24 19:52:03       91 阅读

热门阅读

  1. SpringBoot项目 nohup启动运行日志过大问题

    2024-04-24 19:52:03       37 阅读
  2. 云主机是云服务器吗?

    2024-04-24 19:52:03       35 阅读
  3. react经验14:动态修改第三方组件的样式

    2024-04-24 19:52:03       29 阅读
  4. 深圳杯&东三省联赛数学建模挑战赛2024D题

    2024-04-24 19:52:03       42 阅读
  5. class089 贪心经典题目专题1【左程云算法】

    2024-04-24 19:52:03       39 阅读
  6. ADB 命令大全

    2024-04-24 19:52:03       173 阅读
  7. ASP.Net MVC 登录页面实现RSA非对称加密

    2024-04-24 19:52:03       81 阅读
  8. 单片机选型

    2024-04-24 19:52:03       40 阅读
  9. 理解React Hooks

    2024-04-24 19:52:03       174 阅读
  10. Go 之 Label 使用

    2024-04-24 19:52:03       32 阅读
  11. 通过Redis实现一个异步请求-响应程序

    2024-04-24 19:52:03       31 阅读
  12. 京东商品详情API:电商创新的利器

    2024-04-24 19:52:03       32 阅读