config: Move KVM CPU checking to CpuConfig helper module
authorAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 28 Aug 2018 10:56:55 +0000 (11:56 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Mon, 3 Sep 2018 16:05:46 +0000 (16:05 +0000)
Both se.py and fs.py need to check if a CPU is a KVM CPU. This is
somewhat involved since CPUs can be disabled at compile time. Enable
better code reuse by moving it to the CpuConfig module.

Change-Id: I47b1512ecb62e757399a407a0e41be83b9f83be3
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/12418
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>

configs/common/CpuConfig.py
configs/example/fs.py
configs/example/se.py

index 3f193ae605cff63e280db6622daaeb00155cf31b..d70e6cfa774162bc7d3dcba32b8c61ef4a63f643 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2012, 2017 ARM Limited
+# Copyright (c) 2012, 2017-2018 ARM Limited
 # All rights reserved.
 #
 # The license below extends only to copyright in the software and shall
@@ -59,6 +59,17 @@ def is_cpu_class(cls):
     except (TypeError, AttributeError):
         return False
 
+def _cpu_subclass_tester(name):
+    cpu_class = getattr(m5.objects, name, None)
+
+    def tester(cls):
+        return cpu_class is not None and cls is not None and \
+            issubclass(cls, cpu_class)
+
+    return tester
+
+is_kvm_cpu = _cpu_subclass_tester("BaseKvmCPU")
+
 def get(name):
     """Get a CPU class from a user provided class name or alias."""
 
index 4031fd05ede91f299c6849622879b801ca095bc3..f299d761c61122762c04801e3088ea0a7ed7b1b0 100644 (file)
@@ -66,14 +66,6 @@ from common import CpuConfig
 from common.Caches import *
 from common import Options
 
-
-# Check if KVM support has been enabled, we might need to do VM
-# configuration if that's the case.
-have_kvm_support = 'BaseKvmCPU' in globals()
-def is_kvm_cpu(cpu_class):
-    return have_kvm_support and cpu_class != None and \
-        issubclass(cpu_class, BaseKvmCPU)
-
 def cmd_line_template():
     if options.command_line and options.command_line_file:
         print("Error: --command-line and --command-line-file are "
@@ -148,7 +140,7 @@ def build_test_system(np):
     test_sys.cpu = [TestCPUClass(clk_domain=test_sys.cpu_clk_domain, cpu_id=i)
                     for i in xrange(np)]
 
-    if is_kvm_cpu(TestCPUClass) or is_kvm_cpu(FutureClass):
+    if CpuConfig.is_kvm_cpu(TestCPUClass) or CpuConfig.is_kvm_cpu(FutureClass):
         test_sys.kvm_vm = KvmVM()
 
     if options.ruby:
@@ -282,7 +274,7 @@ def build_drive_system(np):
     if options.kernel is not None:
         drive_sys.kernel = binary(options.kernel)
 
-    if is_kvm_cpu(DriveCPUClass):
+    if CpuConfig.is_kvm_cpu(DriveCPUClass):
         drive_sys.kvm_vm = KvmVM()
 
     drive_sys.iobridge = Bridge(delay='50ns',
index 99d79bc575ebac0b4ac08297f75971ff6d7cde68..015a953da5a984b3dfbbd543f4447db65c6024c3 100644 (file)
@@ -65,13 +65,6 @@ from common import MemConfig
 from common.Caches import *
 from common.cpu2000 import *
 
-# Check if KVM support has been enabled, we might need to do VM
-# configuration if that's the case.
-have_kvm_support = 'BaseKvmCPU' in globals()
-def is_kvm_cpu(cpu_class):
-    return have_kvm_support and cpu_class != None and \
-        issubclass(cpu_class, BaseKvmCPU)
-
 def get_processes(options):
     """Interprets provided options and returns a list of processes"""
 
@@ -210,7 +203,7 @@ if options.elastic_trace_en:
 for cpu in system.cpu:
     cpu.clk_domain = system.cpu_clk_domain
 
-if is_kvm_cpu(CPUClass) or is_kvm_cpu(FutureClass):
+if CpuConfig.is_kvm_cpu(CPUClass) or CpuConfig.is_kvm_cpu(FutureClass):
     if buildEnv['TARGET_ISA'] == 'x86':
         system.kvm_vm = KvmVM()
         for process in multiprocesses: