aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-07-09 13:44:18 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-07-16 10:24:37 +0200
commitc135b878cd7a155431b4f000e9c00be07e157222 (patch)
tree0ff6170fe856187fa01b893a97985e232d9c614d
parent1139ec1d0f20014bb17ea5d5cb65478b4489a8e7 (diff)
alloc: Merge find_least_busy_pdch and find_least_reserved_pdch
Both functions only differ in the computation of the value for num_tbfs. This commit merge both functions and adds a parameter containing a function for that compuation. Sponsored-by: On-Waves ehf
-rw-r--r--src/gprs_rlcmac_ts_alloc.cpp78
1 files changed, 19 insertions, 59 deletions
diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index c1b7339..b427a54 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -178,65 +178,24 @@ static int find_possible_pdchs(struct gprs_rlcmac_trx *trx,
return valid_ts_set;
}
-static int find_least_busy_pdch(struct gprs_rlcmac_trx *trx,
- enum gprs_rlcmac_tbf_direction dir,
- uint8_t mask,
- int *free_usf = 0)
+static int compute_usage_by_num_tbfs(struct gprs_rlcmac_pdch *pdch,
+ enum gprs_rlcmac_tbf_direction dir)
{
- unsigned ts;
- int min_used = INT_MAX;
- int min_ts = -1;
- int min_usf = -1;
-
- for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
- struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
- int num_tbfs;
- int usf = -1; /* must be signed */
-
- if (((1 << ts) & mask) == 0)
- continue;
-
- num_tbfs = pdch->num_tbfs(dir);
- if (num_tbfs < min_used) {
- /* We have found a candidate */
- /* Make sure that an USF is available */
- if (dir == GPRS_RLCMAC_UL_TBF) {
- usf = find_free_usf(pdch);
- if (usf < 0) {
- LOGP(DRLCMAC, LOGL_DEBUG,
- "- Skipping TS %d, because "
- "no USF available\n", ts);
- continue;
- }
- }
- if (min_ts >= 0)
- LOGP(DRLCMAC, LOGL_DEBUG,
- "- Skipping TS %d, because "
- "num TBFs %d > %d\n",
- min_ts, min_used, num_tbfs);
- min_used = num_tbfs;
- min_ts = ts;
- min_usf = usf;
- } else {
- LOGP(DRLCMAC, LOGL_DEBUG,
- "- Skipping TS %d, because "
- "num TBFs %d >= %d\n",
- ts, num_tbfs, min_used);
- }
- }
-
- if (min_ts < 0)
- return -1;
-
- if (free_usf)
- *free_usf = min_usf;
+ return pdch->num_tbfs(dir);
+}
- return min_ts;
+static int compute_usage_by_reservation(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 find_least_reserved_pdch(struct gprs_rlcmac_trx *trx,
+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_usf = 0)
{
unsigned ts;
@@ -252,9 +211,7 @@ static int find_least_reserved_pdch(struct gprs_rlcmac_trx *trx,
if (((1 << ts) & mask) == 0)
continue;
- num_tbfs =
- pdch->num_reserved(GPRS_RLCMAC_DL_TBF) +
- pdch->num_reserved(GPRS_RLCMAC_UL_TBF);
+ num_tbfs = fn(pdch, dir);
if (num_tbfs < min_used) {
/* We have found a candidate */
@@ -356,7 +313,8 @@ int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
if (!mask)
return -EINVAL;
- ts = find_least_reserved_pdch(tbf->trx, tbf->direction, mask, &usf);
+ ts = find_least_busy_pdch(tbf->trx, tbf->direction, mask,
+ compute_usage_by_reservation, &usf);
if (ts < 0) {
LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
@@ -702,7 +660,8 @@ int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
if (ts < 0)
ts = find_least_busy_pdch(tbf->trx, tbf->direction,
- dl_slots & ul_slots, NULL);
+ dl_slots & ul_slots, compute_usage_by_num_tbfs,
+ NULL);
if (ts < 0)
ul_slots = dl_slots = lsb(dl_slots & ul_slots);
else
@@ -775,7 +734,8 @@ int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
ul_slots = ul_slots & dl_slots;
ts = find_least_busy_pdch(tbf->trx, GPRS_RLCMAC_UL_TBF,
- ul_slots, &free_usf);
+ ul_slots, compute_usage_by_num_tbfs,
+ &free_usf);
if (free_usf < 0) {
LOGP(DRLCMAC, LOGL_NOTICE, "No USF available\n");