From 411d601bed5897bfb7ae45d952e61329f02dbf95 Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Tue, 19 Jul 2022 12:39:25 +0100 Subject: [PATCH] Squashed 'external/devlib/' changes from 1196e336..ff2268b7 ff2268b7 module/cpuidle: Add listing & setting governors 5042f474 module/cgroups: Skip disabled cgroup controllers a5854269 android: Don't error if ADB is already running as root git-subtree-dir: external/devlib git-subtree-split: ff2268b715477a275d38f65d668fab96e4979421 --- devlib/module/cgroups.py | 2 +- devlib/module/cpuidle.py | 26 ++++++++++++++++++++++++++ devlib/utils/android.py | 15 ++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/devlib/module/cgroups.py b/devlib/module/cgroups.py index 6cbab19e0..b3cdb1d5d 100644 --- a/devlib/module/cgroups.py +++ b/devlib/module/cgroups.py @@ -411,7 +411,7 @@ class CgroupsModule(Module): for line in self.target.execute('{} cat /proc/cgroups'\ .format(self.target.busybox), as_root=self.target.is_rooted).splitlines()[1:]: line = line.strip() - if not line or line.startswith('#'): + if not line or line.startswith('#') or line.endswith('0'): continue name, hierarchy, num_cgroups, enabled = line.split() subsystems.append(CgroupSubsystemEntry(name, diff --git a/devlib/module/cpuidle.py b/devlib/module/cpuidle.py index 93774bee0..7b1704c73 100644 --- a/devlib/module/cpuidle.py +++ b/devlib/module/cpuidle.py @@ -19,7 +19,9 @@ from operator import attrgetter from pprint import pformat from devlib.module import Module +from devlib.exception import TargetStableError from devlib.utils.types import integer, boolean +from devlib.utils.misc import memoized class CpuidleState(object): @@ -170,8 +172,32 @@ class Cpuidle(Module): def get_driver(self): 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): + """Returns the currently selected idle governor.""" path = self.target.path.join(self.root_path, 'current_governor_ro') if not self.target.file_exists(path): path = self.target.path.join(self.root_path, 'current_governor') 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) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index 32afa96b0..b46a825d8 100755 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -385,9 +385,18 @@ class AdbConnection(ConnectionBase): def adb_root(self, enable=True): cmd = 'root' if enable else 'unroot' - output = adb_command(self.device, cmd, timeout=30, adb_server=self.adb_server) - if 'cannot run as root in production builds' in output: - raise TargetStableError(output) + try: + output = adb_command(self.device, cmd, timeout=30, adb_server=self.adb_server) + except subprocess.CalledProcessError as e: + # Ignore if we're already root + if 'adbd is already running as root' in e.output: + pass + else: + raise + else: + # Check separately as this does not cause a error exit code. + if 'cannot run as root in production builds' in output: + raise TargetStableError(output) AdbConnection._connected_as_root[self.device] = enable def wait_for_device(self, timeout=30): -- GitLab