From 4ba19938155690ec1571fa7ab248457488169d84 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Fri, 26 Apr 2019 14:52:06 +0100 Subject: [PATCH] fixed some race conditions in the scheduler (#411) --- srsenb/src/mac/scheduler.cc | 28 ++++++++++++++-------------- srsenb/src/mac/scheduler_harq.cc | 2 +- srsenb/src/mac/scheduler_ue.cc | 3 ++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 373c450d2..fa8c5e6a4 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -744,7 +744,9 @@ int sched::dl_sched_data(dl_sched_data_t data[MAX_DATA_LIST]) uint32_t pending_tti = tti_rx_ack % 10; if (cfg.cell.nof_prb == 6 and (srslte_prach_tti_opportunity_config_fdd(cfg.prach_config, tti_rx_ack, -1) or pending_msg3[pending_tti].enabled)) { - start_rbg = avail_rbg; + start_rbg = nof_rbg; + avail_rbg = 0; + log_h->debug("SCHED: Skip tti=%d, as it would cause a conflict between PUCCH and PRACH\n", current_tti); } typedef std::map::iterator it_t; @@ -761,9 +763,6 @@ int sched::dl_sched_data(dl_sched_data_t data[MAX_DATA_LIST]) int nof_data_elems = 0; for (it_t iter = ue_db.begin(); iter != ue_db.end(); ++iter) { sched_ue* user = (sched_ue*)&iter->second; - /** - * Tests whether the RAR and Msg3 were scheduled within the expected windows - */ uint16_t rnti = (uint16_t) iter->first; dl_harq_proc* h = user->get_dl_alloc(); @@ -853,6 +852,11 @@ int sched::dl_sched(uint32_t tti, sched_interface::dl_sched_res_t* sched_result) uint32_t tti_rx = (tti + 10240 - TX_DELAY) % 10240; sched_vars::tti_vars_t* tti_vars = &sched_vars.new_tti(tti_rx); + bzero(sched_result, sizeof(sched_interface::dl_sched_res_t)); + + pthread_mutex_lock(&sched_mutex); + pthread_rwlock_rdlock(&rwlock); + /* Initialize variables */ current_tti = tti; sfn = tti / 10; @@ -862,10 +866,6 @@ int sched::dl_sched(uint32_t tti, sched_interface::dl_sched_res_t* sched_result) current_cfi = sched_cfg.nof_ctrl_symbols; bc_aggr_level = 2; rar_aggr_level = 2; - bzero(sched_result, sizeof(sched_interface::dl_sched_res_t)); - - pthread_mutex_lock(&sched_mutex); - pthread_rwlock_rdlock(&rwlock); /* Schedule Broadcast data */ sched_result->nof_bc_elems += dl_sched_bc(sched_result->bc); @@ -922,6 +922,12 @@ int sched::ul_sched(uint32_t tti, srsenb::sched_interface::ul_sched_res_t* sched uint32_t tti_rx = (tti + 10240 - 2 * FDD_HARQ_DELAY_MS) % 10240; sched_vars::tti_vars_t* tti_vars = &sched_vars.new_tti(tti_rx); + // current_cfi is set in dl_sched() + bzero(sched_result, sizeof(sched_interface::ul_sched_res_t)); + + pthread_mutex_lock(&sched_mutex); + pthread_rwlock_rdlock(&rwlock); + /* Initialize variables */ current_tti = tti; sfn = tti/10; @@ -933,12 +939,6 @@ int sched::ul_sched(uint32_t tti, srsenb::sched_interface::ul_sched_res_t* sched int nof_dci_elems = 0; int nof_phich_elems = 0; - // current_cfi is set in dl_sched() - bzero(sched_result, sizeof(sched_interface::ul_sched_res_t)); - - pthread_mutex_lock(&sched_mutex); - pthread_rwlock_rdlock(&rwlock); - // clear previous UL allocations for (it_t it = ue_db.begin(); it != ue_db.end(); ++it) { it->second.set_ul_alloc(NULL); diff --git a/srsenb/src/mac/scheduler_harq.cc b/srsenb/src/mac/scheduler_harq.cc index 5b546f505..f24b2a327 100644 --- a/srsenb/src/mac/scheduler_harq.cc +++ b/srsenb/src/mac/scheduler_harq.cc @@ -201,7 +201,7 @@ bool dl_harq_proc::has_pending_retx(uint32_t tb_idx, uint32_t current_tti) const { uint32_t tti_diff = srslte_tti_interval(current_tti, tti); // NOTE: tti may be ahead of current_tti due to thread flip - return tti_diff < 10240 / 2 and tti_diff >= (SRSLTE_FDD_NOF_HARQ) && !is_empty(tb_idx); + return (tti_diff < (10240 / 2)) and (tti_diff >= SRSLTE_FDD_NOF_HARQ) and !is_empty(tb_idx); } int dl_harq_proc::get_tbs(uint32_t tb_idx) const diff --git a/srsenb/src/mac/scheduler_ue.cc b/srsenb/src/mac/scheduler_ue.cc index 6d69ededf..1251fa5a7 100644 --- a/srsenb/src/mac/scheduler_ue.cc +++ b/srsenb/src/mac/scheduler_ue.cc @@ -974,7 +974,8 @@ bool sched_ue::is_sr_triggered() void sched_ue::reset_timeout_dl_harq(uint32_t tti) { for (int i=0;i 50) { + uint32_t tti_diff = srslte_tti_interval(tti, dl_harq[i].get_tti()); + if (tti_diff > 50 and tti_diff < 10240 / 2) { log_h->info("SCHED: pid=%d is old. tti_pid=%d, now is %d, resetting\n", i, dl_harq[i].get_tti(), tti); dl_harq[i].reset(0); dl_harq[i].reset(1);