UE: Implement a thread safe wrapper class for accessing the mac_grant_ul_t member in ul_harq_process.

This fixes many race conditions detected by TSAN around this class.
master
faluco 3 years ago committed by Andre Puschmann
parent 6c4548c243
commit a9c65bd369

@ -66,7 +66,56 @@ private:
void new_grant_ul(mac_interface_phy_lte::mac_grant_ul_t grant, mac_interface_phy_lte::tb_action_ul_t* action); void new_grant_ul(mac_interface_phy_lte::mac_grant_ul_t grant, mac_interface_phy_lte::tb_action_ul_t* action);
private: private:
mac_interface_phy_lte::mac_grant_ul_t cur_grant; /// Thread safe wrapper for a mac_grant_ul_t object.
class lockable_grant
{
mac_interface_phy_lte::mac_grant_ul_t grant = {};
mutable std::mutex mutex;
public:
void set(const mac_interface_phy_lte::mac_grant_ul_t& other)
{
std::lock_guard<std::mutex> lock(mutex);
grant = other;
}
void reset()
{
std::lock_guard<std::mutex> lock(mutex);
grant = {};
}
void set_ndi(bool ndi)
{
std::lock_guard<std::mutex> lock(mutex);
grant.tb.ndi = ndi;
}
bool get_ndi() const
{
std::lock_guard<std::mutex> lock(mutex);
return grant.tb.ndi;
}
uint32_t get_tbs() const
{
std::lock_guard<std::mutex> lock(mutex);
return grant.tb.tbs;
}
int get_rv() const
{
std::lock_guard<std::mutex> lock(mutex);
return grant.tb.rv;
}
void set_rv(int rv)
{
std::lock_guard<std::mutex> lock(mutex);
grant.tb.rv = rv;
}
};
lockable_grant cur_grant;
uint32_t pid; uint32_t pid;
uint32_t current_tx_nb; uint32_t current_tx_nb;

