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:
committed by
Bobby Bruce
parent
d9b6a7ff9e
commit
d0b2345086
@@ -42,6 +42,15 @@ class AbstractCore(SubSystem):
|
|||||||
def get_isa(self) -> ISA:
|
def get_isa(self) -> ISA:
|
||||||
raise NotImplementedError
|
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
|
@abstractmethod
|
||||||
def connect_icache(self, port: Port) -> None:
|
def connect_icache(self, port: Port) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ class AbstractGeneratorCore(AbstractCore):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.port_end = PortTerminator()
|
self.port_end = PortTerminator()
|
||||||
|
|
||||||
|
@overrides(AbstractCore)
|
||||||
|
def is_kvm_core(self) -> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
@overrides(AbstractCore)
|
@overrides(AbstractCore)
|
||||||
def get_isa(self) -> ISA:
|
def get_isa(self) -> ISA:
|
||||||
return ISA.NULL
|
return ISA.NULL
|
||||||
|
|||||||
@@ -60,6 +60,18 @@ class BaseCPUCore(AbstractCore):
|
|||||||
return self.core
|
return self.core
|
||||||
|
|
||||||
@overrides(AbstractCore)
|
@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:
|
def get_isa(self) -> ISA:
|
||||||
return self._isa
|
return self._isa
|
||||||
|
|
||||||
|
|||||||
@@ -68,12 +68,10 @@ class SwitchableProcessor(AbstractProcessor):
|
|||||||
core.set_switched_out(core not in self._current_cores)
|
core.set_switched_out(core not in self._current_cores)
|
||||||
all_cores.append(core)
|
all_cores.append(core)
|
||||||
|
|
||||||
self._prepare_kvm = CPUTypes.KVM in [
|
self._prepare_kvm = any(core.is_kvm_core() for core in all_cores)
|
||||||
core.get_type() for core in all_cores
|
|
||||||
]
|
|
||||||
|
|
||||||
if self._prepare_kvm:
|
if self._prepare_kvm:
|
||||||
if all_cores[0].get_type() != CPUTypes.KVM:
|
if not all_cores[0].is_kvm_core():
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"When using KVM, the switchable processor must start "
|
"When using KVM, the switchable processor must start "
|
||||||
"with the KVM cores."
|
"with the KVM cores."
|
||||||
@@ -98,9 +96,7 @@ class SwitchableProcessor(AbstractProcessor):
|
|||||||
|
|
||||||
# To get the KVM CPUs to run on different host CPUs
|
# To get the KVM CPUs to run on different host CPUs
|
||||||
# Specify a different event queue for each CPU
|
# Specify a different event queue for each CPU
|
||||||
kvm_cores = [
|
kvm_cores = [core for core in self.cores if core.is_kvm_core()]
|
||||||
core for core in self.cores if core.get_type() == CPUTypes.KVM
|
|
||||||
]
|
|
||||||
for i, core in enumerate(kvm_cores):
|
for i, core in enumerate(kvm_cores):
|
||||||
for obj in core.get_simobject().descendants():
|
for obj in core.get_simobject().descendants():
|
||||||
obj.eventq_index = 0
|
obj.eventq_index = 0
|
||||||
|
|||||||
@@ -283,10 +283,10 @@ class Simulator:
|
|||||||
# (for example, in `get_stats()`).
|
# (for example, in `get_stats()`).
|
||||||
self._root = root
|
self._root = root
|
||||||
|
|
||||||
if CPUTypes.KVM in [
|
if any(
|
||||||
core.get_type()
|
core.is_kvm_core()
|
||||||
for core in self._board.get_processor().get_cores()
|
for core in self._board.get_processor().get_cores()
|
||||||
]:
|
):
|
||||||
m5.ticks.fixGlobalFrequency()
|
m5.ticks.fixGlobalFrequency()
|
||||||
root.sim_quantum = m5.ticks.fromSeconds(0.001)
|
root.sim_quantum = m5.ticks.fromSeconds(0.001)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user