blob: b220173dbe1e4ee80dfb724b2c076ad1cca8411d [file] [log] [blame]
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001// SPDX-License-Identifier: GPL-2.0
Björn Töpeldac09142018-05-18 14:00:21 +02002/* Copyright(c) 2017 - 2018 Intel Corporation. */
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02003
Magnus Karlsson248c7f92019-02-21 10:21:27 +01004#include <asm/barrier.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02005#include <errno.h>
6#include <getopt.h>
7#include <libgen.h>
8#include <linux/bpf.h>
Magnus Karlsson248c7f92019-02-21 10:21:27 +01009#include <linux/compiler.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020010#include <linux/if_link.h>
11#include <linux/if_xdp.h>
12#include <linux/if_ether.h>
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +053013#include <linux/ip.h>
14#include <linux/udp.h>
15#include <arpa/inet.h>
Magnus Karlsson248c7f92019-02-21 10:21:27 +010016#include <locale.h>
17#include <net/ethernet.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020018#include <net/if.h>
Magnus Karlsson248c7f92019-02-21 10:21:27 +010019#include <poll.h>
20#include <pthread.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020021#include <signal.h>
22#include <stdbool.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
Magnus Karlsson248c7f92019-02-21 10:21:27 +010026#include <sys/mman.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020027#include <sys/resource.h>
28#include <sys/socket.h>
Magnus Karlsson248c7f92019-02-21 10:21:27 +010029#include <sys/types.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020030#include <time.h>
31#include <unistd.h>
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020032
Toke Høiland-Jørgensen7cf245a2020-01-20 14:06:49 +010033#include <bpf/libbpf.h>
34#include <bpf/xsk.h>
Jakub Kicinski2bf3e2e2018-05-14 22:35:02 -070035#include <bpf/bpf.h>
Toke Høiland-Jørgensen7cf245a2020-01-20 14:06:49 +010036#include "xdpsock.h"
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020037
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020038#ifndef SOL_XDP
39#define SOL_XDP 283
40#endif
41
42#ifndef AF_XDP
43#define AF_XDP 44
44#endif
45
46#ifndef PF_XDP
47#define PF_XDP AF_XDP
48#endif
49
Magnus Karlsson248c7f92019-02-21 10:21:27 +010050#define NUM_FRAMES (4 * 1024)
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +053051#define MIN_PKT_SIZE 64
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020052
53#define DEBUG_HEXDUMP 0
54
Björn Töpela412ef52018-06-04 13:57:14 +020055typedef __u64 u64;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020056typedef __u32 u32;
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +053057typedef __u16 u16;
58typedef __u8 u8;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020059
60static unsigned long prev_time;
61
62enum benchmark_type {
63 BENCH_RXDROP = 0,
64 BENCH_TXONLY = 1,
65 BENCH_L2FWD = 2,
66};
67
68static enum benchmark_type opt_bench = BENCH_RXDROP;
Maciej Fijalkowski743e5682019-02-01 22:42:28 +010069static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020070static const char *opt_if = "";
71static int opt_ifindex;
72static int opt_queue;
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +053073static unsigned long opt_duration;
74static unsigned long start_time;
75static bool benchmark_done;
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +053076static u32 opt_batch_size = 64;
Jay Jayatheerthanece6e962019-12-20 14:25:28 +053077static int opt_pkt_count;
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +053078static u16 opt_pkt_size = MIN_PKT_SIZE;
Jay Jayatheerthan46e32682019-12-20 14:25:30 +053079static u32 opt_pkt_fill_pattern = 0x12345678;
Ciara Loftusb36c3202020-07-08 07:28:34 +000080static bool opt_extra_stats;
Magnus Karlsson74e00672020-09-10 10:31:06 +020081static bool opt_quiet;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020082static int opt_poll;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020083static int opt_interval = 1;
Magnus Karlsson46738f72019-08-14 09:27:21 +020084static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
Kevin Laatzc543f542019-08-27 02:25:28 +000085static u32 opt_umem_flags;
86static int opt_unaligned_chunks;
Kevin Laatz3945b372019-08-27 02:25:30 +000087static int opt_mmap_flags;
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +030088static int opt_xsk_frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
Magnus Karlsson46738f72019-08-14 09:27:21 +020089static int opt_timeout = 1000;
90static bool opt_need_wakeup = true;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +010091static u32 opt_num_xsks = 1;
92static u32 prog_id;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020093
Magnus Karlsson248c7f92019-02-21 10:21:27 +010094struct xsk_umem_info {
95 struct xsk_ring_prod fq;
96 struct xsk_ring_cons cq;
97 struct xsk_umem *umem;
98 void *buffer;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020099};
100
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100101struct xsk_socket_info {
102 struct xsk_ring_cons rx;
103 struct xsk_ring_prod tx;
104 struct xsk_umem_info *umem;
105 struct xsk_socket *xsk;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200106 unsigned long rx_npkts;
107 unsigned long tx_npkts;
Ciara Loftusb36c3202020-07-08 07:28:34 +0000108 unsigned long rx_dropped_npkts;
109 unsigned long rx_invalid_npkts;
110 unsigned long tx_invalid_npkts;
111 unsigned long rx_full_npkts;
112 unsigned long rx_fill_empty_npkts;
113 unsigned long tx_empty_npkts;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200114 unsigned long prev_rx_npkts;
115 unsigned long prev_tx_npkts;
Ciara Loftusb36c3202020-07-08 07:28:34 +0000116 unsigned long prev_rx_dropped_npkts;
117 unsigned long prev_rx_invalid_npkts;
118 unsigned long prev_tx_invalid_npkts;
119 unsigned long prev_rx_full_npkts;
120 unsigned long prev_rx_fill_empty_npkts;
121 unsigned long prev_tx_empty_npkts;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100122 u32 outstanding_tx;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200123};
124
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200125static int num_socks;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100126struct xsk_socket_info *xsks[MAX_SOCKS];
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200127
128static unsigned long get_nsecs(void)
129{
130 struct timespec ts;
131
132 clock_gettime(CLOCK_MONOTONIC, &ts);
133 return ts.tv_sec * 1000000000UL + ts.tv_nsec;
134}
135
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200136static void print_benchmark(bool running)
137{
138 const char *bench_str = "INVALID";
139
140 if (opt_bench == BENCH_RXDROP)
141 bench_str = "rxdrop";
142 else if (opt_bench == BENCH_TXONLY)
143 bench_str = "txonly";
144 else if (opt_bench == BENCH_L2FWD)
145 bench_str = "l2fwd";
146
147 printf("%s:%d %s ", opt_if, opt_queue, bench_str);
148 if (opt_xdp_flags & XDP_FLAGS_SKB_MODE)
149 printf("xdp-skb ");
150 else if (opt_xdp_flags & XDP_FLAGS_DRV_MODE)
151 printf("xdp-drv ");
152 else
153 printf(" ");
154
155 if (opt_poll)
156 printf("poll() ");
157
158 if (running) {
159 printf("running...");
160 fflush(stdout);
161 }
162}
163
Ciara Loftusb36c3202020-07-08 07:28:34 +0000164static int xsk_get_xdp_stats(int fd, struct xsk_socket_info *xsk)
165{
166 struct xdp_statistics stats;
167 socklen_t optlen;
168 int err;
169
170 optlen = sizeof(stats);
171 err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen);
172 if (err)
173 return err;
174
175 if (optlen == sizeof(struct xdp_statistics)) {
176 xsk->rx_dropped_npkts = stats.rx_dropped;
177 xsk->rx_invalid_npkts = stats.rx_invalid_descs;
178 xsk->tx_invalid_npkts = stats.tx_invalid_descs;
179 xsk->rx_full_npkts = stats.rx_ring_full;
180 xsk->rx_fill_empty_npkts = stats.rx_fill_ring_empty_descs;
181 xsk->tx_empty_npkts = stats.tx_ring_empty_descs;
182 return 0;
183 }
184
185 return -EINVAL;
186}
187
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200188static void dump_stats(void)
189{
190 unsigned long now = get_nsecs();
191 long dt = now - prev_time;
192 int i;
193
194 prev_time = now;
195
Prashant Bhole11c3f512018-08-31 10:00:49 +0900196 for (i = 0; i < num_socks && xsks[i]; i++) {
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200197 char *fmt = "%-15s %'-11.0f %'-11lu\n";
Ciara Loftusb36c3202020-07-08 07:28:34 +0000198 double rx_pps, tx_pps, dropped_pps, rx_invalid_pps, full_pps, fill_empty_pps,
199 tx_invalid_pps, tx_empty_pps;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200200
201 rx_pps = (xsks[i]->rx_npkts - xsks[i]->prev_rx_npkts) *
202 1000000000. / dt;
203 tx_pps = (xsks[i]->tx_npkts - xsks[i]->prev_tx_npkts) *
204 1000000000. / dt;
205
206 printf("\n sock%d@", i);
207 print_benchmark(false);
208 printf("\n");
209
210 printf("%-15s %-11s %-11s %-11.2f\n", "", "pps", "pkts",
211 dt / 1000000000.);
212 printf(fmt, "rx", rx_pps, xsks[i]->rx_npkts);
213 printf(fmt, "tx", tx_pps, xsks[i]->tx_npkts);
214
215 xsks[i]->prev_rx_npkts = xsks[i]->rx_npkts;
216 xsks[i]->prev_tx_npkts = xsks[i]->tx_npkts;
Ciara Loftusb36c3202020-07-08 07:28:34 +0000217
218 if (opt_extra_stats) {
219 if (!xsk_get_xdp_stats(xsk_socket__fd(xsks[i]->xsk), xsks[i])) {
220 dropped_pps = (xsks[i]->rx_dropped_npkts -
221 xsks[i]->prev_rx_dropped_npkts) * 1000000000. / dt;
222 rx_invalid_pps = (xsks[i]->rx_invalid_npkts -
223 xsks[i]->prev_rx_invalid_npkts) * 1000000000. / dt;
224 tx_invalid_pps = (xsks[i]->tx_invalid_npkts -
225 xsks[i]->prev_tx_invalid_npkts) * 1000000000. / dt;
226 full_pps = (xsks[i]->rx_full_npkts -
227 xsks[i]->prev_rx_full_npkts) * 1000000000. / dt;
228 fill_empty_pps = (xsks[i]->rx_fill_empty_npkts -
229 xsks[i]->prev_rx_fill_empty_npkts)
230 * 1000000000. / dt;
231 tx_empty_pps = (xsks[i]->tx_empty_npkts -
232 xsks[i]->prev_tx_empty_npkts) * 1000000000. / dt;
233
234 printf(fmt, "rx dropped", dropped_pps,
235 xsks[i]->rx_dropped_npkts);
236 printf(fmt, "rx invalid", rx_invalid_pps,
237 xsks[i]->rx_invalid_npkts);
238 printf(fmt, "tx invalid", tx_invalid_pps,
239 xsks[i]->tx_invalid_npkts);
240 printf(fmt, "rx queue full", full_pps,
241 xsks[i]->rx_full_npkts);
242 printf(fmt, "fill ring empty", fill_empty_pps,
243 xsks[i]->rx_fill_empty_npkts);
244 printf(fmt, "tx ring empty", tx_empty_pps,
245 xsks[i]->tx_empty_npkts);
246
247 xsks[i]->prev_rx_dropped_npkts = xsks[i]->rx_dropped_npkts;
248 xsks[i]->prev_rx_invalid_npkts = xsks[i]->rx_invalid_npkts;
249 xsks[i]->prev_tx_invalid_npkts = xsks[i]->tx_invalid_npkts;
250 xsks[i]->prev_rx_full_npkts = xsks[i]->rx_full_npkts;
251 xsks[i]->prev_rx_fill_empty_npkts = xsks[i]->rx_fill_empty_npkts;
252 xsks[i]->prev_tx_empty_npkts = xsks[i]->tx_empty_npkts;
253 } else {
254 printf("%-15s\n", "Error retrieving extra stats");
255 }
256 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200257 }
258}
259
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +0530260static bool is_benchmark_done(void)
261{
262 if (opt_duration > 0) {
263 unsigned long dt = (get_nsecs() - start_time);
264
265 if (dt >= opt_duration)
266 benchmark_done = true;
267 }
268 return benchmark_done;
269}
270
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200271static void *poller(void *arg)
272{
273 (void)arg;
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +0530274 while (!is_benchmark_done()) {
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200275 sleep(opt_interval);
276 dump_stats();
277 }
278
279 return NULL;
280}
281
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100282static void remove_xdp_program(void)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200283{
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100284 u32 curr_prog_id = 0;
Maciej Fijalkowski3b7a8ec2019-02-01 22:42:30 +0100285
Maciej Fijalkowski3b7a8ec2019-02-01 22:42:30 +0100286 if (bpf_get_link_xdp_id(opt_ifindex, &curr_prog_id, opt_xdp_flags)) {
287 printf("bpf_get_link_xdp_id failed\n");
288 exit(EXIT_FAILURE);
289 }
290 if (prog_id == curr_prog_id)
291 bpf_set_link_xdp_fd(opt_ifindex, -1, opt_xdp_flags);
292 else if (!curr_prog_id)
293 printf("couldn't find a prog id on a given interface\n");
294 else
295 printf("program on interface changed, not removing\n");
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100296}
297
298static void int_exit(int sig)
299{
Jay Jayatheerthan69525582019-12-20 14:25:26 +0530300 benchmark_done = true;
301}
302
303static void xdpsock_cleanup(void)
304{
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100305 struct xsk_umem *umem = xsks[0]->umem->umem;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100306 int i;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100307
308 dump_stats();
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100309 for (i = 0; i < num_socks; i++)
310 xsk_socket__delete(xsks[i]->xsk);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100311 (void)xsk_umem__delete(umem);
312 remove_xdp_program();
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200313}
314
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100315static void __exit_with_error(int error, const char *file, const char *func,
316 int line)
317{
318 fprintf(stderr, "%s:%s:%i: errno: %d/\"%s\"\n", file, func,
319 line, error, strerror(error));
320 dump_stats();
321 remove_xdp_program();
322 exit(EXIT_FAILURE);
323}
324
325#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, \
326 __LINE__)
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100327static void swap_mac_addresses(void *data)
328{
329 struct ether_header *eth = (struct ether_header *)data;
330 struct ether_addr *src_addr = (struct ether_addr *)&eth->ether_shost;
331 struct ether_addr *dst_addr = (struct ether_addr *)&eth->ether_dhost;
332 struct ether_addr tmp;
333
334 tmp = *src_addr;
335 *src_addr = *dst_addr;
336 *dst_addr = tmp;
337}
338
339static void hex_dump(void *pkt, size_t length, u64 addr)
340{
341 const unsigned char *address = (unsigned char *)pkt;
342 const unsigned char *line = address;
343 size_t line_size = 32;
344 unsigned char c;
345 char buf[32];
346 int i = 0;
347
348 if (!DEBUG_HEXDUMP)
349 return;
350
351 sprintf(buf, "addr=%llu", addr);
352 printf("length = %zu\n", length);
353 printf("%s | ", buf);
354 while (length-- > 0) {
355 printf("%02X ", *address++);
356 if (!(++i % line_size) || (length == 0 && i % line_size)) {
357 if (length == 0) {
358 while (i++ % line_size)
359 printf("__ ");
360 }
361 printf(" | "); /* right close */
362 while (line < address) {
363 c = *line++;
364 printf("%c", (c < 33 || c == 255) ? 0x2E : c);
365 }
366 printf("\n");
367 if (length > 0)
368 printf("%s | ", buf);
369 }
370 }
371 printf("\n");
372}
373
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530374static void *memset32_htonl(void *dest, u32 val, u32 size)
375{
376 u32 *ptr = (u32 *)dest;
377 int i;
378
379 val = htonl(val);
380
381 for (i = 0; i < (size & (~0x3)); i += 4)
382 ptr[i >> 2] = val;
383
384 for (; i < size; i++)
385 ((char *)dest)[i] = ((char *)&val)[i & 3];
386
387 return dest;
388}
389
390/*
391 * This function code has been taken from
392 * Linux kernel lib/checksum.c
393 */
394static inline unsigned short from32to16(unsigned int x)
395{
396 /* add up 16-bit and 16-bit for 16+c bit */
397 x = (x & 0xffff) + (x >> 16);
398 /* add up carry.. */
399 x = (x & 0xffff) + (x >> 16);
400 return x;
401}
402
403/*
404 * This function code has been taken from
405 * Linux kernel lib/checksum.c
406 */
407static unsigned int do_csum(const unsigned char *buff, int len)
408{
409 unsigned int result = 0;
410 int odd;
411
412 if (len <= 0)
413 goto out;
414 odd = 1 & (unsigned long)buff;
415 if (odd) {
416#ifdef __LITTLE_ENDIAN
417 result += (*buff << 8);
418#else
419 result = *buff;
420#endif
421 len--;
422 buff++;
423 }
424 if (len >= 2) {
425 if (2 & (unsigned long)buff) {
426 result += *(unsigned short *)buff;
427 len -= 2;
428 buff += 2;
429 }
430 if (len >= 4) {
431 const unsigned char *end = buff +
432 ((unsigned int)len & ~3);
433 unsigned int carry = 0;
434
435 do {
436 unsigned int w = *(unsigned int *)buff;
437
438 buff += 4;
439 result += carry;
440 result += w;
441 carry = (w > result);
442 } while (buff < end);
443 result += carry;
444 result = (result & 0xffff) + (result >> 16);
445 }
446 if (len & 2) {
447 result += *(unsigned short *)buff;
448 buff += 2;
449 }
450 }
451 if (len & 1)
452#ifdef __LITTLE_ENDIAN
453 result += *buff;
454#else
455 result += (*buff << 8);
456#endif
457 result = from32to16(result);
458 if (odd)
459 result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
460out:
461 return result;
462}
463
464__sum16 ip_fast_csum(const void *iph, unsigned int ihl);
465
466/*
467 * This is a version of ip_compute_csum() optimized for IP headers,
468 * which always checksum on 4 octet boundaries.
469 * This function code has been taken from
470 * Linux kernel lib/checksum.c
471 */
472__sum16 ip_fast_csum(const void *iph, unsigned int ihl)
473{
474 return (__force __sum16)~do_csum(iph, ihl * 4);
475}
476
477/*
478 * Fold a partial checksum
479 * This function code has been taken from
480 * Linux kernel include/asm-generic/checksum.h
481 */
482static inline __sum16 csum_fold(__wsum csum)
483{
484 u32 sum = (__force u32)csum;
485
486 sum = (sum & 0xffff) + (sum >> 16);
487 sum = (sum & 0xffff) + (sum >> 16);
488 return (__force __sum16)~sum;
489}
490
491/*
492 * This function code has been taken from
493 * Linux kernel lib/checksum.c
494 */
495static inline u32 from64to32(u64 x)
496{
497 /* add up 32-bit and 32-bit for 32+c bit */
498 x = (x & 0xffffffff) + (x >> 32);
499 /* add up carry.. */
500 x = (x & 0xffffffff) + (x >> 32);
501 return (u32)x;
502}
503
504__wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
505 __u32 len, __u8 proto, __wsum sum);
506
507/*
508 * This function code has been taken from
509 * Linux kernel lib/checksum.c
510 */
511__wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
512 __u32 len, __u8 proto, __wsum sum)
513{
514 unsigned long long s = (__force u32)sum;
515
516 s += (__force u32)saddr;
517 s += (__force u32)daddr;
518#ifdef __BIG_ENDIAN__
519 s += proto + len;
520#else
521 s += (proto + len) << 8;
522#endif
523 return (__force __wsum)from64to32(s);
524}
525
526/*
527 * This function has been taken from
528 * Linux kernel include/asm-generic/checksum.h
529 */
530static inline __sum16
531csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len,
532 __u8 proto, __wsum sum)
533{
534 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
535}
536
537static inline u16 udp_csum(u32 saddr, u32 daddr, u32 len,
538 u8 proto, u16 *udp_pkt)
539{
540 u32 csum = 0;
541 u32 cnt = 0;
542
543 /* udp hdr and data */
544 for (; cnt < len; cnt += 2)
545 csum += udp_pkt[cnt >> 1];
546
547 return csum_tcpudp_magic(saddr, daddr, len, proto, csum);
548}
549
550#define ETH_FCS_SIZE 4
551
552#define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
553 sizeof(struct udphdr))
554
555#define PKT_SIZE (opt_pkt_size - ETH_FCS_SIZE)
556#define IP_PKT_SIZE (PKT_SIZE - sizeof(struct ethhdr))
557#define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr))
558#define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr))
559
560static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
561
562static void gen_eth_hdr_data(void)
563{
564 struct udphdr *udp_hdr = (struct udphdr *)(pkt_data +
565 sizeof(struct ethhdr) +
566 sizeof(struct iphdr));
567 struct iphdr *ip_hdr = (struct iphdr *)(pkt_data +
568 sizeof(struct ethhdr));
569 struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data;
570
571 /* ethernet header */
572 memcpy(eth_hdr->h_dest, "\x3c\xfd\xfe\x9e\x7f\x71", ETH_ALEN);
573 memcpy(eth_hdr->h_source, "\xec\xb1\xd7\x98\x3a\xc0", ETH_ALEN);
574 eth_hdr->h_proto = htons(ETH_P_IP);
575
576 /* IP header */
577 ip_hdr->version = IPVERSION;
578 ip_hdr->ihl = 0x5; /* 20 byte header */
579 ip_hdr->tos = 0x0;
580 ip_hdr->tot_len = htons(IP_PKT_SIZE);
581 ip_hdr->id = 0;
582 ip_hdr->frag_off = 0;
583 ip_hdr->ttl = IPDEFTTL;
584 ip_hdr->protocol = IPPROTO_UDP;
585 ip_hdr->saddr = htonl(0x0a0a0a10);
586 ip_hdr->daddr = htonl(0x0a0a0a20);
587
588 /* IP header checksum */
589 ip_hdr->check = 0;
590 ip_hdr->check = ip_fast_csum((const void *)ip_hdr, ip_hdr->ihl);
591
592 /* UDP header */
593 udp_hdr->source = htons(0x1000);
594 udp_hdr->dest = htons(0x1000);
595 udp_hdr->len = htons(UDP_PKT_SIZE);
596
597 /* UDP data */
Jay Jayatheerthan46e32682019-12-20 14:25:30 +0530598 memset32_htonl(pkt_data + PKT_HDR_SIZE, opt_pkt_fill_pattern,
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530599 UDP_PKT_DATA_SIZE);
600
601 /* UDP header checksum */
602 udp_hdr->check = 0;
603 udp_hdr->check = udp_csum(ip_hdr->saddr, ip_hdr->daddr, UDP_PKT_SIZE,
604 IPPROTO_UDP, (u16 *)udp_hdr);
605}
606
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530607static void gen_eth_frame(struct xsk_umem_info *umem, u64 addr)
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100608{
609 memcpy(xsk_umem__get_data(umem->buffer, addr), pkt_data,
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530610 PKT_SIZE);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100611}
612
613static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
614{
615 struct xsk_umem_info *umem;
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300616 struct xsk_umem_config cfg = {
Magnus Karlssonc8a039a2020-08-28 14:51:05 +0200617 /* We recommend that you set the fill ring size >= HW RX ring size +
618 * AF_XDP RX ring size. Make sure you fill up the fill ring
619 * with buffers at regular intervals, and you will with this setting
620 * avoid allocation failures in the driver. These are usually quite
621 * expensive since drivers have not been written to assume that
622 * allocation failures are common. For regular sockets, kernel
623 * allocated memory is used that only runs out in OOM situations
624 * that should be rare.
625 */
626 .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS * 2,
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300627 .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
628 .frame_size = opt_xsk_frame_size,
629 .frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM,
Kevin Laatzc543f542019-08-27 02:25:28 +0000630 .flags = opt_umem_flags
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300631 };
Magnus Karlsson661842c2019-11-07 18:47:39 +0100632 int ret;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100633
634 umem = calloc(1, sizeof(*umem));
635 if (!umem)
636 exit_with_error(errno);
637
638 ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq,
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300639 &cfg);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100640 if (ret)
641 exit_with_error(-ret);
642
Magnus Karlsson661842c2019-11-07 18:47:39 +0100643 umem->buffer = buffer;
644 return umem;
645}
646
647static void xsk_populate_fill_ring(struct xsk_umem_info *umem)
648{
649 int ret, i;
650 u32 idx;
651
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100652 ret = xsk_ring_prod__reserve(&umem->fq,
Magnus Karlssonc8a039a2020-08-28 14:51:05 +0200653 XSK_RING_PROD__DEFAULT_NUM_DESCS * 2, &idx);
654 if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS * 2)
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100655 exit_with_error(-ret);
Magnus Karlssonc8a039a2020-08-28 14:51:05 +0200656 for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS * 2; i++)
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100657 *xsk_ring_prod__fill_addr(&umem->fq, idx++) =
658 i * opt_xsk_frame_size;
Magnus Karlssonc8a039a2020-08-28 14:51:05 +0200659 xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS * 2);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100660}
661
Magnus Karlsson661842c2019-11-07 18:47:39 +0100662static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
663 bool rx, bool tx)
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100664{
665 struct xsk_socket_config cfg;
666 struct xsk_socket_info *xsk;
Magnus Karlsson661842c2019-11-07 18:47:39 +0100667 struct xsk_ring_cons *rxr;
668 struct xsk_ring_prod *txr;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100669 int ret;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100670
671 xsk = calloc(1, sizeof(*xsk));
672 if (!xsk)
673 exit_with_error(errno);
674
675 xsk->umem = umem;
676 cfg.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
677 cfg.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100678 if (opt_num_xsks > 1)
679 cfg.libbpf_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD;
680 else
681 cfg.libbpf_flags = 0;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100682 cfg.xdp_flags = opt_xdp_flags;
683 cfg.bind_flags = opt_xdp_bind_flags;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100684
Magnus Karlsson661842c2019-11-07 18:47:39 +0100685 rxr = rx ? &xsk->rx : NULL;
686 txr = tx ? &xsk->tx : NULL;
687 ret = xsk_socket__create(&xsk->xsk, opt_if, opt_queue, umem->umem,
688 rxr, txr, &cfg);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100689 if (ret)
690 exit_with_error(-ret);
691
692 ret = bpf_get_link_xdp_id(opt_ifindex, &prog_id, opt_xdp_flags);
693 if (ret)
694 exit_with_error(-ret);
695
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100696 return xsk;
697}
698
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200699static struct option long_options[] = {
700 {"rxdrop", no_argument, 0, 'r'},
701 {"txonly", no_argument, 0, 't'},
702 {"l2fwd", no_argument, 0, 'l'},
703 {"interface", required_argument, 0, 'i'},
704 {"queue", required_argument, 0, 'q'},
705 {"poll", no_argument, 0, 'p'},
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200706 {"xdp-skb", no_argument, 0, 'S'},
707 {"xdp-native", no_argument, 0, 'N'},
708 {"interval", required_argument, 0, 'n'},
Björn Töpel58c50ae2018-08-28 14:44:35 +0200709 {"zero-copy", no_argument, 0, 'z'},
710 {"copy", no_argument, 0, 'c'},
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300711 {"frame-size", required_argument, 0, 'f'},
Magnus Karlsson46738f72019-08-14 09:27:21 +0200712 {"no-need-wakeup", no_argument, 0, 'm'},
Kevin Laatzc543f542019-08-27 02:25:28 +0000713 {"unaligned", no_argument, 0, 'u'},
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100714 {"shared-umem", no_argument, 0, 'M'},
Andre Guedesb3133322019-11-14 08:28:47 -0800715 {"force", no_argument, 0, 'F'},
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +0530716 {"duration", required_argument, 0, 'd'},
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530717 {"batch-size", required_argument, 0, 'b'},
Jay Jayatheerthanece6e962019-12-20 14:25:28 +0530718 {"tx-pkt-count", required_argument, 0, 'C'},
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530719 {"tx-pkt-size", required_argument, 0, 's'},
Jay Jayatheerthan46e32682019-12-20 14:25:30 +0530720 {"tx-pkt-pattern", required_argument, 0, 'P'},
Ciara Loftusb36c3202020-07-08 07:28:34 +0000721 {"extra-stats", no_argument, 0, 'x'},
Magnus Karlsson74e00672020-09-10 10:31:06 +0200722 {"quiet", no_argument, 0, 'Q'},
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200723 {0, 0, 0, 0}
724};
725
726static void usage(const char *prog)
727{
728 const char *str =
729 " Usage: %s [OPTIONS]\n"
730 " Options:\n"
731 " -r, --rxdrop Discard all incoming packets (default)\n"
732 " -t, --txonly Only send packets\n"
733 " -l, --l2fwd MAC swap L2 forwarding\n"
734 " -i, --interface=n Run on interface n\n"
735 " -q, --queue=n Use queue n (default 0)\n"
736 " -p, --poll Use poll syscall\n"
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200737 " -S, --xdp-skb=n Use XDP skb-mod\n"
Anton Ivanov4564a8bb2019-10-07 09:26:36 +0100738 " -N, --xdp-native=n Enforce XDP native mode\n"
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200739 " -n, --interval=n Specify statistics update interval (default 1 sec).\n"
Björn Töpel58c50ae2018-08-28 14:44:35 +0200740 " -z, --zero-copy Force zero-copy mode.\n"
741 " -c, --copy Force copy mode.\n"
Magnus Karlsson46738f72019-08-14 09:27:21 +0200742 " -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n"
Kevin Laatzc543f542019-08-27 02:25:28 +0000743 " -f, --frame-size=n Set the frame size (must be a power of two in aligned mode, default is %d).\n"
744 " -u, --unaligned Enable unaligned chunk placement\n"
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100745 " -M, --shared-umem Enable XDP_SHARED_UMEM\n"
Andre Guedesb3133322019-11-14 08:28:47 -0800746 " -F, --force Force loading the XDP prog\n"
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +0530747 " -d, --duration=n Duration in secs to run command.\n"
748 " Default: forever.\n"
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530749 " -b, --batch-size=n Batch size for sending or receiving\n"
750 " packets. Default: %d\n"
Jay Jayatheerthanece6e962019-12-20 14:25:28 +0530751 " -C, --tx-pkt-count=n Number of packets to send.\n"
752 " Default: Continuous packets.\n"
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530753 " -s, --tx-pkt-size=n Transmit packet size.\n"
754 " (Default: %d bytes)\n"
755 " Min size: %d, Max size %d.\n"
Jay Jayatheerthan46e32682019-12-20 14:25:30 +0530756 " -P, --tx-pkt-pattern=nPacket fill pattern. Default: 0x%x\n"
Ciara Loftusb36c3202020-07-08 07:28:34 +0000757 " -x, --extra-stats Display extra statistics.\n"
Magnus Karlsson74e00672020-09-10 10:31:06 +0200758 " -Q, --quiet Do not display any stats.\n"
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200759 "\n";
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530760 fprintf(stderr, str, prog, XSK_UMEM__DEFAULT_FRAME_SIZE,
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530761 opt_batch_size, MIN_PKT_SIZE, MIN_PKT_SIZE,
Jay Jayatheerthan46e32682019-12-20 14:25:30 +0530762 XSK_UMEM__DEFAULT_FRAME_SIZE, opt_pkt_fill_pattern);
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530763
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200764 exit(EXIT_FAILURE);
765}
766
767static void parse_command_line(int argc, char **argv)
768{
769 int option_index, c;
770
771 opterr = 0;
772
773 for (;;) {
Magnus Karlsson74e00672020-09-10 10:31:06 +0200774 c = getopt_long(argc, argv, "Frtli:q:pSNn:czf:muMd:b:C:s:P:xQ",
Magnus Karlsson46738f72019-08-14 09:27:21 +0200775 long_options, &option_index);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200776 if (c == -1)
777 break;
778
779 switch (c) {
780 case 'r':
781 opt_bench = BENCH_RXDROP;
782 break;
783 case 't':
784 opt_bench = BENCH_TXONLY;
785 break;
786 case 'l':
787 opt_bench = BENCH_L2FWD;
788 break;
789 case 'i':
790 opt_if = optarg;
791 break;
792 case 'q':
793 opt_queue = atoi(optarg);
794 break;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200795 case 'p':
796 opt_poll = 1;
797 break;
798 case 'S':
799 opt_xdp_flags |= XDP_FLAGS_SKB_MODE;
Björn Töpel9f5232c2018-06-04 14:06:01 +0200800 opt_xdp_bind_flags |= XDP_COPY;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200801 break;
802 case 'N':
Toke Høiland-Jørgensend50ecc42019-12-16 12:07:42 +0100803 /* default, set below */
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200804 break;
805 case 'n':
806 opt_interval = atoi(optarg);
807 break;
Björn Töpel58c50ae2018-08-28 14:44:35 +0200808 case 'z':
809 opt_xdp_bind_flags |= XDP_ZEROCOPY;
810 break;
811 case 'c':
812 opt_xdp_bind_flags |= XDP_COPY;
813 break;
Kevin Laatzc543f542019-08-27 02:25:28 +0000814 case 'u':
815 opt_umem_flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG;
816 opt_unaligned_chunks = 1;
Kevin Laatz3945b372019-08-27 02:25:30 +0000817 opt_mmap_flags = MAP_HUGETLB;
Kevin Laatzc543f542019-08-27 02:25:28 +0000818 break;
Maciej Fijalkowski743e5682019-02-01 22:42:28 +0100819 case 'F':
820 opt_xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
821 break;
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300822 case 'f':
823 opt_xsk_frame_size = atoi(optarg);
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100824 break;
Magnus Karlsson46738f72019-08-14 09:27:21 +0200825 case 'm':
826 opt_need_wakeup = false;
827 opt_xdp_bind_flags &= ~XDP_USE_NEED_WAKEUP;
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300828 break;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +0100829 case 'M':
830 opt_num_xsks = MAX_SOCKS;
831 break;
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +0530832 case 'd':
833 opt_duration = atoi(optarg);
834 opt_duration *= 1000000000;
835 break;
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530836 case 'b':
837 opt_batch_size = atoi(optarg);
838 break;
Jay Jayatheerthanece6e962019-12-20 14:25:28 +0530839 case 'C':
840 opt_pkt_count = atoi(optarg);
841 break;
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +0530842 case 's':
843 opt_pkt_size = atoi(optarg);
844 if (opt_pkt_size > (XSK_UMEM__DEFAULT_FRAME_SIZE) ||
845 opt_pkt_size < MIN_PKT_SIZE) {
846 fprintf(stderr,
847 "ERROR: Invalid frame size %d\n",
848 opt_pkt_size);
849 usage(basename(argv[0]));
850 }
851 break;
Jay Jayatheerthan46e32682019-12-20 14:25:30 +0530852 case 'P':
853 opt_pkt_fill_pattern = strtol(optarg, NULL, 16);
854 break;
Ciara Loftusb36c3202020-07-08 07:28:34 +0000855 case 'x':
856 opt_extra_stats = 1;
857 break;
Magnus Karlsson74e00672020-09-10 10:31:06 +0200858 case 'Q':
859 opt_quiet = 1;
860 break;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200861 default:
862 usage(basename(argv[0]));
863 }
864 }
865
Toke Høiland-Jørgensend50ecc42019-12-16 12:07:42 +0100866 if (!(opt_xdp_flags & XDP_FLAGS_SKB_MODE))
867 opt_xdp_flags |= XDP_FLAGS_DRV_MODE;
868
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200869 opt_ifindex = if_nametoindex(opt_if);
870 if (!opt_ifindex) {
871 fprintf(stderr, "ERROR: interface \"%s\" does not exist\n",
872 opt_if);
873 usage(basename(argv[0]));
874 }
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100875
Kevin Laatzc543f542019-08-27 02:25:28 +0000876 if ((opt_xsk_frame_size & (opt_xsk_frame_size - 1)) &&
877 !opt_unaligned_chunks) {
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +0300878 fprintf(stderr, "--frame-size=%d is not a power of two\n",
879 opt_xsk_frame_size);
880 usage(basename(argv[0]));
881 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200882}
883
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100884static void kick_tx(struct xsk_socket_info *xsk)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200885{
886 int ret;
887
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100888 ret = sendto(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, 0);
Maciej Fijalkowski8ed47e12020-02-05 05:58:34 +0100889 if (ret >= 0 || errno == ENOBUFS || errno == EAGAIN ||
890 errno == EBUSY || errno == ENETDOWN)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200891 return;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100892 exit_with_error(errno);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200893}
894
Magnus Karlsson46738f72019-08-14 09:27:21 +0200895static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk,
896 struct pollfd *fds)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200897{
Kevin Laatz03895e62019-08-27 02:25:29 +0000898 struct xsk_umem_info *umem = xsk->umem;
Yonghong Songb74e21a2019-02-28 22:19:41 -0800899 u32 idx_cq = 0, idx_fq = 0;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200900 unsigned int rcvd;
901 size_t ndescs;
902
903 if (!xsk->outstanding_tx)
904 return;
905
Magnus Karlsson3131cf62020-09-10 10:31:04 +0200906 /* In copy mode, Tx is driven by a syscall so we need to use e.g. sendto() to
907 * really send the packets. In zero-copy mode we do not have to do this, since Tx
908 * is driven by the NAPI loop. So as an optimization, we do not have to call
909 * sendto() all the time in zero-copy mode for l2fwd.
910 */
911 if (opt_xdp_bind_flags & XDP_COPY)
912 kick_tx(xsk);
913
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530914 ndescs = (xsk->outstanding_tx > opt_batch_size) ? opt_batch_size :
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100915 xsk->outstanding_tx;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200916
917 /* re-add completed Tx buffers */
Kevin Laatz03895e62019-08-27 02:25:29 +0000918 rcvd = xsk_ring_cons__peek(&umem->cq, ndescs, &idx_cq);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200919 if (rcvd > 0) {
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100920 unsigned int i;
921 int ret;
922
Kevin Laatz03895e62019-08-27 02:25:29 +0000923 ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100924 while (ret != rcvd) {
925 if (ret < 0)
926 exit_with_error(-ret);
Kevin Laatz03895e62019-08-27 02:25:29 +0000927 if (xsk_ring_prod__needs_wakeup(&umem->fq))
Magnus Karlsson46738f72019-08-14 09:27:21 +0200928 ret = poll(fds, num_socks, opt_timeout);
Kevin Laatz03895e62019-08-27 02:25:29 +0000929 ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100930 }
Kevin Laatz03895e62019-08-27 02:25:29 +0000931
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100932 for (i = 0; i < rcvd; i++)
Kevin Laatz03895e62019-08-27 02:25:29 +0000933 *xsk_ring_prod__fill_addr(&umem->fq, idx_fq++) =
934 *xsk_ring_cons__comp_addr(&umem->cq, idx_cq++);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100935
936 xsk_ring_prod__submit(&xsk->umem->fq, rcvd);
937 xsk_ring_cons__release(&xsk->umem->cq, rcvd);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200938 xsk->outstanding_tx -= rcvd;
939 xsk->tx_npkts += rcvd;
940 }
941}
942
Jay Jayatheerthanece6e962019-12-20 14:25:28 +0530943static inline void complete_tx_only(struct xsk_socket_info *xsk,
944 int batch_size)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200945{
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200946 unsigned int rcvd;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100947 u32 idx;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200948
949 if (!xsk->outstanding_tx)
950 return;
951
Magnus Karlsson46738f72019-08-14 09:27:21 +0200952 if (!opt_need_wakeup || xsk_ring_prod__needs_wakeup(&xsk->tx))
953 kick_tx(xsk);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200954
Jay Jayatheerthanece6e962019-12-20 14:25:28 +0530955 rcvd = xsk_ring_cons__peek(&xsk->umem->cq, batch_size, &idx);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200956 if (rcvd > 0) {
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100957 xsk_ring_cons__release(&xsk->umem->cq, rcvd);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200958 xsk->outstanding_tx -= rcvd;
959 xsk->tx_npkts += rcvd;
960 }
961}
962
Magnus Karlsson46738f72019-08-14 09:27:21 +0200963static void rx_drop(struct xsk_socket_info *xsk, struct pollfd *fds)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200964{
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200965 unsigned int rcvd, i;
Yonghong Songb74e21a2019-02-28 22:19:41 -0800966 u32 idx_rx = 0, idx_fq = 0;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100967 int ret;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200968
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +0530969 rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx);
Magnus Karlsson46738f72019-08-14 09:27:21 +0200970 if (!rcvd) {
971 if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq))
972 ret = poll(fds, num_socks, opt_timeout);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200973 return;
Magnus Karlsson46738f72019-08-14 09:27:21 +0200974 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200975
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100976 ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq);
977 while (ret != rcvd) {
978 if (ret < 0)
979 exit_with_error(-ret);
Magnus Karlsson46738f72019-08-14 09:27:21 +0200980 if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq))
981 ret = poll(fds, num_socks, opt_timeout);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100982 ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200983 }
984
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100985 for (i = 0; i < rcvd; i++) {
986 u64 addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr;
987 u32 len = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++)->len;
Kevin Laatz03895e62019-08-27 02:25:29 +0000988 u64 orig = xsk_umem__extract_addr(addr);
989
990 addr = xsk_umem__add_offset_to_addr(addr);
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100991 char *pkt = xsk_umem__get_data(xsk->umem->buffer, addr);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200992
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100993 hex_dump(pkt, len, addr);
Kevin Laatz03895e62019-08-27 02:25:29 +0000994 *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig;
Magnus Karlsson248c7f92019-02-21 10:21:27 +0100995 }
996
997 xsk_ring_prod__submit(&xsk->umem->fq, rcvd);
998 xsk_ring_cons__release(&xsk->rx, rcvd);
999 xsk->rx_npkts += rcvd;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001000}
1001
1002static void rx_drop_all(void)
1003{
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001004 struct pollfd fds[MAX_SOCKS] = {};
Magnus Karlsson46738f72019-08-14 09:27:21 +02001005 int i, ret;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001006
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001007 for (i = 0; i < num_socks; i++) {
Magnus Karlsson248c7f92019-02-21 10:21:27 +01001008 fds[i].fd = xsk_socket__fd(xsks[i]->xsk);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001009 fds[i].events = POLLIN;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001010 }
1011
1012 for (;;) {
1013 if (opt_poll) {
Magnus Karlsson46738f72019-08-14 09:27:21 +02001014 ret = poll(fds, num_socks, opt_timeout);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001015 if (ret <= 0)
1016 continue;
1017 }
1018
1019 for (i = 0; i < num_socks; i++)
Magnus Karlsson46738f72019-08-14 09:27:21 +02001020 rx_drop(xsks[i], fds);
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +05301021
1022 if (benchmark_done)
1023 break;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001024 }
1025}
1026
Weqaar Janjuab69e56c2020-08-29 00:17:17 +08001027static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001028{
Magnus Karlsson46738f72019-08-14 09:27:21 +02001029 u32 idx;
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +05301030 unsigned int i;
Magnus Karlsson46738f72019-08-14 09:27:21 +02001031
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301032 while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) <
1033 batch_size) {
1034 complete_tx_only(xsk, batch_size);
Magnus Karlsson46738f72019-08-14 09:27:21 +02001035 }
1036
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301037 for (i = 0; i < batch_size; i++) {
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +05301038 struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx,
1039 idx + i);
Weqaar Janjuab69e56c2020-08-29 00:17:17 +08001040 tx_desc->addr = (*frame_nb + i) << XSK_UMEM__DEFAULT_FRAME_SHIFT;
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +05301041 tx_desc->len = PKT_SIZE;
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +05301042 }
1043
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301044 xsk_ring_prod__submit(&xsk->tx, batch_size);
1045 xsk->outstanding_tx += batch_size;
Weqaar Janjuab69e56c2020-08-29 00:17:17 +08001046 *frame_nb += batch_size;
1047 *frame_nb %= NUM_FRAMES;
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301048 complete_tx_only(xsk, batch_size);
1049}
1050
1051static inline int get_batch_size(int pkt_cnt)
1052{
1053 if (!opt_pkt_count)
1054 return opt_batch_size;
1055
1056 if (pkt_cnt + opt_batch_size <= opt_pkt_count)
1057 return opt_batch_size;
1058
1059 return opt_pkt_count - pkt_cnt;
1060}
1061
1062static void complete_tx_only_all(void)
1063{
1064 bool pending;
1065 int i;
1066
1067 do {
1068 pending = false;
1069 for (i = 0; i < num_socks; i++) {
1070 if (xsks[i]->outstanding_tx) {
1071 complete_tx_only(xsks[i], opt_batch_size);
1072 pending = !!xsks[i]->outstanding_tx;
1073 }
1074 }
1075 } while (pending);
Magnus Karlsson46738f72019-08-14 09:27:21 +02001076}
1077
1078static void tx_only_all(void)
1079{
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001080 struct pollfd fds[MAX_SOCKS] = {};
Magnus Karlsson46738f72019-08-14 09:27:21 +02001081 u32 frame_nb[MAX_SOCKS] = {};
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301082 int pkt_cnt = 0;
Magnus Karlsson46738f72019-08-14 09:27:21 +02001083 int i, ret;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001084
Magnus Karlsson46738f72019-08-14 09:27:21 +02001085 for (i = 0; i < num_socks; i++) {
1086 fds[0].fd = xsk_socket__fd(xsks[i]->xsk);
1087 fds[0].events = POLLOUT;
1088 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001089
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301090 while ((opt_pkt_count && pkt_cnt < opt_pkt_count) || !opt_pkt_count) {
1091 int batch_size = get_batch_size(pkt_cnt);
1092
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001093 if (opt_poll) {
Magnus Karlsson46738f72019-08-14 09:27:21 +02001094 ret = poll(fds, num_socks, opt_timeout);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001095 if (ret <= 0)
1096 continue;
1097
Magnus Karlsson248c7f92019-02-21 10:21:27 +01001098 if (!(fds[0].revents & POLLOUT))
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001099 continue;
1100 }
1101
Magnus Karlsson46738f72019-08-14 09:27:21 +02001102 for (i = 0; i < num_socks; i++)
Weqaar Janjuab69e56c2020-08-29 00:17:17 +08001103 tx_only(xsks[i], &frame_nb[i], batch_size);
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301104
1105 pkt_cnt += batch_size;
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +05301106
1107 if (benchmark_done)
1108 break;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001109 }
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301110
1111 if (opt_pkt_count)
1112 complete_tx_only_all();
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001113}
1114
Magnus Karlsson46738f72019-08-14 09:27:21 +02001115static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001116{
Magnus Karlsson46738f72019-08-14 09:27:21 +02001117 unsigned int rcvd, i;
1118 u32 idx_rx = 0, idx_tx = 0;
1119 int ret;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001120
Magnus Karlsson46738f72019-08-14 09:27:21 +02001121 complete_tx_l2fwd(xsk, fds);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001122
Jay Jayatheerthancd9e72b62019-12-20 14:25:27 +05301123 rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx);
Magnus Karlsson46738f72019-08-14 09:27:21 +02001124 if (!rcvd) {
1125 if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq))
1126 ret = poll(fds, num_socks, opt_timeout);
1127 return;
1128 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001129
Magnus Karlsson46738f72019-08-14 09:27:21 +02001130 ret = xsk_ring_prod__reserve(&xsk->tx, rcvd, &idx_tx);
1131 while (ret != rcvd) {
1132 if (ret < 0)
1133 exit_with_error(-ret);
Magnus Karlsson5a2a0dd2020-09-10 10:31:05 +02001134 complete_tx_l2fwd(xsk, fds);
Magnus Karlsson46738f72019-08-14 09:27:21 +02001135 if (xsk_ring_prod__needs_wakeup(&xsk->tx))
1136 kick_tx(xsk);
Magnus Karlsson248c7f92019-02-21 10:21:27 +01001137 ret = xsk_ring_prod__reserve(&xsk->tx, rcvd, &idx_tx);
Magnus Karlsson46738f72019-08-14 09:27:21 +02001138 }
1139
1140 for (i = 0; i < rcvd; i++) {
1141 u64 addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr;
1142 u32 len = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++)->len;
Ciara Loftus5a712e12019-09-13 10:39:48 +00001143 u64 orig = addr;
Kevin Laatz03895e62019-08-27 02:25:29 +00001144
1145 addr = xsk_umem__add_offset_to_addr(addr);
Magnus Karlsson46738f72019-08-14 09:27:21 +02001146 char *pkt = xsk_umem__get_data(xsk->umem->buffer, addr);
1147
1148 swap_mac_addresses(pkt);
1149
1150 hex_dump(pkt, len, addr);
Kevin Laatz03895e62019-08-27 02:25:29 +00001151 xsk_ring_prod__tx_desc(&xsk->tx, idx_tx)->addr = orig;
Magnus Karlsson46738f72019-08-14 09:27:21 +02001152 xsk_ring_prod__tx_desc(&xsk->tx, idx_tx++)->len = len;
1153 }
1154
1155 xsk_ring_prod__submit(&xsk->tx, rcvd);
1156 xsk_ring_cons__release(&xsk->rx, rcvd);
1157
1158 xsk->rx_npkts += rcvd;
1159 xsk->outstanding_tx += rcvd;
1160}
1161
1162static void l2fwd_all(void)
1163{
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001164 struct pollfd fds[MAX_SOCKS] = {};
Magnus Karlsson46738f72019-08-14 09:27:21 +02001165 int i, ret;
1166
Magnus Karlsson46738f72019-08-14 09:27:21 +02001167 for (i = 0; i < num_socks; i++) {
1168 fds[i].fd = xsk_socket__fd(xsks[i]->xsk);
1169 fds[i].events = POLLOUT | POLLIN;
1170 }
1171
1172 for (;;) {
1173 if (opt_poll) {
1174 ret = poll(fds, num_socks, opt_timeout);
1175 if (ret <= 0)
1176 continue;
Magnus Karlsson248c7f92019-02-21 10:21:27 +01001177 }
1178
Magnus Karlsson46738f72019-08-14 09:27:21 +02001179 for (i = 0; i < num_socks; i++)
1180 l2fwd(xsks[i], fds);
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +05301181
1182 if (benchmark_done)
1183 break;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001184 }
1185}
1186
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001187static void load_xdp_program(char **argv, struct bpf_object **obj)
1188{
1189 struct bpf_prog_load_attr prog_load_attr = {
1190 .prog_type = BPF_PROG_TYPE_XDP,
1191 };
1192 char xdp_filename[256];
1193 int prog_fd;
1194
1195 snprintf(xdp_filename, sizeof(xdp_filename), "%s_kern.o", argv[0]);
1196 prog_load_attr.file = xdp_filename;
1197
1198 if (bpf_prog_load_xattr(&prog_load_attr, obj, &prog_fd))
1199 exit(EXIT_FAILURE);
1200 if (prog_fd < 0) {
1201 fprintf(stderr, "ERROR: no program found: %s\n",
1202 strerror(prog_fd));
1203 exit(EXIT_FAILURE);
1204 }
1205
1206 if (bpf_set_link_xdp_fd(opt_ifindex, prog_fd, opt_xdp_flags) < 0) {
1207 fprintf(stderr, "ERROR: link set xdp fd failed\n");
1208 exit(EXIT_FAILURE);
1209 }
1210}
1211
1212static void enter_xsks_into_map(struct bpf_object *obj)
1213{
1214 struct bpf_map *map;
1215 int i, xsks_map;
1216
1217 map = bpf_object__find_map_by_name(obj, "xsks_map");
1218 xsks_map = bpf_map__fd(map);
1219 if (xsks_map < 0) {
1220 fprintf(stderr, "ERROR: no xsks map found: %s\n",
1221 strerror(xsks_map));
1222 exit(EXIT_FAILURE);
1223 }
1224
1225 for (i = 0; i < num_socks; i++) {
1226 int fd = xsk_socket__fd(xsks[i]->xsk);
1227 int key, ret;
1228
1229 key = i;
1230 ret = bpf_map_update_elem(xsks_map, &key, &fd, 0);
1231 if (ret) {
1232 fprintf(stderr, "ERROR: bpf_map_update_elem %d\n", i);
1233 exit(EXIT_FAILURE);
1234 }
1235 }
1236}
1237
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001238int main(int argc, char **argv)
1239{
1240 struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
Magnus Karlsson661842c2019-11-07 18:47:39 +01001241 bool rx = false, tx = false;
Magnus Karlsson248c7f92019-02-21 10:21:27 +01001242 struct xsk_umem_info *umem;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001243 struct bpf_object *obj;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001244 pthread_t pt;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001245 int i, ret;
Magnus Karlsson248c7f92019-02-21 10:21:27 +01001246 void *bufs;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001247
1248 parse_command_line(argc, argv);
1249
1250 if (setrlimit(RLIMIT_MEMLOCK, &r)) {
1251 fprintf(stderr, "ERROR: setrlimit(RLIMIT_MEMLOCK) \"%s\"\n",
1252 strerror(errno));
1253 exit(EXIT_FAILURE);
1254 }
1255
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001256 if (opt_num_xsks > 1)
1257 load_xdp_program(argv, &obj);
1258
Kevin Laatz3945b372019-08-27 02:25:30 +00001259 /* Reserve memory for the umem. Use hugepages if unaligned chunk mode */
1260 bufs = mmap(NULL, NUM_FRAMES * opt_xsk_frame_size,
1261 PROT_READ | PROT_WRITE,
1262 MAP_PRIVATE | MAP_ANONYMOUS | opt_mmap_flags, -1, 0);
1263 if (bufs == MAP_FAILED) {
1264 printf("ERROR: mmap failed\n");
1265 exit(EXIT_FAILURE);
1266 }
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001267
1268 /* Create sockets... */
Maxim Mikityanskiy123e8da12019-06-26 17:35:27 +03001269 umem = xsk_configure_umem(bufs, NUM_FRAMES * opt_xsk_frame_size);
Magnus Karlsson661842c2019-11-07 18:47:39 +01001270 if (opt_bench == BENCH_RXDROP || opt_bench == BENCH_L2FWD) {
1271 rx = true;
1272 xsk_populate_fill_ring(umem);
1273 }
1274 if (opt_bench == BENCH_L2FWD || opt_bench == BENCH_TXONLY)
1275 tx = true;
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001276 for (i = 0; i < opt_num_xsks; i++)
Magnus Karlsson661842c2019-11-07 18:47:39 +01001277 xsks[num_socks++] = xsk_configure_socket(umem, rx, tx);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001278
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +05301279 if (opt_bench == BENCH_TXONLY) {
1280 gen_eth_hdr_data();
1281
Magnus Karlsson661842c2019-11-07 18:47:39 +01001282 for (i = 0; i < NUM_FRAMES; i++)
1283 gen_eth_frame(umem, i * opt_xsk_frame_size);
Jay Jayatheerthan4a3c23a2019-12-20 14:25:29 +05301284 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001285
Magnus Karlsson2e5d72c2019-11-07 18:47:37 +01001286 if (opt_num_xsks > 1 && opt_bench != BENCH_TXONLY)
1287 enter_xsks_into_map(obj);
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001288
1289 signal(SIGINT, int_exit);
1290 signal(SIGTERM, int_exit);
1291 signal(SIGABRT, int_exit);
1292
1293 setlocale(LC_ALL, "");
1294
Magnus Karlsson74e00672020-09-10 10:31:06 +02001295 if (!opt_quiet) {
1296 ret = pthread_create(&pt, NULL, poller, NULL);
1297 if (ret)
1298 exit_with_error(ret);
1299 }
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001300
1301 prev_time = get_nsecs();
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +05301302 start_time = prev_time;
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001303
1304 if (opt_bench == BENCH_RXDROP)
1305 rx_drop_all();
1306 else if (opt_bench == BENCH_TXONLY)
Magnus Karlsson46738f72019-08-14 09:27:21 +02001307 tx_only_all();
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001308 else
Magnus Karlsson46738f72019-08-14 09:27:21 +02001309 l2fwd_all();
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001310
Jay Jayatheerthanece6e962019-12-20 14:25:28 +05301311 benchmark_done = true;
1312
Magnus Karlsson74e00672020-09-10 10:31:06 +02001313 if (!opt_quiet)
1314 pthread_join(pt, NULL);
Jay Jayatheerthand3f11b02019-12-20 14:25:25 +05301315
Jay Jayatheerthan69525582019-12-20 14:25:26 +05301316 xdpsock_cleanup();
1317
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +02001318 return 0;
1319}