[MERGED] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Simplify TS alloc: move slot assignment
..


Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M src/mslot_class.c
M src/mslot_class.h
M tests/tbf/TbfTest.err
4 files changed, 84 insertions(+), 42 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index f26b27c..4cc9539 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -812,6 +812,75 @@
return ul_slots;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -834,8 +903,6 @@
int8_t first_common_ts;
uint8_t slotcount = 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;
@@ -927,50 +994,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-02-21 Thread Harald Welte

Patch Set 17: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 17
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-02-19 Thread Max
Hello Harald Welte, Jenkins Builder, Holger Freyther,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M src/mslot_class.c
M src/mslot_class.h
M tests/tbf/TbfTest.err
4 files changed, 84 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/05/3905/16

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 0955411..f23b89f 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -828,6 +828,75 @@
return ul_slots;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -850,8 +919,6 @@
int8_t first_common_ts;
uint8_t slotcount = 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;
@@ -943,50 +1010,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL 

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-02-19 Thread Harald Welte

Patch Set 15: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 15
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-01-31 Thread Max
Hello Harald Welte, Jenkins Builder, Holger Freyther,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M src/mslot_class.c
M src/mslot_class.h
M tests/tbf/TbfTest.err
4 files changed, 84 insertions(+), 42 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 6883cb0..77c76f9 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -828,6 +828,75 @@
return ul_slots;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -850,8 +919,6 @@
int8_t first_common_ts;
uint8_t slotcount = 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;
@@ -948,50 +1015,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL 

[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-01-31 Thread Max
Hello Harald Welte, Jenkins Builder, Holger Freyther,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M tests/tbf/TbfTest.err
2 files changed, 90 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/05/3905/13

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index e290a14..655036c 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -58,6 +58,21 @@
return was_set;
 }
 
+static inline void masked_override_with(char *buf, uint8_t mask, char set_char)
+{
+   int i;
+   for (i = 0; mask; i++, mask >>= 1)
+   if (mask & 1)
+   buf[i] = set_char;
+}
+
+static void ts_format(char *buf, uint8_t dl_mask, uint8_t ul_mask)
+{
+   snprintf(buf, 9, OSMO_BIT_SPEC, OSMO_BIT_PRINT_EX(dl_mask, 'D'));
+   masked_override_with(buf, ul_mask, 'U');
+   masked_override_with(buf, ul_mask & dl_mask, 'C');
+}
+
 static inline int8_t find_free_usf(const struct gprs_rlcmac_pdch *pdch)
 {
uint8_t usf_map = 0;
@@ -724,6 +739,75 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -897,50 +981,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-01-30 Thread Harald Welte

Patch Set 10: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 10
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-01-29 Thread Max
Hello Harald Welte, Jenkins Builder, Holger Freyther,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M tests/tbf/TbfTest.err
2 files changed, 90 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/05/3905/10

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index fa3f788..7aecf09 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -50,6 +50,21 @@
return buf;
 }
 
+static inline void masked_override_with(char *buf, uint8_t mask, char set_char)
+{
+   int i;
+   for (i = 0; mask; i++, mask >>= 1)
+   if (mask & 1)
+   buf[i] = set_char;
+}
+
+static void ts_format(char *buf, uint8_t dl_mask, uint8_t ul_mask)
+{
+   snprintf(buf, 9, OSMO_BIT_SPEC, OSMO_BIT_PRINT_EX(dl_mask, 'D'));
+   masked_override_with(buf, ul_mask, 'U');
+   masked_override_with(buf, ul_mask & dl_mask, 'C');
+}
+
 static inline int8_t find_free_usf(const struct gprs_rlcmac_pdch *pdch)
 {
uint8_t usf_map = 0;
@@ -658,6 +673,75 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -841,50 +925,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->dire

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-01-27 Thread Harald Welte

Patch Set 9: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 9
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-28 Thread Max
Hello Harald Welte, Jenkins Builder, Holger Freyther,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
1 file changed, 74 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/05/3905/8

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 1bde088..99ce4c5 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -819,6 +819,75 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -988,47 +1057,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   ts_format(slot_info, dl_slots, ul_slots);
-   LOGP(DRLCMAC, LOGL_DEBUG,
-"- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n", slot_info);
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
-   "%d\n", ts);
-   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
-   }
-   } else {
-   struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
-
-   for (ts = 0; ts < 8; ts++) {
-   if (!(ul_slots & (1 << ts)))
-   continue;
-
-   OSMO_ASSERT(usf[ts] >= 0);
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
- 

[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-20 Thread Max
Hello Harald Welte, Jenkins Builder, Holger Freyther,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
1 file changed, 74 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/05/3905/7

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index eadeef4..36fc7a0 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -754,6 +754,75 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -923,46 +992,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   ts_format(slot_info, dl_slots, ul_slots);
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
-   "%d\n", ts);
-   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
-   }
-   } else {
-   struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
-
-   for (ts = 0; ts < 8; ts++) {
-   if (!(ul_slots & (1 << ts)))
-   continue;
-
-   OSMO_ASSERT(usf[ts] >= 0);
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
-   "%d\n", ts);
- 

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-18 Thread Holger Freyther

Patch Set 6: Code-Review-1

Depends on "ts_print" which doesn't print.. so I stop review here for now.

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 6
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-13 Thread Harald Welte

Patch Set 5: Code-Review+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 5
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-13 Thread Max
Hello Harald Welte, Jenkins Builder,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
1 file changed, 74 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/05/3905/5

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 9eb8464..81b19a5 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -802,6 +802,75 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_print(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -982,46 +1051,15 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   ts_print(slot_info, dl_slots, ul_slots);
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
-   }
-
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
-   "%d\n", ts);
-   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
-   }
-   } else {
-   struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
-
-   for (ts = 0; ts < 8; ts++) {
-   if (!(ul_slots & (1 << ts)))
-   continue;
-
-   OSMO_ASSERT(usf[ts] >= 0);
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
-   "%d\n", ts);
-   

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-11 Thread Harald Welte

Patch Set 2: Code-Review+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 2
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-11 Thread Max
Hello Jenkins Builder,

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

https://gerrit.osmocom.org/3905

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

Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
1 file changed, 75 insertions(+), 40 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 47a892d..c5b398f 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -811,6 +811,76 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n",
+set_flag_chars(set_flag_chars(set_flag_chars(slot_info, dl_slots, 
'D', '.'), ul_slots, 'U'),
+   ul_slots & dl_slots, 'C'));
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -993,51 +1063,16 @@
 * may be modified from now on. */
 
/* Step 4: Update MS and TBF and really allocate the resources */
-
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
-   "%d\n", ts);
-   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
-   }
-   } else {
-   struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
-
-

[PATCH] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2017-09-11 Thread Max

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

Simplify TS alloc: move slot assignment

Move into separate functionS:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
1 file changed, 75 insertions(+), 40 deletions(-)


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

diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 47a892d..c5b398f 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -811,6 +811,76 @@
return 0;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n",
+set_flag_chars(set_flag_chars(set_flag_chars(slot_info, dl_slots, 
'D', '.'), ul_slots, 'U'),
+   ul_slots & dl_slots, 'C'));
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -993,51 +1063,16 @@
 * may be modified from now on. */
 
/* Step 4: Update MS and TBF and really allocate the resources */
-
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
-   "%d\n", ts);
-   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
-   }
-   } else {
-   struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
-
-   for (ts = 0; ts < 8; ts++) {
-   if (!(ul_slots & (1 << ts)))
-