[PATCH] osmo-pcu[master]: Simplify TS alloc: adjust function signatures

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/.

Max gerrit-no-reply at lists.osmocom.org
Tue Sep 12 11:36:43 UTC 2017


Review at  https://gerrit.osmocom.org/3912

Simplify TS alloc: adjust function signatures

* document used parameters and return values
* use consistent formatting
* constify function parameters where appropriate (adjusting parameter
  types if necessary)

Tests are adjusted accordingly but test results are left untouched to
avoid regressions.

Change-Id: I211b10b4da59c73d509b719346774515c761886a
Related: OS#2282
---
M src/bts.cpp
M src/bts.h
M src/gprs_rlcmac_ts_alloc.cpp
3 files changed, 63 insertions(+), 55 deletions(-)


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

diff --git a/src/bts.cpp b/src/bts.cpp
index 1284f11..0046238 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -439,10 +439,9 @@
  * a TRX. The first TRX that contains such an TFI is returned. Negative values
  * indicate errors.
  */
-int BTS::tfi_find_free(enum gprs_rlcmac_tbf_direction dir,
-		uint8_t *_trx, int8_t use_trx)
+int BTS::tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx) const
 {
-	struct gprs_rlcmac_pdch *pdch;
+	const struct gprs_rlcmac_pdch *pdch;
 	uint32_t free_tfis;
 	bool has_pdch = false;
 	uint8_t trx_from, trx_to, trx, ts, tfi;
diff --git a/src/bts.h b/src/bts.h
index e4b1c23..611a58b 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -364,7 +364,7 @@
 	gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts);
 	gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts);
 
-	int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx);
+	int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx) const;
 
 	int rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn);
 	uint8_t is_single_block(uint16_t ra, enum ph_burst_type burst_type,
diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 14d9e17..0cebd93 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -103,7 +103,7 @@
 	return was_set;
 }
 
-static inline int8_t find_free_usf(struct gprs_rlcmac_pdch *pdch)
+static inline int8_t find_free_usf(const struct gprs_rlcmac_pdch *pdch)
 {
 	uint8_t usf_map = 0;
 	uint8_t usf;
@@ -121,13 +121,11 @@
 	return -1;
 }
 
-static inline int8_t find_free_tfi(struct gprs_rlcmac_pdch *pdch,
-	enum gprs_rlcmac_tbf_direction dir)
+static inline int8_t find_free_tfi(const struct gprs_rlcmac_pdch *pdch, enum gprs_rlcmac_tbf_direction dir)
 {
-	uint32_t tfi_map = 0;
+	uint32_t tfi_map = pdch->assigned_tfi(dir);
 	int8_t tfi;
 
-	tfi_map = pdch->assigned_tfi(dir);
 	if (tfi_map == 0xffffffffUL)
 		return -1;
 
@@ -140,16 +138,15 @@
 	return -1;
 }
 
