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

Clean up and enforce ecpri_period parameter

parent c4fba315
......@@ -9,3 +9,6 @@ raw-socket-test/raw_socket
raw-socket-test/raw_socket.d
raw-socket-test/raw_socket.o
dpdk-test/build
*.so
*.o
*.d
......@@ -3,7 +3,7 @@
CC=gcc -m64 -msse4.1
CXX=g++ -m64 -msse4.1
CFLAGS=-fno-strict-aliasing -Wall -pedantic
CFLAGS=-O2 -fno-strict-aliasing -Wall -pedantic
CFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
CFLAGS +=-DALLOW_EXPERIMENTAL_API
CFLAGS+=-MMD -g
......@@ -32,7 +32,9 @@ LDFLAGS = -l:libpthread.a -l:libm.a
all: $(LIB)
$(LIB): $(APP).o
$(CC) -shared $(LDFLAGS) $(LDFLAGS_STATIC) -o $@ $<
$(CC) -shared -o $@ $< -lm -lpthread $(LDFLAGS_SHARED)
#$(LIB): $(APP).o
# $(CC) -shared $(LDFLAGS) $(LDFLAGS_STATIC) -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) $(SRCS-y) -fpic -c -o $@
......
......@@ -8,7 +8,7 @@ CFLAGS +=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
CFLAGS += -DALLOW_EXPERIMENTAL_API
CXXFLAGS=$(CFLAGS)
LIB=trx_ecpri_dpdk
LIBDIR=/root/ecpri/trx-ecpri-priv
LIBDIR=/root/ecpri-priv
LDFLAGS=-l$(LIB)
PROG=test-dpdk-ecpri
......@@ -16,7 +16,7 @@ PROG=test-dpdk-ecpri
all: $(PROG)
$(PROG): $(PROG).o
$(CC) -o $@ $< $(LDFLAGS)
$(CC) -L$(LIBDIR) -o $@ $< $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
......
......@@ -86,15 +86,10 @@ int main(int argc, char * argv[]) {
s = malloc(sizeof(TRXEcpriState));
memset(s, 0, sizeof(*s));
#if 1
s->rec_mac = "b8:59:9f:07:7d:da";
s->rec_mac = "b8:59:9f:07:86:42";
s->re_mac = "04:09:a5:0f:9f:4c";
s->rec_if = "ens9f0np0";
#else
s->rec_mac = "b8:ce:f6:4b:00:22";
s->re_mac = "b8:ce:f6:4b:00:23";
s->rec_if = "ens5f0np0";
#endif
s->rec_if = "ens9f0";
s->recv_affinity = 39;
s->send_affinity = 38;
s->prepare_affinity = 37;
......@@ -109,7 +104,7 @@ int main(int argc, char * argv[]) {
startdpdk(s);
for(int i = 0; i < 1000; i++) {
for(;;) {
sleep(1);
}
......
......@@ -4,4 +4,5 @@ cd ..;
make;
cd ecpri-tests;
make all;
export LD_LIBRARY_PATH="/root/ecpri-priv:$LD_LIBRARY_PATH"
./test-dpdk-ecpri
chrt -f 97 taskset -c 39 phc2sys -m -c ens9f1 -s CLOCK_REALTIME -O0 -f $HOME/linuxptp/configs/G.8275.1.cfg
chrt -f 97 taskset -c 39 phc2sys -m -c ens5f0 -s CLOCK_REALTIME -O0 -f $HOME/linuxptp/configs/G.8275.1.cfg
chrt -f 97 taskset -c 38 ptp4l -H -i ens9f1 -m -f $HOME/linuxptp/configs/G.8275.1.cfg
chrt -f 97 taskset -c 38 ptp4l -H -i ens5f0 -m -f $HOME/linuxptp/configs/G.8275.1.cfg
......@@ -170,6 +170,7 @@ typedef struct {
const char * re_mac;
const char * rec_mac;
const char * rec_if;
const char * dpdk_options;
int recv_affinity;
int send_affinity;
int prepare_affinity;
......@@ -269,7 +270,7 @@ struct rte_ether_addr s_addr;
struct rte_ether_addr d_addr;
int8_t data[BURST_SIZE][DATA_SIZE];
static const struct rte_eth_conf port_conf_default = {
.rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN }
.rxmode = { .max_lro_pkt_size = RTE_ETHER_MAX_LEN }
};
static inline int port_init(int portid, struct rte_mempool *mbuf_pool) {
struct rte_eth_conf port_conf = port_conf_default;
......@@ -335,15 +336,16 @@ static void send_packets(int port) {
pkt[i] = rte_pktmbuf_alloc(mbuf_pool);
eth_hdr = rte_pktmbuf_mtod(pkt[i], struct rte_ether_hdr*);
if(port) {
eth_hdr->d_addr = s_addr;
eth_hdr->s_addr = d_addr;
eth_hdr->dst_addr = s_addr;
eth_hdr->src_addr = d_addr;
} else {
eth_hdr->d_addr = d_addr;
eth_hdr->s_addr = s_addr;
eth_hdr->dst_addr = d_addr;
eth_hdr->src_addr = s_addr;
}
eth_hdr->ether_type = htons(0xaefe);
memcpy(rte_pktmbuf_mtod_offset(pkt[i], uint8_t *, sizeof(struct rte_ether_hdr)), data[i], DATA_SIZE);
pkt_size = DATA_SIZE + sizeof(struct rte_ether_hdr);
//pkt_size = DATA_SIZE + sizeof(struct rte_ether_hdr);
pkt_size = PACKET_SIZE;
pkt[i]->data_len = pkt_size;
pkt[i]->pkt_len = pkt_size;
}
......@@ -365,7 +367,7 @@ static void send_packets(int port) {
static int recv_packets(int port) {
struct rte_mbuf * pkt[BURST_SIZE];
while(1) {
const int nb_rx = rte_eth_rx_burst(port, 0, pkt, BURST_SIZE);
const int nb_rx = rte_eth_rx_burst(port, 0, pkt, 1024);
for(int i = 0; i < nb_rx; i++)
rte_pktmbuf_free(pkt[i]);
......@@ -519,7 +521,7 @@ static void *prepare_thread(void *p) {
}
}
else {
*((uint16_t *) (RBUF_WRITE(tx_rbuf, uint8_t) + 20)) = htons(seq_id++);
*((uint16_t *) (RBUF_WRITE(tx_rbuf, uint8_t) + 6)) = htons(seq_id++);
rbuf_update_write_index(&tx_rbuf);
prepared_frame_count++;
}
......@@ -589,6 +591,11 @@ static void *statistic_thread(void *p) {
int64_t duration_ns;
TRXEcpriState * s = (TRXEcpriState *) p;
const int div_a[] = {1,2,4,5,8,10,16,20,25,32,40,50,64,80,100,125,128,160,200,250,256,320,400,500,512,625,640,800,1000,1250,1280,1600,2000,2500,2560,3125,3200,4000,5000,6250,6400,8000,10000,12500,12800,15625,16000,20000,25000,31250};
const int div_b[] = {1000000000,500000000,250000000,200000000,125000000,100000000,62500000,50000000,40000000,31250000,25000000,20000000,15625000,12500000,10000000,8000000,7812500,6250000,5000000,4000000,3906250,3125000,2500000,2000000,1953125,1600000,1562500,1250000,1000000,800000,781250,625000,500000,400000,390625,320000,312500,250000,200000,160000,156250,125000,100000,80000,78125,64000,62500,50000,40000,32000};
int div_index = 0;
int div_indexr = 0;
log_info("STATISTIC_THREAD", "Thread init");
// Set thread CPU affinity
......@@ -600,15 +607,23 @@ static void *statistic_thread(void *p) {
clock_gettime(CLOCK_TAI, &initial);
next = initial;
for(;;) {
int64_t pps, ppsr;
add_ns(&next, STATISTIC_REFRESH_RATE);
clock_gettime(CLOCK_TAI, &current);
duration_ns = calcdiff_ns(current, initial);
log_info("STATS", "%14" PRIi64 " - %14" PRIi64 " - %14" PRIi64 " - %14" PRIi64 " - %14" PRIi64 "pps",
if(sent_frame_count >= INT64_MAX / div_b[div_index])
div_index++;
if(recv_frame_count >= INT64_MAX / div_b[div_indexr])
div_indexr++;
pps = ((sent_frame_count * div_b[div_index]) / duration_ns) * div_a[div_index];
ppsr = ((recv_frame_count * div_b[div_indexr]) / duration_ns) * div_a[div_indexr];
log_info("STATS", "%14" PRIi64 " - %14" PRIi64 " - %14" PRIi64 " - %14" PRIi64 " - %14" PRIi64 "pps %14" PRIi64 "pps",
prepared_frame_count,
read_frame_count,
sent_frame_count,
recv_frame_count,
(NSEC_PER_SEC * sent_frame_count) / duration_ns);
pps,
ppsr);
clock_nanosleep(CLOCK_TAI, TIMER_ABSTIME, &next, NULL);
}
pthread_exit(EXIT_SUCCESS);
......@@ -714,37 +729,32 @@ static int start_threads(TRXEcpriState * s) {
int startdpdk(TRXEcpriState * s) {
uint8_t ecpri_message[DATA_SIZE];
#define USE10G
#define ARGC 11
#define ARGC_LEN 256
char _argv[ARGC][ARGC_LEN] = {
"",
"-l",
"28",
"-b",
"0000:04:00.0",
#ifdef USE10G
"-b",
"0000:3b:00.0",
#endif
"-b",
"0000:3b:00.1",
#ifndef USE10G
"-b",
"0000:5e:00.0",
#endif
"-b",
"0000:5e:00.1",
};
char ** argv = (char **) malloc(sizeof(char *) * ARGC);
for(int i = 0; i < ARGC; i++) {
argv[i] = (char *) malloc(ARGC_LEN);
strcpy(argv[i], _argv[i]);
int argc = 0;
int k = 0;
int prev_space = 0;
char ** argv;
for(int i = 0;; i++)
if(s->dpdk_options[i] == ' ')
argc++;
else if(s->dpdk_options[i] == '\0')
break;
argv = (char **) malloc(sizeof(char *) * argc);
for(int i = 0;; i++) {
if(s->dpdk_options[i] == ' ') {
argv[k] = (char *) malloc(i - prev_space + 1);
strncpy(argv[k], s->dpdk_options, i - prev_space);
argv[k][i - prev_space] = '\0';
prev_space = i;
k++;
}
else if(s->dpdk_options[i] == '\0') {
break;
}
}
init_dpdk(ARGC, argv);
#undef ARGC
#undef ARGC_LEN
init_dpdk(argc, argv);
log_debug("TRX_ECPRI", "start");
......@@ -867,6 +877,8 @@ static int trx_ecpri_start(TRXState *s1, const TRXDriverParams *params)
{
TRXEcpriState *s = s1->opaque;
log_debug("TRX_ECPRI_START", "Start");
s->sample_rate = params->sample_rate[0].num / params->sample_rate[0].den;
startdpdk(s);
......@@ -909,11 +921,16 @@ int trx_driver_init(TRXState *s1)
trx_get_param_double(s1, &val, "flow_id");
s->flow_id = (int) val;
trx_get_param_double(s1, &val, "ecpri_period");
if(((int) val) == 0) {
fprintf(stderr, "ecpri_period parameter can't be null\n");
return -1;
}
s->ecpri_period = (int) val;
s->re_mac = trx_get_param_string(s1, "re_mac");
s->rec_mac = trx_get_param_string(s1, "rec_mac");
s->rec_if = trx_get_param_string(s1, "rec_if");
s->dpdk_options = trx_get_param_string(s1, "dpdk_options");
s1->opaque = s;
s1->trx_end_func = trx_ecpri_end;
......
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