From afe889af2b7dd13904cd2ce9f401a0221b047b3d Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 21 Nov 2017 11:58:11 -0800 Subject: mpm: mg: Optionally parallelize init calls to dboard Default is to run in parallel. serialize_init=1 will run them serially. Reviewed-By: Brent Stapleton --- mpm/python/usrp_mpm/periph_manager/base.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'mpm') diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index f5b3f39e8..3cfcc0ce8 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -20,6 +20,7 @@ Mboard implementation base class from __future__ import print_function import os +from concurrent import futures from hashlib import md5 from builtins import str from builtins import range @@ -323,7 +324,8 @@ class PeriphManagerBase(object): all RFNoC blocks must be reachable via CHDR interfaces (i.e., clocks need to be on). - Return False on failure, True on success. + Return False on failure, True on success. If daughterboard inits return + False (any of them), this will also return False. args -- A dictionary of args for initialization. Similar to device args in UHD. @@ -336,8 +338,22 @@ class PeriphManagerBase(object): "Cannot run init(), device was never fully initialized!") return False self._init_args = args - self.log.debug("Initializing dboards...") - return all((dboard.init(args) for dboard in self.dboards)) + if len(self.dboards) == 0: + return True + if args.get("serialize_init", False): + self.log.debug("Initializing dboards serially...") + return all((dboard.init(args) for dboard in self.dboards)) + self.log.debug("Initializing dboards in parallel...") + num_workers = len(self.dboards) + with futures.ThreadPoolExecutor(max_workers=num_workers) as executor: + init_futures = [ + executor.submit(dboard.init, args) + for dboard in self.dboards + ] + return all([ + x.result() + for x in futures.as_completed(init_futures) + ]) def deinit(self): """ -- cgit v1.2.3