From ec1f1cc677cc11a31a5d63554b788fb0c8d0be34 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Thu, 5 Mar 2020 18:51:22 +0000 Subject: [PATCH] remove const_casts from scheduler. Fix ODR issue --- lib/include/srslte/phy/phch/dci.h | 8 ++++---- lib/include/srslte/phy/phch/ra_dl.h | 9 +++++--- lib/src/phy/phch/dci.c | 26 +++++++++++++----------- lib/src/phy/phch/ra_dl.c | 17 ++++++++-------- srsenb/hdr/stack/mac/scheduler_common.h | 4 ++-- srsenb/src/stack/mac/scheduler_grid.cc | 8 +++----- srsenb/test/mac/scheduler_test_common.cc | 6 ++---- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/include/srslte/phy/phch/dci.h b/lib/include/srslte/phy/phch/dci.h index 20831d57c..fd8175219 100644 --- a/lib/include/srslte/phy/phch/dci.h +++ b/lib/include/srslte/phy/phch/dci.h @@ -215,10 +215,10 @@ SRSLTE_API int srslte_dci_msg_unpack_pdsch(srslte_cell_t* cell, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci); -SRSLTE_API uint32_t srslte_dci_format_sizeof(srslte_cell_t* cell, - srslte_dl_sf_cfg_t* sf, - srslte_dci_cfg_t* cfg, - srslte_dci_format_t format); +SRSLTE_API uint32_t srslte_dci_format_sizeof(const srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_format_t format); SRSLTE_API void srslte_dci_dl_fprint(FILE* f, srslte_dci_dl_t* dci, uint32_t nof_prb); diff --git a/lib/include/srslte/phy/phch/ra_dl.h b/lib/include/srslte/phy/phch/ra_dl.h index ca56a6027..fb6f3b0f5 100644 --- a/lib/include/srslte/phy/phch/ra_dl.h +++ b/lib/include/srslte/phy/phch/ra_dl.h @@ -44,7 +44,7 @@ **************************************************/ /** Functions to generate a grant from a received DCI */ -SRSLTE_API int srslte_ra_dl_dci_to_grant(srslte_cell_t* cell, +SRSLTE_API int srslte_ra_dl_dci_to_grant(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_tm_t tm, bool pdsch_use_tbs_index_alt, @@ -57,12 +57,15 @@ srslte_ra_dl_grant_to_grant_prb_allocation(srslte_dci_dl_t* dci, srslte_pdsch_gr /** Functions used by the eNodeB scheduler */ SRSLTE_API uint32_t srslte_ra_dl_approx_nof_re(srslte_cell_t* cell, uint32_t nof_prb, uint32_t nof_ctrl_symbols); -SRSLTE_API uint32_t srslte_ra_dl_grant_nof_re(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant); +SRSLTE_API uint32_t srslte_ra_dl_grant_nof_re(const srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_pdsch_grant_t* grant); /** Others */ SRSLTE_API int srslte_dl_fill_ra_mcs(srslte_ra_tb_t* tb, int last_tbs, uint32_t nprb, bool pdsch_use_tbs_index_alt); -SRSLTE_API void srslte_ra_dl_compute_nof_re(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant); +SRSLTE_API void +srslte_ra_dl_compute_nof_re(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant); SRSLTE_API uint32_t srslte_ra_dl_info(srslte_pdsch_grant_t* grant, char* info_str, uint32_t len); diff --git a/lib/src/phy/phch/dci.c b/lib/src/phy/phch/dci.c index 1c43c498d..b1e01526b 100644 --- a/lib/src/phy/phch/dci.c +++ b/lib/src/phy/phch/dci.c @@ -111,7 +111,7 @@ static bool is_ambiguous_size(uint32_t size) /********************************** * PAYLOAD sizeof functions * ********************************/ -static uint32_t dci_format0_sizeof_(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format0_sizeof_(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = 0; @@ -156,7 +156,7 @@ static uint32_t dci_format0_sizeof_(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -static uint32_t dci_format1A_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format1A_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = 0; @@ -202,7 +202,7 @@ static uint32_t dci_format1A_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -static uint32_t dci_format0_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format0_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = dci_format0_sizeof_(cell, sf, cfg); while (n < dci_format1A_sizeof(cell, sf, cfg)) { @@ -211,7 +211,7 @@ static uint32_t dci_format0_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -static uint32_t dci_format1_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format1_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = (uint32_t)ceilf((float)cell->nof_prb / srslte_ra_type0_P(cell->nof_prb)) + 5 + HARQ_PID_LEN + 1 + 2 + 2 + @@ -225,7 +225,7 @@ static uint32_t dci_format1_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -static uint32_t dci_format1C_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format1C_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n_vrb_dl_gap1 = srslte_ra_type2_n_vrb_dl(cell->nof_prb, true); uint32_t n_step = srslte_ra_type2_n_rb_step(cell->nof_prb); @@ -246,7 +246,7 @@ static uint32_t tpmi_bits(uint32_t nof_ports) } } -static uint32_t dci_format1B_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format1B_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = 0; @@ -292,7 +292,7 @@ static uint32_t dci_format1B_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -static uint32_t dci_format1D_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format1D_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { // same size as format1B return dci_format1B_sizeof(cell, sf, cfg); @@ -308,7 +308,7 @@ static uint32_t precoding_bits_f2(uint32_t nof_ports) } } -static uint32_t dci_format2_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format2_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = (uint32_t)ceilf((float)cell->nof_prb / srslte_ra_type0_P(cell->nof_prb)) + 2 + HARQ_PID_LEN + 1 + 2 * (5 + 1 + 2) + precoding_bits_f2(cell->nof_ports) + (cfg->cif_enabled ? 3 : 0) + (IS_TDD ? 2 : 0); @@ -331,7 +331,7 @@ static uint32_t precoding_bits_f2a(uint32_t nof_ports) } } -static uint32_t dci_format2A_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format2A_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = (uint32_t)ceilf((float)cell->nof_prb / srslte_ra_type0_P(cell->nof_prb)) + 2 + HARQ_PID_LEN + 1 + 2 * (5 + 1 + 2) + precoding_bits_f2a(cell->nof_ports) + (cfg->cif_enabled ? 3 : 0) + (IS_TDD ? 2 : 0); @@ -344,7 +344,7 @@ static uint32_t dci_format2A_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -static uint32_t dci_format2B_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) +static uint32_t dci_format2B_sizeof(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) { uint32_t n = (uint32_t)ceilf((float)cell->nof_prb / srslte_ra_type0_P(cell->nof_prb)) + 2 + HARQ_PID_LEN + 1 + 2 * (5 + 1 + 2) + (cfg->cif_enabled ? 3 : 0) + (IS_TDD ? 2 : 0); @@ -357,8 +357,10 @@ static uint32_t dci_format2B_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, return n; } -uint32_t -srslte_dci_format_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_format_t format) +uint32_t srslte_dci_format_sizeof(const srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_format_t format) { srslte_dl_sf_cfg_t _sf; if (sf == NULL) { diff --git a/lib/src/phy/phch/ra_dl.c b/lib/src/phy/phch/ra_dl.c index 444c5db3c..e41966cd3 100644 --- a/lib/src/phy/phch/ra_dl.c +++ b/lib/src/phy/phch/ra_dl.c @@ -45,7 +45,7 @@ const int tbs_format1c_table[32] = {40, 56, 72, 120, 136, 144, 176, 208 **********/ /* Returns the number of RE in a PRB in a slot and subframe */ -static uint32_t ra_re_x_prb(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, uint32_t slot, uint32_t prb_idx) +static uint32_t ra_re_x_prb(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, uint32_t slot, uint32_t prb_idx) { uint32_t subframe = sf->tti % 10; @@ -441,7 +441,7 @@ static int dl_dci_compute_tb(bool pdsch_use_tbs_index_alt, srslte_dci_dl_t* dci, return SRSLTE_SUCCESS; } -void srslte_ra_dl_compute_nof_re(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant) +void srslte_ra_dl_compute_nof_re(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant) { // Compute number of RE grant->nof_re = srslte_ra_dl_grant_nof_re(cell, sf, grant); @@ -468,7 +468,8 @@ void srslte_ra_dl_compute_nof_re(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, sr } /* Determine MIMO type based on number of cell ports and receive antennas, transport blocks and pinfo */ -static int config_mimo_type(srslte_cell_t* cell, srslte_tm_t tm, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) +static int +config_mimo_type(const srslte_cell_t* cell, srslte_tm_t tm, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) { grant->tx_scheme = SRSLTE_TXSCHEME_PORT0; bool valid_config = true; @@ -525,7 +526,7 @@ static int config_mimo_type(srslte_cell_t* cell, srslte_tm_t tm, srslte_dci_dl_t } /* Translates Precoding Information (pinfo) to Precoding matrix Index (pmi) as 3GPP 36.212 Table 5.3.3.1.5-4 */ -static int config_mimo_pmi(srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) +static int config_mimo_pmi(const srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) { uint32_t nof_tb = grant->nof_tb; if (grant->tx_scheme == SRSLTE_TXSCHEME_SPATIALMUX) { @@ -556,7 +557,7 @@ static int config_mimo_pmi(srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_pds } /* Determine number of MIMO layers */ -static int config_mimo_layers(srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) +static int config_mimo_layers(const srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) { uint32_t nof_tb = grant->nof_tb; switch (grant->tx_scheme) { @@ -599,7 +600,7 @@ static int config_mimo_layers(srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_ return 0; } -static int config_mimo(srslte_cell_t* cell, srslte_tm_t tm, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) +static int config_mimo(const srslte_cell_t* cell, srslte_tm_t tm, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant) { if (config_mimo_type(cell, tm, dci, grant)) { @@ -626,7 +627,7 @@ static int config_mimo(srslte_cell_t* cell, srslte_tm_t tm, srslte_dci_dl_t* dci **********/ /** Compute the DL grant parameters */ -int srslte_ra_dl_dci_to_grant(srslte_cell_t* cell, +int srslte_ra_dl_dci_to_grant(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_tm_t tm, bool pdsch_use_tbs_index_alt, @@ -684,7 +685,7 @@ uint32_t srslte_ra_dl_approx_nof_re(srslte_cell_t* cell, uint32_t nof_prb, uint3 } /* Computes the number of RE for each PRB in the prb_dist structure */ -uint32_t srslte_ra_dl_grant_nof_re(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant) +uint32_t srslte_ra_dl_grant_nof_re(const srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_pdsch_grant_t* grant) { uint32_t j, s; // Compute number of RE per PRB diff --git a/srsenb/hdr/stack/mac/scheduler_common.h b/srsenb/hdr/stack/mac/scheduler_common.h index 56b3cb5db..f3c8a7162 100644 --- a/srsenb/hdr/stack/mac/scheduler_common.h +++ b/srsenb/hdr/stack/mac/scheduler_common.h @@ -91,13 +91,13 @@ using prbmask_t = srslte::bounded_bitset<100, true>; namespace sched_utils { -uint32_t aggr_level(uint32_t aggr_idx) +inline uint32_t aggr_level(uint32_t aggr_idx) { return 1u << aggr_idx; } //! Obtain rvidx from nof retxs. This value is stored in DCI -uint32_t get_rvidx(uint32_t retx_idx) +inline uint32_t get_rvidx(uint32_t retx_idx) { const static uint32_t rv_idx[4] = {0, 2, 3, 1}; return rv_idx[retx_idx % 4]; diff --git a/srsenb/src/stack/mac/scheduler_grid.cc b/srsenb/src/stack/mac/scheduler_grid.cc index d40434481..3adc802f9 100644 --- a/srsenb/src/stack/mac/scheduler_grid.cc +++ b/srsenb/src/stack/mac/scheduler_grid.cc @@ -342,9 +342,8 @@ sf_grid_t::dl_ctrl_alloc_t sf_grid_t::alloc_dl_ctrl(uint32_t aggr_lvl, alloc_typ alloc_outcome_t sf_grid_t::alloc_dl_data(sched_ue* user, const rbgmask_t& user_mask) { srslte_dci_format_t dci_format = user->get_dci_format(); - uint32_t nof_bits = - srslte_dci_format_sizeof(const_cast(&cc_cfg->cfg.cell), nullptr, nullptr, dci_format); - uint32_t aggr_level = user->get_ue_carrier(cc_cfg->enb_cc_idx)->get_aggr_level(nof_bits); + uint32_t nof_bits = srslte_dci_format_sizeof(&cc_cfg->cfg.cell, nullptr, nullptr, dci_format); + uint32_t aggr_level = user->get_ue_carrier(cc_cfg->enb_cc_idx)->get_aggr_level(nof_bits); return alloc_dl(aggr_level, alloc_type_t::DL_DATA, user_mask, user); } @@ -362,8 +361,7 @@ alloc_outcome_t sf_grid_t::alloc_ul_data(sched_ue* user, ul_harq_proc::ul_alloc_ // Generate PDCCH except for RAR and non-adaptive retx if (needs_pdcch) { - uint32_t nof_bits = - srslte_dci_format_sizeof(const_cast(&cc_cfg->cfg.cell), nullptr, nullptr, SRSLTE_DCI_FORMAT0); + uint32_t nof_bits = srslte_dci_format_sizeof(&cc_cfg->cfg.cell, nullptr, nullptr, SRSLTE_DCI_FORMAT0); uint32_t aggr_idx = user->get_ue_carrier(cc_cfg->enb_cc_idx)->get_aggr_level(nof_bits); if (not pdcch_alloc.alloc_dci(alloc_type_t::UL_DATA, aggr_idx, user)) { if (log_h->get_level() == srslte::LOG_LEVEL_DEBUG) { diff --git a/srsenb/test/mac/scheduler_test_common.cc b/srsenb/test/mac/scheduler_test_common.cc index e9d284286..e87d6ef93 100644 --- a/srsenb/test/mac/scheduler_test_common.cc +++ b/srsenb/test/mac/scheduler_test_common.cc @@ -303,14 +303,12 @@ int srsenb::extract_dl_prbmask(const srslte_cell_t& cell, srslte::bounded_bitset<100, true>* alloc_mask) { srslte_pdsch_grant_t grant; - srslte_dl_sf_cfg_t dl_sf = {}; - srslte_dci_dl_t* dci_dyn = const_cast(&dci); // TODO - srslte_cell_t* cell_dyn = const_cast(&cell); + srslte_dl_sf_cfg_t dl_sf = {}; alloc_mask->resize(cell.nof_prb); alloc_mask->reset(); - CONDERROR(srslte_ra_dl_dci_to_grant(cell_dyn, &dl_sf, SRSLTE_TM1, false, dci_dyn, &grant) == SRSLTE_ERROR, + CONDERROR(srslte_ra_dl_dci_to_grant(&cell, &dl_sf, SRSLTE_TM1, false, &dci, &grant) == SRSLTE_ERROR, "Failed to decode PDSCH grant\n"); for (uint32_t j = 0; j < alloc_mask->size(); ++j) { if (grant.prb_idx[0][j]) {