Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/40872 )

Change subject: scons: Pull domain specific build setup out of SConstruct.
......................................................................

scons: Pull domain specific build setup out of SConstruct.

Use SConsopts files local to individual domains to pull
non-foundational build code out of SConstruct. This greatly simplifies
SConstruct, and also makes it easier to find build configuration having
to do with particular pieces of gem5.

Change-Id: Ie61ceb75ae9e5557cc400603c972a9582e99c1ea
---
M SConstruct
A src/arch/SConsopts
M src/arch/arm/kvm/SConscript
M src/base/SConscript
A src/base/SConsopts
A src/base/stats/SConsopts
A src/cpu/SConsopts
M src/cpu/kvm/SConscript
A src/cpu/kvm/SConsopts
A src/dev/net/SConsopts
A src/gpu-compute/SConsopts
A src/mem/ruby/SConsopts
M src/mem/ruby/protocol/SConsopts
A src/proto/SConsopts
A src/sim/SConsopts
M src/systemc/SConsopts
16 files changed, 593 insertions(+), 112 deletions(-)



diff --git a/SConstruct b/SConstruct
index 5150ff9..74ae060 100755
--- a/SConstruct
+++ b/SConstruct
@@ -77,6 +77,7 @@

 # Global Python includes
 import atexit
+import collections
 import itertools
 import os
 import re
@@ -453,6 +454,7 @@


 have_pkg_config = main.Detect('pkg-config')
+main['HAVE_PKG_CONFIG'] = have_pkg_config

 # Check for the protobuf compiler
 main['HAVE_PROTOC'] = False
@@ -672,11 +674,6 @@
     print("Info: Compatible header file <linux/kvm.h> not found, "
           "disabling KVM support.")

-# Check if the TUN/TAP driver is available.
-have_tuntap = conf.CheckHeader('linux/if_tun.h', '<>')
-if not have_tuntap:
-    print("Info: Compatible header file <linux/if_tun.h> not found.")
-
 # Determine what ISA KVM can support on this host.
 kvm_isa = None
 host_isa = None
@@ -704,26 +701,6 @@
 main['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
     'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host')

-# Check if there is a pkg-config configuration for hdf5. If we find
-# it, setup the environment to enable linking and header inclusion. We
-# don't actually try to include any headers or link with hdf5 at this
-# stage.
-if have_pkg_config:
-    conf.CheckPkgConfig(['hdf5-serial', 'hdf5'],
-            '--cflags-only-I', '--libs-only-L')
-
-# Check if the HDF5 libraries can be found. This check respects the
-# include path and library path provided by pkg-config. We perform
-# this check even if there isn't a pkg-config configuration for hdf5
-# since some installations don't use pkg-config.
-have_hdf5 = \
-        conf.CheckLibWithHeader('hdf5', 'hdf5.h', 'C',
-                                'H5Fcreate("", 0, 0, 0);') and \
-        conf.CheckLibWithHeader('hdf5_cpp', 'H5Cpp.h', 'C++',
-                                'H5::H5File("", 0);')
-if not have_hdf5:
- warning("Couldn't find any HDF5 C++ libraries. Disabling HDF5 support.")
-
 ######################################################################
 #
 # Finish the configuration
@@ -735,32 +712,11 @@
 # Collect all non-global variables
 #

-# Define the universe of supported ISAs
-all_isa_list = [ ]
-all_gpu_isa_list = [ ]
-Export('all_isa_list')
-Export('all_gpu_isa_list')
-
-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
-
-Export('CpuModel')
+# Register a callback which is called after all SConsopts files have been read.
+after_sconsopts_callbacks = []
+def AfterSConsopts(cb):
+    after_sconsopts_callbacks.append(cb)
+Export('AfterSConsopts')

 # Sticky variables get saved in the variables file so they persist from
 # one invocation to the next (unless overridden, in which case the new
@@ -773,12 +729,6 @@
 Export('export_vars')

 # For Ruby