-static int find_possible_pdchs(struct gprs_rlcmac_trx *trx,
-	size_t max_slots,
-	uint8_t mask, const char *mask_reason = NULL)
+static int find_possible_pdchs(const struct gprs_rlcmac_trx *trx, size_t max_slots, uint8_t mask,
+			       const char *mask_reason = NULL)
 {
 	unsigned ts;
 	int valid_ts_set = 0;
 	int8_t last_tsc = -1; /* must be signed */
 
 	for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
-		struct gprs_rlcmac_pdch *pdch;
+		const struct gprs_rlcmac_pdch *pdch;
 
 		pdch = &trx->pdch[ts];
 		if (!pdch->is_enabled()) {
@@ -187,22 +184,19 @@
 	return valid_ts_set;
 }
 
-static int compute_usage_by_num_tbfs(struct gprs_rlcmac_pdch *pdch,
-	enum gprs_rlcmac_tbf_direction dir)
+static int compute_usage_by_num_tbfs(const struct gprs_rlcmac_pdch *pdch, enum gprs_rlcmac_tbf_direction dir)
 {
 	return pdch->num_tbfs(dir);
 }
 
-static int compute_usage_by_reservation(struct gprs_rlcmac_pdch *pdch,
-	enum gprs_rlcmac_tbf_direction)
+static int compute_usage_by_reservation(const struct gprs_rlcmac_pdch *pdch, enum gprs_rlcmac_tbf_direction)
 {
 	return
 		pdch->num_reserved(GPRS_RLCMAC_DL_TBF) +
 		pdch->num_reserved(GPRS_RLCMAC_UL_TBF);
 }
 
-static int compute_usage_for_algo_a(struct gprs_rlcmac_pdch *pdch,
-	enum gprs_rlcmac_tbf_direction dir)
+static int compute_usage_for_algo_a(const struct gprs_rlcmac_pdch *pdch, enum gprs_rlcmac_tbf_direction dir)
 {
 	int usage =
 		pdch->num_tbfs(GPRS_RLCMAC_DL_TBF) +
@@ -217,11 +211,19 @@
 
 }
 
-static int find_least_busy_pdch(struct gprs_rlcmac_trx *trx,
-	enum gprs_rlcmac_tbf_direction dir,
-	uint8_t mask,
-	int (*fn)(struct gprs_rlcmac_pdch *, enum gprs_rlcmac_tbf_direction dir),
-	int *free_tfi = 0, int *free_usf = 0)
+/*! Return the TS which corresponds to least busy PDCH
+ *
+ *  \param[in] trx Pointer to TRX object
+ *  \param[in] dir TBF direction
+ *  \param[in] mask set of available timeslots
+ *  \param[in] fn Function pointer to function which computes number of associated TBFs
+ *  \param[out] free_tfi Free TFI
+ *  \param[out] free_usf Free USF
+ *  \returns TS number or -1 if unable to find
+ */
+static int find_least_busy_pdch(const struct gprs_rlcmac_trx *trx, enum gprs_rlcmac_tbf_direction dir, uint8_t mask,
+				int (*fn)(const struct gprs_rlcmac_pdch *, enum gprs_rlcmac_tbf_direction dir),
+				int *free_tfi = 0, int *free_usf = 0)
 {
 	unsigned ts;
 	int min_used = INT_MAX;
@@ -230,7 +232,7 @@
 	int min_usf = -1;
 
 	for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
-		struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
+		const struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
 		int num_tbfs;
 		int usf = -1; /* must be signed */
 		int tfi = -1;
@@ -300,30 +302,23 @@
 	pdch->attach_tbf(tbf);
 }
 
-static void assign_uplink_tbf_usf(
-				struct gprs_rlcmac_pdch *pdch,
-				struct gprs_rlcmac_ul_tbf *tbf,
-				int tfi, int8_t usf)
+static void assign_uplink_tbf_usf(struct gprs_rlcmac_pdch *pdch, struct gprs_rlcmac_ul_tbf *tbf, uint8_t tfi, int8_t usf)
 {
 	tbf->m_tfi = tfi;
 	tbf->m_usf[pdch->ts_no] = usf;
 	attach_tbf_to_pdch(pdch, tbf);
 }
 
-static void assign_dlink_tbf(
-				struct gprs_rlcmac_pdch *pdch,
-				struct gprs_rlcmac_dl_tbf *tbf,
-				int tfi)
+static void assign_dlink_tbf(struct gprs_rlcmac_pdch *pdch, struct gprs_rlcmac_dl_tbf *tbf, uint8_t tfi)
 {
 	tbf->m_tfi = tfi;
 	attach_tbf_to_pdch(pdch, tbf);
 }
 
-static int find_trx(BTS *bts, const GprsMs *ms, int use_trx)
+static int find_trx(const struct gprs_rlcmac_bts *bts_data, const GprsMs *ms, int8_t use_trx)
 {
 	unsigned trx_no;
 	unsigned ts;
-	struct gprs_rlcmac_bts *bts_data = bts->bts_data();
 
 	/* We must use the TRX currently actively used by an MS */
 	if (ms && ms->current_trx())
@@ -334,9 +329,9 @@
 
 	/* Find the first TRX that has a PDCH with a free UL and DL TFI */
 	for (trx_no = 0; trx_no < ARRAY_SIZE(bts_data->trx); trx_no += 1) {
-		struct gprs_rlcmac_trx *trx = &bts_data->trx[trx_no];
+		const struct gprs_rlcmac_trx *trx = &bts_data->trx[trx_no];
 		for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
-			struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
+			const struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
 			if (!pdch->is_enabled())
 				continue;
 
@@ -353,32 +348,41 @@
 	return -EBUSY;
 }
 
-static struct gprs_rlcmac_pdch * find_idle_pdch(BTS *bts)
+static bool idle_pdch_avail(const struct gprs_rlcmac_bts *bts_data)
 {
 	unsigned trx_no;
 	unsigned ts;
-	struct gprs_rlcmac_bts *bts_data = bts->bts_data();
 
 	/* Find the first PDCH with an unused DL TS */
 	for (trx_no = 0; trx_no < ARRAY_SIZE(bts_data->trx); trx_no += 1) {
-		struct gprs_rlcmac_trx *trx = &bts_data->trx[trx_no];
+		const struct gprs_rlcmac_trx *trx = &bts_data->trx[trx_no];
 		for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
-			struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
+			const struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
 			if (!pdch->is_enabled())
 				continue;
 
 			if (pdch->num_tbfs(GPRS_RLCMAC_DL_TBF) > PDCH_IDLE_TBF_THRESH)
 				continue;
 
-			return pdch;
+			return true;
 		}
 	}
 
-	return NULL;
+	return false;
 }
 
-static int tfi_find_free(BTS *bts, const GprsMs *ms,
-	enum gprs_rlcmac_tbf_direction dir, int use_trx, int *trx_no_)
+/*! Return free TFI
+ *
+ *  \param[in] bts Pointer to BTS struct
+ *  \param[in] trx Pointer to TRX struct
+ *  \param[in] ms Pointer to MS object
+ *  \param[in] dir DL or UL direction
+ *  \param[in] use_trx which TRX to use or -1 if it should be selected based on what MS uses
+ *  \param[out] trx_no_ TRX number on which TFI was found
+ *  \returns negative error code or 0 on success
+ */
+static int tfi_find_free(const BTS *bts, const gprs_rlcmac_trx *trx, const GprsMs *ms,
+			 enum gprs_rlcmac_tbf_direction dir, int8_t use_trx, uint8_t *trx_no_)
 {
 	int tfi;
 	uint8_t trx_no;
@@ -426,7 +430,7 @@
 	LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
 		"%d\n", tbf->ms_class());
 
-	trx_no = find_trx(bts->bts, ms, use_trx);
+	trx_no = find_trx(bts, ms, use_trx);
 	if (trx_no < 0) {
 		LOGP(DRLCMAC, LOGL_NOTICE,
 			"- Failed to find a usable TRX (TFI exhausted)\n");
@@ -494,9 +498,15 @@
 	return 0;
 }
 
-static int find_multi_slots(struct gprs_rlcmac_bts *bts,
-	struct gprs_rlcmac_trx *trx,
-	const GprsMs *ms, uint8_t *ul_slots, uint8_t *dl_slots)
+/*! Find set of slots available for allocation while taking MS class into account
+ *
+ *  \param[in] trx Pointer to TRX object
+ *  \param[in] ms Pointer to MS object
+ *  \param[in,out] ul_slots set of UL timeslots
+ *  \param[in,out] dl_slots set of DL timeslots
+ *  \returns negative error code or 0 on success
+ */
+static int find_multi_slots(const struct gprs_rlcmac_trx *trx, const GprsMs *ms, uint8_t *ul_slots, uint8_t *dl_slots)
 {
 	const struct gprs_ms_multislot_class *ms_class;
 	uint8_t Tx, Sum;	/* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
@@ -753,7 +763,7 @@
 
 		for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
 			int c;
-			struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
+			const struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
 			if (rx_window & (1 << ts)) {
 				c = 32 - pdch->num_reserved(GPRS_RLCMAC_DL_TBF);
 				c = OSMO_MAX(c, 1);
@@ -824,14 +834,13 @@
 	uint8_t reserved_ul_slots;
 	int8_t first_common_ts;
 	uint8_t slotcount = 0;
-	uint8_t avail_count = 0;
+	uint8_t avail_count = 0, trx_no;
 	char slot_info[9] = {0};
 	int ts;
 	int first_ts = -1;
 	int usf[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
 	int rc;
 	int tfi;
-	int trx_no;
 	const GprsMs *ms = ms_;
 	const gprs_rlcmac_tbf *tbf = tbf_;
 	gprs_rlcmac_trx *trx;
@@ -859,7 +868,7 @@
 	}
 
 	/* Step 2a: Find usable TRX and TFI */
-	tfi = tfi_find_free(bts->bts, ms, tbf->direction, use_trx, &trx_no);
+	tfi = tfi_find_free(bts->bts, trx, ms, tbf->direction, use_trx, &trx_no);
 	if (tfi < 0) {
 		LOGP(DRLCMAC, LOGL_NOTICE, "- Failed to allocate a TFI\n");
 		return tfi;
@@ -870,7 +879,7 @@
 		trx = &bts->trx[trx_no];
 
 	if (!dl_slots || !ul_slots) {
-		rc = find_multi_slots(bts, trx, ms, &ul_slots, &dl_slots);
+		rc = find_multi_slots(trx, ms, &ul_slots, &dl_slots);
 		if (rc < 0)
 			return rc;
 
@@ -1060,7 +1069,7 @@
 
 	/* Reset load_is_high if there is at least one idle PDCH */
 	if (bts->multislot_disabled) {
-		bts->multislot_disabled = find_idle_pdch(bts->bts) == NULL;
+		bts->multislot_disabled = !idle_pdch_avail(bts);
 		if (!bts->multislot_disabled)
 			LOGP(DRLCMAC, LOGL_DEBUG, "Enabling algorithm B\n");
 	}

-- 
To view, visit https://gerrit.osmocom.org/3912
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I211b10b4da59c73d509b719346774515c761886a
Gerrit-PatchSet: 1
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list