[gem5-dev] Change in gem5/gem5[develop]: sim: Create a StubWorkload for System.workload to default to.

2021-11-17 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/52103 )


Change subject: sim: Create a StubWorkload for System.workload to default  
to.

..

sim: Create a StubWorkload for System.workload to default to.

This way there will always be a workload object, even if nothing needs
to be set up. This default can also be used in low_power_sweep.py,
where the workload object was just a placeholder.

This will allow required functionality like determining endianness of a
system into the workload, rather than (for instance) in the more generic
System object. This also makes accessing less essential functionality
simpler, because we don't have to detect whether the workload is there,
and can just return default, placeholder values from the StubWorkload.

Change-Id: Idfc3e75c65318d75a3eae6a19944ae1f79a2d111
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52103
Reviewed-by: Gabe Black 
Maintainer: Gabe Black 
Tested-by: kokoro 
---
M src/sim/workload.hh
M src/sim/system.cc
M src/sim/System.py
M configs/dram/low_power_sweep.py
M src/sim/Workload.py
5 files changed, 63 insertions(+), 13 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/configs/dram/low_power_sweep.py  
b/configs/dram/low_power_sweep.py

index c21a180..db02a06 100644
--- a/configs/dram/low_power_sweep.py
+++ b/configs/dram/low_power_sweep.py
@@ -90,8 +90,6 @@
voltage_domain =
VoltageDomain(voltage = '1V'))

-system.workload = SEWorkload()
-
 # We are fine with 256 MB memory for now.
 mem_range = AddrRange('256MB')
 # Start address is 0
diff --git a/src/sim/System.py b/src/sim/System.py
index d7b88b0..115fb94 100644
--- a/src/sim/System.py
+++ b/src/sim/System.py
@@ -44,6 +44,7 @@

 from m5.objects.DVFSHandler import *
 from m5.objects.SimpleMemory import *
+from m5.objects.Workload import StubWorkload

 class MemoryMode(Enum): vals = ['invalid', 'atomic', 'timing',
 'atomic_noncaching']
@@ -117,7 +118,7 @@
 work_cpus_ckpt_count = Param.Counter(0,
 "create checkpoint when active cpu count value is reached")

