Pick unreserved UL FN when allocating an SBA

Make sure an unreserved FN is picked and reserved when allocating and
scheduling an SBA.
In practice this has no change in behavior right now, since anyway using
an offset of 52 FNs ensure no USF or POLL has alredy been scheduled that
far in the future. Since it's also impossible to allocate more than 1
SBA per PDCH and RTS FN, we are also safe about multiple SBAs being
allocated, because we use a hardcoded offset of 52.
However, that could change in the future, when we dynamically tweak the
current offset of 52 FN based on information from BTS about its AGCH
queue load:
* If load is high, we may need to increase the offset since it
will take more time for the BTS to transmit the TBF and hence we must
reserve a TBF starting time further in the future (higher FN).
* If load turns low, we may schedule next SBA a bit more nearby in time
  than the previously allocated SBA, hence here there could be a
  collision.

Related: OS#5020
Change-Id: I2d4e21e2307de6c17748e8da5c7e149c947a7eb9
This commit is contained in:
Pau Espin 2021-03-29 12:13:13 +02:00
parent 222f674116
commit ce3bd2522a
5 changed files with 64 additions and 3 deletions

View File

@ -128,6 +128,29 @@ int pdch_ulc_get_next_free_rrbp_fn(struct pdch_ulc *ulc, uint32_t fn, uint32_t *
return 0;
}
/* Get next free (unreserved) FN which is not located in time before "start_fn" */
uint32_t pdch_ulc_get_next_free_fn(struct pdch_ulc *ulc, uint32_t start_fn)
{
struct rb_node *node;
struct pdch_ulc_node *it;
int res;
uint32_t check_fn = start_fn;
for (node = rb_first(&ulc->tree_root); node; node = rb_next(node)) {
it = container_of(node, struct pdch_ulc_node, node);
res = fn_cmp(it->fn, check_fn);
if (res > 0) { /* it->fn AFTER check_fn */
/* Next reserved FN is passed check_fn, hence it means check_fn is free */
return check_fn;
}
/* if it->fn < check_fn, simply continue iterating, we want to reach at least check_fn */
if (res == 0)/* it->fn == fn */
check_fn = fn_next_block(check_fn);
/* if it->fn < check_fn, simply continue iterating, we want to reach at least check_fn */
}
return check_fn;
}
static struct pdch_ulc_node *_alloc_node(struct pdch_ulc *ulc, uint32_t fn)
{
struct pdch_ulc_node *node;

View File

@ -71,6 +71,7 @@ int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba);
bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn);
int pdch_ulc_get_next_free_rrbp_fn(struct pdch_ulc *ulc, uint32_t fn, uint32_t *poll_fn, unsigned int *rrbp);
uint32_t pdch_ulc_get_next_free_fn(struct pdch_ulc *ulc, uint32_t start_fn);
struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn);
struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn);

View File

@ -57,15 +57,18 @@
struct gprs_rlcmac_sba *sba_alloc(void *ctx, struct gprs_rlcmac_pdch *pdch, uint8_t ta)
{
struct gprs_rlcmac_sba *sba;
uint32_t start_fn;
sba = talloc_zero(ctx, struct gprs_rlcmac_sba);
if (!sba)
return NULL;
/* TODO: Increase start_fn dynamically based on AGCH queue load in the BTS: */
start_fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET);
sba->pdch = pdch;
sba->ta = ta;
/* TODO: request ULC for next available FN instead of hardcoded AGCH_START_OFFSET */
sba->fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET);
sba->fn = pdch_ulc_get_next_free_fn(pdch->ulc, start_fn);
pdch_ulc_reserve_sba(pdch->ulc, sba);
return sba;

View File

@ -212,6 +212,30 @@ static void test_fn_wrap_around()
printf("=== end: %s ===\n", __FUNCTION__);
}
static void test_next_free_fn_sba()
{
printf("=== start: %s ===\n", __FUNCTION__);
struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
struct gprs_rlcmac_pdch *pdch = &bts->trx[0].pdch[0];
struct gprs_rlcmac_sba *sba1, *sba2, *sba3, *sba4;
pdch->last_rts_fn = 52;
printf("*** ALLOC 1 SBA FN=%" PRIu32 ":\n", pdch->last_rts_fn);
sba1 = sba_alloc(bts, pdch, 0);
print_ulc_nodes(pdch->ulc);
pdch->last_rts_fn = 65;
printf("*** ALLOC 3 SBA FN=%" PRIu32 ":\n", pdch->last_rts_fn);
sba2 = sba_alloc(bts, pdch, 0);
sba3 = sba_alloc(bts, pdch, 0);
sba4 = sba_alloc(bts, pdch, 0);
print_ulc_nodes(pdch->ulc);
(void)sba1; (void)sba2; (void)sba3; (void)sba4;
talloc_free(bts);
printf("=== end: %s ===\n", __FUNCTION__);
}
int main(int argc, char **argv)
{
tall_pcu_ctx = talloc_named_const(NULL, 1, "pdch_ulc test context");
@ -231,6 +255,7 @@ int main(int argc, char **argv)
test_reserve_multiple();
test_fn_wrap_around();
test_next_free_fn_sba();
talloc_free(the_pcu);
return EXIT_SUCCESS;

View File

@ -247,3 +247,12 @@ FN=34 type=POLL
FN=39 type=POLL
*** EXPIRE FN=43:
=== end: test_fn_wrap_around ===
=== start: test_next_free_fn_sba ===
*** ALLOC 1 SBA FN=52:
FN=104 type=SBA
*** ALLOC 3 SBA FN=65:
FN=104 type=SBA
FN=117 type=SBA
FN=121 type=SBA
FN=125 type=SBA
=== end: test_next_free_fn_sba ===