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