mirror of https://github.com/pvnis/srsRAN_4G.git
move scheduler rbg/prb/cce mask and interval types and associated helper functions to a separate file
parent
7c0649bc24
commit
0e0835a805
@ -0,0 +1,174 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 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 SRSRAN_SCHED_PHY_RESOURCE_H
|
||||
#define SRSRAN_SCHED_PHY_RESOURCE_H
|
||||
|
||||
#include "srsran/adt/bounded_bitset.h"
|
||||
#include "srsran/adt/interval.h"
|
||||
#include "srsran/common/srsran_assert.h"
|
||||
extern "C" {
|
||||
#include "srsran/phy/phch/ra.h"
|
||||
}
|
||||
|
||||
// Description: This file defines the types associated with representing the allocation masks/intervals for RBGs, PRBs
|
||||
// and PDCCH CCEs, and provides some function helpers and algorithms to handle these types.
|
||||
|
||||
constexpr uint32_t MAX_NOF_RBGS = 25;
|
||||
constexpr uint32_t MAX_NOF_PRBS = 100;
|
||||
constexpr uint32_t MAX_NOF_CCES = 128;
|
||||
|
||||
namespace srsenb {
|
||||
|
||||
/// convert cell nof PRBs to nof RBGs
|
||||
inline uint32_t cell_nof_prb_to_rbg(uint32_t nof_prbs)
|
||||
{
|
||||
switch (nof_prbs) {
|
||||
case 6:
|
||||
return 6;
|
||||
case 15:
|
||||
return 8;
|
||||
case 25:
|
||||
return 13;
|
||||
case 50:
|
||||
return 17;
|
||||
case 75:
|
||||
return 19;
|
||||
case 100:
|
||||
return 25;
|
||||
default:
|
||||
srsran_terminate("Provided nof PRBs not valid");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// convert cell nof RBGs to nof PRBs
|
||||
inline uint32_t cell_nof_rbg_to_prb(uint32_t nof_rbgs)
|
||||
{
|
||||
switch (nof_rbgs) {
|
||||
case 6:
|
||||
return 6;
|
||||
case 8:
|
||||
return 15;
|
||||
case 13:
|
||||
return 25;
|
||||
case 17:
|
||||
return 50;
|
||||
case 19:
|
||||
return 75;
|
||||
case 25:
|
||||
return 100;
|
||||
default:
|
||||
srsran_terminate("Provided nof PRBs not valid");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Bitmask used for CCE allocations
|
||||
using pdcch_mask_t = srsran::bounded_bitset<MAX_NOF_CCES, true>;
|
||||
|
||||
/// Bitmask that stores the allocared DL RBGs
|
||||
using rbgmask_t = srsran::bounded_bitset<MAX_NOF_RBGS, true>;
|
||||
|
||||
/// Bitmask that stores the allocated UL PRBs
|
||||
using prbmask_t = srsran::bounded_bitset<MAX_NOF_PRBS, true>;
|
||||
|
||||
/// Struct to express a {min,...,max} range of RBGs
|
||||
struct prb_interval;
|
||||
struct rbg_interval : public srsran::interval<uint32_t> {
|
||||
using interval::interval;
|
||||
static rbg_interval find_first_interval(const rbgmask_t& mask);
|
||||
static rbg_interval prbs_to_rbgs(const prb_interval& prbs, uint32_t cell_nof_prb);
|
||||
};
|
||||
|
||||
/// Struct to express a {min,...,max} range of PRBs
|
||||
struct prb_interval : public srsran::interval<uint32_t> {
|
||||
using interval::interval;
|
||||
static prb_interval rbgs_to_prbs(const rbg_interval& rbgs, uint32_t cell_nof_prb)
|
||||
{
|
||||
uint32_t P = srsran_ra_type0_P(cell_nof_prb);
|
||||
return prb_interval{rbgs.start() * P, std::min(rbgs.stop() * P, cell_nof_prb)};
|
||||
}
|
||||
static prb_interval riv_to_prbs(uint32_t riv, uint32_t nof_prbs, int nof_vrbs = -1);
|
||||
};
|
||||
|
||||
inline rbg_interval rbg_interval::prbs_to_rbgs(const prb_interval& prbs, uint32_t cell_nof_prb)
|
||||
{
|
||||
uint32_t P = srsran_ra_type0_P(cell_nof_prb);
|
||||
return rbg_interval{prbs.start() / P, srsran::ceil_div(prbs.stop(), P)};
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
* helper functions
|
||||
*******************************************************/
|
||||
|
||||
/// If the RBG mask one bits are all contiguous
|
||||
inline bool is_contiguous(const rbgmask_t& mask)
|
||||
{
|
||||
return rbg_interval::find_first_interval(mask).length() == mask.count();
|
||||
}
|
||||
|
||||
/// Count number of PRBs present in a DL RBG mask
|
||||
inline uint32_t count_prb_per_tb(const rbgmask_t& bitmask)
|
||||
{
|
||||
uint32_t Nprb = cell_nof_rbg_to_prb(bitmask.size());
|
||||
uint32_t P = srsran_ra_type0_P(Nprb);
|
||||
uint32_t nof_prb = P * bitmask.count();
|
||||
if (bitmask.test(bitmask.size() - 1)) {
|
||||
nof_prb -= bitmask.size() * P - Nprb;
|
||||
}
|
||||
return nof_prb;
|
||||
}
|
||||
|
||||
/// Estimate of number of PRBs in DL grant given Nof RBGs
|
||||
inline uint32_t count_prb_per_tb_approx(uint32_t nof_rbgs, uint32_t cell_nof_prb)
|
||||
{
|
||||
uint32_t P = srsran_ra_type0_P(cell_nof_prb);
|
||||
return std::min(nof_rbgs * P, cell_nof_prb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a contiguous interval of "zeroed"/available RBG resources
|
||||
* @param max_nof_rbgs maximum number of RBGs
|
||||
* @param current_mask bitmask of occupied RBGs, used to search for available RBGs
|
||||
* @return interval with found RBGs. If a valid interval wasn't found, interval.length() == 0
|
||||
*/
|
||||
rbg_interval find_empty_rbg_interval(uint32_t max_nof_rbgs, const rbgmask_t& current_mask);
|
||||
|
||||
/**
|
||||
* Finds a bitmask of "zeroed"/available RBG resources
|
||||
* @param max_nof_rbgs maximum number of RBGs
|
||||
* @param current_mask bitmask of occupied RBGs, used to search for available RBGs
|
||||
* @return bitmask of found RBGs. If a valid mask wasn't found, bitmask::size() == 0
|
||||
*/
|
||||
rbgmask_t find_available_rbgmask(uint32_t max_nof_rbgs, bool is_contiguous, const rbgmask_t& current_mask);
|
||||
|
||||
/**
|
||||
* Finds a range of L contiguous PRBs that are empty
|
||||
* @param L Max length of the requested UL PRBs
|
||||
* @param current_mask input PRB mask where to search for available PRBs
|
||||
* @return found interval of PRBs
|
||||
*/
|
||||
prb_interval find_contiguous_ul_prbs(uint32_t L, const prbmask_t& current_mask);
|
||||
|
||||
} // namespace srsenb
|
||||
|
||||
namespace fmt {
|
||||
|
||||
template <>
|
||||
struct formatter<srsenb::rbg_interval> : public formatter<srsran::interval<uint32_t> > {};
|
||||
template <>
|
||||
struct formatter<srsenb::prb_interval> : public formatter<srsran::interval<uint32_t> > {};
|
||||
|
||||
} // namespace fmt
|
||||
|
||||
#endif // SRSRAN_SCHED_PHY_RESOURCE_H
|
@ -0,0 +1,139 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 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_phy_ch/sched_phy_resource.h"
|
||||
extern "C" {
|
||||
#include "lib/include/srsran/phy/dft/dft_precoding.h"
|
||||
}
|
||||
|
||||
namespace srsenb {
|
||||
|
||||
rbg_interval rbg_interval::find_first_interval(const rbgmask_t& mask)
|
||||
{
|
||||
int rb_start = -1;
|
||||
for (uint32_t i = 0; i < mask.size(); i++) {
|
||||
if (rb_start == -1) {
|
||||
if (mask.test(i)) {
|
||||
rb_start = i;
|
||||
}
|
||||
} else {
|
||||
if (!mask.test(i)) {
|
||||
return rbg_interval(rb_start, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rb_start != -1) {
|
||||
return rbg_interval(rb_start, mask.size());
|
||||
}
|
||||
return rbg_interval();
|
||||
}
|
||||
|
||||
prb_interval prb_interval::riv_to_prbs(uint32_t riv, uint32_t nof_prbs, int nof_vrbs)
|
||||
{
|
||||
if (nof_vrbs < 0) {
|
||||
nof_vrbs = nof_prbs;
|
||||
}
|
||||
uint32_t rb_start, l_crb;
|
||||
srsran_ra_type2_from_riv(riv, &l_crb, &rb_start, nof_prbs, (uint32_t)nof_vrbs);
|
||||
return {rb_start, rb_start + l_crb};
|
||||
}
|
||||
|
||||
template <typename RBMask,
|
||||
typename RBInterval =
|
||||
typename std::conditional<std::is_same<RBMask, prbmask_t>::value, prb_interval, rbg_interval>::type>
|
||||
RBInterval find_contiguous_interval(const RBMask& in_mask, uint32_t max_size)
|
||||
{
|
||||
RBInterval max_interv;
|
||||
|
||||
for (size_t n = 0; n < in_mask.size();) {
|
||||
int pos = in_mask.find_lowest(n, in_mask.size(), false);
|
||||
if (pos < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
size_t max_pos = std::min(in_mask.size(), (size_t)pos + max_size);
|
||||
int pos2 = in_mask.find_lowest(pos, max_pos, true);
|
||||
RBInterval interv(pos, pos2 < 0 ? max_pos : pos2);
|
||||
if (interv.length() >= max_size) {
|
||||
return interv;
|
||||
}
|
||||
if (interv.length() > max_interv.length()) {
|
||||
max_interv = interv;
|
||||
}
|
||||
n = interv.stop();
|
||||
}
|
||||
return max_interv;
|
||||
}
|
||||
|
||||
rbgmask_t find_available_rbgmask(const rbgmask_t& in_mask, uint32_t max_size)
|
||||
{
|
||||
// 1's for free RBs
|
||||
rbgmask_t localmask = ~(in_mask);
|
||||
|
||||
if (max_size >= localmask.size() or max_size >= localmask.count()) {
|
||||
// shortcut in case rbg count < max_size
|
||||
return localmask;
|
||||
}
|
||||
|
||||
uint32_t i = 0, nof_alloc = 0;
|
||||
for (; i < localmask.size() and nof_alloc < max_size; ++i) {
|
||||
if (localmask.test(i)) {
|
||||
nof_alloc++;
|
||||
}
|
||||
}
|
||||
localmask.fill(i, localmask.size(), false);
|
||||
return localmask;
|
||||
}
|
||||
|
||||
rbg_interval find_empty_rbg_interval(uint32_t max_nof_rbgs, const rbgmask_t& current_mask)
|
||||
{
|
||||
return find_contiguous_interval(current_mask, max_nof_rbgs);
|
||||
}
|
||||
|
||||
rbgmask_t find_available_rbgmask(uint32_t max_nof_rbgs, bool is_contiguous, const rbgmask_t& current_mask)
|
||||
{
|
||||
// Allocate enough RBs that accommodate pending data
|
||||
rbgmask_t newtx_mask(current_mask.size());
|
||||
if (is_contiguous) {
|
||||
rbg_interval interv = find_contiguous_interval(current_mask, max_nof_rbgs);
|
||||
newtx_mask.fill(interv.start(), interv.stop());
|
||||
} else {
|
||||
newtx_mask = find_available_rbgmask(current_mask, max_nof_rbgs);
|
||||
}
|
||||
return newtx_mask;
|
||||
}
|
||||
|
||||
prb_interval find_contiguous_ul_prbs(uint32_t L, const prbmask_t& current_mask)
|
||||
{
|
||||
prb_interval prb_interv = find_contiguous_interval(current_mask, L);
|
||||
if (prb_interv.empty()) {
|
||||
return prb_interv;
|
||||
}
|
||||
|
||||
// Make sure L is allowed by SC-FDMA modulation
|
||||
prb_interval prb_interv2 = prb_interv;
|
||||
while (not srsran_dft_precoding_valid_prb(prb_interv.length()) and prb_interv.stop() < current_mask.size() and
|
||||
not current_mask.test(prb_interv.stop())) {
|
||||
prb_interv.resize_by(1);
|
||||
}
|
||||
if (not srsran_dft_precoding_valid_prb(prb_interv.length())) {
|
||||
// if length increase failed, try to decrease
|
||||
prb_interv = prb_interv2;
|
||||
prb_interv.resize_by(-1);
|
||||
while (not srsran_dft_precoding_valid_prb(prb_interv.length()) and not prb_interv.empty()) {
|
||||
prb_interv.resize_by(-1);
|
||||
}
|
||||
}
|
||||
return prb_interv;
|
||||
}
|
||||
|
||||
} // namespace srsenb
|
Loading…
Reference in New Issue