From bcfe3a6733452f5a2c739fa0e6ef17cbb96de864 Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Fri, 14 Jun 2024 16:34:27 +0200 Subject: [PATCH] Initialize number of NR UEs equal to --num-ues parameter --- executables/nr-ue.c | 29 +++++------ executables/nr-uesoftmodem.c | 95 +++++++++++++++++++----------------- executables/nr-uesoftmodem.h | 2 +- 3 files changed, 64 insertions(+), 62 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index e5e3ef3569..8a73bdd311 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -146,7 +146,7 @@ void init_nr_ue_vars(PHY_VARS_NR_UE *ue, int nb_connected_gNB = 1; ue->Mod_id = UE_id; - ue->if_inst = nr_ue_if_module_init(0); + ue->if_inst = nr_ue_if_module_init(UE_id); ue->dci_thres = 0; ue->target_Nid_cell = -1; @@ -998,27 +998,22 @@ void init_NR_UE(int nb_inst, char *uecap_file, char *reconfig_file, char *rbconf mac->if_module = nr_ue_if_module_init(i); AssertFatal(mac->if_module, "can not initialize IF module\n"); if (!get_softmodem_params()->sa || !get_softmodem_params()->sl_mode) { - init_nsa_message(rrc_inst, reconfig_file, rbconfig_file); - nr_rlc_activate_srb0(mac_inst->crnti, NULL, send_srb0_rrc); + init_nsa_message(&rrc_inst[i], reconfig_file, rbconfig_file); + nr_rlc_activate_srb0(mac_inst[i].crnti, NULL, send_srb0_rrc); } //TODO: Move this call to RRC start_sidelink((&rrc_inst[i])->ue_id); } } -void init_NR_UE_threads(int nb_inst) { - int inst; - - pthread_t threads[nb_inst]; - - for (inst=0; inst < nb_inst; inst++) { - PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - - LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); - threadCreate(&threads[inst], UE_thread, (void *)UE, "UEthread", -1, OAI_PRIORITY_RT_MAX); - if (!IS_SOFTMODEM_NOSTATS_BIT) { - pthread_t stat_pthread; - threadCreate(&stat_pthread, nrL1_UE_stats_thread, UE, "L1_UE_stats", -1, OAI_PRIORITY_RT_LOW); - } +void init_NR_UE_threads(PHY_VARS_NR_UE *UE) { + pthread_t thread; + char thread_name[16]; + sprintf(thread_name, "UEthread_%d", UE->Mod_id); + threadCreate(&thread, UE_thread, (void *)UE, thread_name, -1, OAI_PRIORITY_RT_MAX); + if (!IS_SOFTMODEM_NOSTATS_BIT) { + pthread_t stat_pthread; + sprintf(thread_name, "L1_UE_stats_%d", UE->Mod_id); + threadCreate(&stat_pthread, nrL1_UE_stats_thread, UE, thread_name, -1, OAI_PRIORITY_RT_LOW); } } diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index befc03a2da..b3944548fd 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -502,11 +502,13 @@ int main(int argc, char **argv) // strdup to put the sring in the core file for post mortem identification LOG_I(HW, "Version: %s\n", strdup(PACKAGE_VERSION)); - PHY_vars_UE_g = malloc(sizeof(*PHY_vars_UE_g)); - PHY_vars_UE_g[0] = malloc(sizeof(*PHY_vars_UE_g[0]) * MAX_NUM_CCs); - for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { - PHY_vars_UE_g[0][CC_id] = malloc(sizeof(*PHY_vars_UE_g[0][CC_id])); - memset(PHY_vars_UE_g[0][CC_id], 0, sizeof(*PHY_vars_UE_g[0][CC_id])); + PHY_vars_UE_g = malloc(sizeof(*PHY_vars_UE_g) * NB_UE_INST); + for (int inst = 0; inst < NB_UE_INST; inst++) { + PHY_vars_UE_g[inst] = malloc(sizeof(*PHY_vars_UE_g[inst]) * MAX_NUM_CCs); + for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { + PHY_vars_UE_g[inst][CC_id] = malloc(sizeof(*PHY_vars_UE_g[inst][CC_id])); + memset(PHY_vars_UE_g[inst][CC_id], 0, sizeof(*PHY_vars_UE_g[inst][CC_id])); + } } int mode_offset = get_softmodem_params()->nsa ? NUMBER_OF_UE_MAX : 1; @@ -536,49 +538,51 @@ int main(int argc, char **argv) start_oai_nrue_threads(); if (!get_softmodem_params()->emulate_l1) { - PHY_VARS_NR_UE *UE[MAX_NUM_CCs]; - for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { - UE[CC_id] = PHY_vars_UE_g[0][CC_id]; + for (int inst = 0; inst < NB_UE_INST; inst++) { + PHY_VARS_NR_UE *UE[MAX_NUM_CCs]; + for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { + UE[CC_id] = PHY_vars_UE_g[inst][CC_id]; - set_options(CC_id, UE[CC_id]); - NR_UE_MAC_INST_t *mac = get_mac_inst(0); + set_options(CC_id, UE[CC_id]); + NR_UE_MAC_INST_t *mac = get_mac_inst(inst); - if (get_softmodem_params()->sa || get_softmodem_params()->sl_mode) { // set frame config to initial values from command line - // and assume that the SSB is centered on the grid - uint16_t nr_band = get_softmodem_params()->band; - mac->nr_band = nr_band; - mac->ssb_start_subcarrier = UE[CC_id]->frame_parms.ssb_start_subcarrier; - nr_init_frame_parms_ue_sa(&UE[CC_id]->frame_parms, - downlink_frequency[CC_id][0], - uplink_frequency_offset[CC_id][0], - get_softmodem_params()->numerology, - nr_band); - } else { - DevAssert(mac->if_module != NULL && mac->if_module->phy_config_request != NULL); - mac->if_module->phy_config_request(&mac->phy_config); - mac->phy_config_request_sent = true; - fapi_nr_config_request_t *nrUE_config = &UE[CC_id]->nrUE_config; + if (get_softmodem_params()->sa || get_softmodem_params()->sl_mode) { // set frame config to initial values from command line + // and assume that the SSB is centered on the grid + uint16_t nr_band = get_softmodem_params()->band; + mac->nr_band = nr_band; + mac->ssb_start_subcarrier = UE[CC_id]->frame_parms.ssb_start_subcarrier; + nr_init_frame_parms_ue_sa(&UE[CC_id]->frame_parms, + downlink_frequency[CC_id][0], + uplink_frequency_offset[CC_id][0], + get_softmodem_params()->numerology, + nr_band); + } else { + DevAssert(mac->if_module != NULL && mac->if_module->phy_config_request != NULL); + mac->if_module->phy_config_request(&mac->phy_config); + mac->phy_config_request_sent = true; + fapi_nr_config_request_t *nrUE_config = &UE[CC_id]->nrUE_config; - nr_init_frame_parms_ue(&UE[CC_id]->frame_parms, nrUE_config, mac->nr_band); - } + nr_init_frame_parms_ue(&UE[CC_id]->frame_parms, nrUE_config, mac->nr_band); + } - UE[CC_id]->sl_mode = get_softmodem_params()->sl_mode; - init_nr_ue_vars(UE[CC_id], 0, abstraction_flag); + UE[CC_id]->sl_mode = get_softmodem_params()->sl_mode; + init_nr_ue_vars(UE[CC_id], inst, abstraction_flag); - if (UE[CC_id]->sl_mode) { - AssertFatal(UE[CC_id]->sl_mode == 2, "Only Sidelink mode 2 supported. Mode 1 not yet supported\n"); - DevAssert(mac->if_module != NULL && mac->if_module->sl_phy_config_request != NULL); - nr_sl_phy_config_t *phycfg = &mac->SL_MAC_PARAMS->sl_phy_config; - phycfg->sl_config_req.sl_carrier_config.sl_num_rx_ant = get_nrUE_params()->nb_antennas_rx; - phycfg->sl_config_req.sl_carrier_config.sl_num_tx_ant = get_nrUE_params()->nb_antennas_tx; - mac->if_module->sl_phy_config_request(phycfg); - mac->phy_config_request_sent = true; - sl_nr_ue_phy_params_t *sl_phy = &UE[CC_id]->SL_UE_PHY_PARAMS; - nr_init_frame_parms_ue_sl(&sl_phy->sl_frame_params, - &sl_phy->sl_config, - get_softmodem_params()->threequarter_fs, - get_nrUE_params()->ofdm_offset_divisor); - sl_ue_phy_init(UE[CC_id]); + if (UE[CC_id]->sl_mode) { + AssertFatal(UE[CC_id]->sl_mode == 2, "Only Sidelink mode 2 supported. Mode 1 not yet supported\n"); + DevAssert(mac->if_module != NULL && mac->if_module->sl_phy_config_request != NULL); + nr_sl_phy_config_t *phycfg = &mac->SL_MAC_PARAMS->sl_phy_config; + phycfg->sl_config_req.sl_carrier_config.sl_num_rx_ant = get_nrUE_params()->nb_antennas_rx; + phycfg->sl_config_req.sl_carrier_config.sl_num_tx_ant = get_nrUE_params()->nb_antennas_tx; + mac->if_module->sl_phy_config_request(phycfg); + mac->phy_config_request_sent = true; + sl_nr_ue_phy_params_t *sl_phy = &UE[CC_id]->SL_UE_PHY_PARAMS; + nr_init_frame_parms_ue_sl(&sl_phy->sl_frame_params, + &sl_phy->sl_config, + get_softmodem_params()->threequarter_fs, + get_nrUE_params()->ofdm_offset_divisor); + sl_ue_phy_init(UE[CC_id]); + } } } @@ -593,7 +597,10 @@ int main(int argc, char **argv) load_softscope("nr",PHY_vars_UE_g[0][0]); } - init_NR_UE_threads(1); + for (int inst = 0; inst < NB_UE_INST; inst++) { + LOG_I(PHY,"Intializing UE Threads for instance %d ...\n", inst); + init_NR_UE_threads(PHY_vars_UE_g[inst][0]); + } printf("UE threads created by %ld\n", gettid()); } diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h index 9471988c02..c61151e9ad 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -92,7 +92,7 @@ extern nrUE_params_t *get_nrUE_params(void); extern int setup_nr_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg); extern void fill_ue_band_info(void); extern void init_NR_UE(int, char *, char *, char *); -extern void init_NR_UE_threads(int); +extern void init_NR_UE_threads(PHY_VARS_NR_UE *ue); extern void reset_opp_meas(void); extern void print_opp_meas(void); void start_oai_nrue_threads(void);