Commit 129d4833 authored by laurent's avatar laurent

more fixes in mutext

parent 5e47fa4d
/* /*
Author: Laurent THOMAS, Open Cells for Nokia Author: Laurent THOMAS, Open Cells for Nokia
copyleft: OpenAirInterface Software Alliance and it's licence copyleft: OpenAirInterface Software Alliance and it's licence
...@@ -326,7 +325,6 @@ bool flushInput(rfsimulator_state_t *t) { ...@@ -326,7 +325,6 @@ bool flushInput(rfsimulator_state_t *t) {
return nfds>0; return nfds>0;
} }
int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, void **samplesVoid, int nsamps, int nbAnt) { int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, void **samplesVoid, int nsamps, int nbAnt) {
if (nbAnt != 1) { LOG_E(HW, "rfsimulator: only 1 antenna tested\n"); exit(1); } if (nbAnt != 1) { LOG_E(HW, "rfsimulator: only 1 antenna tested\n"); exit(1); }
...@@ -413,6 +411,7 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo ...@@ -413,6 +411,7 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
return nsamps; return nsamps;
} }
int rfsimulator_request(openair0_device *device, void *msg, ssize_t msg_len) { int rfsimulator_request(openair0_device *device, void *msg, ssize_t msg_len) {
abort(); abort();
return 0; return 0;
...@@ -442,6 +441,7 @@ int rfsimulator_set_gains(openair0_device *device, openair0_config_t *openair0_c ...@@ -442,6 +441,7 @@ int rfsimulator_set_gains(openair0_device *device, openair0_config_t *openair0_c
__attribute__((__visibility__("default"))) __attribute__((__visibility__("default")))
int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
//set_log(HW,OAILOG_DEBUG); //set_log(HW,OAILOG_DEBUG);
//set_log(PHY,OAILOG_DEBUG);
rfsimulator_state_t *rfsimulator = (rfsimulator_state_t *)calloc(sizeof(rfsimulator_state_t),1); rfsimulator_state_t *rfsimulator = (rfsimulator_state_t *)calloc(sizeof(rfsimulator_state_t),1);
if ((rfsimulator->ip=getenv("RFSIMULATOR")) == NULL ) { if ((rfsimulator->ip=getenv("RFSIMULATOR")) == NULL ) {
......
...@@ -544,7 +544,7 @@ static void *UE_thread_synch(void *arg) ...@@ -544,7 +544,7 @@ static void *UE_thread_synch(void *arg)
while (UE->proc.instance_cnt_synch < 0) while (UE->proc.instance_cnt_synch < 0)
// the thread waits here most of the time // the thread waits here most of the time
pthread_cond_wait( &UE->proc.cond_synch, &UE->proc.mutex_synch ); pthread_cond_wait( &UE->proc.cond_synch, &UE->proc.mutex_synch );
AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), "");
LOG_I(PHY,"Starting a sync process\n"); LOG_I(PHY,"Starting a sync process\n");
switch (sync_mode) { switch (sync_mode) {
case pss: case pss:
...@@ -647,9 +647,7 @@ static void *UE_thread_synch(void *arg) ...@@ -647,9 +647,7 @@ static void *UE_thread_synch(void *arg)
UE->UE_scan_carrier = 0; UE->UE_scan_carrier = 0;
} else { } else {
AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), "");
UE->is_synchronized = 1; UE->is_synchronized = 1;
AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), "");
if( UE->mode == rx_dump_frame ) { if( UE->mode == rx_dump_frame ) {
FILE *fd; FILE *fd;
...@@ -667,10 +665,7 @@ static void *UE_thread_synch(void *arg) ...@@ -667,10 +665,7 @@ static void *UE_thread_synch(void *arg)
exit(0); exit(0);
} }
} else { } else {
AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), "");
UE->is_synchronized = 0; UE->is_synchronized = 0;
AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), "");
} }
} }
} }
...@@ -719,7 +714,6 @@ static void *UE_thread_synch(void *arg) ...@@ -719,7 +714,6 @@ static void *UE_thread_synch(void *arg)
break; break;
} }
AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), "");
// indicate readiness // indicate readiness
UE->proc.instance_cnt_synch--; UE->proc.instance_cnt_synch--;
AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), "");
...@@ -773,18 +767,10 @@ static void *UE_thread_rxn_txnp4(void *arg) { ...@@ -773,18 +767,10 @@ static void *UE_thread_rxn_txnp4(void *arg) {
threadname); threadname);
while (!oai_exit) { while (!oai_exit) {
if (pthread_mutex_lock(&proc->mutex_rxtx) != 0) { AssertFatal(pthread_mutex_lock(&proc->mutex_rxtx) == 0, "[SCHED][UE] error locking mutex for UE RXTX\n" );
LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" ); while (proc->instance_cnt_rxtx < 0)
exit_fun("nothing to add");
}
while (proc->instance_cnt_rxtx < 0) {
// most of the time, the thread is waiting here // most of the time, the thread is waiting here
pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx ); pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx );
}
if (pthread_mutex_unlock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE RXn_TXnp4\n" );
exit_fun("nothing to add");
}
initRefTimes(t2); initRefTimes(t2);
initRefTimes(t3); initRefTimes(t3);
...@@ -858,18 +844,8 @@ static void *UE_thread_rxn_txnp4(void *arg) { ...@@ -858,18 +844,8 @@ static void *UE_thread_rxn_txnp4(void *arg) {
phy_procedures_UE_S_TX(UE,0,0); phy_procedures_UE_S_TX(UE,0,0);
updateTimes(current, &t3, 10000, "Delay to process sub-frame (case 3)"); updateTimes(current, &t3, 10000, "Delay to process sub-frame (case 3)");
if (pthread_mutex_lock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" );
exit_fun("noting to add");
}
proc->instance_cnt_rxtx--; proc->instance_cnt_rxtx--;
#if BASIC_SIMULATOR AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, "[SCHED][UE] error unlocking mutex for UE RXTX\n" );
if (pthread_cond_signal(&proc->cond_rxtx) != 0) abort();
#endif
if (pthread_mutex_unlock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE RXTX\n" );
exit_fun("noting to add");
}
} }
// thread finished // thread finished
...@@ -1557,35 +1533,26 @@ void *UE_thread(void *arg) { ...@@ -1557,35 +1533,26 @@ void *UE_thread(void *arg) {
oai_exit=1; oai_exit=1;
} }
UE_rxtx_proc_t *proc=UE->proc.proc_rxtx;
while (!oai_exit) { while (!oai_exit) {
#if BASIC_SIMULATOR
while (!(UE->proc.instance_cnt_synch < 0)) {
printf("ue sync not ready\n");
usleep(500*1000);
}
#endif
AssertFatal ( 0 == pthread_mutex_lock(&UE->proc.mutex_synch), "");
int instance_cnt_synch = UE->proc.instance_cnt_synch;
int is_synchronized = UE->is_synchronized;
AssertFatal ( 0 == pthread_mutex_unlock(&UE->proc.mutex_synch), "");
if (is_synchronized == 0) { if ( pthread_mutex_trylock(&UE->proc.mutex_synch) != 0 ) {
if (instance_cnt_synch < 0) { // we can invoke the synch // a sync detection is running
// grab 10 ms of signal and wakeup synch thread // grab 10 ms of signal into dummy buffer to wait result of sync detection
if (UE->mode != loop_through_memory) { if (UE->mode != loop_through_memory) {
void *dummy_tx[UE->frame_parms.nb_antennas_tx]; void *dummy_tx[UE->frame_parms.nb_antennas_tx];
for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_tti*4); dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_tti*4);
for(int x=0; x<10; x++) { void *dummy_rx[UE->frame_parms.nb_antennas_rx];
for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++)
rxp[i] = ((void*)&UE->common_vars.rxdata[i][0]) + 4*x*UE->frame_parms.samples_per_tti; dummy_rx[i]=malloc16(UE->frame_parms.samples_per_tti*4);
AssertFatal( UE->frame_parms.samples_per_tti == for (int sf=0; sf<10; sf++) {
// printf("Reading dummy sf %d\n",sf);
UE->rfdevice.trx_read_func(&UE->rfdevice, UE->rfdevice.trx_read_func(&UE->rfdevice,
&timestamp, &timestamp,
rxp, dummy_rx,
UE->frame_parms.samples_per_tti, UE->frame_parms.samples_per_tti,
UE->frame_parms.nb_antennas_rx), ""); UE->frame_parms.nb_antennas_rx);
AssertFatal( UE->frame_parms.samples_per_tti == AssertFatal( UE->frame_parms.samples_per_tti ==
UE->rfdevice.trx_write_func(&UE->rfdevice, UE->rfdevice.trx_write_func(&UE->rfdevice,
timestamp+(2*UE->frame_parms.samples_per_tti) - timestamp+(2*UE->frame_parms.samples_per_tti) -
...@@ -1597,27 +1564,28 @@ void *UE_thread(void *arg) { ...@@ -1597,27 +1564,28 @@ void *UE_thread(void *arg) {
} }
for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
free(dummy_tx[i]); free(dummy_tx[i]);
for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++)
free(dummy_rx[i]);
} }
AssertFatal( 0 == pthread_mutex_lock(&UE->proc.mutex_synch), ""); usleep(1000); // relax time when I/Q acquisition is not realtime (simulators)
AssertFatal( 0 == ++UE->proc.instance_cnt_synch, "[SCHED][UE] UE sync thread busy!!\n" ); continue;
AssertFatal( 0 == pthread_cond_signal(&UE->proc.cond_synch), ""); }
AssertFatal( 0 == pthread_mutex_unlock(&UE->proc.mutex_synch), "");
} else { if (UE->is_synchronized == 0) {
// grab 10 ms of signal into dummy buffer to wait result of sync detection // grab 10 ms of signal and wakeup synch thread
if (UE->mode != loop_through_memory) { if (UE->mode != loop_through_memory) {
void *dummy_tx[UE->frame_parms.nb_antennas_tx]; void *dummy_tx[UE->frame_parms.nb_antennas_tx];
for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_tti*4); dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_tti*4);
void *dummy_rx[UE->frame_parms.nb_antennas_rx]; for(int x=0; x<10; x++) {
for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++)
dummy_rx[i]=malloc16(UE->frame_parms.samples_per_tti*4); rxp[i] = ((void*)&UE->common_vars.rxdata[i][0]) + 4*x*UE->frame_parms.samples_per_tti;
for (int sf=0; sf<10; sf++) { AssertFatal( UE->frame_parms.samples_per_tti ==
// printf("Reading dummy sf %d\n",sf);
UE->rfdevice.trx_read_func(&UE->rfdevice, UE->rfdevice.trx_read_func(&UE->rfdevice,
&timestamp, &timestamp,
dummy_rx, rxp,
UE->frame_parms.samples_per_tti, UE->frame_parms.samples_per_tti,
UE->frame_parms.nb_antennas_rx); UE->frame_parms.nb_antennas_rx), "");
AssertFatal( UE->frame_parms.samples_per_tti == AssertFatal( UE->frame_parms.samples_per_tti ==
UE->rfdevice.trx_write_func(&UE->rfdevice, UE->rfdevice.trx_write_func(&UE->rfdevice,
timestamp+(2*UE->frame_parms.samples_per_tti) - timestamp+(2*UE->frame_parms.samples_per_tti) -
...@@ -1626,18 +1594,20 @@ void *UE_thread(void *arg) { ...@@ -1626,18 +1594,20 @@ void *UE_thread(void *arg) {
UE->frame_parms.samples_per_tti, UE->frame_parms.samples_per_tti,
UE->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_tx,
1),""); 1),"");
usleep(900); // this sleep improves in the case of simulated RF and doesn't harm with true radio
} }
for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
free(dummy_tx[i]); free(dummy_tx[i]);
for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++)
free(dummy_rx[i]);
}
} }
UE->proc.instance_cnt_synch=0;
AssertFatal( 0 == pthread_cond_signal(&UE->proc.cond_synch), "");
AssertFatal( 0 == pthread_mutex_unlock(&UE->proc.mutex_synch), "");
continue;
} // UE->is_synchronized==0 } // UE->is_synchronized==0
else {
// UE is synchronized
AssertFatal( 0 == pthread_mutex_unlock(&UE->proc.mutex_synch), "");
// A specific processing for first sub-frame after synchro
if (start_rx_stream==0) { if (start_rx_stream==0) {
start_rx_stream=1; start_rx_stream=1;
if (UE->mode != loop_through_memory) { if (UE->mode != loop_through_memory) {
...@@ -1685,32 +1655,33 @@ void *UE_thread(void *arg) { ...@@ -1685,32 +1655,33 @@ void *UE_thread(void *arg) {
} //UE->mode != loop_through_memory } //UE->mode != loop_through_memory
else else
rt_sleep_ns(1000*1000); rt_sleep_ns(1000*1000);
continue;
}
} else { // Normale subframe processing
sub_frame++; sub_frame= (sub_frame + 1 ) % 10;
sub_frame%=10; //Force wait in simulation because odd and even subframe processing threads seems to haverace conditions
UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[thread_idx]; AssertFatal(proc,"");
// update thread index for received subframe if ( getenv("RFSIMULATOR")) {
UE->current_thread_id[sub_frame] = thread_idx; bool ok;
do {
#if BASIC_SIMULATOR
{
int t;
for (t = 0; t < 2; t++) {
UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[t];
pthread_mutex_lock(&proc->mutex_rxtx); pthread_mutex_lock(&proc->mutex_rxtx);
while (proc->instance_cnt_rxtx >= 0) pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx ); ok=proc->instance_cnt_rxtx==-1;
pthread_mutex_unlock(&proc->mutex_rxtx); pthread_mutex_unlock(&proc->mutex_rxtx);
} while (!ok);
} }
} #if BASIC_SIMULATOR
pthread_mutex_lock(&proc->mutex_rxtx);
pthread_mutex_unlock(&proc->mutex_rxtx);
#endif #endif
LOG_D(PHY,"Process Subframe %d thread Idx %d \n", sub_frame, UE->current_thread_id[sub_frame]); LOG_D(PHY,"Process Subframe %d thread Idx %d \n", sub_frame, UE->current_thread_id[sub_frame]);
proc = &UE->proc.proc_rxtx[thread_idx];
// update thread index for received subframe
UE->current_thread_id[sub_frame] = thread_idx;
thread_idx++; LOG_D(PHY,"Process Subframe %d thread Idx %d \n", sub_frame, UE->current_thread_id[sub_frame]);
if(thread_idx>=RX_NB_TH)
thread_idx = 0;
thread_idx= (thread_idx + 1 ) % RX_NB_TH;
if (UE->mode != loop_through_memory) { if (UE->mode != loop_through_memory) {
for (i=0; i<UE->frame_parms.nb_antennas_rx; i++) for (i=0; i<UE->frame_parms.nb_antennas_rx; i++)
rxp[i] = (void*)&UE->common_vars.rxdata[i][UE->frame_parms.ofdm_symbol_size+ rxp[i] = (void*)&UE->common_vars.rxdata[i][UE->frame_parms.ofdm_symbol_size+
...@@ -1731,9 +1702,6 @@ void *UE_thread(void *arg) { ...@@ -1731,9 +1702,6 @@ void *UE_thread(void *arg) {
// compute TO compensation that should be applied for this frame // compute TO compensation that should be applied for this frame
if (UE->no_timing_correction == 0) { if (UE->no_timing_correction == 0) {
if (getenv("RFSIMULATOR") != NULL && UE->rx_offset) {
LOG_W(HW,"in simu, rx_offset is not null: %d\n", UE->rx_offset);
}
if ( UE->rx_offset < 5*UE->frame_parms.samples_per_tti && if ( UE->rx_offset < 5*UE->frame_parms.samples_per_tti &&
UE->rx_offset > 0 ) UE->rx_offset > 0 )
UE->rx_offset_diff = -1 ; UE->rx_offset_diff = -1 ;
...@@ -1742,7 +1710,12 @@ void *UE_thread(void *arg) { ...@@ -1742,7 +1710,12 @@ void *UE_thread(void *arg) {
UE->rx_offset_diff = 1; UE->rx_offset_diff = 1;
} }
LOG_D(PHY,"AbsSubframe %d.%d SET rx_off_diff to %d rx_offset %d \n",proc->frame_rx,sub_frame,UE->rx_offset_diff,UE->rx_offset); LOG_D(PHY,"AbsSubframe %d.%d SET rx_off_diff to %d rx_offset %d \n",
proc->frame_rx,sub_frame,UE->rx_offset_diff,UE->rx_offset);
if (getenv("RFSIMULATOR") != NULL && UE->rx_offset) {
LOG_W(HW,"in simu, rx_offset is not null: %d\n", UE->rx_offset);
//UE->rx_offset_diff=0;
}
readBlockSize=UE->frame_parms.samples_per_tti - readBlockSize=UE->frame_parms.samples_per_tti -
UE->frame_parms.ofdm_symbol_size - UE->frame_parms.ofdm_symbol_size -
UE->frame_parms.nb_prefix_samples0 - UE->frame_parms.nb_prefix_samples0 -
...@@ -1784,7 +1757,11 @@ void *UE_thread(void *arg) { ...@@ -1784,7 +1757,11 @@ void *UE_thread(void *arg) {
} }
pickTime(gotIQs); pickTime(gotIQs);
// operate on thread sf mod 2 // operate on thread sf mod 2
AssertFatal(pthread_mutex_lock(&proc->mutex_rxtx) ==0,""); if (pthread_mutex_trylock(&proc->mutex_rxtx) != 0 ) {
LOG_E(PHY,"Real time issue in subframes processing, skipping subframe %d\n", proc->subframe_rx);
continue;
}
if(sub_frame == 0) { if(sub_frame == 0) {
//UE->proc.proc_rxtx[0].frame_rx++; //UE->proc.proc_rxtx[0].frame_rx++;
//UE->proc.proc_rxtx[1].frame_rx++; //UE->proc.proc_rxtx[1].frame_rx++;
...@@ -1804,23 +1781,7 @@ void *UE_thread(void *arg) { ...@@ -1804,23 +1781,7 @@ void *UE_thread(void *arg) {
(4*UE->frame_parms.samples_per_tti)- (4*UE->frame_parms.samples_per_tti)-
UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0;
proc->instance_cnt_rxtx++; proc->instance_cnt_rxtx=0;
LOG_D( PHY, "[SCHED][UE %d] UE RX instance_cnt_rxtx %d subframe %d !!\n", UE->Mod_id, proc->instance_cnt_rxtx,proc->subframe_rx);
if (proc->instance_cnt_rxtx != 0) {
if ( getenv("RFSIMULATOR") != NULL ) {
do {
AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, "");
usleep(100);
AssertFatal (pthread_mutex_lock(&proc->mutex_rxtx) == 0, "");
} while ( proc->instance_cnt_rxtx >= 0);
} else
LOG_E( PHY, "[SCHED][UE %d] UE RX thread busy (IC %d)!!\n", UE->Mod_id, proc->instance_cnt_rxtx);
if (proc->instance_cnt_rxtx > 2)
exit_fun("instance_cnt_rxtx > 2");
}
AssertFatal (pthread_cond_signal(&proc->cond_rxtx) ==0 ,""); AssertFatal (pthread_cond_signal(&proc->cond_rxtx) ==0 ,"");
AssertFatal(pthread_mutex_unlock(&proc->mutex_rxtx) ==0,""); AssertFatal(pthread_mutex_unlock(&proc->mutex_rxtx) ==0,"");
initRefTimes(t1); initRefTimes(t1);
...@@ -1832,10 +1793,7 @@ void *UE_thread(void *arg) { ...@@ -1832,10 +1793,7 @@ void *UE_thread(void *arg) {
printf("Processing subframe %d",proc->subframe_rx); printf("Processing subframe %d",proc->subframe_rx);
getchar(); getchar();
} }
} // start_rx_stream==1 }
} // UE->is_synchronized==1
} // while !oai_exit
return NULL; return NULL;
} }
......
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