Commit 5d3b7d94 authored by Joanne Hugé's avatar Joanne Hugé

wip

parent 02fdac90
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
#define PACKET_HEADER (ETHERNET_HEADER + ECPRI_IQ_HEADER + ORAN_HEADER) #define PACKET_HEADER (ETHERNET_HEADER + ECPRI_IQ_HEADER + ORAN_HEADER)
// MAX_IQ_PAYLOAD + PAYLOAD_SIZE // MAX_IQ_PAYLOAD + PAYLOAD_SIZE
#define MAX_IQ_PAYLOAD (8832 + 2) #define MAX_IQ_PAYLOAD (8832 + 2)
#define TX_IQ_PAYLOAD 4414 #define TX_IQ_PAYLOAD 4416
#define MAX_PACKET_SIZE (PACKET_HEADER + MAX_IQ_PAYLOAD) #define MAX_PACKET_SIZE (PACKET_HEADER + MAX_IQ_PAYLOAD)
#define TX_PACKET_SIZE (PACKET_HEADER + TX_IQ_PAYLOAD) #define TX_PACKET_SIZE (PACKET_HEADER + TX_IQ_PAYLOAD)
#define MAX_RX_BURST 1024 #define MAX_RX_BURST 1024
...@@ -118,11 +118,6 @@ ...@@ -118,11 +118,6 @@
*/ */
typedef struct {
float re;
float im;
} Complex;
typedef struct { typedef struct {
const char * rrh_mac; const char * rrh_mac;
const char * bbu_mac; const char * bbu_mac;
...@@ -140,9 +135,6 @@ typedef struct { ...@@ -140,9 +135,6 @@ typedef struct {
int rx_burst; int rx_burst;
int tx_burst; int tx_burst;
int monitor_pps;
int monitor_trigger_duration;
int rx_n_channel; int rx_n_channel;
int tx_n_channel; int tx_n_channel;
int statistics_refresh_rate_ns; int statistics_refresh_rate_ns;
...@@ -151,9 +143,9 @@ typedef struct { ...@@ -151,9 +143,9 @@ typedef struct {
typedef struct { typedef struct {
int64_t counter; int64_t counter;
int64_t pps_counter; int64_t freq_counter;
int64_t pps_ts; int64_t freq_ts;
int64_t pps; int64_t freq;
} counter_stat_t; } counter_stat_t;
typedef struct { typedef struct {
...@@ -203,13 +195,15 @@ static uint8_t rx_buf[MAX_PACKET_SIZE * MAX_RX_BURST]; ...@@ -203,13 +195,15 @@ static uint8_t rx_buf[MAX_PACKET_SIZE * MAX_RX_BURST];
static uint8_t tx_buf[MAX_PACKET_SIZE * MAX_TX_BURST]; static uint8_t tx_buf[MAX_PACKET_SIZE * MAX_TX_BURST];
// Counters // Counters
static counter_stat_t recv_counter[MAX_CHANNELS]; // frames received from RRH static counter_stat_t recv_counter[MAX_CHANNELS]; // IQs received from RRH
static counter_stat_t read_counter; // frames passed to amarisoft stack static counter_stat_t read_counter; // IQs passed to amarisoft stack
static counter_stat_t write_counter; // samples to write from TRX static counter_stat_t write_counter; // IQs to write from TRX
static counter_stat_t sent_counter; // frames sent to RRH static counter_stat_t sent_counter; // IQs sent to RRH
static counter_stat_t rx_drop_counter; // frames sent to RRH static counter_stat_t rx_drop_counter; // rx packets dropped by driver
static counter_stat_t tx_drop_counter; // frames sent to RRH static counter_stat_t tx_drop_counter; // tx packets dropped by driver
static counter_stat_t lost_rx_counter; // when seq_id doesn't match static counter_stat_t lost_rx_counter; // gaps between seq_id's
static counter_stat_t rx_packet_counter; // packets received from RRH
static counter_stat_t tx_packet_counter; // packets sent from TRX
// Network // Network
static int tx_seq_id; static int tx_seq_id;
...@@ -274,73 +268,108 @@ static void print_debug(FILE * f, int print_header) { ...@@ -274,73 +268,108 @@ static void print_debug(FILE * f, int print_header) {
fprintf(f, "%s", buffer); fprintf(f, "%s", buffer);
} }
int pow10i(int n) {
int r = 1;
for(int i = 0; i < n; i++)
r *= 10;
return r;
}
int n_digits(int64_t n) {
int r = 1;
while (n > 9) {
n /= 10;
r++;
}
return r;
}
static void int64_to_6s(char * s, int64_t x) {
double n = n_digits((double) x);
if(n < 7)
sprintf(s, "%6d", (int) x);
else if(n < 10) {
int a = x / 1000000;
int b = (x % 1000000) / pow10i(n - 4);
sprintf(s, "%d.%dM", a, b);
}
else if(n < 13) {
int a = x / 1000000000;
int b = (x % 1000000000) / pow10i(n - 4);
sprintf(s, "%d.%dG", a, b);
}
else if(n < 16) {
int c = x / 1000000;
int a = c / 1000000;
int b = ((c / 1000) % 1000) / pow10i(n - 13);
sprintf(s, "%d.%dT", a, b);
}
s[6] = '\0';
}
static void print_stats(FILE * f, int print_header) { static void print_stats(FILE * f, int print_header) {
char s[300];
int offset = 0;
if(print_header) { if(print_header) {
fprintf(f, fprintf(f,
"%" STAT_INT_LEN "s " "%6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
"%" STAT_INT_LEN "s " "rxdrop",
"%" STAT_INT_LEN "s " "txdrop",
"%" STAT_INT_LEN "s " "lostrx",
"%" STAT_INT_LEN "s " "recv 0",
"%" STAT_INT_LEN "s " "recv 1",
"%" STAT_INT_LEN "s " "recv 2",
"%" STAT_INT_LEN "s " "recv 3",
"%" STAT_INT_LEN "s "
"%" STAT_INT_LEN "s "
"%" STAT_INT_LEN "s "
"%" STAT_INT_LEN "s "
"%" STAT_INT_LEN "s "
"%" STAT_INT_LEN "s "
"%" STAT_INT_LEN "s "
"\n",
"rx dropped",
"tx dropped",
"received 0",
"received 1",
"received 2",
"received 3",
"read", "read",
"write", "write",
"sent", "sent",
"lost rx", "recv f",
"received pps", "read f",
"read pps", "wrte f",
"write pps", "sent f",
"sent pps", "rx pkt",
"lost rx pps"); "tx pkt",
"rx pps",
"tx pps");
} }
offset = 0;
int64_to_6s(s + 7 * offset++, rx_drop_counter.counter);
int64_to_6s(s + 7 * offset++, tx_drop_counter.counter);
int64_to_6s(s + 7 * offset++, lost_rx_counter.counter);
int64_to_6s(s + 7 * offset++, recv_counter[0].counter);
int64_to_6s(s + 7 * offset++, recv_counter[1].counter);
int64_to_6s(s + 7 * offset++, recv_counter[2].counter);
int64_to_6s(s + 7 * offset++, recv_counter[3].counter);
int64_to_6s(s + 7 * offset++, read_counter.counter);
int64_to_6s(s + 7 * offset++, write_counter.counter);
int64_to_6s(s + 7 * offset++, sent_counter.counter);
int64_to_6s(s + 7 * offset++, recv_counter[0].freq);
int64_to_6s(s + 7 * offset++, read_counter.freq);
int64_to_6s(s + 7 * offset++, write_counter.freq);
int64_to_6s(s + 7 * offset++, sent_counter.freq);
int64_to_6s(s + 7 * offset++, rx_packet_counter.counter);
int64_to_6s(s + 7 * offset++, tx_packet_counter.counter);
int64_to_6s(s + 7 * offset++, rx_packet_counter.freq);
int64_to_6s(s + 7 * offset++, tx_packet_counter.freq);
offset = 0;
fprintf(f, fprintf(f,
"%" STAT_INT_LEN "" PRIi64 " " "%6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 0,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 1,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 2,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 3,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 4,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 5,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 6,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 7,
"%" STAT_INT_LEN "" PRIi64 " " s + 7 * 8,
"%" STAT_INT_LEN "" PRIi64 "pps " s + 7 * 9,
"%" STAT_INT_LEN "" PRIi64 "pps " s + 7 * 10,
"%" STAT_INT_LEN "" PRIi64 "pps " s + 7 * 11,
"%" STAT_INT_LEN "" PRIi64 "pps " s + 7 * 12,
"%" STAT_INT_LEN "" PRIi64 "pps " s + 7 * 13,
"\n", s + 7 * 14,
rx_drop_counter.counter, s + 7 * 15,
tx_drop_counter.counter, s + 7 * 16,
recv_counter[0].counter, s + 7 * 17);
recv_counter[1].counter,
recv_counter[2].counter,
recv_counter[3].counter,
read_counter.counter,
write_counter.counter,
sent_counter.counter,
lost_rx_counter.counter,
recv_counter[0].pps,
read_counter.pps,
write_counter.pps,
sent_counter.pps,
lost_rx_counter.pps);
} }
static void log_exit(const char * section, const char * msg, ...) { static void log_exit(const char * section, const char * msg, ...) {
...@@ -375,20 +404,20 @@ static void log_exit(const char * section, const char * msg, ...) { ...@@ -375,20 +404,20 @@ static void log_exit(const char * section, const char * msg, ...) {
static void init_counter(counter_stat_t * c) { static void init_counter(counter_stat_t * c) {
c->counter = 0; c->counter = 0;
c->pps_counter = 0; c->freq_counter = 0;
c->pps_ts = 0; c->freq_ts = 0;
c->pps = 0; c->freq = 0;
} }
static void update_counter_pps(counter_stat_t * c) { static void update_counter_freq(counter_stat_t * c) {
struct timespec _ts; struct timespec _ts;
int64_t ts; int64_t ts;
clock_gettime(CLOCK_TAI, &_ts); clock_gettime(CLOCK_TAI, &_ts);
ts = ts_to_int(_ts); ts = ts_to_int(_ts);
if((ts - c->pps_ts) > PPS_UPDATE_PERIOD) { if((ts - c->freq_ts) > PPS_UPDATE_PERIOD) {
if(c->pps_ts) if(c->freq_ts)
c->pps = ((c->counter - c->pps_counter) * NSEC_PER_SEC) / (ts - c->pps_ts); c->freq = ((c->counter - c->freq_counter) * NSEC_PER_SEC) / (ts - c->freq_ts);
c->pps_counter = c->counter; c->freq_counter = c->counter;
c->pps_ts = ts; c->freq_ts = ts;
} }
} }
static void update_counter(counter_stat_t * c, int64_t v) { static void update_counter(counter_stat_t * c, int64_t v) {
...@@ -503,7 +532,7 @@ static void *recv_thread(void *p) { ...@@ -503,7 +532,7 @@ static void *recv_thread(void *p) {
// Exit if there is no more space in the buffer // Exit if there is no more space in the buffer
if(!rbuf_write_amount(&trxr_rbuf[antenna_id])) { if(!rbuf_write_amount(&trxr_rbuf[antenna_id])) {
rbuf_increment_read(&trxr_rbuf[antenna_id], MAX_IQ_PAYLOAD); rbuf_increment_read(&trxr_rbuf[antenna_id], MAX_IQ_PAYLOAD);
update_counter(&rx_drop_counter, MAX_IQ_PAYLOAD / sizeof(Complex)); update_counter(&rx_drop_counter, MAX_IQ_PAYLOAD / 4);
//log_exit("RECV_THREAD", "No more space in %s buffer", //log_exit("RECV_THREAD", "No more space in %s buffer",
// trxr_rbuf[antenna_id].name); // trxr_rbuf[antenna_id].name);
} }
...@@ -515,7 +544,8 @@ static void *recv_thread(void *p) { ...@@ -515,7 +544,8 @@ static void *recv_thread(void *p) {
iq_packet->iq_samples, iq_packet->iq_samples,
ntohs(iq_packet->payload_size)); ntohs(iq_packet->payload_size));
rbuf_increment_write(&trxr_rbuf[antenna_id], trxr_rbuf[antenna_id].block_len); rbuf_increment_write(&trxr_rbuf[antenna_id], trxr_rbuf[antenna_id].block_len);
update_counter(&recv_counter[antenna_id], ntohs(iq_packet->payload_size) / sizeof(Complex)); update_counter(&recv_counter[antenna_id], ntohs(iq_packet->payload_size) / 4);
update_counter(&rx_packet_counter, 1);
} }
if(stop) { if(stop) {
for(int j = 0; j < ret; j++) { for(int j = 0; j < ret; j++) {
...@@ -562,7 +592,6 @@ static void *send_thread(void *p) { ...@@ -562,7 +592,6 @@ static void *send_thread(void *p) {
clock_gettime(CLOCK_TAI, &initial); clock_gettime(CLOCK_TAI, &initial);
log_info("SEND_THREAD", "Starting loop"); log_info("SEND_THREAD", "Starting loop");
symbol_id = 0; symbol_id = 0;
slot_id = 0; slot_id = 0;
subframe_id = 0; subframe_id = 0;
...@@ -621,7 +650,8 @@ static void *send_thread(void *p) { ...@@ -621,7 +650,8 @@ static void *send_thread(void *p) {
if(ret <= 0) if(ret <= 0)
error(EXIT_FAILURE, errno, "sendmmsg error (returned %d)", ret); error(EXIT_FAILURE, errno, "sendmmsg error (returned %d)", ret);
j += ret; j += ret;
update_counter(&sent_counter, ret * TX_IQ_PAYLOAD / sizeof(Complex)); update_counter(&sent_counter, ret * TX_IQ_PAYLOAD / 4);
update_counter(&tx_packet_counter, ret * 4);
} }
} }
pthread_exit(EXIT_SUCCESS); pthread_exit(EXIT_SUCCESS);
...@@ -659,15 +689,17 @@ static void *statistic_thread(void *p) { ...@@ -659,15 +689,17 @@ static void *statistic_thread(void *p) {
#endif #endif
fflush(stats_file_desc); fflush(stats_file_desc);
update_counter_pps(&rx_drop_counter); update_counter_freq(&rx_drop_counter);
update_counter_pps(&tx_drop_counter); update_counter_freq(&tx_drop_counter);
update_counter_pps(&recv_counter[0]); update_counter_freq(&recv_counter[0]);
update_counter_pps(&recv_counter[1]); update_counter_freq(&recv_counter[1]);
update_counter_pps(&recv_counter[2]); update_counter_freq(&recv_counter[2]);
update_counter_pps(&recv_counter[3]); update_counter_freq(&recv_counter[3]);
update_counter_pps(&read_counter); update_counter_freq(&read_counter);
update_counter_pps(&write_counter); update_counter_freq(&write_counter);
update_counter_pps(&sent_counter); update_counter_freq(&sent_counter);
update_counter_freq(&rx_packet_counter);
update_counter_freq(&tx_packet_counter);
clock_nanosleep(CLOCK_TAI, TIMER_ABSTIME, &next, NULL); clock_nanosleep(CLOCK_TAI, TIMER_ABSTIME, &next, NULL);
} }
...@@ -765,6 +797,7 @@ int start(TRXEcpriState * s) { ...@@ -765,6 +797,7 @@ int start(TRXEcpriState * s) {
tx_seq_id = 0; tx_seq_id = 0;
init_counter(&rx_drop_counter); init_counter(&rx_drop_counter);
init_counter(&tx_drop_counter); init_counter(&tx_drop_counter);
init_counter(&lost_rx_counter);
init_counter(&recv_counter[0]); init_counter(&recv_counter[0]);
init_counter(&recv_counter[1]); init_counter(&recv_counter[1]);
init_counter(&recv_counter[2]); init_counter(&recv_counter[2]);
...@@ -772,7 +805,8 @@ int start(TRXEcpriState * s) { ...@@ -772,7 +805,8 @@ int start(TRXEcpriState * s) {
init_counter(&read_counter); init_counter(&read_counter);
init_counter(&write_counter); init_counter(&write_counter);
init_counter(&sent_counter); init_counter(&sent_counter);
init_counter(&lost_rx_counter); init_counter(&rx_packet_counter);
init_counter(&tx_packet_counter);
for(int i = 0; i < s->tx_n_channel; i++) { for(int i = 0; i < s->tx_n_channel; i++) {
char name[256]; char name[256];
...@@ -914,7 +948,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void ...@@ -914,7 +948,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
prev_timestamp = timestamp; prev_count = count; prev_timestamp = timestamp; prev_count = count;
// Drop samples if we don't have enough space in trx write buffer // Drop samples if we don't have enough space in trx write buffer
if( (count * sizeof(Complex)) > rbuf_write_amount(&trxw_rbuf[0]) ) { if( (count * 4) > rbuf_write_amount(&trxw_rbuf[0]) ) {
//log_exit("TRX_ECPRI_WRITE", //log_exit("TRX_ECPRI_WRITE",
// "Not enough space to write in trxw_rbuf (count = %d)", count); // "Not enough space to write in trxw_rbuf (count = %d)", count);
update_counter(&tx_drop_counter, count); update_counter(&tx_drop_counter, count);
...@@ -923,7 +957,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void ...@@ -923,7 +957,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
offset = 0; offset = 0;
count_left = count; count_left = count;
while((nc = rbuf_contiguous_copy(NULL, &trxw_rbuf[0], count_left * sizeof(Complex)))) { while((nc = rbuf_contiguous_copy(NULL, &trxw_rbuf[0], count_left * 4))) {
for(int i = 0; i < s->tx_n_channel; i++) { for(int i = 0; i < s->tx_n_channel; i++) {
if(__samples) if(__samples)
memcpy( memcpy(
...@@ -937,7 +971,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void ...@@ -937,7 +971,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
nc); nc);
rbuf_increment_write(&trxw_rbuf[i], nc); rbuf_increment_write(&trxw_rbuf[i], nc);
} }
count_left -= nc / sizeof(Complex); count_left -= nc / 4;
offset += nc; offset += nc;
} }
update_counter(&write_counter, (s->tx_n_channel * count)); update_counter(&write_counter, (s->tx_n_channel * count));
...@@ -970,13 +1004,13 @@ static int trx_ecpri_read(TRXState *s1, trx_timestamp_t *ptimestamp, void **__sa ...@@ -970,13 +1004,13 @@ static int trx_ecpri_read(TRXState *s1, trx_timestamp_t *ptimestamp, void **__sa
for(int j = 0; j < ra; j++) { for(int j = 0; j < ra; j++) {
data = trxr_rbuf[i].buffer + trxr_rbuf[i].read_index; data = trxr_rbuf[i].buffer + trxr_rbuf[i].read_index;
payload_size = *((uint16_t *) data); payload_size = *((uint16_t *) data);
if(count_left < payload_size / sizeof(Complex)) if(count_left < payload_size / 4)
payload_size = count_left * sizeof(Complex); payload_size = count_left * 4;
memcpy( memcpy(
((uint8_t*) _samples[i]) + offset, ((uint8_t*) _samples[i]) + offset,
data + 2, data + 2,
payload_size); payload_size);
count_left -= payload_size / sizeof(Complex); count_left -= payload_size / 4;
if(!count_left) if(!count_left)
break; break;
offset += payload_size; offset += payload_size;
......
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