-all_protocols = []
-Export('all_protocols')
-protocol_dirs = []
-Export('protocol_dirs')
-slicc_includes = []
-Export('slicc_includes')

 # Walk the tree and execute all SConsopts scripts that wil add to the
 # above variables
@@ -793,17 +743,11 @@
                 print("Reading", joinpath(root, 'SConsopts'))
             SConscript(joinpath(root, 'SConsopts'))

-all_isa_list.sort()
-all_gpu_isa_list.sort()
+for cb in after_sconsopts_callbacks:
+    cb()

 sticky_vars.AddVariables(
-    EnumVariable('TARGET_ISA', 'Target ISA', 'null', all_isa_list),
- EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'gcn3', all_gpu_isa_list),
-    ListVariable('CPU_MODELS', 'CPU models',
-                 sorted(n for n,m in CpuModel.dict.items() if m.default),
-                 sorted(CpuModel.dict.keys())),
-    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
-                 False),
+ BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', False),
     BoolVariable('USE_SSE2',
                  'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
                  False),
@@ -812,23 +756,12 @@
     BoolVariable('USE_PNG',  'Enable support for PNG images', have_png),
     BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models',
                  have_kvm),
-    BoolVariable('USE_TUNTAP',
-                 'Enable using a tap device to bridge to the host network',
-                 have_tuntap),
-    BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False),
-    EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None',
-                  all_protocols),
-    ('NUMBER_BITS_PER_SET', 'Max elements in set (default 64)',
-                 64),
-    BoolVariable('USE_HDF5', 'Enable the HDF5 support', have_hdf5),
     )

# These variables get exported to #defines in config/*.hh (see src/SConscript).
-export_vars += ['USE_FENV', 'TARGET_ISA', 'TARGET_GPU_ISA',
-                'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP', 'PROTOCOL',
+export_vars += ['USE_FENV', 'USE_POSIX_CLOCK', 'USE_KVM',
                 'HAVE_PROTOBUF', 'HAVE_VALGRIND',
-                'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG',
-                'NUMBER_BITS_PER_SET', 'USE_HDF5']
+                'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG']

 ###################################################
 #
@@ -1039,11 +972,6 @@
                   (env['TARGET_ISA'], kvm_isa))
             env['USE_KVM'] = False

-    if env['USE_TUNTAP']:
-        if not have_tuntap:
-            warning("Can't connect EtherTap with a tap device.")
-            env['USE_TUNTAP'] = False
-
     if env['BUILD_GPU']:
         env.Append(CPPDEFINES=['BUILD_GPU'])

diff --git a/src/arch/SConsopts b/src/arch/SConsopts
new file mode 100644
index 0000000..90ac93b
--- /dev/null
+++ b/src/arch/SConsopts
@@ -0,0 +1,43 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+# Define the universe of supported ISAs
+all_isa_list = []
+Export('all_isa_list')
+
+all_gpu_isa_list = []
+Export('all_gpu_isa_list')
+
+def add_isa_lists():
+    sticky_vars.AddVariables(
+ EnumVariable('TARGET_ISA', 'Target ISA', 'null', sorted(all_isa_list)),
+        EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'gcn3',
+            sorted(all_gpu_isa_list)),
+        )
+AfterSConsopts(add_isa_lists)
+
+export_vars.extend(['TARGET_ISA', 'TARGET_GPU_ISA'])
diff --git a/src/arch/arm/kvm/SConscript b/src/arch/arm/kvm/SConscript
index e49c725..d999505 100644
--- a/src/arch/arm/kvm/SConscript
+++ b/src/arch/arm/kvm/SConscript
@@ -37,12 +37,13 @@

 Import('*')

-if not (env['USE_KVM'] and env['TARGET_ISA'] == 'arm'):
-    Return()
-
 import platform
 host_isa = platform.machine()

+if not (env['USE_KVM'] and env['TARGET_ISA'] == 'arm' and
+        host_isa in ('armv71', 'aarch64')):
+    Return()
+
 SimObject('KvmGic.py')
 Source('gic.cc')

