Hello Jason Lowe-Power,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/4001
to review the following change.
Change subject: cpu, config: Add setMainCPU to BaseCPU
..
cpu, config: Add setMainCPU to BaseCPU
To facilitate taking over from a CPU in the future, force users to first
call setMainCPU before gem5 instantiation. This allows us to be sure the
CPU instantiation that is taking over from the "main" CPU has pointers to
the right objects.
Change-Id: I3a3c39a46380e32e2cb18dc8e8304bbc3716f723
Signed-off-by: Jason Lowe-Power
Signed-off-by: Sean Wilson
---
M configs/common/Simulation.py
M configs/example/apu_se.py
M src/cpu/BaseCPU.py
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/configs/common/Simulation.py b/configs/common/Simulation.py
index c4d5c96..3c74e00 100644
--- a/configs/common/Simulation.py
+++ b/configs/common/Simulation.py
@@ -453,7 +453,7 @@
testsys.cpu[i].max_insts_any_thread = options.maxinsts
if cpu_class:
-switch_cpus = [cpu_class(switched_out=True, cpu_id=(i))
+switch_cpus = [cpu_class(main_cpu=testsys.cpu[i])
for i in xrange(np)]
for i in xrange(np):
@@ -489,8 +489,8 @@
print "%s: CPU switching not supported" % str(switch_class)
sys.exit(1)
-repeat_switch_cpus = [switch_class(switched_out=True, \
- cpu_id=(i)) for i in
xrange(np)]
+repeat_switch_cpus = [switch_class(main_cpu=testsys.cpu[i])
+ for i in xrange(np)]
for i in xrange(np):
repeat_switch_cpus[i].system = testsys
@@ -513,9 +513,9 @@
for i in xrange(np)]
if options.standard_switch:
-switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i))
+switch_cpus = [TimingSimpleCPU(main_cpu=testsys.cpu[i])
for i in xrange(np)]
-switch_cpus_1 = [DerivO3CPU(switched_out=True, cpu_id=(i))
+switch_cpus_1 = [DerivO3CPU(main_cpu=testsys.cpu[i])
for i in xrange(np)]
for i in xrange(np):
diff --git a/configs/example/apu_se.py b/configs/example/apu_se.py
index f93442d..aaafd88 100644
--- a/configs/example/apu_se.py
+++ b/configs/example/apu_se.py
@@ -344,7 +344,6 @@
voltage_domain = VoltageDomain(
voltage = options.cpu_voltage)))
if fast_forward:
-cpu.switched_out = True
future_cpu_list.append(cpu)
else:
cpu_list.append(cpu)
@@ -405,8 +404,10 @@
## Create the overall system
# List of CPUs that must be switched when moving between KVM and simulation
if fast_forward:
-switch_cpu_list = \
-[(cpu_list[i], future_cpu_list[i]) for i in
xrange(options.num_cpus)]
+switch_cpu_list = zip(cpu_list, future_cpu_list)
+for (start_cpu, future_cpu) in switch_cpu_list:
+future_cpu.setMainCPU(start_cpu)
+
# Full list of processing cores in the system. Note that
# dispatcher is also added to cpu_list although it is
diff --git a/src/cpu/BaseCPU.py b/src/cpu/BaseCPU.py
index 550ba62..bef195a 100644
--- a/src/cpu/BaseCPU.py
+++ b/src/cpu/BaseCPU.py
@@ -47,6 +47,7 @@
from m5.defines import buildEnv
from m5.params import *
from m5.proxy import *
+from m5.util import panic
from XBar import L2XBar
from InstTracer import InstTracer
@@ -97,6 +98,12 @@
abstract = True
cxx_header = "cpu/base.hh"
+def __init__(self, main_cpu=None, **kwargs):
+self._readyToTakeOver = False
+super(BaseCPU, self).__init__(**kwargs)
+if main_cpu:
+self.setMainCPU(main_cpu)
+
cxx_exports = [
PyBindMethod("switchOut"),
PyBindMethod("takeOverFrom"),
@@ -127,7 +134,21 @@
"""Does the CPU model support CPU takeOverFrom?"""
return False
+def setMainCPU(self, other_cpu):
+"""This CPU will take over from the other_cpu at some point in the
+ future. This function *must* be called before taking over from
+ another CPU. Sets this CPU to switched out and replaces this
CPUs
+ TLBs with the other_cpu's. Also sets the cpu_id to the same.
+"""
+self._readyToTakeOver = True
+self.switched_out = True
+self.itb = other_cpu.itb
+self.dtb = other_cpu.dtb
+self.cpu_id = other_cpu.cpu_id
+
def takeOverFrom(self, old_cpu):
+if not self._readyToTakeOver:
+panic("Must call setMainCPU before takeOverFrom!")
self._ccObject.takeOverFrom(old_cpu._ccObject)
--
To view, visit https://gem5-review.googlesource.com/4001
To unsubscribe, visit https://gem5-review.googlesource.com/settings
Gerrit-Project: