From c88b528738f5dc9217d900b90b71855db7f8db77 Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Wed, 19 Oct 2022 14:12:44 -0700 Subject: [PATCH] stdlib: Update AbstractCore's 'set_inst_stop_any_thread' This patch: - Makes this function private. - Updates the function's documentation. - Changes the 'init' parameter to 'board_initialized'. It doesn't make much sense for this function to be exposed directly to the user as it requires knowing whether the board is initialized or not. In addition to this I believe it makes more sense for the 'init' logic to be flipped and renamed "board_initialized' so that this value is True if the board has been initialized. The documentation for this function has been updated. Change-Id: I016c65bde88357111d3e648d7aa99aeb6e31f410 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/64833 Maintainer: Bobby Bruce Reviewed-by: Bobby Bruce Tested-by: kokoro --- .../checkpoints/simpoints-se-restore.py | 2 +- .../gem5/components/processors/abstract_core.py | 13 ++++++++----- .../gem5/components/processors/base_cpu_core.py | 10 ++++++---- src/python/gem5/simulate/simulator.py | 17 ++++++----------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/configs/example/gem5_library/checkpoints/simpoints-se-restore.py b/configs/example/gem5_library/checkpoints/simpoints-se-restore.py index b529672981..f8f48d0ec1 100644 --- a/configs/example/gem5_library/checkpoints/simpoints-se-restore.py +++ b/configs/example/gem5_library/checkpoints/simpoints-se-restore.py @@ -132,5 +132,5 @@ simulator = Simulator( # is greater than 0. # In here, it schedules an exit event for the first SimPoint's warmup # instructions -simulator.schedule_max_insts(board.get_simpoint().get_warmup_list()[0], True) +simulator.schedule_max_insts(board.get_simpoint().get_warmup_list()[0]) simulator.run() diff --git a/src/python/gem5/components/processors/abstract_core.py b/src/python/gem5/components/processors/abstract_core.py index ea2875eabf..58296bca3b 100644 --- a/src/python/gem5/components/processors/abstract_core.py +++ b/src/python/gem5/components/processors/abstract_core.py @@ -140,15 +140,18 @@ class AbstractCore(SubSystem): raise NotImplementedError("This core type does not support simpoints") @abstractmethod - def set_inst_stop_any_thread(self, inst: int, init: bool) -> None: + def _set_inst_stop_any_thread( + self, inst: int, board_initialized: bool + ) -> None: """Schedule an exit event when any thread in this core reaches the - given number of instructions. + given number of instructions. This is called through the simulator + module and should not be called directly. This is used to raise MAX_INSTS exit event in the gem5 standard library :param inst: a number of instructions - :param init: if it is True, the exit event will be scheduled at the - init stage of the core, else, it will be scheduled during the - simulation + :param board_initialized: True if the board has already been + initialized, otherwise False. This parameter is necessary as the + instruction stop is setup differently dependent on this. """ raise NotImplementedError("This core type does not support MAX_INSTS") diff --git a/src/python/gem5/components/processors/base_cpu_core.py b/src/python/gem5/components/processors/base_cpu_core.py index 535a80000c..631fd0ad0e 100644 --- a/src/python/gem5/components/processors/base_cpu_core.py +++ b/src/python/gem5/components/processors/base_cpu_core.py @@ -162,8 +162,10 @@ class BaseCPUCore(AbstractCore): self.core.simpoint_start_insts = sorted(set(inst_starts)) @overrides(AbstractCore) - def set_inst_stop_any_thread(self, inst: int, init: bool) -> None: - if init: - self.core.max_insts_any_thread = inst - else: + def _set_inst_stop_any_thread( + self, inst: int, board_initialized: bool + ) -> None: + if board_initialized: self.core.scheduleInstStopAnyThread(inst) + else: + self.core.max_insts_any_thread = inst diff --git a/src/python/gem5/simulate/simulator.py b/src/python/gem5/simulate/simulator.py index d7e214191b..0d2917d755 100644 --- a/src/python/gem5/simulate/simulator.py +++ b/src/python/gem5/simulate/simulator.py @@ -251,20 +251,15 @@ class Simulator: simpoint_start_insts, self._instantiated ) - def schedule_max_insts( - self, inst: int, schedule_at_init: bool = False - ) -> None: + def schedule_max_insts(self, inst: int) -> None: """ - Schedule a MAX_INSTS exit event when any thread in the current core - reaches the given number of instructions + Schedule a MAX_INSTS exit event when any thread in any core reaches the + given number of instructions. - :param insts: a number of instructions - :param schedule_at_init: if it is True, schedule the event in the init - stage of the core, else, schedule the event during the simulation + :param insts: a number of instructions to run to. """ - self._board.get_processor().get_cores()[0].set_inst_stop_any_thread( - inst, schedule_at_init - ) + for core in self._board.get_processor().get_cores(): + core._set_inst_stop_any_thread(inst, self._instantiated) def get_stats(self) -> Dict: """