grouped different sched params/args/derived params into a single struct to simplify the ctor api of different sched sub components

This commit is contained in:
Francisco Paisana 2019-11-27 14:12:57 +00:00
parent 9493e7492c
commit 011b2168a6
9 changed files with 139 additions and 125 deletions

View File

@ -50,6 +50,23 @@ inline bool is_in_tti_interval(uint32_t tti, uint32_t tti1, uint32_t tti2)
} // namespace sched_utils
//! struct to bundle together all the sched arguments, and share them with all the sched sub-components
class sched_params_t
{
public:
srslte::log* log_h = nullptr;
sched_interface::cell_cfg_t* cfg = nullptr;
sched_interface::sched_args_t sched_cfg = {};
srslte_regs_t* regs = nullptr;
std::array<sched_ue::sched_dci_cce_t, 3> common_locations = {};
std::array<std::array<sched_ue::sched_dci_cce_t, 10>, 3> rar_locations = {};
std::array<uint32_t, 3> nof_cce_table = {}; ///< map cfix -> nof cces in PDCCH
uint32_t P = 0;
uint32_t nof_rbgs = 0;
bool set_derived();
};
/* Caution: User addition (ue_cfg) and removal (ue_rem) are not thread-safe
* Rest of operations are thread-safe
*
@ -154,11 +171,11 @@ public:
protected:
srslte::log* log_h;
rrc_interface_mac* rrc;
sched_params_t sched_params;
pthread_rwlock_t rwlock;
cell_cfg_t cfg;
sched_args_t sched_cfg;
cell_cfg_t cfg;
// This is for computing DCI locations
srslte_regs_t regs;
@ -169,10 +186,6 @@ protected:
std::map<uint16_t, sched_ue> ue_db;
// Allowed DCI locations for SIB and RAR per CFI
std::array<sched_ue::sched_dci_cce_t, 3> common_locations;
std::array<std::array<sched_ue::sched_dci_cce_t, 10>, 3> rar_locations;
// independent schedulers for each carrier
std::vector<std::unique_ptr<carrier_sched> > carrier_schedulers;

View File

@ -128,8 +128,8 @@ public:
// consts
carrier_sched* parent_carrier = nullptr;
sched_params_t* sched_params = nullptr;
srslte::log* log_h = nullptr;
uint32_t P = 0;
cell_cfg_sib_t* sibs_cfg = nullptr;
// internal state

View File

@ -56,18 +56,15 @@ public:
};
using alloc_result_t = std::vector<const alloc_t*>;
void init(srslte::log* log_,
srslte_regs_t* regs,
std::array<sched_ue::sched_dci_cce_t, 3>& common_locs,
std::array<std::array<sched_ue::sched_dci_cce_t, 10>, 3>& rar_locs);
void init(const sched_params_t& sched_params);
void new_tti(uint32_t tti_rx_, uint32_t start_cfi);
bool alloc_dci(alloc_type_t alloc_type, uint32_t aggr_idx, sched_ue* user = nullptr);
bool set_cfi(uint32_t cfi);
// getters
uint32_t get_cfi() const { return current_cfix + 1; }
void get_allocs(alloc_result_t* vec = nullptr, pdcch_mask_t* tot_mask = nullptr, size_t idx = 0) const;
uint32_t nof_cces() const { return cce_size_array[current_cfix]; }
uint32_t get_cfi() const { return current_cfix + 1; }
void get_allocs(alloc_result_t* vec = nullptr, pdcch_mask_t* tot_mask = nullptr, size_t idx = 0) const;
uint32_t nof_cces() const;
size_t nof_allocs() const { return nof_dci_allocs; }
size_t nof_alloc_combinations() const { return prev_end - prev_start; }
std::string result_to_string(bool verbose = false) const;
@ -86,10 +83,8 @@ private:
const sched_ue::sched_dci_cce_t* dci_locs);
// consts
srslte::log* log_h = nullptr;
sched_ue::sched_dci_cce_t* common_locations = nullptr;
std::array<sched_ue::sched_dci_cce_t*, 3> rar_locations{};
std::array<uint32_t, 3> cce_size_array{};
const sched_params_t* sched_params = nullptr;
srslte::log* log_h = nullptr;
// tti vars
uint32_t tti_rx = 0;
@ -109,7 +104,7 @@ public:
rbg_range_t rbg_range;
};
void init(srslte::log* log_, sched_interface::cell_cfg_t* cell_, const pdcch_grid_t& pdcch_grid);
void init(const sched_params_t& sched_params_);
void new_tti(uint32_t tti_rx_, uint32_t start_cfi);
dl_ctrl_alloc_t alloc_dl_ctrl(uint32_t aggr_lvl, alloc_type_t alloc_type);
alloc_outcome_t alloc_dl_data(sched_ue* user, const rbgmask_t& user_mask);
@ -133,10 +128,11 @@ private:
alloc_outcome_t alloc_dl(uint32_t aggr_lvl, alloc_type_t alloc_type, rbgmask_t alloc_mask, sched_ue* user = nullptr);
// consts
srslte::log* log_h = nullptr;
sched_interface::cell_cfg_t* cell_cfg = nullptr;
uint32_t nof_prbs = 0;
uint32_t nof_rbgs = 0;
const sched_params_t* sched_params = nullptr;
srslte::log* log_h = nullptr;
sched_interface::cell_cfg_t* cell_cfg = nullptr;
uint32_t nof_prbs = 0;
uint32_t nof_rbgs = 0;
uint32_t si_n_rbg = 0, rar_n_rbg = 0;
// tti const

View File

@ -32,6 +32,8 @@
namespace srsenb {
class sched_params_t;
/** This class is designed to be thread-safe because it is called from workers through scheduler thread and from
* higher layers and mac threads.
*
@ -57,11 +59,7 @@ public:
sched_ue();
void reset();
void phy_config_enabled(uint32_t tti, bool enabled);
void set_cfg(uint16_t rnti,
sched_interface::ue_cfg_t* cfg,
sched_interface::cell_cfg_t* cell_cfg,
srslte_regs_t* regs,
srslte::log* log_h);
void set_cfg(uint16_t rnti, const sched_params_t& sched_params_, sched_interface::ue_cfg_t* cfg);
void set_bearer_cfg(uint32_t lc_id, srsenb::sched_interface::ue_bearer_cfg_t* cfg);
void rem_bearer(uint32_t lc_id);
@ -197,6 +195,7 @@ private:
sched_interface::ue_cfg_t cfg = {};
srslte_cell_t cell = {};
srslte::log* log_h = nullptr;
const sched_params_t* sched_params;
std::mutex mutex;
@ -223,7 +222,6 @@ private:
uint32_t max_msg3retx = 0;
int fixed_mcs_ul = 0;
int fixed_mcs_dl = 0;
uint32_t P = 0;
uint32_t nof_ta_cmd = 0;

View File

@ -48,6 +48,49 @@ uint32_t max_tti(uint32_t tti1, uint32_t tti2)
} // namespace sched_utils
/*******************************************************
* Sched Params
*******************************************************/
bool sched_params_t::set_derived()
{
// Compute Common locations for DCI for each CFI
for (uint32_t cfi = 0; cfi < 3; cfi++) {
sched::generate_cce_location(regs, &common_locations[cfi], cfi + 1);
}
// Compute UE locations for RA-RNTI
for (uint32_t cfi = 0; cfi < 3; cfi++) {
for (uint32_t sf_idx = 0; sf_idx < 10; sf_idx++) {
sched::generate_cce_location(regs, &rar_locations[cfi][sf_idx], cfi + 1, sf_idx);
}
}
P = srslte_ra_type0_P(cfg->cell.nof_prb);
nof_rbgs = srslte::ceil_div(cfg->cell.nof_prb, P);
// precompute nof cces in PDCCH for each CFI
for (uint32_t cfix = 0; cfix < nof_cce_table.size(); ++cfix) {
int ret = srslte_regs_pdcch_ncce(regs, cfix + 1);
if (ret < 0) {
log_h->error("SCHED: Failed to calculate the number of CCEs in the PDCCH\n");
return false;
}
nof_cce_table[cfix] = (uint32_t)ret;
}
if (common_locations[sched_cfg.nof_ctrl_symbols - 1].nof_loc[2] == 0) {
log_h->error("SCHED: Current cfi=%d is not valid for broadcast (check scheduler.nof_ctrl_symbols in conf file).\n",
sched_cfg.nof_ctrl_symbols);
log_h->console(
"SCHED: Current cfi=%d is not valid for broadcast (check scheduler.nof_ctrl_symbols in conf file).\n",
sched_cfg.nof_ctrl_symbols);
return false;
}
return true;
}
/*******************************************************
*
* Initialization and sched configuration functions
@ -61,14 +104,8 @@ sched::sched()
bzero(&cfg, sizeof(cfg));
bzero(&regs, sizeof(regs));
bzero(&sched_cfg, sizeof(sched_cfg));
common_locations = {};
bzero(&pdsch_re, sizeof(pdsch_re));
for (auto& rar : rar_locations) {
rar = {};
}
pthread_rwlock_init(&rwlock, nullptr);
// Initialize Independent carrier schedulers
@ -87,14 +124,16 @@ sched::~sched()
void sched::init(rrc_interface_mac* rrc_, srslte::log* log)
{
sched_cfg.pdsch_max_mcs = 28;
sched_cfg.pdsch_mcs = -1;
sched_cfg.pusch_max_mcs = 28;
sched_cfg.pusch_mcs = -1;
sched_cfg.nof_ctrl_symbols = 3;
sched_cfg.max_aggr_level = 3;
log_h = log;
rrc = rrc_;
sched_params.sched_cfg.pdsch_max_mcs = 28;
sched_params.sched_cfg.pdsch_mcs = -1;
sched_params.sched_cfg.pusch_max_mcs = 28;
sched_params.sched_cfg.pusch_mcs = -1;
sched_params.sched_cfg.nof_ctrl_symbols = 3;
sched_params.sched_cfg.max_aggr_level = 3;
sched_params.log_h = log;
log_h = log;
rrc = rrc_;
reset();
}
@ -113,7 +152,7 @@ int sched::reset()
void sched::set_sched_cfg(sched_interface::sched_args_t* sched_cfg_)
{
if (sched_cfg_ != nullptr) {
sched_cfg = *sched_cfg_;
sched_params.sched_cfg = *sched_cfg_;
}
}
@ -140,16 +179,10 @@ int sched::cell_cfg(sched_interface::cell_cfg_t* cell_cfg)
return SRSLTE_ERROR;
}
// Compute Common locations for DCI for each CFI
for (uint32_t cfi = 0; cfi < 3; cfi++) {
generate_cce_location(&regs, &common_locations[cfi], cfi + 1);
}
// Compute UE locations for RA-RNTI
for (uint32_t cfi = 0; cfi < 3; cfi++) {
for (uint32_t sf_idx = 0; sf_idx < 10; sf_idx++) {
generate_cce_location(&regs, &rar_locations[cfi][sf_idx], cfi + 1, sf_idx);
}
sched_params.cfg = &cfg;
sched_params.regs = &regs;
if (not sched_params.set_derived()) {
return -1;
}
// Initiate the tti_scheduler for each TTI
@ -169,14 +202,6 @@ int sched::cell_cfg(sched_interface::cell_cfg_t* cell_cfg)
return -1;
}
if (common_locations[sched_cfg.nof_ctrl_symbols - 1].nof_loc[2] == 0) {
Error("SCHED: Current cfi=%d is not valid for broadcast (check scheduler.nof_ctrl_symbols in conf file).\n",
sched_cfg.nof_ctrl_symbols);
log_h->console(
"SCHED: Current cfi=%d is not valid for broadcast (check scheduler.nof_ctrl_symbols in conf file).\n",
sched_cfg.nof_ctrl_symbols);
}
return 0;
}
@ -190,9 +215,7 @@ int sched::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* ue_cfg)
{
// Add or config user
pthread_rwlock_wrlock(&rwlock);
ue_db[rnti].set_cfg(rnti, ue_cfg, &cfg, &regs, log_h);
ue_db[rnti].set_max_mcs(sched_cfg.pusch_max_mcs, sched_cfg.pdsch_max_mcs, sched_cfg.max_aggr_level);
ue_db[rnti].set_fixed_mcs(sched_cfg.pusch_mcs, sched_cfg.pdsch_mcs);
ue_db[rnti].set_cfg(rnti, sched_params, ue_cfg);
pthread_rwlock_unlock(&rwlock);
return 0;

View File

@ -35,17 +35,10 @@ namespace srsenb {
void sched::carrier_sched::tti_sched_result_t::init(carrier_sched* carrier_)
{
parent_carrier = carrier_;
log_h = carrier_->log_h;
P = srslte_ra_type0_P(parent_carrier->cfg->cell.nof_prb);
sibs_cfg = carrier_->cfg->sibs;
// nof_rbg = srslte::ceil_div(cfg->cell.nof_prb, P);
pdcch_grid_t pdcch_alloc;
pdcch_alloc.init(log_h,
&parent_carrier->sched_ptr->regs,
parent_carrier->sched_ptr->common_locations,
parent_carrier->sched_ptr->rar_locations);
tti_alloc.init(log_h, parent_carrier->cfg, pdcch_alloc);
sched_params = &carrier_->sched_ptr->sched_params;
log_h = sched_params->log_h;
sibs_cfg = sched_params->cfg->sibs;
tti_alloc.init(*sched_params);
}
void sched::carrier_sched::tti_sched_result_t::new_tti(uint32_t tti_rx_, uint32_t start_cfi)
@ -268,7 +261,7 @@ void sched::carrier_sched::tti_sched_result_t::set_bc_sched_result(const pdcch_g
bc->dci.location = dci_result[bc_alloc.dci_idx]->dci_pos;
/* Generate DCI format1A */
prb_range_t prb_range = prb_range_t(bc_alloc.rbg_range, P);
prb_range_t prb_range = prb_range_t(bc_alloc.rbg_range, sched_params->P);
int tbs = generate_format1a(
prb_range.prb_start, prb_range.length(), bc_alloc.req_bytes, bc_alloc.rv, bc_alloc.rnti, &bc->dci);
@ -337,7 +330,7 @@ void sched::carrier_sched::tti_sched_result_t::set_rar_sched_result(const pdcch_
rar->dci.location = dci_result[rar_alloc.dci_idx]->dci_pos;
/* Generate DCI format1A */
prb_range_t prb_range = prb_range_t(rar_alloc.rbg_range, P);
prb_range_t prb_range = prb_range_t(rar_alloc.rbg_range, sched_params->P);
int tbs =
generate_format1a(prb_range.prb_start, prb_range.length(), rar_alloc.req_bytes, 0, rar_alloc.rnti, &rar->dci);
if (tbs <= 0) {
@ -852,8 +845,8 @@ void sched::carrier_sched::carrier_cfg()
bc_sched_ptr->init(sched_ptr->rrc);
ra_sched_ptr->init(log_h, sched_ptr->ue_db);
dl_metric->set_log(sched_ptr->log_h);
ul_metric->set_log(sched_ptr->log_h);
dl_metric->set_log(log_h);
ul_metric->set_log(log_h);
// Setup constant PUCCH/PRACH mask
pucch_mask.resize(cfg->cell.nof_prb);
@ -887,7 +880,7 @@ sched::carrier_sched::tti_sched_result_t* sched::carrier_sched::generate_tti_res
// if it is the first time tti is run, reset vars
if (tti_rx != tti_sched->get_tti_rx()) {
uint32_t start_cfi = sched_ptr->sched_cfg.nof_ctrl_symbols;
uint32_t start_cfi = sched_ptr->sched_params.sched_cfg.nof_ctrl_symbols;
tti_sched->new_tti(tti_rx, start_cfi);
// Protects access to pending_rar[], pending_msg3[], pending_sibs[], rlc buffers

View File

@ -44,25 +44,10 @@ const char* alloc_outcome_t::to_string() const
* PDCCH Allocation Methods
*******************************************************/
void pdcch_grid_t::init(srslte::log* log_,
srslte_regs_t* regs,
std::array<sched_ue::sched_dci_cce_t, 3>& common_locs,
std::array<std::array<sched_ue::sched_dci_cce_t, 10>, 3>& rar_locs)
void pdcch_grid_t::init(const sched_params_t& sched_params_)
{
log_h = log_;
common_locations = &common_locs[0];
for (uint32_t cfix = 0; cfix < 3; ++cfix) {
rar_locations[cfix] = &rar_locs[cfix][0];
}
// precompute nof_cces
for (uint32_t cfix = 0; cfix < cce_size_array.size(); ++cfix) {
int ret = srslte_regs_pdcch_ncce(regs, cfix + 1);
if (ret < 0) {
log_h->error("SCHED: Failed to calculate the number of CCEs in the PDCCH\n");
}
cce_size_array[cfix] = (uint32_t)ret;
}
sched_params = &sched_params_;
log_h = sched_params_.log_h;
reset();
}
@ -79,11 +64,11 @@ const sched_ue::sched_dci_cce_t* pdcch_grid_t::get_cce_loc_table(alloc_type_t al
{
switch (alloc_type) {
case alloc_type_t::DL_BC:
return &common_locations[current_cfix];
return &sched_params->common_locations[current_cfix];
case alloc_type_t::DL_PCCH:
return &common_locations[current_cfix];
return &sched_params->common_locations[current_cfix];
case alloc_type_t::DL_RAR:
return &rar_locations[current_cfix][sf_idx];
return &sched_params->rar_locations[current_cfix][sf_idx];
case alloc_type_t::DL_DATA:
return user->get_locations(current_cfix + 1, sf_idx);
case alloc_type_t::UL_DATA:
@ -187,6 +172,11 @@ bool pdcch_grid_t::set_cfi(uint32_t cfi)
return true;
}
uint32_t pdcch_grid_t::nof_cces() const
{
return sched_params->nof_cce_table[current_cfix];
}
void pdcch_grid_t::reset()
{
prev_start = 0;
@ -260,17 +250,17 @@ std::string pdcch_grid_t::result_to_string(bool verbose) const
* TTI resource Scheduling Methods
*******************************************************/
void tti_grid_t::init(srslte::log* log_, sched_interface::cell_cfg_t* cell_, const pdcch_grid_t& pdcch_grid)
void tti_grid_t::init(const sched_params_t& sched_params_)
{
log_h = log_;
cell_cfg = cell_;
nof_prbs = cell_cfg->cell.nof_prb;
uint32_t P = srslte_ra_type0_P(cell_cfg->cell.nof_prb);
nof_rbgs = srslte::ceil_div(cell_cfg->cell.nof_prb, P);
si_n_rbg = srslte::ceil_div(4, P);
rar_n_rbg = srslte::ceil_div(3, P);
sched_params = &sched_params_;
log_h = sched_params->log_h;
cell_cfg = sched_params->cfg;
nof_prbs = cell_cfg->cell.nof_prb;
nof_rbgs = sched_params->nof_rbgs;
si_n_rbg = srslte::ceil_div(4, sched_params->P);
rar_n_rbg = srslte::ceil_div(3, sched_params->P);
pdcch_alloc = pdcch_grid;
pdcch_alloc.init(*sched_params);
}
void tti_grid_t::new_tti(uint32_t tti_rx_, uint32_t start_cfi)

View File

@ -60,25 +60,21 @@ sched_ue::sched_ue()
reset();
}
void sched_ue::set_cfg(uint16_t rnti_,
sched_interface::ue_cfg_t* cfg_,
sched_interface::cell_cfg_t* cell_cfg,
srslte_regs_t* regs,
srslte::log* log_h_)
void sched_ue::set_cfg(uint16_t rnti_, const sched_params_t& sched_params_, sched_interface::ue_cfg_t* cfg_)
{
reset();
{
std::lock_guard<std::mutex> lock(mutex);
rnti = rnti_;
log_h = log_h_;
memcpy(&cell, &cell_cfg->cell, sizeof(srslte_cell_t));
P = srslte_ra_type0_P(cell.nof_prb);
rnti = rnti_;
sched_params = &sched_params_;
log_h = sched_params->log_h;
cell = sched_params->cfg->cell;
max_mcs_dl = 28;
max_mcs_ul = 28;
max_aggr_level = 3;
max_msg3retx = cell_cfg->maxharq_msg3tx;
max_msg3retx = sched_params->cfg->maxharq_msg3tx;
cfg = *cfg_;
@ -95,7 +91,7 @@ void sched_ue::set_cfg(uint16_t rnti_,
// Generate allowed CCE locations
for (int cfi = 0; cfi < 3; cfi++) {
for (int sf_idx = 0; sf_idx < 10; sf_idx++) {
sched::generate_cce_location(regs, &dci_locations[cfi][sf_idx], cfi + 1, sf_idx, rnti);
sched::generate_cce_location(sched_params->regs, &dci_locations[cfi][sf_idx], cfi + 1, sf_idx, rnti);
}
}
}
@ -103,6 +99,11 @@ void sched_ue::set_cfg(uint16_t rnti_,
for (int i = 0; i < sched_interface::MAX_LC; i++) {
set_bearer_cfg(i, &cfg.ue_bearers[i]);
}
set_max_mcs(sched_params->sched_cfg.pusch_max_mcs,
sched_params->sched_cfg.pdsch_max_mcs,
sched_params->sched_cfg.max_aggr_level);
set_fixed_mcs(sched_params->sched_cfg.pusch_mcs, sched_params->sched_cfg.pdsch_mcs);
}
void sched_ue::reset()
@ -894,12 +895,12 @@ uint32_t sched_ue::get_pending_ul_old_data_unlocked()
uint32_t sched_ue::prb_to_rbg(uint32_t nof_prb)
{
return (uint32_t)ceil((float)nof_prb / P);
return (uint32_t)ceil((float)nof_prb / sched_params->P);
}
uint32_t sched_ue::rgb_to_prb(uint32_t nof_rbg)
{
return P * nof_rbg;
return sched_params->P * nof_rbg;
}
uint32_t sched_ue::get_required_prb_dl(uint32_t req_bytes, uint32_t nof_ctrl_symbols)

View File

@ -283,7 +283,7 @@ void sched_tester::new_test_tti(uint32_t tti_)
tti_data.ul_sf_idx = (tti_data.tti_tx_ul + 10240 - FDD_HARQ_DELAY_MS) % 10;
}
tti_data.ul_pending_msg3 = carrier_schedulers[0]->ra_sched_ptr->find_pending_msg3(tti_data.tti_tx_ul);
tti_data.current_cfi = sched_cfg.nof_ctrl_symbols;
tti_data.current_cfi = sched_params.sched_cfg.nof_ctrl_symbols;
tti_data.used_cce.resize(srslte_regs_pdcch_ncce(&regs, tti_data.current_cfi));
tti_data.used_cce.reset();
tti_data.ue_data.clear();