diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c index 253b85cfce..d0ad07721c 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c @@ -1386,7 +1386,7 @@ int64_t *get_prach_config_info(frequency_range_t freq_range, void find_aggregation_candidates(uint8_t *aggregation_level, uint8_t *nr_of_candidates, - NR_SearchSpace_t *ss, + const NR_SearchSpace_t *ss, int L) { AssertFatal(L>=1 && L<=16,"L %d not ok\n",L); *nr_of_candidates = 0; @@ -3931,7 +3931,7 @@ uint8_t get_BG(uint32_t A, uint16_t R) { return 1; } -uint32_t get_Y(NR_SearchSpace_t *ss, int slot, rnti_t rnti) { +uint32_t get_Y(const NR_SearchSpace_t *ss, int slot, rnti_t rnti) { if(ss->searchSpaceType->present == NR_SearchSpace__searchSpaceType_PR_common) return 0; diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h index e3ad29b43f..507d4469a5 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h @@ -50,7 +50,7 @@ typedef enum { typeB = 1 } mappingType_t; -uint32_t get_Y(NR_SearchSpace_t *ss, int slot, rnti_t rnti); +uint32_t get_Y(const NR_SearchSpace_t *ss, int slot, rnti_t rnti); uint8_t get_BG(uint32_t A, uint16_t R); @@ -90,7 +90,7 @@ uint16_t nr_dci_size(const NR_BWP_DownlinkCommon_t *initialDLBWP, void find_aggregation_candidates(uint8_t *aggregation_level, uint8_t *nr_of_candidates, - NR_SearchSpace_t *ss, + const NR_SearchSpace_t *ss, int maxL); void find_monitoring_periodicity_offset_common(NR_SearchSpace_t *ss, diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index e1cff2eaa1..d61adf5d3d 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -792,20 +792,13 @@ void nr_generate_Msg3_retransmission(module_id_t module_idP, int CC_id, frame_t } uint8_t aggregation_level; - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&aggregation_level, &nr_of_candidates, ss, 1<0) break; - } - AssertFatal(nr_of_candidates>0,"nr_of_candidates is 0\n"); - int CCEIndex = find_pdcch_candidate(nr_mac, - CC_id, - aggregation_level, - nr_of_candidates, - &ra->sched_pdcch, - coreset, - 0); + int CCEIndex = get_cce_index(nr_mac, + CC_id, slot, 0, + &aggregation_level, + ss, + coreset, + &ra->sched_pdcch, + true); if (CCEIndex < 0) { LOG_E(NR_MAC, "%s(): cannot find free CCE for RA RNTI 0x%04x!\n", __func__, ra->rnti); return; @@ -1188,21 +1181,13 @@ void nr_generate_Msg2(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra } uint8_t aggregation_level; - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&aggregation_level, &nr_of_candidates, ss, 1<0) break; - } - AssertFatal(nr_of_candidates>0,"nr_of_candidates is 0\n"); - - int CCEIndex = find_pdcch_candidate(nr_mac, - CC_id, - aggregation_level, - nr_of_candidates, - &ra->sched_pdcch, - coreset, - 0); + int CCEIndex = get_cce_index(nr_mac, + CC_id, slotP, 0, + &aggregation_level, + ss, + coreset, + &ra->sched_pdcch, + true); if (CCEIndex < 0) { LOG_E(NR_MAC, "%s(): cannot find free CCE for RA RNTI 0x%04x!\n", __func__, ra->rnti); @@ -1446,21 +1431,13 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra // get CCEindex, needed also for PUCCH and then later for PDCCH uint8_t aggregation_level; - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&aggregation_level, &nr_of_candidates, ss, 1<0) break; - } - AssertFatal(nr_of_candidates>0,"nr_of_candidates is 0\n"); - - int CCEIndex = find_pdcch_candidate(nr_mac, - CC_id, - aggregation_level, - nr_of_candidates, - &ra->sched_pdcch, - coreset, - 0); + int CCEIndex = get_cce_index(nr_mac, + CC_id, slotP, 0, + &aggregation_level, + ss, + coreset, + &ra->sched_pdcch, + true); if (CCEIndex < 0) { LOG_E(NR_MAC, "%s(): cannot find free CCE for RA RNTI 0x%04x!\n", __func__, ra->rnti); @@ -1522,7 +1499,7 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra const int delta_PRI=0; int r_pucch = nr_get_pucch_resource(coreset, ra->UL_BWP.pucch_Config, CCEIndex); - LOG_D(NR_MAC,"[RAPROC] Msg4 r_pucch %d (CCEIndex %d, nb_of_candidates %d, delta_PRI %d)\n", r_pucch, CCEIndex, nr_of_candidates, delta_PRI); + LOG_D(NR_MAC,"[RAPROC] Msg4 r_pucch %d (CCEIndex %d, delta_PRI %d)\n", r_pucch, CCEIndex, delta_PRI); int alloc = nr_acknack_scheduling(nr_mac, UE, frameP, slotP, r_pucch, 1); if (alloc<0) { diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c index adba522db9..af76867ef3 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c @@ -385,6 +385,7 @@ bool allocate_dl_retransmission(module_id_t module_id, NR_UE_info_t *UE, int current_harq_pid) { + int CC_id = 0; gNB_MAC_INST *nr_mac = RC.nrmac[module_id]; const NR_ServingCellConfigCommon_t *scc = nr_mac->common_channels->ServingCellConfigCommon; NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl; @@ -400,11 +401,11 @@ bool allocate_dl_retransmission(module_id_t module_id, int pm_index = (curInfo->nrOfLayers < retInfo->nrOfLayers) ? curInfo->pm_index : retInfo->pm_index; const int coresetid = sched_ctrl->coreset->controlResourceSetId; - const uint16_t bwpSize = coresetid == 0 ? RC.nrmac[module_id]->cset0_bwp_size : dl_bwp->BWPSize; + const uint16_t bwpSize = coresetid == 0 ? nr_mac->cset0_bwp_size : dl_bwp->BWPSize; int rbStart = 0; // start wrt BWPstart int rbSize = 0; - const int tda = get_dl_tda(RC.nrmac[module_id], scc, slot); + const int tda = get_dl_tda(nr_mac, scc, slot); AssertFatal(tda>=0,"Unable to find PDSCH time domain allocation in list\n"); if (tda == retInfo->time_domain_allocation && @@ -476,28 +477,13 @@ bool allocate_dl_retransmission(module_id_t module_id, } /* Find a free CCE */ - - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, UE->rnti); - uint8_t nr_of_candidates; - - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) break; - } - - int CCEIndex = find_pdcch_candidate(RC.nrmac[module_id], - /* CC_id = */ 0, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); - + int CCEIndex = get_cce_index(nr_mac, + CC_id, slot, UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); if (CCEIndex<0) { LOG_D(MAC, "%4d.%2d could not find CCE for DL DCI retransmission RNTI %04x\n", frame, slot, UE->rnti); @@ -519,7 +505,7 @@ bool allocate_dl_retransmission(module_id_t module_id, } sched_ctrl->cce_index = CCEIndex; - fill_pdcch_vrb_map(RC.nrmac[module_id], + fill_pdcch_vrb_map(nr_mac, /* CC_id = */ 0, &sched_ctrl->sched_pdcch, CCEIndex, @@ -560,6 +546,7 @@ void pf_dl(module_id_t module_id, UEsched_t UE_sched[MAX_MOBILES_PER_GNB] = {0}; int remainUEs = max_num_ue; int curUE = 0; + int CC_id = 0; /* Loop UE_info->list to check retransmission */ UE_iterator(UE_list, UE) { @@ -569,7 +556,8 @@ void pf_dl(module_id_t module_id, NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl; NR_UE_DL_BWP_t *current_BWP = &UE->current_DL_BWP; - if (sched_ctrl->ul_failure==1 && get_softmodem_params()->phy_test==0) continue; + if (sched_ctrl->ul_failure==1) + continue; const NR_mac_dir_stats_t *stats = &UE->mac_stats.dl; NR_sched_pdsch_t *sched_pdsch = &sched_ctrl->sched_pdsch; @@ -580,6 +568,9 @@ void pf_dl(module_id_t module_id, const uint32_t b = UE->mac_stats.dl.current_bytes; UE->dl_thr_ue = (1 - a) * UE->dl_thr_ue + a * b; + if (remainUEs == 0) + continue; + /* retransmission */ if (sched_pdsch->dl_harq_pid >= 0) { /* Allocate retransmission */ @@ -589,15 +580,9 @@ void pf_dl(module_id_t module_id, LOG_D(NR_MAC, "%4d.%2d retransmission can NOT be allocated\n", frame, slot); continue; } - /* reduce max_num_ue once we are sure UE can be allocated, i.e., has CCE */ remainUEs--; - // we have filled all with mandatory retransmissions - // no need to schedule new transmissions - if (remainUEs == 0) - return; - } else { /* skip this UE if there are no free HARQ processes. This can happen e.g. * if the UE disconnected in L2sim, in which case the gNB is not notified @@ -659,7 +644,7 @@ void pf_dl(module_id_t module_id, const int coresetid = sched_ctrl->coreset->controlResourceSetId; const uint16_t bwpSize = coresetid == 0 ? - RC.nrmac[module_id]->cset0_bwp_size : + mac->cset0_bwp_size : dl_bwp->BWPSize; int rbStart = 0; // start wrt BWPstart @@ -669,28 +654,13 @@ void pf_dl(module_id_t module_id, continue; } - /* Find a free CCE */ - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, iterator->UE->rnti); - uint8_t nr_of_candidates; - - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) break; - } - - int CCEIndex = find_pdcch_candidate(mac, - /* CC_id = */ 0, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); - + int CCEIndex = get_cce_index(mac, + CC_id, slot, iterator->UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); if (CCEIndex<0) { LOG_D(NR_MAC, "%4d.%2d could not find CCE for DL DCI RNTI %04x\n", frame, slot, rnti); iterator++; @@ -722,7 +692,7 @@ void pf_dl(module_id_t module_id, /* MCS has been set above */ NR_sched_pdsch_t *sched_pdsch = &sched_ctrl->sched_pdsch; - sched_pdsch->time_domain_allocation = get_dl_tda(RC.nrmac[module_id], scc, slot); + sched_pdsch->time_domain_allocation = get_dl_tda(mac, scc, slot); AssertFatal(sched_pdsch->time_domain_allocation>=0,"Unable to find PDSCH time domain allocation in list\n"); sched_pdsch->tda_info = nr_get_pdsch_tda_info(dl_bwp, sched_pdsch->time_domain_allocation); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index 6238016cb3..9f78ac06c1 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -250,27 +250,13 @@ void nr_preprocessor_phytest(module_id_t module_id, 0); sched_ctrl->num_total_bytes += sched_ctrl->rlc_status[lcid].bytes_in_buffer; - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) break; - } - AssertFatal(nr_of_candidates>0,"nr_of_candidates is 0\n"); - - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, UE->rnti); - - int CCEIndex = find_pdcch_candidate(RC.nrmac[module_id], - CC_id, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); - + int CCEIndex = get_cce_index(RC.nrmac[module_id], + CC_id, slot, UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); AssertFatal(CCEIndex >= 0, "%s(): could not find CCE for UE %04x\n", __func__, @@ -412,27 +398,13 @@ bool nr_ul_preprocessor_phytest(module_id_t module_id, frame_t frame, sub_frame_ sched_ctrl->sched_pusch.slot = sched_slot; sched_ctrl->sched_pusch.frame = sched_frame; - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) break; - } - AssertFatal(nr_of_candidates>0,"nr_of_candidates is 0\n"); - - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, UE->rnti); - - int CCEIndex = find_pdcch_candidate(nr_mac, - CC_id, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); - + int CCEIndex = get_cce_index(nr_mac, + CC_id, slot, UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); if (CCEIndex < 0) { LOG_E(MAC, "%s(): CCE list not empty, couldn't schedule PUSCH\n", __func__); return false; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c index ccdc8aca59..d85d8d85a1 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c @@ -114,10 +114,6 @@ uint8_t nr_ss_first_symb_idx_scs_240_120_set1_mux2[6] = {0,1,2,3,0,1}; // Mux pattern type 3 uint8_t nr_ss_first_symb_idx_scs_120_120_mux3[4] = {4,8,2,6}; -/// Search space max values indexed by scs -uint8_t nr_max_number_of_candidates_per_slot[4] = {44, 36, 22, 20}; -uint8_t nr_max_number_of_cces_per_slot[4] = {56, 56, 48, 32}; - // CQI TABLES (10 times the value in 214 to adequately compare with R) // Table 1 (38.214 5.2.2.1-2) uint16_t cqi_table1[16][2] = {{0,0},{2,780},{2,1200},{2,1930},{2,3080},{2,4490},{2,6020},{4,3780}, @@ -132,16 +128,6 @@ uint16_t cqi_table3[16][2] = {{0,0},{2,300},{2,500},{2,780},{2,1200},{2,1930},{2 {2,6020},{4,3780},{4,4900},{4,6160},{6,4660},{6,5670},{6,6660},{6,7720}}; -static inline uint8_t get_max_candidates(uint8_t scs) { - AssertFatal(scs<4, "Invalid PDCCH subcarrier spacing %d\n", scs); - return (nr_max_number_of_candidates_per_slot[scs]); -} - -static inline uint8_t get_max_cces(uint8_t scs) { - AssertFatal(scs<4, "Invalid PDCCH subcarrier spacing %d\n", scs); - return (nr_max_number_of_cces_per_slot[scs]); -} - uint8_t get_dl_nrOfLayers(const NR_UE_sched_ctrl_t *sched_ctrl, const nr_dci_format_t dci_format) { @@ -431,16 +417,15 @@ NR_sched_pdcch_t set_pdcch_structure(gNB_MAC_INST *gNB_mac, return pdcch; } - -int find_pdcch_candidate(gNB_MAC_INST *mac, +int find_pdcch_candidate(const gNB_MAC_INST *mac, int cc_id, int aggregation, int nr_of_candidates, - NR_sched_pdcch_t *pdcch, - NR_ControlResourceSet_t *coreset, + const NR_sched_pdcch_t *pdcch, + const NR_ControlResourceSet_t *coreset, uint32_t Y){ - uint16_t *vrb_map = mac->common_channels[cc_id].vrb_map; + const uint16_t *vrb_map = mac->common_channels[cc_id].vrb_map; const int N_ci = 0; const int N_rb = pdcch->n_rb; // nb of rbs of coreset per symbol @@ -475,6 +460,39 @@ int find_pdcch_candidate(gNB_MAC_INST *mac, return -1; } + +int get_cce_index(const gNB_MAC_INST *nrmac, + const int CC_id, + const int slot, + const rnti_t rnti, + uint8_t *aggregation_level, + const NR_SearchSpace_t *ss, + const NR_ControlResourceSet_t *coreset, + NR_sched_pdcch_t *sched_pdcch, + bool is_common) +{ + + const uint32_t Y = is_common ? 0 : get_Y(ss, slot, rnti); + uint8_t nr_of_candidates; + for (int i=0; i<5; i++) { + // for now taking the lowest value among the available aggregation levels + find_aggregation_candidates(aggregation_level, + &nr_of_candidates, + ss, + 1<0) + break; + } + int CCEIndex = find_pdcch_candidate(nrmac, + CC_id, + *aggregation_level, + nr_of_candidates, + sched_pdcch, + coreset, + Y); + return CCEIndex; +} + void fill_pdcch_vrb_map(gNB_MAC_INST *mac, int CC_id, NR_sched_pdcch_t *pdcch, diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c index 19b614b732..38da157a28 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c @@ -1382,7 +1382,6 @@ static bool allocate_ul_retransmission(gNB_MAC_INST *nrmac, int *n_rb_sched, NR_UE_info_t* UE, int harq_pid, - const NR_SIB1_t *sib1, const NR_ServingCellConfigCommon_t *scc, const int tda) { @@ -1449,24 +1448,13 @@ static bool allocate_ul_retransmission(gNB_MAC_INST *nrmac, } /* Find a free CCE */ - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, UE->rnti); - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) break; - } - int CCEIndex = find_pdcch_candidate(nrmac, - CC_id, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); - + int CCEIndex = get_cce_index(nrmac, + CC_id, slot, UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); if (CCEIndex<0) { LOG_D(NR_MAC, "%4d.%2d no free CCE for retransmission UL DCI UE %04x\n", frame, slot, UE->rnti); return false; @@ -1517,6 +1505,7 @@ static int comparator(const void *p, const void *q) { return ((UEsched_t*)p)->coef < ((UEsched_t*)q)->coef; } + void pf_ul(module_id_t module_id, frame_t frame, sub_frame_t slot, @@ -1528,22 +1517,21 @@ void pf_ul(module_id_t module_id, const int CC_id = 0; gNB_MAC_INST *nrmac = RC.nrmac[module_id]; NR_ServingCellConfigCommon_t *scc = nrmac->common_channels[CC_id].ServingCellConfigCommon; - const NR_SIB1_t *sib1 = RC.nrmac[module_id]->common_channels[0].sib1 ? RC.nrmac[module_id]->common_channels[0].sib1->message.choice.c1->choice.systemInformationBlockType1 : NULL; const int min_rb = 5; // UEs that could be scheduled UEsched_t UE_sched[MAX_MOBILES_PER_GNB] = {0}; - int remainUEs=max_num_ue; + int remainUEs = max_num_ue; int curUE=0; /* Loop UE_list to calculate throughput and coeff */ UE_iterator(UE_list, UE) { - if (UE->Msg4_ACKed != true) + NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl; + if (UE->Msg4_ACKed != true || sched_ctrl->ul_failure == 1) continue; LOG_D(NR_MAC,"pf_ul: preparing UL scheduling for UE %04x\n",UE->rnti); - NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl; NR_UE_UL_BWP_t *current_BWP = &UE->current_UL_BWP; int rbStart = 0; // wrt BWP start @@ -1557,13 +1545,16 @@ void pf_ul(module_id_t module_id, const uint32_t b = stats->current_bytes; UE->ul_thr_ue = (1 - a) * UE->ul_thr_ue + a * b; + if(remainUEs == 0) + continue; + /* Check if retransmission is necessary */ sched_pusch->ul_harq_pid = sched_ctrl->retrans_ul_harq.head; LOG_D(NR_MAC,"pf_ul: UE %04x harq_pid %d\n",UE->rnti,sched_pusch->ul_harq_pid); if (sched_pusch->ul_harq_pid >= 0) { /* Allocate retransmission*/ const int tda = get_ul_tda(nrmac, scc, sched_pusch->slot); - bool r = allocate_ul_retransmission(nrmac, frame, slot, rballoc_mask, &n_rb_sched, UE, sched_pusch->ul_harq_pid, sib1, scc, tda); + bool r = allocate_ul_retransmission(nrmac, frame, slot, rballoc_mask, &n_rb_sched, UE, sched_pusch->ul_harq_pid, scc, tda); if (!r) { LOG_D(NR_MAC, "%4d.%2d UL retransmission UE RNTI %04x can NOT be allocated\n", frame, slot, UE->rnti); continue; @@ -1572,12 +1563,6 @@ void pf_ul(module_id_t module_id, /* reduce max_num_ue once we are sure UE can be allocated, i.e., has CCE */ remainUEs--; - - // we have filled all with mandatory retransmissions - // no need to schedule new transmissions - if (remainUEs == 0) - return; - continue; } @@ -1603,44 +1588,25 @@ void pf_ul(module_id_t module_id, if (bo->harq_round_max == 1) sched_pusch->mcs = max_mcs; else - sched_pusch->mcs = get_mcs_from_bler(bo, stats, &UE->UE_sched_ctrl.ul_bler_stats, max_mcs, frame); + sched_pusch->mcs = get_mcs_from_bler(bo, stats, &sched_ctrl->ul_bler_stats, max_mcs, frame); /* Schedule UE on SR or UL inactivity and no data (otherwise, will be scheduled * based on data to transmit) */ if (B == 0 && do_sched) { /* if no data, pre-allocate 5RB */ /* Find a free CCE */ - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, UE->rnti); - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) break; - } - int CCEIndex = find_pdcch_candidate(RC.nrmac[module_id], - CC_id, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); - + int CCEIndex = get_cce_index(nrmac, + CC_id, slot, UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); if (CCEIndex<0) { LOG_D(NR_MAC, "%4d.%2d no free CCE for UL DCI UE %04x (BSR 0)\n", frame, slot, UE->rnti); continue; } - /* reduce max_num_ue once we are sure UE can be allocated, i.e., has CCE */ - remainUEs--; - - // we have filled all with mandatory retransmissions - // no need to schedule new transmissions - if (remainUEs == 0) - return; - sched_pusch->nrOfLayers = 1; sched_pusch->time_domain_allocation = get_ul_tda(nrmac, scc, sched_pusch->slot); sched_pusch->tda_info = nr_get_pusch_tda_info(current_BWP, sched_pusch->time_domain_allocation); @@ -1657,11 +1623,11 @@ void pf_ul(module_id_t module_id, if (rbStart + min_rb >= bwpSize) { LOG_W(NR_MAC, "cannot allocate continuous UL data for RNTI %04x: no resources (rbStart %d, min_rb %d, bwpSize %d\n", UE->rnti,rbStart,min_rb,bwpSize); - return; + continue; } sched_ctrl->cce_index = CCEIndex; - fill_pdcch_vrb_map(RC.nrmac[module_id], + fill_pdcch_vrb_map(nrmac, CC_id, &sched_ctrl->sched_pdcch, CCEIndex, @@ -1687,6 +1653,7 @@ void pf_ul(module_id_t module_id, for (int rb = 0; rb < sched_ctrl->sched_pusch.rbSize; rb++) rballoc_mask[rb + sched_ctrl->sched_pusch.rbStart] ^= slbitmap; + remainUEs--; continue; } @@ -1704,30 +1671,18 @@ void pf_ul(module_id_t module_id, qsort(UE_sched, sizeof(*UE_sched), sizeofArray(UE_sched), comparator); UEsched_t *iterator=UE_sched; - const int min_rbSize = 5; /* Loop UE_sched to find max coeff and allocate transmission */ - while (remainUEs> 0 && n_rb_sched >= min_rbSize && iterator->UE != NULL) { + while (remainUEs> 0 && n_rb_sched >= min_rb && iterator->UE != NULL) { NR_UE_sched_ctrl_t *sched_ctrl = &iterator->UE->UE_sched_ctrl; + int CCEIndex = get_cce_index(nrmac, + CC_id, slot, iterator->UE->rnti, + &sched_ctrl->aggregation_level, + sched_ctrl->search_space, + sched_ctrl->coreset, + &sched_ctrl->sched_pdcch, + false); - const uint32_t Y = get_Y(sched_ctrl->search_space, slot, iterator->UE->rnti); - uint8_t nr_of_candidates; - for (int i=0; i<5; i++) { - // for now taking the lowest value among the available aggregation levels - find_aggregation_candidates(&sched_ctrl->aggregation_level, - &nr_of_candidates, - sched_ctrl->search_space, - 1<0) - break; - } - int CCEIndex = find_pdcch_candidate(RC.nrmac[module_id], - CC_id, - sched_ctrl->aggregation_level, - nr_of_candidates, - &sched_ctrl->sched_pdcch, - sched_ctrl->coreset, - Y); if (CCEIndex<0) { LOG_D(NR_MAC, "%4d.%2d no free CCE for UL DCI UE %04x\n", frame, slot, iterator->UE->rnti); iterator++; @@ -1737,7 +1692,6 @@ void pf_ul(module_id_t module_id, NR_UE_UL_BWP_t *current_BWP = &iterator->UE->current_UL_BWP; - const uint16_t bwpSize = current_BWP->BWPSize; NR_sched_pusch_t *sched_pusch = &sched_ctrl->sched_pusch; sched_pusch->nrOfLayers = 1; @@ -1748,10 +1702,9 @@ void pf_ul(module_id_t module_id, &sched_pusch->tda_info, sched_pusch->nrOfLayers); - update_ul_ue_R_Qm(sched_pusch->mcs, current_BWP->mcs_table, current_BWP->pusch_Config, &sched_pusch->R, &sched_pusch->Qm); - int rbStart = 0; const uint16_t slbitmap = SL_to_bitmap(sched_pusch->tda_info.startSymbolIndex, sched_pusch->tda_info.nrOfSymbols); + const uint16_t bwpSize = current_BWP->BWPSize; while (rbStart < bwpSize && (rballoc_mask[rbStart] & slbitmap) != slbitmap) rbStart++; sched_pusch->rbStart = rbStart; @@ -1762,7 +1715,7 @@ void pf_ul(module_id_t module_id, if (rbStart + min_rb >= bwpSize) { LOG_W(NR_MAC, "cannot allocate UL data for RNTI %04x: no resources (rbStart %d, min_rb %d, bwpSize %d)\n", iterator->UE->rnti,rbStart,min_rb,bwpSize); - return; + continue; } else LOG_D(NR_MAC,"allocating UL data for RNTI %04x (rbStsart %d, min_rb %d, bwpSize %d)\n", iterator->UE->rnti,rbStart,min_rb,bwpSize); @@ -1770,24 +1723,24 @@ void pf_ul(module_id_t module_id, /* Calculate the current scheduling bytes */ const int B = cmax(sched_ctrl->estimated_ul_buffer - sched_ctrl->sched_ul_bytes, 0); /* adjust rbSize and MCS according to PHR and BPRE */ - sched_pusch->mu = scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.subcarrierSpacing; + sched_pusch->mu = scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.subcarrierSpacing; if(sched_ctrl->pcmax!=0 || sched_ctrl->ph!=0) // verify if the PHR related parameter have been initialized - nr_ue_max_mcs_min_rb(current_BWP->scs, sched_ctrl->ph, sched_pusch, current_BWP, min_rbSize, B, &max_rbSize, &sched_pusch->mcs); + nr_ue_max_mcs_min_rb(current_BWP->scs, sched_ctrl->ph, sched_pusch, current_BWP, min_rb, B, &max_rbSize, &sched_pusch->mcs); if (sched_pusch->mcs < sched_ctrl->ul_bler_stats.mcs) sched_ctrl->ul_bler_stats.mcs = sched_pusch->mcs; /* force estimated MCS down */ + update_ul_ue_R_Qm(sched_pusch->mcs, current_BWP->mcs_table, current_BWP->pusch_Config, &sched_pusch->R, &sched_pusch->Qm); uint16_t rbSize = 0; uint32_t TBS = 0; - nr_find_nb_rb(sched_pusch->Qm, sched_pusch->R, 1, // layers sched_pusch->tda_info.nrOfSymbols, sched_pusch->dmrs_info.N_PRB_DMRS * sched_pusch->dmrs_info.num_dmrs_symb, B, - min_rbSize, + min_rb, max_rbSize, &TBS, &rbSize); @@ -1801,7 +1754,7 @@ void pf_ul(module_id_t module_id, /* Mark the corresponding RBs as used */ sched_ctrl->cce_index = CCEIndex; - fill_pdcch_vrb_map(RC.nrmac[module_id], + fill_pdcch_vrb_map(nrmac, CC_id, &sched_ctrl->sched_pdcch, CCEIndex, diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 64f9882294..0d1e2fc3e0 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -269,12 +269,12 @@ NR_sched_pdcch_t set_pdcch_structure(gNB_MAC_INST *gNB_mac, NR_BWP_t *bwp, NR_Type0_PDCCH_CSS_config_t *type0_PDCCH_CSS_config); -int find_pdcch_candidate(gNB_MAC_INST *mac, +int find_pdcch_candidate(const gNB_MAC_INST *mac, int cc_id, int aggregation, int nr_of_candidates, - NR_sched_pdcch_t *pdcch, - NR_ControlResourceSet_t *coreset, + const NR_sched_pdcch_t *pdcch, + const NR_ControlResourceSet_t *coreset, uint32_t Y); void fill_pdcch_vrb_map(gNB_MAC_INST *mac, @@ -473,7 +473,15 @@ void set_sched_pucch_list(NR_UE_sched_ctrl_t *sched_ctrl, const int get_dl_tda(const gNB_MAC_INST *nrmac, const NR_ServingCellConfigCommon_t *scc, int slot); const int get_ul_tda(const gNB_MAC_INST *nrmac, const NR_ServingCellConfigCommon_t *scc, int slot); -bool find_free_CCE(sub_frame_t slot, NR_UE_info_t *UE); +int get_cce_index(const gNB_MAC_INST *nrmac, + const int CC_id, + const int slot, + const rnti_t rnti, + uint8_t *aggregation_level, + const NR_SearchSpace_t *ss, + const NR_ControlResourceSet_t *coreset, + NR_sched_pdcch_t *sched_pdcch, + bool is_common); bool nr_find_nb_rb(uint16_t Qm, uint16_t R,