stdlib, configs: stdlib SimPoints support and example scripts

simpoints-se-checkpoint.py & simpoints-se-restore.py:
These are two example scripts to show how to use SimPoints functions with
the stdlib.

se_binary_workload.py:
Allow se_binary_workload to take in SimPoint Class item and schedule
SimPoint exit events.

exit_event.py:
Added SIMPOINT_BEGIN and MAX_INSTS exit events.

simulator.py:
Added SIMPOINT_BEGIN and MAX_INSTS exit event scheduling functions.
They can schedule exit events before or during the simulation.

Jira Issue: https://gem5.atlassian.net/browse/GEM5-1259

Change-Id: Iaa07a83de9dddc293b9f1a230aba8e35d4f5af6c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63154
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
Zhantong Qiu
2022-09-02 15:51:29 -07:00
parent f08a4d2dc5
commit 07b693a186
5 changed files with 329 additions and 0 deletions

View File

@@ -26,10 +26,12 @@
from .abstract_board import AbstractBoard
from ...resources.resource import AbstractResource
from gem5.utils.simpoint import SimPoint
from m5.objects import SEWorkload, Process
from typing import Optional, List
from m5.util import warn
class SEBinaryWorkload:
@@ -52,6 +54,7 @@ class SEBinaryWorkload:
exit_on_work_items: bool = True,
stdin_file: Optional[AbstractResource] = None,
arguments: List[str] = [],
simpoint: SimPoint = None,
) -> None:
"""Set up the system to run a specific binary.
@@ -60,11 +63,16 @@ class SEBinaryWorkload:
* Dynamically linked executables are partially supported when the host
ISA and the simulated ISA are the same.
**Warning:** SimPoints only works with one core
:param binary: The resource encapsulating the binary to be run.
:param exit_on_work_items: Whether the simulation should exit on work
items. True by default.
:param stdin_file: The input file for the binary
:param arguments: The input arguments for the binary
:param simpoint: The SimPoint object that contains the list of
SimPoints starting instructions, the list of weights, and the SimPoints
interval
"""
# We assume this this is in a multiple-inheritance setup with an
@@ -87,5 +95,12 @@ class SEBinaryWorkload:
for core in self.get_processor().get_cores():
core.set_workload(process)
if simpoint is not None:
if self.get_processor().get_num_cores() > 1:
warn("SimPoints only works with one core")
self.get_processor().get_cores()[0].set_simpoint(
inst_starts=simpoint.get_simpoint_start_insts(), init=True
)
# Set whether to exit on work items for the se_workload
self.exit_on_work_items = exit_on_work_items

View File

@@ -46,6 +46,8 @@ class ExitEvent(Enum):
USER_INTERRUPT = ( # An exit due to a user interrupt (e.g., cntr + c)
"user interupt"
)
SIMPOINT_BEGIN = "simpoint begins"
MAX_INSTS = "number of instructions reached"
@classmethod
def translate_exit_status(cls, exit_string: str) -> "ExitEvent":
@@ -81,6 +83,10 @@ class ExitEvent(Enum):
return ExitEvent.CHECKPOINT
elif exit_string == "user interrupt received":
return ExitEvent.USER_INTERRUPT
elif exit_string == "simpoint starting point found":
return ExitEvent.SIMPOINT_BEGIN
elif exit_string == "a thread reached the max instruction count":
return ExitEvent.MAX_INSTS
raise NotImplementedError(
"Exit event '{}' not implemented".format(exit_string)
)

View File

@@ -41,6 +41,7 @@ from .exit_event_generators import (
default_switch_generator,
default_workbegin_generator,
default_workend_generator,
default_simpoint_generator,
)
from .exit_event import ExitEvent
from ..components.boards.abstract_board import AbstractBoard
@@ -179,6 +180,8 @@ class Simulator:
ExitEvent.WORKEND: default_workend_generator(),
ExitEvent.USER_INTERRUPT: default_exit_generator(),
ExitEvent.MAX_TICK: default_exit_generator(),
ExitEvent.SIMPOINT_BEGIN: default_simpoint_generator(),
ExitEvent.MAX_INSTS: default_simpoint_generator(),
}
if on_exit_event:
@@ -197,6 +200,40 @@ class Simulator:
self._checkpoint_path = checkpoint_path
def schedule_simpoint(
self, simpoint_start_insts: List[int], schedule_at_init: bool = False
) -> None:
"""
Schedule SIMPOINT_BEGIN exit events
**Warning:** SimPoints only work with one core
:param simpoint_start_insts: a list of number of instructions
indicating the starting point of the simpoints
:param schedule_at_init: if it is True, schedule the events in the init
stage of the core, else, schedule the events during the simulation
"""
if self._board.get_processor().get_num_cores() > 1:
warn("SimPoints only work with one core")
self._board.get_processor().get_cores()[0].set_simpoint(
simpoint_start_insts, schedule_at_init
)
def schedule_max_insts(
self, inst: int, schedule_at_init: bool = False
) -> None:
"""
Schedule a MAX_INSTS exit event when any thread in the current 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
"""
self._board.get_processor().get_cores()[0].set_inst_stop_any_thread(
inst, schedule_at_init
)
def get_stats(self) -> Dict:
"""
Obtain the current simulation statistics as a Dictionary, conforming