From c386bee3994ed1b6980c0a051ca6a44c4514624c Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 30 Jan 2018 12:52:31 +0100 Subject: [PATCH 1/4] Fixed PUSCH aperiodic report bug. --- lib/src/phy/phch/test/pusch_test.c | 2 +- lib/src/phy/ue/ue_ul.c | 1 - srsue/hdr/mac/ul_harq.h | 8 +++++++- srsue/src/phy/phch_worker.cc | 20 ++++++++++++++++---- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/src/phy/phch/test/pusch_test.c b/lib/src/phy/phch/test/pusch_test.c index 651803617..a7a3c49bf 100644 --- a/lib/src/phy/phch/test/pusch_test.c +++ b/lib/src/phy/phch/test/pusch_test.c @@ -193,7 +193,7 @@ int main(int argc, char **argv) { uci_data_tx.uci_ack_len = 1; memcpy(&uci_data_rx, &uci_data_tx, sizeof(srslte_uci_data_t)); - for (uint32_t i=0;i<20;i++) { + for (uint32_t i=0;irnti_type == SRSLTE_RNTI_TEMP) && grant->ndi[0] != get_ndi() && harq_feedback) || + if (grant->has_cqi_request && grant->phy_grant.ul.mcs.tbs == 0) { + /* Only CQI reporting (without SCH) */ + memcpy(&action->phy_grant.ul, &grant->phy_grant.ul, sizeof(srslte_ra_ul_grant_t)); + memcpy(&cur_grant, grant, sizeof(Tgrant)); + action->tx_enabled = true; + action->rnti = grant->rnti; + } else if ((!(grant->rnti_type == SRSLTE_RNTI_TEMP) && grant->ndi[0] != get_ndi() && harq_feedback) || (grant->rnti_type == SRSLTE_RNTI_USER && !has_grant()) || grant->is_from_rar) { diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 2910f07ff..0c05c5efa 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -771,7 +771,7 @@ bool phch_worker::decode_pdcch_ul(mac_interface_phy::mac_grant_t* grant) // Handle Format0 adaptive retx if (ret) { // Use last TBS for this TB in case of mcs>28 - if (grant->phy_grant.ul.mcs.idx > 28) { + if (grant->phy_grant.ul.mcs.idx > 28 && grant->phy_grant.ul.mcs.mod == SRSLTE_MOD_LAST) { // Make sure we received a grant in the previous TTI for this PID grant->phy_grant.ul.mcs.tbs = phy->last_ul_tbs[UL_PIDOF(TTI_TX(tti))]; grant->phy_grant.ul.mcs.mod = phy->last_ul_mod[UL_PIDOF(TTI_TX(tti))]; @@ -924,8 +924,16 @@ void phch_worker::set_uci_aperiodic_cqi() cqi_report.subband_hl.subband_diff_cqi_cw0 = 0; // Always report zero offset on all subbands cqi_report.subband_hl.N = (cell.nof_prb > 7) ? srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0; - Info("PUSCH: Aperiodic CQI=%d, SNR=%.1f dB, for %d subbands\n", cqi_report.wideband.wideband_cqi, phy->avg_snr_db, cqi_report.subband_hl.N); uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + + char cqi_str[64] = {0}; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 64); + + Info("PUSCH: Aperiodic CQI=%s, SNR=%.1f dB, for %d subbands\n", cqi_str, phy->avg_snr_db, cqi_report.subband_hl.N); + + /* Fake RI = 1 */ + uci_data.uci_ri = 0; + uci_data.uci_ri_len = 0; } break; case LIBLTE_RRC_CQI_REPORT_MODE_APERIODIC_RM31: @@ -966,6 +974,11 @@ void phch_worker::set_uci_aperiodic_cqi() // TODO: implement subband CQI properly cqi_report.subband_hl.N = (uint32_t) ((cell.nof_prb > 7) ? srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0); + uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + + char cqi_str[64] = {0}; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 64); + if (cqi_report.subband_hl.rank_is_not_one) { Info("PUSCH: Aperiodic ri~1, CQI=%02d/%02d, SINR=%2.1f/%2.1fdB, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, cqi_report.subband_hl.wideband_cqi_cw1, @@ -975,7 +988,6 @@ void phch_worker::set_uci_aperiodic_cqi() cqi_report.subband_hl.wideband_cqi_cw0, sinr_db, pmi, cqi_report.subband_hl.N); } - uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); } break; default: @@ -1048,7 +1060,7 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui (tti + HARQ_DELAY_MS) % 10240, grant->n_prb[0], grant->n_prb[0] + grant->L_prb, grant->mcs.tbs / 8, grant->mcs.idx, rv, - uci_data.uci_ack_len > 0 ? (uci_data.uci_ack ? ", ack=1" : "0") : "", + uci_data.uci_ack_len > 0 ? (uci_data.uci_ack ? ", ack=1" : ", ack=0") : "", uci_data.uci_ack_len > 1 ? (uci_data.uci_ack_2 ? "1" : "0") : "", uci_data.uci_ri_len > 0 ? (uci_data.uci_ri ? ", ri=1" : ", ri=0") : "", cfo * 15, timestr, From 684a4c37dcc767da1bd69ea85499e06224b76ef2 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 30 Jan 2018 13:11:44 +0100 Subject: [PATCH 2/4] Do not catch SIGKILL --- srsenb/src/main.cc | 1 - srsue/src/main.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index e2b00fd1f..3aedda25a 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -366,7 +366,6 @@ int main(int argc, char *argv[]) { signal(SIGINT, sig_int_handler); signal(SIGTERM, sig_int_handler); - signal(SIGKILL, sig_int_handler); all_args_t args; metrics_stdout metrics; enb *enb = enb::get_instance(); diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 84748748b..444621c12 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -426,7 +426,6 @@ int main(int argc, char *argv[]) srslte::metrics_hub metricshub; signal(SIGINT, sig_int_handler); signal(SIGTERM, sig_int_handler); - signal(SIGKILL, sig_int_handler); all_args_t args; srslte_debug_handle_crash(argc, argv); From 7d633951a94c43f4d652469c3b69b4a40a20d7f8 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 30 Jan 2018 13:13:41 +0100 Subject: [PATCH 3/4] Improved srsUE stability when loosing signal and restoring it --- srsue/hdr/phy/phch_common.h | 1 + srsue/hdr/phy/phch_recv.h | 6 ++--- srsue/hdr/phy/prach.h | 1 + srsue/src/phy/phch_recv.cc | 50 ++++++++++++++++-------------------- srsue/src/phy/phch_worker.cc | 11 +++----- srsue/src/phy/prach.cc | 6 ++++- srsue/src/upper/rrc.cc | 4 +-- 7 files changed, 37 insertions(+), 42 deletions(-) diff --git a/srsue/hdr/phy/phch_common.h b/srsue/hdr/phy/phch_common.h index fd73d9421..77fd50ff9 100644 --- a/srsue/hdr/phy/phch_common.h +++ b/srsue/hdr/phy/phch_common.h @@ -46,6 +46,7 @@ namespace srsue { class chest_feedback_itf { public: + virtual void in_sync() = 0; virtual void out_of_sync() = 0; virtual void set_cfo(float cfo) = 0; }; diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index ed4bd706a..0530459df 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -75,6 +75,7 @@ public: bool status_is_sync(); // from chest_feedback_itf + void in_sync(); void out_of_sync(); void set_cfo(float cfo); @@ -153,7 +154,7 @@ private: srslte_ue_mib_t ue_mib; uint32_t cnt; uint32_t timeout; - const static uint32_t SYNC_SFN_TIMEOUT = 200; + const static uint32_t SYNC_SFN_TIMEOUT = 500; }; // Class to perform cell measurements @@ -324,9 +325,6 @@ private: int cur_earfcn_index; bool cell_search_in_progress; - uint32_t out_of_sync_cnt; - uint32_t out_of_sync2_cnt; - float dl_freq; float ul_freq; diff --git a/srsue/hdr/phy/prach.h b/srsue/hdr/phy/prach.h index 8218ca644..09be0c9b2 100644 --- a/srsue/hdr/phy/prach.h +++ b/srsue/hdr/phy/prach.h @@ -56,6 +56,7 @@ namespace srsue { bool set_cell(srslte_cell_t cell); bool prepare_to_send(uint32_t preamble_idx, int allowed_subframe = -1, float target_power_dbm = -1); bool is_ready_to_send(uint32_t current_tti); + bool is_pending(); int tx_tti(); void send(srslte::radio* radio_handler, float cfo, float pathloss, srslte_timestamp_t rx_time); diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 834be7624..7d89892c9 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -97,7 +97,7 @@ void phch_recv::init(srslte::radio_multi *_radio_handler, mac_interface_phy *_ma intra_freq_meas.init(worker_com, rrc, log_h); reset(); - + running = true; // Start main thread if (sync_cpu_affinity < 0) { start(prio); @@ -125,7 +125,6 @@ void phch_recv::stop() void phch_recv::reset() { tx_mutex_cnt = 0; - running = true; phy_state = IDLE; time_adv_sec = 0; next_offset = 0; @@ -690,6 +689,12 @@ void phch_recv::run_thread() worker->set_tti(tti, tx_mutex_cnt); tx_mutex_cnt = (tx_mutex_cnt+1) % nof_tx_mutex; + // Reset Uplink TX buffer to avoid mixing packets in TX queue + if (prach_buffer->is_pending()) { + Info("SYNC: PRACH pending: Reset UL\n"); + worker_com->reset_ul(); + } + // Check if we need to TX a PRACH if (prach_buffer->is_ready_to_send(tti)) { srslte_timestamp_copy(&tx_time_prach, &rx_time); @@ -706,21 +711,11 @@ void phch_recv::run_thread() srslte_pss_sic(&ue_sync.strack.pss, &buffer[0][SRSLTE_SF_LEN_PRB(cell.nof_prb)/2-ue_sync.strack.fft_size]); } intra_freq_meas.write(tti, buffer[0], SRSLTE_SF_LEN_PRB(cell.nof_prb)); - out_of_sync_cnt = 0; break; case 0: - // Signal every 5 errors only (PSS is every 5) - if (out_of_sync_cnt == 0) { - // Notify RRC of out-of-sync frame - log_h->error("SYNC: Sync error. Sending out-of-sync to RRC\n"); - rrc->out_of_sync(); - } + out_of_sync(); worker->release(); worker_com->reset_ul(); - out_of_sync_cnt++; - if (out_of_sync_cnt >= 5) { - out_of_sync_cnt = 0; - } break; default: radio_error(); @@ -746,14 +741,12 @@ void phch_recv::run_thread() } } +void phch_recv::in_sync() { + rrc->in_sync(); +} + void phch_recv::out_of_sync() { - out_of_sync2_cnt++; - Info("SYNC: Received out_of_sync from channel estimator (%d)\n", out_of_sync2_cnt); - if (out_of_sync2_cnt >= 2) { - out_of_sync2_cnt = 0; - Info("SYNC: Trying to resync signal\n"); - resync_sfn(true, true); - } + rrc->out_of_sync(); } @@ -1085,7 +1078,7 @@ phch_recv::measure::ret_code phch_recv::measure::run_subframe_sync(srslte_ue_syn { int sync_res = srslte_ue_sync_zerocopy_multi(ue_sync, buffer); if (sync_res == 1) { - log_h->info("SYNC: CFO=%.1f KHz\n", srslte_ue_sync_get_cfo(ue_sync)); + log_h->info("SYNC: CFO=%.1f KHz\n", srslte_ue_sync_get_cfo(ue_sync)/1000); return run_subframe(sf_idx); } else { log_h->error("SYNC: Measuring RSRP: Sync error\n"); @@ -1284,10 +1277,11 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, srslte_sync_reset(&sync_find); srslte_sync_cfo_reset(&sync_find); - uint32_t sf5_cnt=0; + int sf5_cnt=-1; do { + sf5_cnt++; sync_res = srslte_sync_find(&sync_find, input_buffer, sf5_cnt*5*sf_len, &peak_idx); - } while(sync_res != SRSLTE_SYNC_FOUND && sf5_cnt < nof_sf/5); + } while(sync_res != SRSLTE_SYNC_FOUND && (uint32_t) sf5_cnt + 1 < nof_sf/5); switch(sync_res) { case SRSLTE_SYNC_ERROR: @@ -1315,20 +1309,20 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, -srslte_sync_get_cfo(&sync_find)/sync_find.fft_size); - switch(measure_p.run_multiple_subframes(input_cfo_corrected, peak_idx, sf_idx, nof_sf)) { + switch(measure_p.run_multiple_subframes(input_cfo_corrected, peak_idx+sf5_cnt*5*sf_len, sf_idx, nof_sf)) { case measure::MEASURE_OK: cells[nof_cells].pci = found_cell.id; cells[nof_cells].rsrp = measure_p.rsrp(); cells[nof_cells].rsrq = measure_p.rsrq(); cells[nof_cells].offset = measure_p.frame_st_idx(); - Info("INTRA: Found neighbour cell %d: PCI=%03d, RSRP=%5.1f dBm, peak_idx=%5d, peak_value=%3.2f n_id_2=%d, CFO=%6.1f Hz\n", - nof_cells, cell_id, measure_p.rsrp(), measure_p.frame_st_idx(), sync_find.peak_value, n_id_2, 15000*srslte_sync_get_cfo(&sync_find)); + Info("INTRA: Found neighbour cell %d: PCI=%03d, RSRP=%5.1f dBm, peak_idx=%5d, peak_value=%3.2f, sf5_cnt=%d, n_id_2=%d, CFO=%6.1f Hz\n", + nof_cells, cell_id, measure_p.rsrp(), measure_p.frame_st_idx(), sync_find.peak_value, sf5_cnt, n_id_2, 15000*srslte_sync_get_cfo(&sync_find)); nof_cells++; if (sic_pss_enabled) { - srslte_pss_sic(&sync_find.pss, &input_buffer[sf_len/2-fft_sz]); + srslte_pss_sic(&sync_find.pss, &input_buffer[sf5_cnt*5*sf_len+sf_len/2-fft_sz]); } break; @@ -1349,7 +1343,7 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, default: break; } - } while (sync_res == SRSLTE_SYNC_FOUND && sic_pss_enabled); + } while (sync_res == SRSLTE_SYNC_FOUND && sic_pss_enabled && nof_cells < MAX_CELLS); } } return nof_cells; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 2910f07ff..4bae892f3 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -175,8 +175,6 @@ void phch_worker::set_tti(uint32_t tti_, uint32_t tx_tti_) tx_tti = tx_tti_; log_h->step(tti); log_phy_lib_h->step(tti); - - } void phch_worker::set_cfo(float cfo_) @@ -364,13 +362,12 @@ void phch_worker::work_imp() if (chest_ok) { if (snr_th_ok) { - phy->rrc->in_sync(); - log_h->debug("SYNC: Sending in-sync to RRC\n"); + log_h->debug("SNR=%.1f dB sync=in-sync from channel estimator\n", 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))); + chest_loop->in_sync(); } else if (snr_th_err) { - chest_loop->out_of_sync(); - phy->rrc->out_of_sync(); - log_h->info("SNR=%.1f dB under threshold. Sending out-of-sync to RRC\n", + log_h->info("SNR=%.1f dB sync=out-of-sync from channel estimator\n", 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))); + chest_loop->out_of_sync(); } } diff --git a/srsue/src/phy/prach.cc b/srsue/src/phy/prach.cc index 498ea1c6a..fdf925642 100644 --- a/srsue/src/phy/prach.cc +++ b/srsue/src/phy/prach.cc @@ -152,8 +152,12 @@ bool prach::prepare_to_send(uint32_t preamble_idx_, int allowed_subframe_, float } } +bool prach::is_pending() { + return cell_initiated && preamble_idx >= 0 && preamble_idx < 64; +} + bool prach::is_ready_to_send(uint32_t current_tti_) { - if (cell_initiated && preamble_idx >= 0 && preamble_idx < 64) { + if (is_pending()) { // consider the number of subframes the transmission must be anticipated uint32_t current_tti = (current_tti_ + tx_advance_sf)%10240; if (srslte_prach_tti_opportunity(&prach_obj, current_tti, allowed_subframe)) { diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 654d64b40..84e4bbfd1 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -722,7 +722,6 @@ float rrc::get_squal(float Qqualmeas) { // Detection of physical layer problems (5.3.11.1) void rrc::out_of_sync() { - // attempt resync current_cell->in_sync = false; if (!mac_timers->timer_get(t311)->is_running() && !mac_timers->timer_get(t310)->is_running()) { n310_cnt++; @@ -730,7 +729,8 @@ void rrc::out_of_sync() { mac_timers->timer_get(t310)->reset(); mac_timers->timer_get(t310)->run(); n310_cnt = 0; - rrc_log->info("Detected %d out-of-sync from PHY. Starting T310 timer\n", N310); + phy->sync_reset(); + rrc_log->info("Detected %d out-of-sync from PHY. Trying to resync. Starting T310 timer\n", N310); } } } From 9b6e18d84fac5ec28412115ede38c1ab65da2112 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 30 Jan 2018 13:27:03 +0100 Subject: [PATCH 4/4] Lower srsENB priorities below UHD threads --- lib/include/srslte/common/buffer_pool.h | 8 ++++++-- lib/include/srslte/common/common.h | 2 +- srsenb/hdr/mac/mac.h | 2 +- srsenb/hdr/upper/gtpu.h | 2 +- srsenb/hdr/upper/rrc.h | 2 +- srsenb/hdr/upper/s1ap.h | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 567203c75..16d21dce8 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -79,7 +79,10 @@ public: printf("%s\n", strlen(used[i]->debug_name)?used[i]->debug_name:"Undefined"); } } - + + bool is_almost_empty() { + return available.size() < capacity/20; + } buffer_t* allocate(const char *debug_name = NULL) { @@ -92,8 +95,9 @@ public: used.push_back(b); available.pop(); - if (available.size() < capacity/20) { + if (is_almost_empty()) { printf("Warning buffer pool capacity is %f %%\n", (float) 100*available.size()/capacity); + print_all_buffers(); } #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED if (debug_name) { diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 41a89fb36..ddd558016 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -63,7 +63,7 @@ #define SRSLTE_MAX_BUFFER_SIZE_BYTES 12756 #define SRSLTE_BUFFER_HEADER_OFFSET 1024 -//#define SRSLTE_BUFFER_POOL_LOG_ENABLED +#define SRSLTE_BUFFER_POOL_LOG_ENABLED #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED #define pool_allocate (pool->allocate(__FUNCTION__)) diff --git a/srsenb/hdr/mac/mac.h b/srsenb/hdr/mac/mac.h index 4e37d439f..c99b733fb 100644 --- a/srsenb/hdr/mac/mac.h +++ b/srsenb/hdr/mac/mac.h @@ -121,7 +121,7 @@ private: static const uint32_t cfi = 3; srslte_dci_location_t locations[MAX_LOCATIONS]; - static const int MAC_PDU_THREAD_PRIO = 3; + static const int MAC_PDU_THREAD_PRIO = 60; diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index 6ec371655..6958773b6 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -84,7 +84,7 @@ public: private: - static const int THREAD_PRIO = 7; + static const int THREAD_PRIO = 65; static const int GTPU_PORT = 2152; srslte::byte_buffer_pool *pool; bool running; diff --git a/srsenb/hdr/upper/rrc.h b/srsenb/hdr/upper/rrc.h index 97741a670..764320cc6 100644 --- a/srsenb/hdr/upper/rrc.h +++ b/srsenb/hdr/upper/rrc.h @@ -321,7 +321,7 @@ private: const static uint32_t LCID_REM_USER = 0xffff0001; bool running; - static const int RRC_THREAD_PRIO = 7; + static const int RRC_THREAD_PRIO = 65; srslte::block_queue rx_pdu_queue; typedef struct { diff --git a/srsenb/hdr/upper/s1ap.h b/srsenb/hdr/upper/s1ap.h index 02e5e207e..714035638 100644 --- a/srsenb/hdr/upper/s1ap.h +++ b/srsenb/hdr/upper/s1ap.h @@ -85,7 +85,7 @@ public: //void ue_capabilities(uint16_t rnti, LIBLTE_RRC_UE_EUTRA_CAPABILITY_STRUCT *caps); private: - static const int S1AP_THREAD_PRIO = 7; + static const int S1AP_THREAD_PRIO = 65; static const int MME_PORT = 36412; static const int ADDR_FAMILY = AF_INET; static const int SOCK_TYPE = SOCK_STREAM;