Fix data races in srsENB MAC

master
Ismael Gomez 4 years ago
parent 4ed33fed7d
commit c0fd64c4e6

@ -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<std::mutex> 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<std::mutex> lock(mutex);
// Increase measurement timestamp counter
meas_t_ms++;

@ -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);

@ -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<std::mutex> 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<int, SRSRAN_MAX_CARRIERS> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(metrics_mutex);
ue_metrics.nof_tti++;
}

Loading…
Cancel
Save