gem5 to build and NVM (full version)

NVM and build gem5

Built environment

The main reference

The main reference blog

Download

Since hg hung up, and I use the cloud machine, many domestic traffic can not clone, had just great to upload, organize here all the resources used in the process

Step Process

Path Description

+-- nvmain
|
+-- gem5
|
+-- fs-image
|
+-- benchmark

 它们是同一路径!!!

Officially begin

Installation nvm

wget https://bitbucket.org/mrp5060/nvmain/get/9c0e87b164bc.zip -O nvmain.zip
unzip nvmain.zip
mv mrp5060-nvmain-9c0e87b164bc nvmain 
Installation scon
安装编译工具scons
sudo apt-get install scons

Compile NVMain

Compile NVMain, which the compiler can choose the type of fast | debug | prof any of three kinds, where we use fast

scons --build-type=fast

Here are some compiler will complain, but to compile only build file, do not go directly to the following file change

If during compilation, reported the following error, no tension, this is just a small problem, because we are still not used gem5, so just being given that this line of code to comment.

scons: Reading SConscript files ...
ImportError: No module named gem5_scons:
  File "/home/greek/master/experiment/nvmain/SConstruct", line 253:
    SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 614:
    return method(*args, **kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 551:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 256:
    call_stack[-1].globals)
  File "/home/greek/master/experiment/nvmain/build/SConscript", line 36:
    from gem5_scons import Transform

Specific solution is to line 36 nvmain / build / SConscript comments in

# from gem5_scons import Transform # 这行注释

note! We also modify the back behind the back will say, here just to make you feel a spectrum

After resolving the error, and then recompile

nvm test

Specified configuration file, the file specified test period, the format command is: ./nvmain CONFIG_FILE TRACE_FILE [Cycles [PARAM = value]]
Here we test command follows

./nvmain.fast Config/PCM_ISSCC_2012_4GB.config Tests/Traces/hello_world.nvt 1000000

Test Results

i0.defaultMemory.channel0.FRFCFS-WQF.maximum_reads_during_drain 0
i0.defaultMemory.channel0.FRFCFS-WQF.starvation_precharges 4704
i0.defaultMemory.channel0.FRFCFS-WQF.averageLatency 86.4423
i0.defaultMemory.channel0.FRFCFS-WQF.averageQueueLatency 2088.42
i0.defaultMemory.channel0.FRFCFS-WQF.averageTotalLatency 2174.86
i0.defaultMemory.channel0.FRFCFS-WQF.measuredLatencies 26485
i0.defaultMemory.channel0.FRFCFS-WQF.measuredQueueLatencies 26485
i0.defaultMemory.channel0.FRFCFS-WQF.measuredTotalLatencies 26485
i0.defaultMemory.channel0.FRFCFS-WQF.simulation_cycles 1000000
i0.defaultMemory.channel0.FRFCFS-WQF.wakeupCount 54116
i0.defaultMemory.totalReadRequests 13933
i0.defaultMemory.totalWriteRequests 12608
i0.defaultMemory.successfulPrefetches 0
i0.defaultMemory.unsuccessfulPrefetches 0
Exiting at cycle 5000000 because simCycles 5000000 reached.
Note: 57 requests still in-flight.

Installation gem5

On Ubuntu, you can install all required dependencies using the following command. Requirements described in detail below.

Official website Description

Installation dependent (s)
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev python-dev python

Under normal circumstances, these things do not all mirror (I only tested and Tencent Ali clouds), but ensure that the basis of c ++, etc. (as detailed in the document) is necessary to boost installed will be much better systemc can use

Dependent libraries protobuf-compiler
sudo apt-get install protobuf-compiler

Measures well in advance (because the memory is insufficient to resolve the use of swap)

The reason is very simple: the student computers only 1G, certainly is not enough, the compilation process will often automatically kill

Solution Description

sudo dd if=/dev/zero of=/swapfile bs=64M count=16
#count的大小就是增加的swap空间的大小,64M是块大小,所以空间大小是bs*count=1024MB
sudo mkswap /swapfile
#把刚才空间格式化成swap格式
sudo swapon /swapfile
#使用刚才创建的swap空间

Logically, it should also be back, but consider the following often hung, not also the

