Commit Graph

547 Commits

Author SHA1 Message Date
e9ec65d667 AF_XDP-interaction: README: Explaning XDP-hints via local BTF info
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 19:45:43 +01:00
ae4f6a5846 AF_XDP-interaction: Print XSK queue_id packet was RXed on
Now that program process all queues it is relevant to know
what queue_id received the packet.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 18:49:06 +01:00
732bd6ec41 AF_XDP-interaction: This example bind to all queues
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 18:07:09 +01:00
0f08e825bd AF_XDP-interaction: README update AF_XDP documentation section
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 17:44:27 +01:00
f5833725cc AF_XDP-interaction: Fix xsk_bind_flags options
This allows enabling another AF_XDP mode e.g. --zero-copy.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 17:12:29 +01:00
37f00015b6 AF_XDP-interaction: Cleanups
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 17:10:34 +01:00
a80aab5ae7 AF_XDP-interaction: Allocate more frame when we have more queues
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 16:29:38 +01:00
e558ab94e2 Make simple mem_frame_allocator more dynamic
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 16:07:35 +01:00
34dd6fc6c4 AF_XDP-interaction: Refactor a bit
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 15:53:56 +01:00
ca9ef962de AF_XDP-interaction: Update ethtool_utils
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 15:24:31 +01:00
9bca7ea4ff AF_XDP-interaction: Implement ethtool_get_max_queues
Need to get configured queues on the NIC device

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 13:03:38 +01:00
9c3a6a7a9d AF_XDP-interaction: Default to AF_XDP copy mode
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-16 12:10:04 +01:00
8806cf2264 AF_XDP-interaction: refactor FQ+CQ per xsk_socket_info
Cannot share/associate the FQ (Fill Queue) and CQ (Completion Q) with
umem container (xsk_umem_info).  This is the reason current program
cannot handle packets for each queue ID.

As described in [1] we need more FQ and CQ ring pairs, a pair per for each
unique netdev and queue IP tuple.

Thus, add FQ and CQ for each queue id in struct xsk_socket_info.

[1] https://www.kernel.org/doc/html/latest/networking/af_xdp.html

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-15 12:54:22 +01:00
529256b00c Mannally insert XSK FDs into xsks_map
Do like enter_xsks_into_map() in kernels xdpsock_user.c

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 22:19:45 +01:00
062b5d96fb AF_XDP-interaction: call handle_receive_packets on all XSKs
Strangely multiple RX-queues still doesn't work

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 22:03:13 +01:00
e0b044085c AF_XDP-interaction: Processing multiple XSKs doesn't work
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 20:52:23 +01:00
cf47f471aa AF_XDP-interaction: Handle queue id per xsk socket
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 19:15:25 +01:00
acf251c8bc AF_XDP-interaction: Introduce xsk_container for multiple XSK sockets
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 18:53:41 +01:00
7150416ccf AF_XDP-interaction: Split out memory allocator for umem frames
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 15:44:12 +01:00
d1d57c1dfc AF_XDP-interaction: Prepare for multiple XSK sockets
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 13:23:29 +01:00
de646516c3 AF_XDP-interaction: Shared header for defining MAX_AF_SOCKS
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 12:46:11 +01:00
396854e2e1 AF_XDP-interaction: Add --spin-mode that disables --wakeup-mode
And default that AF_XDP userspace prog to use wakeup-mode

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 11:47:48 +01:00
b950ab63f0 AF_XDP-interaction: rename --poll-mode to --wakeup-mode
It is confusing to name the option what will wait for packets
on the file descriptor, for --poll, just because the function
call have this name.  It confusing as AF_XDP users often want
to busy-poll for packets (for max performance reasons).

Name the new option --wakeup instead of --wait as the effect
of waiting for the FD is that the kernel needs to wakeup
the userspace process.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 10:59:37 +01:00
8db4d3b33c lib_xsk_extend: Avoid crashing in XSK_BTF_READ_xxx macros
The macros XSK_BTF_READ_xxx doesn't handle or report on errors
if the input or field were wrong, which is not uncommon for macros.

The bad behavior is that the macro continue to dereference the
pointer even-when xsk_btf__read_xxx() functions returns an error.
This often leads to crashing the application.

Change macro to only dereference when no errors were reported.

Side-note: The compiler warnings will detect if API user didn't
init the 'dest' value with a default value.  As the effect of
the change is that the 'dest' value will not be touch, and thus
contain the value before the macro was used.

Example:
  warning: ‘mark’ may be used uninitialized in this function

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 10:01:58 +01:00
1337b2dbaa AF_XDP-interaction: Reorg BTF access code
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-12 09:18:04 +01:00
e3c2ded159 AF_XDP-interaction: Move BTF code to separate setup vs. using
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-11 15:56:22 +01:00
8703e1a320 AF_XDP-interaction: Explain xsk_btf__read_field in user code
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-11 14:34:43 +01:00
a333281166 lib_xsk_extend: Explain xsk_btf__read_field hashmap caching
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 22:10:43 +01:00
f61c9be97f lib_xsk_extend: Rename xsk_btf__read_member to xsk_btf__read
Making it the main API.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 21:59:14 +01:00
9b36c233fe lib_xsk_extend: Let XSK_BTF_READ_INTO call xsk_btf__read_member
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 21:52:56 +01:00
465f069fab lib_xsk_extend: API change introduce xsk_btf__read_field
Rename xsk_btf__read to xsk_btf__read_field.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 20:56:32 +01:00
be949736ef AF_XDP-interaction: Also introduce BTF mirror for struct xdp_hints_mark
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 19:39:50 +01:00
219ea356a4 AF_XDP-interaction: btf_id zero indicate no BTF info
Zero init xdp_hints_rx_time, which means xdp_hints_rx_time.btf_type_id
is zero if setup_btf_info() didn't find the struct name.

