Change in osmo-pcu[master]: alloc_algo_b: Select TRX with least assigned TFIs during TBF alloc

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Mon Oct 26 15:22:12 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/20919 )


Change subject: alloc_algo_b: Select TRX with least assigned TFIs during TBF alloc
......................................................................

alloc_algo_b: Select TRX with least assigned TFIs during TBF alloc

Before this patch, it would always allocate all TBFs on the first TRX
until all TFIs were filled, then second, and so on. But it would
actually fail around 8th MS requesting an UL TBF because despite a TFI
was successfuly assigned, because all USFs were already exhausted for
that PDCH.

Related: OS#1775
Change-Id: Iccfc8acfbfdc258ed16cc5af01f12b376fe73b72
---
M src/bts.cpp
M tests/tbf/TbfTest.cpp
2 files changed, 53 insertions(+), 30 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/19/20919/1

diff --git a/src/bts.cpp b/src/bts.cpp
index da62b30..833dcca 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -536,18 +536,51 @@
 	return m_bts.trx[trx].pdch[ts].ul_tbf_by_tfi(tfi);
 }
 
+
+static uint8_t trx_count_free_tfi(const struct gprs_rlcmac_trx *trx, enum gprs_rlcmac_tbf_direction dir, uint32_t *free_tfi_mask)
+{
+	const struct gprs_rlcmac_pdch *pdch;
+	uint8_t ts;
+	unsigned i;
+	uint8_t free_tfi = 0;
+	bool has_pdch = false;
+	uint32_t mask = NO_FREE_TFI;
+
+	for (ts = 0; ts < 8; ts++) {
+		pdch = &trx->pdch[ts];
+		if (!pdch->is_enabled())
+			continue;
+		has_pdch = true;
+		mask &= ~pdch->assigned_tfi(dir);
+	}
+
+	if (!has_pdch || !mask) {
+		*free_tfi_mask = 0;
+		return 0;
+	}
+
+	*free_tfi_mask = mask;
+
+	/* Count free tfis and return */
+	for (i = 0; i < sizeof(uint32_t)*8 ; i++) {
+		if(mask & 1)
+			free_tfi++;
+		mask >>= 1;
+	}
+	return free_tfi;
+}
+
 /*
- * Search for free TFI and return TFI, TRX.
- * This method returns the first TFI that is currently not used in any PDCH of
- * a TRX. The first TRX that contains such an TFI is returned. Negative values
- * indicate errors.
+ * Search for free TFI and return TFI, TRX. This method returns the first TFI
+ * that is currently not used in any PDCH of a the TRX with least TFIs currently
+ * assigned. Negative values indicate errors.
  */
 int BTS::tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx) const
 {
-	const struct gprs_rlcmac_pdch *pdch;
-	uint32_t free_tfis;
-	bool has_pdch = false;
-	uint8_t trx_from, trx_to, trx, ts, tfi;
+	uint8_t trx_from, trx_to, trx, tfi;
+	uint8_t best_trx_nr = 0xff;
+	uint8_t best_cnt = 0;
+	uint32_t best_mask = 0;
 
 	if (use_trx >= 0 && use_trx < 8)
 		trx_from = trx_to = use_trx;
@@ -558,47 +591,36 @@
 
 	/* find a TFI that is unused on all PDCH */
 	for (trx = trx_from; trx <= trx_to; trx++) {
-		bool trx_has_pdch = false;
 
-		free_tfis = NO_FREE_TFI;
-
-		for (ts = 0; ts < 8; ts++) {
-			pdch = &m_bts.trx[trx].pdch[ts];
-			if (!pdch->is_enabled())
-				continue;
-			free_tfis &= ~pdch->assigned_tfi(dir);
-			trx_has_pdch = true;
-			has_pdch = true;
+		uint32_t tmp_mask;
+		uint8_t tmp_cnt;
+		tmp_cnt = trx_count_free_tfi(&m_bts.trx[trx], dir, &tmp_mask);
+		if (tmp_cnt > best_cnt) {
+			best_cnt = tmp_cnt;
+			best_mask = tmp_mask;
+			best_trx_nr = trx;
 		}
-		if (trx_has_pdch && free_tfis)
-			break;
-
-		free_tfis = 0;
-	}
-	if (!has_pdch) {
-		LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH available.\n");
-		return -EINVAL;
 	}
 
-	if (!free_tfis) {
+	if (best_trx_nr == 0xff || best_cnt == 0) {
 		LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available (suggested TRX: %d).\n", use_trx);
 		return -EBUSY;
 	}
 
 
 	LOGP(DRLCMAC, LOGL_DEBUG,
-		"Searching for first unallocated TFI: TRX=%d\n", trx);
+		"Searching for first unallocated TFI: TRX=%d\n", best_trx_nr);
 
 	/* find the first */
 	for (tfi = 0; tfi < 32; tfi++) {
-		if (free_tfis & 1 << tfi)
+		if (best_mask & 1 << tfi)
 			break;
 	}
 
 	OSMO_ASSERT(tfi < 32);
 
 	LOGP(DRLCMAC, LOGL_DEBUG, " Found TFI=%d.\n", tfi);
-	*_trx = trx;
+	*_trx = best_trx_nr;
 	return tfi;
 }
 
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index 2b5bda5..8a6789b 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -197,6 +197,7 @@
 	tfi = the_bts->tfi_find_free(GPRS_RLCMAC_DL_TBF, &trx_no, -1);
 	OSMO_ASSERT(tfi >= 0);
 	dl_tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, true);
+	OSMO_ASSERT(dl_tbf);
 	dl_tbf->set_ta(0);
 	check_tbf(dl_tbf);
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-pcu/+/20919
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: Iccfc8acfbfdc258ed16cc5af01f12b376fe73b72
Gerrit-Change-Number: 20919
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201026/d2dac9b6/attachment.htm>


More information about the gerrit-log mailing list