1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-19 04:21:17 +00:00

fw/target: enhanced cpu info

Replace Target.cpuinfo, which contained parsed contents of
/proc/cpuinfo, with a list of more comprehensive CpuInfo objects which
include cpufreq and cpuidle information as well.
This commit is contained in:
sergei Trofimov 2018-04-30 17:45:24 +01:00 committed by Marc Bonnici
parent 2d39e5699f
commit 84fba8617d

View File

@ -1,3 +1,5 @@
from copy import copy
from devlib import AndroidTarget from devlib import AndroidTarget
from devlib.target import KernelConfig, KernelVersion, Cpuinfo from devlib.target import KernelConfig, KernelVersion, Cpuinfo
from devlib.utils.android import AndroidProperties from devlib.utils.android import AndroidProperties
@ -42,10 +44,121 @@ def kernel_config_from_pod(pod):
return config return config
class CpufreqInfo(object):
@staticmethod
def from_pod(pod):
return CpufreqInfo(**pod)
def __init__(self, **kwargs):
self.available_frequencies = kwargs.pop('available_frequencies', [])
self.available_governors = kwargs.pop('available_governors', [])
self.related_cpus = kwargs.pop('related_cpus', [])
self.driver = kwargs.pop('driver', None)
def to_pod(self):
return copy(self.__dict__)
def __repr__(self):
return 'Cpufreq({} {})'.format(self.driver, self.related_cpus)
__str__ = __repr__
class IdleStateInfo(object):
@staticmethod
def from_pod(pod):
return IdleStateInfo(**pod)
def __init__(self, **kwargs):
self.name = kwargs.pop('name', None)
self.desc = kwargs.pop('desc', None)
self.power = kwargs.pop('power', None)
self.latency = kwargs.pop('latency', None)
def to_pod(self):
return copy(self.__dict__)
def __repr__(self):
return 'IdleState({}/{})'.format(self.name, self.desc)
__str__ = __repr__
class CpuidleInfo(object):
@staticmethod
def from_pod(pod):
instance = CpuidleInfo()
instance.governor = pod['governor']
instance.driver = pod['driver']
instance.states = [IdleStateInfo.from_pod(s) for s in pod['states']]
return instance
@property
def num_states(self):
return len(self.states)
def __init__(self):
self.governor = None
self.driver = None
self.states = []
def to_pod(self):
pod = {}
pod['governor'] = self.governor
pod['driver'] = self.driver
pod['states'] = [s.to_pod() for s in self.states]
return pod
def __repr__(self):
return 'Cpuidle({}/{} {} states)'.format(
self.governor, self.driver, self.num_states)
__str__ = __repr__
class CpuInfo(object):
@staticmethod
def from_pod(pod):
instance = CpuInfo()
instance.id = pod['id']
instance.name = pod['name']
instance.architecture = pod['architecture']
instance.features = pod['features']
instance.cpufreq = CpufreqInfo.from_pod(pod['cpufreq'])
instance.cpuidle = CpuidleInfo.from_pod(pod['cpuidle'])
return instance
def __init__(self):
self.id = None
self.name = None
self.architecture = None
self.features = []
self.cpufreq = CpufreqInfo()
self.cpuidle = CpuidleInfo()
def to_pod(self):
pod = {}
pod['id'] = self.id
pod['name'] = self.name
pod['architecture'] = self.architecture
pod['features'] = self.features
pod['cpufreq'] = self.cpufreq.to_pod()
pod['cpuidle'] = self.cpuidle.to_pod()
return pod
def __repr__(self):
return 'Cpu({} {})'.format(self.id, self.name)
__str__ = __repr__
def get_target_info(target): def get_target_info(target):
info = TargetInfo() info = TargetInfo()
info.target = target.__class__.__name__ info.target = target.__class__.__name__
info.cpuinfo = target.cpuinfo
info.os = target.os info.os = target.os
info.os_version = target.os_version info.os_version = target.os_version
info.abi = target.abi info.abi = target.abi
@ -53,6 +166,32 @@ def get_target_info(target):
info.kernel_version = target.kernel_version info.kernel_version = target.kernel_version
info.kernel_config = target.config info.kernel_config = target.config
for i, name in enumerate(target.cpuinfo.cpu_names):
cpu = CpuInfo()
cpu.id = i
cpu.name = name
cpu.features = target.cpuinfo.get_cpu_features(i)
cpu.architecture = target.cpuinfo.architecture
if target.has('cpufreq'):
cpu.cpufreq.available_governors = target.cpufreq.list_governors(i)
cpu.cpufreq.available_frequencies = target.cpufreq.list_frequencies(i)
cpu.cpufreq.related_cpus = target.cpufreq.get_related_cpus(i)
cpu.cpufreq.driver = target.cpufreq.get_driver(i)
if target.has('cpuidle'):
cpu.cpuidle.driver = target.cpuidle.get_driver()
cpu.cpuidle.governor = target.cpuidle.get_governor()
for state in target.cpuidle.get_states(i):
state_info = IdleStateInfo()
state_info.name = state.name
state_info.desc = state.desc
state_info.power = state.power
state_info.latency = state.latency
cpu.cpuidle.states.append(state_info)
info.cpus.append(cpu)
if isinstance(target, AndroidTarget): if isinstance(target, AndroidTarget):
info.screen_resolution = target.screen_resolution info.screen_resolution = target.screen_resolution
info.prop = target.getprop() info.prop = target.getprop()
@ -68,7 +207,7 @@ class TargetInfo(object):
instance = TargetInfo() instance = TargetInfo()
instance.target = pod['target'] instance.target = pod['target']
instance.abi = pod['abi'] instance.abi = pod['abi']
instance.cpuinfo = cpuinfo_from_pod(pod) instance.cpus = [CpuInfo.from_pod(c) for c in pod['cpus']]
instance.os = pod['os'] instance.os = pod['os']
instance.os_version = pod['os_version'] instance.os_version = pod['os_version']
instance.abi = pod['abi'] instance.abi = pod['abi']
@ -85,7 +224,7 @@ class TargetInfo(object):
def __init__(self): def __init__(self):
self.target = None self.target = None
self.cpuinfo = None self.cpus = []
self.os = None self.os = None
self.os_version = None self.os_version = None
self.abi = None self.abi = None
@ -97,7 +236,7 @@ class TargetInfo(object):
pod = {} pod = {}
pod['target'] = self.target pod['target'] = self.target
pod['abi'] = self.abi pod['abi'] = self.abi
pod['cpuinfo'] = self.cpuinfo.sections pod['cpus'] = [c.to_pod() for c in self.cpus]
pod['os'] = self.os pod['os'] = self.os
pod['os_version'] = self.os_version pod['os_version'] = self.os_version
pod['abi'] = self.abi pod['abi'] = self.abi