Commit e3cbb609 authored by Joanne Hugé's avatar Joanne Hugé

Add offset feature for tracing

parent 977bcccf
...@@ -50,7 +50,9 @@ ...@@ -50,7 +50,9 @@
#define EFREQ 38400 #define EFREQ 38400
//#define DEBUG // Enables / deactivates log_debug //#define DEBUG // Enables / deactivates log_debug
//#define TRACE //#define TRACE 0
//#define TRACE_TX
//#define TRACE_RX
//#define MONITOR //#define MONITOR
//#define MONITOR_EXIT //#define MONITOR_EXIT
...@@ -160,7 +162,12 @@ static uint8_t pkt_frame_full[1024]; ...@@ -160,7 +162,12 @@ static uint8_t pkt_frame_full[1024];
#ifdef TRACE #ifdef TRACE
static volatile int rx_trace_ready = 0; static volatile int rx_trace_ready = 0;
static volatile int tx_trace_ready = 1; static volatile int tx_trace_ready = 1;
static int tx_trace_index_start = 0; static int64_t encode_counter_prev = 0;
static int64_t decode_counter_prev = 0;
static volatile int rx_exited = 0;
static volatile int trxr_exited = 0;
static volatile int trxw_exited = 0;
static volatile int tx_exited = 0;
#endif #endif
// Network // Network
...@@ -381,57 +388,80 @@ static void update_counter(volatile counter_stat_t * c, int64_t v) { ...@@ -381,57 +388,80 @@ static void update_counter(volatile counter_stat_t * c, int64_t v) {
#ifdef TRACE #ifdef TRACE
static void trace_handler(struct timespec initial, TRXEcpriState * s) { static void trace_handler(struct timespec initial, TRXEcpriState * s) {
struct timespec next; struct timespec next;
if(tx_trace_ready && rx_trace_ready) { int ready = 1;
#ifdef TRACE_TX
ready &= tx_trace_ready;
#endif
#ifdef TRACE_RX
ready &= rx_trace_ready;
#endif
if(ready) {
int64_t d; int64_t d;
clock_gettime(CLOCK_TAI, &next);
d = calcdiff_ns(next, initial);
log_info("TRACE", "Packets sent: %" PRIi64, sent_counter.counter);
log_info("TRACE", "Duration: %" PRIi64, d);
log_info("TRACE", "FRAME_FREQ: %" PRIi64, FRAME_FREQ);
FILE * f; FILE * f;
char n[256]; char n[256];
uint8_t ones[14]; uint8_t ones[14];
int start;
for(int i = 0; i < 14; i++) for(int i = 0; i < 14; i++)
ones[i] = 0xff; ones[i] = 0xff;
clock_gettime(CLOCK_TAI, &next);
d = calcdiff_ns(next, initial);
log_info("TRACE", "Packets sent: %" PRIi64, sent_counter.counter);
log_info("TRACE", "Duration: %" PRIi64, d);
log_info("TRACE", "FRAME_FREQ: %" PRIi64, FRAME_FREQ);
#ifdef TRACE_TX
while (!tx_exited || !trxw_exited) {
usleep(1000);
}
memset(n, '\0', 256); memset(n, '\0', 256);
sprintf(n, "%s/tx.trace", s->log_directory); sprintf(n, "%s/tx.trace", s->log_directory);
f = fopen(n, "wb+"); f = fopen(n, "wb+");
log_info("TRACE", "Writing %d frames to tx.trace", tx_rbuf.write_index + tx_rbuf.buf_len - tx_trace_index_start); start = (TRACE + encode_counter_prev) % tx_rbuf.buf_len;
for(int i = tx_trace_index_start; i != tx_rbuf.write_index; i = (i + 1) % tx_rbuf.buf_len) { log_info("TRACE", "Writing %d frames to tx.trace", tx_rbuf.write_index + tx_rbuf.buf_len - start);
for(int i = start; i != tx_rbuf.write_index; i = (i + 1) % tx_rbuf.buf_len) {
fwrite(ones, 14, 1, f); fwrite(ones, 14, 1, f);
fwrite(((uint8_t*) tx_rbuf.buffer) + i * tx_rbuf.len, tx_rbuf.len, 1, f); fwrite(((uint8_t*) tx_rbuf.buffer) + i * tx_rbuf.len, tx_rbuf.len, 1, f);
} }
fclose(f); fclose(f);
memset(n, '\0', 256); memset(n, '\0', 256);
sprintf(n, "%s/rx.trace", s->log_directory); sprintf(n, "%s/trxw.trace", s->log_directory);
f = fopen(n, "wb+"); f = fopen(n, "wb+");
log_info("TRACE", "Writing %d frames to rx.trace", rx_rbuf.write_index); start = (TRACE) % trxw_rbuf[0].buf_len;
for(int i = 0; i < rx_rbuf.write_index; i++) { log_info("TRACE", "Writing %d frames to trxw.trace", trxw_rbuf[0].write_index + trxw_rbuf.buf_len - start);
fwrite(((uint8_t*) rx_rbuf.buffer) + i * rx_rbuf.len, rx_rbuf.len, 1, f); for(int i = start; i != trxw_rbuf[0].write_index; i = (i + 1) % trxw_rbuf[0].buf_len) {
for(int j = 0; j < TX_N_CHANNEL; j++)
fwrite((uint8_t *) (((Complex *) trxw_rbuf[j].buffer) + i * trxw_rbuf[0].len), trxw_rbuf[0].len * sizeof(Complex), 1, f);
} }
fclose(f); fclose(f);
#endif
#ifdef TRACE_RX
while (!rx_exited || !trxr_exited) {
usleep(1000);
}
memset(n, '\0', 256); memset(n, '\0', 256);
sprintf(n, "%s/trxw.trace", s->log_directory); sprintf(n, "%s/rx.trace", s->log_directory);
f = fopen(n, "wb+"); f = fopen(n, "wb+");
log_info("TRACE", "Writing %d frames to trxw.trace", trxw_rbuf[0].write_index); start = TRACE % rx_rbuf.buf_len;
for(int i = 0; i < trxw_rbuf[0].write_index; i++) { log_info("TRACE", "Writing %d frames to rx.trace", rx_rbuf.write_index + rx_rbuf.buf_len - start);
for(int j = 0; j < TX_N_CHANNEL; j++) for(int i = start; i != rx_rbuf.write_index; i = (i + 1) % rx_rbuf.buf_len) {
fwrite((uint8_t *) (((Complex *) trxw_rbuf[j].buffer) + i * trxw_rbuf[0].len), trxw_rbuf[0].len * sizeof(Complex), 1, f); fwrite(((uint8_t*) rx_rbuf.buffer) + i * rx_rbuf.len, rx_rbuf.len, 1, f);
} }
fclose(f); fclose(f);
memset(n, '\0', 256); memset(n, '\0', 256);
sprintf(n, "%s/trxr.trace", s->log_directory); sprintf(n, "%s/trxr.trace", s->log_directory);
f = fopen(n, "wb+"); f = fopen(n, "wb+");
log_info("TRACE", "Writing %d frames to trxr.trace", trxr_rbuf[0].write_index); start = (TRACE + decode_counter_prev) % trxr_rbuf.buf_len;
for(int i = 0; i < trxr_rbuf[0].write_index; i++) { log_info("TRACE", "Writing %d frames to trxr.trace", trxr_rbuf[0].write_index + trxr_rbuf[0].buf_len - start);
for(int i = start; i != trxr_rbuf[0].write_index; i = (i + 1) % trxr_rbuf[0].buf_len) {
for(int j = 0; j < RX_N_CHANNEL; j++) for(int j = 0; j < RX_N_CHANNEL; j++)
fwrite((uint8_t *) (((Complex *) trxr_rbuf[j].buffer) + i * trxr_rbuf[0].len), trxr_rbuf[0].len * sizeof(Complex), 1, f); fwrite((uint8_t *) (((Complex *) trxr_rbuf[j].buffer) + i * trxr_rbuf[0].len), trxr_rbuf[0].len * sizeof(Complex), 1, f);
} }
fclose(f); fclose(f);
#endif
log_exit("", "Finished tracing"); log_exit("", "Finished tracing");
} }
} }
...@@ -519,11 +549,17 @@ static void *recv_thread(void *p) { ...@@ -519,11 +549,17 @@ static void *recv_thread(void *p) {
while((nc = rbuf_contiguous_copy(NULL, &rx_rbuf, nr))) { while((nc = rbuf_contiguous_copy(NULL, &rx_rbuf, nr))) {
#ifdef TRACE #ifdef TRACE
if((rx_rbuf.write_index + nc) >= rx_rbuf.buf_len) { #if TRACE_RX
log_info("RECV_THREAD", "RX Trace ready"); if((recv_counter.counter + nc) >= (rx_rbuf.buf_len + TRACE)) {
rx_trace_ready = 1; rx_trace_ready = 1;
log_info("RECV_THREAD", "RX Trace ready");
rx_exited = 1;
pthread_exit(EXIT_SUCCESS);
} else if (rx_trace_ready) {
rx_exited = 1;
pthread_exit(EXIT_SUCCESS); pthread_exit(EXIT_SUCCESS);
} }
#endif
#endif #endif
buf = ((uint8_t *) rx_rbuf.buffer) + (rx_rbuf.write_index * rx_rbuf.len); buf = ((uint8_t *) rx_rbuf.buffer) + (rx_rbuf.write_index * rx_rbuf.len);
...@@ -612,8 +648,8 @@ static void *encode_thread(void *p) { ...@@ -612,8 +648,8 @@ static void *encode_thread(void *p) {
#ifdef START_SENDING #ifdef START_SENDING
int64_t target_counter = 0; int64_t target_counter = 0;
struct timespec next; struct timespec next;
#endif
int reset_encode_counter = 1; int reset_encode_counter = 1;
#endif
// Set thread CPU affinity // Set thread CPU affinity
CPU_ZERO(&mask); CPU_ZERO(&mask);
...@@ -624,15 +660,6 @@ static void *encode_thread(void *p) { ...@@ -624,15 +660,6 @@ static void *encode_thread(void *p) {
for(int64_t i = 0;; i++) { for(int64_t i = 0;; i++) {
int n; int n;
if(sync_complete && reset_encode_counter) {
encode_counter.counter = 0;
reset_encode_counter = 0;
seq_id = 0;
#ifdef TRACE
tx_trace_index_start = tx_rbuf.write_index;
#endif
}
n = rbuf_write_amount(&tx_rbuf); n = rbuf_write_amount(&tx_rbuf);
// Send empty frames until we receive something // Send empty frames until we receive something
...@@ -655,6 +682,12 @@ static void *encode_thread(void *p) { ...@@ -655,6 +682,12 @@ static void *encode_thread(void *p) {
} }
update_counter(&encode_counter, n); update_counter(&encode_counter, n);
} }
else if (reset_encode_counter) {
encode_counter_prev = encode_counter.counter;
encode_counter.counter = 0;
reset_encode_counter = 0;
seq_id = 0;
}
#endif #endif
// If we have frames to encode (is there space in TX buffer) // If we have frames to encode (is there space in TX buffer)
...@@ -671,11 +704,17 @@ static void *encode_thread(void *p) { ...@@ -671,11 +704,17 @@ static void *encode_thread(void *p) {
nb_frames = g->count > n ? n : g->count; nb_frames = g->count > n ? n : g->count;
g->count -= nb_frames; g->count -= nb_frames;
#ifdef TRACE #ifdef TRACE
if((encode_counter.counter + nb_frames) >= tx_rbuf.buf_len) { #if TRACE_TX
log_info("ENCODE_THREAD", "TX Trace ready"); if(sync_complete && (encode_counter.counter + nb_frames) >= (tx_rbuf.buf_len + TRACE)) {
tx_trace_ready = 1; tx_trace_ready = 1;
log_info("ENCODE_THREAD", "TX Trace ready");
tx_exited = 1;
pthread_exit(EXIT_SUCCESS);
} else if (tx_trace_ready) {
tx_exited = 1;
pthread_exit(EXIT_SUCCESS); pthread_exit(EXIT_SUCCESS);
} }
#endif
#endif #endif
if(g->zeroes) { if(g->zeroes) {
for(int j = 0; j < nb_frames; j++) { for(int j = 0; j < nb_frames; j++) {
...@@ -726,6 +765,7 @@ static void *decode_thread(void *p) { ...@@ -726,6 +765,7 @@ static void *decode_thread(void *p) {
#ifdef START_RECEIVING #ifdef START_RECEIVING
struct timespec next; struct timespec next;
int64_t target_counter = 0; int64_t target_counter = 0;
int reset_decode_counter = 1;
#endif #endif
log_info("DECODE_THREAD", "Thread init"); log_info("DECODE_THREAD", "Thread init");
...@@ -738,7 +778,7 @@ static void *decode_thread(void *p) { ...@@ -738,7 +778,7 @@ static void *decode_thread(void *p) {
for(int64_t i = 0;; i++) { for(int64_t i = 0;; i++) {
int n, nc; int n, nc;
#ifdef START_RECEIVING #ifdef START_RECEIVING
if(!received_pkts && !rbuf_read_amount(&rx_rbuf)) { if(!received_pkts) {
if(i == 0) if(i == 0)
clock_gettime(CLOCK_TAI, &next); clock_gettime(CLOCK_TAI, &next);
// Limit packets sent // Limit packets sent
...@@ -754,21 +794,36 @@ static void *decode_thread(void *p) { ...@@ -754,21 +794,36 @@ static void *decode_thread(void *p) {
update_counter(&decode_counter, n); update_counter(&decode_counter, n);
continue; continue;
} }
else if (reset_decode_counter) {
decode_counter_prev = decode_counter.counter
decode_counter.counter = 0;
reset_decode_counter = 0;
}
#endif #endif
while(!(n = rbuf_read_amount(&rx_rbuf))); while(!(n = rbuf_read_amount(&rx_rbuf)));
while(rbuf_write_amount(&trxr_rbuf[0]) < n); while(rbuf_write_amount(&trxr_rbuf[0]) < n);
#ifdef TRACE
trxr_trace_index_start = trxr_rbuf.write_index;
#endif
while((nc = rbuf_contiguous_copy(&rx_rbuf, &trxr_rbuf[0], n))) { while((nc = rbuf_contiguous_copy(&rx_rbuf, &trxr_rbuf[0], n))) {
uint8_t * buf = ((uint8_t *) rx_rbuf.buffer) + (rx_rbuf.read_index * rx_rbuf.len) + 22; uint8_t * buf = ((uint8_t *) rx_rbuf.buffer) + (rx_rbuf.read_index * rx_rbuf.len) + 22;
#ifdef TRACE #ifdef TRACE
if((trxr_rbuf[0].write_index + nc) >= trxr_rbuf[0].buf_len) { #if TRACE_RX
if(received_pkts && ((decode_counter.counter + nc) >= (trxr_rbuf[0].buf_len + TRACE))) {
rx_trace_ready = 1; rx_trace_ready = 1;
log_info("DECODE_THREAD", "RX Trace ready"); log_info("DECODE_THREAD", "RX Trace ready");
trxr_exited = 1;
pthread_exit(EXIT_SUCCESS);
} else if (rx_trace_ready) {
trxr_exited = 1;
pthread_exit(EXIT_SUCCESS); pthread_exit(EXIT_SUCCESS);
} }
#endif
#endif #endif
Complex * iq_samples[4]; Complex * iq_samples[4];
...@@ -1109,11 +1164,17 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void ...@@ -1109,11 +1164,17 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
} }
#ifdef TRACE #ifdef TRACE
if((trxw_rbuf[0].write_index + write_count) >= trxw_rbuf[0].buf_len) { #if TRACE_TX
log_info("TRX_ECPRI_WRITE", "TX Trace ready"); if((write_counter.counter + write_count) >= (trxw_rbuf[0].buf_len + TRACE)) {
tx_trace_ready = 1; tx_trace_ready = 1;
log_info("TRX_ECPRI_WRITE", "TX Trace ready");
trxw_exited = 1;
pthread_exit(EXIT_SUCCESS);
} else if (tx_trace_ready) {
trxw_exited = 1;
pthread_exit(EXIT_SUCCESS); pthread_exit(EXIT_SUCCESS);
} }
#endif
#endif #endif
if(first_trx_write) { if(first_trx_write) {
......
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