From ef65d3ddb4639661cad89295ee6587930ba9f0ce Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 18 Nov 2020 15:13:57 +0100 Subject: [PATCH] hodec 2: prefer moving TCH/H from half-used dyn TS Change-Id: I427dc9faa3790c24119127ae227d8cc802dd50e6 --- src/osmo-bsc/handover_decision_2.c | 24 +++++++++++++++++++++--- tests/handover/handover_test.c | 5 ++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/osmo-bsc/handover_decision_2.c b/src/osmo-bsc/handover_decision_2.c index 4e54368ca..9fab1fcde 100644 --- a/src/osmo-bsc/handover_decision_2.c +++ b/src/osmo-bsc/handover_decision_2.c @@ -1368,6 +1368,17 @@ static bool lchan_is_on_dynamic_ts(struct gsm_lchan *lchan) || lchan->ts->pchan_on_init == GSM_PCHAN_TCH_F_PDCH; } +static unsigned int ts_usage_count(struct gsm_bts_trx_ts *ts) +{ + struct gsm_lchan *lchan; + unsigned int count = 0; + ts_for_each_lchan(lchan, ts) { + if (lchan_state_is(lchan, LCHAN_ST_ESTABLISHED)) + count++; + } + return count; +} + /* Given two candidates, pick the one that should rather be moved during handover. * Return the better candidate in out-parameters best_cand and best_avg_db. */ @@ -1384,10 +1395,17 @@ static void pick_better_lchan_to_move(bool want_highest_db, goto return_other; /* The two lchans have identical ratings, prefer picking a dynamic timeslot: free PDCH and allow more timeslot - * type flexibility for further congestion resolution. If both are dynamic, it does not matter which one is - * picked. */ - if (lchan_is_on_dynamic_ts(other_cand->lchan)) + * type flexibility for further congestion resolution. */ + if (lchan_is_on_dynamic_ts(other_cand->lchan)) { + /* If both are dynamic, prefer one that completely (or to a higher degree) frees its timeslot. */ + if (lchan_is_on_dynamic_ts((*best_cand_p)->lchan) + && ts_usage_count((*best_cand_p)->lchan->ts) < ts_usage_count(other_cand->lchan->ts)) + return; + /* If both equally satisfy these preferences, it does not matter which one is picked. + * Give slight preference to moving later dyn TS, so that a free dyn TS may group with following static + * PDCH, though this depends on how the user configured the TS -- not harmful to do so anyway. */ goto return_other; + } /* keep the same candidate. */ return; diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c index 62c01f06e..28d87db79 100644 --- a/tests/handover/handover_test.c +++ b/tests/handover/handover_test.c @@ -1765,10 +1765,9 @@ static char *test_case_32[] = { "congestion-check", "expect-chan", "0", "1", "ack-chan", - /* Not so good: should move the half-used TCH/H instead of "halving" another dyn TS */ - "expect-ho", "0", "4", + "expect-ho", "0", "3", "ho-complete", - "expect-ts-use", "0", "0", "*", "TCH/F", "TCH/HH", "TCH/H-", "TCH/H-", "PDCH", "-", "-", + "expect-ts-use", "0", "0", "*", "TCH/F", "TCH/HH", "PDCH", "TCH/HH", "PDCH", "-", "-", NULL };