Skip to content

Commit e1e4524

Browse files
devlib: Use async Target API
Make use of the new async API to speedup other parts of devlib.
1 parent 7df9305 commit e1e4524

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'
@@ -243,7 +244,8 @@ def reset(self):
243244
self.target.write_value(self.function_profile_file, 0, verify=False)
244245
self._reset_needed = False
245246

246-
def start(self):
247+
@asyncf
248+
async def start(self):
247249
self.start_time = time.time()
248250
if self._reset_needed:
249251
self.reset()
@@ -282,14 +284,17 @@ def start(self):
282284
self.target.cpuidle.perturb_cpus()
283285
# Enable kernel function profiling
284286
if self.functions and self.tracer is None:
285-
self.target.execute('echo nop > {}'.format(self.current_tracer_file),
286-
as_root=True)
287-
self.target.execute('echo 0 > {}'.format(self.function_profile_file),
288-
as_root=True)
289-
self.target.execute('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
290-
as_root=True)
291-
self.target.execute('echo 1 > {}'.format(self.function_profile_file),
292-
as_root=True)
287+
target = self.target
288+
await target.async_manager.concurrently(
289+
execute.asyn('echo nop > {}'.format(self.current_tracer_file),
290+
as_root=True),
291+
execute.asyn('echo 0 > {}'.format(self.function_profile_file),
292+
as_root=True),
293+
execute.asyn('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
294+
as_root=True),
295+
execute.asyn('echo 1 > {}'.format(self.function_profile_file),
296+
as_root=True),
297+
)
293298

294299

295300
def stop(self):

devlib/module/cgroups.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
from shlex import quote
2020
import itertools
2121
import warnings
22+
import asyncio
2223

2324
from devlib.module import Module
2425
from devlib.exception import TargetStableError
2526
from devlib.utils.misc import list_to_ranges, isiterable
2627
from devlib.utils.types import boolean
28+
from devlib.utils.asyn import asyncf
2729

2830

2931
class Controller(object):
@@ -55,7 +57,8 @@ def __init__(self, kind, hid, clist):
5557
self.mount_point = None
5658
self._cgroups = {}
5759

58-
def mount(self, target, mount_root):
60+
@asyncf
61+
async def mount(self, target, mount_root):
5962

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

7982
# Check if this controller uses "noprefix" option
80-
output = target.execute('mount | grep "{} "'.format(self.mount_name))
83+
output = await target.execute.asyn('mount | grep "{} "'.format(self.mount_name))
8184
if 'noprefix' in output:
8285
self._noprefix = True
8386
# self.logger.debug('Controller %s using "noprefix" option',
@@ -394,18 +397,27 @@ def __init__(self, target):
394397
# Initialize controllers
395398
self.logger.info('Available controllers:')
396399
self.controllers = {}
397-
for ss in subsys:
400+
401+
async def register_controller(ss):
398402
hid = ss.hierarchy
399403
controller = Controller(ss.name, hid, hierarchy[hid])
400404
try:
401-
controller.mount(self.target, self.cgroup_root)
405+
await controller.mount.asyn(self.target, self.cgroup_root)
402406
except TargetStableError:
403407
message = 'Failed to mount "{}" controller'
404408
raise TargetStableError(message.format(controller.kind))
405409
self.logger.info(' %-12s : %s', controller.kind,
406410
controller.mount_point)
407411
self.controllers[ss.name] = controller
408412

413+
asyncio.run(
414+
target.async_manager.map_concurrently(
415+
register_controller,
416+
subsys,
417+
)
418+
)
419+
420+
409421
def list_subsystems(self):
410422
subsystems = []
411423
for line in self.target.execute('{} cat /proc/cgroups'\

0 commit comments

Comments
 (0)