Hello Jenkins Builder, I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/2654 to look at the new patch set (#2). Cleanup FN scheduling * replace magic number with defined constant * move copy-pasted code to inline functions * remove unused code Change-Id: I6fee0714453d0c3c3f3f875f88daea2d9c477331 Related: OS#1524 --- M src/bts.cpp M src/gprs_rlcmac_sched.cpp M src/pcu_utils.h M src/poll_controller.cpp M src/sba.cpp M src/tbf.cpp M src/tbf_dl.cpp M tests/tbf/TbfTest.cpp 8 files changed, 48 insertions(+), 53 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/54/2654/2 diff --git a/src/bts.cpp b/src/bts.cpp index 61c9321..1d27284 100644 --- a/src/bts.cpp +++ b/src/bts.cpp @@ -238,6 +238,11 @@ m_pollController.expireTimedout(m_cur_fn, max_delay); } +static inline int delta_fn(int fn, int to) +{ + return (fn + GSM_MAX_FN * 3 / 2 - to) % GSM_MAX_FN - GSM_MAX_FN/2; +} + void BTS::set_current_block_frame_number(int fn, unsigned max_delay) { int delay = 0; @@ -248,15 +253,14 @@ /* frame numbers in the received blocks are assumed to be strongly * monotonic. */ if (m_cur_blk_fn >= 0) { - int delta = (fn + 2715648 * 3 / 2 - m_cur_blk_fn) % 2715648 - 2715648/2; + int delta = delta_fn(fn, m_cur_blk_fn); if (delta <= 0) return; } /* Check block delay vs. the current frame number */ if (current_frame_number() != 0) - delay = (fn + 2715648 * 3 / 2 - current_frame_number()) % 2715648 - - 2715648/2; + delay = delta_fn(fn, current_frame_number()); if (delay <= -late_block_delay_thresh) { LOGP(DRLCMAC, LOGL_NOTICE, "Late RLC block, FN delta: %d FN: %d curFN: %d\n", @@ -814,7 +818,7 @@ tbf->trx->trx_no, tbf->trx->arfcn, ts, tbf->ta(), poll ? tbf->poll_fn : -1); plen = Encoding::write_immediate_assignment(tbf, immediate_assignment, 1, 125, - (tbf->pdch[ts]->last_rts_fn + 21216) % 2715648, tbf->ta(), + (tbf->pdch[ts]->last_rts_fn + 21216) % GSM_MAX_FN, tbf->ta(), tbf->trx->arfcn, ts, tbf->tsc(), 7, poll, tbf->poll_fn, m_bts.alpha, m_bts.gamma, -1); if (plen >= 0) { diff --git a/src/gprs_rlcmac_sched.cpp b/src/gprs_rlcmac_sched.cpp index 97ee53e..a21c023 100644 --- a/src/gprs_rlcmac_sched.cpp +++ b/src/gprs_rlcmac_sched.cpp @@ -41,7 +41,7 @@ poll_fn = fn + 4; if ((block_nr % 3) == 2) poll_fn ++; - poll_fn = poll_fn % 2715648; + poll_fn = poll_fn % GSM_MAX_FN; llist_for_each(pos, &bts->ul_tbfs()) { ul_tbf = as_ul_tbf(pos->entry()); OSMO_ASSERT(ul_tbf); diff --git a/src/pcu_utils.h b/src/pcu_utils.h index d664446..3a64a47 100644 --- a/src/pcu_utils.h +++ b/src/pcu_utils.h @@ -20,6 +20,11 @@ return (msecs * (1024 * 1000 / 4615)) / 1024; } +inline uint32_t next_fn(uint32_t fn, uint32_t offset) +{ + return (fn + offset) % GSM_MAX_FN; +} + inline void csecs_to_timeval(unsigned csecs, struct timeval *tv) { tv->tv_sec = csecs / 100; tv->tv_usec = (csecs % 100) * 10000; diff --git a/src/poll_controller.cpp b/src/poll_controller.cpp index 54e3bc7..f8ab6c9 100644 --- a/src/poll_controller.cpp +++ b/src/poll_controller.cpp @@ -28,35 +28,39 @@ : m_bts(bts) {} +static inline bool elapsed_fn_check(unsigned max_delay, int frame_number, uint32_t from) +{ + uint32_t elapsed = (frame_number + GSM_MAX_FN - from) % GSM_MAX_FN; + + if (elapsed > max_delay && elapsed < 2715400) + return true; + + return false; +} + void PollController::expireTimedout(int frame_number, unsigned max_delay) { struct gprs_rlcmac_dl_tbf *dl_tbf; struct gprs_rlcmac_ul_tbf *ul_tbf; struct gprs_rlcmac_sba *sba, *sba2; LListHead<gprs_rlcmac_tbf> *pos; - uint32_t elapsed; llist_for_each(pos, &m_bts.ul_tbfs()) { ul_tbf = as_ul_tbf(pos->entry()); if (ul_tbf->poll_state == GPRS_RLCMAC_POLL_SCHED) { - elapsed = (frame_number + 2715648 - ul_tbf->poll_fn) - % 2715648; - if (elapsed > max_delay && elapsed < 2715400) + if (elapsed_fn_check(max_delay, frame_number, ul_tbf->poll_fn)) ul_tbf->poll_timeout(); } } llist_for_each(pos, &m_bts.dl_tbfs()) { dl_tbf = as_dl_tbf(pos->entry()); if (dl_tbf->poll_state == GPRS_RLCMAC_POLL_SCHED) { - elapsed = (frame_number + 2715648 - dl_tbf->poll_fn) - % 2715648; - if (elapsed > max_delay && elapsed < 2715400) + if (elapsed_fn_check(max_delay, frame_number, dl_tbf->poll_fn)) dl_tbf->poll_timeout(); } } llist_for_each_entry_safe(sba, sba2, &m_bts.sba()->m_sbas, list) { - elapsed = (frame_number + 2715648 - sba->fn) % 2715648; - if (elapsed > max_delay && elapsed < 2715400) { + if (elapsed_fn_check(max_delay, frame_number, sba->fn)) { /* sba will be freed here */ m_bts.sba()->timeout(sba); } diff --git a/src/sba.cpp b/src/sba.cpp index 5d75b17..56a7543 100644 --- a/src/sba.cpp +++ b/src/sba.cpp @@ -23,6 +23,7 @@ #include <gprs_rlcmac.h> #include <gprs_debug.h> #include <bts.h> +#include <pcu_utils.h> extern "C" { #include <osmocom/core/talloc.h> @@ -75,7 +76,7 @@ return -EINVAL; } - fn = (pdch->last_rts_fn + AGCH_START_OFFSET) % 2715648; + fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET); sba->trx_no = trx; sba->ts_no = ts; @@ -110,14 +111,13 @@ uint32_t SBAController::sched(uint8_t trx, uint8_t ts, uint32_t fn, uint8_t block_nr) { - uint32_t sba_fn; + uint32_t sba_fn = fn + 4; struct gprs_rlcmac_sba *sba; /* check special TBF for events */ - sba_fn = fn + 4; if ((block_nr % 3) == 2) - sba_fn ++; - sba_fn = sba_fn % 2715648; + sba_fn++; + sba_fn = sba_fn % GSM_MAX_FN; sba = find(trx, ts, sba_fn); if (sba) return sba_fn; diff --git a/src/tbf.cpp b/src/tbf.cpp index 70b8d61..48e8289 100644 --- a/src/tbf.cpp +++ b/src/tbf.cpp @@ -566,8 +566,7 @@ int gprs_rlcmac_tbf::check_polling(uint32_t fn, uint8_t ts, uint32_t *poll_fn_, unsigned int *rrbp_) { - uint32_t fn_offs = 13; - uint32_t new_poll_fn = (fn + fn_offs) % 2715648; + uint32_t new_poll_fn = next_fn(fn, 13); if (!is_control_ts(ts)) { LOGP(DRLCMAC, LOGL_DEBUG, "Polling cannot be " @@ -581,7 +580,7 @@ name()); return -EBUSY; } - if (bts->sba()->find(trx->trx_no, ts, (fn + 13) % 2715648)) { + if (bts->sba()->find(trx->trx_no, ts, next_fn(fn, 13))) { LOGP(DRLCMAC, LOGL_DEBUG, "%s: Polling is already scheduled " "for single block allocation at FN %d TS %d ...\n", name(), new_poll_fn, ts); diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp index d871c4d..24c6385 100644 --- a/src/tbf_dl.cpp +++ b/src/tbf_dl.cpp @@ -1170,30 +1170,27 @@ (llc_queue_size() > 0); } -int gprs_rlcmac_dl_tbf::frames_since_last_poll(unsigned fn) const +static inline int frames_since_last(int32_t last, unsigned fn) { - unsigned wrapped; - if (m_last_dl_poll_fn < 0) + unsigned wrapped = (fn + GSM_MAX_FN - last) % GSM_MAX_FN; + + if (last < 0) return -1; - wrapped = (fn + 2715648 - m_last_dl_poll_fn) % 2715648; - if (wrapped < 2715648/2) + if (wrapped < GSM_MAX_FN/2) return wrapped; - else - return wrapped - 2715648; + + return wrapped - GSM_MAX_FN; +} + +int gprs_rlcmac_dl_tbf::frames_since_last_poll(unsigned fn) const +{ + return frames_since_last(m_last_dl_poll_fn, fn); } int gprs_rlcmac_dl_tbf::frames_since_last_drain(unsigned fn) const { - unsigned wrapped; - if (m_last_dl_drained_fn < 0) - return -1; - - wrapped = (fn + 2715648 - m_last_dl_drained_fn) % 2715648; - if (wrapped < 2715648/2) - return wrapped; - else - return wrapped - 2715648; + return frames_since_last(m_last_dl_drained_fn, fn); } bool gprs_rlcmac_dl_tbf::keep_open(unsigned fn) const diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp index 496437d..0db7fde 100644 --- a/tests/tbf/TbfTest.cpp +++ b/tests/tbf/TbfTest.cpp @@ -56,20 +56,6 @@ OSMO_ASSERT(tbf->T != 0); } -/* -static unsigned inc_fn(fn) -{ - unsigned next_fn; - - next_fn = fn + 4; - if ((block_nr % 3) == 2) - next_fn ++; - next_fn = next_fn % 2715648; - - return next_fn; -} -*/ - static void test_tbf_base() { @@ -209,7 +195,7 @@ unsigned bn = fn2bn(fn) + blocks; fn = fn - (fn % 52); fn += bn * 4 + bn / 3; - return fn % 2715648; + return fn % GSM_MAX_FN; } static void request_dl_rlc_block(struct gprs_rlcmac_bts *bts, -- To view, visit https://gerrit.osmocom.org/2654 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: I6fee0714453d0c3c3f3f875f88daea2d9c477331 Gerrit-PatchSet: 2 Gerrit-Project: osmo-pcu Gerrit-Branch: master Gerrit-Owner: Max <msur...@sysmocom.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Max <msur...@sysmocom.de>