From c0fd64c4e6aa6889d451c55256fc671d2f6f1084 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 1 Jul 2021 13:01:24 +0200 Subject: [PATCH] Fix data races in srsENB MAC --- srsenb/hdr/stack/mac/ta.h | 4 ++++ srsenb/hdr/stack/mac/ue.h | 1 + srsenb/src/stack/mac/ue.cc | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/srsenb/hdr/stack/mac/ta.h b/srsenb/hdr/stack/mac/ta.h index 068bb9227..1e7591dd9 100644 --- a/srsenb/hdr/stack/mac/ta.h +++ b/srsenb/hdr/stack/mac/ta.h @@ -67,6 +67,8 @@ private: float ta_us; ///< TA measurement in microseconds } ta_meas_t; + std::mutex mutex; + uint32_t meas_t_ms = 0; ///< Time counter in milliseconds uint32_t meas_count = 0; ///< Number of measures in the buffer uint32_t meas_idx = 0; ///< Next mesurement index in the buffer @@ -211,6 +213,7 @@ public: */ uint32_t push_value(float ta_us) { + std::lock_guard lock(mutex); // Put measurement if state is measurement if (state == state_measure) { // Set measurement @@ -238,6 +241,7 @@ public: */ uint32_t tick() { + std::lock_guard lock(mutex); // Increase measurement timestamp counter meas_t_ms++; diff --git a/srsenb/hdr/stack/mac/ue.h b/srsenb/hdr/stack/mac/ue.h index 895466104..3718771ad 100644 --- a/srsenb/hdr/stack/mac/ue.h +++ b/srsenb/hdr/stack/mac/ue.h @@ -164,6 +164,7 @@ public: srsran::unique_byte_buffer_t release_pdu(uint32_t tti, uint32_t enb_cc_idx); void clear_old_buffers(uint32_t tti); + std::mutex metrics_mutex = {}; void metrics_read(mac_ue_metrics_t* metrics_); void metrics_rx(bool crc, uint32_t tbs); void metrics_tx(bool crc, uint32_t tbs); diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index 4a54a7294..cae9939f2 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -596,9 +596,13 @@ uint8_t* ue::generate_mch_pdu(uint32_t harq_pid, /******* METRICS interface ***************/ void ue::metrics_read(mac_ue_metrics_t* metrics_) { + uint32_t ul_buffer = sched->get_ul_buffer(rnti); + uint32_t dl_buffer = sched->get_dl_buffer(rnti); + + std::lock_guard lock(metrics_mutex); ue_metrics.rnti = rnti; - ue_metrics.ul_buffer = sched->get_ul_buffer(rnti); - ue_metrics.dl_buffer = sched->get_dl_buffer(rnti); + ue_metrics.ul_buffer = ul_buffer; + ue_metrics.dl_buffer = dl_buffer; // set PCell sector id std::array cc_list = sched->get_enb_ue_cc_map(rnti); @@ -614,12 +618,14 @@ void ue::metrics_read(mac_ue_metrics_t* metrics_) void ue::metrics_phr(float phr) { + std::lock_guard lock(metrics_mutex); ue_metrics.phr = SRSRAN_VEC_CMA(phr, ue_metrics.phr, phr_counter); phr_counter++; } void ue::metrics_dl_ri(uint32_t dl_ri) { + std::lock_guard lock(metrics_mutex); if (ue_metrics.dl_ri == 0.0f) { ue_metrics.dl_ri = (float)dl_ri + 1.0f; } else { @@ -630,18 +636,21 @@ void ue::metrics_dl_ri(uint32_t dl_ri) void ue::metrics_dl_pmi(uint32_t dl_ri) { + std::lock_guard lock(metrics_mutex); ue_metrics.dl_pmi = SRSRAN_VEC_CMA((float)dl_ri, ue_metrics.dl_pmi, dl_pmi_counter); dl_pmi_counter++; } void ue::metrics_dl_cqi(uint32_t dl_cqi) { + std::lock_guard lock(metrics_mutex); ue_metrics.dl_cqi = SRSRAN_VEC_CMA((float)dl_cqi, ue_metrics.dl_cqi, dl_cqi_counter); dl_cqi_counter++; } void ue::metrics_rx(bool crc, uint32_t tbs) { + std::lock_guard lock(metrics_mutex); if (crc) { ue_metrics.rx_brate += tbs * 8; } else { @@ -652,6 +661,7 @@ void ue::metrics_rx(bool crc, uint32_t tbs) void ue::metrics_tx(bool crc, uint32_t tbs) { + std::lock_guard lock(metrics_mutex); if (crc) { ue_metrics.tx_brate += tbs * 8; } else { @@ -662,6 +672,7 @@ void ue::metrics_tx(bool crc, uint32_t tbs) void ue::metrics_cnt() { + std::lock_guard lock(metrics_mutex); ue_metrics.nof_tti++; }