From 4fc74c17ab4ce9615ea06dfcaa8b228c2e53d773 Mon Sep 17 00:00:00 2001 From: vijay chadachan Date: Mon, 7 Oct 2024 14:19:45 +0200 Subject: [PATCH] Refactoring of is_xlsch_in_slot usage in MAC * Remove the ulsch_slot_bitmap and dlsch_slot_bitmap from nrmac * Adopt the new is_dl_slot/is_ul_slot functions in the stack to replace is_xlsch_in_slot: these functions are getting the DL and UL slots as they are set in the TDD configuration stored in tdd_slot_bitmap (frame_structure_t) * Keep is_xlsch_in_slot in openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c: this is necessary because the phy-test pre-processors are using the bitmaps dlsch_slot_bitmap and ulsch_slot_bitmap to check which DL/UL slots to use for transmission among those set in the TDD configuration Co-authored-by: Guido Casati --- .../RAN_FUNCTION/CUSTOMIZED/ran_func_mac.c | 4 +-- openair2/LAYER2/NR_MAC_gNB/config.c | 25 ------------------- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 4 --- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 16 ++++++------ .../LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c | 2 +- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 8 ++++++ .../LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c | 11 ++++---- .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c | 4 +-- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 1 - openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h | 5 ---- 10 files changed, 25 insertions(+), 55 deletions(-) diff --git a/openair2/E2AP/RAN_FUNCTION/CUSTOMIZED/ran_func_mac.c b/openair2/E2AP/RAN_FUNCTION/CUSTOMIZED/ran_func_mac.c index 3e3caac9fe..854ef57d15 100644 --- a/openair2/E2AP/RAN_FUNCTION/CUSTOMIZED/ran_func_mac.c +++ b/openair2/E2AP/RAN_FUNCTION/CUSTOMIZED/ran_func_mac.c @@ -60,11 +60,11 @@ bool read_mac_sm(void* data) rd->dl_aggr_tbs = UE->mac_stats.dl.total_bytes; rd->ul_aggr_tbs = UE->mac_stats.ul.total_bytes; - if (is_xlsch_in_slot(RC.nrmac[mod_id]->dlsch_slot_bitmap[rd->slot / 64], rd->slot)) { + if (is_dl_slot(rd->slot, &RC.nrmac[mod_id]->frame_structure)) { rd->dl_curr_tbs = UE->mac_stats.dl.current_bytes; rd->dl_sched_rb = UE->mac_stats.dl.current_rbs; } - if (is_xlsch_in_slot(RC.nrmac[mod_id]->ulsch_slot_bitmap[rd->slot / 64], rd->slot)) { + if (is_ul_slot(rd->slot, &RC.nrmac[mod_id]->frame_structure)) { rd->ul_curr_tbs = UE->mac_stats.ul.current_bytes; rd->ul_sched_rb = sched_ctrl->sched_pusch.rbSize; } diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 3dea85f77f..99aa6ed880 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -921,31 +921,6 @@ void nr_mac_config_scc(gNB_MAC_INST *nrmac, NR_ServingCellConfigCommon_t *scc, c find_SSB_and_RO_available(nrmac); - const NR_TDD_UL_DL_Pattern_t *tdd = scc->tdd_UL_DL_ConfigurationCommon ? &scc->tdd_UL_DL_ConfigurationCommon->pattern1 : NULL; - - int nr_slots_period = n; - int nr_dl_slots = n; - int nr_ulstart_slot = 0; - if (tdd) { - nr_dl_slots = tdd->nrofDownlinkSlots + (tdd->nrofDownlinkSymbols != 0); - nr_ulstart_slot = get_first_ul_slot(&nrmac->frame_structure, true); - nr_slots_period /= get_nb_periods_per_frame(tdd->dl_UL_TransmissionPeriodicity); - } else { - // if TDD configuration is not present and the band is not FDD, it means it is a dynamic TDD configuration - AssertFatal(nrmac->common_channels[0].frame_type == FDD,"Dynamic TDD not handled yet\n"); - } - - for (int slot = 0; slot < n; ++slot) { - nrmac->dlsch_slot_bitmap[slot / 64] |= (uint64_t)((slot % nr_slots_period) < nr_dl_slots) << (slot % 64); - nrmac->ulsch_slot_bitmap[slot / 64] |= (uint64_t)((slot % nr_slots_period) >= nr_ulstart_slot) << (slot % 64); - - LOG_D(NR_MAC, - "slot %d DL %d UL %d\n", - slot, - (nrmac->dlsch_slot_bitmap[slot / 64] & ((uint64_t)1 << (slot % 64))) != 0, - (nrmac->ulsch_slot_bitmap[slot / 64] & ((uint64_t)1 << (slot % 64))) != 0); - } - NR_COMMON_channels_t *cc = &nrmac->common_channels[0]; NR_SCHED_LOCK(&nrmac->sched_lock); for (int n = 0; n < NR_NB_RA_PROC_MAX; n++) { diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index e3a3b175c7..f8b8953920 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -122,10 +122,6 @@ void clear_beam_information(NR_beam_info_t *beam_info, int frame, int slot, int } } -bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot) { - return (bitmap >> (slot % 64)) & 0x01; -} - /** * @brief Returns true for: * (1) FDD diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index 753b587a9f..7954aa2443 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -278,7 +278,7 @@ static void schedule_nr_MsgA_pusch(NR_UplinkConfigCommon_t *uplinkConfigCommon, UL_tti_req->SFN = msgA_pusch_frame; UL_tti_req->Slot = msgA_pusch_slot; - AssertFatal(is_xlsch_in_slot(nr_mac->ulsch_slot_bitmap[msgA_pusch_slot / 64], msgA_pusch_slot), + AssertFatal(is_ul_slot(msgA_pusch_slot, &nr_mac->frame_structure), "Slot %d is not an Uplink slot, invalid msgA_PUSCH_TimeDomainOffset_r16 %ld\n", msgA_pusch_slot, msgA_PUSCH_Resource->msgA_PUSCH_TimeDomainOffset_r16); @@ -376,7 +376,7 @@ void schedule_nr_prach(module_id_t module_idP, frame_t frameP, sub_frame_t slotP nfapi_nr_ul_tti_request_t *UL_tti_req = &RC.nrmac[module_idP]->UL_tti_req_ahead[0][index]; nfapi_nr_config_request_scf_t *cfg = &RC.nrmac[module_idP]->config[0]; - if (is_nr_UL_slot(scc->tdd_UL_DL_ConfigurationCommon, slotP, cc->frame_type)) { + if (is_ul_slot(slotP, &RC.nrmac[module_idP]->frame_structure)) { const NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &rach_ConfigCommon->rach_ConfigGeneric; uint8_t config_index = rach_ConfigGeneric->prach_ConfigurationIndex; uint8_t N_dur, N_t_slot, start_symbol = 0, N_RA_slot; @@ -787,7 +787,7 @@ static void nr_generate_Msg3_retransmission(module_id_t module_idP, const int sched_frame = (frame + (slot + K2) / nr_slots_per_frame[mu]) % MAX_FRAME_NUMBER; const int sched_slot = (slot + K2) % nr_slots_per_frame[mu]; - if (is_xlsch_in_slot(nr_mac->ulsch_slot_bitmap[sched_slot / 64], sched_slot)) { + if (is_ul_slot(sched_slot, &nr_mac->frame_structure)) { const int n_slots_frame = nr_slots_per_frame[mu]; NR_beam_alloc_t beam_ul = beam_allocation_procedure(&nr_mac->beam_info, sched_frame, sched_slot, ra->beam_id, n_slots_frame); if (beam_ul.idx < 0) @@ -957,7 +957,6 @@ static void nr_generate_Msg3_retransmission(module_id_t module_idP, static bool get_feasible_msg3_tda(const NR_ServingCellConfigCommon_t *scc, int mu_delta, - uint64_t ulsch_slot_bitmap[3], const NR_PUSCH_TimeDomainResourceAllocationList_t *tda_list, int frame, int slot, @@ -976,7 +975,7 @@ static bool get_feasible_msg3_tda(const NR_ServingCellConfigCommon_t *scc, int abs_slot = slot + k2 + mu_delta; int temp_frame = (frame + (abs_slot / slots_per_frame)) & 1023; int temp_slot = abs_slot % slots_per_frame; // msg3 slot according to 8.3 in 38.213 - if (fs->is_tdd && !is_xlsch_in_slot(ulsch_slot_bitmap[temp_slot / 64], temp_slot)) + if (fs->is_tdd && !is_ul_slot(temp_slot, fs)) continue; const tdd_bitmap_t *tdd_slot_bitmap = fs->period_cfg.tdd_slot_bitmap; @@ -1385,7 +1384,7 @@ static void nr_generate_Msg2(module_id_t module_idP, gNB_MAC_INST *nr_mac = RC.nrmac[module_idP]; // no DL -> cannot send Msg2 - if (!is_xlsch_in_slot(nr_mac->dlsch_slot_bitmap[slotP / 64], slotP)) { + if (!is_dl_slot(slotP, &nr_mac->frame_structure)) { return; } @@ -1415,7 +1414,6 @@ static void nr_generate_Msg2(module_id_t module_idP, const NR_UE_UL_BWP_t *ul_bwp = &ra->UL_BWP; bool ret = get_feasible_msg3_tda(scc, DELTA[ul_bwp->scs], - nr_mac->ulsch_slot_bitmap, ul_bwp->tdaList_Common, frameP, slotP, @@ -1946,8 +1944,8 @@ static void nr_generate_Msg4_MsgB(module_id_t module_idP, NR_COMMON_channels_t *cc = &nr_mac->common_channels[CC_id]; NR_UE_DL_BWP_t *dl_bwp = &ra->DL_BWP; - // if it is a DL slot, if the RA is in MSG4 state - if (is_xlsch_in_slot(nr_mac->dlsch_slot_bitmap[slotP / 64], slotP)) { + // if it is a DL slot, if the RA is in MSG4 state + if (is_dl_slot(slotP, &nr_mac->frame_structure)) { NR_ServingCellConfigCommon_t *scc = cc->ServingCellConfigCommon; NR_SearchSpace_t *ss = ra->ra_ss; const char *ra_type_str = ra->ra_type == RA_2_STEP ? "MsgB" : "Msg4"; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c index 9bd1cedebd..8b6639a3e7 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c @@ -957,7 +957,7 @@ void nr_schedule_ue_spec(module_id_t module_id, AssertFatal(pthread_mutex_trylock(&gNB_mac->sched_lock) == EBUSY, "this function should be called with the scheduler mutex locked\n"); - if (!is_xlsch_in_slot(gNB_mac->dlsch_slot_bitmap[slot / 64], slot)) + if (!is_dl_slot(slot, &gNB_mac->frame_structure)) return; /* PREPROCESSOR */ diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index 62cd6ce5a1..edb28a703c 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -42,6 +42,14 @@ extern RAN_CONTEXT_t RC; //#define ENABLE_MAC_PAYLOAD_DEBUG 1 +/* This function checks whether the given Dl/UL slot is set + in the input bitmap, which is a mask indicating in which + slot to transmit (among those available in the TDD configuration) */ +static bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot) +{ + return (bitmap >> (slot % 64)) & 0x01; +} + uint32_t target_dl_mcs = 9; uint32_t target_dl_Nl = 1; uint32_t target_dl_bw = 50; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c index b927b5e676..bda5bdddf2 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c @@ -138,7 +138,6 @@ static const int diff_rsrp_ssb_csi_meas_10_1_6_1_2[16] = { static int get_pucch_index(int frame, int slot, const frame_structure_t *fs, int sched_pucch_size) { - gNB_MAC_INST *nrmac = RC.nrmac[0]; // PUCCH structures are indexed by slot in the PUCCH period determined by sched_pucch_size number of UL slots // this functions return the index to the structure for slot passed to the function const int n_ul_slots_period = get_ul_slots_per_period(fs); @@ -150,7 +149,7 @@ static int get_pucch_index(int frame, int slot, const frame_structure_t *fs, int // ((slot % nr_slots_period) - first_ul_slot_period) gives the progressive number of the slot in this TDD period int ul_period_slot = -1; for (int i = 0; i <= slot % fs->numb_slots_period; i++) { - if (is_xlsch_in_slot(nrmac->ulsch_slot_bitmap[i / 64], i)) { + if (is_ul_slot(i, fs)) { ul_period_slot++; } } @@ -173,7 +172,7 @@ void nr_schedule_pucch(gNB_MAC_INST *nrmac, frame_t frameP, sub_frame_t slotP) /* already mutex protected: held in gNB_dlsch_ulsch_scheduler() */ NR_SCHED_ENSURE_LOCKED(&nrmac->sched_lock); - if (!is_xlsch_in_slot(nrmac->ulsch_slot_bitmap[slotP / 64], slotP)) + if (!is_ul_slot(slotP, &nrmac->frame_structure)) return; UE_iterator(nrmac->UE_info.list, UE) { @@ -247,7 +246,7 @@ void nr_csi_meas_reporting(int Mod_idP,frame_t frame, sub_frame_t slot) if ((sched_frame * n_slots_frame + sched_slot - offset) % period != 0) continue; - AssertFatal(is_xlsch_in_slot(nrmac->ulsch_slot_bitmap[sched_slot / 64], sched_slot), "CSI reporting slot %d is not set for an uplink slot\n", sched_slot); + AssertFatal(is_ul_slot(sched_slot, &nrmac->frame_structure), "CSI reporting slot %d is not set for an uplink slot\n", sched_slot); LOG_D(NR_MAC, "CSI reporting in frame %d slot %d CSI report ID %ld\n", sched_frame, sched_slot, csirep->reportConfigId); const NR_PUCCH_ResourceSet_t *pucchresset = pucch_Config->resourceSetToAddModList->list.array[1]; // set with formats >1 @@ -1030,7 +1029,7 @@ int nr_acknack_scheduling(gNB_MAC_INST *mac, // check if the slot is UL if (fs->is_tdd) { int mod_slot = pucch_slot % fs->numb_slots_period; - if (!is_xlsch_in_slot(mac->ulsch_slot_bitmap[mod_slot / 64], mod_slot)) + if (!is_ul_slot(mod_slot, fs)) continue; } const int pucch_frame = (frame + ((slot + pdsch_to_harq_feedback[f] + NTN_gNB_Koffset) / n_slots_frame)) % MAX_FRAME_NUMBER; @@ -1134,7 +1133,7 @@ void nr_sr_reporting(gNB_MAC_INST *nrmac, frame_t SFN, sub_frame_t slot) /* already mutex protected: held in gNB_dlsch_ulsch_scheduler() */ NR_SCHED_ENSURE_LOCKED(&nrmac->sched_lock); - if (!is_xlsch_in_slot(nrmac->ulsch_slot_bitmap[slot / 64], slot)) + if (!is_ul_slot(slot, &nrmac->frame_structure)) return; const int CC_id = 0; UE_iterator(nrmac->UE_info.list, UE) { diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c index d4b44ebed4..31342d7523 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c @@ -2221,7 +2221,7 @@ static bool nr_ulsch_preprocessor(module_id_t module_id, frame_t frame, sub_fram const int K2 = nr_mac->radio_config.minRXTXTIME + get_NTN_Koffset(scc); const int sched_frame = (frame + (slot + K2) / slots_frame) % MAX_FRAME_NUMBER; const int sched_slot = (slot + K2) % slots_frame; - if (!is_xlsch_in_slot(nr_mac->ulsch_slot_bitmap[sched_slot / 64], sched_slot)) + if (!is_ul_slot(sched_slot, &nr_mac->frame_structure)) return false; int num_beams = nr_mac->beam_info.beam_allocation ? nr_mac->beam_info.beams_per_period : 1; @@ -2280,7 +2280,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot, n /* Uplink data ONLY can be scheduled when the current slot is downlink slot, * because we have to schedule the DCI0 first before schedule uplink data */ - if (!is_xlsch_in_slot(nr_mac->dlsch_slot_bitmap[slot / 64], slot)) { + if (!is_dl_slot(slot, &nr_mac->frame_structure)) { LOG_D(NR_MAC, "Current slot %d is NOT DL slot, cannot schedule DCI0 for UL data\n", slot); return; } diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 99bc2259ea..4cd5563200 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -352,7 +352,6 @@ int nr_write_ce_dlsch_pdu(module_id_t module_idP, int binomial(int n, int k); -bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot); bool is_ul_slot(const slot_t slot, const frame_structure_t *fs); bool is_dl_slot(const slot_t slot, const frame_structure_t *fs); bool is_mixed_slot(const slot_t slot, const frame_structure_t *fs); diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h index 1dcde6bbf2..c8604c431f 100644 --- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h +++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h @@ -905,11 +905,6 @@ typedef struct gNB_MAC_INST_s { NR_beam_info_t beam_info; - /// bitmap of DLSCH slots, can hold up to 160 slots - uint64_t dlsch_slot_bitmap[3]; - /// bitmap of ULSCH slots, can hold up to 160 slots - uint64_t ulsch_slot_bitmap[3]; - /// maximum number of slots before a UE will be scheduled ULSCH automatically uint32_t ulsch_max_frame_inactivity; /// instance of the frame structure configuration