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

wip

parent 02fdac90
......@@ -57,7 +57,7 @@
#define PACKET_HEADER (ETHERNET_HEADER + ECPRI_IQ_HEADER + ORAN_HEADER)
// MAX_IQ_PAYLOAD + PAYLOAD_SIZE
#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 TX_PACKET_SIZE (PACKET_HEADER + TX_IQ_PAYLOAD)
#define MAX_RX_BURST 1024
......@@ -118,11 +118,6 @@
*/
typedef struct {
float re;
float im;
} Complex;
typedef struct {
const char * rrh_mac;
const char * bbu_mac;
......@@ -140,9 +135,6 @@ typedef struct {
int rx_burst;
int tx_burst;
int monitor_pps;
int monitor_trigger_duration;
int rx_n_channel;
int tx_n_channel;
int statistics_refresh_rate_ns;
......@@ -151,9 +143,9 @@ typedef struct {
typedef struct {
int64_t counter;
int64_t pps_counter;
int64_t pps_ts;
int64_t pps;
int64_t freq_counter;
int64_t freq_ts;
int64_t freq;
} counter_stat_t;
typedef struct {
......@@ -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];
// Counters
static counter_stat_t recv_counter[MAX_CHANNELS]; // frames received from RRH
static counter_stat_t read_counter; // frames passed to amarisoft stack
static counter_stat_t write_counter; // samples to write from TRX
static counter_stat_t sent_counter; // frames sent to RRH
static counter_stat_t rx_drop_counter; // frames sent to RRH
static counter_stat_t tx_drop_counter; // frames sent to RRH
static counter_stat_t lost_rx_counter; // when seq_id doesn't match
static counter_stat_t recv_counter[MAX_CHANNELS]; // IQs received from RRH
static counter_stat_t read_counter; // IQs passed to amarisoft stack
static counter_stat_t write_counter; // IQs to write from TRX
static counter_stat_t sent_counter; // IQs sent to RRH
static counter_stat_t rx_drop_counter; // rx packets dropped by driver
static counter_stat_t tx_drop_counter; // tx packets dropped by driver
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
static int tx_seq_id;
......@@ -274,73 +268,108 @@ static void print_debug(FILE * f, int print_header) {
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) {
char s[300];
int offset = 0;
if(print_header) {
fprintf(f,
"%" 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 "
"%" 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 "
"%" STAT_INT_LEN "s "
"\n",
"rx dropped",
"tx dropped",
"received 0",
"received 1",
"received 2",
"received 3",
"%6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
"rxdrop",
"txdrop",
"lostrx",
"recv 0",
"recv 1",
"recv 2",
"recv 3",
"read",
"write",
"sent",
"lost rx",
"received pps",
"read pps",
"write pps",
"sent pps",
"lost rx pps");
"recv f",
"read f",
"wrte f",
"sent f",
"rx pkt",
"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,
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 " "
"%" STAT_INT_LEN "" PRIi64 "pps "
"%" STAT_INT_LEN "" PRIi64 "pps "
"%" STAT_INT_LEN "" PRIi64 "pps "
"%" STAT_INT_LEN "" PRIi64 "pps "
"%" STAT_INT_LEN "" PRIi64 "pps "
"\n",
rx_drop_counter.counter,
tx_drop_counter.counter,
recv_counter[0].counter,
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);
"%6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
s + 7 * 0,
s + 7 * 1,
s + 7 * 2,
s + 7 * 3,
s + 7 * 4,
s + 7 * 5,
s + 7 * 6,
s + 7 * 7,
s + 7 * 8,
s + 7 * 9,
s + 7 * 10,
s + 7 * 11,
s + 7 * 12,
s + 7 * 13,
s + 7 * 14,
s + 7 * 15,
s + 7 * 16,
s + 7 * 17);
}
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) {
c->counter = 0;
c->pps_counter = 0;
c->pps_ts = 0;
c->pps = 0;
c->freq_counter = 0;
c->freq_ts = 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;
int64_t ts;
clock_gettime(CLOCK_TAI, &_ts);
ts = ts_to_int(_ts);
if((ts - c->pps_ts) > PPS_UPDATE_PERIOD) {
if(c->pps_ts)
c->pps = ((c->counter - c->pps_counter) * NSEC_PER_SEC) / (ts - c->pps_ts);
c->pps_counter = c->counter;
c->pps_ts = ts;
if((ts - c->freq_ts) > PPS_UPDATE_PERIOD) {
if(c->freq_ts)
c->freq = ((c->counter - c->freq_counter) * NSEC_PER_SEC) / (ts - c->freq_ts);
c->freq_counter = c->counter;
c->freq_ts = ts;
}
}
static void update_counter(counter_stat_t * c, int64_t v) {
......@@ -503,7 +532,7 @@ static void *recv_thread(void *p) {
// Exit if there is no more space in the buffer
if(!rbuf_write_amount(&trxr_rbuf[antenna_id])) {
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",
// trxr_rbuf[antenna_id].name);
}
......@@ -515,7 +544,8 @@ static void *recv_thread(void *p) {
iq_packet->iq_samples,
ntohs(iq_packet->payload_size));
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) {
for(int j = 0; j < ret; j++) {
......@@ -562,7 +592,6 @@ static void *send_thread(void *p) {
clock_gettime(CLOCK_TAI, &initial);
log_info("SEND_THREAD", "Starting loop");
symbol_id = 0;
slot_id = 0;
subframe_id = 0;
......@@ -621,7 +650,8 @@ static void *send_thread(void *p) {
if(ret <= 0)
error(EXIT_FAILURE, errno, "sendmmsg error (returned %d)", 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);
......@@ -659,15 +689,17 @@ static void *statistic_thread(void *p) {
#endif
fflush(stats_file_desc);
update_counter_pps(&rx_drop_counter);
update_counter_pps(&tx_drop_counter);
update_counter_pps(&recv_counter[0]);
update_counter_pps(&recv_counter[1]);
update_counter_pps(&recv_counter[2]);
update_counter_pps(&recv_counter[3]);
update_counter_pps(&read_counter);
update_counter_pps(&write_counter);
update_counter_pps(&sent_counter);
update_counter_freq(&rx_drop_counter);
update_counter_freq(&tx_drop_counter);
update_counter_freq(&recv_counter[0]);
update_counter_freq(&recv_counter[1]);
update_counter_freq(&recv_counter[2]);
update_counter_freq(&recv_counter[3]);
update_counter_freq(&read_counter);
update_counter_freq(&write_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);
}
......@@ -765,6 +797,7 @@ int start(TRXEcpriState * s) {
tx_seq_id = 0;
init_counter(&rx_drop_counter);
init_counter(&tx_drop_counter);
init_counter(&lost_rx_counter);
init_counter(&recv_counter[0]);
init_counter(&recv_counter[1]);
init_counter(&recv_counter[2]);
......@@ -772,7 +805,8 @@ int start(TRXEcpriState * s) {
init_counter(&read_counter);
init_counter(&write_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++) {
char name[256];
......@@ -914,7 +948,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
prev_timestamp = timestamp; prev_count = count;
// 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",
// "Not enough space to write in trxw_rbuf (count = %d)", count);
update_counter(&tx_drop_counter, count);
......@@ -923,7 +957,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
offset = 0;
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++) {
if(__samples)
memcpy(
......@@ -937,7 +971,7 @@ static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void
nc);
rbuf_increment_write(&trxw_rbuf[i], nc);
}
count_left -= nc / sizeof(Complex);
count_left -= nc / 4;
offset += nc;
}
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
for(int j = 0; j < ra; j++) {
data = trxr_rbuf[i].buffer + trxr_rbuf[i].read_index;
payload_size = *((uint16_t *) data);
if(count_left < payload_size / sizeof(Complex))
payload_size = count_left * sizeof(Complex);
if(count_left < payload_size / 4)
payload_size = count_left * 4;
memcpy(
((uint8_t*) _samples[i]) + offset,
data + 2,
payload_size);
count_left -= payload_size / sizeof(Complex);
count_left -= payload_size / 4;
if(!count_left)
break;
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