From 00ac4f0b46a52170f12d10afd3d2a1acb47b946f Mon Sep 17 00:00:00 2001 From: francescomani Date: Thu, 13 Feb 2025 15:01:34 +0100 Subject: [PATCH] functions to read BSR tables --- openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c | 12 ++++++++ openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h | 3 +- openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h | 11 ------- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 30 ++++++++++++------- .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c | 8 ++--- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c index c7c0b282a8..6bd57a4406 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c @@ -45,6 +45,12 @@ const uint32_t NR_SHORT_BSR_TABLE[NR_SHORT_BSR_TABLE_SIZE] = { 20516, 28581, 39818, 55474, 77284, 107669, 150000, 300000 }; +uint32_t get_short_bsr_value(int idx) +{ + AssertFatal(idx < NR_SHORT_BSR_TABLE_SIZE, "Short BSR table index %d exceeding its size\n", idx); + return NR_SHORT_BSR_TABLE[idx]; +} + //38.321 Table 6.1.3.1-2 const uint32_t NR_LONG_BSR_TABLE[NR_LONG_BSR_TABLE_SIZE] ={ 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 25, 26, @@ -65,6 +71,12 @@ const uint32_t NR_LONG_BSR_TABLE[NR_LONG_BSR_TABLE_SIZE] ={ 35910462, 38241455, 40723756, 43367187, 46182206, 49179951, 52372284, 55771835, 59392055, 63247269, 67352729, 71724679, 76380419, 81338368, 162676736, 4294967295 }; +uint32_t get_long_bsr_value(int idx) +{ + AssertFatal(idx < NR_LONG_BSR_TABLE_SIZE, "Short BSR table index %d exceeding its size\n", idx); + return NR_LONG_BSR_TABLE[idx]; +} + // start symbols for SSB types A,B,C,D,E static const uint16_t symbol_ssb_AC[8] = {2, 8, 16, 22, 30, 36, 44, 50}; static const uint16_t symbol_ssb_BD[64] = {4, 8, 16, 20, 32, 36, 44, 48, 60, 64, 72, 76, 88, 92, 100, 104, diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h index cb0d5a9611..28c3b171ae 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h @@ -55,7 +55,8 @@ typedef enum { uint32_t get_Y(const NR_SearchSpace_t *ss, int slot, rnti_t rnti); uint8_t get_BG(uint32_t A, uint16_t R); - +uint32_t get_short_bsr_value(int idx); +uint32_t get_long_bsr_value(int idx); int16_t fill_dmrs_mask(const NR_PDSCH_Config_t *pdsch_Config, int dci_format, int dmrs_TypeA_Position, diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h index cff2c3757e..e17f7784b5 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h @@ -32,16 +32,5 @@ #ifndef __NR_MAC_EXTERN_H__ #define __NR_MAC_EXTERN_H__ -#include "common/ran_context.h" -#include "nr_mac.h" - -/*#include "PHY/defs_common.h"*/ - -/* Scheduler */ -extern RAN_CONTEXT_t RC; -extern uint8_t nfapi_mode; - -extern const uint32_t NR_SHORT_BSR_TABLE[NR_SHORT_BSR_TABLE_SIZE]; -extern const uint32_t NR_LONG_BSR_TABLE[NR_LONG_BSR_TABLE_SIZE]; #endif //DEF_H diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index e3407c95b3..11711f1e36 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -1701,28 +1701,38 @@ void nr_ue_ul_scheduler(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_info) } } -static uint8_t nr_locate_BsrIndexByBufferSize(const uint32_t *table, int size, int value) +static uint8_t nr_locate_BsrIndexByBufferSize(int size, int value) { if (value == 0) { return 0; //elseif (value > 150000) return 63; } + uint32_t (*get_bsr_value)(int); + if (size == NR_SHORT_BSR_TABLE_SIZE) + get_bsr_value = &get_short_bsr_value; + else + get_bsr_value = &get_long_bsr_value; + int jl = 0; // lower bound int ju = size - 1; // upper bound - bool ascend = table[ju] >= table[jl] ? 1 : 0; // determine the order of the the table: 1 if ascending order of table, 0 otherwise + // determine the order of the the table: 1 if ascending order of table, 0 otherwise + bool ascend = (*get_bsr_value)(ju) >= (*get_bsr_value)(jl) ? 1 : 0; while (ju - jl > 1) { //If we are not yet done, int jm = (ju + jl) / 2; // compute a midpoint, - if ((value >= table[jm]) == ascend) { + if ((value >= (*get_bsr_value)(jm)) == ascend) { jl = jm; // replace the lower limit } else { ju = jm; //replace the upper limit } - LOG_T(NR_MAC, "[UE] searching BSR index %d for (BSR TABLE %d < value %d)\n", - jm, table[jm], value); + LOG_T(NR_MAC, + "[UE] searching BSR index %d for (BSR TABLE %d < value %d)\n", + jm, + (*get_bsr_value)(jm), + value); } - if (value == table[jl]) { + if (value == (*get_bsr_value)(jl)) { return jl; } else { return jl + 1; //equally ju @@ -3144,7 +3154,7 @@ static void nr_ue_get_sdu_mac_ce_post(NR_UE_MAC_INST_t *mac, mac_ce_p->bsr.type_bsr = b_short; mac_ce_p->bsr.bsr.s.LcgID = lcg_id_bsr_max; mac_ce_p->bsr.bsr.s.Buffer_size = - nr_locate_BsrIndexByBufferSize(NR_SHORT_BSR_TABLE, NR_SHORT_BSR_TABLE_SIZE, LCG_bytes[lcg_id_bsr_max]); + nr_locate_BsrIndexByBufferSize(NR_SHORT_BSR_TABLE_SIZE, LCG_bytes[lcg_id_bsr_max]); LOG_D(NR_MAC, "[UE %d] sfn %d.%d BSR Trigger=0x%x report SHORT BSR with level %d for LCGID %d\n", mac->ue_id, @@ -3159,7 +3169,7 @@ static void nr_ue_get_sdu_mac_ce_post(NR_UE_MAC_INST_t *mac, mac_ce_p->bsr.type_bsr = b_long; uint8_t *tmp = mac_ce_p->bsr.bsr.lcg_bsr; for (int lcg_id = 0; lcg_id < 8; lcg_id++) { - tmp[lcg_id] = nr_locate_BsrIndexByBufferSize(NR_LONG_BSR_TABLE, NR_LONG_BSR_TABLE_SIZE, LCG_bytes[lcg_id]); + tmp[lcg_id] = nr_locate_BsrIndexByBufferSize(NR_LONG_BSR_TABLE_SIZE, LCG_bytes[lcg_id]); } LOG_D(NR_MAC, "[UE %d] sfn %d.%d BSR Trig=0x%x report LONG BSR (level LCGID %d %d %d %d %d %d %d %d)\n", @@ -3179,7 +3189,7 @@ static void nr_ue_get_sdu_mac_ce_post(NR_UE_MAC_INST_t *mac, mac_ce_p->bsr.type_bsr = b_short_trunc; mac_ce_p->bsr.bsr.s.LcgID = lcg_id_bsr_max; mac_ce_p->bsr.bsr.s.Buffer_size = - nr_locate_BsrIndexByBufferSize(NR_SHORT_BSR_TABLE, NR_SHORT_BSR_TABLE_SIZE, LCG_bytes[lcg_id_bsr_max]); + nr_locate_BsrIndexByBufferSize(NR_SHORT_BSR_TABLE_SIZE, LCG_bytes[lcg_id_bsr_max]); } else if (padding_len >= sizeof(NR_BSR_LONG) + sizeof(NR_MAC_SUBHEADER_SHORT)) { mac_ce_p->bsr.type_bsr = b_long_trunc; // Fixme: this should be sorted by (TS 38.321, 5.4.5) @@ -3188,7 +3198,7 @@ static void nr_ue_get_sdu_mac_ce_post(NR_UE_MAC_INST_t *mac, // available for transmission) in each of these LCG(s), and in case of equal priority, in increasing order of LCGID uint8_t *tmp = mac_ce_p->bsr.bsr.lcg_bsr; for (int lcg_id = 0; lcg_id < 8; lcg_id++) { - tmp[lcg_id] = nr_locate_BsrIndexByBufferSize(NR_LONG_BSR_TABLE, NR_LONG_BSR_TABLE_SIZE, LCG_bytes[lcg_id]); + tmp[lcg_id] = nr_locate_BsrIndexByBufferSize(NR_LONG_BSR_TABLE_SIZE, LCG_bytes[lcg_id]); } } else LOG_D(NR_MAC, "Can't add any BSR, not enough padding\n"); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c index cf30983977..b9a7a1dbae 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c @@ -112,9 +112,9 @@ static int estimate_ul_buffer_short_bsr(const NR_BSR_SHORT *bsr) * differentiate them */ int rep_idx = bsr->Buffer_size; int estim_idx = overestim_bsr_index(rep_idx); - int max = sizeofArray(NR_SHORT_BSR_TABLE) - 1; + int max = NR_SHORT_BSR_TABLE_SIZE - 1; int idx = min(estim_idx, max); - int estim_size = NR_SHORT_BSR_TABLE[idx]; + int estim_size = get_short_bsr_value(idx); LOG_D(NR_MAC, "short BSR LCGID %d index %d estim index %d size %d\n", bsr->LcgID, rep_idx, estim_idx, estim_size); return estim_size; } @@ -134,7 +134,7 @@ static int estimate_ul_buffer_long_bsr(const NR_BSR_LONG *bsr) bool bsr_active[8] = {bsr->LcgID0 != 0, bsr->LcgID1 != 0, bsr->LcgID2 != 0, bsr->LcgID3 != 0, bsr->LcgID4 != 0, bsr->LcgID5 != 0, bsr->LcgID6 != 0, bsr->LcgID7 != 0}; int estim_size = 0; - int max = sizeofArray(NR_LONG_BSR_TABLE) - 1; + int max = NR_LONG_BSR_TABLE_SIZE - 1; uint8_t *payload = ((uint8_t*) bsr) + 1; int m = 0; const int total_lcgids = 8; /* see 38.321 6.1.3.1 */ @@ -144,7 +144,7 @@ static int estimate_ul_buffer_long_bsr(const NR_BSR_LONG *bsr) int rep_idx = payload[m]; int estim_idx = overestim_bsr_index(rep_idx); int idx = min(estim_idx, max); - estim_size += NR_LONG_BSR_TABLE[idx]; + estim_size += get_long_bsr_value(idx); LOG_D(NR_MAC, "LONG BSR LCGID/m %d/%d Index %d estim index %d size %d", n, m, rep_idx, estim_idx, estim_size); m++;