mem-ruby,scons: Add scons option for multiple protocols

This change does many things, but they must all be atomically done.

**USER FACING CHANGE**: The Ruby protocols in Kconfig have changed names
(they are now the same case as the SLICC file names). So, after this
commit, your build configurations need to be updated. You can do so by
running `scons menuconfig <build dir>` and selecting the right ruby
options. Alternatively, if you're using a `build_opts` file, you can run
`scons defconfig build/<ISA> build_opts/<ISA>` which should update your
config correctly.

Detailed changes are described below.

Kconfig changes:

- Kconfig files in ruby now must all be declared in the ruby/Kconfig
  file
- All of the protocol names are changed to match their slicc file names
  including the case
- A new option is available called "Use multiple protocols" which should
  be selected if multiple protocols are selected. This is only used to
  set the PROTOCOL variable to "MULTIPLE" when in multiple mode.
- The PROTOCOL variable can now be "MULTIPLE" which means it will be
  ignored. If it's not "MULTIPLE" then it holds the "main" protocol,
  which is necessary for backwards compatibility with the Ruby.py files.

Ruby config changes:

To make this change backwards compatible with Ruby.py, this change adds
a new "protocol" config called MULTIPLE.py which is used to allow the
user to set a "--protocol" option on the command line. This is only
needed if you are using a gem5 binary with multiple protocols but need
to use Ruby.py.

stdlib changes:

- Make the coherence protocol file behave like the ISA file
- Add a function to get the coherence protocol from the `CacheHierarchy`
  like we do with the ISA in the `Processor`.
  - Use this function where `get_runtime_coherence_protocol` was used
- Update the requires code to work with the ne CoherenceProtocol
- Fix a typo in the AMD Hammer name and also add the missing MSI
  protocol

Scons changes:

- In Ruby we now gather up all of the protocols and build them all if
  there are multiple protocols
- There's some bending over backwards to tell the user if they are using
  an out of date gem5.build/config file and how to update it
- Note that multiple ruby protocols adds a significant amount of time to
  the build since we have to run slicc twice for each file.

build_opts:

- Update all files with new names
- Add a new NULL_All_Ruby that will be used for testing

Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
Jason Lowe-Power
2024-10-25 16:28:46 -07:00
committed by Bobby R. Bruce
parent 9a904478eb
commit 97542c1a4c
45 changed files with 344 additions and 138 deletions

View File

