mirror of https://github.com/pvnis/srsRAN_4G.git
moved the carrier scheduler and tti_result_t classes out of the main sched class. Now it is possible to instantiate more than one carrier_sched per sched
parent
2019fec37a
commit
b88b8fde7b
@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_SCHEDULER_CARRIER_H
|
||||
#define SRSLTE_SCHEDULER_CARRIER_H
|
||||
|
||||
#include "scheduler.h"
|
||||
|
||||
namespace srsenb {
|
||||
|
||||
class bc_sched;
|
||||
class ra_sched;
|
||||
|
||||
class sched::carrier_sched
|
||||
{
|
||||
public:
|
||||
explicit carrier_sched(sched* sched_);
|
||||
|
||||
class tti_sched_result_t : public dl_tti_sched_t, public ul_tti_sched_t
|
||||
{
|
||||
public:
|
||||
struct ctrl_alloc_t {
|
||||
size_t dci_idx;
|
||||
rbg_range_t rbg_range;
|
||||
uint16_t rnti;
|
||||
uint32_t req_bytes;
|
||||
alloc_type_t alloc_type;
|
||||
};
|
||||
struct rar_alloc_t : public ctrl_alloc_t {
|
||||
dl_sched_rar_t rar_grant;
|
||||
rar_alloc_t() = default;
|
||||
explicit rar_alloc_t(const ctrl_alloc_t& c) : ctrl_alloc_t(c) {}
|
||||
};
|
||||
struct bc_alloc_t : public ctrl_alloc_t {
|
||||
uint32_t rv = 0;
|
||||
uint32_t sib_idx = 0;
|
||||
bc_alloc_t() = default;
|
||||
explicit bc_alloc_t(const ctrl_alloc_t& c) : ctrl_alloc_t(c) {}
|
||||
};
|
||||
struct dl_alloc_t {
|
||||
size_t dci_idx;
|
||||
sched_ue* user_ptr;
|
||||
rbgmask_t user_mask;
|
||||
uint32_t pid;
|
||||
};
|
||||
struct ul_alloc_t {
|
||||
enum type_t { NEWTX, NOADAPT_RETX, ADAPT_RETX, MSG3 };
|
||||
size_t dci_idx;
|
||||
type_t type;
|
||||
sched_ue* user_ptr;
|
||||
ul_harq_proc::ul_alloc_t alloc;
|
||||
uint32_t mcs = 0;
|
||||
bool is_retx() const { return type == NOADAPT_RETX or type == ADAPT_RETX; }
|
||||
bool is_msg3() const { return type == MSG3; }
|
||||
bool needs_pdcch() const { return type == NEWTX or type == ADAPT_RETX; }
|
||||
};
|
||||
typedef std::pair<alloc_outcome_t, const rar_alloc_t*> rar_code_t;
|
||||
typedef std::pair<alloc_outcome_t, const ctrl_alloc_t> ctrl_code_t;
|
||||
|
||||
// TTI scheduler result
|
||||
pdcch_mask_t pdcch_mask;
|
||||
sched_interface::dl_sched_res_t dl_sched_result;
|
||||
sched_interface::ul_sched_res_t ul_sched_result;
|
||||
|
||||
void init(carrier_sched* carrier_);
|
||||
void new_tti(uint32_t tti_rx_, uint32_t start_cfi);
|
||||
alloc_outcome_t alloc_bc(uint32_t aggr_lvl, uint32_t sib_idx, uint32_t sib_ntx);
|
||||
alloc_outcome_t alloc_paging(uint32_t aggr_lvl, uint32_t paging_payload);
|
||||
rar_code_t alloc_rar(uint32_t aggr_lvl, const dl_sched_rar_t& rar_grant, uint32_t rar_tti, uint32_t buf_rar);
|
||||
void generate_dcis();
|
||||
// dl_tti_sched itf
|
||||
alloc_outcome_t alloc_dl_user(sched_ue* user, const rbgmask_t& user_mask, uint32_t pid) final;
|
||||
uint32_t get_tti_tx_dl() const final { return tti_alloc.get_tti_tx_dl(); }
|
||||
uint32_t get_nof_ctrl_symbols() const final;
|
||||
const rbgmask_t& get_dl_mask() const final { return tti_alloc.get_dl_mask(); }
|
||||
// ul_tti_sched itf
|
||||
alloc_outcome_t alloc_ul_user(sched_ue* user, ul_harq_proc::ul_alloc_t alloc) final;
|
||||
alloc_outcome_t alloc_ul_msg3(sched_ue* user, ul_harq_proc::ul_alloc_t alloc, uint32_t mcs);
|
||||
const prbmask_t& get_ul_mask() const final { return tti_alloc.get_ul_mask(); }
|
||||
uint32_t get_tti_tx_ul() const final { return tti_alloc.get_tti_tx_ul(); }
|
||||
|
||||
// getters
|
||||
const pdcch_mask_t& get_pdcch_mask() const { return pdcch_mask; }
|
||||
rbgmask_t& get_dl_mask() { return tti_alloc.get_dl_mask(); }
|
||||
prbmask_t& get_ul_mask() { return tti_alloc.get_ul_mask(); }
|
||||
const std::vector<ul_alloc_t>& get_ul_allocs() const { return ul_data_allocs; }
|
||||
uint32_t get_cfi() const { return tti_alloc.get_cfi(); }
|
||||
uint32_t get_tti_rx() const { return tti_alloc.get_tti_rx(); }
|
||||
uint32_t get_sfn() const { return tti_alloc.get_sfn(); }
|
||||
uint32_t get_sf_idx() const { return tti_alloc.get_sf_idx(); }
|
||||
|
||||
private:
|
||||
bool is_dl_alloc(sched_ue* user) const final;
|
||||
bool is_ul_alloc(sched_ue* user) const final;
|
||||
ctrl_code_t alloc_dl_ctrl(uint32_t aggr_lvl, uint32_t tbs_bytes, uint16_t rnti);
|
||||
alloc_outcome_t alloc_ul(sched_ue* user,
|
||||
ul_harq_proc::ul_alloc_t alloc,
|
||||
tti_sched_result_t::ul_alloc_t::type_t alloc_type,
|
||||
uint32_t msg3 = 0);
|
||||
int generate_format1a(
|
||||
uint32_t rb_start, uint32_t l_crb, uint32_t tbs, uint32_t rv, uint16_t rnti, srslte_dci_dl_t* dci);
|
||||
void set_bc_sched_result(const pdcch_grid_t::alloc_result_t& dci_result);
|
||||
void set_rar_sched_result(const pdcch_grid_t::alloc_result_t& dci_result);
|
||||
void set_dl_data_sched_result(const pdcch_grid_t::alloc_result_t& dci_result);
|
||||
void set_ul_sched_result(const pdcch_grid_t::alloc_result_t& dci_result);
|
||||
|
||||
// consts
|
||||
carrier_sched* parent_carrier = nullptr;
|
||||
srslte::log* log_h = nullptr;
|
||||
uint32_t P = 0;
|
||||
cell_cfg_sib_t* sibs_cfg = nullptr;
|
||||
|
||||
// internal state
|
||||
tti_grid_t tti_alloc;
|
||||
std::vector<rar_alloc_t> rar_allocs;
|
||||
std::vector<bc_alloc_t> bc_allocs;
|
||||
std::vector<dl_alloc_t> data_allocs;
|
||||
std::vector<ul_alloc_t> ul_data_allocs;
|
||||
};
|
||||
|
||||
void reset();
|
||||
void carrier_cfg();
|
||||
void set_metric(sched::metric_dl* dl_metric_, sched::metric_ul* ul_metric_);
|
||||
void set_dl_tti_mask(uint8_t* tti_mask, uint32_t nof_sfs);
|
||||
tti_sched_result_t* generate_tti_result(uint32_t tti_rx);
|
||||
int dl_rach_info(dl_sched_rar_info_t rar_info);
|
||||
|
||||
// private:
|
||||
void generate_phich(tti_sched_result_t* tti_sched);
|
||||
//! Compute DL scheduler result for given TTI
|
||||
int generate_dl_sched(tti_sched_result_t* tti_result);
|
||||
//! Compute UL scheduler result for given TTI
|
||||
int generate_ul_sched(tti_sched_result_t* tti_sched);
|
||||
|
||||
// args
|
||||
sched* sched_ptr = nullptr;
|
||||
srslte::log* log_h = nullptr;
|
||||
cell_cfg_t* cfg = nullptr;
|
||||
metric_dl* dl_metric = nullptr;
|
||||
metric_ul* ul_metric = nullptr;
|
||||
|
||||
// derived from args
|
||||
prbmask_t prach_mask;
|
||||
prbmask_t pucch_mask;
|
||||
|
||||
// TTI result storage and management
|
||||
std::array<tti_sched_result_t, 10> tti_scheds;
|
||||
tti_sched_result_t* get_tti_sched(uint32_t tti_rx) { return &tti_scheds[tti_rx % tti_scheds.size()]; }
|
||||
std::vector<uint8_t> tti_dl_mask; ///< Some TTIs may be forbidden for DL sched due to MBMS
|
||||
|
||||
std::unique_ptr<bc_sched> bc_sched_ptr;
|
||||
std::unique_ptr<ra_sched> ra_sched_ptr;
|
||||
|
||||
// protects access to bc/ra schedulers and harqs
|
||||
std::mutex sched_mutex;
|
||||
};
|
||||
|
||||
//! Broadcast (SIB + paging) scheduler
|
||||
class bc_sched
|
||||
{
|
||||
public:
|
||||
explicit bc_sched(sched::cell_cfg_t* cfg_);
|
||||
void init(rrc_interface_mac* rrc_);
|
||||
|
||||
void dl_sched(sched::carrier_sched::tti_sched_result_t* tti_sched);
|
||||
void reset();
|
||||
|
||||
private:
|
||||
struct sched_sib_t {
|
||||
bool is_in_window = false;
|
||||
uint32_t window_start = 0;
|
||||
uint32_t n_tx = 0;
|
||||
};
|
||||
|
||||
void update_si_windows(sched::carrier_sched::tti_sched_result_t* tti_sched);
|
||||
void alloc_sibs(sched::carrier_sched::tti_sched_result_t* tti_sched);
|
||||
void alloc_paging(sched::carrier_sched::tti_sched_result_t* tti_sched);
|
||||
|
||||
// args
|
||||
sched::cell_cfg_t* cfg;
|
||||
rrc_interface_mac* rrc = nullptr;
|
||||
|
||||
std::array<sched_sib_t, sched_interface::MAX_SIBS> pending_sibs;
|
||||
|
||||
// TTI specific
|
||||
uint32_t current_sfn = 0, current_sf_idx = 0;
|
||||
uint32_t current_tti = 0;
|
||||
uint32_t bc_aggr_level = 2;
|
||||
};
|
||||
|
||||
//! RAR/Msg3 scheduler
|
||||
class ra_sched
|
||||
{
|
||||
public:
|
||||
using dl_sched_rar_info_t = sched_interface::dl_sched_rar_info_t;
|
||||
using dl_sched_rar_t = sched_interface::dl_sched_rar_t;
|
||||
using dl_sched_rar_grant_t = sched_interface::dl_sched_rar_grant_t;
|
||||
struct pending_msg3_t {
|
||||
bool enabled = false;
|
||||
uint16_t rnti = 0;
|
||||
uint32_t L = 0;
|
||||
uint32_t n_prb = 0;
|
||||
uint32_t mcs = 0;
|
||||
};
|
||||
|
||||
explicit ra_sched(sched::cell_cfg_t* cfg_);
|
||||
void init(srslte::log* log_, std::map<uint16_t, sched_ue>& ue_db_);
|
||||
void dl_sched(sched::carrier_sched::tti_sched_result_t* tti_sched);
|
||||
void ul_sched(sched::carrier_sched::tti_sched_result_t* tti_sched);
|
||||
int dl_rach_info(dl_sched_rar_info_t rar_info);
|
||||
void reset();
|
||||
const pending_msg3_t& find_pending_msg3(uint32_t tti);
|
||||
|
||||
private:
|
||||
struct sched_rar_t {
|
||||
int buf_rar = 0;
|
||||
uint16_t rnti = 0;
|
||||
uint32_t ra_id = 0;
|
||||
uint32_t rar_tti = 0;
|
||||
};
|
||||
|
||||
// args
|
||||
srslte::log* log_h = nullptr;
|
||||
sched::cell_cfg_t* cfg;
|
||||
std::map<uint16_t, sched_ue>* ue_db = nullptr;
|
||||
|
||||
std::queue<dl_sched_rar_info_t> pending_rars;
|
||||
std::array<pending_msg3_t, TTIMOD_SZ> pending_msg3;
|
||||
uint32_t tti_tx_dl = 0;
|
||||
uint32_t rar_aggr_level = 2;
|
||||
};
|
||||
|
||||
} // namespace srsenb
|
||||
|
||||
#endif // SRSLTE_SCHEDULER_CARRIER_H
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_SCHEDULER_CTRL_H
|
||||
#define SRSLTE_SCHEDULER_CTRL_H
|
||||
|
||||
#include "scheduler.h"
|
||||
|
||||
namespace srsenb {
|
||||
|
||||
class sched::bc_sched_t
|
||||
{
|
||||
public:
|
||||
explicit bc_sched_t(cell_cfg_t* cfg_);
|
||||
void init(rrc_interface_mac* rrc_);
|
||||
|
||||
void dl_sched(tti_sched_result_t* tti_sched);
|
||||
void reset();
|
||||
|
||||
private:
|
||||
struct sched_sib_t {
|
||||
bool is_in_window = false;
|
||||
uint32_t window_start = 0;
|
||||
uint32_t n_tx = 0;
|
||||
};
|
||||
|
||||
void update_si_windows(tti_sched_result_t* tti_sched);
|
||||
void alloc_sibs(tti_sched_result_t* tti_sched);
|
||||
void alloc_paging(tti_sched_result_t* tti_sched);
|
||||
|
||||
// args
|
||||
cell_cfg_t* cfg;
|
||||
rrc_interface_mac* rrc = nullptr;
|
||||
|
||||
std::array<sched_sib_t, sched_interface::MAX_SIBS> pending_sibs;
|
||||
|
||||
// TTI specific
|
||||
uint32_t current_sfn = 0, current_sf_idx = 0;
|
||||
uint32_t current_tti = 0;
|
||||
uint32_t bc_aggr_level = 2;
|
||||
};
|
||||
|
||||
class sched::ra_sched_t
|
||||
{
|
||||
public:
|
||||
struct pending_msg3_t {
|
||||
bool enabled = false;
|
||||
uint16_t rnti = 0;
|
||||
uint32_t L = 0;
|
||||
uint32_t n_prb = 0;
|
||||
uint32_t mcs = 0;
|
||||
};
|
||||
|
||||
explicit ra_sched_t(cell_cfg_t* cfg_);
|
||||
void init(srslte::log* log_, std::map<uint16_t, sched_ue>& ue_db_);
|
||||
void dl_sched(tti_sched_result_t* tti_sched);
|
||||
void ul_sched(tti_sched_result_t* tti_sched);
|
||||
int dl_rach_info(dl_sched_rar_info_t rar_info);
|
||||
void reset();
|
||||
const pending_msg3_t& find_pending_msg3(uint32_t tti);
|
||||
|
||||
private:
|
||||
struct sched_rar_t {
|
||||
int buf_rar = 0;
|
||||
uint16_t rnti = 0;
|
||||
uint32_t ra_id = 0;
|
||||
uint32_t rar_tti = 0;
|
||||
};
|
||||
|
||||
// args
|
||||
srslte::log* log_h = nullptr;
|
||||
cell_cfg_t* cfg;
|
||||
std::map<uint16_t, sched_ue>* ue_db = nullptr;
|
||||
|
||||
|
||||
std::queue<dl_sched_rar_info_t> pending_rars;
|
||||
std::array<pending_msg3_t, TTIMOD_SZ> pending_msg3;
|
||||
uint32_t tti_tx_dl = 0;
|
||||
uint32_t rar_aggr_level = 2;
|
||||
};
|
||||
|
||||
class sched::carrier_sched
|
||||
{
|
||||
public:
|
||||
explicit carrier_sched(sched* sched_);
|
||||
|
||||
void init();
|
||||
void reset();
|
||||
void cell_cfg();
|
||||
void set_metric(sched::metric_dl* dl_metric_, sched::metric_ul* ul_metric_);
|
||||
void set_dl_tti_mask(uint8_t* tti_mask, uint32_t nof_sfs);
|
||||
sched::tti_sched_result_t* generate_tti_result(uint32_t tti_rx);
|
||||
|
||||
// private:
|
||||
void generate_phich(tti_sched_result_t* tti_sched);
|
||||
//! Compute DL scheduler result for given TTI
|
||||
int generate_dl_sched(tti_sched_result_t* tti_result);
|
||||
//! Compute UL scheduler result for given TTI
|
||||
int generate_ul_sched(tti_sched_result_t* tti_sched);
|
||||
|
||||
// args
|
||||
sched* sched_ptr = nullptr;
|
||||
srslte::log* log_h = nullptr;
|
||||
cell_cfg_t* cfg = nullptr;
|
||||
metric_dl* dl_metric = nullptr;
|
||||
metric_ul* ul_metric = nullptr;
|
||||
|
||||
// TTI result storage and management
|
||||
std::array<tti_sched_result_t, 10> tti_scheds;
|
||||
tti_sched_result_t* get_tti_sched(uint32_t tti_rx) { return &tti_scheds[tti_rx % tti_scheds.size()]; }
|
||||
std::vector<uint8_t> tti_dl_mask; ///< Some TTIs may be forbidden for DL sched due to MBMS
|
||||
|
||||
std::unique_ptr<sched::bc_sched_t> bc_sched;
|
||||
std::unique_ptr<sched::ra_sched_t> ra_sched;
|
||||
};
|
||||
|
||||
} // namespace srsenb
|
||||
|
||||
#endif // SRSLTE_SCHEDULER_CTRL_H
|
File diff suppressed because it is too large
Load Diff
@ -1,445 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsenb/hdr/stack/mac/scheduler_ctrl.h"
|
||||
|
||||
namespace srsenb {
|
||||
|
||||
sched::bc_sched_t::bc_sched_t(cell_cfg_t* cfg_) : cfg(cfg_) {}
|
||||
|
||||
void sched::bc_sched_t::init(srsenb::rrc_interface_mac* rrc_)
|
||||
{
|
||||
rrc = rrc_;
|
||||
}
|
||||
|
||||
void sched::bc_sched_t::dl_sched(sched::tti_sched_result_t* tti_sched)
|
||||
{
|
||||
current_sf_idx = tti_sched->get_sf_idx();
|
||||
current_sfn = tti_sched->get_sfn();
|
||||
current_tti = tti_sched->get_tti_tx_dl();
|
||||
bc_aggr_level = 2;
|
||||
|
||||
/* Activate/deactivate SI windows */
|
||||
update_si_windows(tti_sched);
|
||||
|
||||
/* Allocate DCIs and RBGs for each SIB */
|
||||
alloc_sibs(tti_sched);
|
||||
|
||||
/* Allocate Paging */
|
||||
// NOTE: It blocks
|
||||
alloc_paging(tti_sched);
|
||||
}
|
||||
|
||||
void sched::bc_sched_t::update_si_windows(tti_sched_result_t* tti_sched)
|
||||
{
|
||||
uint32_t tti_tx_dl = tti_sched->get_tti_tx_dl();
|
||||
|
||||
for (uint32_t i = 0; i < pending_sibs.size(); ++i) {
|
||||
// There is SIB data
|
||||
if (cfg->sibs[i].len == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (not pending_sibs[i].is_in_window) {
|
||||
uint32_t sf = 5;
|
||||
uint32_t x = 0;
|
||||
if (i > 0) {
|
||||
x = (i - 1) * cfg->si_window_ms;
|
||||
sf = x % 10;
|
||||
}
|
||||
if ((current_sfn % (cfg->sibs[i].period_rf)) == x / 10 && current_sf_idx == sf) {
|
||||
pending_sibs[i].is_in_window = true;
|
||||
pending_sibs[i].window_start = tti_tx_dl;
|
||||
pending_sibs[i].n_tx = 0;
|
||||
}
|
||||
} else {
|
||||
if (i > 0) {
|
||||
if (srslte_tti_interval(tti_tx_dl, pending_sibs[i].window_start) > cfg->si_window_ms) {
|
||||
// the si window has passed
|
||||
pending_sibs[i] = {};
|
||||
}
|
||||
} else {
|
||||
// SIB1 is always in window
|
||||
if (pending_sibs[0].n_tx == 4) {
|
||||
pending_sibs[0].n_tx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sched::bc_sched_t::alloc_sibs(tti_sched_result_t* tti_sched)
|
||||
{
|
||||
for (uint32_t i = 0; i < pending_sibs.size(); i++) {
|
||||
if (cfg->sibs[i].len > 0 and pending_sibs[i].is_in_window and pending_sibs[i].n_tx < 4) {
|
||||
uint32_t nof_tx = (i > 0) ? SRSLTE_MIN(srslte::ceil_div(cfg->si_window_ms, 10), 4) : 4;
|
||||
uint32_t n_sf = (tti_sched->get_tti_tx_dl() - pending_sibs[i].window_start);
|
||||
|
||||
// Check if there is any SIB to tx
|
||||
bool sib1_flag = (i == 0) and (current_sfn % 2) == 0 and current_sf_idx == 5;
|
||||
bool other_sibs_flag =
|
||||
(i > 0) and (n_sf >= (cfg->si_window_ms / nof_tx) * pending_sibs[i].n_tx) and current_sf_idx == 9;
|
||||
if (not sib1_flag and not other_sibs_flag) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Schedule SIB
|
||||
tti_sched->alloc_bc(bc_aggr_level, i, pending_sibs[i].n_tx);
|
||||
pending_sibs[i].n_tx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sched::bc_sched_t::alloc_paging(srsenb::sched::tti_sched_result_t* tti_sched)
|
||||
{
|
||||
/* Allocate DCIs and RBGs for paging */
|
||||
if (rrc != nullptr) {
|
||||
uint32_t paging_payload = 0;
|
||||
if (rrc->is_paging_opportunity(current_tti, &paging_payload) and paging_payload > 0) {
|
||||
tti_sched->alloc_paging(bc_aggr_level, paging_payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sched::bc_sched_t::reset()
|
||||
{
|
||||
for (auto& sib : pending_sibs) {
|
||||
sib = {};
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
* RAR scheduling
|
||||
*******************************************************/
|
||||
|
||||
sched::ra_sched_t::ra_sched_t(cell_cfg_t* cfg_) : cfg(cfg_) {}
|
||||
|
||||
void sched::ra_sched_t::init(srslte::log* log_, std::map<uint16_t, sched_ue>& ue_db_)
|
||||
{
|
||||
log_h = log_;
|
||||
ue_db = &ue_db_;
|
||||
}
|
||||
|
||||
// Schedules RAR
|
||||
// On every call to this function, we schedule the oldest RAR which is still within the window. If outside the window we discard it.
|
||||
void sched::ra_sched_t::dl_sched(srsenb::sched::tti_sched_result_t* tti_sched)
|
||||
{
|
||||
tti_tx_dl = tti_sched->get_tti_tx_dl();
|
||||
rar_aggr_level = 2;
|
||||
|
||||
// Discard all RARs out of the window. The first one inside the window is scheduled, if we can't we exit
|
||||
while (!pending_rars.empty()) {
|
||||
dl_sched_rar_info_t rar = pending_rars.front();
|
||||
if (not sched_utils::is_in_tti_interval(tti_tx_dl,
|
||||
rar.prach_tti + 3,
|
||||
rar.prach_tti + 3 + cfg->prach_rar_window))
|
||||
{
|
||||
if (tti_tx_dl >= rar.prach_tti + 3 + cfg->prach_rar_window) {
|
||||
log_h->console("SCHED: Could not transmit RAR within the window (RA TTI=%d, Window=%d, Now=%d)\n",
|
||||
rar.prach_tti,
|
||||
cfg->prach_rar_window,
|
||||
tti_tx_dl);
|
||||
log_h->error("SCHED: Could not transmit RAR within the window (RA TTI=%d, Window=%d, Now=%d)\n",
|
||||
rar.prach_tti,
|
||||
cfg->prach_rar_window,
|
||||
tti_tx_dl);
|
||||
// Remove from pending queue and get next one if window has passed already
|
||||
pending_rars.pop();
|
||||
continue;
|
||||
}
|
||||
// If window not yet started do not look for more pending RARs
|
||||
return;
|
||||
}
|
||||
|
||||
/* Since we do a fixed Msg3 scheduling for all RAR, we can only allocate 1 RAR per TTI.
|
||||
* If we have enough space in the window, every call to this function we'll allocate 1 pending RAR and associate a
|
||||
* Msg3 transmission
|
||||
*/
|
||||
dl_sched_rar_t rar_grant;
|
||||
uint32_t L_prb = 3;
|
||||
uint32_t n_prb = cfg->nrb_pucch>0?cfg->nrb_pucch:2;
|
||||
bzero(&rar_grant, sizeof(rar_grant));
|
||||
uint32_t rba = srslte_ra_type2_to_riv(L_prb, n_prb, cfg->cell.nof_prb);
|
||||
|
||||
dl_sched_rar_grant_t *grant = &rar_grant.msg3_grant[0];
|
||||
grant->grant.tpc_pusch = 3;
|
||||
grant->grant.trunc_mcs = 0;
|
||||
grant->grant.rba = rba;
|
||||
grant->data = rar;
|
||||
rar_grant.nof_grants++;
|
||||
|
||||
// Try to schedule DCI + RBGs for RAR Grant
|
||||
tti_sched_result_t::rar_code_t ret = tti_sched->alloc_rar(rar_aggr_level,
|
||||
rar_grant,
|
||||
rar.prach_tti,
|
||||
7 * rar_grant.nof_grants); //fixme: check RAR size
|
||||
|
||||
// If we can allocate, schedule Msg3 and remove from pending
|
||||
if (!ret.first) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule Msg3 only if there is a requirement for Msg3 data
|
||||
uint32_t pending_tti = (tti_sched->get_tti_tx_dl() + MSG3_DELAY_MS + TX_DELAY) % TTIMOD_SZ;
|
||||
pending_msg3[pending_tti].enabled = true;
|
||||
pending_msg3[pending_tti].rnti = rar.temp_crnti; // FIXME
|
||||
pending_msg3[pending_tti].L = L_prb;
|
||||
pending_msg3[pending_tti].n_prb = n_prb;
|
||||
dl_sched_rar_grant_t *last_msg3 = &rar_grant.msg3_grant[rar_grant.nof_grants - 1];
|
||||
pending_msg3[pending_tti].mcs = last_msg3->grant.trunc_mcs;
|
||||
log_h->info("SCHED: Allocating Msg3 for rnti=%d at tti=%d\n", rar.temp_crnti, tti_sched->get_tti_tx_dl() + MSG3_DELAY_MS + TX_DELAY);
|
||||
|
||||
// Remove pending RAR and exit
|
||||
pending_rars.pop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Schedules Msg3
|
||||
void sched::ra_sched_t::ul_sched(srsenb::sched::tti_sched_result_t* tti_sched)
|
||||
{
|
||||
uint32_t pending_tti = tti_sched->get_tti_tx_ul() % TTIMOD_SZ;
|
||||
|
||||
// check if there is a Msg3 to allocate
|
||||
if (not pending_msg3[pending_tti].enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t rnti = pending_msg3[pending_tti].rnti;
|
||||
auto user_it = ue_db->find(rnti);
|
||||
if (user_it == ue_db->end()) {
|
||||
log_h->warning("SCHED: Msg3 allocated for user rnti=0x%x that no longer exists\n", rnti);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate RBGs and HARQ for Msg3 */
|
||||
ul_harq_proc::ul_alloc_t msg3 = {pending_msg3[pending_tti].n_prb, pending_msg3[pending_tti].L};
|
||||
if (not tti_sched->alloc_ul_msg3(&user_it->second, msg3, pending_msg3[pending_tti].mcs)) {
|
||||
log_h->warning("SCHED: Could not allocate msg3 within (%d,%d)\n", msg3.RB_start, msg3.RB_start + msg3.L);
|
||||
return;
|
||||
}
|
||||
pending_msg3[pending_tti].enabled = false;
|
||||
}
|
||||
|
||||
int sched::ra_sched_t::dl_rach_info(dl_sched_rar_info_t rar_info)
|
||||
{
|
||||
log_h->info("SCHED: New RAR tti=%d, preamble=%d, temp_crnti=0x%x, ta_cmd=%d, msg3_size=%d\n",
|
||||
rar_info.prach_tti, rar_info.preamble_idx, rar_info.temp_crnti, rar_info.ta_cmd, rar_info.msg3_size);
|
||||
pending_rars.push(rar_info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sched::ra_sched_t::reset()
|
||||
{
|
||||
tti_tx_dl = 0;
|
||||
for (auto& msg3 : pending_msg3) {
|
||||
msg3 = {};
|
||||
}
|
||||
while (not pending_rars.empty()) {
|
||||
pending_rars.pop();
|
||||
}
|
||||
}
|
||||
|
||||
const sched::ra_sched_t::pending_msg3_t& sched::ra_sched_t::find_pending_msg3(uint32_t tti)
|
||||
{
|
||||
uint32_t pending_tti = tti % TTIMOD_SZ;
|
||||
return pending_msg3[pending_tti];
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
* Carrier scheduling
|
||||
*******************************************************/
|
||||
|
||||
sched::carrier_sched::carrier_sched(sched* sched_) : sched_ptr(sched_), cfg(&sched_->cfg) {}
|
||||
|
||||
void sched::carrier_sched::init()
|
||||
{
|
||||
log_h = sched_ptr->log_h;
|
||||
tti_dl_mask.resize(10, 0);
|
||||
|
||||
// FIXME check cfg
|
||||
bc_sched.reset(new bc_sched_t{cfg});
|
||||
ra_sched.reset(new ra_sched_t{cfg});
|
||||
bc_sched->init(sched_ptr->rrc);
|
||||
ra_sched->init(log_h, sched_ptr->ue_db);
|
||||
}
|
||||
|
||||
void sched::carrier_sched::reset()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(sched_ptr->sched_mutex);
|
||||
if (ra_sched != nullptr) {
|
||||
ra_sched->reset();
|
||||
}
|
||||
if (bc_sched != nullptr) {
|
||||
bc_sched->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void sched::carrier_sched::cell_cfg()
|
||||
{
|
||||
// sched::cfg is now fully set
|
||||
|
||||
// Initiate the tti_scheduler for each TTI
|
||||
for (tti_sched_result_t& tti_sched : tti_scheds) {
|
||||
tti_sched.init(sched_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void sched::carrier_sched::set_metric(sched::metric_dl* dl_metric_, sched::metric_ul* ul_metric_)
|
||||
{
|
||||
dl_metric = dl_metric_;
|
||||
ul_metric = ul_metric_;
|
||||
dl_metric->set_log(log_h);
|
||||
ul_metric->set_log(log_h);
|
||||
}
|
||||
|
||||
void sched::carrier_sched::set_dl_tti_mask(uint8_t* tti_mask, uint32_t nof_sfs)
|
||||
{
|
||||
tti_dl_mask.assign(tti_mask, tti_mask + nof_sfs);
|
||||
}
|
||||
|
||||
sched::tti_sched_result_t* sched::carrier_sched::generate_tti_result(uint32_t tti_rx)
|
||||
{
|
||||
tti_sched_result_t* tti_sched = get_tti_sched(tti_rx);
|
||||
|
||||
// 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 - ((cfg->cell.nof_prb >= 10) ? 0 : 1);
|
||||
tti_sched->new_tti(tti_rx, start_cfi);
|
||||
|
||||
// Protects access to pending_rar[], pending_msg3[], pending_sibs[], rlc buffers
|
||||
std::lock_guard<std::mutex> lock(sched_ptr->sched_mutex);
|
||||
pthread_rwlock_rdlock(&sched_ptr->rwlock);
|
||||
|
||||
/* Schedule PHICH */
|
||||
generate_phich(tti_sched);
|
||||
|
||||
/* Schedule DL */
|
||||
if (tti_dl_mask[tti_sched->get_tti_tx_dl() % tti_dl_mask.size()] == 0) {
|
||||
generate_dl_sched(tti_sched);
|
||||
}
|
||||
|
||||
/* Schedule UL */
|
||||
generate_ul_sched(tti_sched);
|
||||
|
||||
/* Generate DCI */
|
||||
tti_sched->generate_dcis();
|
||||
|
||||
/* reset PIDs with pending data or blocked */
|
||||
for (auto& user : sched_ptr->ue_db) {
|
||||
user.second.reset_pending_pids(tti_rx);
|
||||
}
|
||||
|
||||
pthread_rwlock_unlock(&sched_ptr->rwlock);
|
||||
}
|
||||
|
||||
return tti_sched;
|
||||
}
|
||||
|
||||
void sched::carrier_sched::generate_phich(tti_sched_result_t* tti_sched)
|
||||
{
|
||||
// Allocate user PHICHs
|
||||
uint32_t nof_phich_elems = 0;
|
||||
for (auto& ue_pair : sched_ptr->ue_db) {
|
||||
sched_ue& user = ue_pair.second;
|
||||
uint16_t rnti = ue_pair.first;
|
||||
|
||||
// user.has_pucch = false; // FIXME: What is this for?
|
||||
|
||||
ul_harq_proc* h = user.get_ul_harq(tti_sched->get_tti_rx());
|
||||
|
||||
/* Indicate PHICH acknowledgment if needed */
|
||||
if (h->has_pending_ack()) {
|
||||
tti_sched->ul_sched_result.phich[nof_phich_elems].phich =
|
||||
h->get_pending_ack() ? ul_sched_phich_t::ACK : ul_sched_phich_t::NACK;
|
||||
tti_sched->ul_sched_result.phich[nof_phich_elems].rnti = rnti;
|
||||
log_h->debug("SCHED: Allocated PHICH for rnti=0x%x, value=%d\n",
|
||||
rnti,
|
||||
tti_sched->ul_sched_result.phich[nof_phich_elems].phich);
|
||||
nof_phich_elems++;
|
||||
}
|
||||
}
|
||||
tti_sched->ul_sched_result.nof_phich_elems = nof_phich_elems;
|
||||
}
|
||||
|
||||
int sched::carrier_sched::generate_dl_sched(tti_sched_result_t* tti_result)
|
||||
{
|
||||
/* Schedule Broadcast data (SIB and paging) */
|
||||
if (bc_sched != nullptr) {
|
||||
bc_sched->dl_sched(tti_result);
|
||||
}
|
||||
|
||||
/* Schedule RAR */
|
||||
ra_sched->dl_sched(tti_result);
|
||||
|
||||
/* Schedule pending RLC data */
|
||||
// NOTE: In case of 6 PRBs, do not transmit if there is going to be a PRACH in the UL to avoid collisions
|
||||
if (cfg->cell.nof_prb == 6) {
|
||||
uint32_t tti_rx_ack = TTI_RX_ACK(tti_result->get_tti_rx());
|
||||
bool msg3_enabled = false;
|
||||
if (ra_sched != nullptr and ra_sched->find_pending_msg3(tti_rx_ack).enabled) {
|
||||
msg3_enabled = true;
|
||||
}
|
||||
if (srslte_prach_tti_opportunity_config_fdd(cfg->prach_config, tti_rx_ack, -1) or msg3_enabled) {
|
||||
tti_result->get_dl_mask().fill(0, tti_result->get_dl_mask().size());
|
||||
}
|
||||
}
|
||||
|
||||
// call scheduler metric to fill RB grid
|
||||
dl_metric->sched_users(sched_ptr->ue_db, tti_result);
|
||||
|
||||
return LIBLTE_SUCCESS;
|
||||
}
|
||||
|
||||
int sched::carrier_sched::generate_ul_sched(srsenb::sched::tti_sched_result_t* tti_result)
|
||||
{
|
||||
uint32_t tti_tx_ul = tti_result->get_tti_tx_ul();
|
||||
prbmask_t& ul_mask = tti_result->get_ul_mask();
|
||||
|
||||
/* reserve PRBs for PRACH */
|
||||
if (srslte_prach_tti_opportunity_config_fdd(cfg->prach_config, tti_tx_ul, -1)) {
|
||||
ul_mask = sched_ptr->prach_mask;
|
||||
log_h->debug("SCHED: Allocated PRACH RBs. Mask: 0x%s\n", sched_ptr->prach_mask.to_hex().c_str());
|
||||
}
|
||||
|
||||
/* Allocate Msg3 if there's a pending RAR */
|
||||
ra_sched->ul_sched(tti_result);
|
||||
|
||||
/* reserve PRBs for PUCCH */
|
||||
if (cfg->cell.nof_prb != 6 and (ul_mask & sched_ptr->pucch_mask).any()) {
|
||||
log_h->error("There was a collision with the PUCCH. current mask=0x%s, pucch_mask=0x%s\n",
|
||||
ul_mask.to_hex().c_str(),
|
||||
sched_ptr->pucch_mask.to_hex().c_str());
|
||||
}
|
||||
ul_mask |= sched_ptr->pucch_mask;
|
||||
|
||||
/* Call scheduler for UL data */
|
||||
ul_metric->sched_users(sched_ptr->ue_db, tti_result);
|
||||
|
||||
/* Update pending data counters after this TTI */
|
||||
for (auto& user : sched_ptr->ue_db) {
|
||||
user.second.get_ul_harq(tti_tx_ul)->reset_pending_data();
|
||||
}
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace srsenb
|
Loading…
Reference in New Issue