stdlib,tests: Add BaseCPUProcessor to stdlib

The BaseCPUProcessor is processor containing BaseCPUCores. This gives
gem5 stdlib users a way to create processors containing BaseCPU
SimObjects. While SimpleProcessor does this by-proxy (the user simply
specifies the desires CPUType and ISA and the correct BaseCPU
instantiation is chosen), this new Processor allows a more raw passing
of BaseCPU objects.

The SimpleProcessor now inherrits from this BaseCPUProcessor to avoid
duplcation of functionality. A refactor to achieve this was moving the
setting of the board's memory mode from the SimpleProcessor's
"incorporate_processor" function to the BaseCPUProcessor's then altering
it to determine MemMode based on BaseCPU subclass rather than the
CPUType.

The tests/gem5/configs/simple_binary_run.py test script has been
extended to create an stdlib run with a BaseCPUProcessor instead of the
SimpleProcessor and tests have been included to ensure the
BaseCPUProcessor functions as intended.

Multiple cores comprising of different BaseCPU types has not been tested
and is not officially supported as of this commit.

Change-Id: I229943ab98ece39646f1b4feb909250bb5c61772
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62353
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
Bobby R. Bruce
2022-08-12 14:19:34 -07:00
committed by Bobby Bruce
parent 5e281c969b
commit 3238822e9e
5 changed files with 215 additions and 59 deletions

View File

@@ -39,11 +39,17 @@ from gem5.components.memory import SingleChannelDDR3_1600
from gem5.components.boards.simple_board import SimpleBoard
from gem5.components.cachehierarchies.classic.no_cache import NoCache
from gem5.components.processors.simple_processor import SimpleProcessor
from gem5.components.processors.base_cpu_processor import BaseCPUProcessor
from gem5.components.processors.simple_core import SimpleCore
from gem5.components.boards.mem_mode import MemMode
from gem5.components.processors.cpu_types import CPUTypes
from gem5.simulate.simulator import Simulator
from gem5.isas import get_isa_from_str, get_isas_str_set
import argparse
from python.gem5.components.processors.base_cpu_core import BaseCPUCore
parser = argparse.ArgumentParser(
description="A gem5 script for running simple binaries in SE mode."
)
@@ -60,6 +66,13 @@ parser.add_argument(
"isa", type=str, choices=get_isas_str_set(), help="The ISA used"
)
parser.add_argument(
"-b",
"--base-cpu-processor",
action="store_true",
help="Use the BaseCPUProcessor instead of the SimpleProcessor.",
)
parser.add_argument(
"-r",
"--resource-directory",
@@ -82,11 +95,28 @@ args = parser.parse_args()
# Setup the system.
cache_hierarchy = NoCache()
memory = SingleChannelDDR3_1600()
processor = SimpleProcessor(
cpu_type=get_cpu_type_from_str(args.cpu),
isa=get_isa_from_str(args.isa),
num_cores=1,
)
if args.base_cpu_processor:
cores = [
BaseCPUCore(
core=SimpleCore.cpu_simobject_factory(
cpu_type=get_cpu_type_from_str(args.cpu),
isa=get_isa_from_str(args.isa),
core_id=0,
),
isa=get_isa_from_str(args.isa),
)
]
processor = BaseCPUProcessor(
cores=cores,
)
else:
processor = SimpleProcessor(
cpu_type=get_cpu_type_from_str(args.cpu),
isa=get_isa_from_str(args.isa),
num_cores=1,
)
motherboard = SimpleBoard(
clk_freq="3GHz",

View File

@@ -0,0 +1,69 @@
# Copyright (c) 2022 The Regents of the University of California
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from testlib import *
"""
These tests are designed to test the BaseCPUProcessor. It utilizes the
tests/gem5/configs/simple_binary_run.py to run a simple SE-mode simualation
with different configurations of the BaseCPUProcessor.
"""
gem5_verify_config(
name=f"BaseCPUProcessor-x86-hello",
verifiers=(),
fixtures=(),
config=joinpath(
config.base_dir, "tests", "gem5", "configs", "simple_binary_run.py"
),
config_args=["x86-hello64-static", "timing", "x86", "-b"],
valid_isas=(constants.vega_x86_tag,),
length=constants.quick_tag,
)
gem5_verify_config(
name=f"BaseCPUProcessor-riscv-hello",
verifiers=(),
fixtures=(),
config=joinpath(
config.base_dir, "tests", "gem5", "configs", "simple_binary_run.py"
),
config_args=["riscv-hello", "atomic", "riscv", "-b"],
valid_isas=(constants.riscv_tag,),
length=constants.quick_tag,
)
gem5_verify_config(
name=f"BaseCPUProcessor-arm-hello",
verifiers=(),
fixtures=(),
config=joinpath(
config.base_dir, "tests", "gem5", "configs", "simple_binary_run.py"
),
config_args=["arm-hello64-static", "o3", "arm", "-b"],
valid_isas=(constants.arm_tag,),
length=constants.quick_tag,
)