| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="x-ua-compatible" content="ie=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| |
| <title>gem5</title> |
| |
| <!-- SITE FAVICON --> |
| <link rel="shortcut icon" type="image/gif" href="/assets/img/gem5ColorVert.gif"/> |
| |
| <link rel="canonical" href="http://localhost:4000/running/"> |
| <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800,600' rel='stylesheet' type='text/css'> |
| <link href='https://fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'> |
| |
| <!-- FAVICON --> |
| <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> |
| |
| <!-- BOOTSTRAP --> |
| <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> |
| |
| <!-- CUSTOM CSS --> |
| <link rel="stylesheet" href="/css/main.css"> |
| </head> |
| |
| |
| <body> |
| <nav class="navbar navbar-expand-md navbar-light bg-light"> |
| <a class="navbar-brand" href="/"> |
| <img src="/assets/img/gem5ColorLong.gif" alt="gem5" height=45px> |
| </a> |
| <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"> |
| <span class="navbar-toggler-icon"></span> |
| </button> |
| <div class="collapse navbar-collapse" id="navbarNavDropdown"> |
| <ul class="navbar-nav ml-auto"> |
| <li class="nav-item "> |
| <a class="nav-link" href="/">Home</a> |
| </li> |
| |
| <li class="nav-item dropdown "> |
| <a class="nav-link dropdown-toggle" href="/about" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| About |
| </a> |
| <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> |
| <a class="dropdown-item" href="/about">About</a> |
| <a class="dropdown-item" href="/publications">Publications</a> |
| <a class="dropdown-item" href="/governance">Governance</a> |
| </div> |
| </li> |
| |
| <li class="nav-item dropdown active"> |
| <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| Documentation |
| </a> |
| <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> |
| <!-- Pull navigation from _data/documentation.yml --> |
| |
| <a class="dropdown-item" href="/introduction">Introduction</a> |
| |
| <a class="dropdown-item" href="/building">Getting Started</a> |
| |
| <a class="dropdown-item" href="/environment">Modifying/Extending</a> |
| |
| <a class="dropdown-item" href="/MSIintro">Modeling Cache Coherence with Ruby</a> |
| |
| </div> |
| </li> |
| |
| <li class="nav-item "> |
| <a class="nav-link" href="/contributing">Contributing</a> |
| </li> |
| |
| <li class="nav-item "> |
| <a class="nav-link" href="/blog">Blog</a> |
| </li> |
| |
| <li class="nav-item "> |
| <a class="nav-link" href="/search">Search</a> |
| </li> |
| </ul> |
| </div> |
| </nav> |
| |
| <main> |
| <div class="sidenav-top"> |
| <a href="/"><img src="/assets/img/gem5ColorLong.gif" height="80"></a> |
| <div class="search"> |
| <form action="/search" method="get"> |
| <!-- <label for="search-box"><i class="fa fa-search"></i></label> --> |
| <input type="text" name="query"> |
| <button type="submit" name="submit"><i class="fa fa-search"></i></button> |
| </form> |
| </div> |
| </div> |
| <div class="sidenav"> |
| <!-- Pull navigation from _data/documentation.yml --> |
| |
| <a class="item" href="/introduction" role="button" aria-expanded="false" aria-controls="collapseExample"> |
| Introduction |
| </a> |
| <div class="collapse " id="introduction"> |
| |
| </div> |
| |
| <a class="item" data-toggle="collapse" href="#pt1" role="button" aria-expanded="false" aria-controls="collapseExample"> |
| Getting Started |
| </a> |
| <div class="collapse " id="pt1"> |
| |
| <a class="subitem " href="/building">Building gem5</a> |
| |
| <a class="subitem " href="/simple_config">Creating a simple configuration script</a> |
| |
| <a class="subitem " href="/cache_config">Adding cache to configuration script</a> |
| |
| <a class="subitem " href="/gem5_stats">Understanding gem5 statistics and output</a> |
| |
| <a class="subitem " href="/example_configs">Using the default configuration scripts</a> |
| |
| </div> |
| |
| <a class="item" data-toggle="collapse" href="#pt2" role="button" aria-expanded="false" aria-controls="collapseExample"> |
| Modifying/Extending |
| </a> |
| <div class="collapse " id="pt2"> |
| |
| <a class="subitem " href="/environment">Setting up your development environment</a> |
| |
| <a class="subitem " href="/helloobject">Creating a very simple SimObject</a> |
| |
| <a class="subitem " href="/debugging">Debugging gem5</a> |
| |
| <a class="subitem " href="/events">Event-driven programming</a> |
| |
| <a class="subitem " href="/parameters">Adding parameters to SimObjects and more events</a> |
| |
| <a class="subitem " href="/memoryobject">Creating SimObjects in the memory system</a> |
| |
| <a class="subitem " href="/simplecache">Creating a simple cache object</a> |
| |
| </div> |
| |
| <a class="item" data-toggle="collapse" href="#pt3" role="button" aria-expanded="false" aria-controls="collapseExample"> |
| Modeling Cache Coherence with Ruby |
| </a> |
| <div class="collapse show" id="pt3"> |
| |
| <a class="subitem " href="/MSIintro">Introduction to Ruby</a> |
| |
| <a class="subitem " href="/cache-intro">MSI example cache protocol</a> |
| |
| <a class="subitem " href="/cache-declarations">Declaring a state machine</a> |
| |
| <a class="subitem " href="/cache-in-ports">In port code blocks</a> |
| |
| <a class="subitem " href="/cache-actions">Action code blocks</a> |
| |
| <a class="subitem " href="/cache-transitions">Transition code blocks</a> |
| |
| <a class="subitem " href="/directory">MSI Directory implementation</a> |
| |
| <a class="subitem " href="/MSIbuilding">Compiling a SLICC protocol</a> |
| |
| <a class="subitem " href="/configuration">Configuring a simple Ruby system</a> |
| |
| <a class="subitem active" href="/running">Running the simple Ruby system</a> |
| |
| <a class="subitem " href="/MSIdebugging">Debugging SLICC Protocols</a> |
| |
| <a class="subitem " href="/simple-MI_example">Configuring for a standard protocol</a> |
| |
| </div> |
| |
| </div> |
| |
| <div class="container" id="doc-container"> |
| <div class="edit"><a href="https://github.com/gem5/new-website/tree/master/_pages/documentation/part3/running.md">Edit this page</a></div> |
| <dl> |
| <dt>authors</dt> |
| <dd>Jason Lowe-Power</dd> |
| </dl> |
| |
| <h1 id="running-the-simple-ruby-system">Running the simple Ruby system</h1> |
| |
| <p>Now, we can run our system with the MSI protocol!</p> |
| |
| <p>As something interesting, below is a simple multithreaded program (note: |
| as of this writing there is a bug in gem5 preventing this code from |
| executing).</p> |
| |
| <p>``` {.sourceCode .c++} |
| #include <iostream> |
| #include <thread></thread></iostream></p> |
| |
| <p>using namespace std;</p> |
| |
| <p>/*</p> |
| <ul> |
| <li>c = a + b |
| */ |
| void array_add(int *a, int *b, int *c, int tid, int threads, int num_values) |
| { |
| for (int i = tid; i < num_values; i += threads) { |
| c[i] = a[i] + b[i]; |
| } |
| }</li> |
| </ul> |
| |
| <p>int main(int argc, char *argv[]) |
| { |
| unsigned num_values; |
| if (argc == 1) { |
| num_values = 100; |
| } else if (argc == 2) { |
| num_values = atoi(argv[1]); |
| if (num_values <= 0) { |
| cerr « “Usage: “ « argv[0] « ” [num_values]” « endl; |
| return 1; |
| } |
| } else { |
| cerr « “Usage: “ « argv[0] « ” [num_values]” « endl; |
| return 1; |
| }</p> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>unsigned cpus = thread::hardware_concurrency(); |
| |
| cout << "Running on " << cpus << " cores. "; |
| cout << "with " << num_values << " values" << endl; |
| |
| int *a, *b, *c; |
| a = new int[num_values]; |
| b = new int[num_values]; |
| c = new int[num_values]; |
| |
| if (!(a && b && c)) { |
| cerr << "Allocation error!" << endl; |
| return 2; |
| } |
| |
| for (int i = 0; i < num_values; i++) { |
| a[i] = i; |
| b[i] = num_values - i; |
| c[i] = 0; |
| } |
| |
| thread **threads = new thread*[cpus]; |
| |
| // NOTE: -1 is required for this to work in SE mode. |
| for (int i = 0; i < cpus - 1; i++) { |
| threads[i] = new thread(array_add, a, b, c, i, cpus, num_values); |
| } |
| // Execute the last thread with this thread context to appease SE mode |
| array_add(a, b, c, cpus - 1, cpus, num_values); |
| |
| cout << "Waiting for other threads to complete" << endl; |
| |
| for (int i = 0; i < cpus - 1; i++) { |
| threads[i]->join(); |
| } |
| |
| delete[] threads; |
| |
| cout << "Validating..." << flush; |
| |
| int num_valid = 0; |
| for (int i = 0; i < num_values; i++) { |
| if (c[i] == num_values) { |
| num_valid++; |
| } else { |
| cerr << "c[" << i << "] is wrong."; |
| cerr << " Expected " << num_values; |
| cerr << " Got " << c[i] << "." << endl; |
| } |
| } |
| |
| if (num_valid == num_values) { |
| cout << "Success!" << endl; |
| return 0; |
| } else { |
| return 2; |
| } } ``` |
| </code></pre></div></div> |
| |
| <p>With the above code compiled as <code class="highlighter-rouge">threads</code>, we can run gem5!</p> |
| |
| <p><code class="highlighter-rouge">{.sourceCode .sh} |
| build/MSI/gem5.opt configs/learning_gem5/part6/simple_ruby.py |
| </code></p> |
| |
| <p>The output should be something like the following. Most of the warnings |
| are unimplemented syscalls in SE mode due to using pthreads and can be |
| safely ignored for this simple example.</p> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem5 Simulator System. http://gem5.org |
| gem5 is copyrighted software; use the --copyright option for details. |
| |
| gem5 compiled Sep 7 2017 12:39:51 |
| gem5 started Sep 10 2017 20:56:35 |
| gem5 executing on fuggle, pid 6687 |
| command line: build/MSI/gem5.opt configs/learning_gem5/part6/simple_ruby.py |
| |
| Global frequency set at 1000000000000 ticks per second |
| warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes) |
| 0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000 |
| 0: system.remote_gdb.listener: listening for remote gdb #1 on port 7001 |
| Beginning simulation! |
| info: Entering event queue @ 0. Starting simulation... |
| warn: Replacement policy updates recently became the responsibility of SLICC state machines. Make sure to setMRU() near callbacks in .sm files! |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall access(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall mprotect(...) |
| warn: ignoring syscall set_robust_list(...) |
| warn: ignoring syscall rt_sigaction(...) |
| (further warnings will be suppressed) |
| warn: ignoring syscall rt_sigprocmask(...) |
| (further warnings will be suppressed) |
| info: Increasing stack size by one page. |
| info: Increasing stack size by one page. |
| Running on 2 cores. with 100 values |
| warn: ignoring syscall mprotect(...) |
| warn: ClockedObject: Already in the requested power state, request ignored |
| warn: ignoring syscall set_robust_list(...) |
| Waiting for other threads to complete |
| warn: ignoring syscall madvise(...) |
| Validating...Success! |
| Exiting @ tick 9386342000 because exiting with last active thread context |
| </code></pre></div></div> |
| |
| <br> |
| |
| <!-- RETRIVE PREVIOUS PAGE LINK --> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <!-- RETRIEVE NEXT PAGE LINK --> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <div class="navbuttons"> |
| |
| <a href="/configuration"><button type="button" class="btn btn-outline-primary">PREVIOUS</button></a> |
| |
| |
| |
| <a href="/MSIdebugging"><button type="button" class="btn btn-outline-primary">NEXT</button></a> |
| |
| </div> |
| </div> |
| |
| </main> |
| |
| |
| <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> |
| <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> |
| |
| <script> |
| // When the user scrolls down 20px from the top of the document, show the button |
| window.onscroll = function() {scrollFunction()}; |
| |
| function scrollFunction() { |
| if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 20) { |
| document.getElementById("myBtn").style.display = "block"; |
| } else { |
| document.getElementById("myBtn").style.display = "none"; |
| } |
| } |
| |
| // When the user clicks on the button, scroll to the top of the document |
| function topFunction() { |
| document.body.scrollTop = 0; |
| document.documentElement.scrollTop = 0; |
| } |
| </script> |
| |
| </body> |
| |
| |
| </html> |