From 1512e39e4e6f8e869d9ae2a1912be34278f64d77 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Tue, 17 May 2022 11:18:37 +0200 Subject: [PATCH] Rewrite kill_NR_RU_proc() and reuse functions --- executables/nr-ru.c | 42 ++++++++++------------------ openair1/SCHED_NR/nr_ru_procedures.c | 31 ++++++++++++++++++++ openair1/SCHED_NR/sched_nr.h | 2 ++ 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index b29947c9be..2f75c2d295 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -1331,40 +1331,26 @@ void init_RU_proc(RU_t *ru) { } + void kill_NR_RU_proc(int inst) { RU_t *ru = RC.ru[inst]; RU_proc_t *proc = &ru->proc; - LOG_D(PHY, "Joining pthread_FH\n"); + + /* Note: it seems pthread_FH and and FEP thread below both use + * mutex_fep/cond_fep. Thus, we unlocked above for pthread_FH above and do + * the same for FEP thread below again (using broadcast() to ensure both + * threads get the signal). This one will also destroy the mutex and cond. */ + pthread_mutex_lock(&proc->mutex_fep); + proc->instance_cnt_fep = 0; + pthread_cond_broadcast(&proc->cond_fep); + pthread_mutex_unlock( &proc->mutex_fep ); pthread_join(proc->pthread_FH, NULL); - if (get_nprocs() >= 2) { - if (ru->feprx) { - pthread_mutex_lock(&proc->mutex_fep); - proc->instance_cnt_fep = 0; - pthread_mutex_unlock(&proc->mutex_fep); - pthread_cond_signal(&proc->cond_fep); - LOG_D(PHY, "Joining pthread_fep\n"); - pthread_join(proc->pthread_fep, NULL); - pthread_mutex_destroy(&proc->mutex_fep); - pthread_cond_destroy(&proc->cond_fep); - } + if (ru->feprx) + nr_kill_feprx_thread(ru); - if (ru->feptx_ofdm) { - pthread_mutex_lock(&proc->mutex_feptx); - proc->instance_cnt_feptx = 0; - pthread_mutex_unlock(&proc->mutex_feptx); - pthread_cond_signal(&proc->cond_feptx); - LOG_D(PHY, "Joining pthread_feptx\n"); - pthread_join(proc->pthread_feptx, NULL); - pthread_mutex_destroy(&proc->mutex_feptx); - pthread_cond_destroy(&proc->cond_feptx); - } - } - - if (opp_enabled) { - LOG_D(PHY, "Joining ru_stats_thread\n"); - pthread_join(ru->ru_stats_thread, NULL); - } + if (ru->feptx_ofdm) + nr_kill_feptx_thread(ru); } int check_capabilities(RU_t *ru,RRU_capabilities_t *cap) { diff --git a/openair1/SCHED_NR/nr_ru_procedures.c b/openair1/SCHED_NR/nr_ru_procedures.c index fa9ff4564a..a93ac0ded2 100644 --- a/openair1/SCHED_NR/nr_ru_procedures.c +++ b/openair1/SCHED_NR/nr_ru_procedures.c @@ -453,6 +453,24 @@ void nr_init_feptx_thread(RU_t *ru) { } +void nr_kill_feptx_thread(RU_t *ru) { + RU_proc_t *proc = &ru->proc; + + for (int i = 0; i < ru->nb_tx * 2; i++) { + RU_feptx_t *feptx = &proc->feptx[i]; + if (feptx->pthread_feptx == 0) + continue; + + pthread_mutex_lock(&feptx->mutex_feptx); + feptx->instance_cnt_feptx = 0; + pthread_mutex_unlock(&feptx->mutex_feptx); + pthread_cond_signal(&feptx->cond_feptx); + LOG_I(PHY, "Joining pthread_feptx %d\n", i); + pthread_join(feptx->pthread_feptx, NULL); + pthread_mutex_destroy(&feptx->mutex_feptx); + pthread_cond_destroy(&feptx->cond_feptx); + } +} void nr_feptx_prec(RU_t *ru,int frame_tx,int tti_tx) { @@ -590,6 +608,19 @@ void nr_init_feprx_thread(RU_t *ru) { threadCreate(&proc->pthread_fep, nr_feprx_thread, (void*)ru, "feprx", -1, OAI_PRIORITY_RT); } +void nr_kill_feprx_thread(RU_t *ru) { + RU_proc_t *proc = &ru->proc; + if (proc->pthread_fep == 0) + return; + LOG_I(PHY, "Joining pthread_feprx\n"); + pthread_mutex_lock(&proc->mutex_fep); + proc->instance_cnt_fep = 0; + pthread_mutex_unlock(&proc->mutex_fep); + pthread_cond_signal(&proc->cond_fep); + pthread_join(proc->pthread_fep, NULL); + pthread_mutex_destroy(&proc->mutex_fep); + pthread_cond_destroy(&proc->cond_fep); +} void nr_fep_full_2thread(RU_t *ru, int slot) { diff --git a/openair1/SCHED_NR/sched_nr.h b/openair1/SCHED_NR/sched_nr.h index 2124397c47..22b341623e 100644 --- a/openair1/SCHED_NR/sched_nr.h +++ b/openair1/SCHED_NR/sched_nr.h @@ -45,11 +45,13 @@ void nr_feptx_ofdm(RU_t *ru,int frame_tx,int tti_tx); void nr_feptx_ofdm_2thread(RU_t *ru,int frame_tx,int tti_tx); void nr_feptx0(RU_t *ru,int tti_tx,int first_symbol, int num_symbols, int aa); void nr_init_feptx_thread(RU_t *ru); +void nr_kill_feptx_thread(RU_t *ru); void fep_full(RU_t *ru,int slot); void nr_feptx_prec(RU_t *ru,int frame_tx,int tti_tx); void nr_init_feptx_prec_thread(RU_t *ru); void nr_feptx_prec_control(RU_t *ru,int frame,int tti_tx); void nr_init_feprx_thread(RU_t *ru); +void nr_kill_feprx_thread(RU_t *ru); void nr_fep_full(RU_t *ru, int slot); void nr_fep_full_2thread(RU_t *ru, int slot); void feptx_prec(RU_t *ru,int frame_tx,int tti_tx);