From a70327997507bf852f9614903ea4af9ccc8a7ef3 Mon Sep 17 00:00:00 2001 From: faluco Date: Tue, 5 Oct 2021 12:02:41 +0200 Subject: [PATCH] Fix a data race when passing the nr_workers to the txrx worker. There was an unprotected access of the txrx reading this variable while being set from a different thread. Fix it by starting the txrx thread after all variables are ready. --- srsenb/hdr/phy/phy.h | 13 +++++++++---- srsenb/src/phy/phy.cc | 27 +++++++++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/srsenb/hdr/phy/phy.h b/srsenb/hdr/phy/phy.h index bfbbbcb9c..ade136bc3 100644 --- a/srsenb/hdr/phy/phy.h +++ b/srsenb/hdr/phy/phy.h @@ -38,13 +38,13 @@ public: int init(const phy_args_t& args, const phy_cfg_t& cfg, srsran::radio_interface_phy* radio_, - stack_interface_phy_lte* stack_, + stack_interface_phy_lte* stack_lte_, + stack_interface_phy_nr& stack_nr_, enb_time_interface* enb_); int init(const phy_args_t& args, const phy_cfg_t& cfg, srsran::radio_interface_phy* radio_, - stack_interface_phy_lte* stack_lte_, - stack_interface_phy_nr& stack_nr_, + stack_interface_phy_lte* stack_, enb_time_interface* enb_); void stop() override; @@ -72,7 +72,6 @@ public: void srsran_phy_logger(phy_logger_level_t log_level, char* str); - int init_nr(const phy_args_t& args, const phy_cfg_t& cfg, stack_interface_phy_nr& stack); int set_common_cfg(const common_cfg_t& common_cfg) override; private: @@ -103,6 +102,12 @@ private: common_cfg_t common_cfg = {}; void parse_common_config(const phy_cfg_t& cfg); + int init_lte(const phy_args_t& args, + const phy_cfg_t& cfg, + srsran::radio_interface_phy* radio_, + stack_interface_phy_lte* stack_, + enb_time_interface* enb_); + int init_nr(const phy_args_t& args, const phy_cfg_t& cfg, stack_interface_phy_nr& stack); }; } // namespace srsenb diff --git a/srsenb/src/phy/phy.cc b/srsenb/src/phy/phy.cc index 18b174416..47d59199c 100644 --- a/srsenb/src/phy/phy.cc +++ b/srsenb/src/phy/phy.cc @@ -100,7 +100,7 @@ int phy::init(const phy_args_t& args, stack_interface_phy_nr& stack_nr_, enb_time_interface* enb_) { - if (init(args, cfg, radio_, stack_lte_, enb_) != SRSRAN_SUCCESS) { + if (init_lte(args, cfg, radio_, stack_lte_, enb_) != SRSRAN_SUCCESS) { phy_log.error("Couldn't initialize LTE PHY"); return SRSRAN_ERROR; } @@ -110,6 +110,9 @@ int phy::init(const phy_args_t& args, return SRSRAN_ERROR; } + tx_rx.init(enb_, radio, <e_workers, &workers_common, &prach, SF_RECV_THREAD_PRIO); + initialized = true; + return SRSRAN_SUCCESS; } @@ -118,6 +121,23 @@ int phy::init(const phy_args_t& args, srsran::radio_interface_phy* radio_, stack_interface_phy_lte* stack_lte_, enb_time_interface* enb_) +{ + if (init_lte(args, cfg, radio_, stack_lte_, enb_) != SRSRAN_SUCCESS) { + phy_log.error("Couldn't initialize LTE PHY"); + return SRSRAN_ERROR; + } + + tx_rx.init(enb_, radio, <e_workers, &workers_common, &prach, SF_RECV_THREAD_PRIO); + initialized = true; + + return SRSRAN_SUCCESS; +} + +int phy::init_lte(const phy_args_t& args, + const phy_cfg_t& cfg, + srsran::radio_interface_phy* radio_, + stack_interface_phy_lte* stack_lte_, + enb_time_interface* enb_) { if (cfg.phy_cell_cfg.size() > SRSRAN_MAX_CARRIERS) { phy_log.error( @@ -166,11 +186,6 @@ int phy::init(const phy_args_t& args, } prach.set_max_prach_offset_us(args.max_prach_offset_us); - // Warning this must be initialized after all workers have been added to the pool - tx_rx.init(enb_, radio, <e_workers, &workers_common, &prach, SF_RECV_THREAD_PRIO); - - initialized = true; - return SRSRAN_SUCCESS; }