diff --git a/src/base/SConscript b/src/base/SConscript
index 1190b93..5646a4f 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -44,7 +44,11 @@
 GTest('debug.test', 'debug.test.cc', 'debug.cc')
 if env['USE_FENV']:
     Source('fenv.c')
+else:
+    warning("No IEEE FP rounding mode control.\n"
+            "FP results may deviate slightly from other platforms.")
 if env['USE_PNG']:
+    env.Append(LIBS=['png'])
     Source('pngwriter.cc')
 Source('fiber.cc')
 GTest('fiber.test', 'fiber.test.cc', 'fiber.cc')
diff --git a/src/base/SConsopts b/src/base/SConsopts
new file mode 100644
index 0000000..424789d
--- /dev/null
+++ b/src/base/SConsopts
@@ -0,0 +1,76 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+from gem5_scons import warning
+
+import gem5_scons
+
+conf = gem5_scons.Configure(main)
+
+# Check for <fenv.h> (C99 FP environment control)
+have_fenv = conf.CheckHeader('fenv.h', '<>')
+
+# Check for <png.h> (libpng library needed if wanting to dump
+# frame buffer image in png format)
+have_png = conf.CheckHeader('png.h', '<>')
+
+have_posix_clock = \
+    conf.CheckLibWithHeader([None, 'rt'], 'time.h', 'C',
+                            'clock_nanosleep(0,0,NULL,NULL);')
+if not have_posix_clock:
+    warning("Can't find library for POSIX clocks.")
+
+# Valgrind gets much less confused if you tell it when you're using
+# alternative stacks.
+main['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h')
+
+main = conf.Finish()
+
+
+if have_fenv:
+ sticky_vars.Add(BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control',
+                                 True))
+else:
+    warning("Header file <fenv.h> not found.\n"
+            "This host has no IEEE FP rounding mode control.")
+    main['USE_FENV'] = False
+
+
+if have_png:
+ sticky_vars.Add(BoolVariable('USE_PNG', 'Enable support for PNG images',
+                                 True))
+else:
+    warning("Header file <png.h> not found.\n"
+            "This host has no libpng library.\n"
+            "Disabling support for PNG framebuffers.")
+    main['USE_PNG'] = False
+
+sticky_vars.Add(BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks',
+                             have_posix_clock))
+
+
+export_vars.extend(['USE_FENV', 'USE_PNG', 'USE_POSIX_CLOCK', 'HAVE_VALGRIND'])
diff --git a/src/base/stats/SConsopts b/src/base/stats/SConsopts
new file mode 100644
index 0000000..6e0fd8a
--- /dev/null
+++ b/src/base/stats/SConsopts
@@ -0,0 +1,60 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+from gem5_scons import warning
+
+import gem5_scons
+
+conf = gem5_scons.Configure(main)
+
+# Check if there is a pkg-config configuration for hdf5. If we find
+# it, setup the environment to enable linking and header inclusion. We
+# don't actually try to include any headers or link with hdf5 at this
+# stage.
+if main['HAVE_PKG_CONFIG']:
+    conf.CheckPkgConfig(['hdf5-serial', 'hdf5'],
+            '--cflags-only-I', '--libs-only-L')
+
+# Check if the HDF5 libraries can be found. This check respects the
+# include path and library path provided by pkg-config. We perform
+# this check even if there isn't a pkg-config configuration for hdf5
+# since some installations don't use pkg-config.
+have_hdf5 = \
+        conf.CheckLibWithHeader('hdf5', 'hdf5.h', 'C',
+                                'H5Fcreate("", 0, 0, 0);') and \
+        conf.CheckLibWithHeader('hdf5_cpp', 'H5Cpp.h', 'C++',
+                                'H5::H5File("", 0);')
+
+main = conf.Finish()
+
+if have_hdf5:
+ sticky_vars.Add(BoolVariable('USE_HDF5', 'Enable the HDF5 support', True))
+else:
+ warning("Couldn't find any HDF5 C++ libraries. Disabling HDF5 support.")
+    main['USE_HDF5'] = False
+
+export_vars.append('USE_HDF5')
diff --git a/src/cpu/SConsopts b/src/cpu/SConsopts
new file mode 100644
index 0000000..6a182f1
--- /dev/null
+++ b/src/cpu/SConsopts
@@ -0,0 +1,53 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+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
+
+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())))
+AfterSConsopts(add_cpu_models_var)
diff --git a/src/cpu/kvm/SConscript b/src/cpu/kvm/SConscript
index 7b25bf4..397d96a 100644
--- a/src/cpu/kvm/SConscript
+++ b/src/cpu/kvm/SConscript
@@ -37,27 +37,32 @@

 Import('*')

