From 255d32389ca51888955457e06d48e89fde8e6498 Mon Sep 17 00:00:00 2001
From: laurent <laurent.thomas@open-cells.com>
Date: Thu, 6 Feb 2020 11:01:54 +0100
Subject: [PATCH] real time ok in monolithic cases, phy test tools fixed

---
 cmake_targets/CMakeLists.txt                       |  4 +++-
 common/utils/threadPool/thread-pool.h              |  6 +++---
 .../nfapi/public_inc/nfapi_nr_interface_scf.h      |  1 +
 openair1/SIMULATION/LTE_PHY/dlsim.c                |  4 ++++
 openair1/SIMULATION/LTE_PHY/ulsim.c                |  4 ++++
 targets/RT/USER/lte-softmodem.c                    | 14 ++++++++++++--
 6 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index d45f655561e..e2c58033d2f 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -186,7 +186,7 @@ set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,${CMAKE_CU
 # these changes are related to hardcoded path to include .h files
 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g3 -DMALLOC_CHECK_=3")
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g3 -DMALLOC_CHECK_=3 -Og")
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS}  -Og")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS}  -O3")
 
 set(GIT_BRANCH        "UNKNOWN")
 set(GIT_COMMIT_HASH   "UNKNOWN")
@@ -2449,6 +2449,7 @@ add_executable(lte-softmodem
   ${OPENAIR_TARGETS}/RT/USER/ru_control.c
   ${OPENAIR_TARGETS}/RT/USER/lte-softmodem.c
   ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c
+  ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c
   ${OPENAIR2_DIR}/ENB_APP/NB_IoT_interface.c
   ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c
   ${OPENAIR_TARGETS}/COMMON/create_tasks.c
@@ -2828,6 +2829,7 @@ foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim pr
   
   add_executable(${myExe}
     ${OPENAIR1_DIR}/SIMULATION/LTE_PHY/${myExe}.c
+    ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c
     ${OPENAIR_DIR}/common/utils/backtrace.c
     ${OPENAIR_DIR}/common/utils/system.c
     ${XFORMS_SOURCE}
diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h
index 9a2681a828e..1b59fb15899 100644
--- a/common/utils/threadPool/thread-pool.h
+++ b/common/utils/threadPool/thread-pool.h
@@ -217,11 +217,11 @@ static inline void pushTpool(tpool_t *t, notifiedFIFO_elt_t *msg) {
 
 static inline notifiedFIFO_elt_t *pullTpool(notifiedFIFO_t *responseFifo, tpool_t *t) {
   notifiedFIFO_elt_t *msg= pullNotifiedFIFO(responseFifo);
-
+  AssertFatal(t->traceFd, "Thread pool used while not initialized");
   if (t->measurePerf)
     msg->returnTime=rdtsc();
 
-  if (t->traceFd >= 0)
+  if (t->traceFd > 0)
     if(write(t->traceFd, msg, sizeof(*msg)));
 
   return msg;
@@ -229,7 +229,7 @@ static inline notifiedFIFO_elt_t *pullTpool(notifiedFIFO_t *responseFifo, tpool_
 
 static inline notifiedFIFO_elt_t *tryPullTpool(notifiedFIFO_t *responseFifo, tpool_t *t) {
   notifiedFIFO_elt_t *msg= pollNotifiedFIFO(responseFifo);
-
+  AssertFatal(t->traceFd, "Thread pool used while not initialized");
   if (msg == NULL)
     return NULL;
 
diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
index 1eea6474f30..408da13718c 100644
--- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
+++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
@@ -11,6 +11,7 @@
 
 #include "stddef.h"
 #include "nfapi_interface.h"
+#include <nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h>
 
 #define NFAPI_NR_MAX_NB_CCE_AGGREGATION_LEVELS 5
 #define NFAPI_NR_MAX_NB_TCI_STATES_PDCCH 64
diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c
index a47a174702e..d8ac505d141 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim.c
@@ -1266,6 +1266,10 @@ int main(int argc, char **argv) {
   }
 
   L1_rxtx_proc_t *proc_eNB = &eNB->proc.L1_proc;
+  initTpool("n", &proc_eNB->threadPool, true);
+  initNotifiedFIFO(&proc_eNB->respEncode);
+  initNotifiedFIFO(&proc_eNB->respDecode);
+
   proc_eNB->frame_tx=0;
 
   if (input_fd==NULL) {
diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c
index 0459109a7ca..34237771aa7 100644
--- a/openair1/SIMULATION/LTE_PHY/ulsim.c
+++ b/openair1/SIMULATION/LTE_PHY/ulsim.c
@@ -793,6 +793,10 @@ int main(int argc, char **argv) {
   proc_rxtx_ue->frame_rx = (subframe<4)?(proc_rxtx->frame_tx-1):(proc_rxtx->frame_tx);
   proc_rxtx_ue->subframe_tx = proc_rxtx->subframe_rx;
   proc_rxtx_ue->subframe_rx = (proc_rxtx->subframe_tx+6)%10;
+  initTpool("n", &proc_rxtx->threadPool, true);
+  initNotifiedFIFO(&proc_rxtx->respEncode);
+  initNotifiedFIFO(&proc_rxtx->respDecode);
+
   printf("Init UL hopping UE\n");
   init_ul_hopping(&UE->frame_parms);
   printf("Init UL hopping eNB\n");
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 737b7d02b43..a06797ee4b0 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -665,9 +665,19 @@ int main ( int argc, char **argv )
     if (RC.nb_L1_inst > 0) {
       printf("Initializing eNB threads single_thread_flag:%d wait_for_sync:%d\n", get_softmodem_params()->single_thread_flag,get_softmodem_params()->wait_for_sync);
       init_eNB(get_softmodem_params()->single_thread_flag,get_softmodem_params()->wait_for_sync);
-      //      for (inst=0;inst<RC.nb_L1_inst;inst++)
-      //  for (CC_id=0;CC_id<RC.nb_L1_CC[inst];CC_id++) phy_init_lte_eNB(RC.eNB[inst][CC_id],0,0);
     }
+    for (int x=0; x < RC.nb_L1_inst; x++) 
+      for (int CC_id=0; CC_id<RC.nb_L1_CC[x]; CC_id++) {
+        L1_rxtx_proc_t *L1proc= &RC.eNB[x][CC_id]->proc.L1_proc;
+        if ( strlen(get_softmodem_params()->threadPoolConfig) > 0 )
+         initTpool(get_softmodem_params()->threadPoolConfig, &L1proc->threadPool, true);
+        else
+         initTpool("n", &L1proc->threadPool, true);
+      initNotifiedFIFO(&L1proc->respEncode);
+      initNotifiedFIFO(&L1proc->respDecode);
+    }
+
+
   }
 
   printf("wait_eNBs()\n");
-- 
GitLab