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

2017-09-14 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3914

to look at the new patch set (#4).

Simplify TS alloc: cosmetic, use proper formatting

The find_multi_slots() function has 5 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, 113 insertions(+), 115 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index a8e0df1..ea699ff 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -597,14 +597,13 @@
/* Iterate through possible numbers of TX slots */
for (num_tx = 1; num_tx <= ms_class->tx; num_tx += 1) {
uint16_t tx_valid_win = (1 << num_tx) - 1;
-
uint8_t rx_mask[MASK_TR+1];
+
if (ms_class->type == 1) {
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;
@@ -614,133 +613,132 @@
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);
-
-   /* 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 

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

2017-09-13 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3914

to look at the new patch set (#3).

Simplify TS alloc: cosmetic, use proper formatting

The find_multi_slots() function has 5 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, 142 insertions(+), 141 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 301b2eb..cfef05a 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -604,8 +604,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;
@@ -615,177 +614,179 @@
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 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;
+   /* 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);
+   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;
+   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;
+   /* 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;
+   /* Validate with both Tta/Ttb/Trb and 
Ttb/Tra/Trb 

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

2017-09-13 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3914

to look at the new patch set (#2).

Simplify TS alloc: cosmetic, use proper formatting

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, 142 insertions(+), 141 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 301b2eb..cfef05a 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -604,8 +604,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;
@@ -615,177 +614,179 @@
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 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;
+   /* 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);
+   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;
+   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;
+   /* 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;
+   /* Validate with both Tta/Ttb/Trb and 
Ttb/Tra/Trb