From d4fd4c835081819c34ede8d782602572969b04c6 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Mon, 20 Dec 2021 17:29:59 +0100 Subject: [PATCH] Fix deadlock --- lib/src/phy/sync/ssb.c | 14 -------- srsue/src/phy/phy_nr_sa.cc | 8 +++-- srsue/src/phy/sync_sa.cc | 37 +++++++------------- srsue/src/phy/test/nr_sa_cell_search_test.cc | 11 +++--- 4 files changed, 23 insertions(+), 47 deletions(-) diff --git a/lib/src/phy/sync/ssb.c b/lib/src/phy/sync/ssb.c index 5223a6248..0cf60f651 100644 --- a/lib/src/phy/sync/ssb.c +++ b/lib/src/phy/sync/ssb.c @@ -420,12 +420,6 @@ int srsran_ssb_set_cfg(srsran_ssb_t* q, const srsran_ssb_cfg_t* cfg) return SRSRAN_ERROR_INVALID_INPUTS; } - printf("-- srate=%.2fMHz; center_freq=%.2fMHz; ssb_freq=%.2fMHz; scs=%s;\n", - cfg->srate_hz / 1e6, - cfg->center_freq_hz / 1e6, - cfg->ssb_freq_hz / 1e6, - srsran_subcarrier_spacing_to_str(cfg->scs)); - // Calculate subcarrier spacing in Hz q->scs_hz = (float)SRSRAN_SUBC_SPACING_NR(cfg->scs); @@ -1133,14 +1127,6 @@ int srsran_ssb_search(srsran_ssb_t* q, const cf_t* in, uint32_t nof_samples, srs return SRSRAN_ERROR; } - if (fabs(q->cfg.ssb_freq_hz - 1842.05e6) < 1e6) { - printf("-- freq=%.3f; N_id=%d; EPRE=%+.2f; RSRP=%+.2f;\n", - q->cfg.ssb_freq_hz, - N_id, - measurements.epre_dB, - measurements.rsrp_dB); - } - // Save result res->N_id = N_id; res->t_offset = t_offset; diff --git a/srsue/src/phy/phy_nr_sa.cc b/srsue/src/phy/phy_nr_sa.cc index e7cc2448c..5c6453bbf 100644 --- a/srsue/src/phy/phy_nr_sa.cc +++ b/srsue/src/phy/phy_nr_sa.cc @@ -146,6 +146,8 @@ phy_interface_rrc_nr::phy_nr_state_t phy_nr_sa::get_state() void phy_nr_sa::reset_nr() { sync.reset(); + + sync.cell_go_idle(); } // This function executes one part of the procedure immediately and returns to continue in the background. @@ -157,10 +159,10 @@ bool phy_nr_sa::start_cell_search(const cell_search_args_t& req) { // TODO: verify arguments are valid before starting procedure - logger.info("Cell Search: Going to IDLE"); - sync.cell_go_idle(); - cmd_worker_cell.add_cmd([this, req]() { + logger.info("Cell Search: Going to IDLE"); + sync.cell_go_idle(); + // Prepare cell search configuration from the request nr::cell_search::cfg_t cfg = {}; cfg.srate_hz = req.srate_hz; diff --git a/srsue/src/phy/sync_sa.cc b/srsue/src/phy/sync_sa.cc index de5bd74eb..d0d530608 100644 --- a/srsue/src/phy/sync_sa.cc +++ b/srsue/src/phy/sync_sa.cc @@ -185,20 +185,18 @@ sync_state::state_t sync_sa::get_state() void sync_sa::run_state_idle() { -#define test 1 - if (radio->is_init() && test) { - logger.debug("Discarding samples and sending tx_end"); - srsran::rf_buffer_t rf_buffer = {}; - rf_buffer.set_nof_samples(slot_sz); - rf_buffer.set(0, rx_buffer); - if (not slot_synchronizer.recv_callback(rf_buffer, last_rx_time.get_ptr(0))) { - logger.error("SYNC: receiving from radio\n"); - } - radio->tx_end(); - } else { - logger.debug("Sleeping 1 s"); - sleep(1); + if (not radio->is_init()) { + return; } + + logger.debug("Discarding samples and sending tx_end"); + srsran::rf_buffer_t rf_buffer = {}; + rf_buffer.set_nof_samples(slot_sz); + rf_buffer.set(0, rx_buffer); + if (not slot_synchronizer.recv_callback(rf_buffer, last_rx_time.get_ptr(0))) { + logger.error("SYNC: receiving from radio\n"); + } + radio->tx_end(); } void sync_sa::run_state_cell_search() @@ -221,19 +219,8 @@ void sync_sa::run_state_cell_search() cell_search_nof_trials++; - if (cs_ret.result == cell_search::ret_t::CELL_FOUND) { - logger.error("CELL FOUND!"); - - rrc_interface_phy_nr::cell_search_result_t result = {}; - result.cell_found = true; - result.pci = cs_ret.ssb_res.N_id; - result.pbch_msg = cs_ret.ssb_res.pbch_msg; - result.measurements = cs_ret.ssb_res.measurements; - stack->cell_search_found_cell(result); - } - // Leave CELL_SEARCH state if error or success and transition to IDLE - if (/*cs_ret.result || */ cell_search_nof_trials >= cell_search_max_trials) { + if (cs_ret.result == cell_search::ret_t::CELL_FOUND || cell_search_nof_trials >= cell_search_max_trials) { phy_state.state_exit(); } } diff --git a/srsue/src/phy/test/nr_sa_cell_search_test.cc b/srsue/src/phy/test/nr_sa_cell_search_test.cc index f4fd7ef70..84cb16f1d 100644 --- a/srsue/src/phy/test/nr_sa_cell_search_test.cc +++ b/srsue/src/phy/test/nr_sa_cell_search_test.cc @@ -38,7 +38,7 @@ public: // Wait for tick std::unique_lock lock(pending_tti_mutex); while (not pending_tti and running) { - pending_tti_cvar.wait(lock); + pending_tti_cvar.wait_for(lock, std::chrono::milliseconds(1)); } // Let the tick proceed @@ -46,12 +46,13 @@ public: pending_tti_cvar.notify_all(); } - void tick() + uint32_t count = 0; + void tick() { // Wait for TTI to get processed std::unique_lock lock(pending_tti_mutex); - while (pending_tti) { - pending_tti_cvar.wait(lock); + while (pending_tti and running) { + pending_tti_cvar.wait_for(lock, std::chrono::milliseconds(1)); } // Let the TTI proceed @@ -376,4 +377,4 @@ int main(int argc, char** argv) radio = nullptr; return 0; -} \ No newline at end of file +}