-workload = Param.Workload(NULL, "Workload to run on this system")
+workload = Param.Workload(StubWorkload(), "Workload to run on this  
system")

 init_param = Param.UInt64(0, "numerical value to pass into simulator")
 readfile = Param.String("", "file to read startup script from")
 symbolfile = Param.String("", "file to get the symbols from")
diff --git a/src/sim/Workload.py b/src/sim/Workload.py
index 74d2306..8d63164 100644
--- a/src/sim/Workload.py
+++ b/src/sim/Workload.py
@@ -37,6 +37,13 @@
 wait_for_remote_gdb = Param.Bool(False,
 "Wait for a remote GDB connection");

+class StubWorkload(Workload):
+type = 'StubWorkload'
+cxx_header = "sim/workload.hh"
+cxx_class = 'gem5::StubWorkload'
+
+entry = Param.Addr(0, 'Dummy entry point for this workload.')
+
 class KernelWorkload(Workload):
 type = 'KernelWorkload'
 cxx_header = "sim/kernel_workload.hh"
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 14e6a78..86ba3be 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -96,9 +96,7 @@
 System::Threads::Thread::quiesce() const
 {
 context->suspend();
-auto *workload = context->getSystemPtr()->workload;
-if (workload)
-workload->recordQuiesce();
+context->getSystemPtr()->workload->recordQuiesce();
 }

 void
@@ -217,8 +215,9 @@
  AddrRange(1, 0)), // Create an empty range if disabled
   redirectPaths(p.redirect_paths)
 {
-if (workload)
-workload->setSystem(this);
+panic_if(!workload, "No workload set for system %s "
+"(could use StubWorkload?).", name());
+workload->setSystem(this);

 // add self to global system list
 systemList.push_back(this);
@@ -277,8 +276,7 @@
 {
 threads.insert(tc, assigned);

-if (workload)
-workload->registerThreadContext(tc);
+workload->registerThreadContext(tc);

 for (auto *e: liveEvents)
 tc->schedule(e);
@@ -310,8 +308,7 @@
 auto *otc = threads[context_id];
 threads.replace(tc, context_id);

-if (workload)
-workload->replaceThreadContext(tc);
+workload->replaceThreadContext(tc);

 for (auto *e: liveEvents) {
 otc->remove(e);
@@ -454,7 +451,7 @@
 bool
 System::trapToGdb(int signal, ContextID ctx_id) const
 {
-return workload && workload->trapToGdb(signal, ctx_id);
+return workload->trapToGdb(signal, ctx_id);
 }

 void
diff --git a/src/sim/workload.hh b/src/sim/workload.hh
index fa62555..c09c56c 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -33,6 +33,7 @@

 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
+#include 

[gem5-dev] Change in gem5/gem5[develop]: sim: Create a StubWorkload for System.workload to default to.

2021-10-27 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/52103 )



Change subject: sim: Create a StubWorkload for System.workload to default  
to.

..

sim: Create a StubWorkload for System.workload to default to.

This way there will always be a workload object, even if nothing needs
to be set up. This default can also be used in low_power_sweep.py,
where the workload object was just a placeholder.

Change-Id: Idfc3e75c65318d75a3eae6a19944ae1f79a2d111
---
M src/sim/workload.hh
M src/sim/system.cc
M src/sim/System.py
M configs/dram/low_power_sweep.py
M src/sim/Workload.py
5 files changed, 55 insertions(+), 13 deletions(-)



diff --git a/configs/dram/low_power_sweep.py  
b/configs/dram/low_power_sweep.py

index c21a180..db02a06 100644
--- a/configs/dram/low_power_sweep.py
+++ b/configs/dram/low_power_sweep.py
@@ -90,8 +90,6 @@
voltage_domain =
VoltageDomain(voltage = '1V'))

-system.workload = SEWorkload()
-
 # We are fine with 256 MB memory for now.
 mem_range = AddrRange('256MB')
 # Start address is 0
diff --git a/src/sim/System.py b/src/sim/System.py
index d7b88b0..115fb94 100644
--- a/src/sim/System.py
+++ b/src/sim/System.py
@@ -44,6 +44,7 @@

 from m5.objects.DVFSHandler import *
 from m5.objects.SimpleMemory import *
+from m5.objects.Workload import StubWorkload

 class MemoryMode(Enum): vals = ['invalid', 'atomic', 'timing',
 'atomic_noncaching']
@@ -117,7 +118,7 @@
 work_cpus_ckpt_count = Param.Counter(0,
 "create checkpoint when active cpu count value is reached")

-workload = Param.Workload(NULL, "Workload to run on this system")
+workload = Param.Workload(StubWorkload(), "Workload to run on this  
system")

 init_param = Param.UInt64(0, "numerical value to pass into simulator")
 readfile = Param.String("", "file to read startup script from")
 symbolfile = Param.String("", "file to get the symbols from")
diff --git a/src/sim/Workload.py b/src/sim/Workload.py
index 62aa047..92ed7c3 100644
--- a/src/sim/Workload.py
+++ b/src/sim/Workload.py
@@ -37,6 +37,15 @@
 wait_for_remote_gdb = Param.Bool(False,
 "Wait for a remote GDB connection");

+class StubWorkload(Workload):
+type = 'StubWorkload'
+cxx_header = "sim/workload.hh"
+cxx_class = 'gem5::StubWorkload'
+
+entry = Param.Addr(0, 'Dummy entry point for this workload.')
+byte_order = Param.ByteOrder('little',
+'Dummy byte order for this workload.')
+
 class KernelWorkload(Workload):
 type = 'KernelWorkload'
 cxx_header = "sim/kernel_workload.hh"
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 14e6a78..5ebf0f4 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -96,9 +96,7 @@
 System::Threads::Thread::quiesce() const
 {
 context->suspend();
-auto *workload = context->getSystemPtr()->workload;
-if (workload)
-workload->recordQuiesce();
+context->getSystemPtr()->workload->recordQuiesce();
 }

 void
@@ -217,8 +215,8 @@
  AddrRange(1, 0)), // Create an empty range if disabled
   redirectPaths(p.redirect_paths)
 {
-if (workload)
-workload->setSystem(this);
+panic_if(!workload, "No workload set for system %s.", name());
+workload->setSystem(this);

 // add self to global system list
 systemList.push_back(this);
@@ -277,8 +275,7 @@
 {
 threads.insert(tc, assigned);

-if (workload)
-workload->registerThreadContext(tc);
+workload->registerThreadContext(tc);

 for (auto *e: liveEvents)
 tc->schedule(e);
@@ -310,8 +307,7 @@
 auto *otc = threads[context_id];
 threads.replace(tc, context_id);

-if (workload)
-workload->replaceThreadContext(tc);
+workload->replaceThreadContext(tc);

 for (auto *e: liveEvents) {
 otc->remove(e);
@@ -454,7 +450,7 @@
 bool
 System::trapToGdb(int signal, ContextID ctx_id) const
 {
-return workload && workload->trapToGdb(signal, ctx_id);
+return workload->trapToGdb(signal, ctx_id);
 }

 void
diff --git a/src/sim/workload.hh b/src/sim/workload.hh
index fa62555..a57b6c1 100644
--- a/src/sim/workload.hh
+++ b/src/sim/workload.hh
@@ -33,6 +33,7 @@

 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
+#include "params/StubWorkload.hh"
 #include "params/Workload.hh"
 #include "sim/sim_object.hh"
 #include "sim/stats.hh"
@@ -159,6 +160,30 @@
 /** @} */
 };

+class StubWorkload : public Workload
+{
+  private:
+PARAMS(StubWorkload);
+loader::SymbolTable _symtab;
+
+  public:
+StubWorkload(const StubWorkloadParams ) : Workload(params) {}
+
+Addr getEntry() const override { return params().entry; }
+ByteOrder byteOrder() const override { return params().byte_order; }
+loader::Arch getArch() const override { return loader::UnknownArch; }