@ -112,8 +112,6 @@ ul_harq_entity::ul_harq_process::ul_harq_process() : logger(srslog::fetch_basic_
pdu_ptr = NULL; pdu_ptr = NULL;
payload_buffer = NULL; payload_buffer = NULL;
bzero(&cur_grant, sizeof(mac_interface_phy_lte::mac_grant_ul_t));
harq_feedback = false; harq_feedback = false;
is_initiated = false; is_initiated = false;
is_grant_configured = false; is_grant_configured = false;
@ -155,12 +153,12 @@ void ul_harq_entity::ul_harq_process::reset()
current_tx_nb = 0; current_tx_nb = 0;
current_irv = 0; current_irv = 0;
is_grant_configured = false; is_grant_configured = false;
bzero(&cur_grant, sizeof(mac_interface_phy_lte::mac_grant_ul_t)); cur_grant.reset();
} }
void ul_harq_entity::ul_harq_process::reset_ndi() void ul_harq_entity::ul_harq_process::reset_ndi()
{ {
cur_grant.tb.ndi = false; cur_grant.set_ndi(false);
} }
void ul_harq_entity::ul_harq_process::new_grant_ul(mac_interface_phy_lte::mac_grant_ul_t grant, void ul_harq_entity::ul_harq_process::new_grant_ul(mac_interface_phy_lte::mac_grant_ul_t grant,
@ -198,8 +196,9 @@ void ul_harq_entity::ul_harq_process::new_grant_ul(mac_interface_phy_lte::mac_gr
// Reset HARQ process if TB has changed // Reset HARQ process if TB has changed
if (harq_feedback && has_grant() && grant.tb.ndi_present) { if (harq_feedback && has_grant() && grant.tb.ndi_present) {
if (grant.tb.tbs != cur_grant.tb.tbs && cur_grant.tb.tbs > 0 && grant.tb.tbs > 0) { uint32_t cur_grant_tbs = cur_grant.get_tbs();
Debug("UL %d: Reset due to change of dci size last_grant=%d, new_grant=%d", pid, cur_grant.tb.tbs, grant.tb.tbs); if (grant.tb.tbs != cur_grant_tbs && cur_grant_tbs > 0 && grant.tb.tbs > 0) {
Debug("UL %d: Reset due to change of dci size last_grant=%d, new_grant=%d", pid, cur_grant_tbs, grant.tb.tbs);
reset(); reset();
} }
} }
@ -286,7 +285,7 @@ bool ul_harq_entity::ul_harq_process::has_grant()
bool ul_harq_entity::ul_harq_process::get_ndi() bool ul_harq_entity::ul_harq_process::get_ndi()
{ {
return cur_grant.tb.ndi; return cur_grant.get_ndi();
} }
bool ul_harq_entity::ul_harq_process::is_sps() bool ul_harq_entity::ul_harq_process::is_sps()
@ -301,7 +300,7 @@ uint32_t ul_harq_entity::ul_harq_process::get_nof_retx()
int ul_harq_entity::ul_harq_process::get_current_tbs() int ul_harq_entity::ul_harq_process::get_current_tbs()
{ {
return cur_grant.tb.tbs; return cur_grant.get_tbs();
} }
// Retransmission with or w/o dci (Section 5.4.2.2) // Retransmission with or w/o dci (Section 5.4.2.2)
@ -323,15 +322,15 @@ void ul_harq_entity::ul_harq_process::generate_retx(mac_interface_phy_lte::mac_g
grant.tb.tbs, grant.tb.tbs,
harq_feedback ? "ACK" : "NACK", harq_feedback ? "ACK" : "NACK",
grant.tb.ndi, grant.tb.ndi,
cur_grant.tb.ndi); cur_grant.get_ndi());
cur_grant = grant; cur_grant.set(grant);
harq_feedback = false; harq_feedback = false;
generate_tx(action); generate_tx(action);
// Reset the RV received in this grant // Reset the RV received in this grant
cur_grant.tb.rv = -1; cur_grant.set_rv(-1);
// HARQ entity requests a non-adaptive transmission // HARQ entity requests a non-adaptive transmission
} else if (!harq_feedback) { } else if (!harq_feedback) {
@ -340,7 +339,7 @@ void ul_harq_entity::ul_harq_process::generate_retx(mac_interface_phy_lte::mac_g
pid, pid,
current_tx_nb, current_tx_nb,
get_rv(), get_rv(),
cur_grant.tb.tbs, cur_grant.get_tbs(),
harq_feedback ? "ACK" : "NACK"); harq_feedback ? "ACK" : "NACK");
generate_tx(action); generate_tx(action);
@ -356,7 +355,7 @@ void ul_harq_entity::ul_harq_process::generate_new_tx(mac_interface_phy_lte::mac
harq_entity->average_retx.load(std::memory_order_relaxed), harq_entity->average_retx.load(std::memory_order_relaxed),
harq_entity->nof_pkts++), harq_entity->nof_pkts++),
std::memory_order_relaxed); std::memory_order_relaxed);
cur_grant = grant; cur_grant.set(grant);
harq_feedback = false; harq_feedback = false;
is_grant_configured = true; is_grant_configured = true;
current_tx_nb = 0; current_tx_nb = 0;
@ -368,7 +367,7 @@ void ul_harq_entity::ul_harq_process::generate_new_tx(mac_interface_phy_lte::mac
pid, pid,
grant.rnti == harq_entity->rntis->get_temp_rnti() ? " for Msg3" : "", grant.rnti == harq_entity->rntis->get_temp_rnti() ? " for Msg3" : "",
get_rv(), get_rv(),
cur_grant.tb.tbs); cur_grant.get_tbs());
generate_tx(action); generate_tx(action);
} }
@ -380,7 +379,8 @@ void ul_harq_entity::ul_harq_process::generate_tx(mac_interface_phy_lte::tb_acti
action->current_tx_nb = current_tx_nb; action->current_tx_nb = current_tx_nb;
action->expect_ack = true; action->expect_ack = true;
action->tb.rv = cur_grant.tb.rv > 0 ? cur_grant.tb.rv : get_rv(); int rv = cur_grant.get_rv();
action->tb.rv = rv > 0 ? rv : get_rv();
action->tb.enabled = true; action->tb.enabled = true;
action->tb.payload = pdu_ptr; action->tb.payload = pdu_ptr;
action->tb.softbuffer.tx = &softbuffer; action->tb.softbuffer.tx = &softbuffer;

Loading…
Cancel
Save