From 20b7ba75017a590294dcd4e38135293f33f66740 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 30 Jun 2015 14:34:24 +0200 Subject: [PATCH] alloc: Optimize find_free_usf According to callgrind, this function consumes 33% CPU when running the AllocTest program. This commit uses the assigned_usf() method to get the USFs allocated by a PDCH instead of traversing the TBFs. Sponsored-by: On-Waves ehf --- src/gprs_rlcmac_ts_alloc.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp index 1819b5b5..5edf9ffa 100644 --- a/src/gprs_rlcmac_ts_alloc.cpp +++ b/src/gprs_rlcmac_ts_alloc.cpp @@ -115,17 +115,12 @@ static bool test_and_set_bit(uint32_t *bits, size_t elem) static inline int8_t find_free_usf(struct gprs_rlcmac_pdch *pdch) { - struct gprs_rlcmac_ul_tbf *tbf; uint8_t usf_map = 0; - uint8_t tfi, usf; + uint8_t usf; - /* make map of used USF */ - for (tfi = 0; tfi < 32; tfi++) { - tbf = pdch->ul_tbf_by_tfi(tfi); - if (!tbf) - continue; - usf_map |= (1 << tbf->m_usf[pdch->ts_no]); - } + usf_map = pdch->assigned_usf(); + if (usf_map == (1 << 7) - 1) + return -1; /* look for USF, don't use USF=7 */ for (usf = 0; usf < 7; usf++) {