Unzip and rename
sudo unzip gem5-master.zip 
ubuntu@VM-0-5-ubuntu:~/skywf$ ls
config-x86.tar.bz2  gem5-master.zip          mrp5060-nvmain-7be1ae0275cb.zip  nvmain.zip          zlib-1.2.11.tar.gz
gem5-master         m5_system_2.0b3.tar.bz2  nvmain                           x86-system.tar.bz2
ubuntu@VM-0-5-ubuntu:~/skywf$ mv gem5-master gem5
ubuntu@VM-0-5-ubuntu:~/skywf$ ls
config-x86.tar.bz2  gem5-master.zip          mrp5060-nvmain-7be1ae0275cb.zip  nvmain.zip          zlib-1.2.11.tar.gz
gem5                m5_system_2.0b3.tar.bz2  nvmain                           x86-system.tar.bz2
Start compiling

Long wait, about one hour it

$<2> [     CXX] X86/cpu/kvm/x86_cpu$<2>.cc$<2> -> $<2>.o$<2>
$<2> [    LINK] $<2>$<2> -> $<2>X86/cpu/kvm/lib.o.partial$<2>
$<2> [     CXX] X86/base/date$<2>.cc$<2> -> $<2>.o$<2>
$<2> [    LINK] $<2>$<2> -> $<2>X86/gem5.opt$<2>
scons: done building targets.

Description translated well

Gem5 the SE test
  1. A single application to run, a series of instructions on a MP / SMT
  2. Modeling and common user-visible ISA system calls
  3. Simulation system call, by calling the host operating system
  4. Simple address translation, no scheduling
./build/X86/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/x86/linux/hello 

Gem5 the FS test

FS test

能够启动完整的操作系统
建模硬件设备
中断,异常,故障处理函数

Reference download URL

If I did not use the package offers, you need to download their own

System-wide X86 download the corresponding file, be sure to download the corresponding file to compile architecture

There is unknowable part of the architecture bug, all right do not go on a safari


wget http://www.m5sim.org/dist/current/x86/x86-system.tar.bz2

Unzip the file, and the file after extracting the folder into the same directory fs-image

tar vxfj x86-system.tar.bz2
mkdir fs-image
mv binaries fs-image
mv disks fs-image

Download the whole file system corresponding alpha, which contains linux-bigswap2.img, this is a file to be run. Once downloaded, unzip the file, and copy files to the fs-image / disks directory, it can be understood as specifically stored image file Directory

wget http://www.m5sim.org/dist/current/m5_system_2.0b3.tar.bz2
tar vxfj m5_system_2.0b3.tar.bz2
cp m5_system_2.0b3/disks/linux-bigswap2.img fs-image/disks

If I use the package offered, directly extracted
sudo tar vxfj x86-system.tar.bz2
mkdir fs-image
sudo mv binaries fs-image
sudo mv disks fs-image
sudo tar vxfj m5_system_2.0b3.tar.bz2
sudo cp m5_system_2.0b3/disks/linux-bigswap2.img fs-image/disks

FS simulation run

 ./build/X86/gem5.opt configs/example/fs.py 

Reported the following error here because the script code in the default image for the x86root.img

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "build/X86/python/m5/main.py", line 457, in main
    exec(filecode, scope)
  File "configs/example/fs.py", line 342, in <module>
    test_sys = build_test_system(np)
  File "configs/example/fs.py", line 93, in build_test_system
    cmdline=cmdline)
  File "/home/ubuntu/skywf/gem5/configs/common/FSConfig.py", line 622, in makeLinuxX86System
    makeX86System(mem_mode, numCPUs, mdesc, self, Ruby)
  File "/home/ubuntu/skywf/gem5/configs/common/FSConfig.py", line 548, in makeX86System
    disks = makeCowDisks(mdesc.disks())
  File "/home/ubuntu/skywf/gem5/configs/common/Benchmarks.py", line 63, in disks
    return [env.get('LINUX_IMAGE', disk('x86root.img'))]
  File "/home/ubuntu/skywf/gem5/configs/common/SysPaths.py", line 69, in __call__
    .format(self.environment_variable))
IOError: Can't find system files directory, check your M5_PATH environment variable
Solution

There are two solutions, it is recommended to use the second:

  1. Modify the code gem5 / configs / common / Benchmarks.py, the line 63, modified as follows, wherein as linux-86.img at fs-image / disks image file directory
return env.get('LINUX_IMAGE', disk('linux-x86.img'))

  1. Directly specified image file using the parameter, the parameter --disk-image and -kernel
./build/X86/gem5.opt configs/example/fs.py --disk-image linux-x86.img --kernel x86_64-vmlinux-2.6.22.9
指定M5_PATH路径,系统会自动从M5_PATH路径中disks和binaries两个目录寻找指定的镜像文件和对应的内核文件.

