website: Code discrepancies and other edits
Fixed discrepancies between code on Github
and tutorial, fixed unclear explanations.
Jira Issue: https://gem5.atlassian.net/browse/GEM5-690
Change-Id: Ia108329fb293c693eda19994c6c6f04aa92de80e
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5-website/+/31454
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: Jason Lowe-Power <power.jg@gmail.com>
diff --git a/_pages/documentation/learning_gem5/part2/part2_0_environment.md b/_pages/documentation/learning_gem5/part2/part2_0_environment.md
index 0b5ca06..ef07a14 100644
--- a/_pages/documentation/learning_gem5/part2/part2_0_environment.md
+++ b/_pages/documentation/learning_gem5/part2/part2_0_environment.md
@@ -18,7 +18,7 @@
When modifying any open source project, it is important to follow the
project's style guidelines. Details on gem5 style can be found on the
-gem5 [wiki page](http://gem5.org/Coding_Style).
+gem5 [Coding Style page](http://www.gem5.org/documentation/general_docs/development/coding_style/).
To help you conform to the style guidelines, gem5 includes a script
which runs whenever you commit a changeset in git. This script should be
diff --git a/_pages/documentation/learning_gem5/part2/part2_1_helloobject.md b/_pages/documentation/learning_gem5/part2/part2_1_helloobject.md
index 190e77a..f19c761 100644
--- a/_pages/documentation/learning_gem5/part2/part2_1_helloobject.md
+++ b/_pages/documentation/learning_gem5/part2/part2_1_helloobject.md
@@ -55,7 +55,7 @@
simply need to declare a new class for our SimObject and set it's name
and the C++ header that will define the C++ class for the SimObject.
-We can create a file, HelloObject.py, in `src/learning_gem5`.
+We can create a file, HelloObject.py, in `src/learning_gem5/part2`. If you have cloned the gem5 repository you'll have the files mentioned in this tutorial completed under `src/learning_gem5/part2` and `configs/learning_gem5/part2`. You can delete these or move them elsewhere to follow this tutorial.
```python
from m5.params import *
@@ -63,7 +63,7 @@
class HelloObject(SimObject):
type = 'HelloObject'
- cxx_header = "learning_gem5/hello_object.hh"
+ cxx_header = "learning_gem5/part2/hello_object.hh"
```
[//]: # You can find the complete file
@@ -82,8 +82,7 @@
Step 2: Implement your SimObject in C++
---------------------------------------
-Next, we need to create `hello_object.hh` and `hello_object.cc` which
-will implement the hello object.
+Next, we need to create `hello_object.hh` and `hello_object.cc` in `src/learning_gem5/part2/` directory which will implement the `HelloObject`.
We'll start with the header file for our `C++` object. By convention,
gem5 wraps all header files in `#ifndef/#endif` with the name of the
@@ -103,7 +102,7 @@
system and is based on the `Python` class for the SimObject, like the
one we created above. The name for this parameter type is generated
automatically from the name of your object. For our "HelloObject" the
-parameter type's name is "HelloObject\**Params*\*".
+parameter type's name is "HelloObjectParams".
The code required for our simple header file is listed below.
@@ -137,7 +136,7 @@
simply use `std::cout` because it is simple.
```cpp
-#include "learning_gem5/hello_object.hh"
+#include "learning_gem5/part2/hello_object.hh"
#include <iostream>
@@ -199,7 +198,7 @@
defined after you import them. See the section on that...
To get your new SimObject to compile, you simply need to create a new
-file with the name "SConscript" in the `src/learning_gem5` directory. In
+file with the name "SConscript" in the `src/learning_gem5/part2` directory. In
this file, you have to declare the SimObject and the `.cc` file. Below
is the required code.
@@ -228,10 +227,7 @@
-----------------------------------------------------------
Now that you have implemented a SimObject, and it has been compiled into
-gem5, you need to create or modify a `Python` config file to instantiate
-your object. Since your object is very simple a system object is not
-required! CPUs are not needed, or caches, or anything, except a `Root`
-object. All gem5 instances require a `Root` object.
+gem5, you need to create or modify a `Python` config file `run_hello.py` in `configs/learning_gem5/part2` to instantiate your object. Since your object is very simple a system object is not required! CPUs are not needed, or caches, or anything, except a `Root` object. All gem5 instances require a `Root` object.
Walking through creating a *very* simple configuration script, first,
import m5 and all of the objects you have compiled.
@@ -274,22 +270,25 @@
[//]: # You can find the complete file
[//]: # [here](/_pages/static/scripts/part2/helloobject/run_hello.py).
-The output should look something like the following
+Remember to rebuild gem5 after modifying files in the src/ directory. The command line to run the config file is in the output below after 'command line:'.
+The output should look something like the following:
+Note: If the code for the future section "Adding parameters to SimObjects and more events", (goodbye_object) is in your src/learning_gem5/part2 directory, run_hello.py will cause an error. If you delete those files or move them outside of the gem5 directory `run_hello.py` should give the output below.
+```
gem5 Simulator System. http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 compiled May 4 2016 11:37:41
gem5 started May 4 2016 11:44:28
gem5 executing on mustardseed.cs.wisc.edu, pid 22480
- command line: build/X86/gem5.opt configs/learning_gem5/run_hello.py
+ command line: build/X86/gem5.opt configs/learning_gem5/part2/run_hello.py
Global frequency set at 1000000000000 ticks per second
Hello World! From a SimObject!
Beginning simulation!
info: Entering event queue @ 0. Starting simulation...
Exiting @ tick 18446744073709551615 because simulate() limit reached
-
+```
Congrats! You have written your first SimObject. In the next chapters,
we will extend this SimObject and explore what you can do with
SimObjects.
diff --git a/_pages/documentation/learning_gem5/part2/part2_4_parameters.md b/_pages/documentation/learning_gem5/part2/part2_4_parameters.md
index 7ce0910..127d701 100644
--- a/_pages/documentation/learning_gem5/part2/part2_4_parameters.md
+++ b/_pages/documentation/learning_gem5/part2/part2_4_parameters.md
@@ -15,7 +15,7 @@
to pass parameters from Python to the C++ objects in gem5. In this
chapter, we will explore some of the kinds of parameters for SimObjects
and how to use them building off of the simple `HelloObject` from the
-previous chapters \<events-chapter\>.
+[previous chapters](http://www.gem5.org/documentation/learning_gem5/part2/helloobject/).
Simple parameters
-----------------
@@ -23,7 +23,7 @@
First, we will add parameters for the latency and number of times to
fire the event in the `HelloObject`. To add a parameter, modify the
`HelloObject` class in the SimObject Python file
-(`src/learning_gem5/HelloObject.py`). Parameters are set by adding new
+(`src/learning_gem5/part2/HelloObject.py`). Parameters are set by adding new
statements to the Python class that include a `Param` type.
For instance, the following code has a parameter `time_to_wait` which is
@@ -33,7 +33,7 @@
```python
class HelloObject(SimObject):
type = 'HelloObject'
- cxx_header = "learning_gem5/hello_object.hh"
+ cxx_header = "learning_gem5/part2/hello_object.hh"
time_to_wait = Param.Latency("Time before firing the event")
number_of_fires = Param.Int(1, "Number of times to fire the event before "
@@ -99,11 +99,11 @@
private:
void processEvent();
- EventWrapper<HelloObject, &HelloObject::processEvent> event;
+ EventWrapper event;
- std::string myName;
+ const std::string myName;
- Tick latency;
+ const Tick latency;
int timesLeft;
@@ -203,7 +203,7 @@
```python
class GoodbyeObject(SimObject):
type = 'GoodbyeObject'
- cxx_header = "learning_gem5/goodbye_object.hh"
+ cxx_header = "learning_gem5/part2/goodbye_object.hh"
buffer_size = Param.MemorySize('1kB',
"Size of buffer to fill with goodbye")
@@ -270,7 +270,7 @@
```
```cpp
-#include "learning_gem5/goodbye_object.hh"
+#include "learning_gem5/part2/goodbye_object.hh"
#include "debug/Hello.hh"
#include "sim/sim_exit.hh"
@@ -374,7 +374,7 @@
```python
class HelloObject(SimObject):
type = 'HelloObject'
- cxx_header = "learning_gem5/hello_object.hh"
+ cxx_header = "learning_gem5/part2/hello_object.hh"
time_to_wait = Param.Latency("Time before firing the event")
number_of_fires = Param.Int(1, "Number of times to fire the event before "
@@ -388,17 +388,24 @@
Second, we will add a reference to a `GoodbyeObject` to the
`HelloObject` class.
+Don't forget to include goodbye_object.hh at the top of the hello_object.hh file!
```cpp
+#include <string>
+
+#include "learning_gem5/part2/goodbye_object.hh"
+#include "params/HelloObject.hh"
+#include "sim/sim_object.hh"
+
class HelloObject : public SimObject
{
private:
void processEvent();
- EventWrapper<HelloObject, &HelloObject::processEvent> event;
+ EventWrapper event;
/// Pointer to the corresponding GoodbyeObject. Set via Python
- const GoodbyeObject* goodbye;
+ GoodbyeObject* goodbye;
/// The name of this object in the Python config file
const std::string myName;
@@ -484,9 +491,9 @@
m5.instantiate()
-print "Beginning simulation!"
+print("Beginning simulation!")
exit_event = m5.simulate()
-print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())
+print('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()))
```
You can download this script