From f8aeba44f485b08e1ccc5a4070c8912ab5e90046 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 15 Oct 2025 09:28:33 +0200 Subject: [PATCH] RLC status ind: make only one call per UE --- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 25 +++++++------- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 26 ++++++++------- .../LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c | 33 +++++++++++-------- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 4 +-- openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 18 ++++++---- openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h | 2 +- 6 files changed, 62 insertions(+), 46 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index fcc977d9e5..51e69a76eb 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -1452,23 +1452,24 @@ static void nr_update_sr(NR_UE_MAC_INST_t *mac, bool BSRsent) static void nr_update_rlc_buffers_status(NR_UE_MAC_INST_t *mac, frame_t frameP, slot_t slotP, uint8_t gNB_index) { + logical_chan_id_t ch[NR_MAX_NUM_LCID] = {0}; + int n = 0; for (int i = 0; i < mac->lc_ordered_list.count; i++) { nr_lcordered_info_t *lc_info = mac->lc_ordered_list.array[i]; if (lc_info->rb_suspended) continue; - int lcid = lc_info->lcid; + ch[n++] = lc_info->lcid; + } + + mac_rlc_status_resp_t ret[NR_MAX_NUM_LCID] = {0}; + nr_mac_rlc_status_ind(mac->ue_id, frameP, n, ch, ret); + for (int i = 0; i < n; ++i) { + const logical_chan_id_t lcid = ch[i]; + const rlc_buffer_occupancy_t b = ret[i].bytes_in_buffer; NR_LC_SCHEDULING_INFO *lc_sched_info = get_scheduling_info_from_lcid(mac, lcid); - mac_rlc_status_resp_t rlc_status = nr_mac_rlc_status_ind(mac->ue_id, frameP, lcid); - if (rlc_status.bytes_in_buffer > 0) { - LOG_D(NR_MAC, - "[UE %d] LCID %d has %d bytes to transmit at sfn %d.%d\n", - mac->ue_id, - lcid, - rlc_status.bytes_in_buffer, - frameP, - slotP); - } - lc_sched_info->LCID_buffer_remain = rlc_status.bytes_in_buffer; + if (b > 0) + LOG_D(NR_MAC, "[UE %d] LCID %d has %d bytes to transmit at sfn %d.%d\n", mac->ue_id, lcid, b, frameP, slotP); + lc_sched_info->LCID_buffer_remain = b; } } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index 1657a492fe..d2c6250070 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -1701,21 +1701,23 @@ static void nr_generate_Msg4_MsgB(module_id_t module_idP, /* get the PID of a HARQ process awaiting retrnasmission, or -1 otherwise */ int current_harq_pid = sched_ctrl->retrans_dl_harq.head; - logical_chan_id_t lcid = DL_SCH_LCID_CCCH; + logical_chan_id_t lcid = 0; if (current_harq_pid < 0) { - // Check for data on SRB0 (RRCSetup) - mac_rlc_status_resp_t srb_status = nr_mac_rlc_status_ind(UE->rnti, frameP, lcid); + const logical_chan_id_t lcid_l[2] = {DL_SCH_LCID_CCCH, DL_SCH_LCID_DCCH}; + mac_rlc_status_resp_t stat[2]; + nr_mac_rlc_status_ind(UE->rnti, frameP, 2, lcid_l, stat); - if (srb_status.bytes_in_buffer == 0) { - lcid = DL_SCH_LCID_DCCH; - // Check for data on SRB1 (RRCReestablishment, RRCReconfiguration) - srb_status = nr_mac_rlc_status_ind(UE->rnti, frameP, lcid); + if (stat[0].bytes_in_buffer > 0) { + // some data in SRB0 (likely RRCSetup) + mac_sdu_length = stat[0].bytes_in_buffer; + lcid = lcid_l[0]; + } else if (stat[1].bytes_in_buffer > 0) { + // some data in SRB1 (likely RRCReestablishmnt/RRCReconfiguration) + mac_sdu_length = stat[1].bytes_in_buffer; + lcid = lcid_l[1]; + } else { + return; // no data to forward } - - // Need to wait until data for Msg4 is ready - if (srb_status.bytes_in_buffer == 0) - return; - mac_sdu_length = srb_status.bytes_in_buffer; } const int n_slots_frame = nr_mac->frame_structure.numb_slots_frame; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c index 921003d110..075e46dd52 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c @@ -326,31 +326,38 @@ static uint32_t update_dlsch_buffer(frame_t frame, slot_t slot, NR_UE_info_t *UE sched_ctrl->num_total_bytes = 0; sched_ctrl->dl_pdus_total = 0; + logical_chan_id_t ch[NR_MAX_NUM_LCID] = {0}; + int n = 0; /* loop over all activated logical channels */ - for (int i = 0; i < seq_arr_size(&sched_ctrl->lc_config); ++i) { - const nr_lc_config_t *c = seq_arr_at(&sched_ctrl->lc_config, i); - const int lcid = c->lcid; - const uint16_t rnti = UE->rnti; - LOG_D(NR_MAC, "UE %x: LCID %d\n", rnti, lcid); - memset(&sched_ctrl->rlc_status[lcid], 0, sizeof(sched_ctrl->rlc_status[lcid])); - if (c->suspended) + FOR_EACH_SEQ_ARR(const nr_lc_config_t *, c, &sched_ctrl->lc_config ) { + logical_chan_id_t lcid = c->lcid; + if (c->suspended || (lcid == DL_SCH_LCID_DTCH && nr_timer_is_active(&sched_ctrl->transm_interrupt))) { + memset(&sched_ctrl->rlc_status[lcid], 0, sizeof(sched_ctrl->rlc_status[lcid])); continue; - if (lcid == DL_SCH_LCID_DTCH && nr_timer_is_active(&sched_ctrl->transm_interrupt)) - continue; - sched_ctrl->rlc_status[lcid] = nr_mac_rlc_status_ind(rnti, frame, lcid); + } + ch[n++] = lcid; + } - if (sched_ctrl->rlc_status[lcid].bytes_in_buffer == 0) + mac_rlc_status_resp_t ret[NR_MAX_NUM_LCID] = {0}; + nr_mac_rlc_status_ind(UE->rnti, frame, n, ch, ret); + + for (int i = 0; i < n; ++i) { + logical_chan_id_t lcid = ch[i]; + + if (ret[i].bytes_in_buffer == 0) continue; + sched_ctrl->rlc_status[lcid] = ret[i]; sched_ctrl->dl_pdus_total += sched_ctrl->rlc_status[lcid].pdus_in_buffer; sched_ctrl->num_total_bytes += sched_ctrl->rlc_status[lcid].bytes_in_buffer; LOG_D(MAC, - "%4d.%2d UE %04x LCID %d status: %d bytes, total buffer %d bytes %d PDUs\n", + "%4d.%2d UE %04x LCID %d status: %d bytes, %d PDUs, total buffer %d bytes %d PDUs\n", frame, slot, UE->rnti, lcid, - sched_ctrl->rlc_status[lcid].bytes_in_buffer, + ret[i].bytes_in_buffer, + ret[i].pdus_in_buffer, sched_ctrl->num_total_bytes, sched_ctrl->dl_pdus_total); } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index f23dfe8b30..d78ae9280f 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -144,11 +144,11 @@ void nr_preprocessor_phytest(gNB_MAC_INST *mac, post_process_pdsch_t *pp_pdsch) sched_ctrl->num_total_bytes = 0; DevAssert(seq_arr_size(&sched_ctrl->lc_config) == 1); const nr_lc_config_t *c = seq_arr_at(&sched_ctrl->lc_config, 0); - const int lcid = c->lcid; + const logical_chan_id_t lcid = c->lcid; const uint16_t rnti = UE->rnti; /* update sched_ctrl->num_total_bytes so that postprocessor schedules data, * if available */ - sched_ctrl->rlc_status[lcid] = nr_mac_rlc_status_ind(rnti, frame, lcid); + nr_mac_rlc_status_ind(rnti, frame, 1, &lcid, &sched_ctrl->rlc_status[lcid]); sched_ctrl->num_total_bytes += sched_ctrl->rlc_status[lcid].bytes_in_buffer; int CCEIndex = get_cce_index(mac, diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index 126f9fb51c..4597b96478 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -223,12 +223,10 @@ tbs_size_t nr_mac_rlc_data_req(const module_id_t module_idP, return ret; } -mac_rlc_status_resp_t nr_mac_rlc_status_ind(const uint16_t ue_id, const frame_t frame, const logical_chan_id_t channel_idP) +static mac_rlc_status_resp_t _nr_rlc_status_ind(nr_rlc_ue_t *ue, frame_t frame, logical_chan_id_t channel_idP) { mac_rlc_status_resp_t ret; - nr_rlc_manager_lock(nr_rlc_ue_manager); - nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, ue_id); nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, channel_idP); if (rb != NULL) { @@ -243,12 +241,10 @@ mac_rlc_status_resp_t nr_mac_rlc_status_ind(const uint16_t ue_id, const frame_t ret.bytes_in_buffer = buf_stat.status_size + buf_stat.retx_size + buf_stat.tx_size; } else { if (!(frame % 128) || channel_idP == 0) //to suppress this warning message - LOG_W(RLC, "Radio Bearer (channel ID %d) is NULL for UE %d\n", channel_idP, ue_id); + LOG_W(RLC, "Radio Bearer (channel ID %d) is NULL for UE %d\n", channel_idP, ue->ue_id); ret.bytes_in_buffer = 0; } - nr_rlc_manager_unlock(nr_rlc_ue_manager); - ret.pdus_in_buffer = 0; /* TODO: creation time may be important (unit: frame, as it seems) */ ret.head_sdu_creation_time = 0; @@ -257,6 +253,16 @@ mac_rlc_status_resp_t nr_mac_rlc_status_ind(const uint16_t ue_id, const frame_t return ret; } +void nr_mac_rlc_status_ind(uint16_t ue_id, frame_t frame, int n_ch, const logical_chan_id_t *ch, mac_rlc_status_resp_t *ret) +{ + nr_rlc_manager_lock(nr_rlc_ue_manager); + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, ue_id); + for (int i = 0; i < n_ch; ++i) { + ret[i] = _nr_rlc_status_ind(ue, frame, ch[i]); + } + nr_rlc_manager_unlock(nr_rlc_ue_manager); +} + rlc_op_status_t nr_rlc_data_req(const protocol_ctxt_t *const ctxt_pP, const srb_flag_t srb_flagP, const rb_id_t rb_idP, diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h index 454a59b928..c426aa8d6e 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h @@ -59,7 +59,7 @@ rlc_op_status_t nr_rlc_data_req(const protocol_ctxt_t *const ctxt_pP, const mui_t muiP, sdu_size_t sdu_sizeP, uint8_t *sdu_pP); -mac_rlc_status_resp_t nr_mac_rlc_status_ind(const uint16_t ue_id, const frame_t frame, const logical_chan_id_t channel_idP); +void nr_mac_rlc_status_ind(uint16_t ue_id, frame_t frame, int n_ch, const logical_chan_id_t *ch, mac_rlc_status_resp_t *ret); void nr_rlc_add_srb(int ue_id, int srb_id, const NR_RLC_BearerConfig_t *rlc_BearerConfig); void nr_rlc_add_drb(int ue_id, int drb_id, const NR_RLC_BearerConfig_t *rlc_BearerConfig);