From 8a091a0b844ca6a6f5638b865bb7eadf5c26fa97 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Thu, 21 Aug 2025 10:31:20 +0200 Subject: [PATCH 1/2] DLSCH sched: only sort relevant part of list This reduces the amount of elements to compare. See also: 7ee8e8eaba7f ("Fix bug: only sort relevant part of list") --- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c index 44d4affb08..f831e8af2e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c @@ -613,7 +613,7 @@ static void pf_dl(module_id_t module_id, int remainUEs[num_beams]; for (int i = 0; i < num_beams; i++) remainUEs[i] = max_num_ue; - int curUE = 0; + int numUE = 0; int CC_id = 0; int slots_per_frame = mac->frame_structure.numb_slots_frame; @@ -704,13 +704,13 @@ static void pf_dl(module_id_t module_id, tbs, coeff_ue); /* Create UE_sched list for UEs eligible for new transmission*/ - UE_sched[curUE].coef=coeff_ue; - UE_sched[curUE].UE=UE; - curUE++; + UE_sched[numUE].coef = coeff_ue; + UE_sched[numUE].UE = UE; + numUE++; } } - qsort(UE_sched, sizeofArray(UE_sched), sizeof(UEsched_t), comparator); + qsort(UE_sched, numUE, sizeof(UEsched_t), comparator); UEsched_t *iterator = UE_sched; const int min_rbSize = 5; From a30bee2fab87f02656882fd01af38fbf4858f88f Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 13 Aug 2025 13:51:35 +0200 Subject: [PATCH 2/2] DLSCH sched: Fix coefficients for UE list ordering Update the comparator() to properly sort UEs based on their coefficient by appliey a consistent logic of -1/0/1 (see man qsort) for smaller/equal/larger. The previous logic was only sorting based on 0/1 (equal/larger), which would result in some UEs with a high coefficient not necessarily advancing to the start of the list, which could reduce the likelihood of them being scheduled when they actually should (in other words, this should improve fairness). See also: 62e4025bc846 ("Integrate inactivity scheduling into main allocation loop") --- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c index f831e8af2e..c88ad3bd96 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c @@ -594,8 +594,15 @@ typedef struct UEsched_s { NR_UE_info_t * UE; } UEsched_t; -static int comparator(const void *p, const void *q) { - return ((UEsched_t*)p)->coef < ((UEsched_t*)q)->coef; +static int comparator(const void *p, const void *q) +{ + const UEsched_t *pp = p; + const UEsched_t *qq = q; + if (pp->coef < qq->coef) + return 1; + else if (pp->coef > qq->coef) + return -1; + return 0; } static void pf_dl(module_id_t module_id,