From 97542c1a4cb80e622b49440459b264871efbc37d Mon Sep 17 00:00:00 2001 From: Jason Lowe-Power Date: Fri, 25 Oct 2024 16:28:46 -0700 Subject: [PATCH] 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 ` and selecting the right ruby options. Alternatively, if you're using a `build_opts` file, you can run `scons defconfig build/ build_opts/` 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 --- RELEASE-NOTES.md | 3 +- build_opts/ALL | 3 +- build_opts/ARM | 1 + build_opts/ARM_MESI_Three_Level | 3 +- build_opts/ARM_MESI_Three_Level_HTM | 3 +- build_opts/ARM_MOESI_hammer | 3 +- build_opts/Garnet_standalone | 3 +- build_opts/MIPS | 3 +- build_opts/NULL | 3 +- build_opts/NULL_All_Ruby | 14 +++ build_opts/NULL_MESI_Two_Level | 3 +- build_opts/NULL_MOESI_CMP_directory | 3 +- build_opts/NULL_MOESI_CMP_token | 3 +- build_opts/NULL_MOESI_hammer | 3 +- build_opts/POWER | 3 +- build_opts/RISCV | 3 +- build_opts/SPARC | 3 +- build_opts/VEGA_X86 | 1 + build_opts/X86 | 3 +- build_opts/X86_MESI_Two_Level | 3 +- build_opts/X86_MI_example | 3 +- build_opts/X86_MOESI_AMD_Base | 3 +- configs/learning_gem5/part3/msi_caches.py | 2 +- .../part3/ruby_caches_MI_example.py | 2 +- configs/ruby/MULTIPLE.py | 89 +++++++++++++++++++ src/Kconfig | 1 - src/arch/arm/SConscript | 3 +- src/learning_gem5/part3/Kconfig | 9 +- src/mem/ruby/Kconfig | 29 ++++-- src/mem/ruby/SConscript | 2 +- src/mem/ruby/protocol/Kconfig | 65 +++++++------- src/mem/ruby/protocol/SConscript | 22 ++++- src/mem/ruby/protocol/chi/Kconfig | 13 +-- src/mem/ruby/structures/SConscript | 2 +- src/python/gem5/coherence_protocol.py | 56 +++++++++--- .../abstract_cache_hierarchy.py | 10 +++ .../chi/private_l1_cache_hierarchy.py | 4 + .../abstract_classic_cache_hierarchy.py | 5 ++ .../caches/prebuilt/octopi_cache/octopi.py | 14 ++- .../ruby/mesi_three_level_cache_hierarchy.py | 5 ++ .../ruby/mesi_two_level_cache_hierarchy.py | 5 ++ .../ruby/mi_example_cache_hierarchy.py | 4 + src/python/gem5/runtime.py | 42 ++++----- src/python/gem5/utils/requires.py | 20 ++--- .../configs/x86_boot_exit_run.py | 5 +- 45 files changed, 344 insertions(+), 138 deletions(-) create mode 100644 build_opts/NULL_All_Ruby create mode 100644 configs/ruby/MULTIPLE.py diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 0044f86893..abc4b237ea 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -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 ` and selecting the right ruby options. Alternatively, if you're using a `build_opts` file, you can run `scons defconfig build/ build_opts/` 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. diff --git a/build_opts/ALL b/build_opts/ALL index 4f4ae1b8dc..23c194a445 100644 --- a/build_opts/ALL +++ b/build_opts/ALL @@ -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 diff --git a/build_opts/ARM b/build_opts/ARM index b50f366703..6844ef73f9 100644 --- a/build_opts/ARM +++ b/build_opts/ARM @@ -1,4 +1,5 @@ BUILD_ISA=y USE_ARM_ISA=y RUBY=y +PROTOCOL="CHI" RUBY_PROTOCOL_CHI=y diff --git a/build_opts/ARM_MESI_Three_Level b/build_opts/ARM_MESI_Three_Level index 4cda128fb1..9f79311f25 100644 --- a/build_opts/ARM_MESI_Three_Level +++ b/build_opts/ARM_MESI_Three_Level @@ -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 diff --git a/build_opts/ARM_MESI_Three_Level_HTM b/build_opts/ARM_MESI_Three_Level_HTM index ade6a0dfb6..f91cb5b950 100644 --- a/build_opts/ARM_MESI_Three_Level_HTM +++ b/build_opts/ARM_MESI_Three_Level_HTM @@ -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 diff --git a/build_opts/ARM_MOESI_hammer b/build_opts/ARM_MOESI_hammer index 44038ff493..f423b99228 100644 --- a/build_opts/ARM_MOESI_hammer +++ b/build_opts/ARM_MOESI_hammer @@ -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 diff --git a/build_opts/Garnet_standalone b/build_opts/Garnet_standalone index 5df3d6c74f..a5b7548e60 100644 --- a/build_opts/Garnet_standalone +++ b/build_opts/Garnet_standalone @@ -1,2 +1,3 @@ RUBY=y -RUBY_PROTOCOL_GARNET_STANDALONE=y +PROTOCOL="Garnet_standalone" +RUBY_PROTOCOL_Garnet_standalone=y diff --git a/build_opts/MIPS b/build_opts/MIPS index e60d44ebc4..16e0922236 100644 --- a/build_opts/MIPS +++ b/build_opts/MIPS @@ -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 diff --git a/build_opts/NULL b/build_opts/NULL index 16f4686a5a..b9a979b295 100644 --- a/build_opts/NULL +++ b/build_opts/NULL @@ -1,2 +1,3 @@ RUBY=y -RUBY_PROTOCOL_MI_EXAMPLE=y +PROTOCOL="MI_example" +RUBY_PROTOCOL_MI_example=y diff --git a/build_opts/NULL_All_Ruby b/build_opts/NULL_All_Ruby new file mode 100644 index 0000000000..2b09f2bbae --- /dev/null +++ b/build_opts/NULL_All_Ruby @@ -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 diff --git a/build_opts/NULL_MESI_Two_Level b/build_opts/NULL_MESI_Two_Level index 57542472df..b0741b16a1 100644 --- a/build_opts/NULL_MESI_Two_Level +++ b/build_opts/NULL_MESI_Two_Level @@ -1,2 +1,3 @@ RUBY=y -RUBY_PROTOCOL_MESI_TWO_LEVEL=y +PROTOCOL="MESI_Two_Level" +RUBY_PROTOCOL_MESI_Two_Level=y diff --git a/build_opts/NULL_MOESI_CMP_directory b/build_opts/NULL_MOESI_CMP_directory index 3c5308f525..8df5ddc4ed 100644 --- a/build_opts/NULL_MOESI_CMP_directory +++ b/build_opts/NULL_MOESI_CMP_directory @@ -1,2 +1,3 @@ RUBY=y -RUBY_PROTOCOL_MOESI_CMP_DIRECTORY=y +PROTOCOL="MOESI_CMP_directory" +RUBY_PROTOCOL_MOESI_CMP_directory=y diff --git a/build_opts/NULL_MOESI_CMP_token b/build_opts/NULL_MOESI_CMP_token index 2297bdd722..bf6fbc10cc 100644 --- a/build_opts/NULL_MOESI_CMP_token +++ b/build_opts/NULL_MOESI_CMP_token @@ -1,2 +1,3 @@ RUBY=y -RUBY_PROTOCOL_MOESI_CMP_TOKEN=y +PROTOCOL="MOESI_CMP_token" +RUBY_PROTOCOL_MOESI_CMP_token=y diff --git a/build_opts/NULL_MOESI_hammer b/build_opts/NULL_MOESI_hammer index fe63b9c54c..1366c547f0 100644 --- a/build_opts/NULL_MOESI_hammer +++ b/build_opts/NULL_MOESI_hammer @@ -1,2 +1,3 @@ RUBY=y -RUBY_PROTOCOL_MOESI_HAMMER=y +PROTOCOL="MOESI_hammer" +RUBY_PROTOCOL_MOESI_hammer=y diff --git a/build_opts/POWER b/build_opts/POWER index 02f7e161d2..2dba26b4dc 100644 --- a/build_opts/POWER +++ b/build_opts/POWER @@ -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 diff --git a/build_opts/RISCV b/build_opts/RISCV index c0de30e4b5..8ef1f4325c 100644 --- a/build_opts/RISCV +++ b/build_opts/RISCV @@ -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 diff --git a/build_opts/SPARC b/build_opts/SPARC index 7f3b544d4a..f575c6f786 100644 --- a/build_opts/SPARC +++ b/build_opts/SPARC @@ -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 diff --git a/build_opts/VEGA_X86 b/build_opts/VEGA_X86 index 89ebbd8d3c..404acb604e 100644 --- a/build_opts/VEGA_X86 +++ b/build_opts/VEGA_X86 @@ -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 diff --git a/build_opts/X86 b/build_opts/X86 index 6d6f4d523a..d82f5aa8cb 100644 --- a/build_opts/X86 +++ b/build_opts/X86 @@ -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 diff --git a/build_opts/X86_MESI_Two_Level b/build_opts/X86_MESI_Two_Level index 6d6f4d523a..d82f5aa8cb 100644 --- a/build_opts/X86_MESI_Two_Level +++ b/build_opts/X86_MESI_Two_Level @@ -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 diff --git a/build_opts/X86_MI_example b/build_opts/X86_MI_example index 4236851d4d..f7859c12e4 100644 --- a/build_opts/X86_MI_example +++ b/build_opts/X86_MI_example @@ -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 diff --git a/build_opts/X86_MOESI_AMD_Base b/build_opts/X86_MOESI_AMD_Base index ffb7fb73c0..6b83c287c3 100644 --- a/build_opts/X86_MOESI_AMD_Base +++ b/build_opts/X86_MOESI_AMD_Base @@ -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 diff --git a/configs/learning_gem5/part3/msi_caches.py b/configs/learning_gem5/part3/msi_caches.py index 691b5fdcbf..0d6fd38645 100644 --- a/configs/learning_gem5/part3/msi_caches.py +++ b/configs/learning_gem5/part3/msi_caches.py @@ -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__() diff --git a/configs/learning_gem5/part3/ruby_caches_MI_example.py b/configs/learning_gem5/part3/ruby_caches_MI_example.py index 6eaec7276c..ac556aa903 100644 --- a/configs/learning_gem5/part3/ruby_caches_MI_example.py +++ b/configs/learning_gem5/part3/ruby_caches_MI_example.py @@ -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__() diff --git a/configs/ruby/MULTIPLE.py b/configs/ruby/MULTIPLE.py new file mode 100644 index 0000000000..6bd81ffafe --- /dev/null +++ b/configs/ruby/MULTIPLE.py @@ -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 . " + "or --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) diff --git a/src/Kconfig b/src/Kconfig index 268f7ca1c5..c010b78f82 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -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" diff --git a/src/arch/arm/SConscript b/src/arch/arm/SConscript index b555c6f12c..457ae83a86 100644 --- a/src/arch/arm/SConscript +++ b/src/arch/arm/SConscript @@ -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") diff --git a/src/learning_gem5/part3/Kconfig b/src/learning_gem5/part3/Kconfig index 9d06122d2e..ca66e02e09 100644 --- a/src/learning_gem5/part3/Kconfig +++ b/src/learning_gem5/part3/Kconfig @@ -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 diff --git a/src/mem/ruby/Kconfig b/src/mem/ruby/Kconfig index 362174d5b7..384ee552a5 100644 --- a/src/mem/ruby/Kconfig +++ b/src/mem/ruby/Kconfig @@ -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 diff --git a/src/mem/ruby/SConscript b/src/mem/ruby/SConscript index 946213ab1a..11c1e30f64 100644 --- a/src/mem/ruby/SConscript +++ b/src/mem/ruby/SConscript @@ -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') diff --git a/src/mem/ruby/protocol/Kconfig b/src/mem/ruby/protocol/Kconfig index bed47a1108..5b584fbedb 100644 --- a/src/mem/ruby/protocol/Kconfig +++ b/src/mem/ruby/protocol/Kconfig @@ -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" diff --git a/src/mem/ruby/protocol/SConscript b/src/mem/ruby/protocol/SConscript index afa97834f3..c0cd28f532 100644 --- a/src/mem/ruby/protocol/SConscript +++ b/src/mem/ruby/protocol/SConscript @@ -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) diff --git a/src/mem/ruby/protocol/chi/Kconfig b/src/mem/ruby/protocol/chi/Kconfig index 708f162fd7..3a8eae759b 100644 --- a/src/mem/ruby/protocol/chi/Kconfig +++ b/src/mem/ruby/protocol/chi/Kconfig @@ -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 diff --git a/src/mem/ruby/structures/SConscript b/src/mem/ruby/structures/SConscript index fb7b99f265..47314be8bd 100644 --- a/src/mem/ruby/structures/SConscript +++ b/src/mem/ruby/structures/SConscript @@ -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') diff --git a/src/python/gem5/coherence_protocol.py b/src/python/gem5/coherence_protocol.py index 1ae45fc190..b4556858e9 100644 --- a/src/python/gem5/coherence_protocol.py +++ b/src/python/gem5/coherence_protocol.py @@ -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}" + ) diff --git a/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py index dc20c14f70..dd9d67d922 100644 --- a/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/abstract_cache_hierarchy.py @@ -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 diff --git a/src/python/gem5/components/cachehierarchies/chi/private_l1_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/chi/private_l1_cache_hierarchy.py index 42c4e2258c..b2ed9015f9 100644 --- a/src/python/gem5/components/cachehierarchies/chi/private_l1_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/chi/private_l1_cache_hierarchy.py @@ -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) diff --git a/src/python/gem5/components/cachehierarchies/classic/abstract_classic_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/classic/abstract_classic_cache_hierarchy.py index 7531b2a3f1..3d8fbec3cb 100644 --- a/src/python/gem5/components/cachehierarchies/classic/abstract_classic_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/classic/abstract_classic_cache_hierarchy.py @@ -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 diff --git a/src/python/gem5/components/cachehierarchies/ruby/caches/prebuilt/octopi_cache/octopi.py b/src/python/gem5/components/cachehierarchies/ruby/caches/prebuilt/octopi_cache/octopi.py index d576ae6ae4..49012247fd 100644 --- a/src/python/gem5/components/cachehierarchies/ruby/caches/prebuilt/octopi_cache/octopi.py +++ b/src/python/gem5/components/cachehierarchies/ruby/caches/prebuilt/octopi_cache/octopi.py @@ -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 diff --git a/src/python/gem5/components/cachehierarchies/ruby/mesi_three_level_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/ruby/mesi_three_level_cache_hierarchy.py index 501fbab081..04cc19665f 100644 --- a/src/python/gem5/components/cachehierarchies/ruby/mesi_three_level_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/ruby/mesi_three_level_cache_hierarchy.py @@ -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() diff --git a/src/python/gem5/components/cachehierarchies/ruby/mesi_two_level_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/ruby/mesi_two_level_cache_hierarchy.py index 52a14c7681..46895b2f0b 100644 --- a/src/python/gem5/components/cachehierarchies/ruby/mesi_two_level_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/ruby/mesi_two_level_cache_hierarchy.py @@ -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() diff --git a/src/python/gem5/components/cachehierarchies/ruby/mi_example_cache_hierarchy.py b/src/python/gem5/components/cachehierarchies/ruby/mi_example_cache_hierarchy.py index 271bc42536..21d3ecdecd 100644 --- a/src/python/gem5/components/cachehierarchies/ruby/mi_example_cache_hierarchy.py +++ b/src/python/gem5/components/cachehierarchies/ruby/mi_example_cache_hierarchy.py @@ -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) diff --git a/src/python/gem5/runtime.py b/src/python/gem5/runtime.py index a7a284f7ae..5634d330ad 100644 --- a/src/python/gem5/runtime.py +++ b/src/python/gem5/runtime.py @@ -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 diff --git a/src/python/gem5/utils/requires.py b/src/python/gem5/utils/requires.py index f1f6053756..239cb8d185 100644 --- a/src/python/gem5/utils/requires.py +++ b/src/python/gem5/utils/requires.py @@ -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( diff --git a/tests/gem5/x86_boot_tests/configs/x86_boot_exit_run.py b/tests/gem5/x86_boot_tests/configs/x86_boot_exit_run.py index 7e9116ad34..ddb2b06c0a 100644 --- a/tests/gem5/x86_boot_tests/configs/x86_boot_exit_run.py +++ b/tests/gem5/x86_boot_tests/configs/x86_boot_exit_run.py @@ -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!")