aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-05-16 16:10:45 +0200
committerMax <msuraev@sysmocom.de>2017-05-26 07:55:52 +0000
commit9dabfa2c2b882bf4ce72c941f021f7a439de041a (patch)
tree6f060cdd5d071f9b156b5cbaafd1e167a4b3b71f /src
parent356ac618f1f4b455e411507c4be4c9909fe927bb (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/bts.cpp12
-rw-r--r--src/gprs_rlcmac_sched.cpp2
-rw-r--r--src/pcu_utils.h5
-rw-r--r--src/poll_controller.cpp22
-rw-r--r--src/sba.cpp10
-rw-r--r--src/tbf.cpp5
-rw-r--r--src/tbf_dl.cpp29
7 files changed, 47 insertions, 38 deletions
diff --git a/src/bts.cpp b/src/bts.cpp
index 61c93214..1d27284b 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -238,6 +238,11 @@ void BTS::set_current_frame_number(int fn)
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 @@ void BTS::set_current_block_frame_number(int fn, unsigned max_delay)
/* 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 @@ void BTS::snd_dl_ass(gprs_rlcmac_tbf *tbf, uint8_t poll, const char *imsi)
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 97ee53e5..a21c0236 100644
--- a/src/gprs_rlcmac_sched.cpp
+++ b/src/gprs_rlcmac_sched.cpp
@@ -41,7 +41,7 @@ static uint32_t sched_poll(BTS *bts,
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 d6644462..3a64a471 100644
--- a/src/pcu_utils.h
+++ b/src/pcu_utils.h
@@ -20,6 +20,11 @@ inline int msecs_to_frames(int msecs) {
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 54e3bc76..f8ab6c97 100644
--- a/src/poll_controller.cpp
+++ b/src/poll_controller.cpp
@@ -28,35 +28,39 @@ PollController::PollController(BTS& bts)
: 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 5d75b17e..56a75432 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 @@ int SBAController::alloc(
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 @@ gprs_rlcmac_sba *SBAController::find(const gprs_rlcmac_pdch *pdch, uint32_t fn)
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 70b8d61e..48e8289b 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -566,8 +566,7 @@ void gprs_rlcmac_tbf::stop_timer()
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 @@ int gprs_rlcmac_tbf::check_polling(uint32_t fn, uint8_t ts,
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 d871c4d7..24c6385c 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -1170,30 +1170,27 @@ bool gprs_rlcmac_dl_tbf::have_data() const
(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_drain(unsigned fn) const
+int gprs_rlcmac_dl_tbf::frames_since_last_poll(unsigned fn) const
{
- unsigned wrapped;
- if (m_last_dl_drained_fn < 0)
- return -1;
+ return frames_since_last(m_last_dl_poll_fn, fn);
+}
- wrapped = (fn + 2715648 - m_last_dl_drained_fn) % 2715648;
- if (wrapped < 2715648/2)
- return wrapped;
- else
- return wrapped - 2715648;
+int gprs_rlcmac_dl_tbf::frames_since_last_drain(unsigned fn) const
+{
+ return frames_since_last(m_last_dl_drained_fn, fn);
}
bool gprs_rlcmac_dl_tbf::keep_open(unsigned fn) const