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

master
Francisco Paisana 5 years ago committed by Francisco Paisana
parent 75f35d8ded
commit 9c028ab723

@ -164,6 +164,7 @@ private:
bool started = false; bool started = false;
srslte::task_multiqueue pending_tasks; 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; int enb_queue_id = -1, sync_queue_id = -1, mme_queue_id = -1, gtpu_queue_id = -1, mac_queue_id = -1;
srslte::block_queue<stack_metrics_t> pending_stack_metrics;
}; };
} // namespace srsenb } // namespace srsenb

@ -440,7 +440,6 @@ private:
std::unique_ptr<mobility_cfg> enb_mobility_cfg; std::unique_ptr<mobility_cfg> enb_mobility_cfg;
void rem_user_thread(uint16_t rnti); void rem_user_thread(uint16_t rnti);
pthread_mutex_t user_mutex;
pthread_mutex_t paging_mutex; pthread_mutex_t paging_mutex;
}; };

@ -179,9 +179,17 @@ void enb_stack_lte::stop_impl()
bool enb_stack_lte::get_metrics(stack_metrics_t* metrics) bool enb_stack_lte::get_metrics(stack_metrics_t* metrics)
{ {
mac.get_metrics(metrics->mac); // use stack thread to query metrics
rrc.get_metrics(metrics->rrc); pending_tasks.try_push(enb_queue_id, [this]() {
s1ap.get_metrics(metrics->s1ap); 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; return true;
} }

@ -78,7 +78,6 @@ void rrc::init(const rrc_cfg_t& cfg_,
config_mac(); config_mac();
enb_mobility_cfg.reset(new mobility_cfg(&cfg)); enb_mobility_cfg.reset(new mobility_cfg(&cfg));
pthread_mutex_init(&user_mutex, nullptr);
pthread_mutex_init(&paging_mutex, nullptr); pthread_mutex_init(&paging_mutex, nullptr);
bzero(&sr_sched, sizeof(sr_sched_t)); bzero(&sr_sched, sizeof(sr_sched_t));
@ -93,29 +92,22 @@ void rrc::stop()
rrc_pdu p = {0, LCID_EXIT, nullptr}; rrc_pdu p = {0, LCID_EXIT, nullptr};
rx_pdu_queue.push(std::move(p)); rx_pdu_queue.push(std::move(p));
} }
pthread_mutex_lock(&user_mutex);
users.clear(); users.clear();
pthread_mutex_unlock(&user_mutex);
pthread_mutex_destroy(&user_mutex);
pthread_mutex_destroy(&paging_mutex); pthread_mutex_destroy(&paging_mutex);
} }
/******************************************************************************* /*******************************************************************************
Public functions Public functions
All public functions must be mutexed.
*******************************************************************************/ *******************************************************************************/
void rrc::get_metrics(rrc_metrics_t& m) void rrc::get_metrics(rrc_metrics_t& m)
{ {
if (running) { if (running) {
pthread_mutex_lock(&user_mutex);
m.n_ues = 0; m.n_ues = 0;
for (auto iter = users.begin(); m.n_ues < ENB_METRICS_MAX_USERS && iter != users.end(); ++iter) { for (auto iter = users.begin(); m.n_ues < ENB_METRICS_MAX_USERS && iter != users.end(); ++iter) {
ue* u = iter->second.get(); ue* u = iter->second.get();
m.ues[m.n_ues++].state = u->get_state(); 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) // 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) 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); auto user_it = users.find(rnti);
if (user_it == users.end()) { if (user_it == users.end()) {
users.insert(std::make_pair(rnti, std::unique_ptr<ue>(new ue{this, rnti, sched_ue_cfg}))); users.insert(std::make_pair(rnti, std::unique_ptr<ue>(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); 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 /* 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); rem_user_thread(new_rnti);
// Send Reconfiguration to old_rnti if is RRC_CONNECT or RRC Release if already released here // 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); auto old_it = users.find(old_rnti);
if (old_it != users.end()) { if (old_it != users.end()) {
if (old_it->second->is_connected()) { 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(); 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.msg.set_c1();
dl_dcch_msg_type_c::c1_c_* msg_c1 = &dl_dcch_msg.msg.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); auto user_it = users.find(rnti);
if (user_it != users.end()) { if (user_it != users.end()) {
dl_info_transfer_r8_ies_s* dl_info_r8 = 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 { } else {
rrc_log->error("Rx SDU for unknown rnti=0x%x\n", rnti); rrc_log->error("Rx SDU for unknown rnti=0x%x\n", rnti);
} }
pthread_mutex_unlock(&user_mutex);
} }
void rrc::release_complete(uint16_t rnti) 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) 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); rrc_log->info("Adding initial context for 0x%x\n", rnti);
auto user_it = users.find(rnti); auto user_it = users.find(rnti);
if (user_it == users.end()) { if (user_it == users.end()) {
rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti);
pthread_mutex_unlock(&user_mutex);
return false; return false;
} }
@ -354,22 +334,18 @@ bool rrc::setup_ue_ctxt(uint16_t rnti, const asn1::s1ap::init_context_setup_requ
// Setup E-RABs // Setup E-RABs
user_it->second->setup_erabs(msg.protocol_ies.erab_to_be_setup_list_ctxt_su_req.value); user_it->second->setup_erabs(msg.protocol_ies.erab_to_be_setup_list_ctxt_su_req.value);
pthread_mutex_unlock(&user_mutex);
return true; return true;
} }
bool rrc::modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request_s& msg) bool rrc::modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request_s& msg)
{ {
bool err = false; bool err = false;
pthread_mutex_lock(&user_mutex);
rrc_log->info("Modifying context for 0x%x\n", rnti); rrc_log->info("Modifying context for 0x%x\n", rnti);
auto user_it = users.find(rnti); auto user_it = users.find(rnti);
if (user_it == users.end()) { if (user_it == users.end()) {
rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti);
pthread_mutex_unlock(&user_mutex);
return false; return false;
} }
@ -400,7 +376,6 @@ bool rrc::modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request
if (err) { if (err) {
// maybe pass a cause value? // maybe pass a cause value?
pthread_mutex_unlock(&user_mutex);
return false; 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(); user_it->second->send_security_mode_command();
} }
pthread_mutex_unlock(&user_mutex);
return true; return true;
} }
bool rrc::setup_ue_erabs(uint16_t rnti, const asn1::s1ap::erab_setup_request_s& msg) 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); rrc_log->info("Setting up erab(s) for 0x%x\n", rnti);
auto user_it = users.find(rnti); auto user_it = users.find(rnti);
if (user_it == users.end()) { if (user_it == users.end()) {
rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti);
pthread_mutex_unlock(&user_mutex);
return false; return false;
} }
@ -448,25 +418,20 @@ bool rrc::setup_ue_erabs(uint16_t rnti, const asn1::s1ap::erab_setup_request_s&
// Setup E-RABs // Setup E-RABs
user_it->second->setup_erabs(msg.protocol_ies.erab_to_be_setup_list_bearer_su_req.value); user_it->second->setup_erabs(msg.protocol_ies.erab_to_be_setup_list_bearer_su_req.value);
pthread_mutex_unlock(&user_mutex);
return true; return true;
} }
bool rrc::release_erabs(uint32_t rnti) bool rrc::release_erabs(uint32_t rnti)
{ {
pthread_mutex_lock(&user_mutex);
rrc_log->info("Releasing E-RABs for 0x%x\n", rnti); rrc_log->info("Releasing E-RABs for 0x%x\n", rnti);
auto user_it = users.find(rnti); auto user_it = users.find(rnti);
if (user_it == users.end()) { if (user_it == users.end()) {
rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti); rrc_log->warning("Unrecognised rnti: 0x%x\n", rnti);
pthread_mutex_unlock(&user_mutex);
return false; return false;
} }
bool ret = user_it->second->release_erabs(); bool ret = user_it->second->release_erabs();
pthread_mutex_unlock(&user_mutex);
return ret; return ret;
} }
@ -1000,11 +965,9 @@ void rrc::enable_encryption(uint16_t rnti, uint32_t lcid)
void rrc::tti_clock() void rrc::tti_clock()
{ {
pthread_mutex_lock(&user_mutex);
// pop cmd from queue // pop cmd from queue
rrc_pdu p; rrc_pdu p;
if (not rx_pdu_queue.try_pop(&p)) { if (not rx_pdu_queue.try_pop(&p)) {
pthread_mutex_unlock(&user_mutex);
return; return;
} }
// print Rx PDU // print Rx PDU
@ -1016,7 +979,6 @@ void rrc::tti_clock()
auto user_it = users.find(p.rnti); auto user_it = users.find(p.rnti);
if (user_it == users.end()) { if (user_it == users.end()) {
rrc_log->warning("Discarding PDU for removed rnti=0x%x\n", p.rnti); rrc_log->warning("Discarding PDU for removed rnti=0x%x\n", p.rnti);
pthread_mutex_unlock(&user_mutex);
return; return;
} }
@ -1048,7 +1010,6 @@ void rrc::tti_clock()
rrc_log->error("Rx PDU with invalid bearer id: %d", p.lcid); rrc_log->error("Rx PDU with invalid bearer id: %d", p.lcid);
break; break;
} }
pthread_mutex_unlock(&user_mutex);
} }
/******************************************************************************* /*******************************************************************************

Loading…
Cancel
Save