Skip to content

Commit 6844720

Browse files
devlib: Use async Target API
Make use of the new async API to speedup other parts of devlib.
1 parent 5080db0 commit 6844720

File tree

3 files changed

+169
-103
lines changed

3 files changed

+169
-103
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: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from devlib.exception import TargetStableError
2323
from devlib.utils.misc import list_to_ranges, isiterable
2424
from devlib.utils.types import boolean
25+
import devlib.utils.asyn as asyn
2526

2627

2728
class Controller(object):
@@ -53,9 +54,10 @@ def __init__(self, kind, hid, clist):
5354
self.mount_point = None
5455
self._cgroups = {}
5556

56-
def mount(self, target, mount_root):
57+
@asyn.asyncf
58+
async def mount(self, target, mount_root):
5759

58-
mounted = target.list_file_systems()
60+
mounted = await target.list_file_systems.asyn()
5961
if self.mount_name in [e.device for e in mounted]:
6062
# Identify mount point if controller is already in use
6163
self.mount_point = [
@@ -66,16 +68,18 @@ def mount(self, target, mount_root):
6668
else:
6769
# Mount the controller if not already in use
6870
self.mount_point = target.path.join(mount_root, self.mount_name)
69-
target.execute('mkdir -p {} 2>/dev/null'\
70-
.format(self.mount_point), as_root=True)
71-
target.execute('mount -t cgroup -o {} {} {}'\
72-
.format(','.join(self.clist),
73-
self.mount_name,
74-
self.mount_point),
75-
as_root=True)
71+
cmd = 'mkdir -p {mount_point} 2>/dev/null && mount -t cgroup -o {clist} {name} {mount_point}'
72+
await target.execute.asyn(
73+
cmd.format(
74+
clist=','.join(self.clist),
75+
name=self.mount_name,
76+
mount_point=self.mount_point,
77+
),
78+
as_root=True,
79+
)
7680

7781
# Check if this controller uses "noprefix" option
78-
output = target.execute('mount | grep "{} "'.format(self.mount_name))
82+
output = await target.execute.asyn('mount | grep "{} "'.format(self.mount_name))
7983
if 'noprefix' in output:
8084
self._noprefix = True
8185
# self.logger.debug('Controller %s using "noprefix" option',
@@ -386,19 +390,30 @@ def __init__(self, target):
386390
self.logger.debug('Available hierarchies: %s', hierarchy)
387391

388392
# Initialize controllers
389-
self.logger.info('Available controllers:')
390-
self.controllers = {}
391-
for ss in subsys:
393+
394+
@asyn.asyncf
395+
async def init_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)
401-
self.controllers[ss.name] = controller
405+
406+
return controller
407+
408+
self.logger.info('Available controllers:')
409+
controllers = self.target.async_manager.map_concurrently(
410+
init_controller,
411+
subsys,
412+
)
413+
self.controllers = {
414+
ss.name: controller
415+
for ss, controller in controllers.items()
416+
}
402417

403418
def list_subsystems(self):
404419
subsystems = []

0 commit comments

Comments
 (0)