{"id":126,"date":"2016-05-02T23:26:02","date_gmt":"2016-05-02T14:26:02","guid":{"rendered":"https:\/\/posuer000.wordpress.com\/?p=126"},"modified":"2018-12-28T12:54:31","modified_gmt":"2018-12-28T03:54:31","slug":"gem5-basic-guideline","status":"publish","type":"post","link":"https:\/\/www.wanggengyu.com\/?p=126","title":{"rendered":"Gem5 Basic Guideline"},"content":{"rendered":"<p>All contents original from https:\/\/github.com\/dependablecomputinglab<\/p>\n<p>This article is just a backup incase myself later using.<\/p>\n<h2>Gem5 Installation<\/h2>\n<h3>step 1: install prerequisites<\/h3>\n<p>for Ubuntu<br \/>\n<code><br \/>\n$ sudo apt-get update<br \/>\n$ sudo apt-get upgrade<br \/>\n$ sudo apt-get install -y git build-essential g++ zlib1g-dev scons m4 swig python-dev<br \/>\n<\/code><\/p>\n<h3>step 2: Download &amp; Build<\/h3>\n<p>Download<br \/>\n<!--more Read More--><br \/>\n<code><br \/>\n$ cd ~<br \/>\n~$ git clone https:\/\/github.com\/gem5\/gem5<br \/>\n<\/code><br \/>\nBuild<\/p>\n<ul>\n<li>Command: $ scons build\/\/<\/li>\n<li>Supported ISA: ARM, ALPHA, MIPS, SPARC, POWER, X86<\/li>\n<li>Supported Binaries: gem5.debug, gem5.opt, gem5.fast, gem5.prof<\/li>\n<\/ul>\n<p>This is a example for ARM architecture<\/p>\n<p><code>$ cd ~\/gem5<br \/>\n~\/gem5$ scons build\/ARM\/gem5.opt<\/code><\/p>\n<h3>step 3: Run benchmark<\/h3>\n<ul>\n<li>Command: $ build\/\/ -c<\/li>\n<li>Outputs are generated in m5out\/<\/li>\n<\/ul>\n<p>This is example for building gem5 for ARM ISA<\/p>\n<p><code><br \/>\n$ cd ~<br \/>\n~$ git clone https:\/\/github.com\/gem5\/gem5<br \/>\n<\/code><\/p>\n<p>All simulation statistics are saved as file m5out\/stats.txt<\/p>\n<h4><\/h4>\n<h2>Simulation Process<\/h2>\n<ol>\n<li>Get benchmark to simulate<\/li>\n<li>Do simulation<\/li>\n<li>Analyze simulation statistics<\/li>\n<\/ol>\n<h3><a id=\"user-content-step1-get-benchmark\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#step1-get-benchmark\"><\/a>STEP1: Get Benchmark<\/h3>\n<p>You can get benchmark by:<\/p>\n<ul>\n<li>Making your own benchmark yourself<\/li>\n<li>Download binary<\/li>\n<li>Download source code &amp; build binary<\/li>\n<\/ul>\n<p>In our case, we will download <em>MiBench<\/em>, then cross-compile to get benchmark.<\/p>\n<h4><a id=\"user-content-download-mibench\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#download-mibench\"><\/a>Download <strong><em>MiBench<\/em><\/strong><\/h4>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ git clone https:\/\/github.com\/embecosm\/mibench.git<\/pre>\n<\/div>\n<h4><a id=\"user-content-install-cross-compiler\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#install-cross-compiler\"><\/a>Install Cross-compiler<\/h4>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ sudo apt-get install gcc-arm-linux-gnueabi<\/pre>\n<\/div>\n<h4><a id=\"user-content-cross-compile-to-build-binary\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#cross-compile-to-build-binary\"><\/a>Cross-compile to build binary<\/h4>\n<p>Initially, you can see <em>Makefile<\/em> in directory &#8216;<em>mibench\/automotive\/qsort<\/em>&#8216; looks like:<\/p>\n<div class=\"highlight highlight-source-makefile\">\n<pre>...\r\ngcc -static qsort_large.c -O3 -o qsort_large -lm \r\n...<\/pre>\n<\/div>\n<p>Replace <strong>all<\/strong> &#8216;<em>gcc<\/em>&#8216; to &#8216;<em>arm-linux-gnueabi-gcc<\/em>&#8216;, so the <em>Makefile<\/em> looks like:<\/p>\n<div class=\"highlight highlight-source-makefile\">\n<pre>...\r\narm-linux-gnueabi-gcc -static qsort_large.c -O3 -o qsort_large -lm \r\n...<\/pre>\n<\/div>\n<p>To build, execute<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ make<\/pre>\n<\/div>\n<p><strong>NOTE<\/strong> When you cross-compile, you must use &#8216;<strong>-static<\/strong>&#8216; option. If there is no &#8216;<strong>-static<\/strong>&#8216; option in <em>Makefile<\/em>, you have to insert it.<br \/>\nFor example, if your <em>Makefile<\/em> looks like:<\/p>\n<div class=\"highlight highlight-source-makefile\">\n<pre>...\r\narm-linux-gnueabi-gcc qsort_large.c -O3 -o qsort_large -lm\r\n...<\/pre>\n<\/div>\n<p>You have to insert &#8216;<strong>-static<\/strong>&#8216; option. Then, <em>Makefile<\/em> will look like:<\/p>\n<div class=\"highlight highlight-source-makefile\">\n<pre>...\r\narm-linux-gnueabi-gcc -static qsort_large.c -O3 -o qsort_large -lm \r\n...<\/pre>\n<\/div>\n<h3><a id=\"user-content-step2-perform-simulation\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#step2-perform-simulation\"><\/a>STEP2: Perform Simulation<\/h3>\n<p>$ &lt;<em>gem5 binary<\/em>&gt; [<em>gem5 options<\/em>] &lt;<em>gem5 script<\/em>&gt; [<em>gem5 script options<\/em>]<\/p>\n<h4><a id=\"user-content-useful-gem5-script-options\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#useful-gem5-script-options\"><\/a>Useful <em>gem5<\/em> script options<\/h4>\n<ul>\n<li>&#8216;-c &lt;<em>binary to simulate<\/em>&gt;&#8217;<\/li>\n<li>&#8216;-o &lt;<em>input set of benchmark<\/em>&gt;&#8217;<\/li>\n<\/ul>\n<p>For example, if you want to simulate <em>qsort_large<\/em>,<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ .\/build\/ARM\/gem5.opt -re configs\/example\/se.py --cpu-type=atomic -c <span class=\"pl-k\">&lt;<\/span>path to qsort_large<span class=\"pl-k\">&gt;<\/span> -o <span class=\"pl-k\">&lt;<\/span>path to input_large.dat<span class=\"pl-k\">&gt;<\/span><\/pre>\n<\/div>\n<p><strong>NOTE<\/strong><br \/>\nIf you want to put multiple input to binary, you have to use quotation marks(&#8220;) and white spaces.<br \/>\nFor example, if your <em>fft<\/em> binary is in <em>~\/mibench\/telecom\/FFT<\/em>,<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ .\/build\/ARM\/gem5.opt -re configs\/example\/se.py --cpu-type=timing -c <span class=\"pl-k\">~<\/span>\/mibench\/telecom\/FFT\/fft -o <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>100 64<span class=\"pl-pds\">\"<\/span><\/span><\/pre>\n<\/div>\n<h3><a id=\"user-content-step3-analyzing-simulation-statistics\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#step3-analyzing-simulation-statistics\"><\/a>STEP3: Analyzing Simulation Statistics<\/h3>\n<h4><a id=\"user-content-find-difference-between-two-files-with-diff\" class=\"anchor\" href=\"https:\/\/github.com\/dependablecomputinglab\/csi3102-gem5-profiling\/blob\/master\/README.md#find-difference-between-two-files-with-diff\"><\/a>Find difference between two files with <em>diff<\/em><\/h4>\n<p>The <em>diff<\/em> is a program in linux.<br \/>\nThe <em>diff<\/em> compares two files, <strong>line by line<\/strong>.<br \/>\nYou can use <em>diff<\/em> by executing: <strong>$ diff [<em>options<\/em>] &lt;<em>file1<\/em>&gt; &lt;<em>file2<\/em>&gt;<\/strong><\/p>\n<p>For example, clone this repository and execute:<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ diff goodbye1.txt goodbye2.txt<\/pre>\n<\/div>\n<p>If you use &#8216;<strong>-u<\/strong>&#8216; option like this:<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ diff -u goodbye1.txt goodbye2.txt<\/pre>\n<\/div>\n<p>Redirection may make you happy! Try this:<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre>$ diff -u goodbye1.txt goodbye2.txt <span class=\"pl-k\">&gt;<\/span> goodbye.diff<\/pre>\n<\/div>\n<p>You can see the file <em>goodbye.diff<\/em>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>All contents original from https:\/\/github.com\/dependablecomputinglab This article is just a backup incase myself later using. Gem5 Installation step 1: install prerequisites for Ubuntu $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install -y git build-essential g++ zlib1g-dev scons m4 swig python-dev step 2: Download &amp; Build Download<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-techniques"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=126"}],"version-history":[{"count":1,"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":684,"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=\/wp\/v2\/posts\/126\/revisions\/684"}],"wp:attachment":[{"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wanggengyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}