2019-01-24 18:59:39 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* Copyright(c) 2019 Intel Corporation. */
|
|
|
|
|
|
|
|
#ifndef XSK_H_
|
|
|
|
#define XSK_H_
|
|
|
|
|
2020-05-20 19:20:52 +00: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)
|
|
|
|
|
|
|
|
/* Flags for the umem flags field.
|
|
|
|
*
|
|
|
|
* The NEED_WAKEUP flag is 1 due to the reuse of the flags field for public
|
|
|
|
* flags. See inlude/uapi/include/linux/if_xdp.h.
|
|
|
|
*/
|
|
|
|
#define XDP_UMEM_USES_NEED_WAKEUP BIT(1)
|
|
|
|
|
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 07:27:17 +00: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-20 19:20:50 +00: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-24 18:59:39 +00:00
|
|
|
static inline struct xdp_sock *xdp_sk(struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct xdp_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2020-05-20 19:20:50 +00:00
|
|
|
bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
|
|
|
|
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);
|
|
|
|
|
2019-01-24 18:59:39 +00:00
|
|
|
#endif /* XSK_H_ */
|