Fix several data races in LTE and NR harq classes.

This commit is contained in:
faluco 2021-10-05 18:15:23 +02:00 committed by Andre Puschmann
parent 991013ca2c
commit 6c4548c243
6 changed files with 31 additions and 14 deletions

View File

@ -99,6 +99,7 @@ private:
ue_rnti* rntis = nullptr; ue_rnti* rntis = nullptr;
srsran::ul_harq_cfg_t harq_cfg = {}; srsran::ul_harq_cfg_t harq_cfg = {};
std::mutex config_mutex;
std::atomic<float> average_retx{0}; std::atomic<float> average_retx{0};
std::atomic<uint64_t> nof_pkts{0}; std::atomic<uint64_t> nof_pkts{0};

View File

@ -96,6 +96,7 @@ private:
srslog::basic_logger& logger; srslog::basic_logger& logger;
uint16_t last_temporal_crnti = SRSRAN_INVALID_RNTI; uint16_t last_temporal_crnti = SRSRAN_INVALID_RNTI;
dl_harq_metrics_t metrics = {}; dl_harq_metrics_t metrics = {};
std::mutex metrics_mutex;
uint8_t cc_idx = 0; uint8_t cc_idx = 0;
pthread_rwlock_t rwlock; pthread_rwlock_t rwlock;
}; };

View File

@ -103,6 +103,7 @@ private:
srsran::ul_harq_cfg_t harq_cfg = {}; srsran::ul_harq_cfg_t harq_cfg = {};
ul_harq_metrics_t metrics = {}; ul_harq_metrics_t metrics = {};
std::mutex metrics_mutex;
}; };
typedef std::unique_ptr<ul_harq_entity_nr> ul_harq_entity_nr_ptr; typedef std::unique_ptr<ul_harq_entity_nr> ul_harq_entity_nr_ptr;

View File

@ -57,6 +57,7 @@ void ul_harq_entity::reset_ndi()
void ul_harq_entity::set_config(srsran::ul_harq_cfg_t& harq_cfg_) void ul_harq_entity::set_config(srsran::ul_harq_cfg_t& harq_cfg_)
{ {
std::lock_guard<std::mutex> lock(config_mutex);
harq_cfg = harq_cfg_; harq_cfg = harq_cfg_;
} }
@ -174,11 +175,14 @@ void ul_harq_entity::ul_harq_process::new_grant_ul(mac_interface_phy_lte::mac_gr
// Get maximum retransmissions // Get maximum retransmissions
uint32_t max_retx; uint32_t max_retx;
{
std::lock_guard<std::mutex> lock(harq_entity->config_mutex);
if (grant.rnti == harq_entity->rntis->get_temp_rnti()) { if (grant.rnti == harq_entity->rntis->get_temp_rnti()) {
max_retx = harq_entity->harq_cfg.max_harq_msg3_tx; max_retx = harq_entity->harq_cfg.max_harq_msg3_tx;
} else { } else {
max_retx = harq_entity->harq_cfg.max_harq_tx; max_retx = harq_entity->harq_cfg.max_harq_tx;
} }
}
// Check maximum retransmissions, do not consider last retx ACK // Check maximum retransmissions, do not consider last retx ACK
if (current_tx_nb >= max_retx && !grant.hi_value) { if (current_tx_nb >= max_retx && !grant.hi_value) {

View File

@ -126,6 +126,7 @@ void dl_harq_entity_nr::reset()
dl_harq_entity_nr::dl_harq_metrics_t dl_harq_entity_nr::get_metrics() dl_harq_entity_nr::dl_harq_metrics_t dl_harq_entity_nr::get_metrics()
{ {
std::lock_guard<std::mutex> lock(metrics_mutex);
dl_harq_metrics_t tmp = metrics; dl_harq_metrics_t tmp = metrics;
metrics = {}; metrics = {};
return tmp; return tmp;
@ -230,9 +231,11 @@ void dl_harq_entity_nr::dl_harq_process_nr::tb_decoded(const mac_nr_grant_dl_t&
} }
} }
std::lock_guard<std::mutex> lock(harq_entity->metrics_mutex);
harq_entity->metrics.rx_ok++; harq_entity->metrics.rx_ok++;
harq_entity->metrics.rx_brate += grant.tbs * 8; harq_entity->metrics.rx_brate += grant.tbs * 8;
} else { } else {
std::lock_guard<std::mutex> lock(harq_entity->metrics_mutex);
harq_entity->metrics.rx_ko++; harq_entity->metrics.rx_ko++;
} }

View File

@ -106,6 +106,7 @@ int ul_harq_entity_nr::get_current_tbs(uint32_t pid)
ul_harq_entity_nr::ul_harq_metrics_t ul_harq_entity_nr::get_metrics() ul_harq_entity_nr::ul_harq_metrics_t ul_harq_entity_nr::get_metrics()
{ {
std::lock_guard<std::mutex> lock(metrics_mutex);
ul_harq_entity_nr::ul_harq_metrics_t tmp = metrics; ul_harq_entity_nr::ul_harq_metrics_t tmp = metrics;
metrics = {}; metrics = {};
return tmp; return tmp;
@ -240,6 +241,7 @@ void ul_harq_entity_nr::ul_harq_process_nr::generate_new_tx(const mac_interface_
generate_tx(action); generate_tx(action);
std::lock_guard<std::mutex> lock(harq_entity->metrics_mutex);
harq_entity->metrics.tx_ok++; harq_entity->metrics.tx_ok++;
} }
@ -255,6 +257,7 @@ void ul_harq_entity_nr::ul_harq_process_nr::generate_retx(const mac_interface_ph
generate_tx(action); generate_tx(action);
// increment Tx error count // increment Tx error count
std::lock_guard<std::mutex> lock(harq_entity->metrics_mutex);
harq_entity->metrics.tx_ko++; harq_entity->metrics.tx_ko++;
} }
@ -262,7 +265,11 @@ void ul_harq_entity_nr::ul_harq_process_nr::generate_retx(const mac_interface_ph
void ul_harq_entity_nr::ul_harq_process_nr::generate_tx(mac_interface_phy_nr::tb_action_ul_t* action) void ul_harq_entity_nr::ul_harq_process_nr::generate_tx(mac_interface_phy_nr::tb_action_ul_t* action)
{ {
nof_retx++; nof_retx++;
{
std::lock_guard<std::mutex> lock(harq_entity->metrics_mutex);
harq_entity->metrics.tx_brate += current_grant.tbs * 8; harq_entity->metrics.tx_brate += current_grant.tbs * 8;
}
action->tb.rv = current_grant.rv; action->tb.rv = current_grant.rv;
action->tb.enabled = true; action->tb.enabled = true;