Skip to content

Commit

Permalink
wp.device: Use lisa.Target instead of ppadb
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkajetanp committed Aug 21, 2023
1 parent 7b27cbd commit 6072fc8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 70 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ packages = find:
exclude = ['agendas', 'assets']
install_requires =
plotly == 5.15.0
pure-python-adb == 0.3.0.dev0
tabulate == 0.9.0
confuse==2.0.1
polars==0.17.12
Expand Down
131 changes: 63 additions & 68 deletions wp/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

import os
import sys
import time
import logging as log
import confuse
import subprocess

from ppadb.client import Client as AdbClient
from devlib.exception import TargetStableError
from typing import List

from lisa.target import Target, TargetConf
from pathlib import Path
from devlib.exception import TargetStableCalledProcessError

from wp.constants import APP_NAME

Expand All @@ -33,27 +34,14 @@ class WorkloadDevice:
def __init__(self):
self.config = confuse.Configuration(APP_NAME, __name__)
"""Handle for the `Confuse` configuration object."""
self.adb_client = AdbClient(host=self.config['host']['adb_host'].get(str),
port=int(self.config['host']['adb_port'].get(int)))
"""Handle for the ADB client"""
self.device = None
"""Handle for the ADB device"""
try:
self.device = self.adb_client.devices()[0]
except IndexError:
raise TargetStableError('No target devices found')

log.debug('Restarting adb as root')
try:
self.device.root()
log.info('ADB restarted as root')
except RuntimeError as e:
log.error(e)

# Give ADB on device a moment to initialise
time.sleep(3)
self.device = Target.from_conf(
TargetConf.from_yaml_map(
Path(self.config['target']['target_conf'].get()).expanduser()
)
)
"""Handle for the Target device"""

self.device.shell("setenforce 0")
self.device.execute("setenforce 0", as_root=True)