-if env['USE_KVM']:
-    SimObject('KvmVM.py')
-    SimObject('BaseKvmCPU.py')
+if not env['USE_KVM']:
+    Return()

-    Source('base.cc')
-    Source('device.cc')
-    Source('vm.cc')
-    Source('perfevent.cc')
-    Source('timer.cc')
+SimObject('KvmVM.py')
+SimObject('BaseKvmCPU.py')

-    if env['TARGET_ISA'] == 'x86':
-        SimObject('X86KvmCPU.py')
-        Source('x86_cpu.cc')
+Source('base.cc')
+Source('device.cc')
+Source('vm.cc')
+Source('perfevent.cc')
+Source('timer.cc')

-    DebugFlag('Kvm', 'Basic KVM Functionality')
-    DebugFlag('KvmContext', 'KVM/gem5 context synchronization')
-    DebugFlag('KvmIO', 'KVM MMIO diagnostics')
-    DebugFlag('KvmInt', 'KVM Interrupt handling')
-    DebugFlag('KvmRun', 'KvmRun entry/exit diagnostics')
-    DebugFlag('KvmTimer', 'KVM timing')
+import platform
+host_isa = platform.machine()

-    CompoundFlag('KvmAll', [ 'Kvm', 'KvmContext', 'KvmRun',
-                             'KvmIO', 'KvmInt', 'KvmTimer' ],
-                 'All KVM debug flags')
+if env['TARGET_ISA'] == 'x86' and host_isa == 'x86_64':
+    SimObject('X86KvmCPU.py')
+    Source('x86_cpu.cc')
+
+DebugFlag('Kvm', 'Basic KVM Functionality')
+DebugFlag('KvmContext', 'KVM/gem5 context synchronization')
+DebugFlag('KvmIO', 'KVM MMIO diagnostics')
+DebugFlag('KvmInt', 'KVM Interrupt handling')
+DebugFlag('KvmRun', 'KvmRun entry/exit diagnostics')
+DebugFlag('KvmTimer', 'KVM timing')
+
+CompoundFlag('KvmAll', [ 'Kvm', 'KvmContext', 'KvmRun',
+                         'KvmIO', 'KvmInt', 'KvmTimer' ],
+             'All KVM debug flags')
diff --git a/src/cpu/kvm/SConsopts b/src/cpu/kvm/SConsopts
new file mode 100644
index 0000000..655786f
--- /dev/null
+++ b/src/cpu/kvm/SConsopts
@@ -0,0 +1,75 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+from gem5_scons import warning
+
+import gem5_scons
+import platform
+
+conf = gem5_scons.Configure(main)
+
+# Check if we should enable KVM-based hardware virtualization. The API
+# we rely on exists since version 2.6.36 of the kernel, but somehow
+# the KVM_API_VERSION does not reflect the change. We test for one of
+# the types as a fall back.
+have_kvm = True
+if not conf.CheckHeader('linux/kvm.h', '<>'):
+    print("Info: Compatible header file <linux/kvm.h> not found, "
+          "disabling KVM support.")
+    have_kvm = False
+elif not conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', + 'timer_create(CLOCK_MONOTONIC, NULL, NULL);'): + warning("Cannot enable KVM, host seems to lack support for POSIX timers")
+    have_kvm = False
+elif platform.machine() == 'x86' and not \
+ conf.CheckTypeSize('struct kvm_xsave', '#include <linux/kvm.h>') == 0:
+    warning("KVM on x86 requires xsave support in kernel headers.")
+    have_kvm = False
+
+if have_kvm:
+    # Check if the exclude_host attribute is available. We want this to
+    # get accurate instruction counts in KVM.
+    main['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
+        'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host')
+
+    # Warn about missing optional functionality
+    if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']:
+        warning("perf_event headers lack support for the exclude_host "
+                "attribute. KVM instruction counts will be inaccurate.")
+
+    export_vars.append('HAVE_PERF_ATTR_EXCLUDE_HOST')
+
+main = conf.Finish()
+
+if have_kvm:
+    sticky_vars.Add(BoolVariable('USE_KVM',
+                'Enable hardware virtualized (KVM) CPU models', True))
+else:
+    main['USE_KVM'] = False
+    warning("Can not enable KVM, host seems to lack KVM support")
+
+export_vars.append('USE_KVM')
diff --git a/src/dev/net/SConsopts b/src/dev/net/SConsopts
new file mode 100644
index 0000000..ce8b168
--- /dev/null
+++ b/src/dev/net/SConsopts
@@ -0,0 +1,45 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+import gem5_scons
+
+conf = gem5_scons.Configure(main)
+
+# Check if the TUN/TAP driver is available.
+have_tuntap = conf.CheckHeader('linux/if_tun.h', '<>')
+
+main = conf.Finish()
+
+if have_tuntap:
+    sticky_vars.Add(BoolVariable('USE_TUNTAP',
+                'Enable using a tap device to bridge to the host network',
+                True))
+else:
+    print("Info: Compatible header file <linux/if_tun.h> not found.")
+    main['USE_TUNTAP'] = False
+
+export_vars.append('USE_TUNTAP')
diff --git a/src/gpu-compute/SConsopts b/src/gpu-compute/SConsopts
new file mode 100644
index 0000000..251ac5d
--- /dev/null
+++ b/src/gpu-compute/SConsopts
@@ -0,0 +1,29 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+sticky_vars.Add(BoolVariable('BUILD_GPU', 'Build the compute-GPU model',
+                             False))
diff --git a/src/mem/ruby/SConsopts b/src/mem/ruby/SConsopts
new file mode 100644
index 0000000..44938ba
--- /dev/null
+++ b/src/mem/ruby/SConsopts
@@ -0,0 +1,43 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+all_protocols = []
+Export('all_protocols')
+protocol_dirs = []
+Export('protocol_dirs')
+slicc_includes = []
+Export('slicc_includes')
+
+def add_protocols_var():
+    sticky_vars.Add(EnumVariable('PROTOCOL', 'Coherence protocol for Ruby',
+                                 'None', sorted(all_protocols)))
+AfterSConsopts(add_protocols_var)
+
+sticky_vars.Add(('NUMBER_BITS_PER_SET', 'Max elements in set (default 64)',
+                 64))
+
+export_vars.extend(['PROTOCOL', 'NUMBER_BITS_PER_SET'])
diff --git a/src/mem/ruby/protocol/SConsopts b/src/mem/ruby/protocol/SConsopts
index 104d425..8825a0e 100644
--- a/src/mem/ruby/protocol/SConsopts
+++ b/src/mem/ruby/protocol/SConsopts
@@ -48,7 +48,7 @@
     ])

 opt = BoolVariable('SLICC_HTML', 'Create HTML files', False)
