Commit 08ea6180 authored by laurent's avatar laurent

fix important bug in CU, merge thread pool improvement and rf simulator...

fix important bug in CU, merge thread pool improvement and rf simulator improvements made initialy in 5G branch
parent e8091083
...@@ -49,23 +49,6 @@ void *one_thread(void *arg) { ...@@ -49,23 +49,6 @@ void *one_thread(void *arg) {
struct one_thread *myThread=(struct one_thread *) arg; struct one_thread *myThread=(struct one_thread *) arg;
struct thread_pool *tp=myThread->pool; struct thread_pool *tp=myThread->pool;
// configure the thread core assignment
// TBD: reserve the core for us exclusively
if ( myThread->coreID >= 0 && myThread->coreID < get_nprocs_conf()) {
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(myThread->coreID, &cpuset);
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
}
//Configure the thread scheduler policy for Linux
struct sched_param sparam= {0};
sparam.sched_priority = sched_get_priority_max(SCHED_RR);
pthread_setschedparam(pthread_self(), SCHED_RR, &sparam);
// set the thread name for debugging
sprintf(myThread->name,"Tpool_%d",myThread->coreID);
pthread_setname_np(pthread_self(), myThread->name );
// Infinite loop to process requests // Infinite loop to process requests
do { do {
notifiedFIFO_elt_t *elt=pullNotifiedFifoRemember(&tp->incomingFifo, myThread); notifiedFIFO_elt_t *elt=pullNotifiedFifoRemember(&tp->incomingFifo, myThread);
...@@ -106,10 +89,6 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { ...@@ -106,10 +89,6 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
} else } else
pool->traceFd=-1; pool->traceFd=-1;
//Configure the thread scheduler policy for Linux
struct sched_param sparam= {0};
sparam.sched_priority = sched_get_priority_max(SCHED_RR)-1;
pthread_setschedparam(pthread_self(), SCHED_RR, &sparam);
pool->activated=true; pool->activated=true;
initNotifiedFIFO(&pool->incomingFifo); initNotifiedFIFO(&pool->incomingFifo);
char *saveptr, * curptr; char *saveptr, * curptr;
...@@ -137,7 +116,11 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { ...@@ -137,7 +116,11 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
pool->allthreads->coreID=atoi(curptr); pool->allthreads->coreID=atoi(curptr);
pool->allthreads->id=pool->nbThreads; pool->allthreads->id=pool->nbThreads;
pool->allthreads->pool=pool; pool->allthreads->pool=pool;
pthread_create(&pool->allthreads->threadID, NULL, one_thread, (void *)pool->allthreads); //Configure the thread scheduler policy for Linux
// set the thread name for debugging
sprintf(pool->allthreads->name,"Tpool_%d",pool->allthreads->coreID);
threadCreate(&pool->allthreads->threadID, one_thread, (void *)pool->allthreads,
pool->allthreads->name, pool->allthreads->coreID, OAI_PRIORITY_RT);
pool->nbThreads++; pool->nbThreads++;
} }
...@@ -152,6 +135,9 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { ...@@ -152,6 +135,9 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
#ifdef TEST_THREAD_POOL #ifdef TEST_THREAD_POOL
void exit_function(const char *file, const char *function, const int line, const char *s) {
}
struct testData { struct testData {
int id; int id;
char txt[30]; char txt[30];
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <assertions.h> #include <assertions.h>
#include <LOG/log.h> #include <LOG/log.h>
#include <common/utils/system.h>
#ifdef DEBUG #ifdef DEBUG
#define THREADINIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP #define THREADINIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
...@@ -77,41 +78,60 @@ static inline void delNotifiedFIFO_elt(notifiedFIFO_elt_t *elt) { ...@@ -77,41 +78,60 @@ static inline void delNotifiedFIFO_elt(notifiedFIFO_elt_t *elt) {
//LOG_W(UTIL,"delNotifiedFIFO on something not allocated by newNotifiedFIFO\n"); //LOG_W(UTIL,"delNotifiedFIFO on something not allocated by newNotifiedFIFO\n");
} }
static inline void initNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf) {
nf->inF=NULL;
nf->outF=NULL;
}
static inline void initNotifiedFIFO(notifiedFIFO_t *nf) { static inline void initNotifiedFIFO(notifiedFIFO_t *nf) {
mutexinit(nf->lockF); mutexinit(nf->lockF);
condinit (nf->notifF); condinit (nf->notifF);
nf->inF=NULL; initNotifiedFIFO_nothreadSafe(nf);
nf->outF=NULL;
// No delete function: the creator has only to free the memory // No delete function: the creator has only to free the memory
} }
static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) { static inline void pushNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) {
mutexlock(nf->lockF);
msg->next=NULL; msg->next=NULL;
if (nf->outF == NULL) if (nf->outF == NULL)
nf->outF = msg; nf->outF = msg;
if (nf->inF) if (nf->inF != NULL)
nf->inF->next = msg; nf->inF->next = msg;
nf->inF = msg; nf->inF = msg;
condbroadcast(nf->notifF);
mutexunlock(nf->lockF);
} }
static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) { static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) {
mutexlock(nf->lockF); mutexlock(nf->lockF);
pushNotifiedFIFO_nothreadSafe(nf,msg);
condbroadcast(nf->notifF);
mutexunlock(nf->lockF);
}
while(!nf->outF) static inline notifiedFIFO_elt_t *pullNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf) {
condwait(nf->notifF, nf->lockF); if (nf->outF == NULL)
return NULL;
notifiedFIFO_elt_t *ret=nf->outF; notifiedFIFO_elt_t *ret=nf->outF;
if (nf->outF==nf->outF->next)
LOG_E(TMR,"Circular list in thread pool: push several times the same buffer is forbidden\n");
nf->outF=nf->outF->next; nf->outF=nf->outF->next;
if (nf->outF==NULL) if (nf->outF==NULL)
nf->inF=NULL; nf->inF=NULL;
return ret;
}
static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) {
mutexlock(nf->lockF);
notifiedFIFO_elt_t *ret;
while((ret=pullNotifiedFIFO_nothreadSafe(nf)) == NULL)
condwait(nf->notifF, nf->lockF);
mutexunlock(nf->lockF); mutexunlock(nf->lockF);
return ret; return ret;
} }
...@@ -122,14 +142,7 @@ static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) { ...@@ -122,14 +142,7 @@ static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) {
if (tmp != 0 ) if (tmp != 0 )
return NULL; return NULL;
notifiedFIFO_elt_t *ret=nf->outF; notifiedFIFO_elt_t *ret=pullNotifiedFIFO_nothreadSafe(nf);
if (ret!=NULL)
nf->outF=nf->outF->next;
if (nf->outF==NULL)
nf->inF=NULL;
mutexunlock(nf->lockF); mutexunlock(nf->lockF);
return ret; return ret;
} }
...@@ -151,6 +164,7 @@ static inline int abortNotifiedFIFO(notifiedFIFO_t *nf, uint64_t key) { ...@@ -151,6 +164,7 @@ static inline int abortNotifiedFIFO(notifiedFIFO_t *nf, uint64_t key) {
} else } else
start=&(*start)->next; start=&(*start)->next;
} }
if (nf->outF == NULL) if (nf->outF == NULL)
nf->inF=NULL; nf->inF=NULL;
...@@ -184,16 +198,20 @@ typedef struct thread_pool { ...@@ -184,16 +198,20 @@ typedef struct thread_pool {
static inline void pushTpool(tpool_t *t, notifiedFIFO_elt_t *msg) { static inline void pushTpool(tpool_t *t, notifiedFIFO_elt_t *msg) {
if (t->measurePerf) msg->creationTime=rdtsc(); if (t->measurePerf) msg->creationTime=rdtsc();
if ( t->activated) if ( t->activated)
pushNotifiedFIFO(&t->incomingFifo, msg); pushNotifiedFIFO(&t->incomingFifo, msg);
else { else {
if (t->measurePerf) if (t->measurePerf)
msg->startProcessingTime=rdtsc(); msg->startProcessingTime=rdtsc();
msg->processingFunc(NotifiedFifoData(msg));
if (t->measurePerf) msg->processingFunc(NotifiedFifoData(msg));
msg->endProcessingTime=rdtsc();
if (msg->reponseFifo) if (t->measurePerf)
pushNotifiedFIFO(msg->reponseFifo, msg); msg->endProcessingTime=rdtsc();
if (msg->reponseFifo)
pushNotifiedFIFO(msg->reponseFifo, msg);
} }
} }
...@@ -202,10 +220,8 @@ static inline notifiedFIFO_elt_t *pullTpool(notifiedFIFO_t *responseFifo, tpool_ ...@@ -202,10 +220,8 @@ static inline notifiedFIFO_elt_t *pullTpool(notifiedFIFO_t *responseFifo, tpool_
if (t->measurePerf) if (t->measurePerf)
msg->returnTime=rdtsc(); msg->returnTime=rdtsc();
if (t->traceFd >= 0)
if (t->traceFd)
if(write(t->traceFd, msg, sizeof(*msg))); if(write(t->traceFd, msg, sizeof(*msg)));
return msg; return msg;
} }
...@@ -217,10 +233,8 @@ static inline notifiedFIFO_elt_t *tryPullTpool(notifiedFIFO_t *responseFifo, tpo ...@@ -217,10 +233,8 @@ static inline notifiedFIFO_elt_t *tryPullTpool(notifiedFIFO_t *responseFifo, tpo
if (t->measurePerf) if (t->measurePerf)
msg->returnTime=rdtsc(); msg->returnTime=rdtsc();
if (t->traceFd) if (t->traceFd)
if(write(t->traceFd, msg, sizeof(*msg))); if(write(t->traceFd, msg, sizeof(*msg)));
return msg; return msg;
} }
...@@ -239,6 +253,7 @@ static inline int abortTpool(tpool_t *t, uint64_t key) { ...@@ -239,6 +253,7 @@ static inline int abortTpool(tpool_t *t, uint64_t key) {
} else } else
start=&(*start)->next; start=&(*start)->next;
} }
if (t->incomingFifo.outF==NULL) if (t->incomingFifo.outF==NULL)
t->incomingFifo.inF=NULL; t->incomingFifo.inF=NULL;
......
...@@ -1324,6 +1324,9 @@ void *DL_du_fs6(void *arg) { ...@@ -1324,6 +1324,9 @@ void *DL_du_fs6(void *arg) {
feptx_prec(ru, &L1_proc); feptx_prec(ru, &L1_proc);
feptx_ofdm(ru, &L1_proc); feptx_ofdm(ru, &L1_proc);
tx_rf(ru, &L1_proc); tx_rf(ru, &L1_proc);
if ( IS_SOFTMODEM_RFSIM )
return NULL;
} }
return NULL; return NULL;
...@@ -1443,13 +1446,22 @@ void *cu_fs6(void *arg) { ...@@ -1443,13 +1446,22 @@ void *cu_fs6(void *arg) {
remoteIP=DU_IP; remoteIP=DU_IP;
AssertFatal(createUDPsock(NULL, CU_PORT, remoteIP, DU_PORT, &sockFS6), ""); AssertFatal(createUDPsock(NULL, CU_PORT, remoteIP, DU_PORT, &sockFS6), "");
L1_rxtx_proc_t L1proc= {0};
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);
uint64_t timeStamp=0; uint64_t timeStamp=0;
initStaticTime(begingWait); initStaticTime(begingWait);
initStaticTime(begingWait2); initStaticTime(begingWait2);
initRefTimes(waitDUAndProcessingUL); initRefTimes(waitDUAndProcessingUL);
initRefTimes(makeSendDL); initRefTimes(makeSendDL);
initRefTimes(fullLoop); initRefTimes(fullLoop);
L1_rxtx_proc_t L1proc= {0};
while(1) { while(1) {
timeStamp+=ru->frame_parms.samples_per_tti; timeStamp+=ru->frame_parms.samples_per_tti;
...@@ -1496,6 +1508,7 @@ void *du_fs6(void *arg) { ...@@ -1496,6 +1508,7 @@ void *du_fs6(void *arg) {
initRefTimes(waitRxAndProcessingUL); initRefTimes(waitRxAndProcessingUL);
initRefTimes(fullLoop); initRefTimes(fullLoop);
pthread_t t; pthread_t t;
if ( !IS_SOFTMODEM_RFSIM )
threadCreate(&t, DL_du_fs6, (void *)ru, "MainDuTx", -1, OAI_PRIORITY_RT_MAX); threadCreate(&t, DL_du_fs6, (void *)ru, "MainDuTx", -1, OAI_PRIORITY_RT_MAX);
while(1) { while(1) {
...@@ -1503,6 +1516,8 @@ void *du_fs6(void *arg) { ...@@ -1503,6 +1516,8 @@ void *du_fs6(void *arg) {
updateTimesReset(begingWait, &fullLoop, 1000, true,"DU for full SubFrame (must be less 1ms)"); updateTimesReset(begingWait, &fullLoop, 1000, true,"DU for full SubFrame (must be less 1ms)");
pickStaticTime(begingWait); pickStaticTime(begingWait);
UL_du_fs6(ru, &L1proc); UL_du_fs6(ru, &L1proc);
if ( IS_SOFTMODEM_RFSIM )
DL_du_fs6((void *)ru);
updateTimesReset(begingWait, &waitRxAndProcessingUL, 1000, true,"DU Time in wait Rx + Ul processing"); updateTimesReset(begingWait, &waitRxAndProcessingUL, 1000, true,"DU Time in wait Rx + Ul processing");
} }
......
...@@ -688,7 +688,7 @@ static void *ru_thread( void *param ) { ...@@ -688,7 +688,7 @@ static void *ru_thread( void *param ) {
setbuf(stdout, NULL); setbuf(stdout, NULL);
setbuf(stderr, NULL); setbuf(stderr, NULL);
RU_t *ru = (RU_t *)param; RU_t *ru = (RU_t *)param;
L1_rxtx_proc_t L1proc; L1_rxtx_proc_t L1proc={0};
L1_rxtx_proc_t *proc=&L1proc; L1_rxtx_proc_t *proc=&L1proc;
if ( strlen(get_softmodem_params()->threadPoolConfig) > 0 ) if ( strlen(get_softmodem_params()->threadPoolConfig) > 0 )
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment