From ecaaf8d595093bdf0783e317c96584caed97958f Mon Sep 17 00:00:00 2001 From: Francisco Date: Wed, 1 Dec 2021 14:44:29 +0000 Subject: [PATCH] nr,gnb,sched: implement helper methods to check available PRBs in BWP, taking into account common SearchSpace BW limitations --- srsgnb/hdr/stack/mac/sched_nr_cfg.h | 14 +++++++ .../hdr/stack/mac/sched_nr_grant_allocator.h | 5 +++ srsgnb/src/stack/mac/sched_nr_bwp.cc | 5 ++- srsgnb/src/stack/mac/sched_nr_cfg.cc | 38 ++++++++++++------- srsgnb/src/stack/mac/sched_nr_helpers.cc | 9 +++-- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/srsgnb/hdr/stack/mac/sched_nr_cfg.h b/srsgnb/hdr/stack/mac/sched_nr_cfg.h index b7af47215..1d986e95d 100644 --- a/srsgnb/hdr/stack/mac/sched_nr_cfg.h +++ b/srsgnb/hdr/stack/mac/sched_nr_cfg.h @@ -95,6 +95,20 @@ struct bwp_params_t { srsran::optional_vector common_cce_list; bwp_params_t(const cell_cfg_t& cell, const sched_args_t& sched_cfg_, uint32_t cc, uint32_t bwp_id); + + const prb_bitmap& used_prbs(uint32_t ss_id, srsran_dci_format_nr_t dci_fmt) const + { + if (used_common_prb_masks.contains(ss_id)) { + if (dci_fmt == srsran_dci_format_nr_1_0) { + return used_common_prb_masks[ss_id]; + } + } + return cached_empty_prb_mask; + } + +private: + prb_bitmap cached_empty_prb_mask; + srsran::optional_vector used_common_prb_masks; }; /// Structure packing a single cell config params, and sched args diff --git a/srsgnb/hdr/stack/mac/sched_nr_grant_allocator.h b/srsgnb/hdr/stack/mac/sched_nr_grant_allocator.h index 21541c5b6..b7b4455eb 100644 --- a/srsgnb/hdr/stack/mac/sched_nr_grant_allocator.h +++ b/srsgnb/hdr/stack/mac/sched_nr_grant_allocator.h @@ -62,6 +62,11 @@ struct bwp_slot_grid { bool is_dl() const { return cfg->slots[slot_idx].is_dl; } bool is_ul() const { return cfg->slots[slot_idx].is_ul; } + + prb_bitmap used_prbs(uint32_t ss_id, srsran_dci_format_nr_t dci_fmt) const + { + return dl_prbs.prbs() | cfg->used_prbs(ss_id, dci_fmt); + } }; struct bwp_res_grid { diff --git a/srsgnb/src/stack/mac/sched_nr_bwp.cc b/srsgnb/src/stack/mac/sched_nr_bwp.cc index c198a4a9a..14b941a50 100644 --- a/srsgnb/src/stack/mac/sched_nr_bwp.cc +++ b/srsgnb/src/stack/mac/sched_nr_bwp.cc @@ -24,8 +24,9 @@ ra_sched::ra_sched(const bwp_params_t& bwp_cfg_) : alloc_result ra_sched::allocate_pending_rar(bwp_slot_allocator& slot_grid, const pending_rar_t& rar, uint32_t& nof_grants_alloc) { - const uint32_t rar_aggr_level = 2; - const prb_bitmap& prbs = slot_grid.res_grid()[slot_grid.get_pdcch_tti()].dl_prbs.prbs(); + const uint32_t rar_aggr_level = 2; + prb_bitmap prbs = slot_grid.res_grid()[slot_grid.get_pdcch_tti()].used_prbs(bwp_cfg->cfg.pdcch.ra_search_space.id, + srsran_dci_format_nr_1_0); alloc_result ret = alloc_result::other_cause; srsran::const_span msg3_grants{rar.msg3_grant}; diff --git a/srsgnb/src/stack/mac/sched_nr_cfg.cc b/srsgnb/src/stack/mac/sched_nr_cfg.cc index e02ff06b6..bc89ebbc1 100644 --- a/srsgnb/src/stack/mac/sched_nr_cfg.cc +++ b/srsgnb/src/stack/mac/sched_nr_cfg.cc @@ -51,6 +51,7 @@ bwp_params_t::bwp_params_t(const cell_cfg_t& cell, const sched_args_t& sched_cfg P = get_P(cfg.rb_width, cfg.pdsch.rbg_size_cfg_1); N_rbg = get_nof_rbgs(cfg.rb_width, cfg.start_rb, cfg.pdsch.rbg_size_cfg_1); + cached_empty_prb_mask.resize(cfg.rb_width); // Derive params of individual slots uint32_t nof_slots = SRSRAN_NSLOTS_PER_FRAME_NR(cfg.numerology_idx); @@ -91,19 +92,30 @@ bwp_params_t::bwp_params_t(const cell_cfg_t& cell, const sched_args_t& sched_cfg } for (uint32_t ss_id = 0; ss_id < SRSRAN_UE_DL_NR_MAX_NOF_SEARCH_SPACE; ++ss_id) { - if (cell_cfg.bwps[0].pdcch.search_space_present[ss_id]) { - auto& ss = cell_cfg.bwps[0].pdcch.search_space[ss_id]; - auto& coreset = cell_cfg.bwps[0].pdcch.coreset[ss.coreset_id]; - common_cce_list.emplace(ss_id); - bwp_cce_pos_list& ss_cce_list = common_cce_list[ss_id]; - for (uint32_t sl = 0; sl < SRSRAN_NOF_SF_X_FRAME; ++sl) { - for (uint32_t agg_idx = 0; agg_idx < MAX_NOF_AGGR_LEVELS; ++agg_idx) { - ss_cce_list[sl][agg_idx].resize(SRSRAN_SEARCH_SPACE_MAX_NOF_CANDIDATES_NR); - int n = srsran_pdcch_nr_locations_coreset( - &coreset, &ss, SRSRAN_SIRNTI, agg_idx, sl, ss_cce_list[sl][agg_idx].data()); - srsran_assert(n >= 0, "Failed to configure DCI locations of search space id=%d", ss_id); - ss_cce_list[sl][agg_idx].resize(n); - } + if (not cell_cfg.bwps[0].pdcch.search_space_present[ss_id]) { + continue; + } + auto& ss = cell_cfg.bwps[0].pdcch.search_space[ss_id]; + auto& coreset = cell_cfg.bwps[0].pdcch.coreset[ss.coreset_id]; + common_cce_list.emplace(ss_id); + bwp_cce_pos_list& ss_cce_list = common_cce_list[ss_id]; + for (uint32_t sl = 0; sl < SRSRAN_NOF_SF_X_FRAME; ++sl) { + for (uint32_t agg_idx = 0; agg_idx < MAX_NOF_AGGR_LEVELS; ++agg_idx) { + ss_cce_list[sl][agg_idx].resize(SRSRAN_SEARCH_SPACE_MAX_NOF_CANDIDATES_NR); + int n = srsran_pdcch_nr_locations_coreset( + &coreset, &ss, SRSRAN_SIRNTI, agg_idx, sl, ss_cce_list[sl][agg_idx].data()); + srsran_assert(n >= 0, "Failed to configure DCI locations of search space id=%d", ss_id); + ss_cce_list[sl][agg_idx].resize(n); + } + } + + if (SRSRAN_SEARCH_SPACE_IS_COMMON(ss.type)) { + used_common_prb_masks.emplace(ss_id, cached_empty_prb_mask); + uint32_t coreset_start = srsran_coreset_start_rb(&cfg.pdcch.coreset[ss.coreset_id]); + used_common_prb_masks[ss_id].fill(0, coreset_start, true); + if (ss.coreset_id == 0) { + uint32_t coreset0_bw = srsran_coreset_get_bw(&cfg.pdcch.coreset[0]); + used_common_prb_masks[ss_id].fill(coreset_start + coreset0_bw, cfg.rb_width, true); } } } diff --git a/srsgnb/src/stack/mac/sched_nr_helpers.cc b/srsgnb/src/stack/mac/sched_nr_helpers.cc index 5b08610f8..73958562a 100644 --- a/srsgnb/src/stack/mac/sched_nr_helpers.cc +++ b/srsgnb/src/stack/mac/sched_nr_helpers.cc @@ -84,6 +84,7 @@ void fill_dci_grant(const bwp_params_t& bwp_cfg, const prb_grant& grant, srsran_ if (dci.ctx.coreset_id == 0 and SRSRAN_SEARCH_SPACE_IS_COMMON(dci.ctx.ss_type)) { nof_prb = dci.coreset0_bw; } + srsran_assert(grant.prbs().start() >= rb_start, "Invalid PRB index=%d < %d", grant.prbs().start(), rb_start); uint32_t grant_start = grant.prbs().start() - rb_start; dci.freq_domain_assigment = srsran_ra_nr_type1_riv(nof_prb, grant_start, grant.prbs().length()); } @@ -233,9 +234,9 @@ void log_sched_bwp_result(srslog::basic_logger& logger, data_count++; } else if (pdcch.dci.ctx.rnti_type == srsran_rnti_type_ra) { const pdsch_t& pdsch = bwp_slot.dl.phy.pdsch[std::distance(bwp_slot.dl.phy.pdcch_dl.data(), &pdcch)]; - srsran::const_span prbs{pdsch.sch.grant.prb_idx, pdsch.sch.grant.prb_idx + pdsch.sch.grant.nof_prb}; + srsran::const_span prbs{pdsch.sch.grant.prb_idx, pdsch.sch.grant.prb_idx + SRSRAN_MAX_PRB_NR}; uint32_t start_idx = std::distance(prbs.begin(), std::find(prbs.begin(), prbs.end(), true)); - uint32_t end_idx = std::distance(prbs.begin(), std::find(prbs.begin() + start_idx, prbs.end(), false)); + uint32_t end_idx = start_idx + pdsch.sch.grant.nof_prb; fmt::format_to(fmtbuf, "SCHED: RAR, cc={}, ra-rnti=0x{:x}, prbs={}, pdsch_slot={}, msg3_slot={}, nof_grants={}", res_grid.cfg->cc, @@ -248,9 +249,9 @@ void log_sched_bwp_result(srslog::basic_logger& logger, } else if (pdcch.dci.ctx.rnti_type == srsran_rnti_type_si) { if (logger.debug.enabled()) { const pdsch_t& pdsch = bwp_slot.dl.phy.pdsch[std::distance(bwp_slot.dl.phy.pdcch_dl.data(), &pdcch)]; - srsran::const_span prbs{pdsch.sch.grant.prb_idx, pdsch.sch.grant.prb_idx + pdsch.sch.grant.nof_prb}; + srsran::const_span prbs{pdsch.sch.grant.prb_idx, pdsch.sch.grant.prb_idx + SRSRAN_MAX_PRB_NR}; uint32_t start_idx = std::distance(prbs.begin(), std::find(prbs.begin(), prbs.end(), true)); - uint32_t end_idx = std::distance(prbs.begin(), std::find(prbs.begin() + start_idx, prbs.end(), false)); + uint32_t end_idx = start_idx + pdsch.sch.grant.nof_prb; fmt::format_to(fmtbuf, "SCHED: SI{}, cc={}, prbs={}, pdsch_slot={}", pdcch.dci.sii == 0 ? "B" : " message",