stdlib: Move Root obj creation from Simulator to Board

It makes much more sense for the Root Object to be create within the
board and passed where required. Creating it in the Simulator class is
not required.

For this to work the signuature of the `_pre_instantiate` function in
`AbstractBoard` has been updated to return the Root object.
This commit is contained in:
Bobby R. Bruce
2024-08-22 05:16:47 -07:00
parent 4b3ba1daa6
commit 4bdcb040d0
10 changed files with 46 additions and 36 deletions

View File

@@ -110,8 +110,7 @@ board.set_kernel_disk_workload(
# Begin running of the simulation. # Begin running of the simulation.
print("Running with ISA: " + processor.get_isa().name) print("Running with ISA: " + processor.get_isa().name)
print() print()
root = Root(full_system=True, system=board) root = board._pre_instantiate()
board._pre_instantiate()
m5.instantiate() m5.instantiate()
print("Beginning simulation!") print("Beginning simulation!")

View File

@@ -41,6 +41,7 @@ from m5.objects import (
ClockDomain, ClockDomain,
IOXBar, IOXBar,
Port, Port,
Root,
SrcClockDomain, SrcClockDomain,
System, System,
VoltageDomain, VoltageDomain,
@@ -391,13 +392,33 @@ class AbstractBoard:
self.get_cache_hierarchy()._post_instantiate() self.get_cache_hierarchy()._post_instantiate()
self.get_memory()._post_instantiate() self.get_memory()._post_instantiate()
def _pre_instantiate(self): def _pre_instantiate(self, full_system: Optional[bool] = None) -> Root:
"""To be called immediately before ``m5.instantiate``. This is where """To be called immediately before ``m5.instantiate``. This is where
``_connect_things`` is executed by default.""" ``_connect_things`` is executed by default and the root object is Root
object is created and returned.
:param full_system: Used to pass the full system flag to the board from
the Simulator module. **Note**: This was
implemented solely to maintain backawards
compatibility with while the Simululator module's
`full_system` flag is in state of deprecation. This
parameter will be removed when it is. When this
occurs whether a simulation is to be run in FS or
SE mode will be determined by the board set."""
# Connect the memory, processor, and cache hierarchy. # Connect the memory, processor, and cache hierarchy.
self._connect_things() self._connect_things()
# Return the Root object.
return Root(
full_system=(
full_system
if full_system is not None
else self.is_fullsystem()
),
board=self,
)
def _connect_things_check(self): def _connect_things_check(self):
""" """
Here we check that connect things has been called and throw an Here we check that connect things has been called and throw an

View File

@@ -28,6 +28,7 @@ import os
from abc import ABCMeta from abc import ABCMeta
from typing import ( from typing import (
List, List,
Optional,
Sequence, Sequence,
Tuple, Tuple,
) )
@@ -327,8 +328,8 @@ class ArmBoard(ArmSystem, AbstractBoard, KernelDiskWorkload):
self.system_port = port self.system_port = port
@overrides(AbstractBoard) @overrides(AbstractBoard)
def _pre_instantiate(self): def _pre_instantiate(self, full_system: Optional[bool] = None) -> None:
super()._pre_instantiate() super()._pre_instantiate(full_system=full_system)
# Add the PCI devices. # Add the PCI devices.
self.pci_devices = self._pci_devices self.pci_devices = self._pci_devices

View File

@@ -26,7 +26,10 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os import os
from typing import List from typing import (
List,
Optional,
)
import m5 import m5
from m5.objects import ( from m5.objects import (
@@ -498,7 +501,7 @@ class RiscvBoard(AbstractSystemBoard, KernelDiskWorkload):
return "/dev/vda" return "/dev/vda"
@overrides(AbstractSystemBoard) @overrides(AbstractSystemBoard)
def _pre_instantiate(self): def _pre_instantiate(self, full_system: Optional[bool] = None):
if len(self._bootloader) > 0: if len(self._bootloader) > 0:
self.workload.bootloader_addr = 0x0 self.workload.bootloader_addr = 0x0
self.workload.bootloader_filename = self._bootloader[0] self.workload.bootloader_filename = self._bootloader[0]
@@ -507,7 +510,7 @@ class RiscvBoard(AbstractSystemBoard, KernelDiskWorkload):
else: else:
self.workload.kernel_addr = 0x0 self.workload.kernel_addr = 0x0
self.workload.entry_point = 0x80000000 self.workload.entry_point = 0x80000000
self._connect_things() super()._pre_instantiate(full_system=full_system)
@overrides(KernelDiskWorkload) @overrides(KernelDiskWorkload)
def _add_disk_to_board(self, disk_image: AbstractResource): def _add_disk_to_board(self, disk_image: AbstractResource):

View File

@@ -313,7 +313,7 @@ class RISCVMatchedBoard(
memory.set_memory_range(self.mem_ranges) memory.set_memory_range(self.mem_ranges)
@overrides(AbstractSystemBoard) @overrides(AbstractSystemBoard)
def _pre_instantiate(self): def _pre_instantiate(self, full_system: Optional[bool] = None) -> None:
if self._fs: if self._fs:
if len(self._bootloader) > 0: if len(self._bootloader) > 0:
self.workload.bootloader_addr = 0x0 self.workload.bootloader_addr = 0x0
@@ -326,7 +326,7 @@ class RISCVMatchedBoard(
self.workload.kernel_addr = 0x0 self.workload.kernel_addr = 0x0
self.workload.entry_point = 0x80000000 self.workload.entry_point = 0x80000000
self._connect_things() super()._pre_instantiate(full_system=full_system)
def generate_device_tree(self, outdir: str) -> None: def generate_device_tree(self, outdir: str) -> None:
"""Creates the ``dtb`` and ``dts`` files. """Creates the ``dtb`` and ``dts`` files.

View File

@@ -664,22 +664,12 @@ class Simulator:
if not self._instantiated: if not self._instantiated:
# Before anything else we run the AbstractBoard's # Before anything else we run the AbstractBoard's
# `_pre_instantiate` function. # `_pre_instantiate` function. This returns the root object which
self._board._pre_instantiate() # is required for instantiation.
self._root = self._board._pre_instantiate(
root = Root( full_system=self._full_system
full_system=(
self._full_system
if self._full_system is not None
else self._board.is_fullsystem()
),
board=self._board,
) )
# We take a copy of the Root in case it's required elsewhere
# (for example, in `get_stats()`).
self._root = root
# The following is a bit of a hack. If a simulation is to use a KVM # The following is a bit of a hack. If a simulation is to use a KVM
# core then the `sim_quantum` value must be set. However, in the # core then the `sim_quantum` value must be set. However, in the
# case of using a SwitchableProcessor the KVM cores may be # case of using a SwitchableProcessor the KVM cores may be

View File

@@ -207,15 +207,15 @@ print("Running with ISA: " + processor.get_isa().name)
print("Running with protocol: " + get_runtime_coherence_protocol().name) print("Running with protocol: " + get_runtime_coherence_protocol().name)
print() print()
root = Root(full_system=True, system=motherboard) # Disable the gdb ports. Required for forking.
m5.disableAllListeners()
root = motherboard._pre_instantiate()
# TODO: This of annoying. Is there a way to fix this to happen # TODO: This of annoying. Is there a way to fix this to happen
# automatically when running KVM? # automatically when running KVM?
root.sim_quantum = int(1e9) root.sim_quantum = int(1e9)
# Disable the gdb ports. Required for forking.
m5.disableAllListeners()
motherboard._pre_instantiate()
m5.instantiate() m5.instantiate()
# Simulate the inital boot with the starting KVM cpu # Simulate the inital boot with the starting KVM cpu

View File

@@ -83,9 +83,8 @@ motherboard = TestBoard(
memory=memory, memory=memory,
cache_hierarchy=cache_hierarchy, cache_hierarchy=cache_hierarchy,
) )
root = Root(full_system=False, system=motherboard)
motherboard._pre_instantiate() root = motherboard._pre_instantiate()
m5.instantiate() m5.instantiate()
generator.start_traffic() generator.start_traffic()

View File

@@ -83,9 +83,8 @@ motherboard = TestBoard(
memory=memory, memory=memory,
cache_hierarchy=cache_hierarchy, cache_hierarchy=cache_hierarchy,
) )
root = Root(full_system=False, system=motherboard)
motherboard._pre_instantiate() root = motherboard._pre_instantiate()
m5.instantiate() m5.instantiate()
generator.start_traffic() generator.start_traffic()

View File

@@ -202,9 +202,7 @@ motherboard = TestBoard(
cache_hierarchy=cache_hierarchy, cache_hierarchy=cache_hierarchy,
) )
root = Root(full_system=False, system=motherboard) root = motherboard._pre_instantiate()
motherboard._pre_instantiate()
m5.instantiate() m5.instantiate()
generator.start_traffic() generator.start_traffic()