SRSUE: avoid deadlock while configuring cell from stack

This commit is contained in:
Xavier Arteaga 2020-06-23 11:34:12 +02:00 committed by Xavier Arteaga
parent 31d7124ae7
commit 2f0c38fc70
2 changed files with 60 additions and 32 deletions

View File

@ -164,6 +164,17 @@ private:
* @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);
/**
* 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();
void set_sampling_rate();
@ -229,7 +240,8 @@ private:
srslte_cell_t cell = {};
bool force_camping_sfn_sync = false;
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 = {};
uint32_t nof_workers = 0;

View File

@ -506,6 +506,9 @@ void sync::run_camping_state()
worker->release();
break;
}
// Run stack
run_stack_tti();
}
void sync::run_idle_state()
@ -847,40 +850,15 @@ int sync::radio_recv_fnc(srslte::rf_buffer_t& data, srslte_timestamp_t* rx_time)
}
*rx_time = rf_timestamp.get(0);
// check timestamp reset
if (forced_rx_time_init || srslte_timestamp_iszero(&tti_ts) || srslte_timestamp_compare(rx_time, &tti_ts) < 0) {
if (srslte_timestamp_compare(rx_time, &tti_ts) < 0) {
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(&tti_ts));
// time-stamp will be set to rx time below and run_tti() will be called with MIN_TTI_JUMP
}
// Save RF timestamp for the stack
stack_tti_ts_new = rf_timestamp.get(0);
// init tti_ts with last rx time
log_h->debug("SYNC: Setting initial TTI time to %f\n", srslte_timestamp_real(rx_time));
srslte_timestamp_copy(&tti_ts, rx_time);
forced_rx_time_init = false;
// Run stack if the sync state is not in camping
if (not phy_state.is_camping()) {
run_stack_tti();
}
// Advance stack in time
if (srslte_timestamp_compare(rx_time, &tti_ts) >= 0) {
srslte_timestamp_t temp = {};
srslte_timestamp_copy(&temp, rx_time);
srslte_timestamp_sub(&temp, tti_ts.full_secs, tti_ts.frac_secs);
int32_t tti_jump = static_cast<int32_t>(srslte_timestamp_uint64(&temp, 1e3));
tti_jump = SRSLTE_MAX(tti_jump, MIN_TTI_JUMP);
if (tti_jump > MAX_TTI_JUMP) {
log_h->warning("SYNC: TTI jump of %d limited to %d\n", tti_jump, MAX_TTI_JUMP);
tti_jump = SRSLTE_MIN(tti_jump, MAX_TTI_JUMP);
}
// Run stack
stack->run_tti(tti, tti_jump);
}
// update timestamp
srslte_timestamp_copy(&tti_ts, rx_time);
// 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);
@ -901,6 +879,44 @@ int sync::radio_recv_fnc(srslte::rf_buffer_t& data, srslte_timestamp_t* rx_time)
return data.get_nof_samples();
}
void sync::run_stack_tti()
{
// check timestamp reset
if (forced_rx_time_init || srslte_timestamp_iszero(&stack_tti_ts) ||
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",
srslte_timestamp_real(&stack_tti_ts_new),
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
}
// init tti_ts with last rx time
log_h->debug("SYNC: Setting initial TTI time to %f\n", srslte_timestamp_real(&stack_tti_ts_new));
srslte_timestamp_copy(&stack_tti_ts, &stack_tti_ts_new);
forced_rx_time_init = false;
}
// Advance stack in time
if (srslte_timestamp_compare(&stack_tti_ts_new, &stack_tti_ts) >= 0) {
srslte_timestamp_t temp = {};
srslte_timestamp_copy(&temp, &stack_tti_ts_new);
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));
tti_jump = SRSLTE_MAX(tti_jump, MIN_TTI_JUMP);
if (tti_jump > MAX_TTI_JUMP) {
log_h->warning("SYNC: TTI jump of %d limited to %d\n", tti_jump, MAX_TTI_JUMP);
tti_jump = SRSLTE_MIN(tti_jump, MAX_TTI_JUMP);
}
// Run stack
stack->run_tti(tti, tti_jump);
}
// update timestamp
srslte_timestamp_copy(&stack_tti_ts, &stack_tti_ts_new);
}
void sync::set_rx_gain(float gain)
{
radio_h->set_rx_gain_th(gain);