Here, the xdpsock sample application is adjusted to the new descriptor format.
Showing the changes to samples (1 of 1 file). Show all
Unified · Split
| @@ -46,6 +46,7 @@ · 45 unmodified lines | ||
| 46 | 46 | |
| 47 | 47 | #define NUM_FRAMES 131072 |
| 48 | 48 | #define FRAME_HEADROOM 0 |
| 49 | +#define FRAME_SHIFT 11 | |
| 49 | 50 | #define FRAME_SIZE 2048 |
| 50 | 51 | #define NUM_DESCS 1024 |
| 51 | 52 | #define BATCH_SIZE 16 |
| @@ -55,6 +56,7 @@ · 3 unmodified lines | ||
| 55 | 56 | |
| 56 | 57 | #define DEBUG_HEXDUMP 0 |
| 57 | 58 | |
| 59 | +typedef __u64 u64; | |
| 58 | 60 | typedef __u32 u32; |
| 59 | 61 | |
| 60 | 62 | static unsigned long prev_time; |
| @@ -81,12 +83,12 @@ struct xdp_umem_uqueue { · 20 unmodified lines | ||
| 81 | 83 | u32 size; |
| 82 | 84 | u32 *producer; |
| 83 | 85 | u32 *consumer; |
| 84 | − u32 *ring; | |
| 86 | + u64 *ring; | |
| 85 | 87 | void *map; |
| 86 | 88 | }; |
| 87 | 89 | |
| 88 | 90 | struct xdp_umem { |
| 89 | − char (*frames)[FRAME_SIZE]; | |
| 91 | + char *frames; | |
| 90 | 92 | struct xdp_umem_uqueue fq; |
| 91 | 93 | struct xdp_umem_uqueue cq; |
| 92 | 94 | int fd; |
| @@ -214,7 +216,7 @@ static inline int umem_fill_to_kernel_ex(struct xdp_umem_uqueue *fq, · 121 unmodified lines | ||
| 214 | 216 | for (i = 0; i < nb; i++) { |
| 215 | 217 | u32 idx = fq->cached_prod++ & fq->mask; |
| 216 | 218 | |
| 217 | − fq->ring[idx] = d[i].idx; | |
| 219 | + fq->ring[idx] = d[i].addr; | |
| 218 | 220 | } |
| 219 | 221 | |
| 220 | 222 | u_smp_wmb(); |
| @@ -224,7 +226,7 @@ static inline int umem_fill_to_kernel_ex(struct xdp_umem_uqueue *fq, · 3 unmodified lines | ||
| 224 | 226 | return 0; |
| 225 | 227 | } |
| 226 | 228 | |
| 227 | −static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u32 *d, | |
| 229 | +static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u64 *d, | |
| 228 | 230 | size_t nb) |
| 229 | 231 | { |
| 230 | 232 | u32 i; |
| @@ -246,7 +248,7 @@ static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u32 *d, · 15 unmodified lines | ||
| 246 | 248 | } |
| 247 | 249 | |
| 248 | 250 | static inline size_t umem_complete_from_kernel(struct xdp_umem_uqueue *cq, |
| 249 | − u32 *d, size_t nb) | |
| 251 | + u64 *d, size_t nb) | |
| 250 | 252 | { |
| 251 | 253 | u32 idx, i, entries = umem_nb_avail(cq, nb); |
| 252 | 254 | |
| @@ -266,10 +268,9 @@ static inline size_t umem_complete_from_kernel(struct xdp_umem_uqueue *cq, · 13 unmodified lines | ||
| 266 | 268 | return entries; |
| 267 | 269 | } |
| 268 | 270 | |
| 269 | −static inline void *xq_get_data(struct xdpsock *xsk, __u32 idx, __u32 off) | |
| 271 | +static inline void *xq_get_data(struct xdpsock *xsk, u64 addr) | |
| 270 | 272 | { |
| 271 | − lassert(idx < NUM_FRAMES); | |
| 272 | − return &xsk->umem->frames[idx][off]; | |
| 273 | + return &xsk->umem->frames[addr]; | |
| 273 | 274 | } |
| 274 | 275 | |
| 275 | 276 | static inline int xq_enq(struct xdp_uqueue *uq, |
| @@ -285,9 +286,8 @@ static inline int xq_enq(struct xdp_uqueue *uq, · 9 unmodified lines | ||
| 285 | 286 | for (i = 0; i < ndescs; i++) { |
| 286 | 287 | u32 idx = uq->cached_prod++ & uq->mask; |
| 287 | 288 | |
| 288 | − r[idx].idx = descs[i].idx; | |
| 289 | + r[idx].addr = descs[i].addr; | |
| 289 | 290 | r[idx].len = descs[i].len; |
| 290 | − r[idx].offset = descs[i].offset; | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | u_smp_wmb(); |
| @@ -297,7 +297,7 @@ static inline int xq_enq(struct xdp_uqueue *uq, · 3 unmodified lines | ||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | static inline int xq_enq_tx_only(struct xdp_uqueue *uq, |
| 300 | − __u32 idx, unsigned int ndescs) | |
| 300 | + unsigned int id, unsigned int ndescs) | |
| 301 | 301 | { |
| 302 | 302 | struct xdp_desc *r = uq->ring; |
| 303 | 303 | unsigned int i; |
| @@ -308,9 +308,8 @@ static inline int xq_enq_tx_only(struct xdp_uqueue *uq, · 4 unmodified lines | ||
| 308 | 308 | for (i = 0; i < ndescs; i++) { |
| 309 | 309 | u32 idx = uq->cached_prod++ & uq->mask; |
| 310 | 310 | |
| 311 | − r[idx].idx = idx + i; | |
| 311 | + r[idx].addr = (id + i) << FRAME_SHIFT; | |
| 312 | 312 | r[idx].len = sizeof(pkt_data) - 1; |
| 313 | − r[idx].offset = 0; | |
| 314 | 313 | } |
| 315 | 314 | |
| 316 | 315 | u_smp_wmb(); |
| @@ -357,17 +356,21 @@ static void swap_mac_addresses(void *data) · 40 unmodified lines | ||
| 357 | 356 | *dst_addr = tmp; |
| 358 | 357 | } |
| 359 | 358 | |
| 360 | −#if DEBUG_HEXDUMP | |
| 361 | −static void hex_dump(void *pkt, size_t length, const char *prefix) | |
| 359 | +static void hex_dump(void *pkt, size_t length, u64 addr) | |
| 362 | 360 | { |
| 363 | − int i = 0; | |
| 364 | 361 | const unsigned char *address = (unsigned char *)pkt; |
| 365 | 362 | const unsigned char *line = address; |
| 366 | 363 | size_t line_size = 32; |
| 367 | 364 | unsigned char c; |
| 365 | + char buf[32]; | |
| 366 | + int i = 0; | |
| 368 | 367 | |
| 368 | + if (!DEBUG_HEXDUMP) | |
| 369 | + return; | |
| 370 | + | |
| 371 | + sprintf(buf, "addr=%llu", addr); | |
| 369 | 372 | printf("length = %zu\n", length); |
| 370 | − printf("%s | ", prefix); | |
| 373 | + printf("%s | ", buf); | |
| 371 | 374 | while (length-- > 0) { |
| 372 | 375 | printf("%02X ", *address++); |
| 373 | 376 | if (!(++i % line_size) || (length == 0 && i % line_size)) { |
| @@ -382,12 +385,11 @@ static void hex_dump(void *pkt, size_t length, const char *prefix) · 8 unmodified lines | ||
| 382 | 385 | } |
| 383 | 386 | printf("\n"); |
| 384 | 387 | if (length > 0) |
| 385 | − printf("%s | ", prefix); | |
| 388 | + printf("%s | ", buf); | |
| 386 | 389 | } |
| 387 | 390 | } |
| 388 | 391 | printf("\n"); |
| 389 | 392 | } |
| 390 | −#endif | |
| 391 | 393 | |
| 392 | 394 | static size_t gen_eth_frame(char *frame) |
| 393 | 395 | { |
| @@ -412,8 +414,8 @@ static struct xdp_umem *xdp_umem_configure(int sfd) · 18 unmodified lines | ||
| 412 | 414 | |
| 413 | 415 | mr.addr = (__u64)bufs; |
| 414 | 416 | mr.len = NUM_FRAMES * FRAME_SIZE; |
| 415 | − mr.frame_size = FRAME_SIZE; | |
| 416 | − mr.frame_headroom = FRAME_HEADROOM; | |
| 417 | + mr.chunk_size = FRAME_SIZE; | |
| 418 | + mr.headroom = FRAME_HEADROOM; | |
| 417 | 419 | |
| 418 | 420 | lassert(setsockopt(sfd, SOL_XDP, XDP_UMEM_REG, &mr, sizeof(mr)) == 0); |
| 419 | 421 | lassert(setsockopt(sfd, SOL_XDP, XDP_UMEM_FILL_RING, &fq_size, |
| @@ -426,7 +428,7 @@ static struct xdp_umem *xdp_umem_configure(int sfd) · 6 unmodified lines | ||
| 426 | 428 | &optlen) == 0); |
| 427 | 429 | |
| 428 | 430 | umem->fq.map = mmap(0, off.fr.desc + |
| 429 | − FQ_NUM_DESCS * sizeof(u32), | |
| 431 | + FQ_NUM_DESCS * sizeof(u64), | |
| 430 | 432 | PROT_READ | PROT_WRITE, |
| 431 | 433 | MAP_SHARED | MAP_POPULATE, sfd, |
| 432 | 434 | XDP_UMEM_PGOFF_FILL_RING); |
| @@ -439,7 +441,7 @@ static struct xdp_umem *xdp_umem_configure(int sfd) · 6 unmodified lines | ||
| 439 | 441 | umem->fq.ring = umem->fq.map + off.fr.desc; |
| 440 | 442 | |
| 441 | 443 | umem->cq.map = mmap(0, off.cr.desc + |
| 442 | − CQ_NUM_DESCS * sizeof(u32), | |
| 444 | + CQ_NUM_DESCS * sizeof(u64), | |
| 443 | 445 | PROT_READ | PROT_WRITE, |
| 444 | 446 | MAP_SHARED | MAP_POPULATE, sfd, |
| 445 | 447 | XDP_UMEM_PGOFF_COMPLETION_RING); |
| @@ -451,14 +453,14 @@ static struct xdp_umem *xdp_umem_configure(int sfd) · 5 unmodified lines | ||
| 451 | 453 | umem->cq.consumer = umem->cq.map + off.cr.consumer; |
| 452 | 454 | umem->cq.ring = umem->cq.map + off.cr.desc; |
| 453 | 455 | |
| 454 | − umem->frames = (char (*)[FRAME_SIZE])bufs; | |
| 456 | + umem->frames = bufs; | |
| 455 | 457 | umem->fd = sfd; |
| 456 | 458 | |
| 457 | 459 | if (opt_bench == BENCH_TXONLY) { |
| 458 | 460 | int i; |
| 459 | 461 | |
| 460 | − for (i = 0; i < NUM_FRAMES; i++) | |
| 461 | − (void)gen_eth_frame(&umem->frames[i][0]); | |
| 462 | + for (i = 0; i < NUM_FRAMES * FRAME_SIZE; i += FRAME_SIZE) | |
| 463 | + (void)gen_eth_frame(&umem->frames[i]); | |
| 462 | 464 | } |
| 463 | 465 | |
| 464 | 466 | return umem; |
| @@ -472,7 +474,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem) · 7 unmodified lines | ||
| 472 | 474 | struct xdpsock *xsk; |
| 473 | 475 | bool shared = true; |
| 474 | 476 | socklen_t optlen; |
| 475 | − u32 i; | |
| 477 | + u64 i; | |
| 476 | 478 | |
| 477 | 479 | sfd = socket(PF_XDP, SOCK_RAW, 0); |
| 478 | 480 | lassert(sfd >= 0); |
| @@ -508,7 +510,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem) · 29 unmodified lines | ||
| 508 | 510 | lassert(xsk->rx.map != MAP_FAILED); |
| 509 | 511 | |
| 510 | 512 | if (!shared) { |
| 511 | − for (i = 0; i < NUM_DESCS / 2; i++) | |
| 513 | + for (i = 0; i < NUM_DESCS * FRAME_SIZE; i += FRAME_SIZE) | |
| 512 | 514 | lassert(umem_fill_to_kernel(&xsk->umem->fq, &i, 1) |
| 513 | 515 | == 0); |
| 514 | 516 | } |
| @@ -727,7 +729,7 @@ static void kick_tx(int fd) · 212 unmodified lines | ||
| 727 | 729 | |
| 728 | 730 | static inline void complete_tx_l2fwd(struct xdpsock *xsk) |
| 729 | 731 | { |
| 730 | − u32 descs[BATCH_SIZE]; | |
| 732 | + u64 descs[BATCH_SIZE]; | |
| 731 | 733 | unsigned int rcvd; |
| 732 | 734 | size_t ndescs; |
| 733 | 735 | |
| @@ -749,7 +751,7 @@ static inline void complete_tx_l2fwd(struct xdpsock *xsk) · 15 unmodified lines | ||
| 749 | 751 | |
| 750 | 752 | static inline void complete_tx_only(struct xdpsock *xsk) |
| 751 | 753 | { |
| 752 | − u32 descs[BATCH_SIZE]; | |
| 754 | + u64 descs[BATCH_SIZE]; | |
| 753 | 755 | unsigned int rcvd; |
| 754 | 756 | |
| 755 | 757 | if (!xsk->outstanding_tx) |
| @@ -774,17 +776,9 @@ static void rx_drop(struct xdpsock *xsk) · 18 unmodified lines | ||
| 774 | 776 | return; |
| 775 | 777 | |
| 776 | 778 | for (i = 0; i < rcvd; i++) { |
| 777 | − u32 idx = descs[i].idx; | |
| 778 | − | |
| 779 | − lassert(idx < NUM_FRAMES); | |
| 780 | −#if DEBUG_HEXDUMP | |
| 781 | − char *pkt; | |
| 782 | − char buf[32]; | |
| 779 | + char *pkt = xq_get_data(xsk, descs[i].addr); | |
| 783 | 780 | |
| 784 | − pkt = xq_get_data(xsk, idx, descs[i].offset); | |
| 785 | − sprintf(buf, "idx=%d", idx); | |
| 786 | − hex_dump(pkt, descs[i].len, buf); | |
| 787 | −#endif | |
| 781 | + hex_dump(pkt, descs[i].len, descs[i].addr); | |
| 788 | 782 | } |
| 789 | 783 | |
| 790 | 784 | xsk->rx_npkts += rcvd; |
| @@ -867,17 +861,11 @@ static void l2fwd(struct xdpsock *xsk) · 76 unmodified lines | ||
| 867 | 861 | } |
| 868 | 862 | |
| 869 | 863 | for (i = 0; i < rcvd; i++) { |
| 870 | − char *pkt = xq_get_data(xsk, descs[i].idx, | |
| 871 | − descs[i].offset); | |
| 864 | + char *pkt = xq_get_data(xsk, descs[i].addr); | |
| 872 | 865 | |
| 873 | 866 | swap_mac_addresses(pkt); |
| 874 | −#if DEBUG_HEXDUMP | |
| 875 | − char buf[32]; | |
| 876 | − u32 idx = descs[i].idx; | |
| 877 | 867 | |
| 878 | − sprintf(buf, "idx=%d", idx); | |
| 879 | − hex_dump(pkt, descs[i].len, buf); | |
| 880 | −#endif | |
| 868 | + hex_dump(pkt, descs[i].len, descs[i].addr); | |
| 881 | 869 | } |
| 882 | 870 | |
| 883 | 871 | xsk->rx_npkts += rcvd; |