summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Laatz <kevin.laatz@intel.com>2019-08-26 22:25:28 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2019-08-30 19:08:26 -0400
commitc543f54698229b50078b72760b9e8a4731cffa03 (patch)
treeed13b213a8ce720f0d5439661a11471b0e99643c
parent10d30e301732636d93d7dcd2e0e6cd34d0454509 (diff)
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: Kevin Laatz <kevin.laatz@intel.com> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com> Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--samples/bpf/xdpsock_user.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index da84c760c094..7312eab4d201 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -68,6 +68,9 @@ static int opt_queue;
68static int opt_poll; 68static int opt_poll;
69static int opt_interval = 1; 69static int opt_interval = 1;
70static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; 70static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
71static u32 opt_umem_flags;
72static int opt_unaligned_chunks;
73static u32 opt_xdp_bind_flags;
71static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE; 74static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
72static int opt_timeout = 1000; 75static int opt_timeout = 1000;
73static bool opt_need_wakeup = true; 76static bool opt_need_wakeup = true;
@@ -284,7 +287,9 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
284 .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, 287 .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
285 .frame_size = opt_xsk_frame_size, 288 .frame_size = opt_xsk_frame_size,
286 .frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM, 289 .frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM,
290 .flags = opt_umem_flags
287 }; 291 };
292
288 int ret; 293 int ret;
289 294
290 umem = calloc(1, sizeof(*umem)); 295 umem = calloc(1, sizeof(*umem));
@@ -293,6 +298,7 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
293 298
294 ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq, 299 ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq,
295 &cfg); 300 &cfg);
301
296 if (ret) 302 if (ret)
297 exit_with_error(-ret); 303 exit_with_error(-ret);
298 304
@@ -355,6 +361,7 @@ static struct option long_options[] = {
355 {"copy", no_argument, 0, 'c'}, 361 {"copy", no_argument, 0, 'c'},
356 {"frame-size", required_argument, 0, 'f'}, 362 {"frame-size", required_argument, 0, 'f'},
357 {"no-need-wakeup", no_argument, 0, 'm'}, 363 {"no-need-wakeup", no_argument, 0, 'm'},
364 {"unaligned", no_argument, 0, 'u'},
358 {0, 0, 0, 0} 365 {0, 0, 0, 0}
359}; 366};
360 367
@@ -376,6 +383,8 @@ static void usage(const char *prog)
376 " -c, --copy Force copy mode.\n" 383 " -c, --copy Force copy mode.\n"
377 " -f, --frame-size=n Set the frame size (must be a power of two, default is %d).\n" 384 " -f, --frame-size=n Set the frame size (must be a power of two, default is %d).\n"
378 " -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n" 385 " -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n"
386 " -f, --frame-size=n Set the frame size (must be a power of two in aligned mode, default is %d).\n"
387 " -u, --unaligned Enable unaligned chunk placement\n"
379 "\n"; 388 "\n";
380 fprintf(stderr, str, prog, XSK_UMEM__DEFAULT_FRAME_SIZE); 389 fprintf(stderr, str, prog, XSK_UMEM__DEFAULT_FRAME_SIZE);
381 exit(EXIT_FAILURE); 390 exit(EXIT_FAILURE);
@@ -388,8 +397,7 @@ static void parse_command_line(int argc, char **argv)
388 opterr = 0; 397 opterr = 0;
389 398
390 for (;;) { 399 for (;;) {
391 400 c = getopt_long(argc, argv, "Frtli:q:psSNn:czf:mu",
392 c = getopt_long(argc, argv, "Frtli:q:psSNn:czf:m",
393 long_options, &option_index); 401 long_options, &option_index);
394 if (c == -1) 402 if (c == -1)
395 break; 403 break;
@@ -429,6 +437,10 @@ static void parse_command_line(int argc, char **argv)
429 case 'c': 437 case 'c':
430 opt_xdp_bind_flags |= XDP_COPY; 438 opt_xdp_bind_flags |= XDP_COPY;
431 break; 439 break;
440 case 'u':
441 opt_umem_flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG;
442 opt_unaligned_chunks = 1;
443 break;
432 case 'F': 444 case 'F':
433 opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST; 445 opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
434 break; 446 break;
@@ -438,6 +450,7 @@ static void parse_command_line(int argc, char **argv)
438 opt_need_wakeup = false; 450 opt_need_wakeup = false;
439 opt_xdp_bind_flags &= ~XDP_USE_NEED_WAKEUP; 451 opt_xdp_bind_flags &= ~XDP_USE_NEED_WAKEUP;
440 break; 452 break;
453
441 default: 454 default:
442 usage(basename(argv[0])); 455 usage(basename(argv[0]));
443 } 456 }
@@ -450,7 +463,8 @@ static void parse_command_line(int argc, char **argv)
450 usage(basename(argv[0])); 463 usage(basename(argv[0]));
451 } 464 }
452 465
453 if (opt_xsk_frame_size & (opt_xsk_frame_size - 1)) { 466 if ((opt_xsk_frame_size & (opt_xsk_frame_size - 1)) &&
467 !opt_unaligned_chunks) {
454 fprintf(stderr, "--frame-size=%d is not a power of two\n", 468 fprintf(stderr, "--frame-size=%d is not a power of two\n",
455 opt_xsk_frame_size); 469 opt_xsk_frame_size);
456 usage(basename(argv[0])); 470 usage(basename(argv[0]));