stdlib: Add "is_kvm_core" function to AbstractCore

This function is useful in various parts of the stdlib to know if a core
is KVM or not as KVM cores requires the simulation to be setup slightly
differently.

Prior to this commit checking whether a core was a KVM core was only
possible via the CPUType which we may not always have.

Change-Id: Ibf6155ad631d5d5e93189d7376f022ea1baa685e
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62351
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
Bobby R. Bruce
2022-08-11 16:49:13 -07:00
committed by Bobby Bruce
parent d9b6a7ff9e
commit d0b2345086
5 changed files with 31 additions and 10 deletions

View File

@@ -42,6 +42,15 @@ class AbstractCore(SubSystem):
def get_isa(self) -> ISA:
raise NotImplementedError
@abstractmethod
def is_kvm_core(self) -> bool:
"""
KVM cores need setup differently than other cores. Frequently it's
useful to know whether a core is a KVM core or not. This function helps
with this.
"""
raise NotImplementedError
@abstractmethod
def connect_icache(self, port: Port) -> None:
"""

View File

@@ -54,6 +54,10 @@ class AbstractGeneratorCore(AbstractCore):
super().__init__()
self.port_end = PortTerminator()
@overrides(AbstractCore)
def is_kvm_core(self) -> bool:
return False
@overrides(AbstractCore)
def get_isa(self) -> ISA:
return ISA.NULL

View File

@@ -60,6 +60,18 @@ class BaseCPUCore(AbstractCore):
return self.core
@overrides(AbstractCore)
def is_kvm_core(self) -> bool:
try:
from m5.objects import BaseKvmCPU
return isinstance(self.core, BaseKvmCPU)
except ImportError:
# If importing BaseKvmCPU throws an exception then it's because
# it's not compiled into the binary. If this is the case then this
# can't be a KVM core.
return False
def get_isa(self) -> ISA:
return self._isa

View File

@@ -68,12 +68,10 @@ class SwitchableProcessor(AbstractProcessor):
core.set_switched_out(core not in self._current_cores)
all_cores.append(core)
self._prepare_kvm = CPUTypes.KVM in [
core.get_type() for core in all_cores
]
self._prepare_kvm = any(core.is_kvm_core() for core in all_cores)
if self._prepare_kvm:
if all_cores[0].get_type() != CPUTypes.KVM:
if not all_cores[0].is_kvm_core():
raise Exception(
"When using KVM, the switchable processor must start "
"with the KVM cores."
@@ -98,9 +96,7 @@ class SwitchableProcessor(AbstractProcessor):
# To get the KVM CPUs to run on different host CPUs
# Specify a different event queue for each CPU
kvm_cores = [
core for core in self.cores if core.get_type() == CPUTypes.KVM
]
kvm_cores = [core for core in self.cores if core.is_kvm_core()]
for i, core in enumerate(kvm_cores):
for obj in core.get_simobject().descendants():
obj.eventq_index = 0

View File

@@ -283,10 +283,10 @@ class Simulator:
# (for example, in `get_stats()`).
self._root = root
if CPUTypes.KVM in [
core.get_type()
if any(
core.is_kvm_core()
for core in self._board.get_processor().get_cores()
]:
):
m5.ticks.fixGlobalFrequency()
root.sim_quantum = m5.ticks.fromSeconds(0.001)