SRSUE PHY: move mutex lock to cc worker and unlock for stack calls

master
Xavier Arteaga 4 years ago committed by Xavier Arteaga
parent 4c1d3ef7e8
commit 52355024e7

@ -44,7 +44,7 @@ public:
void set_tti(uint32_t tti); void set_tti(uint32_t tti);
void set_cfo(float cfo); void set_cfo(float cfo);
float get_ref_cfo(); float get_ref_cfo() const;
void set_tdd_config(srslte_tdd_config_t config); void set_tdd_config(srslte_tdd_config_t config);
void set_config(srslte::phy_cfg_t& phy_cfg); void set_config(srslte::phy_cfg_t& phy_cfg);
@ -120,6 +120,9 @@ private:
// Metrics // Metrics
dl_metrics_t dl_metrics = {}; dl_metrics_t dl_metrics = {};
ul_metrics_t ul_metrics = {}; ul_metrics_t ul_metrics = {};
// Mutex, for protecting what matters most: ue_ul, ue_ul_cfg, ue_dl, ue_dl_cfg, cell, pmch_cfg
std::mutex mutex;
}; };
} // namespace srsue } // namespace srsue

@ -69,7 +69,7 @@ public:
uint32_t get_cell_nof_ports() uint32_t get_cell_nof_ports()
{ {
// wait until cell is initialized // wait until cell is initialized
std::unique_lock<std::mutex> lock(mutex); std::unique_lock<std::mutex> lock(cell_mutex);
while (!cell_initiated) { while (!cell_initiated) {
cell_init_cond.wait(lock); cell_init_cond.wait(lock);
} }
@ -98,9 +98,8 @@ private:
chest_feedback_itf* chest_loop = nullptr; chest_feedback_itf* chest_loop = nullptr;
std::mutex mutex; srslte_cell_t cell = {};
std::mutex cell_mutex;
srslte_cell_t cell = {};
srslte_tdd_config_t tdd_config = {}; srslte_tdd_config_t tdd_config = {};
std::condition_variable cell_init_cond; std::condition_variable cell_init_cond;

@ -127,6 +127,8 @@ void cc_worker::reset()
bool cc_worker::set_cell(srslte_cell_t cell_) bool cc_worker::set_cell(srslte_cell_t cell_)
{ {
std::unique_lock<std::mutex> lock(mutex);
if (cell.id != cell_.id || !cell_initiated) { if (cell.id != cell_.id || !cell_initiated) {
cell = cell_; cell = cell_;
@ -178,29 +180,32 @@ void cc_worker::set_tti(uint32_t tti)
void cc_worker::set_cfo(float cfo) void cc_worker::set_cfo(float cfo)
{ {
std::unique_lock<std::mutex> lock(mutex);
ue_ul_cfg.cfo_value = cfo; ue_ul_cfg.cfo_value = cfo;
} }
float cc_worker::get_ref_cfo() float cc_worker::get_ref_cfo() const
{ {
return ue_dl.chest_res.cfo; return ue_dl.chest_res.cfo;
} }
void cc_worker::set_crnti(uint16_t rnti) void cc_worker::set_crnti(uint16_t rnti)
{ {
std::unique_lock<std::mutex> lock(mutex);
srslte_ue_dl_set_rnti(&ue_dl, rnti); srslte_ue_dl_set_rnti(&ue_dl, rnti);
srslte_ue_ul_set_rnti(&ue_ul, rnti); srslte_ue_ul_set_rnti(&ue_ul, rnti);
} }
void cc_worker::set_tdd_config(srslte_tdd_config_t config) void cc_worker::set_tdd_config(srslte_tdd_config_t config)
{ {
std::unique_lock<std::mutex> lock(mutex);
sf_cfg_dl.tdd_config = config; sf_cfg_dl.tdd_config = config;
sf_cfg_ul.tdd_config = config; sf_cfg_ul.tdd_config = config;
} }
void cc_worker::enable_pregen_signals(bool enabled) void cc_worker::enable_pregen_signals(bool enabled)
{ {
this->pregen_enabled = enabled; pregen_enabled = enabled;
} }
/************ /************
@ -211,7 +216,8 @@ void cc_worker::enable_pregen_signals(bool enabled)
bool cc_worker::work_dl_regular() bool cc_worker::work_dl_regular()
{ {
bool dl_ack[SRSLTE_MAX_CODEWORDS] = {}; std::unique_lock<std::mutex> lock(mutex);
bool dl_ack[SRSLTE_MAX_CODEWORDS] = {};
mac_interface_phy_lte::tb_action_dl_t dl_action = {}; mac_interface_phy_lte::tb_action_dl_t dl_action = {};
@ -287,9 +293,17 @@ bool cc_worker::work_dl_regular()
srslte_pdsch_ack_resource_t ack_resource = {dci_dl.dai, dci_dl.location.ncce, grant_cc_idx, dci_dl.tpc_pucch}; srslte_pdsch_ack_resource_t ack_resource = {dci_dl.dai, dci_dl.location.ncce, grant_cc_idx, dci_dl.tpc_pucch};
// Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC // Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC
mutex.unlock();
phy->stack->new_grant_dl(cc_idx, mac_grant, &dl_action); phy->stack->new_grant_dl(cc_idx, mac_grant, &dl_action);
mutex.lock();
// Decode PDSCH
decode_pdsch(ack_resource, &dl_action, dl_ack); decode_pdsch(ack_resource, &dl_action, dl_ack);
// Informs Stack about the decoding status
mutex.unlock();
phy->stack->tb_decoded(cc_idx, mac_grant, dl_ack); phy->stack->tb_decoded(cc_idx, mac_grant, dl_ack);
mutex.lock();
} }
/* Decode PHICH */ /* Decode PHICH */
@ -300,6 +314,7 @@ bool cc_worker::work_dl_regular()
bool cc_worker::work_dl_mbsfn(srslte_mbsfn_cfg_t mbsfn_cfg) bool cc_worker::work_dl_mbsfn(srslte_mbsfn_cfg_t mbsfn_cfg)
{ {
std::unique_lock<std::mutex> lock(mutex);
mac_interface_phy_lte::tb_action_dl_t dl_action = {}; mac_interface_phy_lte::tb_action_dl_t dl_action = {};
// Configure MBSFN settings // Configure MBSFN settings
@ -539,7 +554,8 @@ void cc_worker::decode_phich()
void cc_worker::update_measurements() void cc_worker::update_measurements()
{ {
float snr_ema_coeff = phy->args->snr_ema_coeff; std::unique_lock<std::mutex> lock(mutex);
float snr_ema_coeff = phy->args->snr_ema_coeff;
// In TDD, ignore special subframes without PDSCH // In TDD, ignore special subframes without PDSCH
if (srslte_sfidx_tdd_type(sf_cfg_dl.tdd_config, CURRENT_SFIDX) == SRSLTE_TDD_SF_S && if (srslte_sfidx_tdd_type(sf_cfg_dl.tdd_config, CURRENT_SFIDX) == SRSLTE_TDD_SF_S &&
@ -625,8 +641,8 @@ void cc_worker::update_measurements()
bool cc_worker::work_ul(srslte_uci_data_t* uci_data) bool cc_worker::work_ul(srslte_uci_data_t* uci_data)
{ {
std::unique_lock<std::mutex> lock(mutex);
bool signal_ready; bool signal_ready;
srslte_dci_ul_t dci_ul = {}; srslte_dci_ul_t dci_ul = {};
mac_interface_phy_lte::mac_grant_ul_t ul_mac_grant = {}; mac_interface_phy_lte::mac_grant_ul_t ul_mac_grant = {};
@ -670,7 +686,9 @@ bool cc_worker::work_ul(srslte_uci_data_t* uci_data)
// Fill MAC dci // Fill MAC dci
ul_phy_to_mac_grant(&ue_ul_cfg.ul_cfg.pusch.grant, &dci_ul, pid, ul_grant_available, &ul_mac_grant); ul_phy_to_mac_grant(&ue_ul_cfg.ul_cfg.pusch.grant, &dci_ul, pid, ul_grant_available, &ul_mac_grant);
mutex.unlock();
phy->stack->new_grant_ul(cc_idx, ul_mac_grant, &ul_action); phy->stack->new_grant_ul(cc_idx, ul_mac_grant, &ul_action);
mutex.lock();
// Calculate PUSCH Hopping procedure // Calculate PUSCH Hopping procedure
ue_ul_cfg.ul_cfg.hopping.current_tx_nb = ul_action.current_tx_nb; ue_ul_cfg.ul_cfg.hopping.current_tx_nb = ul_action.current_tx_nb;
@ -857,6 +875,7 @@ uint32_t cc_worker::get_wideband_cqi()
void cc_worker::set_uci_periodic_cqi(srslte_uci_data_t* uci_data) void cc_worker::set_uci_periodic_cqi(srslte_uci_data_t* uci_data)
{ {
std::unique_lock<std::mutex> lock(mutex);
srslte_ue_dl_gen_cqi_periodic(&ue_dl, &ue_dl_cfg, get_wideband_cqi(), CURRENT_TTI_TX, uci_data); srslte_ue_dl_gen_cqi_periodic(&ue_dl, &ue_dl_cfg, get_wideband_cqi(), CURRENT_TTI_TX, uci_data);
} }
@ -910,6 +929,8 @@ void cc_worker::set_uci_ack(srslte_uci_data_t* uci_data,
*/ */
void cc_worker::set_config(srslte::phy_cfg_t& phy_cfg) void cc_worker::set_config(srslte::phy_cfg_t& phy_cfg)
{ {
std::unique_lock<std::mutex> lock(mutex);
// Save configuration // Save configuration
ue_dl_cfg.cfg = phy_cfg.dl_cfg; ue_dl_cfg.cfg = phy_cfg.dl_cfg;
ue_ul_cfg.ul_cfg = phy_cfg.ul_cfg; ue_ul_cfg.ul_cfg = phy_cfg.ul_cfg;
@ -926,6 +947,7 @@ void cc_worker::set_config(srslte::phy_cfg_t& phy_cfg)
void cc_worker::upd_config_dci(srslte_dci_cfg_t& dci_cfg) void cc_worker::upd_config_dci(srslte_dci_cfg_t& dci_cfg)
{ {
std::unique_lock<std::mutex> lock(mutex);
ue_dl_cfg.cfg.dci = dci_cfg; ue_dl_cfg.cfg.dci = dci_cfg;
} }

@ -81,7 +81,6 @@ sf_worker::~sf_worker()
void sf_worker::reset() void sf_worker::reset()
{ {
std::lock_guard<std::mutex> lock(mutex);
rssi_read_cnt = 0; rssi_read_cnt = 0;
for (auto& cc_worker : cc_workers) { for (auto& cc_worker : cc_workers) {
cc_worker->reset(); cc_worker->reset();
@ -90,7 +89,7 @@ void sf_worker::reset()
bool sf_worker::set_cell(uint32_t cc_idx, srslte_cell_t cell_) bool sf_worker::set_cell(uint32_t cc_idx, srslte_cell_t cell_)
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(cell_mutex);
if (cc_idx < cc_workers.size()) { if (cc_idx < cc_workers.size()) {
if (!cc_workers[cc_idx]->set_cell(cell_)) { if (!cc_workers[cc_idx]->set_cell(cell_)) {
@ -156,7 +155,6 @@ void sf_worker::set_cfo(const uint32_t& cc_idx, float cfo)
void sf_worker::set_crnti(uint16_t rnti) void sf_worker::set_crnti(uint16_t rnti)
{ {
std::lock_guard<std::mutex> lock(mutex);
for (auto& cc_worker : cc_workers) { for (auto& cc_worker : cc_workers) {
cc_worker->set_crnti(rnti); cc_worker->set_crnti(rnti);
} }
@ -164,7 +162,6 @@ void sf_worker::set_crnti(uint16_t rnti)
void sf_worker::set_tdd_config(srslte_tdd_config_t config) void sf_worker::set_tdd_config(srslte_tdd_config_t config)
{ {
std::lock_guard<std::mutex> lock(mutex);
for (auto& cc_worker : cc_workers) { for (auto& cc_worker : cc_workers) {
cc_worker->set_tdd_config(config); cc_worker->set_tdd_config(config);
} }
@ -173,7 +170,6 @@ void sf_worker::set_tdd_config(srslte_tdd_config_t config)
void sf_worker::enable_pregen_signals(bool enabled) void sf_worker::enable_pregen_signals(bool enabled)
{ {
std::lock_guard<std::mutex> lock(mutex);
for (auto& cc_worker : cc_workers) { for (auto& cc_worker : cc_workers) {
cc_worker->enable_pregen_signals(enabled); cc_worker->enable_pregen_signals(enabled);
} }
@ -181,7 +177,6 @@ void sf_worker::enable_pregen_signals(bool enabled)
void sf_worker::set_config(uint32_t cc_idx, srslte::phy_cfg_t& phy_cfg) void sf_worker::set_config(uint32_t cc_idx, srslte::phy_cfg_t& phy_cfg)
{ {
std::lock_guard<std::mutex> lock(mutex);
if (cc_idx < cc_workers.size()) { if (cc_idx < cc_workers.size()) {
Info("Setting configuration for worker=%d, cc=%d\n", get_id(), cc_idx); Info("Setting configuration for worker=%d, cc=%d\n", get_id(), cc_idx);
cc_workers[cc_idx]->set_config(phy_cfg); cc_workers[cc_idx]->set_config(phy_cfg);
@ -207,59 +202,55 @@ void sf_worker::work_imp()
bool tx_signal_ready = false; bool tx_signal_ready = false;
uint32_t nof_samples = SRSLTE_SF_LEN_PRB(cell.nof_prb); uint32_t nof_samples = SRSLTE_SF_LEN_PRB(cell.nof_prb);
{ /***** Downlink Processing *******/
std::lock_guard<std::mutex> lock(mutex);
/***** Downlink Processing *******/ // Loop through all carriers. carrier_idx=0 is PCell
for (uint32_t carrier_idx = 0; carrier_idx < cc_workers.size(); carrier_idx++) {
// Loop through all carriers. carrier_idx=0 is PCell // Process all DL and special subframes
for (uint32_t carrier_idx = 0; carrier_idx < cc_workers.size(); carrier_idx++) { if (srslte_sfidx_tdd_type(tdd_config, tti % 10) != SRSLTE_TDD_SF_U || cell.frame_type == SRSLTE_FDD) {
srslte_mbsfn_cfg_t mbsfn_cfg;
ZERO_OBJECT(mbsfn_cfg);
// Process all DL and special subframes if (carrier_idx == 0 && phy->is_mbsfn_sf(&mbsfn_cfg, tti)) {
if (srslte_sfidx_tdd_type(tdd_config, tti % 10) != SRSLTE_TDD_SF_U || cell.frame_type == SRSLTE_FDD) { cc_workers[0]->work_dl_mbsfn(mbsfn_cfg); // Don't do chest_ok in mbsfn since it trigger measurements
srslte_mbsfn_cfg_t mbsfn_cfg; } else {
ZERO_OBJECT(mbsfn_cfg); if ((carrier_idx == 0) || phy->scell_cfg[carrier_idx].enabled) {
rx_signal_ok = cc_workers[carrier_idx]->work_dl_regular();
if (carrier_idx == 0 && phy->is_mbsfn_sf(&mbsfn_cfg, tti)) {
cc_workers[0]->work_dl_mbsfn(mbsfn_cfg); // Don't do chest_ok in mbsfn since it trigger measurements
} else {
if ((carrier_idx == 0) || phy->scell_cfg[carrier_idx].enabled) {
rx_signal_ok = cc_workers[carrier_idx]->work_dl_regular();
}
} }
} }
} }
}
/***** Uplink Generation + Transmission *******/ /***** Uplink Generation + Transmission *******/
/* If TTI+4 is an uplink subframe (TODO: Support short PRACH and SRS in UpPts special subframes) */ /* If TTI+4 is an uplink subframe (TODO: Support short PRACH and SRS in UpPts special subframes) */
if ((srslte_sfidx_tdd_type(tdd_config, TTI_TX(tti) % 10) == SRSLTE_TDD_SF_U) || cell.frame_type == SRSLTE_FDD) { if ((srslte_sfidx_tdd_type(tdd_config, TTI_TX(tti) % 10) == SRSLTE_TDD_SF_U) || cell.frame_type == SRSLTE_FDD) {
// Generate Uplink signal if no PRACH pending // Generate Uplink signal if no PRACH pending
if (!prach_ptr) { if (!prach_ptr) {
// Common UCI data object for all carriers // Common UCI data object for all carriers
srslte_uci_data_t uci_data; srslte_uci_data_t uci_data;
reset_uci(&uci_data); reset_uci(&uci_data);
uint32_t uci_cc_idx = phy->get_ul_uci_cc(TTI_TX(tti)); uint32_t uci_cc_idx = phy->get_ul_uci_cc(TTI_TX(tti));
// Fill periodic CQI data; In case of periodic CSI report collision, lower carrier index have preference, so // Fill periodic CQI data; In case of periodic CSI report collision, lower carrier index have preference, so
// stop as soon as either CQI data is enabled or RI is carried // stop as soon as either CQI data is enabled or RI is carried
for (uint32_t carrier_idx = 0; carrier_idx < phy->args->nof_carriers and not uci_data.cfg.cqi.data_enable and for (uint32_t carrier_idx = 0;
uci_data.cfg.cqi.ri_len == 0; carrier_idx < phy->args->nof_carriers and not uci_data.cfg.cqi.data_enable and uci_data.cfg.cqi.ri_len == 0;
carrier_idx++) { carrier_idx++) {
if (carrier_idx == 0 or phy->scell_cfg[carrier_idx].configured) { if (carrier_idx == 0 or phy->scell_cfg[carrier_idx].configured) {
cc_workers[carrier_idx]->set_uci_periodic_cqi(&uci_data); cc_workers[carrier_idx]->set_uci_periodic_cqi(&uci_data);
}
} }
}
// Loop through all carriers // Loop through all carriers
for (uint32_t carrier_idx = 0; carrier_idx < phy->args->nof_carriers; carrier_idx++) { for (uint32_t carrier_idx = 0; carrier_idx < phy->args->nof_carriers; carrier_idx++) {
tx_signal_ready |= cc_workers[carrier_idx]->work_ul(uci_cc_idx == carrier_idx ? &uci_data : nullptr); tx_signal_ready |= cc_workers[carrier_idx]->work_ul(uci_cc_idx == carrier_idx ? &uci_data : nullptr);
// Set signal pointer based on offset // Set signal pointer based on offset
tx_signal_ptr.set(carrier_idx, 0, phy->args->nof_rx_ant, cc_workers[carrier_idx]->get_tx_buffer(0)); tx_signal_ptr.set(carrier_idx, 0, phy->args->nof_rx_ant, cc_workers[carrier_idx]->get_tx_buffer(0));
}
} }
} }
} }

Loading…
Cancel
Save