Commit 06c22671 authored by Joanne Hugé's avatar Joanne Hugé

Clean up

parent 821d9418
......@@ -45,17 +45,21 @@
exit(EXIT_FAILURE); \
} while (0)
#define err_errno(...) error(EXIT_FAILURE, errno, __VA_ARGS__);
#define NUM_FRAMES 4096
#define ETH_FCS_SIZE 4
//#define FRAME_SIZE XSK_UMEM__DEFAULT_FRAME_SIZE
#define FRAME_SIZE 2048
#define FRAME_SIZE XSK_UMEM__DEFAULT_FRAME_SIZE
#define PACKET_SIZE 262
#define BUFFER_SIZE 4096
#define NB_PACKETS 1000000
//#define NB_PACKETS 100
#define BATCH_SIZE 2048
//#define PRINT_PROGRESS
#define PRINT_PROGRESS_INTERVAL 1000
#define ACTIVE_POLLING
//#define DEBUG
static void log_info(const char * section, const char * msg, ...) {
time_t t;
......@@ -234,11 +238,11 @@ static void init_xdp_send(char * network_if) {
log_debug("", "posix_memalign");
/* Allocate user space memory for xdp frames */
ret = posix_memalign(&buffer, sysconf(_SC_PAGE_SIZE), NUM_FRAMES * FRAME_SIZE);
ret = posix_memalign(&buffer, sysconf(_SC_PAGE_SIZE), BUFFER_SIZE * FRAME_SIZE);
if (ret) err_errno("posix_memalign() failed");
log_debug("", "xsk_umem__create");
ret = xsk_umem__create(&send_xdp_socket.umem.umem, buffer, NUM_FRAMES * FRAME_SIZE,
ret = xsk_umem__create(&send_xdp_socket.umem.umem, buffer, BUFFER_SIZE * FRAME_SIZE,
&send_xdp_socket.umem.fq, &send_xdp_socket.umem.cq, &cfg);
if (ret) err("xsk_umem__create() failed");
send_xdp_socket.umem.buffer = buffer;
......@@ -275,11 +279,11 @@ static void init_xdp_recv(char * network_if) {
log_debug("", "posix_memalign");
/* Allocate user space memory for xdp frames */
ret = posix_memalign(&buffer, sysconf(_SC_PAGE_SIZE), NUM_FRAMES * FRAME_SIZE);
ret = posix_memalign(&buffer, sysconf(_SC_PAGE_SIZE), BUFFER_SIZE * FRAME_SIZE);
if (ret) err_errno("posix_memalign() failed");
log_debug("", "xsk_umem__create");
ret = xsk_umem__create(&recv_xdp_socket.umem.umem, buffer, NUM_FRAMES * FRAME_SIZE,
ret = xsk_umem__create(&recv_xdp_socket.umem.umem, buffer, BUFFER_SIZE * FRAME_SIZE,
&recv_xdp_socket.umem.fq, &recv_xdp_socket.umem.cq, &cfg);
if (ret) err("xsk_umem__create() failed");
recv_xdp_socket.umem.buffer = buffer;
......@@ -321,7 +325,7 @@ static void send_xdp_packet(void) {
fds[0].fd = xsk_socket__fd(send_xdp_socket.xsk);
fds[0].events = POLLOUT;
for (int i = 0; i < NUM_FRAMES; i++)
for (int i = 0; i < BUFFER_SIZE; i++)
memcpy(xsk_umem__get_data(send_xdp_socket.umem.buffer, i * FRAME_SIZE), pkt_data, PACKET_SIZE - ETH_FCS_SIZE);
clock_gettime(CLOCK_MONOTONIC, &start);
......@@ -334,11 +338,19 @@ static void send_xdp_packet(void) {
progress += PRINT_PROGRESS_INTERVAL;
}
#endif
#ifdef ACTIVE_POLLING
ret = poll(fds, 1, 0);
if ((ret <= 0) || !(fds[0].revents & POLLOUT)) {
complete_tx_only();
continue;
}
#else
ret = poll(fds, 1, 100);
if ((ret <= 0) || !(fds[0].revents & POLLOUT)) {
complete_tx_only();
continue;
}
#endif
while(xsk_ring_prod__reserve(&send_xdp_socket.tx, batch_size, &idx) < batch_size)
complete_tx_only();
......
......@@ -2,7 +2,7 @@ CC=gcc
CFLAGS=-O2
CFLAGS+=-g
PROG=raw_packet
PROG=raw_socket
OBJ=$(PROG).o
all: $(PROG)
......
......@@ -7,6 +7,6 @@ tx_packets() {
make clean && make;
A=$(tx_packets)
nice -n -20 chrt 99 ./raw_packet;
nice -n -20 chrt 99 ./raw_socket;
B=$(tx_packets)
echo "Ethtool tx packets sent: $((B -A))";
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