19
19
from shlex import quote
20
20
import itertools
21
21
import warnings
22
+ import asyncio
22
23
23
24
from devlib .module import Module
24
25
from devlib .exception import TargetStableError
25
26
from devlib .utils .misc import list_to_ranges , isiterable
26
27
from devlib .utils .types import boolean
28
+ from devlib .utils .asyn import asyncf
27
29
28
30
29
31
class Controller (object ):
@@ -55,7 +57,8 @@ def __init__(self, kind, hid, clist):
55
57
self .mount_point = None
56
58
self ._cgroups = {}
57
59
58
- def mount (self , target , mount_root ):
60
+ @asyncf
61
+ async def mount (self , target , mount_root ):
59
62
60
63
mounted = target .list_file_systems ()
61
64
if self .mount_name in [e .device for e in mounted ]:
@@ -68,16 +71,16 @@ def mount(self, target, mount_root):
68
71
else :
69
72
# Mount the controller if not already in use
70
73
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' \
72
75
.format (self .mount_point ), as_root = True )
73
- target .execute ('mount -t cgroup -o {} {} {}' \
76
+ await target .execute . asyn ('mount -t cgroup -o {} {} {}' \
74
77
.format (',' .join (self .clist ),
75
78
self .mount_name ,
76
79
self .mount_point ),
77
80
as_root = True )
78
81
79
82
# 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 ))
81
84
if 'noprefix' in output :
82
85
self ._noprefix = True
83
86
# self.logger.debug('Controller %s using "noprefix" option',
@@ -394,18 +397,27 @@ def __init__(self, target):
394
397
# Initialize controllers
395
398
self .logger .info ('Available controllers:' )
396
399
self .controllers = {}
397
- for ss in subsys :
400
+
401
+ async def register_controller (ss ):
398
402
hid = ss .hierarchy
399
403
controller = Controller (ss .name , hid , hierarchy [hid ])
400
404
try :
401
- controller .mount (self .target , self .cgroup_root )
405
+ await controller .mount . asyn (self .target , self .cgroup_root )
402
406
except TargetStableError :
403
407
message = 'Failed to mount "{}" controller'
404
408
raise TargetStableError (message .format (controller .kind ))
405
409
self .logger .info (' %-12s : %s' , controller .kind ,
406
410
controller .mount_point )
407
411
self .controllers [ss .name ] = controller
408
412
413
+ asyncio .run (
414
+ target .async_manager .map_concurrently (
415
+ register_controller ,
416
+ subsys ,
417
+ )
418
+ )
419
+
420
+
409
421
def list_subsystems (self ):
410
422
subsystems = []
411
423
for line in self .target .execute ('{} cat /proc/cgroups' \
0 commit comments