diff --git a/srsenb/hdr/stack/mac/sched_common.h b/srsenb/hdr/stack/mac/sched_common.h index 650302fdd..e1d7cda76 100644 --- a/srsenb/hdr/stack/mac/sched_common.h +++ b/srsenb/hdr/stack/mac/sched_common.h @@ -61,6 +61,8 @@ public: uint32_t nof_rbgs = 0; }; +using ue_cce_locations_table = std::array, SRSLTE_NOF_CFI>; + //! Bitmask used for CCE allocations using pdcch_mask_t = srslte::bounded_bitset; diff --git a/srsenb/hdr/stack/mac/sched_helpers.h b/srsenb/hdr/stack/mac/sched_helpers.h index 3006010f2..9da7e5fec 100644 --- a/srsenb/hdr/stack/mac/sched_helpers.h +++ b/srsenb/hdr/stack/mac/sched_helpers.h @@ -100,6 +100,8 @@ inline uint32_t count_prb_per_tb(const rbgmask_t& bitmask) return nof_prb; } +ue_cce_locations_table generate_cce_location_table(uint16_t rnti, const sched_cell_params_t& cell_cfg); + /** * Generate possible CCE locations a user can use to allocate DCIs * @param regs Regs data for the given cell configuration diff --git a/srsenb/hdr/stack/mac/sched_ue.h b/srsenb/hdr/stack/mac/sched_ue.h index d30ace871..697c3136a 100644 --- a/srsenb/hdr/stack/mac/sched_ue.h +++ b/srsenb/hdr/stack/mac/sched_ue.h @@ -20,6 +20,7 @@ #include "sched_ue_ctrl/sched_harq.h" #include "sched_ue_ctrl/sched_lch.h" +#include "sched_ue_ctrl/sched_ue_cell.h" #include "sched_ue_ctrl/tpc.h" #include #include @@ -75,9 +76,6 @@ struct cc_sched_ue { int fixed_mcs_ul = 0, fixed_mcs_dl = 0; tpc tpc_fsm; - // Allowed DCI locations per per CFI and per subframe - std::array, 3> dci_locations = {}; - private: // config srslte::log_ref log_h; @@ -190,8 +188,8 @@ public: int explicit_mcs = -1, uci_pusch_t uci_type = UCI_PUSCH_NONE); - srslte_dci_format_t get_dci_format(); - sched_dci_cce_t* get_locations(uint32_t enb_cc_idx, uint32_t current_cfi, uint32_t sf_idx); + srslte_dci_format_t get_dci_format(); + const sched_dci_cce_t* get_locations(uint32_t enb_cc_idx, uint32_t current_cfi, uint32_t sf_idx) const; cc_sched_ue* find_ue_carrier(uint32_t enb_cc_idx); size_t nof_carriers_configured() const { return carriers.size(); } @@ -243,11 +241,10 @@ private: const rbgmask_t& user_mask); /* Args */ - ue_cfg_t cfg = {}; - srslte_cell_t cell = {}; - srslte::log_ref log_h; - const std::vector* cell_params_list = nullptr; - const sched_cell_params_t* main_cc_params = nullptr; + ue_cfg_t cfg = {}; + srslte_cell_t cell = {}; + mutable srslte::log_ref log_h; + const sched_cell_params_t* main_cc_params = nullptr; /* Buffer states */ bool sr = false; @@ -261,7 +258,8 @@ private: tti_point current_tti; std::vector carriers; ///< map of UE CellIndex to carrier configuration - std::vector enb_ue_cc_idx_map; + + std::vector cells; ///< List of eNB cells that may be configured/activated/deactivated for the UE }; using sched_ue_list = std::map; diff --git a/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_ue_cell.h b/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_ue_cell.h new file mode 100644 index 000000000..0806d745a --- /dev/null +++ b/srsenb/hdr/stack/mac/sched_ue_ctrl/sched_ue_cell.h @@ -0,0 +1,44 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2020 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#ifndef SRSLTE_SCHED_UE_CELL_H +#define SRSLTE_SCHED_UE_CELL_H + +#include "../sched_common.h" + +namespace srsenb { + +struct sched_ue_cell { + using ue_cc_cfg = sched_interface::ue_cfg_t::cc_cfg_t; + + sched_ue_cell(uint16_t rnti_, const sched_cell_params_t& cell_cfg_); + void set_ue_cfg(const sched_interface::ue_cfg_t& ue_cfg_); + + bool configured() const { return ue_cc_idx >= 0; } + int get_ue_cc_idx() const { return ue_cc_idx; } + const ue_cc_cfg* get_ue_cc_cfg() const { return configured() ? &ue_cfg->supported_cc_list[ue_cc_idx] : nullptr; } + + /// Cell const configuration + const sched_cell_params_t* cell_cfg = nullptr; + + /// Allowed DCI locations per per CFI and per subframe + const ue_cce_locations_table dci_locations; + +private: + uint16_t rnti = SRSLTE_INVALID_RNTI; + const sched_interface::ue_cfg_t* ue_cfg = nullptr; + int ue_cc_idx = -1; +}; + +} // namespace srsenb + +#endif // SRSLTE_SCHED_UE_CELL_H diff --git a/srsenb/src/stack/mac/CMakeLists.txt b/srsenb/src/stack/mac/CMakeLists.txt index 04a7d4713..7eba11378 100644 --- a/srsenb/src/stack/mac/CMakeLists.txt +++ b/srsenb/src/stack/mac/CMakeLists.txt @@ -9,7 +9,7 @@ add_subdirectory(schedulers) set(SOURCES mac.cc ue.cc sched.cc sched_carrier.cc sched_grid.cc sched_ue_ctrl/sched_harq.cc sched_ue.cc - sched_ue_ctrl/sched_lch.cc sched_helpers.cc) + sched_ue_ctrl/sched_lch.cc sched_ue_ctrl/sched_ue_cell.cc sched_helpers.cc) add_library(srsenb_mac STATIC ${SOURCES} $) if(ENABLE_5GNR) diff --git a/srsenb/src/stack/mac/sched_helpers.cc b/srsenb/src/stack/mac/sched_helpers.cc index e76e65dd0..1222597b3 100644 --- a/srsenb/src/stack/mac/sched_helpers.cc +++ b/srsenb/src/stack/mac/sched_helpers.cc @@ -272,6 +272,18 @@ bool sched_cell_params_t::set_cfg(uint32_t enb_cc_id return true; } +ue_cce_locations_table generate_cce_location_table(uint16_t rnti, const sched_cell_params_t& cell_cfg) +{ + ue_cce_locations_table dci_locations; + // Generate allowed CCE locations + for (int cfi = 0; cfi < SRSLTE_NOF_CFI; cfi++) { + for (int sf_idx = 0; sf_idx < SRSLTE_NOF_SF_X_FRAME; sf_idx++) { + generate_cce_location(cell_cfg.regs.get(), &dci_locations[cfi][sf_idx], cfi + 1, sf_idx, rnti); + } + } + return dci_locations; +} + void generate_cce_location(srslte_regs_t* regs_, sched_dci_cce_t* location, uint32_t cfi, diff --git a/srsenb/src/stack/mac/sched_ue.cc b/srsenb/src/stack/mac/sched_ue.cc index 5ecb87d36..5fc9902f5 100644 --- a/srsenb/src/stack/mac/sched_ue.cc +++ b/srsenb/src/stack/mac/sched_ue.cc @@ -101,8 +101,11 @@ sched_ue::sched_ue() : log_h(srslte::logmap::get("MAC")) void sched_ue::init(uint16_t rnti_, const std::vector& cell_list_params_) { - rnti = rnti_; - cell_params_list = &cell_list_params_; + rnti = rnti_; + cells.reserve(cell_list_params_.size()); + for (auto& c : cell_list_params_) { + cells.emplace_back(rnti_, c); + } Info("SCHED: Added user rnti=0x%x\n", rnti); } @@ -117,7 +120,7 @@ void sched_ue::set_cfg(const ue_cfg_t& cfg_) Warning("Primary cc idx not provided in scheduler ue_cfg. Defaulting to cc_idx=0\n"); } // setup primary cc - main_cc_params = &(*cell_params_list)[primary_cc_idx]; + main_cc_params = cells[primary_cc_idx].cell_cfg; cell = main_cc_params->cfg.cell; max_msg3retx = main_cc_params->cfg.maxharq_msg3tx; } @@ -129,6 +132,11 @@ void sched_ue::set_cfg(const ue_cfg_t& cfg_) // update bearer cfgs lch_handler.set_cfg(cfg_); + // update ue cells + for (auto& c : cells) { + c.set_ue_cfg(cfg); + } + // in case carriers have been removed while (carriers.size() > cfg.supported_cc_list.size()) { // TODO: distinguish cell deactivation from reconfiguration @@ -136,18 +144,15 @@ void sched_ue::set_cfg(const ue_cfg_t& cfg_) } // in case carriers have been added or modified bool scell_activation_state_changed = false; - enb_ue_cc_idx_map.clear(); - enb_ue_cc_idx_map.resize(cell_params_list->size(), -1); for (uint32_t ue_idx = 0; ue_idx < cfg.supported_cc_list.size(); ++ue_idx) { - auto& cc_cfg = cfg.supported_cc_list[ue_idx]; - enb_ue_cc_idx_map[cc_cfg.enb_cc_idx] = ue_idx; + auto& cc_cfg = cfg.supported_cc_list[ue_idx]; if (ue_idx >= prev_supported_cc_list.size()) { // New carrier needs to be added - carriers.emplace_back(cfg, (*cell_params_list)[cc_cfg.enb_cc_idx], rnti, ue_idx, current_tti); + carriers.emplace_back(cfg, *cells[cc_cfg.enb_cc_idx].cell_cfg, rnti, ue_idx, current_tti); } else if (cc_cfg.enb_cc_idx != prev_supported_cc_list[ue_idx].enb_cc_idx) { // One carrier was added in the place of another - carriers[ue_idx] = cc_sched_ue{cfg, (*cell_params_list)[cc_cfg.enb_cc_idx], rnti, ue_idx, current_tti}; + carriers[ue_idx] = cc_sched_ue{cfg, *cells[cc_cfg.enb_cc_idx].cell_cfg, rnti, ue_idx, current_tti}; if (ue_idx == 0) { log_h->info("SCHED: rnti=0x%x PCell is now enb_cc_idx=%d.\n", rnti, cc_cfg.enb_cc_idx); } @@ -189,7 +194,7 @@ void sched_ue::new_subframe(tti_point tti_rx, uint32_t enb_cc_idx) cc.harq_ent.new_tti(tti_rx); } } - int ue_cc_idx = enb_ue_cc_idx_map[enb_cc_idx]; + int ue_cc_idx = cells[enb_cc_idx].get_ue_cc_idx(); if (ue_cc_idx >= 0) { carriers.at(ue_cc_idx).tpc_fsm.new_tti(); } @@ -1124,13 +1129,13 @@ srslte_dci_format_t sched_ue::get_dci_format() return ret; } -sched_dci_cce_t* sched_ue::get_locations(uint32_t enb_cc_idx, uint32_t cfi, uint32_t sf_idx) +const sched_dci_cce_t* sched_ue::get_locations(uint32_t enb_cc_idx, uint32_t cfi, uint32_t sf_idx) const { if (cfi > 0 && cfi <= 3) { - return &carriers[get_active_cell_index(enb_cc_idx).second].dci_locations[cfi - 1][sf_idx]; + return &cells[enb_cc_idx].dci_locations[cfi - 1][sf_idx]; } else { Error("SCHED: Invalid CFI=%d\n", cfi); - return &carriers[get_active_cell_index(enb_cc_idx).second].dci_locations[0][sf_idx]; + return &cells[enb_cc_idx].dci_locations[0][sf_idx]; } } @@ -1153,7 +1158,7 @@ std::bitset sched_ue::scell_activation_mask() const int sched_ue::enb_to_ue_cc_idx(uint32_t enb_cc_idx) const { - return enb_ue_cc_idx_map[enb_cc_idx]; + return cells.at(enb_cc_idx).get_ue_cc_idx(); } float diff_coderate_maxcoderate(int mcs, @@ -1243,13 +1248,6 @@ cc_sched_ue::cc_sched_ue(const sched_interface::ue_cfg_t& cfg_, // set fixed mcs fixed_mcs_dl = cell_params->sched_cfg->pdsch_mcs; fixed_mcs_ul = cell_params->sched_cfg->pusch_mcs; - - // Generate allowed CCE locations - for (int cfi = 0; cfi < 3; cfi++) { - for (int sf_idx = 0; sf_idx < 10; sf_idx++) { - generate_cce_location(cell_params->regs.get(), &dci_locations[cfi][sf_idx], cfi + 1, sf_idx, rnti); - } - } } void cc_sched_ue::reset() diff --git a/srsenb/src/stack/mac/sched_ue_ctrl/sched_ue_cell.cc b/srsenb/src/stack/mac/sched_ue_ctrl/sched_ue_cell.cc new file mode 100644 index 000000000..34df05d5c --- /dev/null +++ b/srsenb/src/stack/mac/sched_ue_ctrl/sched_ue_cell.cc @@ -0,0 +1,32 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2020 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#include "srsenb/hdr/stack/mac/sched_ue_ctrl/sched_ue_cell.h" +#include "srsenb/hdr/stack/mac/sched_helpers.h" + +namespace srsenb { + +sched_ue_cell::sched_ue_cell(uint16_t rnti_, const sched_cell_params_t& cell_cfg_) : + rnti(rnti_), cell_cfg(&cell_cfg_), dci_locations(generate_cce_location_table(rnti_, cell_cfg_)) +{} + +void sched_ue_cell::set_ue_cfg(const sched_interface::ue_cfg_t& ue_cfg_) +{ + ue_cfg = &ue_cfg_; + for (size_t i = 0; i < ue_cfg_.supported_cc_list.size(); ++i) { + if (ue_cfg_.supported_cc_list[i].enb_cc_idx == cell_cfg->enb_cc_idx) { + ue_cc_idx = i; + } + } +} + +} // namespace srsenb diff --git a/srsenb/test/mac/sched_grid_test.cc b/srsenb/test/mac/sched_grid_test.cc index 5b83c5b1d..b1c927589 100644 --- a/srsenb/test/mac/sched_grid_test.cc +++ b/srsenb/test/mac/sched_grid_test.cc @@ -69,9 +69,9 @@ int test_pdcch_one_ue() sched_ue.get_locations(ENB_CC_IDX, pdcch_grid_t::MAX_CFI, to_tx_dl(tti_rx).sf_idx())->nof_loc[aggr_idx]; // allocate DL user - uint32_t prev_cfi = pdcch.get_cfi(); - srsenb::sched_dci_cce_t* dci_cce = sched_ue.get_locations(ENB_CC_IDX, prev_cfi, to_tx_dl(tti_rx).sf_idx()); - uint32_t prev_nof_cce_locs = dci_cce->nof_loc[aggr_idx]; + uint32_t prev_cfi = pdcch.get_cfi(); + const srsenb::sched_dci_cce_t* dci_cce = sched_ue.get_locations(ENB_CC_IDX, prev_cfi, to_tx_dl(tti_rx).sf_idx()); + uint32_t prev_nof_cce_locs = dci_cce->nof_loc[aggr_idx]; TESTASSERT(pdcch.alloc_dci(alloc_type_t::DL_DATA, aggr_idx, &sched_ue)); TESTASSERT(pdcch.nof_allocs() == 1);