@@ -15,7 +15,8 @@ The most notable changes are:
* Removes the RubySlicc_interfaces.slicc file from the SLICC includes of
every protocol.
* Changes required: If you have a custom protocol, you will need to remove the line `include "RubySlicc_interfaces.slicc"` from your .slicc file.
* Updates the build configurations variables
* **USER FACING CHANGE**: The Ruby protocols in Kconfig have changed names (they are now the same case as the SLICC file names). So, after this commit, your build configurations need to be updated. You can do so by running `scons menuconfig <build dir>` and selecting the right ruby options. Alternatively, if you're using a `build_opts` file, you can run `scons defconfig build/<ISA> build_opts/<ISA>` which should update your config correctly.
* The [behavior of the statistics `simInsts` and `simOps` has been changed](https://github.com/gem5/gem5/pull/1615).
* They now reset to zero when m5.stats.reset() is called.
* Previously, they incorrectly did not reset and would increase monotonically throughout the simulation.

View File

@@ -1,5 +1,6 @@
RUBY=y
RUBY_PROTOCOL_MESI_TWO_LEVEL=y
PROTOCOL="MESI_Two_Level"
RUBY_PROTOCOL_MESI_Two_Level=y
BUILD_ISA=y
USE_ARM_ISA=y
USE_MIPS_ISA=y

View File

@@ -1,4 +1,5 @@
BUILD_ISA=y
USE_ARM_ISA=y
RUBY=y
PROTOCOL="CHI"
RUBY_PROTOCOL_CHI=y

View File

@@ -1,4 +1,5 @@
BUILD_ISA=y
USE_ARM_ISA=y
RUBY=y
RUBY_PROTOCOL_MESI_THREE_LEVEL=y
PROTOCOL="MESI_Three_Level"
RUBY_PROTOCOL_MESI_Three_Level=y

View File

@@ -1,4 +1,5 @@
BUILD_ISA=y
USE_ARM_ISA=y
RUBY=y
RUBY_PROTOCOL_MESI_THREE_LEVEL_HTM=y
PROTOCOL="MESI_Three_Level_HTM"
RUBY_PROTOCOL_MESI_Three_Level_HTM=y

View File

@@ -1,4 +1,5 @@
BUILD_ISA=y
USE_ARM_ISA=y
RUBY=y
RUBY_PROTOCOL_MOESI_HAMMER=y
PROTOCOL="MOESI_hammer"
RUBY_PROTOCOL_MOESI_hammer=y

View File

@@ -1,2 +1,3 @@
RUBY=y
RUBY_PROTOCOL_GARNET_STANDALONE=y
PROTOCOL="Garnet_standalone"
RUBY_PROTOCOL_Garnet_standalone=y

View File

@@ -1,4 +1,5 @@
RUBY=y
RUBY_PROTOCOL_MI_EXAMPLE=y
PROTOCOL="MI_example"
RUBY_PROTOCOL_MI_example=y
BUILD_ISA=y
USE_MIPS_ISA=y

View File

@@ -1,2 +1,3 @@
RUBY=y
RUBY_PROTOCOL_MI_EXAMPLE=y
PROTOCOL="MI_example"
RUBY_PROTOCOL_MI_example=y

14
build_opts/NULL_All_Ruby Normal file
View File

@@ -0,0 +1,14 @@
RUBY=y
USE_MULTIPLE_PROTOCOLS=y
PROTOCOL="MULTIPLE"
RUBY_PROTOCOL_MOESI_AMD_Base=y
RUBY_PROTOCOL_MESI_Two_Level=y
RUBY_PROTOCOL_MESI_Three_Level=y
RUBY_PROTOCOL_MESI_Three_Level_HTM=y
RUBY_PROTOCOL_MI_example=y
RUBY_PROTOCOL_MOESI_CMP_directory=y
RUBY_PROTOCOL_MOESI_CMP_token=y
RUBY_PROTOCOL_MOESI_hammer=y
RUBY_PROTOCOL_Garnet_standalone=y
RUBY_PROTOCOL_CHI=y
RUBY_PROTOCOL_MSI=y

View File

@@ -1,2 +1,3 @@
RUBY=y
RUBY_PROTOCOL_MESI_TWO_LEVEL=y
PROTOCOL="MESI_Two_Level"
RUBY_PROTOCOL_MESI_Two_Level=y

View File

@@ -1,2 +1,3 @@
RUBY=y
RUBY_PROTOCOL_MOESI_CMP_DIRECTORY=y
PROTOCOL="MOESI_CMP_directory"
RUBY_PROTOCOL_MOESI_CMP_directory=y

View File

@@ -1,2 +1,3 @@
RUBY=y
RUBY_PROTOCOL_MOESI_CMP_TOKEN=y
PROTOCOL="MOESI_CMP_token"
RUBY_PROTOCOL_MOESI_CMP_token=y

View File

@@ -1,2 +1,3 @@
RUBY=y
RUBY_PROTOCOL_MOESI_HAMMER=y
PROTOCOL="MOESI_hammer"
RUBY_PROTOCOL_MOESI_hammer=y

View File

@@ -1,4 +1,5 @@
RUBY=y
RUBY_PROTOCOL_MI_EXAMPLE=y
PROTOCOL="MI_example"
RUBY_PROTOCOL_MI_example=y
BUILD_ISA=y
USE_POWER_ISA=y

View File

@@ -1,4 +1,5 @@
RUBY=y
RUBY_PROTOCOL_MI_EXAMPLE=y
PROTOCOL="MI_example"
RUBY_PROTOCOL_MI_example=y
BUILD_ISA=y
USE_RISCV_ISA=y

View File

@@ -1,4 +1,5 @@
RUBY=y
RUBY_PROTOCOL_MI_EXAMPLE=y
PROTOCOL="MI_example"
RUBY_PROTOCOL_MI_example=y
BUILD_ISA=y
USE_SPARC_ISA=y

View File

@@ -1,5 +1,6 @@
RUBY=y
NUMBER_BITS_PER_SET=128
PROTOCOL="GPU_VIPER"
RUBY_PROTOCOL_GPU_VIPER=y
BUILD_ISA=y
USE_X86_ISA=y

View File

@@ -1,5 +1,6 @@
RUBY=y
NUMBER_BITS_PER_SET=128
RUBY_PROTOCOL_MESI_TWO_LEVEL=y
PROTOCOL="MESI_Two_Level"
RUBY_PROTOCOL_MESI_Two_Level=y
BUILD_ISA=y
USE_X86_ISA=y

View File

@@ -1,5 +1,6 @@
RUBY=y
NUMBER_BITS_PER_SET=128
RUBY_PROTOCOL_MESI_TWO_LEVEL=y
PROTOCOL="MESI_Two_Level"
RUBY_PROTOCOL_MESI_Two_Level=y
BUILD_ISA=y
USE_X86_ISA=y

View File

@@ -1,4 +1,5 @@
RUBY=y
RUBY_PROTOCOL_MI_EXAMPLE=y
PROTOCOL="MI_example"
RUBY_PROTOCOL_MI_example=y
BUILD_ISA=y
USE_X86_ISA=y

View File

@@ -1,4 +1,5 @@
RUBY=y
RUBY_PROTOCOL_MOESI_AMD_BASE=y
PROTOCOL="MOESI_AMD_Base"
RUBY_PROTOCOL_MOESI_AMD_Base=y
BUILD_ISA=y
USE_X86_ISA=y

View File

@@ -46,7 +46,7 @@ from m5.util import (
class MyCacheSystem(RubySystem):
def __init__(self):
if buildEnv["PROTOCOL"] != "MSI":
if not "RUBY_PROTOCOL_MSI" in buildEnv:
fatal("This system assumes MSI from learning gem5!")
super().__init__()

View File

@@ -48,7 +48,7 @@ from m5.util import (
class MyCacheSystem(RubySystem):
def __init__(self):
if buildEnv["PROTOCOL"] != "MI_example":
if "MI_example" not in buildEnv:
fatal("This system assumes MI_example!")
super().__init__()

89
configs/ruby/MULTIPLE.py Normal file
View File

@@ -0,0 +1,89 @@
# Copyright 2024 (c) Jason Lowe-Power
# 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.
import importlib
from m5.defines import buildEnv
def define_options(parser):
print("**************IMPORTANT*******************************")
print("This gem5 binary is configured with multiple protocols.")
print("To use this gem5 binary, you must use the standard library.")
print("The Ruby.py file is deprecated.")
print("You can use --protocol to specify the protocol you want to use.")
print("IMPORTANT: THIS WILL BE REMOVED IN THE FUTURE.")
available_protocols = [
protocol[len("RUBY_PROTOCOL_") :]
for protocol in buildEnv.keys()
if protocol.startswith("RUBY_PROTOCOL_")
]
parser.add_argument(
"--protocol",
type=str,
help="Specify the protocol you want to use.",
required=True,
choices=available_protocols,
)
# Note: we can't rely on the options yet because they haven't been parsed.
from sys import argv
found = False
for arg in argv:
if arg.startswith("--protocol"):
found = True
if "=" in arg:
protocol = arg[len("--protocol=") :]
else:
protocol = argv[argv.index(arg) + 1]
if not found:
print(
"ERROR: You must specify a protocol with --protocol <protocol>. "
"or --protocol=<protocol>"
)
exit(1)
protocol_module = importlib.import_module(f".{protocol}", package="ruby")
protocol_module.define_options(parser)
buildEnv["PROTOCOL"] = protocol
# Note: This function isn't used because buildEnv["PROTOCOL"] is set
# in define_options. However, this is here just in case.
def create_system(options, *args, **kwargs):
protocol = options.protocol
print("Using protocol: ", protocol)
print("WARNING: The Ruby.py file is deprecated.")
protocol_module = importlib.import_module(f".{protocol}", package="ruby")
(cpu_sequencers, dir_cntrls, topology) = protocol_module.create_system(
options, *args, **kwargs
)
return (cpu_sequencers, dir_cntrls, topology)

View File

@@ -44,7 +44,6 @@ config USE_EFENCE
rsource "base/Kconfig"
rsource "mem/ruby/Kconfig"
rsource "learning_gem5/part3/Kconfig"
rsource "proto/Kconfig"
rsource "dev/net/Kconfig"
rsource "arch/Kconfig"

View File

@@ -50,6 +50,7 @@ if env["CONF"]["USE_ARM_ISA"]:
#
# Note: This will need reconfigured for multi-isa. E.g., if this is
# incorporated: https://gem5-review.googlesource.com/c/public/gem5/+/52491
if env["CONF"]["USE_ARM_ISA"]:
GTest(
"aapcs64.test",
@@ -81,7 +82,7 @@ Source("insts/sve_mem.cc", tags="arm isa")
Source("insts/vfp.cc", tags="arm isa")
Source("insts/crypto.cc", tags="arm isa")
Source("insts/tme64.cc", tags="arm isa")
if env["CONF"]["PROTOCOL"] == "MESI_Three_Level_HTM":
if env["CONF"]["RUBY_PROTOCOL_MESI_Three_Level_HTM"]:
Source("insts/tme64ruby.cc", tags="arm isa")
else:
Source("insts/tme64classic.cc", tags="arm isa")

View File

@@ -23,10 +23,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
config PROTOCOL
default "MSI" if RUBY_PROTOCOL_MSI
cont_choice "Ruby protocol"
config RUBY_PROTOCOL_MSI
bool "MSI"
endchoice
config RUBY_PROTOCOL_MSI
bool "MSI"
default n

View File

@@ -28,15 +28,28 @@ menu "Ruby"
bool "Enable"
if RUBY
menu "Ruby protocols"
config USE_MULTIPLE_PROTOCOLS
bool 'Use multiple protocols'
default y
config PROTOCOL
string
string "The 'main' protocol"
default "MULTIPLE" if USE_MULTIPLE_PROTOCOLS
help
This shows up as `buildEnv["PROTOCOL"]`` for backwards
compatibility, mostly in the Ruby.py config scripts.
Otherwise, this is ignored.
If this is set to anything when build with MULTIPLE,
it will be ignored unless using Ruby.py, in which case
the protocol specified here will appear as the only protocol.
Note: This is case sensitive.
config NEED_PARTIAL_FUNC_READS
bool
rsource "protocol/Kconfig"
rsource "../../learning_gem5/part3/Kconfig"
choice "Ruby protocol"
prompt "Ruby protocol"
endchoice
endmenu
config SLICC_HTML
bool 'Create HTML files'
@@ -45,6 +58,6 @@ menu "Ruby"
int 'Max elements in set'
default 64
endif
endmenu
rsource "protocol/Kconfig"
endmenu

View File

@@ -113,7 +113,7 @@ MakeInclude('structures/PersistentTable.hh')
MakeInclude('structures/RubyPrefetcher.hh')
MakeInclude('structures/RubyPrefetcherProxy.hh')
MakeInclude('structures/TBEStorage.hh')
if env['CONF']['PROTOCOL'] == 'CHI':
if env['CONF']['RUBY_PROTOCOL_CHI']:
MakeInclude('structures/MN_TBEStorage.hh')
MakeInclude('structures/MN_TBETable.hh')
MakeInclude('structures/TBETable.hh')

View File

@@ -23,40 +23,37 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
config PROTOCOL
default "GPU_VIPER" if RUBY_PROTOCOL_GPU_VIPER
default "MOESI_AMD_Base" if RUBY_PROTOCOL_MOESI_AMD_BASE
default "MESI_Two_Level" if RUBY_PROTOCOL_MESI_TWO_LEVEL
default "MESI_Three_Level" if RUBY_PROTOCOL_MESI_THREE_LEVEL
default "MESI_Three_Level_HTM" if RUBY_PROTOCOL_MESI_THREE_LEVEL_HTM
default "MI_example" if RUBY_PROTOCOL_MI_EXAMPLE
default "MOESI_CMP_directory" if RUBY_PROTOCOL_MOESI_CMP_DIRECTORY
default "MOESI_CMP_token" if RUBY_PROTOCOL_MOESI_CMP_TOKEN
default "MOESI_hammer" if RUBY_PROTOCOL_MOESI_HAMMER
default "Garnet_standalone" if RUBY_PROTOCOL_GARNET_STANDALONE
cont_choice "Ruby protocol"
config RUBY_PROTOCOL_GPU_VIPER
bool "GPU VIPER"
depends on BUILD_GPU
config RUBY_PROTOCOL_MOESI_AMD_BASE
bool "MOESI AMD base"
config RUBY_PROTOCOL_MESI_TWO_LEVEL
bool "MESI two level"
config RUBY_PROTOCOL_MESI_THREE_LEVEL
bool "MESI three level"
config RUBY_PROTOCOL_MESI_THREE_LEVEL_HTM
bool "MESI three level HTM"
config RUBY_PROTOCOL_MI_EXAMPLE
bool "MI example"
config RUBY_PROTOCOL_MOESI_CMP_DIRECTORY
bool "MOESI CMP directory"
config RUBY_PROTOCOL_MOESI_CMP_TOKEN
bool "MOESI CMP token"
config RUBY_PROTOCOL_MOESI_HAMMER
bool "MOESI hammer"
config RUBY_PROTOCOL_GARNET_STANDALONE
bool "Garnet standalone"
endchoice
config RUBY_PROTOCOL_GPU_VIPER
bool "GPU VIPER"
depends on BUILD_GPU
default n
config RUBY_PROTOCOL_MOESI_AMD_Base
bool "MOESI AMD base"
default n
config RUBY_PROTOCOL_MESI_Two_Level
bool "MESI two level"
default n
config RUBY_PROTOCOL_MESI_Three_Level
bool "MESI three level"
default n
config RUBY_PROTOCOL_MESI_Three_Level_HTM
bool "MESI three level HTM"
default n
config RUBY_PROTOCOL_MI_example
bool "MI example"
default n
config RUBY_PROTOCOL_MOESI_CMP_directory
bool "MOESI CMP directory"
default n
config RUBY_PROTOCOL_MOESI_CMP_token
bool "MOESI CMP token"
default n
config RUBY_PROTOCOL_MOESI_hammer
bool "MOESI hammer"
default n
config RUBY_PROTOCOL_Garnet_standalone
bool "Garnet standalone"
default n
rsource "chi/Kconfig"

View File

@@ -117,8 +117,26 @@ slicc_builder = Builder(
action=MakeAction(slicc_action, Transform("SLICC")), emitter=slicc_emitter
)
protocol = env["CONF"]["PROTOCOL"]
if env["CONF"]["PROTOCOL"] != "MULTIPLE":
# Using backward compatibility
if (
f"RUBY_PROTOCOL_{env['CONF']['PROTOCOL']}" not in env["CONF"].keys()
or not env["CONF"][f"RUBY_PROTOCOL_{env['CONF']['PROTOCOL']}"]
):
raise ValueError(
"Your build config must be updated for the new multiple Ruby "
"build system. Please select the correct protocol under Ruby. "
"Deselect \"Use multiple protocols\" and select the desired "
f"protocol ({env['CONF']['PROTOCOL']})\n"
"Run the following code:\n"
f"scons menuconfig {env['BUILDDIR']}\n"
)
# Gather protocol names
protocols = []
for variable in env["CONF"]:
if variable.startswith("RUBY_PROTOCOL_") and env["CONF"][variable]:
protocols.append(variable[len("RUBY_PROTOCOL_") :])
def find_protocol_sources(protocol):
protocol_dir = None
@@ -135,7 +153,7 @@ def find_protocol_sources(protocol):
return protocol_dir.File("%s.slicc" % protocol)
sources = [find_protocol_sources(protocol)]
sources = [find_protocol_sources(protocol) for protocol in protocols]
env.Append(BUILDERS={"SLICC": slicc_builder})
nodes = env.SLICC([], sources)

View File

@@ -23,13 +23,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
config PROTOCOL
default "CHI" if RUBY_PROTOCOL_CHI
config NEED_PARTIAL_FUNC_READS
default y if RUBY_PROTOCOL_CHI
cont_choice "Ruby protocol"
config RUBY_PROTOCOL_CHI
bool "CHI"
endchoice
config RUBY_PROTOCOL_CHI
bool "CHI"
default n

View File

@@ -58,5 +58,5 @@ Source('TimerTable.cc')
Source('BankedArray.cc')
Source('ALUFreeListArray.cc')
Source('TBEStorage.cc')
if env['CONF']['PROTOCOL'] == 'CHI':
if env['CONF']['RUBY_PROTOCOL_CHI']:
Source('MN_TBETable.cc')

View File

@@ -28,18 +28,52 @@
Specifies the coherence protocol enum
"""
import os
from enum import Enum
class CoherenceProtocol(Enum):
MESI_THREE_LEVEL = 1
MESI_THREE_LEVEL_HTM = 2
ARM_MOESI_HAMMER = 3
GARNET_STANDALONE = 4
MESI_TWO_LEVEL = 5
MOESI_CMP_DIRECTORY = 6
MOESI_CMP_TOKEN = 7
MOESI_AMD_BASE = 8
MI_EXAMPLE = 9
GPU_VIPER = 10
CHI = 11
NULL = "no protocol (classic only)"
MESI_THREE_LEVEL = "MESI_Three_Level"
MESI_THREE_LEVEL_HTM = "MESI_Three_Level_HTM"
AMD_MOESI_HAMMER = "AMD_MOESI_hammer"
GARNET_STANDALONE = "Garnet_standalone"
MESI_TWO_LEVEL = "MESI_Two_Level"
MOESI_CMP_DIRECTORY = "MOESI_CMP_directory"
MOESI_CMP_TOKEN = "MOESI_CMP_token"
MOESI_AMD_BASE = "MOESI_AMD_Base"
MI_EXAMPLE = "MI_example"
GPU_VIPER = "GPU_VIPER"
CHI = "CHI"
MSI = "MSI"
def get_protocols_str_set():
return {protocol.value for protocol in CoherenceProtocol}
def get_protocol_from_str(protocol_str: str) -> CoherenceProtocol:
"""
Will return the correct enum given the input string. This is matched on
the enum's value. E.g., "CHI" will return CoherenceProtocol.CHI. Throws
an exception if the input string is invalid.
``get_protocols_str_set()`` can be used to determine the valid strings.
This is for parsing text inputs that specify protocol targets.
:param input: The protocol to return, as a string. Case-insensitive.
"""
for protocol in CoherenceProtocol:
if protocol.value.lower() == protocol_str.lower():
return protocol
valid_protocols_str_list = ""
for isa_str in get_protocols_str_set():
valid_protocols_str_list += f"{os.linesep}{isa_str}"
raise Exception(
f"Value '{input}' does not correspond to a known ISA. Known protocols:"
f"{valid_protocols_str_list}"
)

View File

@@ -48,6 +48,7 @@ from m5.objects import (
)
from m5.util.fdthelper import *
from ...coherence_protocol import CoherenceProtocol
from ..boards.abstract_board import AbstractBoard
@@ -142,6 +143,15 @@ class AbstractCacheHierarchy(SubSystem):
"""
raise NotImplementedError
@abstractmethod
def get_coherence_protocol(self) -> CoherenceProtocol:
"""
Returns the coherence protocol used in the cache hierarchy.
:returns: The coherence protocol used in the cache hierarchy.
"""
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

View File

@@ -80,6 +80,10 @@ class PrivateL1CacheHierarchy(AbstractRubyCacheHierarchy):
self._size = size
self._assoc = assoc
@overrides(AbstractCacheHierarchy)
def get_coherence_protocol(self):
return CoherenceProtocol.CHI
@overrides(AbstractCacheHierarchy)
def incorporate_cache(self, board: AbstractBoard) -> None:
super().incorporate_cache(board)

View File

@@ -28,6 +28,7 @@ from abc import abstractmethod
from m5.objects import Port
from ....coherence_protocol import CoherenceProtocol
from ....utils.override import overrides
from ..abstract_cache_hierarchy import AbstractCacheHierarchy
@@ -46,6 +47,10 @@ class AbstractClassicCacheHierarchy(AbstractCacheHierarchy):
def is_ruby(self) -> bool:
return False
@overrides(AbstractCacheHierarchy)
def get_coherence_protocol(self) -> CoherenceProtocol:
return CoherenceProtocol.NULL
@abstractmethod
def get_mem_side_port(self) -> Port:
raise NotImplementedError

View File

@@ -30,7 +30,12 @@ from m5.objects import (
RubySystem,
)
from ......coherence_protocol import CoherenceProtocol
from ....coherence_protocol import CoherenceProtocol
from ....utils.override import overrides
from ....utils.requires import requires
requires(coherence_protocol_required=CoherenceProtocol.MI_EXAMPLE)
from ......components.boards.abstract_board import AbstractBoard
from ......components.cachehierarchies.ruby.caches.mesi_three_level.directory import (
Directory,
@@ -38,8 +43,7 @@ from ......components.cachehierarchies.ruby.caches.mesi_three_level.directory im
from ......components.cachehierarchies.ruby.caches.mesi_three_level.dma_controller import (
DMAController,
)
from ......utils.override import overrides
from ......utils.requires import requires
from ....abstract_cache_hierarchy import AbstractCacheHierarchy
from ....abstract_three_level_cache_hierarchy import (
AbstractThreeLevelCacheHierarchy,
)
@@ -92,6 +96,10 @@ class OctopiCache(
self._num_core_complexes = num_core_complexes
self._is_fullsystem = is_fullsystem
@overrides(AbstractCacheHierarchy)
def get_coherence_protocol(self):
return CoherenceProtocol.MESI_THREE_LEVEL
def incorporate_cache(self, board: AbstractBoard) -> None:
requires(
coherence_protocol_required=CoherenceProtocol.MESI_THREE_LEVEL

View File

@@ -40,6 +40,7 @@ requires(coherence_protocol_required=CoherenceProtocol.MESI_THREE_LEVEL)
from ....isas import ISA
from ...boards.abstract_board import AbstractBoard
from ..abstract_cache_hierarchy import AbstractCacheHierarchy
from ..abstract_three_level_cache_hierarchy import (
AbstractThreeLevelCacheHierarchy,
)
@@ -87,6 +88,10 @@ class MESIThreeLevelCacheHierarchy(
self._num_l3_banks = num_l3_banks
@overrides(AbstractCacheHierarchy)
def get_coherence_protocol(self):
return CoherenceProtocol.MESI_THREE_LEVEL
def incorporate_cache(self, board: AbstractBoard) -> None:
super().incorporate_cache(board)
cache_line_size = board.get_cache_line_size()

View File

@@ -40,6 +40,7 @@ requires(coherence_protocol_required=CoherenceProtocol.MESI_TWO_LEVEL)
from ....isas import ISA
from ...boards.abstract_board import AbstractBoard
from ..abstract_cache_hierarchy import AbstractCacheHierarchy
from ..abstract_two_level_cache_hierarchy import AbstractTwoLevelCacheHierarchy
from .abstract_ruby_cache_hierarchy import AbstractRubyCacheHierarchy
from .caches.mesi_two_level.directory import Directory
@@ -83,6 +84,10 @@ class MESITwoLevelCacheHierarchy(
self._num_l2_banks = num_l2_banks
@overrides(AbstractCacheHierarchy)
def get_coherence_protocol(self):
return CoherenceProtocol.MESI_TWO_LEVEL
def incorporate_cache(self, board: AbstractBoard) -> None:
super().incorporate_cache(board)
cache_line_size = board.get_cache_line_size()

View File

@@ -64,6 +64,10 @@ class MIExampleCacheHierarchy(AbstractRubyCacheHierarchy):
self._size = size
self._assoc = assoc
@overrides(AbstractCacheHierarchy)
def get_coherence_protocol(self):
return CoherenceProtocol.MI_EXAMPLE
@overrides(AbstractCacheHierarchy)
def incorporate_cache(self, board: AbstractBoard) -> None:
super().incorporate_cache(board)

View File

@@ -33,7 +33,11 @@ from typing import Set
from m5.defines import buildEnv
from m5.util import warn
from .coherence_protocol import CoherenceProtocol
from .coherence_protocol import (
CoherenceProtocol,
get_protocol_from_str,
get_protocols_str_set,
)
from .isas import (
ISA,
get_isa_from_str,
@@ -60,30 +64,18 @@ def get_supported_isas() -> Set[ISA]:
return supported_isas
def get_runtime_coherence_protocol() -> CoherenceProtocol:
"""Gets the cache coherence protocol.
This can be inferred at runtime.
:returns: The cache coherence protocol.
def get_supported_protocols() -> Set[CoherenceProtocol]:
"""
protocol_map = {
"mi_example": CoherenceProtocol.MI_EXAMPLE,
"moesi_hammer": CoherenceProtocol.ARM_MOESI_HAMMER,
"garnet_standalone": CoherenceProtocol.GARNET_STANDALONE,
"moesi_cmp_token": CoherenceProtocol.MOESI_CMP_TOKEN,
"mesi_two_level": CoherenceProtocol.MESI_TWO_LEVEL,
"moesi_amd_base": CoherenceProtocol.MOESI_AMD_BASE,
"mesi_three_level_htm": CoherenceProtocol.MESI_THREE_LEVEL_HTM,
"mesi_three_level": CoherenceProtocol.MESI_THREE_LEVEL,
"gpu_viper": CoherenceProtocol.GPU_VIPER,
"chi": CoherenceProtocol.CHI,
}
Returns the set of all the coherence protocols compiled into the current
binary.
"""
supported_protocols = set()
protocol_str = str(buildEnv["PROTOCOL"]).lower()
if protocol_str not in protocol_map.keys():
raise NotImplementedError(
"Protocol '" + buildEnv["PROTOCOL"] + "' not recognized."
)
if not buildEnv["RUBY"]:
return {CoherenceProtocol.NULL}
return protocol_map[protocol_str]
for key in get_protocols_str_set():
if buildEnv.get(f"RUBY_PROTOCOL_{key}", False):
supported_protocols.add(get_protocol_from_str(key))
return supported_protocols

View File

@@ -31,8 +31,8 @@ from typing import Optional
from ..coherence_protocol import CoherenceProtocol
from ..isas import ISA
from ..runtime import (
get_runtime_coherence_protocol,
get_supported_isas,
get_supported_protocols,
)
@@ -73,7 +73,7 @@ def requires(
"""
supported_isas = get_supported_isas()
runtime_coherence_protocol = get_runtime_coherence_protocol()
supported_protocols = get_supported_protocols()
kvm_available = os.access("/dev/kvm", mode=os.R_OK | os.W_OK)
# Note, previously I had the following code here:
@@ -108,17 +108,13 @@ def requires(
if (
coherence_protocol_required != None
and coherence_protocol_required.value
!= runtime_coherence_protocol.value
not in (protocol.value for protocol in supported_protocols)
):
raise Exception(
_get_exception_str(
msg="The current coherence protocol is "
"'{}'. Required: '{}'".format(
runtime_coherence_protocol.name,
coherence_protocol_required.name,
)
)
)
msg = f"The required protocol is '{coherence_protocol_required.name}'."
msg += "Supported protocols: "
for protocol in supported_protocols:
msg += f"{os.linesep}{protocol.name}"
raise Exception(_get_exception_str(msg=msg))
if kvm_required and not kvm_available:
raise Exception(

View File

@@ -42,7 +42,6 @@ from gem5.components.processors.cpu_types import (
from gem5.components.processors.simple_processor import SimpleProcessor
from gem5.isas import ISA
from gem5.resources.resource import obtain_resource
from gem5.runtime import get_runtime_coherence_protocol
from gem5.simulate.simulator import Simulator
from gem5.utils.requires import requires
@@ -196,7 +195,9 @@ motherboard.set_workload(workload)
# Begin running of the simulation. This will exit once the Linux system boot
# is complete.
print("Running with ISA: " + processor.get_isa().name)
print("Running with protocol: " + get_runtime_coherence_protocol().name)
print(
"Running with protocol: " + cache_hierarchy.get_coherence_protocol().name
)
print()
print("Beginning simulation!")