Skip to content

Commit a450043

Browse files
magnus-karlssonborkmann
authored andcommitted
libbpf: add support for need_wakeup flag in AF_XDP part
This commit adds support for the new need_wakeup flag in AF_XDP. The xsk_socket__create function is updated to handle this and a new function is introduced called xsk_ring_prod__needs_wakeup(). This function can be used by the application to check if Rx and/or Tx processing needs to be explicitly woken up. Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 5c12924 commit a450043

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎tools/include/uapi/linux/if_xdp.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
#define XDP_SHARED_UMEM (1 << 0)
1717
#define XDP_COPY (1 << 1) /* Force copy-mode */
1818
#define XDP_ZEROCOPY (1 << 2) /* Force zero-copy mode */
19+
/* If this option is set, the driver might go sleep and in that case
20+
* the XDP_RING_NEED_WAKEUP flag in the fill and/or Tx rings will be
21+
* set. If it is set, the application need to explicitly wake up the
22+
* driver with a poll() (Rx and Tx) or sendto() (Tx only). If you are
23+
* running the driver and the application on the same core, you should
24+
* use this option so that the kernel will yield to the user space
25+
* application.
26+
*/
27+
#define XDP_USE_NEED_WAKEUP (1 << 3)
1928

2029
struct sockaddr_xdp {
2130
__u16 sxdp_family;
@@ -25,10 +34,14 @@ struct sockaddr_xdp {
2534
__u32 sxdp_shared_umem_fd;
2635
};
2736

37+
/* XDP_RING flags */
38+
#define XDP_RING_NEED_WAKEUP (1 << 0)
39+
2840
struct xdp_ring_offset {
2941
__u64 producer;
3042
__u64 consumer;
3143
__u64 desc;
44+
__u64 flags;
3245
};
3346

3447
struct xdp_mmap_offsets {

‎tools/lib/bpf/xsk.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area, __u64 size,
224224
fill->size = umem->config.fill_size;
225225
fill->producer = map + off.fr.producer;
226226
fill->consumer = map + off.fr.consumer;
227+
fill->flags = map + off.fr.flags;
227228
fill->ring = map + off.fr.desc;
228229
fill->cached_cons = umem->config.fill_size;
229230

@@ -241,6 +242,7 @@ int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area, __u64 size,
241242
comp->size = umem->config.comp_size;
242243
comp->producer = map + off.cr.producer;
243244
comp->consumer = map + off.cr.consumer;
245+
comp->flags = map + off.cr.flags;
244246
comp->ring = map + off.cr.desc;
245247

246248
*umem_ptr = umem;
@@ -564,6 +566,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
564566
rx->size = xsk->config.rx_size;
565567
rx->producer = rx_map + off.rx.producer;
566568
rx->consumer = rx_map + off.rx.consumer;
569+
rx->flags = rx_map + off.rx.flags;
567570
rx->ring = rx_map + off.rx.desc;
568571
}
569572
xsk->rx = rx;
@@ -583,6 +586,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
583586
tx->size = xsk->config.tx_size;
584587
tx->producer = tx_map + off.tx.producer;
585588
tx->consumer = tx_map + off.tx.consumer;
589+
tx->flags = tx_map + off.tx.flags;
586590
tx->ring = tx_map + off.tx.desc;
587591
tx->cached_cons = xsk->config.tx_size;
588592
}

‎tools/lib/bpf/xsk.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct name { \
3232
__u32 *producer; \
3333
__u32 *consumer; \
3434
void *ring; \
35+
__u32 *flags; \
3536
}
3637

3738
DEFINE_XSK_RING(xsk_ring_prod);
@@ -76,6 +77,11 @@ xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx)
7677
return &descs[idx & rx->mask];
7778
}
7879

80+
static inline int xsk_ring_prod__needs_wakeup(const struct xsk_ring_prod *r)
81+
{
82+
return *r->flags & XDP_RING_NEED_WAKEUP;
83+
}
84+
7985
static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb)
8086
{
8187
__u32 free_entries = r->cached_cons - r->cached_prod;

0 commit comments

Comments
 (0)