From 5f93ff6ed0f1acbef2df0c56f7bc5aa2c5015ad8 Mon Sep 17 00:00:00 2001 From: faluco Date: Thu, 21 Oct 2021 16:51:57 +0200 Subject: [PATCH] Batch of data race fixes in the following classes: RLC AM, Intra measure, UL HARQ, PHY common. --- srsue/hdr/phy/scell/intra_measure_lte.h | 5 +++-- srsue/hdr/stack/mac/ul_harq.h | 12 ++++++------ srsue/src/phy/phy_common.cc | 8 +++++--- srsue/src/phy/scell/intra_measure_lte.cc | 17 +++++++++++++---- srsue/src/stack/mac/ul_harq.cc | 4 ++-- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/srsue/hdr/phy/scell/intra_measure_lte.h b/srsue/hdr/phy/scell/intra_measure_lte.h index 7a1b7a931..69fc93cc0 100644 --- a/srsue/hdr/phy/scell/intra_measure_lte.h +++ b/srsue/hdr/phy/scell/intra_measure_lte.h @@ -73,8 +73,9 @@ private: bool measure_rat(measure_context_t context, std::vector& buffer, float rx_gain_offset) override; srslog::basic_logger& logger; - srsran_cell_t serving_cell = {}; ///< Current serving cell in the EARFCN, to avoid reporting it - uint32_t current_earfcn = 0; ///< Current EARFCN + srsran_cell_t serving_cell = {}; ///< Current serving cell in the EARFCN, to avoid reporting it + std::atomic current_earfcn = {0}; ///< Current EARFCN + std::mutex mutex; /// LTE-based measuring objects scell_recv scell_rx; ///< Secondary cell searcher diff --git a/srsue/hdr/stack/mac/ul_harq.h b/srsue/hdr/stack/mac/ul_harq.h index 182f15672..de55b241f 100644 --- a/srsue/hdr/stack/mac/ul_harq.h +++ b/srsue/hdr/stack/mac/ul_harq.h @@ -117,12 +117,12 @@ private: }; lockable_grant cur_grant; - uint32_t pid; - uint32_t current_tx_nb; - uint32_t current_irv; - bool harq_feedback; - bool is_grant_configured; - bool is_initiated; + uint32_t pid; + std::atomic current_tx_nb = {0}; + uint32_t current_irv; + bool harq_feedback; + bool is_grant_configured; + bool is_initiated; srslog::basic_logger& logger; ul_harq_entity* harq_entity; diff --git a/srsue/src/phy/phy_common.cc b/srsue/src/phy/phy_common.cc index a3c7618eb..f44c57e9e 100644 --- a/srsue/src/phy/phy_common.cc +++ b/srsue/src/phy/phy_common.cc @@ -306,12 +306,14 @@ bool phy_common::is_any_ul_pending_ack() #define tti_pusch_hi(sf) \ (sf->tti + \ (cell.frame_type == SRSRAN_FDD ? FDD_HARQ_DELAY_UL_MS \ - : I_phich ? 7 : k_pusch[sf->tdd_config.sf_config][sf->tti % 10]) + \ + : I_phich ? 7 \ + : k_pusch[sf->tdd_config.sf_config][sf->tti % 10]) + \ (FDD_HARQ_DELAY_DL_MS - FDD_HARQ_DELAY_UL_MS)) #define tti_pusch_gr(sf) \ (sf->tti + \ (cell.frame_type == SRSRAN_FDD ? FDD_HARQ_DELAY_UL_MS \ - : dci->ul_idx == 1 ? 7 : k_pusch[sf->tdd_config.sf_config][sf->tti % 10]) + \ + : dci->ul_idx == 1 ? 7 \ + : k_pusch[sf->tdd_config.sf_config][sf->tti % 10]) + \ (FDD_HARQ_DELAY_DL_MS - FDD_HARQ_DELAY_UL_MS)) // SF->TTI is at which Format0 dci is received @@ -893,7 +895,7 @@ void phy_common::reset() cur_pathloss = 0; cur_pusch_power = 0; } - last_ri = 0; + last_ri = 0; // Reset all measurements reset_measurements(SRSRAN_MAX_CARRIERS); diff --git a/srsue/src/phy/scell/intra_measure_lte.cc b/srsue/src/phy/scell/intra_measure_lte.cc index 7719a42c1..b31cda61d 100644 --- a/srsue/src/phy/scell/intra_measure_lte.cc +++ b/srsue/src/phy/scell/intra_measure_lte.cc @@ -42,8 +42,11 @@ void intra_measure_lte::init(uint32_t cc_idx, const args_t& args) void intra_measure_lte::set_primary_cell(uint32_t earfcn, srsran_cell_t cell) { + { + std::lock_guard lock(mutex); + serving_cell = cell; + } current_earfcn = earfcn; - serving_cell = cell; set_current_sf_len((uint32_t)SRSRAN_SF_LEN_PRB(cell.nof_prb)); } @@ -51,8 +54,14 @@ bool intra_measure_lte::measure_rat(measure_context_t context, std::vector { std::set cells_to_measure = context.active_pci; + srsran_cell_t serving_cell_copy{}; + { + std::lock_guard lock(mutex); + serving_cell_copy = serving_cell; + } + // Detect new cells using PSS/SSS - scell_rx.find_cells(buffer.data(), serving_cell, context.meas_len_ms, cells_to_measure); + scell_rx.find_cells(buffer.data(), serving_cell_copy, context.meas_len_ms, cells_to_measure); // Initialise empty neighbour cell list std::vector neighbour_cells = {}; @@ -62,10 +71,10 @@ bool intra_measure_lte::measure_rat(measure_context_t context, std::vector // Use Cell Reference signal to measure cells in the time domain for all known active PCI for (const uint32_t& id : cells_to_measure) { // Do not measure serving cell here since it's measured by workers - if (id == serving_cell.id) { + if (id == serving_cell_copy.id) { continue; } - srsran_cell_t cell = serving_cell; + srsran_cell_t cell = serving_cell_copy; cell.id = id; if (srsran_refsignal_dl_sync_set_cell(&refsignal_dl_sync, cell) < SRSRAN_SUCCESS) { diff --git a/srsue/src/stack/mac/ul_harq.cc b/srsue/src/stack/mac/ul_harq.cc index c97eb4a11..47c53f452 100644 --- a/srsue/src/stack/mac/ul_harq.cc +++ b/srsue/src/stack/mac/ul_harq.cc @@ -317,7 +317,7 @@ void ul_harq_entity::ul_harq_process::generate_retx(mac_interface_phy_lte::mac_g Info("UL %d: Adaptive retx=%d, RV=%d, TBS=%d, HI=%s, ndi=%d, prev_ndi=%d", pid, - current_tx_nb, + current_tx_nb.load(), get_rv(), grant.tb.tbs, harq_feedback ? "ACK" : "NACK", @@ -337,7 +337,7 @@ void ul_harq_entity::ul_harq_process::generate_retx(mac_interface_phy_lte::mac_g // Non-adaptive retx are only sent if HI=NACK. If HI=ACK but no dci was received do not reset PID Info("UL %d: Non-Adaptive retx=%d, RV=%d, TBS=%d, HI=%s", pid, - current_tx_nb, + current_tx_nb.load(), get_rv(), cur_grant.get_tbs(), harq_feedback ? "ACK" : "NACK");