2019-01-25 02:59:39 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* Copyright(c) 2019 Intel Corporation. */
|
|
|
|
|
|
|
|
#ifndef XSK_H_
|
|
|
|
#define XSK_H_
|
|
|
|
|
2020-05-21 03:20:52 +08:00
|
|
|
/* Masks for xdp_umem_page flags.
|
|
|
|
* The low 12-bits of the addr will be 0 since this is the page address, so we
|
|
|
|
* can use them for flags.
|
|
|
|
*/
|
|
|
|
#define XSK_NEXT_PG_CONTIG_SHIFT 0
|
|
|
|
#define XSK_NEXT_PG_CONTIG_MASK BIT_ULL(XSK_NEXT_PG_CONTIG_SHIFT)
|
|
|
|
|
xsk: add support for need_wakeup flag in AF_XDP rings
This commit adds support for a new flag called need_wakeup in the
AF_XDP Tx and fill rings. When this flag is set, it means that the
application has to explicitly wake up the kernel Rx (for the bit in
the fill ring) or kernel Tx (for bit in the Tx ring) processing by
issuing a syscall. Poll() can wake up both depending on the flags
submitted and sendto() will wake up tx processing only.
The main reason for introducing this new flag is to be able to
efficiently support the case when application and driver is executing
on the same core. Previously, the driver was just busy-spinning on the
fill ring if it ran out of buffers in the HW and there were none on
the fill ring. This approach works when the application is running on
another core as it can replenish the fill ring while the driver is
busy-spinning. Though, this is a lousy approach if both of them are
running on the same core as the probability of the fill ring getting
more entries when the driver is busy-spinning is zero. With this new
feature the driver now sets the need_wakeup flag and returns to the
application. The application can then replenish the fill queue and
then explicitly wake up the Rx processing in the kernel using the
syscall poll(). For Tx, the flag is only set to one if the driver has
no outstanding Tx completion interrupts. If it has some, the flag is
zero as it will be woken up by a completion interrupt anyway.
As a nice side effect, this new flag also improves the performance of
the case where application and driver are running on two different
cores as it reduces the number of syscalls to the kernel. The kernel
tells user space if it needs to be woken up by a syscall, and this
eliminates many of the syscalls.
This flag needs some simple driver support. If the driver does not
support this, the Rx flag is always zero and the Tx flag is always
one. This makes any application relying on this feature default to the
old behaviour of not requiring any syscalls in the Rx path and always
having to call sendto() in the Tx path.
For backwards compatibility reasons, this feature has to be explicitly
turned on using a new bind flag (XDP_USE_NEED_WAKEUP). I recommend
that you always turn it on as it so far always have had a positive
performance impact.
The name and inspiration of the flag has been taken from io_uring by
Jens Axboe. Details about this feature in io_uring can be found in
http://kernel.dk/io_uring.pdf, section 8.3.
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>
2019-08-14 15:27:17 +08:00
|
|
|
struct xdp_ring_offset_v1 {
|
|
|
|
__u64 producer;
|
|
|
|
__u64 consumer;
|
|
|
|
__u64 desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xdp_mmap_offsets_v1 {
|
|
|
|
struct xdp_ring_offset_v1 rx;
|
|
|
|
struct xdp_ring_offset_v1 tx;
|
|
|
|
struct xdp_ring_offset_v1 fr;
|
|
|
|
struct xdp_ring_offset_v1 cr;
|
|
|
|
};
|
|
|
|
|
2020-05-21 03:20:50 +08:00
|
|
|
/* Nodes are linked in the struct xdp_sock map_list field, and used to
|
|
|
|
* track which maps a certain socket reside in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct xsk_map_node {
|
|
|
|
struct list_head node;
|
|
|
|
struct xsk_map *map;
|
|
|
|
struct xdp_sock **map_entry;
|
|
|
|
};
|
|
|
|
|
2019-01-25 02:59:39 +08:00
|
|
|
static inline struct xdp_sock *xdp_sk(struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct xdp_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2020-05-21 03:20:50 +08:00
|
|
|
void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
|
|
|
|
struct xdp_sock **map_entry);
|
|
|
|
int xsk_map_inc(struct xsk_map *map);
|
|
|
|
void xsk_map_put(struct xsk_map *map);
|
2020-08-28 16:26:17 +08:00
|
|
|
void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id);
|
|
|
|
int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,
|
|
|
|
u16 queue_id);
|
2020-05-21 03:20:50 +08:00
|
|
|
|
2019-01-25 02:59:39 +08:00
|
|
|
#endif /* XSK_H_ */
|