From 99e67dc59964f1eed01492bbc48e85e5a5602f20 Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Thu, 6 Mar 2025 09:11:36 +0100 Subject: [PATCH] Ensure clean exit of NR UE - Shutdown DL/UL actors - Join the main/stat UE threads --- executables/nr-ue.c | 6 ++---- executables/nr-uesoftmodem.c | 17 +++++++++++++++-- openair1/PHY/defs_nr_UE.h | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index a5c4f69ed5..7ce1eebba6 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -1162,13 +1162,11 @@ void init_NR_UE(int nb_inst, char *uecap_file, char *reconfig_file, char *rbconf } 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); + threadCreate(&UE->main_thread, UE_thread, (void *)UE, thread_name, -1, OAI_PRIORITY_RT_MAX); if (!IS_SOFTMODEM_NOSTATS) { - 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); + threadCreate(&UE->stat_thread, 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 83bee89c06..d5f4a528ff 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "T.h" #include "common/oai_version.h" @@ -572,8 +573,20 @@ int main(int argc, char **argv) if (PHY_vars_UE_g && PHY_vars_UE_g[0]) { for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { PHY_VARS_NR_UE *phy_vars = PHY_vars_UE_g[0][CC_id]; - if (phy_vars && phy_vars->rfdevice.trx_end_func) - phy_vars->rfdevice.trx_end_func(&phy_vars->rfdevice); + if (phy_vars) { + shutdown_actor(&phy_vars->ul_actor); + for (int i = 0; i < NUM_DL_ACTORS; i++) { + shutdown_actor(&phy_vars->dl_actors[i]); + } + int ret = pthread_join(phy_vars->main_thread, NULL); + AssertFatal(ret == 0, "pthread_join error %d, errno %d (%s)\n", ret, errno, strerror(errno)); + if (!IS_SOFTMODEM_NOSTATS) { + ret = pthread_join(phy_vars->stat_thread, NULL); + AssertFatal(ret == 0, "pthread_join error %d, errno %d (%s)\n", ret, errno, strerror(errno)); + } + if (phy_vars->rfdevice.trx_end_func) + phy_vars->rfdevice.trx_end_func(&phy_vars->rfdevice); + } } } diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 542c94f63d..ecd863de0c 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -549,6 +549,8 @@ typedef struct PHY_VARS_NR_UE_s { Actor_t dl_actors[NUM_DL_ACTORS]; Actor_t ul_actor; ntn_config_message_t* ntn_config_message; + pthread_t main_thread; + pthread_t stat_thread; } PHY_VARS_NR_UE; typedef struct {