From 968d28d5fedaa2d34387222a77b0cf03d9915b3c Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Tue, 29 Nov 2022 14:12:08 +0100 Subject: [PATCH 1/2] RU: stop RF after all threads finished If we do not stop RF after all threads, it can happen that the RF is finished, but another thread of the RU (e.g., reorder thread) tries to send out a package to the RF. This can lead to a segfault, as observed in UHD, because we free all resources before reusing them. This commit fixes this behavior. --- executables/nr-ru.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index 1dd8ba7d40..58a5e46e09 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -1295,12 +1295,6 @@ void *ru_thread( void *param ) { printf( "Exiting ru_thread \n"); - if (ru->stop_rf != NULL) { - if (ru->stop_rf(ru) != 0) - LOG_E(HW,"Could not stop the RF device\n"); - else LOG_I(PHY,"RU %d rf device stopped\n",ru->idx); - } - ru_thread_status = 0; return &ru_thread_status; } @@ -1378,6 +1372,18 @@ void kill_NR_RU_proc(int inst) { LOG_D(PHY, "Joining ru_stats_thread\n"); pthread_join(ru->ru_stats_thread, NULL); } + + // everything should be stopped now, we can safely stop the RF device + if (ru->stop_rf == NULL) { + LOG_W(PHY, "No stop_rf() for RU %d defined, cannot stop RF!\n", ru->idx); + return; + } + int rc = ru->stop_rf(ru); + if (rc != 0) { + LOG_W(PHY, "stop_rf() returned %d, RU %d RF device did not stop properly!\n", rc, ru->idx); + return; + } + LOG_I(PHY, "RU %d RF device stopped\n",ru->idx); } int check_capabilities(RU_t *ru,RRU_capabilities_t *cap) { From 24fceb43c2219611eb9f7241c957d740adb222aa Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Tue, 29 Nov 2022 14:14:19 +0100 Subject: [PATCH 2/2] Unlock mutex after condition signal in USRP driver --- radio/USRP/USERSPACE/LIB/usrp_lib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/USRP/USERSPACE/LIB/usrp_lib.cpp b/radio/USRP/USERSPACE/LIB/usrp_lib.cpp index abbaddb255..1f6fbd34b1 100644 --- a/radio/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/radio/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -640,8 +640,8 @@ static void trx_usrp_write_reset(openair0_thread_t *wt) { pthread_mutex_lock(&wt->mutex_write); wt->count_write = 1; wt->write_thread_exit = true; - pthread_mutex_unlock(&wt->mutex_write); pthread_cond_signal(&wt->cond_write); + pthread_mutex_unlock(&wt->mutex_write); void *retval = NULL; pthread_join(wt->pthread_write, &retval); LOG_I(HW, "stopped USRP write thread\n");