Commit c543f546 authored by Kevin Laatz's avatar Kevin Laatz Committed by Daniel Borkmann

samples/bpf: add unaligned chunks mode support to xdpsock

This patch adds support for the unaligned chunks mode. The addition of the
unaligned chunks option will allow users to run the application with more
relaxed chunk placement in the XDP umem.

Unaligned chunks mode can be used with the '-u' or '--unaligned' command
line options.
Signed-off-by: default avatarKevin Laatz <kevin.laatz@intel.com>
Signed-off-by: default avatarCiara Loftus <ciara.loftus@intel.com>
Acked-by: default avatarJonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 10d30e30
...@@ -68,6 +68,9 @@ static int opt_queue; ...@@ -68,6 +68,9 @@ static int opt_queue;
static int opt_poll; static int opt_poll;
static int opt_interval = 1; static int opt_interval = 1;
static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
static u32 opt_umem_flags;
static int opt_unaligned_chunks;
static u32 opt_xdp_bind_flags;
static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE; static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
static int opt_timeout = 1000; static int opt_timeout = 1000;
static bool opt_need_wakeup = true; static bool opt_need_wakeup = true;
...@@ -284,7 +287,9 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size) ...@@ -284,7 +287,9 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = opt_xsk_frame_size, .frame_size = opt_xsk_frame_size,
.frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM, .frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM,
.flags = opt_umem_flags
}; };
int ret; int ret;
umem = calloc(1, sizeof(*umem)); umem = calloc(1, sizeof(*umem));
...@@ -293,6 +298,7 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size) ...@@ -293,6 +298,7 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq, ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq,
&cfg); &cfg);
if (ret) if (ret)
exit_with_error(-ret); exit_with_error(-ret);
...@@ -355,6 +361,7 @@ static struct option long_options[] = { ...@@ -355,6 +361,7 @@ static struct option long_options[] = {
{"copy", no_argument, 0, 'c'}, {"copy", no_argument, 0, 'c'},
{"frame-size", required_argument, 0, 'f'}, {"frame-size", required_argument, 0, 'f'},
{"no-need-wakeup", no_argument, 0, 'm'}, {"no-need-wakeup", no_argument, 0, 'm'},
{"unaligned", no_argument, 0, 'u'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
...@@ -376,6 +383,8 @@ static void usage(const char *prog) ...@@ -376,6 +383,8 @@ static void usage(const char *prog)
" -c, --copy Force copy mode.\n" " -c, --copy Force copy mode.\n"
" -f, --frame-size=n Set the frame size (must be a power of two, default is %d).\n" " -f, --frame-size=n Set the frame size (must be a power of two, default is %d).\n"
" -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n" " -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n"
" -f, --frame-size=n Set the frame size (must be a power of two in aligned mode, default is %d).\n"
" -u, --unaligned Enable unaligned chunk placement\n"
"\n"; "\n";
fprintf(stderr, str, prog, XSK_UMEM__DEFAULT_FRAME_SIZE); fprintf(stderr, str, prog, XSK_UMEM__DEFAULT_FRAME_SIZE);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -388,8 +397,7 @@ static void parse_command_line(int argc, char **argv) ...@@ -388,8 +397,7 @@ static void parse_command_line(int argc, char **argv)
opterr = 0; opterr = 0;
for (;;) { for (;;) {
c = getopt_long(argc, argv, "Frtli:q:psSNn:czf:mu",
c = getopt_long(argc, argv, "Frtli:q:psSNn:czf:m",
long_options, &option_index); long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
...@@ -429,6 +437,10 @@ static void parse_command_line(int argc, char **argv) ...@@ -429,6 +437,10 @@ static void parse_command_line(int argc, char **argv)
case 'c': case 'c':
opt_xdp_bind_flags |= XDP_COPY; opt_xdp_bind_flags |= XDP_COPY;
break; break;
case 'u':
opt_umem_flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG;
opt_unaligned_chunks = 1;
break;
case 'F': case 'F':
opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST; opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
break; break;
...@@ -438,6 +450,7 @@ static void parse_command_line(int argc, char **argv) ...@@ -438,6 +450,7 @@ static void parse_command_line(int argc, char **argv)
opt_need_wakeup = false; opt_need_wakeup = false;
opt_xdp_bind_flags &= ~XDP_USE_NEED_WAKEUP; opt_xdp_bind_flags &= ~XDP_USE_NEED_WAKEUP;
break; break;
default: default:
usage(basename(argv[0])); usage(basename(argv[0]));
} }
...@@ -450,7 +463,8 @@ static void parse_command_line(int argc, char **argv) ...@@ -450,7 +463,8 @@ static void parse_command_line(int argc, char **argv)
usage(basename(argv[0])); usage(basename(argv[0]));
} }
if (opt_xsk_frame_size & (opt_xsk_frame_size - 1)) { if ((opt_xsk_frame_size & (opt_xsk_frame_size - 1)) &&
!opt_unaligned_chunks) {
fprintf(stderr, "--frame-size=%d is not a power of two\n", fprintf(stderr, "--frame-size=%d is not a power of two\n",
opt_xsk_frame_size); opt_xsk_frame_size);
usage(basename(argv[0])); usage(basename(argv[0]));
......
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