Note that here you need to specify M5_PATH
Note here x86 uppercase lowercase

M5_PATH specify which provides two ways I recommend use the second

  1. Modify .basrhc document, adding M5_PATH at the end of the file path
vim ~/.bashrc
export M5_PATH=$M5_PATH:/home/ubuntu/skywf/fs-image
source ~/.bashrc

Note that the path has ubuntu, centos and not the same

Direct dynamically add environment variables run the command

M5_PATH=/home/skywf/fs-image ./build/X86/gem5.opt configs/example/fs.py --disk-image linux-x86.img --kernel x86_64-vmlinux-2.6.22.9

Note that the above skywf changed their username

linux-x86.img as fs-image / disks / directory file, x86_64-vmlinux-2.6.22.9 is fs-image / binaries / directory under the file, I see a lot of online tutorials will be renamed x86_64-vmlinux-2.6.22.9 is vmlinux this step is actually the meaning of words is not particularly large, but also convenient changed, I am here temporarily make changes

Possible problems encountered
  1. 出现Output file stream not open”: Error while running SE for X86 using gem5
    The reason is you do not have permission to file operation, you can change the 777 or directly through sudo sudo command to resolve
    the issue resolved
  2. Traceback (most recent call last): File "<string>", line 1, in <module> File "build/X86/python/m5/main.py", line 457, in main exec(filecode, scope) File "configs/example/fs.py", line 342, in <module> test_sys = build_test_system(np) File "configs/example/fs.py", line 93, in build_test_system cmdline=cmdline) File "/home/ubuntu/skywf/gem5/configs/common/FSConfig.py", line 622, in makeLinuxX86System makeX86System(mem_mode, numCPUs, mdesc, self, Ruby) File "/home/ubuntu/skywf/gem5/configs/common/FSConfig.py", line 548, in makeX86System disks = makeCowDisks(mdesc.disks()) File "/home/ubuntu/skywf/gem5/configs/common/Benchmarks.py", line 59, in disks return [disk(diskname) for diskname in self.disknames] File "/home/ubuntu/skywf/gem5/configs/common/SysPaths.py", line 69, in __call__ .format(self.environment_variable)) IOError: Can't find system files directory, check your M5_PATH environment variable

M5_PATH path set is still a problem, a little metaphysical here I did not understand, but with the specified dynamic variables can be solved temporarily refrain.

Connecting an analog system

Gem5 using a connection program system comes in gem5 / util / term / directory, to be make, executable file

cd util/term/
make

./m5term localhost 3456

[Recommended] directly via a telnet connection system

telnet localhost 3456

Tencent cloud default this port is not open, go inside to open their own security group
The following represents the emergence of this success even on

usbcore: registered new interface driver usbhid
drivers/hid/usbhid/hid-core.c: v2.6:USB HID core driver
oprofile: using timer interrupt.
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 10
IPv6 over IPv4 tunneling driver
NET: Registered protocol family 17
EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
VFS: Mounted root (ext2 filesystem).
Freeing unused kernel memory: 232k freed
INIT: version 2.86 booting
mounting filesystems...
loading script...
Script from M5 readfile is empty, starting bash shell...
(none) / # 
drop out

Here I still use two methods, the first method is recommended

M5 exit command line input connected to the
input on the command line - connected.

NVMain and Gem5 integrated environment

Why patch

Gem5 patch

First, in order to eliminate the differences between NVMain and Gem5 version, so you first need to Gem5 patched. (Do not feel afraid to hear the patch, first I have this feeling, in fact, I found the back really nothing).

Open patch

Manual patch, patch directly view the contents, manually modify the file as follows for the patch content

Patch file has been given in nvmain / patches / gem5 directory, nvmain2-gem5-11688 + This is the name of the patch file, in nvmain / patches / gem5, the future may be other versions, and replaced with the name of their version of the patch that is can.

ubuntu@VM-0-5-ubuntu:~/skywf/nvmain/patches/gem5$ ls
nvmain2-gem5-11688+
# HG changeset patch
# Parent 78ef8daecd81de0c392034809b3bc155396bf983
gem5: Updated for gem5 revisions 10789+

diff --git a/configs/common/Options.py b/configs/common/Options.py
--- a/configs/common/Options.py
+++ b/configs/common/Options.py
@@ -63,6 +63,12 @@
 # being used, and consequently no CPUs, but rather various types of
 # testers and traffic generators.
 def addNoISAOptions(parser):