In print_meta_info_via_btf() we also exit if btf_id is zero, as
this isn't a valid BTF type id.

Thus, we don't need to explicitly handle "error" case of a btf_type_id
being zero, it will just naturally not match when userspace could not
find the struct name.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 17:47:11 +01:00
1cb72f03df AF_XDP-interaction: introduce struct to mirror kernel-side struct
The 'struct xdp_hints_rx_time' exist both in kernel-side (af_xdp_kern.c)
and userspace program af_xdp_user.c, but are very different.

The kernel-side is the actual XDP-hints memory layout used in metadata area.

The userspace side uses the same struct name, but contains BTF info
that allow us to access the struct members from kernel-side struct.
The BTF info is extracted on userspace startup, from the BPF-prog
ELF data BTF section.

Caching BTF lookups at startup is done, as target application
is a real-time application.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-09 16:50:35 +01:00
54d67979a5 Merge pull request #27 from rst0git/readme
readme: fix typos
2021-11-06 15:38:27 +01:00
7f6f9d5a9d readme: fix typos
Signed-off-by: Radostin Stoyanov <radostin@redhat.com>
2021-11-06 12:33:09 +00:00
5e93cf0993 AF_XDP-interaction: Code cleanup, remove local BTF code
The local BTF code in af_xdp_user.c was only used for
debugging the BTF structures while developing and testing
the lib_xsk_extend.c code.

If is confusing for other reading the code, so simply
remove thisi, as the lib_xsk_extend.c should hide
these details fpr API users.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-05 15:59:33 +01:00
87654aecdd AF_XDP-interaction: code cleanup, remove manual C type-casting approach
This method have been obsoleted by the BTF approach.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-05 15:50:34 +01:00
d84ced9730 AF_XDP-interaction: Fix to work on newer kernels supporting bpf_link
Program fails on newer kernels, with error message:

 libbpf: Netlink-based XDP prog detected, please unload it in order to launch AF_XDP prog
 ERROR: Can't setup AF_XDP socket "Invalid argument"

Since kernel v5.13 libbpf version, when bpf_link support is
detected then libbpf/xsk require XDP/BPF programs use this feature.
See kernel commit 10397994d30f ("libbpf: xsk: Use bpf_link").

To continue using our netlink-based XDP attach approach,
instruct libbpf/xsk to not be in change of loading the
BPF-prog.  As our XDP-prog is special it also makes
to control this ourselves.

This is achived with the flag XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD

 xsk_cfg.libbpf_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD

Remember to update the xskmap manually.

Fixes: 10397994d30f ("libbpf: xsk: Use bpf_link")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-05 14:54:50 +01:00
1807d1024b AF_XDP-interaction: Add README.org
I keep forgetting the API docs, so lets add links in the README.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-05 13:40:20 +01:00
b028f24513 lib_xsk_extend: Add comment describing XDP metadata and BTF
Add a large comments to the most central piece of code that
access the right offset into the metadata based on the BTF
info we have extracted.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-05 10:13:42 +01:00
f46743a75f AF_XDP-interaction: Enable AF_XDP code that reply to ICMPV6_ECHO_REQUEST
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 15:54:21 +01:00
173cc762fd AF_XDP-interaction: Let netstack handle ARP and IPv6 NDP
NDP (Neighbor Discovery Protocol)

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 15:25:49 +01:00
556d6fd47b AF_XDP-interaction: Move refill of fill-queue to after RX processing
The root cause of the slowdown on the first packet with timestamps,
as primary related to refilling the fill-queue, which happend before
process_packet.

Primary cause, as first packet still see a slowdown of around 4 usec
while it was around 9 usec before.

In commit 5df5332f23 ("AF_XDP-interaction: config AF_XDP frame_headroom")
the fill-queue size was increase to be larger.  This caused the
first call to handle_receive_packets() to refill too many frames
into the fill-queue.

Patch split out refill into function restock_receive_fill_queue()
which is now called *after* process_packet step, but before
releasing RX packets via xsk_ring_cons__release(&xsk->rx).

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 13:49:20 +01:00
6016a13008 AF_XDP-interaction: Usage of xsk_btf__read_member API
This API xsk_btf__read_member() is faster, but it was not the
root cause of the slowdown on the first packet with timestamps.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 12:15:16 +01:00
7af928b8a8 lib_xsk_extend: Expose more direct xsk_btf_member API
With the current xsk_btf__read() we are seeing a slowdown on the
first packet with timestamps.  The theory is this is caused
by the allocation for the cached hashmap entry.

meta-time rx_ktime:870394156129518 time_now:870394156139039 diff:9521 ns
meta-time rx_ktime:870396208293894 time_now:870396208295098 diff:1204 ns
meta-time rx_ktime:870398256286553 time_now:870398256287772 diff:1219 ns

Create a new API that can access struct members more directly
via caching the xsk_btf_member offset + size in the C-code API user.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 10:25:16 +01:00
6b200aa8d5 lib_xsk_extend: rename xsk_btf_entry to xsk_btf_member
And export xsk_btf_member in header file.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 10:01:30 +01:00
a37b82bd9d AF_XDP-interaction: lib_xsk_extend move entry allocation
Avoid doing a malloc in xsk_btf__field_entry().

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 09:44:53 +01:00
07617277ab AF_XDP-interaction: Cleanup debugging code in lib_xsk_extend
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-04 09:18:44 +01:00
b06ebaf7d9 AF_XDP-interaction: Implement BTF extraction of 'mark'
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 21:59:13 +01:00