History

xsk: remove explicit ring structure from uapi

In this commit we remove the explicit ring structure from the the uapi. It is tricky for an uapi to depend on a certain L1 cache line size, since it can differ for variants of the same architecture. Now, we let the user application determine the offsets of the producer, consumer and descriptors by asking the socket via getsockopt. A typical flow would be (Rx ring): struct xdp_mmap_offsets off; struct xdp_desc *ring; u32 *prod, *cons; void *map; ... getsockopt(fd, SOL_XDP, XDP_MMAP_OFFSETS, &off, &optlen); map = mmap(NULL, off.rx.desc + NUM_DESCS * sizeof(struct xdp_desc), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, sfd, XDP_PGOFF_RX_RING); prod = map + off.rx.producer; cons = map + off.rx.consumer; ring = map + off.rx.desc;

Björn Töpel committed 8 years ago

Commit b3a9e0b1 parent 2e59dd53 files · +68 −22Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/if_xdp.h+22−22
@@ -23,13 +23,27 @@ struct sockaddr_xdp { · 22 unmodified lines
23 __u32 sxdp_shared_umem_fd;23 __u32 sxdp_shared_umem_fd;
24};24};
25 25
26struct xdp_ring_offset {
27 __u64 producer;
28 __u64 consumer;
29 __u64 desc;
30};
31
32struct xdp_mmap_offsets {
33 struct xdp_ring_offset rx;
34 struct xdp_ring_offset tx;
35 struct xdp_ring_offset fr; /* Fill */
36 struct xdp_ring_offset cr; /* Completion */
37};
38
26/* XDP socket options */39/* XDP socket options */
27#define XDP_RX_RING 140#define XDP_MMAP_OFFSETS 1
28#define XDP_TX_RING 241#define XDP_RX_RING 2
29#define XDP_UMEM_REG 342#define XDP_TX_RING 3
30#define XDP_UMEM_FILL_RING 443#define XDP_UMEM_REG 4
31#define XDP_UMEM_COMPLETION_RING 544#define XDP_UMEM_FILL_RING 5
32#define XDP_STATISTICS 645#define XDP_UMEM_COMPLETION_RING 6
46#define XDP_STATISTICS 7
33 47
34struct xdp_umem_reg {48struct xdp_umem_reg {
35 __u64 addr; /* Start of packet data area */49 __u64 addr; /* Start of packet data area */
@@ -50,6 +64,7 @@ struct xdp_statistics { · 14 unmodified lines
50#define XDP_UMEM_PGOFF_FILL_RING 0x10000000064#define XDP_UMEM_PGOFF_FILL_RING 0x100000000
51#define XDP_UMEM_PGOFF_COMPLETION_RING 0x18000000065#define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000
52 66
67/* Rx/Tx descriptor */
53struct xdp_desc {68struct xdp_desc {
54 __u32 idx;69 __u32 idx;
55 __u32 len;70 __u32 len;
@@ -58,21 +73,6 @@ struct xdp_desc { · 2 unmodified lines
58 __u8 padding[5];73 __u8 padding[5];
59};74};
60 75
61struct xdp_ring {76/* UMEM descriptor is __u32 */
62 __u32 producer __attribute__((aligned(64)));
63 __u32 consumer __attribute__((aligned(64)));
64};
65
66/* Used for the RX and TX queues for packets */
67struct xdp_rxtx_ring {
68 struct xdp_ring ptrs;
69 struct xdp_desc desc[0] __attribute__((aligned(64)));
70};
71
72/* Used for the fill and completion queues for buffers */
73struct xdp_umem_ring {
74 struct xdp_ring ptrs;
75 __u32 desc[0] __attribute__((aligned(64)));
76};
77 77
78#endif /* _LINUX_IF_XDP_H */78#endif /* _LINUX_IF_XDP_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t