From 7c83e3379b169f1dd6ed28ce1780602e88849ffd Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Fri, 4 Oct 2024 11:56:48 -0700 Subject: [PATCH] stdlib: Add `_pre_instantiate` funcs for caches and memory Note: At present this is not used but these functions can be filled or overriden in subclasses as required. --- .../gem5/components/boards/abstract_board.py | 4 +++- .../abstract_cache_hierarchy.py | 17 ++++++++++++++++- .../components/memory/abstract_memory_system.py | 13 +++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/python/gem5/components/boards/abstract_board.py b/src/python/gem5/components/boards/abstract_board.py index af9ff300b6..5819adc9de 100644 --- a/src/python/gem5/components/boards/abstract_board.py +++ b/src/python/gem5/components/boards/abstract_board.py @@ -420,8 +420,10 @@ class AbstractBoard: ) # 3. Call any of the components' `_pre_instantiate` functions. - # Right now, only the processor requires this. self.get_processor()._pre_instantiate(root) + self.get_memory()._pre_instantiate(root) + if self.get_cache_hierarchy(): + self.get_cache_hierarchy()._pre_instantiate(root) # 4. Return the root object. return root diff --git a/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py index b0435543af..dc20c14f70 100644 --- a/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py @@ -42,7 +42,10 @@ from abc import ( ) from typing import Callable -from m5.objects import SubSystem +from m5.objects import ( + Root, + SubSystem, +) from m5.util.fdthelper import * from ..boards.abstract_board import AbstractBoard @@ -139,6 +142,18 @@ class AbstractCacheHierarchy(SubSystem): """ raise NotImplementedError + def _pre_instantiate(self, root: Root) -> None: + """Called in the `AbstractBoard`'s `_pre_instantiate` method. This is + called after `connect_things`, after the creation of the root object + (which is passed in as an argument), but before `m5.instantiate`). + + Subclasses should override this method to set up any connections. + + At present there is no general task that must be specified here and is + default or applicable to all cache hierarchies. + """ + pass + def _post_instantiate(self): """Called to set up anything needed after ``m5.instantiate``.""" pass diff --git a/src/python/gem5/components/memory/abstract_memory_system.py b/src/python/gem5/components/memory/abstract_memory_system.py index 06fa60cad8..6d24e724b6 100644 --- a/src/python/gem5/components/memory/abstract_memory_system.py +++ b/src/python/gem5/components/memory/abstract_memory_system.py @@ -38,6 +38,7 @@ from m5.objects import ( AddrRange, MemCtrl, Port, + Root, SubSystem, ) @@ -50,6 +51,18 @@ class AbstractMemorySystem(SubSystem): def __init__(self) -> None: super().__init__() + def _pre_instantiate(self, root: Root) -> None: + """Called in the `AbstractBoard`'s `_pre_instantiate` method. This is + called after `connect_things`, after the creation of the root object + (which is passed in as an argument), but before `m5.instantiate`). + + Subclasses should override this method to set up any connections. + + At present there is no general task that must be specified here and is + default or applicable to all memory systems. + """ + pass + @abstractmethod def incorporate_memory(self, board: AbstractBoard) -> None: """This function completes all of the necessary steps to add this