Skip to content

Commit

Permalink
devlib: Use async Target API
Browse files Browse the repository at this point in the history
Make use of the new async API to speedup other parts of devlib.
  • Loading branch information
douglas-raillard-arm committed Apr 11, 2022
1 parent 77cc365 commit f92e27a
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 125 deletions.
23 changes: 14 additions & 9 deletions devlib/collector/ftrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from devlib.host import PACKAGE_BIN_DIRECTORY
from devlib.exception import TargetStableError, HostError
from devlib.utils.misc import check_output, which, memoized
from devlib.utils.asyn import asyncf


TRACE_MARKER_START = 'TRACE_MARKER_START'
Expand Down Expand Up @@ -224,7 +225,8 @@ def reset(self):
self.target.write_value(self.function_profile_file, 0, verify=False)
self._reset_needed = False

def start(self):
@asyncf
async def start(self):
self.start_time = time.time()
if self._reset_needed:
self.reset()
Expand Down Expand Up @@ -263,14 +265,17 @@ def start(self):
self.target.cpuidle.perturb_cpus()
# Enable kernel function profiling
if self.functions and self.tracer is None:
self.target.execute('echo nop > {}'.format(self.current_tracer_file),
as_root=True)
self.target.execute('echo 0 > {}'.format(self.function_profile_file),
as_root=True)
self.target.execute('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
as_root=True)
self.target.execute('echo 1 > {}'.format(self.function_profile_file),
as_root=True)
target = self.target
await target.async_manager.concurrently(
execute.asyn('echo nop > {}'.format(self.current_tracer_file),
as_root=True),
execute.asyn('echo 0 > {}'.format(self.function_profile_file),
as_root=True),
execute.asyn('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
as_root=True),
execute.asyn('echo 1 > {}'.format(self.function_profile_file),
as_root=True),
)


def stop(self):
Expand Down
24 changes: 18 additions & 6 deletions devlib/module/cgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import re
from collections import namedtuple
from shlex import quote
import asyncio

from devlib.module import Module
from devlib.exception import TargetStableError
from devlib.utils.misc import list_to_ranges, isiterable
from devlib.utils.types import boolean
from devlib.utils.asyn import asyncf


class Controller(object):
Expand Down Expand Up @@ -53,7 +55,8 @@ def __init__(self, kind, hid, clist):
self.mount_point = None
self._cgroups = {}

def mount(self, target, mount_root):
@asyncf
async def mount(self, target, mount_root):

mounted = target.list_file_systems()
if self.mount_name in [e.device for e in mounted]:
Expand All @@ -66,16 +69,16 @@ def mount(self, target, mount_root):
else:
# Mount the controller if not already in use
self.mount_point = target.path.join(mount_root, self.mount_name)
target.execute('mkdir -p {} 2>/dev/null'\
await target.execute.asyn('mkdir -p {} 2>/dev/null'\
.format(self.mount_point), as_root=True)
target.execute('mount -t cgroup -o {} {} {}'\
await target.execute.asyn('mount -t cgroup -o {} {} {}'\
.format(','.join(self.clist),
self.mount_name,
self.mount_point),
as_root=True)

# Check if this controller uses "noprefix" option
output = target.execute('mount | grep "{} "'.format(self.mount_name))
output = await target.execute.asyn('mount | grep "{} "'.format(self.mount_name))
if 'noprefix' in output:
self._noprefix = True
# self.logger.debug('Controller %s using "noprefix" option',
Expand Down Expand Up @@ -388,18 +391,27 @@ def __init__(self, target):
# Initialize controllers
self.logger.info('Available controllers:')
self.controllers = {}
for ss in subsys:

async def register_controller(ss):
hid = ss.hierarchy
controller = Controller(ss.name, hid, hierarchy[hid])
try:
controller.mount(self.target, self.cgroup_root)
await controller.mount.asyn(self.target, self.cgroup_root)
except TargetStableError:
message = 'Failed to mount "{}" controller'
raise TargetStableError(message.format(controller.kind))
self.logger.info(' %-12s : %s', controller.kind,
controller.mount_point)
self.controllers[ss.name] = controller

asyncio.run(
target.async_manager.map_concurrently(
register_controller,
subsys,
)
)


def list_subsystems(self):
subsystems = []
for line in self.target.execute('{} cat /proc/cgroups'\
Expand Down
Loading

0 comments on commit f92e27a

Please sign in to comment.