From a1f1d53cb5eaee0a1b969daecbd95f6d9191c9df Mon Sep 17 00:00:00 2001
From: francescomani <francesco.mani@eurecom.fr>
Date: Thu, 18 Mar 2021 13:09:36 +0100
Subject: [PATCH] another tentative fix for gnb initialization crashes

---
 .../conf_files/gnb.band261.tm1.32PRB.usrpn300.conf       | 1 +
 executables/nr-gnb.c                                     | 9 ++-------
 executables/nr-softmodem.c                               | 4 ++--
 openair2/GNB_APP/gnb_app.c                               | 2 --
 openair2/GNB_APP/gnb_config.c                            | 2 --
 .../CONF/gnb.band261.tm1.32PRB.usrpn300.conf             | 1 +
 6 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/ci-scripts/conf_files/gnb.band261.tm1.32PRB.usrpn300.conf b/ci-scripts/conf_files/gnb.band261.tm1.32PRB.usrpn300.conf
index f810dd546ca..2bfd09509c7 100644
--- a/ci-scripts/conf_files/gnb.band261.tm1.32PRB.usrpn300.conf
+++ b/ci-scripts/conf_files/gnb.band261.tm1.32PRB.usrpn300.conf
@@ -249,6 +249,7 @@ L1s = (
     	{
 	num_cc = 1;
 	tr_n_preference = "local_mac";
+	pusch_proc_threads = 8;
         }  
 );
 
diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c
index 81d43fe2b09..26551b8e073 100644
--- a/executables/nr-gnb.c
+++ b/executables/nr-gnb.c
@@ -468,21 +468,16 @@ void init_gNB(int single_thread_flag,int wait_for_sync) {
 
   if (RC.gNB == NULL) {
     RC.gNB = (PHY_VARS_gNB **) malloc((1+RC.nb_nr_L1_inst)*sizeof(PHY_VARS_gNB *));
-    for (inst=0; inst<RC.nb_nr_L1_inst; inst++) {
-      RC.gNB[inst] = (PHY_VARS_gNB *) malloc(sizeof(PHY_VARS_gNB));
-      memset((void*)RC.gNB[inst],0,sizeof(PHY_VARS_gNB));
-    }
+    LOG_I(PHY,"gNB L1 structure RC.gNB allocated @ %p\n",RC.gNB);
   }
 
-  LOG_I(PHY,"gNB L1 structure RC.gNB allocated @ %p\n",RC.gNB);
-
   for (inst=0; inst<RC.nb_nr_L1_inst; inst++) {
 
     if (RC.gNB[inst] == NULL) {
       RC.gNB[inst] = (PHY_VARS_gNB *) malloc(sizeof(PHY_VARS_gNB));
       memset((void*)RC.gNB[inst],0,sizeof(PHY_VARS_gNB));
+      LOG_I(PHY,"[nr-gnb.c] gNB structure RC.gNB[%d] allocated @ %p\n",inst,RC.gNB[inst]);
     }
-    LOG_I(PHY,"[nr-gnb.c] gNB structure RC.gNB[%d] allocated @ %p\n",inst,RC.gNB[inst]);
     gNB                     = RC.gNB[inst];
     gNB->abstraction_flag   = 0;
     gNB->single_thread_flag = single_thread_flag;
diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c
index 924c32b8a7c..428d1b65c2e 100644
--- a/executables/nr-softmodem.c
+++ b/executables/nr-softmodem.c
@@ -809,10 +809,10 @@ if(!IS_SOFTMODEM_NOS1)
 
   if (RC.nb_nr_inst > 0)  {
     // don't create if node doesn't connect to RRC/S1/GTP
+    RCconfig_NR_L1();
     AssertFatal(create_gNB_tasks(1) == 0,"cannot create ITTI tasks\n");
   } else {
-    printf("No ITTI, Initializing L1\n");
-    RCconfig_NR_L1();
+    AssertFatal(1==0,"RC.nb_nr_inst should have been already initialized in get_options()");
   }
 
   /* Start the agent. If it is turned off in the configuration, it won't start */
diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c
index 77e45646326..b525e7edb7c 100644
--- a/openair2/GNB_APP/gnb_app.c
+++ b/openair2/GNB_APP/gnb_app.c
@@ -147,8 +147,6 @@ void *gNB_app_task(void *args_p)
 
   LOG_I(PHY, "%s() Task ready initialize structures\n", __FUNCTION__);
 
-  RCconfig_NR_L1();
-
   RCconfig_nr_macrlc();
 
   LOG_I(PHY, "%s() RC.nb_nr_L1_inst:%d\n", __FUNCTION__, RC.nb_nr_L1_inst);
diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c
index 957485a9923..115073a334e 100644
--- a/openair2/GNB_APP/gnb_config.c
+++ b/openair2/GNB_APP/gnb_config.c
@@ -424,8 +424,6 @@ void RCconfig_NR_L1(void) {
         RC.nb_nr_CC = (int *)malloc((1+RC.nb_nr_inst)*sizeof(int));
         RC.nb_nr_CC[0]=1;
 
-        RC.nb_nr_inst =1; // DJP - feptx_prec uses num_gNB but phy_init_RU uses nb_nr_inst
-
         LOG_I(PHY,"%s() NFAPI PNF mode - RC.nb_nr_inst=1 this is because phy_init_RU() uses that to index and not RC.num_gNB - why the 2 similar variables?\n", __FUNCTION__);
         LOG_I(PHY,"%s() NFAPI PNF mode - RC.nb_nr_CC[0]=%d for init_gNB_afterRU()\n", __FUNCTION__, RC.nb_nr_CC[0]);
         LOG_I(PHY,"%s() NFAPI PNF mode - RC.nb_nr_macrlc_inst:%d because used by mac_top_init_gNB()\n", __FUNCTION__, RC.nb_nr_macrlc_inst);
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band261.tm1.32PRB.usrpn300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band261.tm1.32PRB.usrpn300.conf
index 72e01228fd6..95d8945f9d1 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band261.tm1.32PRB.usrpn300.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band261.tm1.32PRB.usrpn300.conf
@@ -249,6 +249,7 @@ L1s = (
     	{
 	num_cc = 1;
 	tr_n_preference = "local_mac";
+	pusch_proc_threads = 8;
         }  
 );
 
-- 
GitLab