+    # Check for extra nvmain configuration override options
+    for arg in sys.argv:
+        if arg[:9] == "--nvmain-":
+            parser.add_option(arg, type="string", default="NULL",
+                       help="Set NVMain configuration value for a parameter")
+
     parser.add_option("-n", "--num-cpus", type="int", default=1)
     parser.add_option("--sys-voltage", action="store", type="string",
                       default='1.0V',

In fact, it means an increase of three lines, we will be able to manually add

Just after gem5 / configs / common / 82nd Options.py, adding the following three lines (lines 89 there may be, depending on the editor vim or nano)
Anyway, as far as is it addnoisaoptions

for arg in sys.argv:
    if arg[:9] == "--nvmain-":
        parser.add_option(arg, type="string", default="NULL", help="Set NVMain configuration value for a parameter")

Here Insert Picture Description

NVMain and Gem5 mixed compilation

(Drift off in the middle of the night nvmain get a long time to get mad at the head) in gem5 folder

scons EXTRAS=../nvmain build/X86/gem5.opt

Found error

NameError: global name 'Transform' is not defined:
  File "/home/ubuntu/skywf/gem5/SConstruct", line 1269:
    SConscript('src/SConscript', variant_dir = variant_path, exports = 'env')
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 614:
    return method(*args, **kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 551:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 260:
    exec _file_ in call_stack[-1].globals
  File "/home/ubuntu/skywf/gem5/build/X86/SConscript", line 618:
    SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 614:
    return method(*args, **kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 551:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 260:
    exec _file_ in call_stack[-1].globals
  File "/home/ubuntu/skywf/gem5/build/X86/nvmain/SConscript", line 88:
    MakeInclude('SimInterface/Gem5Interface/Gem5Interface.h')
  File "/home/ubuntu/skywf/gem5/build/X86/nvmain/SConscript", line 85:
    include_action = MakeAction(MakeIncludeAction, Transform("MAKE INC", 1))

This is because before we delete a row, and now to restore

sudo nano nvmain/build/SConscript

Well, next is to wait

Harvest inspection

Test, which is an important sign of success is mixed compiler can use -mem-type = NVMainMemory parameter to specify the main memory for the NVM

M5_PATH=/home/hsc/fs-image ./build/X86/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/x86/linux/hello --caches --l2cache --mem-type=NVMainMemory --nvmain-config=../nvmain/Config/PCM_ISSCC_2012_4GB.config

As long as you show this, as evidenced by your own work ok,

i0.defaultMemory.channel0.FRFCFS-WQF.maximum_read_spacing 0
i0.defaultMemory.channel0.FRFCFS-WQF.total_readqueue_size 0
i0.defaultMemory.channel0.FRFCFS-WQF.average_predrain_readqueue_size 0
i0.defaultMemory.channel0.FRFCFS-WQF.minimum_predrain_readqueue_size 10000000000
i0.defaultMemory.channel0.FRFCFS-WQF.maximum_predrain_readqueue_size 0
i0.defaultMemory.channel0.FRFCFS-WQF.total_reads_during_drain 0
i0.defaultMemory.channel0.FRFCFS-WQF.average_reads_during_drain 0
i0.defaultMemory.channel0.FRFCFS-WQF.minimum_reads_during_drain 10000000000
i0.defaultMemory.channel0.FRFCFS-WQF.maximum_reads_during_drain 0
i0.defaultMemory.channel0.FRFCFS-WQF.starvation_precharges 0
i0.defaultMemory.channel0.FRFCFS-WQF.averageLatency 0
i0.defaultMemory.channel0.FRFCFS-WQF.averageQueueLatency 0
i0.defaultMemory.channel0.FRFCFS-WQF.averageTotalLatency 0
i0.defaultMemory.channel0.FRFCFS-WQF.measuredLatencies 0
i0.defaultMemory.channel0.FRFCFS-WQF.measuredQueueLatencies 0
i0.defaultMemory.channel0.FRFCFS-WQF.measuredTotalLatencies 0
i0.defaultMemory.channel0.FRFCFS-WQF.simulation_cycles 1188
i0.defaultMemory.channel0.FRFCFS-WQF.wakeupCount 0
i0.defaultMemory.totalReadRequests 0
i0.defaultMemory.totalWriteRequests 0
i0.defaultMemory.successfulPrefetches 0
i0.defaultMemory.unsuccessfulPrefetches 0

Toss back and forth a dozen times, and quickly buy a desktop computer to install it

Published 83 original articles · won praise 400 · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_43914889/article/details/104713850