-sticky_vars.AddVariables(opt)
+sticky_vars.Add(opt)

 protocol_dirs.append(Dir('.').abspath)

diff --git a/src/proto/SConsopts b/src/proto/SConsopts
new file mode 100644
index 0000000..e6a0bd5
--- /dev/null
+++ b/src/proto/SConsopts
@@ -0,0 +1,80 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+from gem5_scons import warning
+from m5.util import readCommand, compareVersions
+
+import gem5_scons
+
+conf = gem5_scons.Configure(main)
+
+# Check for the protobuf compiler
+main['HAVE_PROTOC'] = False
+protoc_version = None
+try:
+    protoc_version = readCommand([main['PROTOC'], '--version']).split()
+except Exception as e:
+    warning('While checking protoc version:', str(e))
+
+# Based on the availability of the compress stream wrappers, require 2.1.0.
+min_protoc_version = '2.1.0'
+
+# First two words should be "libprotoc x.y.z"
+if len(protoc_version) < 2 or protoc_version[0] != 'libprotoc':
+    warning('Protocol buffer compiler (protoc) not found.\n'
+            'Please install protobuf-compiler for tracing support.')
+elif compareVersions(protoc_version[1], min_protoc_version) < 0:
+    warning('protoc version', min_protoc_version, 'or newer required.\n'
+            'Installed version:', protoc_version[1])
+else:
+    # Attempt to determine the appropriate include path and
+    # library path using pkg-config, that means we also need to
+    # check for pkg-config. Note that it is possible to use
+    # protobuf without the involvement of pkg-config. Later on we
+    # check go a library config check and at that point the test
+    # will fail if libprotobuf cannot be found.
+    if main['HAVE_PKG_CONFIG']:
+        conf.CheckPkgConfig('protobuf', '--cflags', '--libs-only-L')
+    main['HAVE_PROTOC'] = True
+
+# If we have the protobuf compiler, also make sure we have the
+# development libraries. If the check passes, libprotobuf will be
+# automatically added to the LIBS environment variable. After
+# this, we can use the HAVE_PROTOBUF flag to determine if we have
+# got both protoc and libprotobuf available.
+main['HAVE_PROTOBUF'] = main['HAVE_PROTOC'] and \
+    conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h',
+                            'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;')
+
+# If we have the compiler but not the library, print another warning.
+if main['HAVE_PROTOC'] and not main['HAVE_PROTOBUF']:
+    warning('Did not find protocol buffer library and/or headers.\n'
+            'Please install libprotobuf-dev for tracing support.')
+
+main = conf.Finish()
+
+export_vars.append('HAVE_PROTOBUF')
diff --git a/src/sim/SConsopts b/src/sim/SConsopts
new file mode 100644
index 0000000..e299071
--- /dev/null
+++ b/src/sim/SConsopts
@@ -0,0 +1,41 @@
+# Copyright 2020 Google, Inc.
+#
+# 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('*')
+
+from gem5_scons import warning
+
+import gem5_scons
+
+conf = gem5_scons.Configure(main)
+
+if conf.CheckLibWithHeader([None, 'execinfo'], 'execinfo.h', 'C',
+        'char temp; backtrace_symbols_fd((void *)&temp, 0, 0);'):
+    main['BACKTRACE_IMPL'] = 'glibc'
+else:
+    main['BACKTRACE_IMPL'] = 'none'
+    warning("No suitable back trace implementation found.")
+
+main = conf.Finish()
diff --git a/src/systemc/SConsopts b/src/systemc/SConsopts
index bd9f1da..13636cd 100644
--- a/src/systemc/SConsopts
+++ b/src/systemc/SConsopts
@@ -43,9 +43,7 @@

 main.AddMethod(use_systemc_check, 'UseSystemcCheck')

-sticky_vars.AddVariables(
-    BoolVariable('USE_SYSTEMC', 'Enable SystemC API support',
-                 main.UseSystemcCheck())
-    )
+sticky_vars.Add(BoolVariable('USE_SYSTEMC', 'Enable SystemC API support',
+                             main.UseSystemcCheck()))

 export_vars.append('USE_SYSTEMC')

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40872
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ie61ceb75ae9e5557cc400603c972a9582e99c1ea
Gerrit-Change-Number: 40872
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to