From fa4d14652de0482b94b08df1f16a5a03899a124c Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Mar 2018 13:32:19 +0100 Subject: [PATCH] Added mutex for ue_rem/buffer access for more safety --- srsenb/hdr/mac/scheduler.h | 6 +++--- srsenb/src/mac/scheduler.cc | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/srsenb/hdr/mac/scheduler.h b/srsenb/hdr/mac/scheduler.h index c3ca7d624..12c336c36 100644 --- a/srsenb/hdr/mac/scheduler.h +++ b/srsenb/hdr/mac/scheduler.h @@ -100,8 +100,8 @@ public: uint32_t get_ul_buffer(uint16_t rnti); uint32_t get_dl_buffer(uint16_t rnti); - int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); - int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code); + int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); + int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code); int dl_ant_info(uint16_t rnti, LIBLTE_RRC_ANTENNA_INFO_DEDICATED_STRUCT *dedicated); int dl_ack_info(uint32_t tti, uint16_t rnti, uint32_t tb_idx, bool ack); @@ -217,7 +217,7 @@ private: bool configured; - pthread_mutex_t mutex; + pthread_mutex_t mutex, mutex2; }; diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 995363045..2e0504193 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -64,6 +64,7 @@ sched::sched() : bc_aggr_level(0), rar_aggr_level(0), avail_rbg(0), P(0), start_ } pthread_mutex_init(&mutex, NULL); + pthread_mutex_init(&mutex2, NULL); reset(); } @@ -71,6 +72,7 @@ sched::~sched() { srslte_regs_free(®s); pthread_mutex_destroy(&mutex); + pthread_mutex_destroy(&mutex2); } void sched::init(rrc_interface_mac *rrc_, srslte::log* log) @@ -173,13 +175,15 @@ int sched::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t *ue_cfg) int sched::ue_rem(uint16_t rnti) { pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db.erase(rnti); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex); return ret; } @@ -217,13 +221,15 @@ int sched::bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bear int sched::bearer_ue_rem(uint16_t rnti, uint32_t lc_id) { pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].rem_bearer(lc_id); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex); return ret; } @@ -259,9 +265,13 @@ uint32_t sched::get_ul_buffer(uint16_t rnti) * Ideally we would like the scheduler to query the RLC for buffer states in order to get the most updated * buffer state with the minimum overhead. However, the current architecture is designed to be compliant * with the FAPI interface + * + * We add a new mutex used only in ue_rem to avoid the UE being removed in between the access to + * ue_db.count() and the access to the std::map. */ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) { + pthread_mutex_lock(&mutex2); int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].dl_buffer_state(lc_id, tx_queue, retx_queue); @@ -269,21 +279,23 @@ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); return ret; } +/* \Warning Read comment in dl_rlc_buffer_state() */ int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) { - pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].mac_buffer_state(ce_code); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } - pthread_mutex_unlock(&mutex); - return ret; + pthread_mutex_unlock(&mutex2); + return ret; } int sched::dl_ant_info(uint16_t rnti, LIBLTE_RRC_ANTENNA_INFO_DEDICATED_STRUCT *dl_ant_info) {