From 7ba25a638eaa6e88696471df5ecd6af70e57d796 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Thu, 7 Oct 2021 15:20:54 -0500 Subject: mpm: rfdc: Tear down RFDC on teardown So, the Python garbage collector is a bit pernicious, in that it happens behind the scenes in a way which is difficult to predict. The rfdc_ctrl class expects that its "lifetime" will be a single live/die cycle of the FPGA (i.e. that when a new FPGA is loaded, it will be destructed). However, by default the Python GC will keep the X4xxRfdcCtrl class alive for an arbitrary amount of time, meaning that it's possible that multiple (C++) rfdc_ctrl classes can be alive at a single time. When the GC reaps all of these classes, libmetal segfaults when we call metal_finish several times in a row. This change works around that issue, if not the overall GC issue, by explicitly deleting the rfdc_ctrl object. --- mpm/python/usrp_mpm/periph_manager/x4xx.py | 2 +- mpm/python/usrp_mpm/periph_manager/x4xx_rfdc_ctrl.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'mpm/python') diff --git a/mpm/python/usrp_mpm/periph_manager/x4xx.py b/mpm/python/usrp_mpm/periph_manager/x4xx.py index a9db6f510..30938a6b2 100644 --- a/mpm/python/usrp_mpm/periph_manager/x4xx.py +++ b/mpm/python/usrp_mpm/periph_manager/x4xx.py @@ -696,7 +696,7 @@ class x4xx(ZynqComponents, PeriphManagerBase): super(x4xx, self).tear_down() if self.dio_control is not None: self.dio_control.tear_down() - self.rfdc.unset_cbs() + self.rfdc.tear_down() self._clk_mgr.unset_cbs() # remove x4xx overlay active_overlays = self.list_active_overlays() diff --git a/mpm/python/usrp_mpm/periph_manager/x4xx_rfdc_ctrl.py b/mpm/python/usrp_mpm/periph_manager/x4xx_rfdc_ctrl.py index be93a495e..6dca79b2a 100644 --- a/mpm/python/usrp_mpm/periph_manager/x4xx_rfdc_ctrl.py +++ b/mpm/python/usrp_mpm/periph_manager/x4xx_rfdc_ctrl.py @@ -88,11 +88,13 @@ class X4xxRfdcCtrl: self._cal_freeze_cache = {} @no_rpc - def unset_cbs(self): + def tear_down(self): """ - Removes any stored references to our owning X4xx class instance + Removes any stored references to our owning X4xx class instance and + destructs anything that must happen at teardown """ self._get_spll_freq = None + del self._rfdc_ctrl ########################################################################### # Public APIs (not available as MPM RPC calls) -- cgit v1.2.3