Skip to content

Commit 659a4ff

Browse files
devlib: Use async Target API
Make use of the new async API to speedup other parts of devlib.
1 parent 3adec4e commit 659a4ff

File tree

4 files changed

+205
-125
lines changed

4 files changed

+205
-125
lines changed

devlib/collector/ftrace.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from devlib.host import PACKAGE_BIN_DIRECTORY
2929
from devlib.exception import TargetStableError, HostError
3030
from devlib.utils.misc import check_output, which, memoized
31+
from devlib.utils.asyn import asyncf
3132

3233

3334
TRACE_MARKER_START = 'TRACE_MARKER_START'
@@ -224,7 +225,8 @@ def reset(self):
224225
self.target.write_value(self.function_profile_file, 0, verify=False)
225226
self._reset_needed = False
226227

227-
def start(self):
228+
@asyncf
229+
async def start(self):
228230
self.start_time = time.time()
229231
if self._reset_needed:
230232
self.reset()
@@ -263,14 +265,17 @@ def start(self):
263265
self.target.cpuidle.perturb_cpus()
264266
# Enable kernel function profiling
265267
if self.functions and self.tracer is None:
266-
self.target.execute('echo nop > {}'.format(self.current_tracer_file),
267-
as_root=True)
268-
self.target.execute('echo 0 > {}'.format(self.function_profile_file),
269-
as_root=True)
270-
self.target.execute('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
271-
as_root=True)
272-
self.target.execute('echo 1 > {}'.format(self.function_profile_file),
273-
as_root=True)
268+
target = self.target
269+
await target.async_manager.concurrently(
270+
execute.asyn('echo nop > {}'.format(self.current_tracer_file),
271+
as_root=True),
272+
execute.asyn('echo 0 > {}'.format(self.function_profile_file),
273+
as_root=True),
274+
execute.asyn('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
275+
as_root=True),
276+
execute.asyn('echo 1 > {}'.format(self.function_profile_file),
277+
as_root=True),
278+
)
274279

275280

276281
def stop(self):

devlib/module/cgroups.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import re
1818
from collections import namedtuple
1919
from shlex import quote
20+
import asyncio
2021

2122
from devlib.module import Module
2223
from devlib.exception import TargetStableError
2324
from devlib.utils.misc import list_to_ranges, isiterable
2425
from devlib.utils.types import boolean
26+
from devlib.utils.asyn import asyncf
2527

2628

2729
class Controller(object):
@@ -53,7 +55,8 @@ def __init__(self, kind, hid, clist):
5355
self.mount_point = None
5456
self._cgroups = {}
5557

56-
def mount(self, target, mount_root):
58+
@asyncf
59+
async def mount(self, target, mount_root):
5760

5861
mounted = target.list_file_systems()
5962
if self.mount_name in [e.device for e in mounted]:
@@ -66,16 +69,16 @@ def mount(self, target, mount_root):
6669
else:
6770
# Mount the controller if not already in use
6871
self.mount_point = target.path.join(mount_root, self.mount_name)
69-
target.execute('mkdir -p {} 2>/dev/null'\
72+
await target.execute.asyn('mkdir -p {} 2>/dev/null'\
7073
.format(self.mount_point), as_root=True)
71-
target.execute('mount -t cgroup -o {} {} {}'\
74+
await target.execute.asyn('mount -t cgroup -o {} {} {}'\
7275
.format(','.join(self.clist),
7376
self.mount_name,
7477
self.mount_point),
7578
as_root=True)
7679

7780
# Check if this controller uses "noprefix" option
78-
output = target.execute('mount | grep "{} "'.format(self.mount_name))
81+
output = await target.execute.asyn('mount | grep "{} "'.format(self.mount_name))
7982
if 'noprefix' in output:
8083
self._noprefix = True
8184
# self.logger.debug('Controller %s using "noprefix" option',
@@ -388,18 +391,27 @@ def __init__(self, target):
388391
# Initialize controllers
389392
self.logger.info('Available controllers:')
390393
self.controllers = {}
391-
for ss in subsys:
394+
395+
async def register_controller(ss):
392396
hid = ss.hierarchy
393397
controller = Controller(ss.name, hid, hierarchy[hid])
394398
try:
395-
controller.mount(self.target, self.cgroup_root)
399+
await controller.mount.asyn(self.target, self.cgroup_root)
396400
except TargetStableError:
397401
message = 'Failed to mount "{}" controller'
398402
raise TargetStableError(message.format(controller.kind))
399403
self.logger.info(' %-12s : %s', controller.kind,
400404
controller.mount_point)
401405
self.controllers[ss.name] = controller
402406

407+
asyncio.run(
408+
target.async_manager.map_concurrently(
409+
register_controller,
410+
subsys,
411+
)
412+
)
413+
414+
403415
def list_subsystems(self):
404416
subsystems = []
405417
for line in self.target.execute('{} cat /proc/cgroups'\

0 commit comments

Comments
 (0)