[PATCH] osmo-pcu[master]: Simplify TS alloc: cosmetic, use proper format

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 12:53:14 UTC 2017


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

Simplify TS alloc: cosmetic, use proper format

The find_multi_slots() function has 4 nested for(;;) loops but it's
formatted as one. Before trying to split this into smth saner, let's
first fix code formatting to make nested loops obvious. Also, fix typos
in comments.

Change-Id: I50b59b12e8d938bd96f9b29d00a649cd3e77bc5e
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
1 file changed, 161 insertions(+), 159 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index c050030..1410e00 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -608,8 +608,7 @@
 			rx_mask[MASK_TT] = (0x100 >> OSMO_MAX(Ttb, Tta)) - 1;
 			rx_mask[MASK_TT] &= ~((1 << (Trb + num_tx)) - 1);
 			rx_mask[MASK_TR] = (0x100 >> Ttb) - 1;
-			rx_mask[MASK_TR] &=
-				~((1 << (OSMO_MAX(Trb, Tra) + num_tx)) - 1);
+			rx_mask[MASK_TR] &= ~((1 << (OSMO_MAX(Trb, Tra) + num_tx)) - 1);
 		} else {
 			/* Class type 2 MS have independant RX and TX */
 			rx_mask[MASK_TT] = 0xff;
@@ -619,180 +618,183 @@
 		rx_mask[MASK_TT] = (rx_mask[MASK_TT] << 3) | (rx_mask[MASK_TT] >> 5);
 		rx_mask[MASK_TR] = (rx_mask[MASK_TR] << 3) | (rx_mask[MASK_TR] >> 5);
 
-	/* Rotate group of TX slots: UUU-----, -UUU----, ..., UU-----U */
-	for (ul_ts = 0; ul_ts < 8; ul_ts += 1, tx_valid_win <<= 1) {
-		unsigned tx_slot_count;
-		int max_rx;
-		uint16_t rx_valid_win;
-		uint32_t checked_rx[256/32] = {0};
+		/* Rotate group of TX slots: UUU-----, -UUU----, ..., UU-----U */
+		for (ul_ts = 0; ul_ts < 8; ul_ts += 1, tx_valid_win <<= 1) {
+			unsigned tx_slot_count;
+			int max_rx;
+			uint16_t rx_valid_win;
+			uint32_t checked_rx[256/32] = {0};
 
-		/* Wrap valid window */
-		tx_valid_win = (tx_valid_win | tx_valid_win >> 8) & 0xff;
+			/* Wrap valid window */
+			tx_valid_win = (tx_valid_win | tx_valid_win >> 8) & 0xff;
 
-		tx_window = tx_valid_win;
+			tx_window = tx_valid_win;
 
-		/* Filter out unavailable slots */
-		tx_window &= *ul_slots;
+			/* Filter out unavailable slots */
+			tx_window &= *ul_slots;
 
-		/* Skip if the the first TS (ul_ts) is not in the set */
-		if ((tx_window & (1 << ul_ts)) == 0)
-			continue;
-
-		/* Skip if the the last TS (ul_ts+num_tx-1) is not in the set */
-		if ((tx_window & (1 << ((ul_ts+num_tx-1) % 8))) == 0)
-			continue;
-
-		tx_slot_count = pcu_bitcount(tx_window);
-
-		max_rx = OSMO_MIN(ms_class->rx, ms_class->sum - num_tx);
-		rx_valid_win = (1 << max_rx) - 1;
-
-	/* Rotate group of RX slots: DDD-----, -DDD----, ..., DD-----D */
-	for (dl_ts = 0; dl_ts < 8; dl_ts += 1, rx_valid_win <<= 1) {
-		/* Wrap valid window */
-		rx_valid_win = (rx_valid_win | rx_valid_win >> 8) & 0xff;
-
-	/* Validate with both Tta/Ttb/Trb and Ttb/Tra/Trb */
-	for (mask_sel = MASK_TT; mask_sel <= MASK_TR; mask_sel += 1) {
-		unsigned common_slot_count;
-		unsigned req_common_slots;
-		unsigned rx_slot_count;
-		uint16_t rx_bad;
-		uint8_t rx_good;
-		unsigned ts;
-		int capacity;
-
-		/* Filter out bad slots */
-		rx_bad = (uint16_t)(0xff & ~rx_mask[mask_sel]) << ul_ts;
-		rx_bad = (rx_bad | (rx_bad >> 8)) & 0xff;
-		rx_good = *dl_slots & ~rx_bad;
-
-		/* TODO: CHECK this calculation -> separate function for unit
-		 * testing */
-
-		rx_window = rx_good & rx_valid_win;
-		rx_slot_count = pcu_bitcount(rx_window);
-
-		if (enable_debug)
-			LOGP(DRLCMAC, LOGL_DEBUG,
-			     "n_tx=%d, n_rx=%d, mask_sel=%d, tx=%02x, rx=%02x, mask=%02x, bad=%02x, good=%02x, ul=%02x,"
-			     " dl=%02x\n",
-			     tx_slot_count, rx_slot_count, mask_sel,
-			     tx_window, rx_window, rx_mask[mask_sel], rx_bad, rx_good,
-			     *ul_slots, *dl_slots);
-
-		/* Check compliance with TS 45.002, table 6.4.2.2.1 */
-		/* Whether to skip this round doesn not only depend on the bit
-		 * sets but also on mask_sel. Therefore this check must be done
-		 * before doing the test_and_set_bit shortcut. */
-		if (ms_class->type == 1) {
-			unsigned slot_sum = rx_slot_count + tx_slot_count;
-			/* Assume down+up/dynamic.
-			 * TODO: For ext-dynamic, down only, up only add more
-			 *       cases.
-			 */
-			if (slot_sum <= 6 && tx_slot_count < 3) {
-			       if (mask_sel != MASK_TR)
-				       /* Skip Tta */
-				       continue;
-			} else if (slot_sum > 6 && tx_slot_count < 3) {
-				if (mask_sel != MASK_TT)
-					/* Skip Tra */
-					continue;
-			} else {
-				/* No supported row in table 6.4.2.2.1. */
-				if (enable_debug)
-					LOGP(DRLCMAC, LOGL_DEBUG,
-					     "- Skipping DL/UL slots: (TS=0)\"%s\"(TS=7), combination not supported\n",
-					     set_flag_chars(set_flag_chars(set_flag_chars(
-										   slot_info,
-										   rx_bad, 'x', '.'),
-									   rx_window, 'D'),
-							    tx_window, 'U'));
-
+			/* Skip if the the first TS (ul_ts) is not in the set */
+			if ((tx_window & (1 << ul_ts)) == 0)
 				continue;
-			}
-		}
 
-		/* Avoid repeated RX combination check */
-		if (test_and_set_bit(checked_rx, rx_window))
-			continue;
+			/* Skip if the the last TS (ul_ts+num_tx-1) is not in the set */
+			if ((tx_window & (1 << ((ul_ts+num_tx-1) % 8))) == 0)
+				continue;
 
-		if (!rx_good) {
-			if (enable_debug)
-				LOGP(DRLCMAC, LOGL_DEBUG,
-				     "- Skipping DL/UL slots: (TS=0)\"%s\"(TS=7), no DL slots available\n",
-				     set_flag_chars(set_flag_chars(slot_info,
-								   rx_bad, 'x', '.'),
-						    tx_window, 'U'));
+			tx_slot_count = pcu_bitcount(tx_window);
 
-			continue;
-		}
+			max_rx = OSMO_MIN(ms_class->rx, ms_class->sum - num_tx);
+			rx_valid_win = (1 << max_rx) - 1;
 
-		if (!rx_window)
-			continue;
+			/* Rotate group of RX slots: DDD-----, -DDD----, ..., DD-----D */
+			for (dl_ts = 0; dl_ts < 8; dl_ts += 1, rx_valid_win <<= 1) {
+				/* Wrap valid window */
+				rx_valid_win = (rx_valid_win | rx_valid_win >> 8) & 0xff;
 
-		/* Check number of common slots according to TS 54.002, 6.4.2.2 */
-		common_slot_count = pcu_bitcount(tx_window & rx_window);
-		req_common_slots = OSMO_MIN(tx_slot_count, rx_slot_count);
-		if (ms_class->type == 1)
-			req_common_slots = OSMO_MIN(req_common_slots, 2);
+				/* Validate with both Tta/Ttb/Trb and Ttb/Tra/Trb */
+				for (mask_sel = MASK_TT; mask_sel <= MASK_TR; mask_sel += 1) {
+					unsigned common_slot_count;
+					unsigned req_common_slots;
+					unsigned rx_slot_count;
+					uint16_t rx_bad;
+					uint8_t rx_good;
+					unsigned ts;
+					int capacity;
 
-		if (req_common_slots != common_slot_count) {
-			if (enable_debug)
-				LOGP(DRLCMAC, LOGL_DEBUG,
-				     "- Skipping DL/UL slots: (TS=0)\"%s\"(TS=7), invalid number of common TS: %d "
-				     "(expected %d)\n",
-				     set_flag_chars(set_flag_chars(set_flag_chars(
-									   slot_info,
-									   rx_bad, 'x', '.'),
-								   rx_window, 'D'),
-						    tx_window, 'U'),
-				     common_slot_count,
-				     req_common_slots);
+					/* Filter out bad slots */
+					rx_bad = (uint16_t)(0xff & ~rx_mask[mask_sel]) << ul_ts;
+					rx_bad = (rx_bad | (rx_bad >> 8)) & 0xff;
+					rx_good = *dl_slots & ~rx_bad;
 
-			continue;
-		}
+					/* TODO: CHECK this calculation -> separate function for unit testing */
 
-		/* Compute capacity */
-		capacity = 0;
+					rx_window = rx_good & rx_valid_win;
+					rx_slot_count = pcu_bitcount(rx_window);
 
-		for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
-			int c;
-			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);
-				capacity += c;
-			}
-			/* Only consider common slots for UL */
-			if (tx_window & rx_window & (1 << ts)) {
-				if (find_free_usf(pdch) >= 0) {
-					c = 32 - pdch->num_reserved(GPRS_RLCMAC_UL_TBF);
-					c = OSMO_MAX(c, 1);
-					capacity += c;
+					if (enable_debug)
+						LOGP(DRLCMAC, LOGL_DEBUG,
+						     "n_tx=%d, n_rx=%d, mask_sel=%d, tx=%02x, rx=%02x, mask=%02x, "
+						     "bad=%02x, good=%02x, ul=%02x, dl=%02x\n",
+						     tx_slot_count, rx_slot_count, mask_sel,
+						     tx_window, rx_window, rx_mask[mask_sel], rx_bad, rx_good,
+						     *ul_slots, *dl_slots);
+
+					/* Check compliance with 3GPP TS 45.002, Table 6.4.2.2.1 */
+					/* Whether to skip this round does not only depend on the bit
+					 * sets but also on mask_sel. Therefore this check must be done
+					 * before doing the test_and_set_bit shortcut. */
+					if (ms_class->type == 1) {
+						unsigned slot_sum = rx_slot_count + tx_slot_count;
+						/* Assume down+up/dynamic.
+						 * TODO: For ext-dynamic, down only, up only add more cases.
+						 */
+						if (slot_sum <= 6 && tx_slot_count < 3) {
+							if (mask_sel != MASK_TR)
+								/* Skip Tta */
+								continue;
+						} else if (slot_sum > 6 && tx_slot_count < 3) {
+							if (mask_sel != MASK_TT)
+								/* Skip Tra */
+								continue;
+						} else {
+							/* No supported row in 3GPP TS 45.002, Table 6.4.2.2.1. */
+							if (enable_debug)
+								LOGP(DRLCMAC, LOGL_DEBUG,
+								     "- Skipping DL/UL slots: (TS=0)\"%s\"(TS=7), "
+								     "combination not supported\n",
+								     set_flag_chars(set_flag_chars(set_flag_chars(
+													   slot_info,
+													   rx_bad, 'x', '.'),
+												   rx_window, 'D'),
+										    tx_window, 'U'));
+
+							continue;
+						}
+					}
+
+					/* Avoid repeated RX combination check */
+					if (test_and_set_bit(checked_rx, rx_window))
+						continue;
+
+					if (!rx_good) {
+						if (enable_debug)
+							LOGP(DRLCMAC, LOGL_DEBUG,
+							     "- Skipping DL/UL slots: (TS=0)\"%s\"(TS=7), "
+							     "no DL slots available\n",
+							     set_flag_chars(set_flag_chars(slot_info,
+											   rx_bad, 'x', '.'),
+									    tx_window, 'U'));
+
+						continue;
+					}
+
+					if (!rx_window)
+						continue;
+
+					/* Check number of common slots according to 3GPP TS 45.002, §6.4.2.2 */
+					common_slot_count = pcu_bitcount(tx_window & rx_window);
+					req_common_slots = OSMO_MIN(tx_slot_count, rx_slot_count);
+					if (ms_class->type == 1)
+						req_common_slots = OSMO_MIN(req_common_slots, 2);
+
+					if (req_common_slots != common_slot_count) {
+						if (enable_debug)
+							LOGP(DRLCMAC, LOGL_DEBUG,
+							     "- Skipping DL/UL slots: (TS=0)\"%s\"(TS=7), "
+							     "invalid number of common TS: %d (expected %d)\n",
+							     set_flag_chars(set_flag_chars(set_flag_chars(
+												   slot_info,
+												   rx_bad, 'x', '.'),
+											   rx_window, 'D'),
+									    tx_window, 'U'),
+							     common_slot_count,
+							     req_common_slots);
+
+						continue;
+					}
+
+					/* Compute capacity */
+					capacity = 0;
+
+					for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
+						int c;
+						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);
+							capacity += c;
+						}
+						/* Only consider common slots for UL */
+						if (tx_window & rx_window & (1 << ts)) {
+							if (find_free_usf(pdch) >= 0) {
+								c = 32 - pdch->num_reserved(GPRS_RLCMAC_UL_TBF);
+								c = OSMO_MAX(c, 1);
+								capacity += c;
+							}
+						}
+					}
+
+					if (enable_debug)
+						LOGP(DRLCMAC, LOGL_DEBUG,
+						     "- Considering DL/UL slots: (TS=0)\"%s\"(TS=7), capacity = %d\n",
+						     set_flag_chars(set_flag_chars(set_flag_chars(set_flag_chars(
+													  slot_info,
+													  rx_bad, 'x', '.'),
+												  rx_window, 'D'),
+										   tx_window, 'U'),
+								    rx_window & tx_window, 'C'),
+						     capacity);
+
+					if (capacity <= max_capacity)
+						continue;
+
+					max_capacity = capacity;
+					max_ul_slots = tx_window;
+					max_dl_slots = rx_window;
 				}
 			}
 		}
-
-		if (enable_debug)
-			LOGP(DRLCMAC, LOGL_DEBUG,
-			     "- Considering DL/UL slots: (TS=0)\"%s\"(TS=7), capacity = %d\n",
-			     set_flag_chars(set_flag_chars(set_flag_chars(set_flag_chars(
-										  slot_info,
-										  rx_bad, 'x', '.'),
-									  rx_window, 'D'),
-							   tx_window, 'U'),
-					    rx_window & tx_window, 'C'),
-			     capacity);
-
-		if (capacity <= max_capacity)
-			continue;
-
-		max_capacity = capacity;
-		max_ul_slots = tx_window;
-		max_dl_slots = rx_window;
-	}}}}
+	}
 
 	if (!max_ul_slots || !max_dl_slots) {
 		LOGP(DRLCMAC, LOGL_NOTICE,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I50b59b12e8d938bd96f9b29d00a649cd3e77bc5e
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