Commit 91f098ee authored by laurent's avatar laurent

add controls, code cleanup

parent 3bd7cd2d
......@@ -209,7 +209,7 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,int frame, int subframe) {
}
else if ((subframe == 1) &&
(fp->frame_type == TDD)){
(fp->frame_type == TDD)) {
generate_pss(txdataF,
AMP,
fp,
......@@ -338,7 +338,7 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,
// 36-212
if (nfapi_mode == 0 || nfapi_mode == 1) { // monolthic OR PNF - do not need turbo encoding on VNF
if (dlsch_harq->pdu==NULL){
if (dlsch_harq->pdu==NULL) {
LOG_E(PHY,"dlsch_harq->pdu == NULL SFN/SF:%04d%d dlsch[rnti:%x] dlsch_harq[pdu:%p pdsch_start:%d Qm:%d Nl:%d round:%d nb_rb:%d rb_alloc[0]:%d]\n", frame,subframe,dlsch->rnti, dlsch_harq->pdu,dlsch_harq->pdsch_start,dlsch_harq->Qm,dlsch_harq->Nl,dlsch_harq->round,dlsch_harq->nb_rb,dlsch_harq->rb_alloc[0]);
return;
}
......@@ -545,7 +545,11 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GENERATE_DLSCH,1);
// Now scan UE specific DLSCH
LTE_eNB_DLSCH_t *dlsch0,*dlsch1;
if (eNB->proc.threadPool.notFinishedJobs != 0 )
if (eNB->proc.threadPool.notFinishedJobs != 0 ||
eNB->proc.threadPool.oldestRequests != NULL ||
eNB->proc.threadPool.newestRequests != NULL ||
eNB->proc.threadPool.doneRequests != NULL
)
LOG_E(PHY,"no finished = %d\n",eNB->proc.threadPool.notFinishedJobs);
for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
{
......@@ -582,25 +586,32 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
// Wait all other threads finish to process
int nbRequest=0;
//printf("%s:%d:%d\n", __FILE__,__LINE__,eNB->proc.threadPool.notFinishedJobs);
AssertFatal(pthread_mutex_lock(&eNB->proc.threadPool.lockReportDone)==0,"");
int rr=0;
mutexlock(eNB->proc.threadPool.lockReportDone);
while ( eNB->proc.threadPool.notFinishedJobs > 0 ) {
// printf("%s:%d:%d\n", __FILE__,__LINE__,eNB->proc.threadPool.notFinishedJobs);
struct timespec t;
clock_gettime(CLOCK_REALTIME,&t);
t.tv_nsec+=100*1000*1000;
t.tv_nsec+=1*1000*1000;
if ( t.tv_nsec >= 1000*1000*1000 ) {
t.tv_nsec -= 1000*1000*1000;
t.tv_sec++;
}
int rr;
if ((rr=pthread_cond_timedwait(&eNB->proc.threadPool.notifDone,&eNB->proc.threadPool.lockReportDone, &t))!=0)
if ((rr=pthread_cond_timedwait(&eNB->proc.threadPool.notifDone,
&eNB->proc.threadPool.lockReportDone, &t))!=0) {
LOG_E(PHY,"timedwait1:%s,%p,%p,%p,%d\n", rr==ETIMEDOUT?"ETIMEDOUT":"other",
eNB->proc.threadPool.oldestRequests,
eNB->proc.threadPool.newestRequests,
eNB->proc.threadPool.doneRequests,
eNB->proc.threadPool.notFinishedJobs);
eNB->proc.threadPool.oldestRequests=NULL;
eNB->proc.threadPool.newestRequests=NULL;
eNB->proc.threadPool.doneRequests=NULL;
eNB->proc.threadPool.notFinishedJobs=0;
}
}
AssertFatal(pthread_mutex_unlock(&eNB->proc.threadPool.lockReportDone)==0,"");
mutexunlock(eNB->proc.threadPool.lockReportDone);
request_t* tmp;
while ((tmp=eNB->proc.threadPool.doneRequests)!=NULL) {
......@@ -698,15 +709,15 @@ void prach_procedures(PHY_VARS_eNB *eNB,
for (i=0;i<eNB->num_RU;i++) {
for (i=0; i<eNB->num_RU; i++) {
ru=eNB->RU_list[i];
for (ru_aa=0,aa=0;ru_aa<ru->nb_rx;ru_aa++,aa++) {
for (ru_aa=0,aa=0; ru_aa<ru->nb_rx; ru_aa++,aa++) {
eNB->prach_vars.rxsigF[0][aa] = eNB->RU_list[i]->prach_rxsigF[ru_aa];
#ifdef Rel14
int ce_level;
if (br_flag==1)
for (ce_level=0;ce_level<4;ce_level++) eNB->prach_vars_br.rxsigF[ce_level][aa] = eNB->RU_list[i]->prach_rxsigF_br[ce_level][ru_aa];
for (ce_level=0; ce_level<4; ce_level++) eNB->prach_vars_br.rxsigF[ce_level][aa] = eNB->RU_list[i]->prach_rxsigF_br[ce_level][ru_aa];
#endif
}
}
......@@ -749,7 +760,7 @@ void prach_procedures(PHY_VARS_eNB *eNB,
(eNB->prach_vars_br.repetition_number[ce_level]==
eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level])) {
*/
if (eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0]==1){
if (eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0]==1) {
if ((eNB->prach_energy_counter == 100) &&
(max_preamble_energy[0] > eNB->measurements.prach_I0 + 100)) {
eNB->UL_INFO.rach_ind_br.rach_indication_body.number_of_preambles++;
......@@ -850,7 +861,7 @@ void srs_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
// Do SRS processing
// check if there is SRS and we have to use shortened format
// TODO: check for exceptions in transmission of SRS together with ACK/NACK
for (i=0;i<NUMBER_OF_UE_MAX;i++) {
for (i=0; i<NUMBER_OF_UE_MAX; i++) {
if (eNB->soundingrs_ul_config_dedicated[i].active==1) {
......@@ -903,7 +914,7 @@ void fill_sr_indication(PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int subframe,u
void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
{
LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
uint8_t SR_payload = 0,pucch_b0b1[4][2]= {{0,0},{0,0},{0,0},{0,0}},harq_ack[4]={0,0,0,0};
uint8_t SR_payload = 0,pucch_b0b1[4][2]= {{0,0},{0,0},{0,0},{0,0}},harq_ack[4]= {0,0,0,0};
int32_t metric[4]= {0,0,0,0},metric_SR=0,max_metric=0;
const int subframe = proc->subframe_rx;
const int frame = proc->frame_rx;
......@@ -912,7 +923,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
uint16_t tdd_multiplexing_mask=0;
int res;
for (i=0;i<NUMBER_OF_UE_MAX;i++) {
for (i=0; i<NUMBER_OF_UE_MAX; i++) {
uci = &eNB->uci_vars[i];
if ((uci->active == 1) &&
......@@ -1065,7 +1076,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
uci->n_pucch_1[res][3],
uci->pucch_fmt);
#endif
for (res=0;res<uci->num_pucch_resources;res++)
for (res=0; res<uci->num_pucch_resources; res++)
metric[res] = rx_pucch(eNB,
uci->pucch_fmt,
i,
......@@ -1101,7 +1112,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
uci->stat = metric[0];
fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,2,0xffff); // special_bundling mode
}
else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==2)){ // multiplexing + no SR, implement Table 10.1.3-5 (Rel14) for multiplexing with M=2
else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==2)) { // multiplexing + no SR, implement Table 10.1.3-5 (Rel14) for multiplexing with M=2
if (pucch_b0b1[0][0] == 4 ||
pucch_b0b1[1][0] == 4) { // there isn't a likely transmission
harq_ack[0] = 4; // DTX
......@@ -1109,12 +1120,12 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
}
else {
if (metric[1]>metric[0]) {
if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 1; // ACK
tdd_multiplexing_mask = 0x3;
}
else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1){
else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1) {
harq_ack[0] = 6; // NACK/DTX
harq_ack[1] = 1; // ACK
tdd_multiplexing_mask = 0x2;
......@@ -1125,12 +1136,12 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
}
}
else {
if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 6; // NACK/DTX
tdd_multiplexing_mask = 0x1;
}
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1) {
harq_ack[0] = 2; // NACK
harq_ack[1] = 6; // NACK/DTX
}
......@@ -1143,7 +1154,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
uci->stat = max(metric[0],metric[1]);
fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
} //else if ((uci->tdd_bundling == 0) && (res==2))
else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==3)){ // multiplexing + no SR, implement Table 10.1.3-6 (Rel14) for multiplexing with M=3
else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==3)) { // multiplexing + no SR, implement Table 10.1.3-6 (Rel14) for multiplexing with M=3
if (harq_ack[0] == 4 ||
harq_ack[1] == 4 ||
......@@ -1158,13 +1169,13 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
max_metric = max(metric[0],max(metric[1],metric[2]));
if (metric[0]==max_metric) {
if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 6; // NACK/DTX
harq_ack[2] = 6; // NACK/DTX
tdd_multiplexing_mask = 0x1;
}
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1) {
harq_ack[0] = 2; // NACK
harq_ack[1] = 6; // NACK/DTX
harq_ack[2] = 6; // NACK/DTX
......@@ -1177,7 +1188,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
} // if (metric[0]==max_metric) {
else if (metric[1]==max_metric) {
if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 1; // ACK
harq_ack[2] = 6; // NACK/DTX
......@@ -1196,7 +1207,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
}
} // if (metric[1]==max_metric) {
else {
if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 1; // ACK
harq_ack[2] = 1; // ACK
......@@ -1225,7 +1236,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
}
} //else if ((uci->tdd_bundling == 0) && (res==3))
else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==4)){ // multiplexing + no SR, implement Table 10.1.3-7 (Rel14) for multiplexing with M=4
else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==4)) { // multiplexing + no SR, implement Table 10.1.3-7 (Rel14) for multiplexing with M=4
if (pucch_b0b1[0][0] == 4 ||
pucch_b0b1[1][0] == 4 ||
pucch_b0b1[2][0] == 4 ||
......@@ -1240,27 +1251,27 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
max_metric = max(metric[0],max(metric[1],max(metric[2],metric[3])));
if (metric[0]==max_metric) {
if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] != 1){
if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] != 1) {
harq_ack[0] = 2; // NACK
harq_ack[1] = 4; // DTX
harq_ack[2] = 4; // DTX
harq_ack[3] = 4; // DTX
}
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] == 1){
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 6; // NACK/DTX
harq_ack[2] = 6; // NACK/DTX
harq_ack[3] = 1; // ACK
tdd_multiplexing_mask = 0x9;
}
else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 6; // NACK/DTX
harq_ack[2] = 6; // NACK/DTX
harq_ack[3] = 6; // NACK/DTX
tdd_multiplexing_mask = 0x1;
}
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1) {
harq_ack[0] = 2; // NACK
harq_ack[1] = 6; // NACK/DTX
harq_ack[2] = 6; // NACK/DTX
......@@ -1269,7 +1280,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
}
else if (metric[1]==max_metric) {
if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] == 1){
if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 1; // ACK
harq_ack[2] = 1; // ACK
......@@ -1299,7 +1310,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
}
}
else if (metric[2]==max_metric) {
if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 1; // ACK
harq_ack[2] = 1; // ACK
......@@ -1329,7 +1340,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
}
}
else { // max_metric[3]=max_metric
if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1) {
harq_ack[0] = 1; // ACK
harq_ack[1] = 6; // NACK/DTX
harq_ack[2] = 1; // ACK
......@@ -1423,13 +1434,16 @@ void post_decode(request_t* decodeResult) {
union turboReqUnion idInFailure= {.p=decodeResult->id};
rnti_t rntiInFailure=idInFailure.s.rnti;
tpool_t * tp=&eNB->proc.threadPool;
AssertFatal(pthread_mutex_lock(&tp->lockRequests)==0,"");
mutexlock(tp->lockRequests);
request_t* pending=NULL;
while ( (pending=searchRNTI(tp, rntiInFailure)) != NULL) {
LOG_W(MAC,"removing a CB belonging to a bad TPU");
freeRequest(pending);
mutexlock(tp->lockReportDone);
tp->notFinishedJobs--;
mutexunlock(tp->lockReportDone);
}
AssertFatal(pthread_mutex_unlock(&tp->lockRequests)==0,"");
mutexunlock(tp->lockRequests);
}
}
......@@ -1490,8 +1504,12 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
else
harq_pid = subframe%10;
if (eNB->proc.threadPool.notFinishedJobs != 0 )
LOG_E(PHY,"no finisehd = %d\n",eNB->proc.threadPool.notFinishedJobs);
if (eNB->proc.threadPool.notFinishedJobs != 0 ||
eNB->proc.threadPool.oldestRequests != NULL ||
eNB->proc.threadPool.newestRequests != NULL ||
eNB->proc.threadPool.doneRequests != NULL
)
LOG_E(PHY,"no finished = %d\n",eNB->proc.threadPool.notFinishedJobs);
for (int i=0; i<NUMBER_OF_UE_MAX; i++) {
LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[i];
LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
......@@ -1548,26 +1566,30 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
if ( eNB->proc.threadPool.activated ) {
// Wait all other threads finish to process
//printf("%s:%d:%d\n", __FILE__,__LINE__,eNB->proc.threadPool.notFinishedJobs);
AssertFatal(pthread_mutex_lock(&eNB->proc.threadPool.lockReportDone)==0,"");
int rr=0;
mutexlock(eNB->proc.threadPool.lockReportDone);
while ( eNB->proc.threadPool.notFinishedJobs > 0 ) {
//printf("%s:%d:%d\n", __FILE__,__LINE__,eNB->proc.threadPool.notFinishedJobs);
struct timespec t;
clock_gettime(CLOCK_REALTIME,&t);
t.tv_nsec+=100*1000*1000;
t.tv_nsec+=1*1000*1000;
if ( t.tv_nsec >= 1000*1000*1000 ) {
t.tv_nsec -= 1000*1000*1000;
t.tv_sec++;
}
int rr;
if ((rr=pthread_cond_timedwait(&eNB->proc.threadPool.notifDone,&eNB->proc.threadPool.lockReportDone, &t))!=0)
if ((rr=pthread_cond_timedwait(&eNB->proc.threadPool.notifDone,&eNB->proc.threadPool.lockReportDone, &t))!=0) {
LOG_E(PHY,"timedwait1:%s,%p,%p,%p,%d\n", rr==ETIMEDOUT?"ETIMEDOUT":"other",
eNB->proc.threadPool.oldestRequests,
eNB->proc.threadPool.newestRequests,
eNB->proc.threadPool.doneRequests,
eNB->proc.threadPool.notFinishedJobs);
eNB->proc.threadPool.oldestRequests=NULL;
eNB->proc.threadPool.newestRequests=NULL;
eNB->proc.threadPool.doneRequests=NULL;
eNB->proc.threadPool.notFinishedJobs=0;
}
}
AssertFatal(pthread_mutex_unlock(&eNB->proc.threadPool.lockReportDone)==0,"");
mutexunlock(eNB->proc.threadPool.lockReportDone);
request_t* tmp;
while ((tmp=eNB->proc.threadPool.doneRequests)!=NULL) {
......@@ -1841,7 +1863,7 @@ void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,
pdu->harq_indication_fdd_rel13.mode = 0;
pdu->harq_indication_fdd_rel13.number_of_ack_nack = ulsch_harq->O_ACK;
for (i=0;i<ulsch_harq->O_ACK;i++) {
for (i=0; i<ulsch_harq->O_ACK; i++) {
AssertFatal(ulsch_harq->o_ACK[i] == 0 || ulsch_harq->o_ACK[i] == 1, "harq_ack[%d] is %d, should be 1,2 or 4\n",i,ulsch_harq->o_ACK[i]);
pdu->harq_indication_fdd_rel13.harq_tb_n[i] = 2-ulsch_harq->o_ACK[i];
......@@ -1867,7 +1889,7 @@ void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,
pdu->harq_indication_tdd_rel13.mode = 1-bundling;
pdu->harq_indication_tdd_rel13.number_of_ack_nack = ulsch_harq->O_ACK;
for (i=0;i<ulsch_harq->O_ACK;i++) {
for (i=0; i<ulsch_harq->O_ACK; i++) {
AssertFatal(ulsch_harq->o_ACK[i] == 0 || ulsch_harq->o_ACK[i] == 1, "harq_ack[%d] is %d, should be 1,2 or 4\n",i,ulsch_harq->o_ACK[i]);
pdu->harq_indication_tdd_rel13.harq_data[0].multiplex.value_0 = 2-ulsch_harq->o_ACK[i];
......@@ -2146,7 +2168,7 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
int min_I0=1000,max_I0=0;
if ((frame==0) && (subframe==6)) {
for (int i=0;i<eNB->frame_parms.N_RB_UL;i++) {
for (int i=0; i<eNB->frame_parms.N_RB_UL; i++) {
if (i==(eNB->frame_parms.N_RB_UL>>1) - 1) i+=2;
if (eNB->measurements.n0_subband_power_tot_dB[i]<min_I0) min_I0 = eNB->measurements.n0_subband_power_tot_dB[i];
......
......@@ -38,11 +38,13 @@ request_t * createRequest(enum request_t type,int size) {
}
void freeRequest(request_t* request) {
//printf("freeing: %ld, %p\n", request->id, request);
free(request);
}
volatile int ii=0;
int add_request(request_t* request, tpool_t * tp) {
AssertFatal(pthread_mutex_lock(&tp->lockRequests)==0,"");
mutexlock(tp->lockRequests);
if (tp->oldestRequests == NULL)
tp->oldestRequests = request;
else {
......@@ -50,22 +52,22 @@ int add_request(request_t* request, tpool_t * tp) {
tp->newestRequests->next = request;
}
tp->newestRequests = request;
AssertFatal(pthread_mutex_lock(&tp->lockReportDone)==0,"");
mutexlock(tp->lockReportDone);
tp->notFinishedJobs++;
//printf("added:%d\n", tp->notFinishedJobs);
AssertFatal(pthread_mutex_unlock(&tp->lockReportDone)==0,"");
AssertFatal(pthread_cond_broadcast(&tp->notifRequest)==0,"");
AssertFatal(pthread_mutex_unlock(&tp->lockRequests)==0,"");
mutexunlock(tp->lockReportDone);
condbroadcast(tp->notifRequest);
mutexunlock(tp->lockRequests);
return 0;
}
int add_requests(uint64_t request_num, tpool_t * tp) {
request_t* request;
int nbToAdd=((uint32_t)lrand48())%20+1;
mutexlock(tp->lockRequests);
for (int i=0; i<nbToAdd; i++) {
// simulate request
request=createRequest(DECODE,sizeof(turboDecode_t));
union turboReqUnion id= {.s={request_num*100+i,1000,i*10,111,222}};
union turboReqUnion id= {.s={request_num,1000,i*10,111,222}};
request->id= id.p;
turboDecode_t * rdata=(turboDecode_t *) request->data;
rdata->function=phy_threegpplte_turbo_decoder8;
......@@ -80,6 +82,11 @@ int add_requests(uint64_t request_num, tpool_t * tp) {
tp->newestRequests = request;
}
mutexlock(tp->lockReportDone);
tp->notFinishedJobs+=nbToAdd;
mutexunlock(tp->lockReportDone);
condbroadcast(tp->notifRequest);
mutexunlock(tp->lockRequests);
return nbToAdd;
}
......@@ -117,8 +124,10 @@ request_t * get_request(tpool_t * tp, uint16_t threadID ) {
nnb++;
r=r->next;
}
//if ( ! ( nb == nnb && request == NULL))
//printf("getr:was=%d,is=%d,gotit=%p\n",nb,nnb,request);
/*
if ( ! ( nb == nnb && request == NULL))
printf("getr:was=%d,is=%d,gotit=%p\n",nb,nnb,request);
*/
return request;
}
......@@ -185,15 +194,12 @@ void handle_request(tpool_t * tp, request_t* request) {
request->startProcessingTime=rdtsc();
process_request(request);
request->endProcessingTime=rdtsc();
AssertFatal(pthread_mutex_lock(&tp->lockReportDone)==0,"");
mutexlock(tp->lockReportDone);
tp->notFinishedJobs--;
//printf("Removed:%d\n",tp->notFinishedJobs);
request->next=tp->doneRequests;
tp->doneRequests=request;
//printf("signaling ...");
AssertFatal(pthread_cond_signal(&tp->notifDone)==0,"");
//printf("...done\n");
AssertFatal(pthread_mutex_unlock(&tp->lockReportDone)==0,"");
condsignal(tp->notifDone);
mutexunlock(tp->lockReportDone);
/*
printf("Thread '%ld' handled request '%d' delay in µs:%ld\n",
syscall( SYS_gettid ),
......@@ -224,13 +230,16 @@ void* one_thread(void* data) {
// Infinite loop to process requests
do {
AssertFatal(pthread_mutex_lock(&tp->lockRequests)==0,"");
mutexlock(tp->lockRequests);
request_t* request = get_request(tp, myThread->id);
if (request == NULL) {
AssertFatal(pthread_cond_wait(&tp->notifRequest,&tp->lockRequests)==0,"");
condwait(tp->notifRequest,tp->lockRequests);
request = get_request(tp, myThread->id);
}
AssertFatal(pthread_mutex_unlock(&tp->lockRequests)==0,"");
mutexunlock(tp->lockRequests);
if (request!=NULL) {
strncpy(request->processedBy,myThread->name, 15);
request->coreId=myThread->coreID;
......@@ -258,10 +267,11 @@ void init_tpool(char * params,tpool_t * pool) {
sparam.sched_priority = sched_get_priority_max(SCHED_RR)-1;
pthread_setschedparam(pthread_self(), SCHED_RR, &sparam);
pool->activated=true;
pthread_mutex_init(&pool->lockRequests,NULL);
pthread_cond_init (&pool->notifRequest,NULL);
pthread_mutex_init(&pool->lockReportDone,NULL);
pthread_cond_init (&pool->notifDone,NULL);
mutexinit(pool->lockRequests);
condinit (pool->notifRequest);
pool->notifCount=0;
mutexinit(pool->lockReportDone);
condinit (pool->notifDone);
pool->oldestRequests=NULL;
pool->newestRequests=NULL;
pool->doneRequests=NULL;
......@@ -346,12 +356,11 @@ int main(int argc, char* argv[]) {
uint64_t i=1;
// Test the lists
srand48(time(NULL));
AssertFatal(pthread_mutex_lock(&pool.lockRequests)==0,"");
int nbRequest=add_requests(i, &pool);
printf("These should be: %d elements in the list\n",nbRequest);
displayList(pool.oldestRequests, pool.newestRequests);
// remove in middle
request_t *req106=searchRNTI(&pool.oldestRequests, &pool.newestRequests, 106);
request_t *req106=searchRNTI(&pool, 106);
if (req106) {
union turboReqUnion id= {.p=req106->id};
printf("Removed: rnti:%u frame:%u-%u codeblock:%u, check it\n",
......@@ -363,8 +372,7 @@ int main(int argc, char* argv[]) {
} else
printf("no rnti 106\n");
displayList(pool.oldestRequests, pool.newestRequests);
request_t *reqlast=searchRNTI(&pool.oldestRequests, &pool.newestRequests,
100+nbRequest-1);
request_t *reqlast=searchRNTI(&pool, 100+nbRequest-1);
if (reqlast) {
printf("Removed last item, check it\n");
freeRequest(reqlast);
......@@ -373,49 +381,59 @@ int main(int argc, char* argv[]) {
displayList(pool.oldestRequests, pool.newestRequests);
printf("Remove all jobs\n");
while(pool.oldestRequests!=NULL)
get_request(&pool);
get_request(&pool,0);
printf("List should be empty now\n");
displayList(pool.oldestRequests, pool.newestRequests);
AssertFatal(pthread_mutex_unlock(&pool.lockRequests)==0,"");
sleep(1);
mutexlock(pool.lockReportDone);
pool.notFinishedJobs=0;
pool.doneRequests=NULL;
mutexunlock(pool.lockReportDone);
while (1) {
uint64_t now=rdtsc();
/* run a loop that generates a lot of requests */
AssertFatal(pthread_mutex_lock(&pool.lockRequests)==0,"");
int nbRequest=add_requests(i, &pool);
AssertFatal(pthread_mutex_lock(&pool.lockReportDone)==0,"");
pool.notFinishedJobs+=nbRequest;
AssertFatal(pthread_mutex_unlock(&pool.lockReportDone)==0,"");
AssertFatal(pthread_cond_broadcast(&pool.notifRequest)==0,"");
AssertFatal(pthread_mutex_unlock(&pool.lockRequests)==0,"");
AssertFatal(pool.notFinishedJobs==0,"");
int n=add_requests(i, &pool);
printf("Added %d requests\n",n);
/*
// The main thread also process the queue
AssertFatal(pthread_mutex_lock(&pool.lockRequests)==0,"");
mutexlock(pool.lockRequests);
request_t* request= NULL;
while ( (request=get_request(&pool)) != NULL ) {
AssertFatal(pthread_mutex_unlock(&pool.lockRequests)==0,"");
while ( (request=get_request(&pool,0)) != NULL ) {
mutexunlock(pool.lockRequests);
strcpy(request->processedBy,"MainThread");
handle_request(&pool, request);
AssertFatal(pthread_mutex_lock(&pool.lockRequests)==0,"");
mutexlock(pool.lockRequests);
}
AssertFatal(pthread_mutex_unlock(&pool.lockRequests)==0,"");
mutexunlock(pool.lockRequests);
*/
// Wait all other threads finish to process
AssertFatal(pthread_mutex_lock(&pool.lockReportDone)==0,"");
mutexlock(pool.lockReportDone);
while ( pool.notFinishedJobs > 0 ) {
AssertFatal(pthread_cond_wait(&pool.notifDone,&pool.lockReportDone)==0,"");
condwait(pool.notifDone,pool.lockReportDone);
}
mutexunlock(pool.lockReportDone);
int i=0;
for (request_t* ptr=pool.doneRequests; ptr!=NULL; ptr=ptr->next) {
i++;
//printf("in return: %ld, %p\n", ptr->id, ptr);
}
AssertFatal(pthread_mutex_unlock(&pool.lockReportDone)==0,"");
AssertFatal(i==n,"%d/%d\n",i,n);
while (pool.doneRequests!=NULL) {
pool.doneRequests->returnTime=rdtsc();
if(write(pool.traceFd,pool.doneRequests,sizeof(request_t))) {};
if(write(pool.traceFd,pool.doneRequests,sizeof(request_t)- 2*sizeof(void*))) {};
request_t* tmp=pool.doneRequests;
pool.doneRequests=pool.doneRequests->next;
free(tmp);
freeRequest(tmp);
}
printf("Requests %lu Done %d requests in %ld µsec\n",i, nbRequest, (rdtsc()-now)/pool.cpuCyclesMicroSec);
printf("Requests %d Done in %ld µsec\n",i, (rdtsc()-now)/pool.cpuCyclesMicroSec);
i++;
};
return 0;
......
#ifndef THREAD_POOL_H
#define THREAD_POOL_H
#include <stdbool.h>
#include <sys/syscall.h>
#include <openair2/COMMON/platform_types.h>
enum request_t {
......@@ -48,6 +49,7 @@ typedef struct thread_pool {
int activated;
pthread_mutex_t lockRequests;
pthread_cond_t notifRequest;
int notifCount;
pthread_mutex_t lockReportDone;
pthread_cond_t notifDone;
request_t* oldestRequests;
......@@ -62,6 +64,18 @@ typedef struct thread_pool {
struct one_thread * allthreads;
} tpool_t;
#define mutexinit(mutex) AssertFatal(pthread_mutex_init(&mutex,NULL)==0,"");
#define condinit(signal) AssertFatal(pthread_cond_init(&signal,NULL)==0,"");
//#define mutexlock(mutex) printf("L:" #mutex __FILE__ ":%d, thread %d\n", __LINE__, syscall( SYS_gettid )); AssertFatal(pthread_mutex_lock(&mutex)==0,"");
//#define mutexunlock(mutex) printf("U:" #mutex __FILE__ ":%d, thread:%d\n", __LINE__, syscall( SYS_gettid )); AssertFatal(pthread_mutex_unlock(&mutex)==0,"");
#define mutexlock(mutex) AssertFatal(pthread_mutex_lock(&mutex)==0,"");
#define mutexunlock(mutex) AssertFatal(pthread_mutex_unlock(&mutex)==0,"");
#define condwait(condition, mutex) AssertFatal(pthread_cond_wait(&condition, &mutex)==0,"");
#define condbroadcast(signal) AssertFatal(pthread_cond_broadcast(&signal)==0,"");
#define condsignal(signal) AssertFatal(pthread_cond_broadcast(&signal)==0,"");
void init_tpool(char*,tpool_t* );
request_t * createRequest(enum request_t type,int size);
void freeRequest(request_t* request);
......
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