scons: Simplify the CpuModel class into a function.

The CpuModel class looks like it was originally intended to hold a lot
more information that it does now, which is just the name of a CPU, and
whether it should be enabled by default. All the built in configs in
build_opts already explicitly list a set of CPUs, and CPUs should not,
generally speaking, be enabled by default, since they almost always need
to be specifically supported by an ISA. This is mutual, since usually
ISAs definitions are not quite correct or complete, and this is often
exposed by plugging them into different, and/or more complex CPU models
which stress those short comings.

This change drops the idea of a "default" CPU, and since the only thing
being tracked at this point is a list of CPUs, it turns CpuModel() into
a simple function which adds a name to a set of supported CPUs.

Change-Id: Id7475d5dc8548802b5253f79839da8c76ef4d165
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48963
Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-07-31 23:23:57 -07:00
parent 3e6d08b751
commit 1bf0b844ff
4 changed files with 8 additions and 25 deletions

View File

@@ -25,29 +25,12 @@
Import('*')
class CpuModel(object):
'''The CpuModel class encapsulates everything the ISA parser needs to
know about a particular CPU model.'''
# Dict of available CPU model objects. Accessible as CpuModel.dict.
dict = {}
# Constructor. Automatically adds models to CpuModel.dict.
def __init__(self, name, default=False):
self.name = name # name of model
# This cpu is enabled by default
self.default = default
# Add self to dict
if name in CpuModel.dict:
raise AttributeError("CpuModel '%s' already registered" % name)
CpuModel.dict[name] = self
all_cpus = set()
def CpuModel(name):
all_cpus.add(name)
Export('CpuModel')
def add_cpu_models_var():
sticky_vars.Add(ListVariable('CPU_MODELS', 'CPU models',
sorted(n for n,m in CpuModel.dict.items() if m.default),
sorted(CpuModel.dict.keys())))
sticky_vars.Add(ListVariable('CPU_MODELS', 'CPU models', [], all_cpus))
AfterSConsopts(add_cpu_models_var)

View File

@@ -37,4 +37,4 @@
Import('*')
CpuModel('MinorCPU', default=True)
CpuModel('MinorCPU')

View File

@@ -28,4 +28,4 @@
Import('*')
CpuModel('O3CPU', default=True)
CpuModel('O3CPU')

View File

@@ -28,5 +28,5 @@
Import('*')
CpuModel('AtomicSimpleCPU', default=True)
CpuModel('TimingSimpleCPU', default=True)
CpuModel('AtomicSimpleCPU')
CpuModel('TimingSimpleCPU')