def dispatch(self, command: str):
"""
Expand All @@ -75,65 +63,72 @@ def command_to_function(cmd):

def status(self):
log.info('Showing current device status')
kernel_version = self.device.shell("uname -a").strip().split()[2]
kernel_version = self.device.execute("uname -a").strip().split()[2]
log.info(f'Kernel version {kernel_version}')

selinux = self.device.shell("getenforce").strip()
selinux = self.device.execute("getenforce").strip()
log.info(f'SELinux status: {selinux}')

module_present = bool(self.device.shell('lsmod | grep lisa'))
module_present = bool(self.device.execute('lsmod | grep lisa'))
log.info(f"Lisa module {'' if module_present else 'not '}loaded")

big_temp = self.device.shell("cat /sys/class/thermal/thermal_zone0/temp").strip()
mid_temp = self.device.shell("cat /sys/class/thermal/thermal_zone1/temp").strip()
ltl_temp = self.device.shell("cat /sys/class/thermal/thermal_zone2/temp").strip()
tz_cmd = "cat /sys/class/thermal/thermal_zone{}/temp"
big_temp = self.device.execute(tz_cmd.format(0)).strip()
mid_temp = self.device.execute(tz_cmd.format(1)).strip()
ltl_temp = self.device.execute(tz_cmd.format(2)).strip()
log.info(f"Temperature: BIG {big_temp} MID {mid_temp} LTL {ltl_temp}")

ltl_cpufreq = self.device.shell("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor").strip()
mid_cpufreq = self.device.shell("cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor").strip()
big_cpufreq = self.device.shell("cat /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor").strip()
log.info(f"cpufreq governor: BIG {big_cpufreq} MID {mid_cpufreq} LTL {ltl_cpufreq}")
cpufreq_cmd = "cat /sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor"
ltl_cpufreq = self.device.execute(cpufreq_cmd.format(0)).strip()
mid_cpufreq = self.device.execute(cpufreq_cmd.format(4)).strip()
big_cpufreq = self.device.execute(cpufreq_cmd.format(6)).strip()
log.info(f"BIG {big_cpufreq} MID {mid_cpufreq} LTL {ltl_cpufreq}")

ls_system = self.device.shell("cat /dev/cpuctl/system/cpu.uclamp.latency_sensitive").strip()
ls_fg = self.device.shell("cat /dev/cpuctl/foreground/cpu.uclamp.latency_sensitive").strip()
ls_bg = self.device.shell("cat /dev/cpuctl/background/cpu.uclamp.latency_sensitive").strip()
ls_sysbg = self.device.shell("cat /dev/cpuctl/system-background/cpu.uclamp.latency_sensitive").strip()
ls_system = self.device.execute("cat /dev/cpuctl/system/cpu.uclamp.latency_sensitive").strip()
ls_fg = self.device.execute("cat /dev/cpuctl/foreground/cpu.uclamp.latency_sensitive").strip()
ls_bg = self.device.execute("cat /dev/cpuctl/background/cpu.uclamp.latency_sensitive").strip()
ls_sysbg = self.device.execute("cat /dev/cpuctl/system-background/cpu.uclamp.latency_sensitive").strip()
log.info(f"latency_sensitive system: {ls_system} fg: {ls_fg} bg: {ls_bg} sys-bg: {ls_sysbg}")

idle_governor = self.device.shell("cat /sys/devices/system/cpu/cpuidle/current_governor_ro").strip()
idle_governor = self.device.execute("cat /sys/devices/system/cpu/cpuidle/current_governor_ro").strip()
log.info(f"cpuidle governor: {idle_governor}")

# TODO: use cgroups in config
cpuset_bg = self.device.shell("cat /dev/cpuset/background/cpus").strip()
cpuset_fg = self.device.shell("cat /dev/cpuset/foreground/cpus").strip()
cpuset_sbg = self.device.shell("cat /dev/cpuset/system-background/cpus").strip()
cpuset_bg = self.device.execute("cat /dev/cpuset/background/cpus").strip()
cpuset_fg = self.device.execute("cat /dev/cpuset/foreground/cpus").strip()
cpuset_sbg = self.device.execute("cat /dev/cpuset/system-background/cpus").strip()
log.info(f"cpusets: background: {cpuset_bg}, foreground: {cpuset_fg}, system-bg: {cpuset_sbg}")

cpushares_bg = self.device.shell("cat /dev/cpuctl/background/cpu.shares").strip()
cpushares_fg = self.device.shell("cat /dev/cpuctl/foreground/cpu.shares").strip()
cpushares_sbg = self.device.shell("cat /dev/cpuctl/system-background/cpu.shares").strip()
cpushares_sys = self.device.shell("cat /dev/cpuctl/system/cpu.shares").strip()
cpushares_bg = self.device.execute("cat /dev/cpuctl/background/cpu.shares").strip()
cpushares_fg = self.device.execute("cat /dev/cpuctl/foreground/cpu.shares").strip()
cpushares_sbg = self.device.execute("cat /dev/cpuctl/system-background/cpu.shares").strip()
cpushares_sys = self.device.execute("cat /dev/cpuctl/system/cpu.shares").strip()
log.info(f"cpushares: bg: {cpushares_bg} fg: {cpushares_fg} sys: {cpushares_sys} sys-bg: {cpushares_sbg}")

if 'schedutil' in [ltl_cpufreq, mid_cpufreq, big_cpufreq]:
pol_0_rl = self.device.shell("cat /sys/devices/system/cpu/cpufreq/policy0/schedutil/rate_limit_us").strip()
pol_4_rl = self.device.shell("cat /sys/devices/system/cpu/cpufreq/policy4/schedutil/rate_limit_us").strip()
pol_6_rl = self.device.shell("cat /sys/devices/system/cpu/cpufreq/policy6/schedutil/rate_limit_us").strip()
su_rate_cmd = "cat /sys/devices/system/cpu/cpufreq/policy{}/schedutil/rate_limit_us"
pol_0_rl = self.device.execute(su_rate_cmd.format(0)).strip()
pol_4_rl = self.device.execute(su_rate_cmd.format(4)).strip()
pol_6_rl = self.device.execute(su_rate_cmd.format(6)).strip()
log.info(f"policy rate limits: 0: {pol_0_rl}, 4: {pol_4_rl}, 6: {pol_6_rl}")

def load_module(self):
# Try to load the module using modprobe (for in-tree builds
log.debug('Loading the Lisa module')
self.device.shell("rmmod lisa")
try:
self.device.execute("rmmod lisa", as_root=True)
except TargetStableCalledProcessError:
pass

modules_base_path = self.config['target']['modules_path'].get()
modules_dir_count = int(self.device.shell(f"ls {modules_base_path} | wc -l").strip())
modules_dir_count = int(self.device.execute(f"ls {modules_base_path} | wc -l").strip())
modules_dir_version_cmd = f"ls {modules_base_path} | head -1" if modules_dir_count == 1 else 'uname -r'
modules_dir_version = self.device.shell(modules_dir_version_cmd).strip()
modules_dir_version = self.device.execute(modules_dir_version_cmd).strip()
modules_path = os.path.join(modules_base_path, modules_dir_version)
self.device.shell(f"modprobe -d {modules_path} lisa")
self.device.execute(f"modprobe -d {modules_path} lisa", as_root=True)

# check if the lisa module is loaded
module_present = bool(self.device.shell('lsmod | grep lisa'))
module_present = bool(self.device.execute('lsmod | grep lisa'))
if module_present:
log.info('Lisa module loaded successfully from the target device')
return
Expand All @@ -148,45 +143,45 @@ def load_module(self):
sys.stdout.buffer.write(c)

def disable_cpusets(self):
log.info('Disabling cpusets for groups background, foreground, system-background and restricted')
self.device.shell("echo '0-7' > /dev/cpuset/background/cpus")
self.device.shell("echo '0-7' > /dev/cpuset/foreground/cpus")
self.device.shell("echo '0-7' > /dev/cpuset/system-background/cpus")
self.device.shell("echo '0-7' > /dev/cpuset/restricted/cpus")
groups: List[str] = self.config['target']['cgroups'].get()
log.info(f'Disabling cpusets for groups {", ".join(groups)}')
for group in groups:
self.device.execute(f"echo '0-7' > /dev/cpuset/{group}/cpus")

def disable_cpushares(self):
log.info('Setting cpushares to 20480 for groups background and system-background')
self.device.shell("echo 20480 > /dev/cpuctl/background/cpu.shares")
self.device.shell("echo 20480 > /dev/cpuctl/system-background/cpu.shares")
groups: List[str] = self.config['target']['cgroups'].get()
log.info(f'Setting cpushares to 20480 for groups {", ".join(groups)}')
for group in groups:
self.device.execute(f"echo 20480 > /dev/cpuctl/{group}/cpu.shares")

def menu(self):
log.info('Setting the current cpuidle governor to menu')
self.device.shell("echo 'menu' > /sys/devices/system/cpu/cpuidle/current_governor")
self.device.execute("echo 'menu' > /sys/devices/system/cpu/cpuidle/current_governor")

def teo(self):
log.info('Setting the current cpuidle governor to teo')
self.device.shell("echo 'teo' > /sys/devices/system/cpu/cpuidle/current_governor")
self.device.execute("echo 'teo' > /sys/devices/system/cpu/cpuidle/current_governor")

def latency_sensitive(self):
log.info('Setting the system cgroup to latency sensitive')
self.device.shell("echo 1 > /dev/cpuctl/system/cpu.uclamp.latency_sensitive")
self.device.execute("echo 1 > /dev/cpuctl/system/cpu.uclamp.latency_sensitive")

def powersave(self):
log.info('Setting the cpufreq governor to powersave')
for cpu in range(8):
self.device.shell(f"echo 'powersave' > /sys/devices/system/cpu/cpu{cpu}/cpufreq/scaling_governor")
self.device.execute(f"echo 'powersave' > /sys/devices/system/cpu/cpu{cpu}/cpufreq/scaling_governor")

def performance(self):
log.info('Setting the cpufreq governor to performance')
for cpu in range(8):
self.device.shell(f"echo 'performance' > /sys/devices/system/cpu/cpu{cpu}/cpufreq/scaling_governor")
self.device.execute(f"echo 'performance' > /sys/devices/system/cpu/cpu{cpu}/cpufreq/scaling_governor")

def schedutil(self):
log.info('Setting the cpufreq governor to schedutil')
for cpu in range(8):
self.device.shell(f"echo 'schedutil' > /sys/devices/system/cpu/cpu{cpu}/cpufreq/scaling_governor")
self.device.execute(f"echo 'schedutil' > /sys/devices/system/cpu/cpu{cpu}/cpufreq/scaling_governor")

def sugov_rate_limit(self):
log.info('Setting the sugov rate limit to 500')
for policy in [0, 4, 6]:
self.device.shell(f"echo '500' > /sys/devices/system/cpu/cpufreq/policy{policy}/schedutil/rate_limit_us")
self.device.execute(f"echo '500' > /sys/devices/system/cpu/cpufreq/policy{policy}/schedutil/rate_limit_us")
1 change: 0 additions & 1 deletion wp/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from wp.device import WorkloadDevice


# TODO: use devlib target to make this platform-agnostic
class WorkloadRunner:
"""The runner class that performs setup and dispatches the run to `workload-automation`."""

Expand Down

0 comments on commit 6072fc8

Please sign in to comment.