From 9c028ab723ce9186530070d8ce27a8c11419e843 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 24 Mar 2020 14:02:51 +0000 Subject: [PATCH] removed user_mutex from srsenb::rrc. All that needed to happen was the prach_worker calling add_user from stack thread (done in an earlier PR), and the get_metrics run in the stack thread. I achieved the latter with an extra metrics queue --- srsenb/hdr/stack/enb_stack_lte.h | 1 + srsenb/hdr/stack/rrc/rrc.h | 3 +-- srsenb/src/stack/enb_stack_lte.cc | 14 ++++++++--- srsenb/src/stack/rrc/rrc.cc | 39 ------------------------------- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/srsenb/hdr/stack/enb_stack_lte.h b/srsenb/hdr/stack/enb_stack_lte.h index 2362963cd..57a473be5 100644 --- a/srsenb/hdr/stack/enb_stack_lte.h +++ b/srsenb/hdr/stack/enb_stack_lte.h @@ -164,6 +164,7 @@ private: bool started = false; srslte::task_multiqueue pending_tasks; int enb_queue_id = -1, sync_queue_id = -1, mme_queue_id = -1, gtpu_queue_id = -1, mac_queue_id = -1; + srslte::block_queue pending_stack_metrics; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/rrc/rrc.h b/srsenb/hdr/stack/rrc/rrc.h index 3a8065224..1d9ec1bdc 100644 --- a/srsenb/hdr/stack/rrc/rrc.h +++ b/srsenb/hdr/stack/rrc/rrc.h @@ -439,8 +439,7 @@ private: class mobility_cfg; std::unique_ptr enb_mobility_cfg; - void rem_user_thread(uint16_t rnti); - pthread_mutex_t user_mutex; + void rem_user_thread(uint16_t rnti); pthread_mutex_t paging_mutex; }; diff --git a/srsenb/src/stack/enb_stack_lte.cc b/srsenb/src/stack/enb_stack_lte.cc index 26291819c..ccd14cc06 100644 --- a/srsenb/src/stack/enb_stack_lte.cc +++ b/srsenb/src/stack/enb_stack_lte.cc @@ -179,9 +179,17 @@ void enb_stack_lte::stop_impl() bool enb_stack_lte::get_metrics(stack_metrics_t* metrics) { - mac.get_metrics(metrics->mac); - rrc.get_metrics(metrics->rrc); - s1ap.get_metrics(metrics->s1ap); + // use stack thread to query metrics + pending_tasks.try_push(enb_queue_id, [this]() { + stack_metrics_t metrics{}; + mac.get_metrics(metrics.mac); + rrc.get_metrics(metrics.rrc); + s1ap.get_metrics(metrics.s1ap); + pending_stack_metrics.push(metrics); + }); + + // wait for result + *metrics = pending_stack_metrics.wait_pop(); return true; } diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index 9b05730d7..8ec08a794 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -78,7 +78,6 @@ void rrc::init(const rrc_cfg_t& cfg_, config_mac(); enb_mobility_cfg.reset(new mobility_cfg(&cfg)); - pthread_mutex_init(&user_mutex, nullptr); pthread_mutex_init(&paging_mutex, nullptr); bzero(&sr_sched, sizeof(sr_sched_t)); @@ -93,29 +92,22 @@ void rrc::stop() rrc_pdu p = {0, LCID_EXIT, nullptr}; rx_pdu_queue.push(std::move(p)); } - pthread_mutex_lock(&user_mutex); users.clear(); - pthread_mutex_unlock(&user_mutex); - pthread_mutex_destroy(&user_mutex); pthread_mutex_destroy(&paging_mutex); } /******************************************************************************* Public functions - - All public functions must be mutexed. *******************************************************************************/ void rrc::get_metrics(rrc_metrics_t& m) { if (running) { - pthread_mutex_lock(&user_mutex); m.n_ues = 0; for (auto iter = users.begin(); m.n_ues < ENB_METRICS_MAX_USERS && iter != users.end(); ++iter) { ue* u = iter->second.get(); m.ues[m.n_ues++].state = u->get_state(); } - pthread_mutex_unlock(&user_mutex); } } @@ -185,7 +177,6 @@ void rrc::max_retx_attempted(uint16_t rnti) {} // This function is called from PRACH worker (can wait) void rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg) { - pthread_mutex_lock(&user_mutex); auto user_it = users.find(rnti); if (user_it == users.end()) { users.insert(std::make_pair(rnti, std::unique_ptr(new ue{this, rnti, sched_ue_cfg}))); @@ -208,8 +199,6 @@ void rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg) gtpu->add_bearer(SRSLTE_MRNTI, lcid, 1, 1, &teid_in); } } - - pthread_mutex_unlock(&user_mutex); } /* Function called by MAC after the reception of a C-RNTI CE indicating that the UE still has a @@ -221,7 +210,6 @@ void rrc::upd_user(uint16_t new_rnti, uint16_t old_rnti) rem_user_thread(new_rnti); // Send Reconfiguration to old_rnti if is RRC_CONNECT or RRC Release if already released here - pthread_mutex_lock(&user_mutex); auto old_it = users.find(old_rnti); if (old_it != users.end()) { if (old_it->second->is_connected()) { @@ -230,7 +218,6 @@ void rrc::upd_user(uint16_t new_rnti, uint16_t old_rnti) old_it->second->send_connection_release(); } } - pthread_mutex_unlock(&user_mutex); } /******************************************************************************* @@ -251,8 +238,6 @@ void rrc::write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu) dl_dcch_msg.msg.set_c1(); dl_dcch_msg_type_c::c1_c_* msg_c1 = &dl_dcch_msg.msg.c1(); - pthread_mutex_lock(&user_mutex); - auto user_it = users.find(rnti); if (user_it != users.end()) { dl_info_transfer_r8_ies_s* dl_info_r8 = @@ -271,8 +256,6 @@ void rrc::write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu) } else { rrc_log->error("Rx SDU for unknown rnti=0x%x\n", rnti); } - - pthread_mutex_unlock(&user_mutex); } void rrc::release_complete(uint16_t rnti) @@ -283,14 +266,11 @@ void rrc::release_complete(uint16_t rnti) bool rrc::setup_ue_ctxt(uint16_t rnti, const asn1::s1ap::init_context_setup_request_s& msg) { - pthread_mutex_lock(&user_mutex); - rrc_log->info("Adding initial context for 0x%x\n", rnti); auto user_it = users.find(rnti); if (user_it == users.end()) { rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); - pthread_mutex_unlock(&user_mutex); return false; } @@ -354,22 +334,18 @@ bool rrc::setup_ue_ctxt(uint16_t rnti, const asn1::s1ap::init_context_setup_requ // Setup E-RABs user_it->second->setup_erabs(msg.protocol_ies.erab_to_be_setup_list_ctxt_su_req.value); - pthread_mutex_unlock(&user_mutex); - return true; } bool rrc::modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request_s& msg) { bool err = false; - pthread_mutex_lock(&user_mutex); rrc_log->info("Modifying context for 0x%x\n", rnti); auto user_it = users.find(rnti); if (user_it == users.end()) { rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); - pthread_mutex_unlock(&user_mutex); return false; } @@ -400,7 +376,6 @@ bool rrc::modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request if (err) { // maybe pass a cause value? - pthread_mutex_unlock(&user_mutex); return false; } @@ -422,21 +397,16 @@ bool rrc::modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request user_it->second->send_security_mode_command(); } - pthread_mutex_unlock(&user_mutex); - return true; } bool rrc::setup_ue_erabs(uint16_t rnti, const asn1::s1ap::erab_setup_request_s& msg) { - pthread_mutex_lock(&user_mutex); - rrc_log->info("Setting up erab(s) for 0x%x\n", rnti); auto user_it = users.find(rnti); if (user_it == users.end()) { rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); - pthread_mutex_unlock(&user_mutex); return false; } @@ -448,25 +418,20 @@ bool rrc::setup_ue_erabs(uint16_t rnti, const asn1::s1ap::erab_setup_request_s& // Setup E-RABs user_it->second->setup_erabs(msg.protocol_ies.erab_to_be_setup_list_bearer_su_req.value); - pthread_mutex_unlock(&user_mutex); - return true; } bool rrc::release_erabs(uint32_t rnti) { - pthread_mutex_lock(&user_mutex); rrc_log->info("Releasing E-RABs for 0x%x\n", rnti); auto user_it = users.find(rnti); if (user_it == users.end()) { rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); - pthread_mutex_unlock(&user_mutex); return false; } bool ret = user_it->second->release_erabs(); - pthread_mutex_unlock(&user_mutex); return ret; } @@ -1000,11 +965,9 @@ void rrc::enable_encryption(uint16_t rnti, uint32_t lcid) void rrc::tti_clock() { - pthread_mutex_lock(&user_mutex); // pop cmd from queue rrc_pdu p; if (not rx_pdu_queue.try_pop(&p)) { - pthread_mutex_unlock(&user_mutex); return; } // print Rx PDU @@ -1016,7 +979,6 @@ void rrc::tti_clock() auto user_it = users.find(p.rnti); if (user_it == users.end()) { rrc_log->warning("Discarding PDU for removed rnti=0x%x\n", p.rnti); - pthread_mutex_unlock(&user_mutex); return; } @@ -1048,7 +1010,6 @@ void rrc::tti_clock() rrc_log->error("Rx PDU with invalid bearer id: %d", p.lcid); break; } - pthread_mutex_unlock(&user_mutex); } /*******************************************************************************