1919from shlex import quote
2020import itertools
2121import warnings
22+ import asyncio
2223
2324from devlib .module import Module
2425from devlib .exception import TargetStableError
2526from devlib .utils .misc import list_to_ranges , isiterable
2627from devlib .utils .types import boolean
28+ from devlib .utils .asyn import asyncf
2729
2830
2931class 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