From 6ec065fe2a1f9d2c0d705b3c5c1bc43959a328d4 Mon Sep 17 00:00:00 2001
From: frtabu <francois.taburet@nokia-bell-labs.com>
Date: Fri, 8 Jan 2021 01:22:23 +0100
Subject: [PATCH] add tpool thread name parameter, review fixes

---
 common/utils/threadPool/thread-pool.c         |  7 ++++---
 common/utils/threadPool/thread-pool.h         |  4 ++--
 common/utils/threadPool/thread-pool.md        | 18 ++++++++++-------
 executables/nr-uesoftmodem.c                  |  9 ++-------
 .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   | 20 +++++++++----------
 5 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c
index e1446f15d71..77729ae7a7a 100644
--- a/common/utils/threadPool/thread-pool.c
+++ b/common/utils/threadPool/thread-pool.c
@@ -92,7 +92,7 @@ void *one_thread(void *arg) {
   } while (true);
 }
 
-void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
+void initNamedTpool(char *params,tpool_t *pool, bool performanceMeas, char *name) {
   memset(pool,0,sizeof(*pool));
   char *measr=getenv("threadPoolMeasurements");
   pool->measurePerf=performanceMeas;
@@ -116,6 +116,7 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
   pool->restrictRNTI=false;
   curptr=strtok_r(parms_cpy,",",&saveptr);
   struct one_thread * ptr;
+  char *tname = (name == NULL ? "Tpool" : name);
   while ( curptr!=NULL ) {
     int c=toupper(curptr[0]);
 
@@ -129,7 +130,7 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
         break;
 
       default:
-	ptr=pool->allthreads;
+        ptr=pool->allthreads;
         pool->allthreads=(struct one_thread *)malloc(sizeof(struct one_thread));
         pool->allthreads->next=ptr;
         printf("create a thread for core %d\n", atoi(curptr));
@@ -138,7 +139,7 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
         pool->allthreads->pool=pool;
         //Configure the thread scheduler policy for Linux
         // set the thread name for debugging
-        sprintf(pool->allthreads->name,"Tpool_%d",pool->allthreads->coreID);
+        sprintf(pool->allthreads->name,"%s%d_%d",tname,pool->nbThreads,pool->allthreads->coreID);
         threadCreate(&pool->allthreads->threadID, one_thread, (void *)pool->allthreads,
                      pool->allthreads->name, pool->allthreads->coreID, OAI_PRIORITY_RT);
         pool->nbThreads++;
diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h
index bd55203c7f9..5db1a5e34e6 100644
--- a/common/utils/threadPool/thread-pool.h
+++ b/common/utils/threadPool/thread-pool.h
@@ -294,6 +294,6 @@ static inline int abortTpool(tpool_t *t, uint64_t key) {
   mutexunlock(nf->lockF);
   return nbRemoved;
 }
-void initTpool(char *params,tpool_t *pool, bool performanceMeas);
-
+void initNamedTpool(char *params,tpool_t *pool, bool performanceMeas, char *name);
+#define  initTpool(PARAMPTR,TPOOLPTR, MEASURFLAG) initNamedTpool(PARAMPTR,TPOOLPTR, MEASURFLAG, NULL)
 #endif
diff --git a/common/utils/threadPool/thread-pool.md b/common/utils/threadPool/thread-pool.md
index 4db3cd6ad17..a087b989fad 100644
--- a/common/utils/threadPool/thread-pool.md
+++ b/common/utils/threadPool/thread-pool.md
@@ -112,13 +112,13 @@ No delete() call, same principle as not thread safe queues
 # Thread pools
 
 ## initialization
-The clients can create one or more thread pools with init_tpool()
+The clients can create one or more thread pools with `initTpool(char *params,tpool_t *pool, bool performanceMeas  )` or `initNamedTpool(char *params,tpool_t *pool, bool performanceMeas , char *name)`
 
 the params string structure: describes a list of cores, separated by "," that run a worker thread
 
 If the core exists on the CPU, the thread pool initialization sets the affinity between this thread and the related code (use negative values is allowed, so the thread will never be mapped on a specific core).
 
-The threads are all Linux real time scheduler, their name is set automatically is "Tpool_<core id>"
+The threads are all Linux real time scheduler, their name is set automatically to `Tpool<thread index>_<core id>` if initTpool is used or to `<name><thread index>_<core id>` when initNamedTpool is used.
 
 ## adding jobs
 The client create their jobs messages as a notifiedFIFO_elt_t, then they push it with pushTpool() (that internally calls push_notifiedFIFO())
@@ -132,11 +132,13 @@ A abort service abortTpool() allows to abort all jobs that match a key (see jobs
 Nevertheless, jobs already performed before the return of abortTpool() are pushed in the response Fifo queue.
 
 ## API details
-Each thread pool (there can be several in the same process) should be initialized
+Each thread pool (there can be several in the same process) should be initialized once using one of the two API's:
 
-### initTpool(char *params,tpool_t *pool, bool performanceMeas) is to be called oncepool
+### initNamedTpool(char *params,tpool_t *pool, bool performanceMeas,char *name)
 
-the configuration parameter is a string, elements separated by ",":
+### initTpool(char *params,tpool_t *pool, bool performanceMeas)
+
+`params`: the configuration parameter is a string, elements separator is a comma ",". An element can be:
 
 * N: if a N is in the parameter list, no threads are created
     The purpose is to keep the same API in any case
@@ -151,9 +153,11 @@ example: "-1,-1,-1"
 as there is no core number -1, the thread pool is made of 3 floating threads
 be careful with fix allocation: it is hard to be more clever than Linux kernel
 
-pool is the memory you allocated before to store the thread pool internal state (same concept as above queues)
+`pool` is the memory you allocated before to store the thread pool internal state (same concept as above queues)
+
+`performanceMeas` is a flag to enable measurements (well described in documentation)
 
-performanceMeas is a flag to enable measurements (well described in documentation)
+`name` is used to build the thread names. 
 
 ### pushTpool(tpool_t *t, notifiedFIFO_elt_t *msg)
 
diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c
index 9a8c4cb2965..36bca40b1a7 100644
--- a/executables/nr-uesoftmodem.c
+++ b/executables/nr-uesoftmodem.c
@@ -214,9 +214,9 @@ nrUE_params_t *get_nrUE_params(void) {
 }
 /* initialie thread pools used for NRUE processing paralleliation */ 
 void init_tpools(uint8_t nun_dlsch_threads) {
-  char *params=calloc(1,(RX_NB_TH*2)+1);
+  char *params=calloc(1,(RX_NB_TH*3)+1);
   for (int i=0; i<RX_NB_TH; i++) {
-    memcpy(params+(i*2),"-1",2);
+    memcpy(params+(i*3),"-1,",3);
   }
   initTpool(params, &(nrUE_params.Tpool), false);
   free(params);
@@ -553,11 +553,6 @@ int main( int argc, char **argv ) {
     load_softscope("nr",PHY_vars_UE_g[0][0]);
   }     
 
-  for(int CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-    PHY_vars_UE_g[0][CC_id]->rf_map.card=0;
-    PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+chain_offset;
-    PHY_vars_UE_g[0][CC_id]->timing_advance = UE[CC_id]->timing_advance;
-  }
   
   init_NR_UE_threads(1);
   config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS);
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index d97bb36717b..1a5675ffd9d 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -60,16 +60,16 @@ int nbDlProcessing =0;
 static  tpool_t pool_dl;
 
 //extern double cpuf;
-void init_dlsch_tpool(uint8_t nun_dlsch_threads)
+void init_dlsch_tpool(uint8_t num_dlsch_threads)
 {
-    if( nun_dlsch_threads==0)
+    if( num_dlsch_threads==0)
     	return;
 
-  char *params=calloc(1,(nun_dlsch_threads*2)+1);
-  for (int i=0; i<nun_dlsch_threads; i++) {
-    memcpy(params+(i*2),"-1",2);
+  char *params=calloc(1,(num_dlsch_threads*3)+1);
+  for (int i=0; i<num_dlsch_threads; i++) {
+    memcpy(params+(i*3),"-1,",3);
   }
-  initTpool(params, &pool_dl, false);
+  initNamedTpool(params, &pool_dl, false,"dlsch");
   free(params);
 }
 
@@ -1311,7 +1311,7 @@ void nr_dlsch_decoding_process(void *arg)
   uint32_t G;
 
   uint32_t ret;
-  uint32_t r,r_offset=0,Kr,Kr_bytes,err_flag=0,K_bytes_F;
+  uint32_t r,r_offset=0,Kr,Kr_bytes,err_flag=0,K_bits_F;
 
   uint8_t crc_type;
   uint8_t C,Cprime;
@@ -1435,7 +1435,7 @@ void nr_dlsch_decoding_process(void *arg)
 
   Kr = harq_process->K;
   Kr_bytes = Kr>>3;
-  K_bytes_F = Kr-harq_process->F;
+  K_bits_F = Kr-harq_process->F;
 
   E = nr_get_E(G, harq_process->C, harq_process->Qm, harq_process->Nl, r);
 
@@ -1547,9 +1547,9 @@ void nr_dlsch_decoding_process(void *arg)
         //set first 2*Z_c bits to zeros
         memset(&z[0],0,2*harq_process->Z*sizeof(int16_t));
         //set Filler bits
-        memset((&z[0]+K_bytes_F),127,harq_process->F*sizeof(int16_t));
+        memset((&z[0]+K_bits_F),127,harq_process->F*sizeof(int16_t));
         //Move coded bits before filler bits
-        memcpy((&z[0]+2*harq_process->Z),harq_process->d[r],(K_bytes_F-2*harq_process->Z)*sizeof(int16_t));
+        memcpy((&z[0]+2*harq_process->Z),harq_process->d[r],(K_bits_F-2*harq_process->Z)*sizeof(int16_t));
         //skip filler bits
         memcpy((&z[0]+Kr),harq_process->d[r]+(Kr-2*harq_process->Z),(kc*harq_process->Z-Kr)*sizeof(int16_t));
         //Saturate coded bits before decoding into 8 bits values
-- 
GitLab