SRSUE: avoid deadlock while configuring cell from stack

master
Xavier Arteaga 5 years ago committed by Xavier Arteaga
parent 31d7124ae7
commit 2f0c38fc70

@ -164,6 +164,17 @@ private:
* @param sync_buffer Sub-frame buffer for the current TTI * @param sync_buffer Sub-frame buffer for the current TTI
*/ */
void run_camping_in_sync_state(sf_worker* worker, srslte::rf_buffer_t& sync_buffer); void run_camping_in_sync_state(sf_worker* worker, srslte::rf_buffer_t& sync_buffer);
/**
* Helper method, executed in a TTI basis for signaling to the stack a new TTI execution
*
* The PHY shall not call run_stack_tti when the PHY has reserved a worker.
*
* Since the sync thread has reserved a worker in camping state, the PHY shall not call the stack in this state.
* Otherwise, there a risk that the stack tries to reserve the same worker for configuration.
*/
void run_stack_tti();
float get_tx_cfo(); float get_tx_cfo();
void set_sampling_rate(); void set_sampling_rate();
@ -229,7 +240,8 @@ private:
srslte_cell_t cell = {}; srslte_cell_t cell = {};
bool force_camping_sfn_sync = false; bool force_camping_sfn_sync = false;
uint32_t tti = 0; uint32_t tti = 0;
srslte_timestamp_t tti_ts = {}; srslte_timestamp_t stack_tti_ts_new = {};
srslte_timestamp_t stack_tti_ts = {};
std::array<uint8_t, SRSLTE_BCH_PAYLOAD_LEN> mib = {}; std::array<uint8_t, SRSLTE_BCH_PAYLOAD_LEN> mib = {};
uint32_t nof_workers = 0; uint32_t nof_workers = 0;

@ -506,6 +506,9 @@ void sync::run_camping_state()
worker->release(); worker->release();
break; break;
} }
// Run stack
run_stack_tti();
} }
void sync::run_idle_state() void sync::run_idle_state()
@ -847,26 +850,58 @@ int sync::radio_recv_fnc(srslte::rf_buffer_t& data, srslte_timestamp_t* rx_time)
} }
*rx_time = rf_timestamp.get(0); *rx_time = rf_timestamp.get(0);
// Save RF timestamp for the stack
stack_tti_ts_new = rf_timestamp.get(0);
// Run stack if the sync state is not in camping
if (not phy_state.is_camping()) {
run_stack_tti();
}
// Execute channel DL emulator
if (channel_emulator and rx_time) {
channel_emulator->set_srate((uint32_t)current_srate);
channel_emulator->run(data.to_cf_t(), data.to_cf_t(), data.get_nof_samples(), *rx_time);
}
// Save signal for Intra-frequency measurement
if (srslte_cell_isvalid(&cell)) {
for (uint32_t i = 0; (uint32_t)i < intra_freq_meas.size(); i++) {
intra_freq_meas[i]->write(tti, data.get(i, 0, worker_com->args->nof_rx_ant), SRSLTE_SF_LEN_PRB(cell.nof_prb));
// Update RX gain
intra_freq_meas[i]->set_rx_gain_offset(worker_com->rx_gain_offset);
}
}
log_h->debug("SYNC: received %d samples from radio\n", data.get_nof_samples());
return data.get_nof_samples();
}
void sync::run_stack_tti()
{
// check timestamp reset // check timestamp reset
if (forced_rx_time_init || srslte_timestamp_iszero(&tti_ts) || srslte_timestamp_compare(rx_time, &tti_ts) < 0) { if (forced_rx_time_init || srslte_timestamp_iszero(&stack_tti_ts) ||
if (srslte_timestamp_compare(rx_time, &tti_ts) < 0) { srslte_timestamp_compare(&stack_tti_ts_new, &stack_tti_ts) < 0) {
if (srslte_timestamp_compare(&stack_tti_ts_new, &stack_tti_ts) < 0) {
log_h->warning("SYNC: radio time seems to be going backwards (rx_time=%f, tti_ts=%f)\n", log_h->warning("SYNC: radio time seems to be going backwards (rx_time=%f, tti_ts=%f)\n",
srslte_timestamp_real(rx_time), srslte_timestamp_real(&stack_tti_ts_new),
srslte_timestamp_real(&tti_ts)); srslte_timestamp_real(&stack_tti_ts));
// time-stamp will be set to rx time below and run_tti() will be called with MIN_TTI_JUMP // time-stamp will be set to rx time below and run_tti() will be called with MIN_TTI_JUMP
} }
// init tti_ts with last rx time // init tti_ts with last rx time
log_h->debug("SYNC: Setting initial TTI time to %f\n", srslte_timestamp_real(rx_time)); log_h->debug("SYNC: Setting initial TTI time to %f\n", srslte_timestamp_real(&stack_tti_ts_new));
srslte_timestamp_copy(&tti_ts, rx_time); srslte_timestamp_copy(&stack_tti_ts, &stack_tti_ts_new);
forced_rx_time_init = false; forced_rx_time_init = false;
} }
// Advance stack in time // Advance stack in time
if (srslte_timestamp_compare(rx_time, &tti_ts) >= 0) { if (srslte_timestamp_compare(&stack_tti_ts_new, &stack_tti_ts) >= 0) {
srslte_timestamp_t temp = {}; srslte_timestamp_t temp = {};
srslte_timestamp_copy(&temp, rx_time); srslte_timestamp_copy(&temp, &stack_tti_ts_new);
srslte_timestamp_sub(&temp, tti_ts.full_secs, tti_ts.frac_secs); srslte_timestamp_sub(&temp, stack_tti_ts.full_secs, stack_tti_ts.frac_secs);
int32_t tti_jump = static_cast<int32_t>(srslte_timestamp_uint64(&temp, 1e3)); int32_t tti_jump = static_cast<int32_t>(srslte_timestamp_uint64(&temp, 1e3));
tti_jump = SRSLTE_MAX(tti_jump, MIN_TTI_JUMP); tti_jump = SRSLTE_MAX(tti_jump, MIN_TTI_JUMP);
if (tti_jump > MAX_TTI_JUMP) { if (tti_jump > MAX_TTI_JUMP) {
@ -879,26 +914,7 @@ int sync::radio_recv_fnc(srslte::rf_buffer_t& data, srslte_timestamp_t* rx_time)
} }
// update timestamp // update timestamp
srslte_timestamp_copy(&tti_ts, rx_time); srslte_timestamp_copy(&stack_tti_ts, &stack_tti_ts_new);
if (channel_emulator and rx_time) {
channel_emulator->set_srate((uint32_t)current_srate);
channel_emulator->run(data.to_cf_t(), data.to_cf_t(), data.get_nof_samples(), *rx_time);
}
// Save signal for Intra-frequency measurement
if (srslte_cell_isvalid(&cell)) {
for (uint32_t i = 0; (uint32_t)i < intra_freq_meas.size(); i++) {
intra_freq_meas[i]->write(tti, data.get(i, 0, worker_com->args->nof_rx_ant), SRSLTE_SF_LEN_PRB(cell.nof_prb));
// Update RX gain
intra_freq_meas[i]->set_rx_gain_offset(worker_com->rx_gain_offset);
}
}
log_h->debug("SYNC: received %d samples from radio\n", data.get_nof_samples());
return data.get_nof_samples();
} }
void sync::set_rx_gain(float gain) void sync::set_rx_gain(float gain)

Loading…
Cancel
Save