1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

module/cpuidle: Add listing & setting governors

Add support for listing the currently available idle governors and
setting the currently used one through sysfs.
This commit is contained in:
Kajetan Puchalski 2022-07-18 14:12:16 +01:00 committed by Marc Bonnici
parent 5042f474c2
commit ff2268b715

View File

@ -19,7 +19,9 @@ from operator import attrgetter
from pprint import pformat from pprint import pformat
from devlib.module import Module from devlib.module import Module
from devlib.exception import TargetStableError
from devlib.utils.types import integer, boolean from devlib.utils.types import integer, boolean
from devlib.utils.misc import memoized
class CpuidleState(object): class CpuidleState(object):
@ -170,8 +172,32 @@ class Cpuidle(Module):
def get_driver(self): def get_driver(self):
return self.target.read_value(self.target.path.join(self.root_path, 'current_driver')) return self.target.read_value(self.target.path.join(self.root_path, 'current_driver'))
@memoized
def list_governors(self):
"""Returns a list of supported idle governors."""
sysfile = self.target.path.join(self.root_path, 'available_governors')
output = self.target.read_value(sysfile)
return output.strip().split()
def get_governor(self): def get_governor(self):
"""Returns the currently selected idle governor."""
path = self.target.path.join(self.root_path, 'current_governor_ro') path = self.target.path.join(self.root_path, 'current_governor_ro')
if not self.target.file_exists(path): if not self.target.file_exists(path):
path = self.target.path.join(self.root_path, 'current_governor') path = self.target.path.join(self.root_path, 'current_governor')
return self.target.read_value(path) return self.target.read_value(path)
def set_governor(self, governor):
"""
Set the idle governor for the system.
:param governor: The name of the governor to be used. This must be
supported by the specific device.
:raises TargetStableError if governor is not supported by the CPU, or
if, for some reason, the governor could not be set.
"""
supported = self.list_governors()
if governor not in supported:
raise TargetStableError('Governor {} not supported'.format(governor))
sysfile = self.target.path.join(self.root_path, 'current_governor')
self.target.write_value(sysfile, governor)