Commit Graph

421 Commits

Author SHA1 Message Date
Jesper Dangaard Brouer
665f26e06b tc-policy: Make more clear that destroying hook kill all progs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 15:55:06 +01:00
Jesper Dangaard Brouer
9fba4b12ac tc-policy: Fix issue of too many TC-BPF filter prog attached multi
This seems to be a common occuring issue with tc cmdline.
And the C-code have inherited the issue in the API.

Trying to replace a TC-BPF prog often result in appending a new prog
(as a new tc filter instance).

Be careful to set both handle and prio and the replace flag.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 15:20:38 +01:00
Jesper Dangaard Brouer
5917dbff3f tc-policy: Add teardown --unload functionality
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 14:59:51 +01:00
Jesper Dangaard Brouer
17c3aa7661 tc-policy: Attach to TC egress hook as libbpf C-code
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 13:37:14 +01:00
Jesper Dangaard Brouer
9e5ab8f4fb tc-policy: Use bpftool skeleton header generate feature
The reason for going this route is that this allow us to
create a user binary that contains the BPF object file.
Thus, we can avoid having to load the BPF file from
a specific location or having to be in same dir as file.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 12:39:31 +01:00
Jesper Dangaard Brouer
dcdceea90c tc-policy: Add C-code boilerplate tc_txq_policy.c
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 12:10:45 +01:00
Jesper Dangaard Brouer
b1efd37ed5 tc-policy: Adapt XPS script to work with ash on Yocto
The Yocto build this is intended for doesn't have /bin/bash
adapt script.

External program "getopt" not avail.

The 'sort' tool is also different, as it comes from busybox.
Adapt the cmdline options for 'sort'.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 10:11:40 +01:00
Jesper Dangaard Brouer
fb84a226b0 tc-policy: Manuel setup steps via tc cmdline
Yocto build have a problem with loading this via tc

 # tc filter replace dev eth1 egress prio 0xC000 handle 1 bpf da obj tc_txq_policy_kern.o
 Continuing without mounted eBPF fs. Too old kernel?
 mkdir (null)/globals failed: No such file or directory
 Unable to load program

It can be worked around via mounting BPF file-system manually:

 # mount -t bpf bpf /sys/fs/bpf/

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 09:17:09 +01:00
Jesper Dangaard Brouer
ae52ac2140 tc-policy: Add script for disabling XPS
Taken from xdp-cpumap-tc git repo:
 https://github.com/xdp-project/xdp-cpumap-tc/blob/master/bin/xps_setup.sh

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 09:12:35 +01:00
Jesper Dangaard Brouer
8fbccb90ab tc-policy: Simple approach static map to TXq 4
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-28 17:25:08 +01:00
Jesper Dangaard Brouer
ceb3fd80e7 tc-policy: Add Makefile
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-28 16:37:06 +01:00
Jesper Dangaard Brouer
e1b18d7b12 AF_XDP-interaction: Fix another warning in complete_tx
warning: ‘return’ with no value, in function returning non-void

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-21 12:09:30 +01:00
Jesper Dangaard Brouer
96e5daf52c AF_XDP-interaction: Fix compiler warnings
warning: suggest parentheses around assignment used as truth value

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-21 12:05:09 +01:00
Jesper Dangaard Brouer
2135ae1c3a Merge pull request #36 from xdp-project/vestas04_AF_XDP_example
AF_XDP example: Improvements to wake-up accuracy
2022-01-21 11:54:54 +01:00
Jesper Dangaard Brouer
0c2ec8a1bd AF_XDP-interaction: Exclude first measurement min/max stats as no next_adj happened
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-19 12:18:27 +01:00
Jesper Dangaard Brouer
4ee53b1fd5 AF_XDP-interaction: Add cmdline options for specifying IPs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-18 16:48:34 +01:00
Jesper Dangaard Brouer
9eefd4bd56 AF_XDP-interaction: Change IP for my testlab
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-18 16:33:17 +01:00
Jesper Dangaard Brouer
1a8a2b9188 AF_XDP-interaction: Add option for selecting batch pkts size
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-18 14:01:57 +01:00
Toke Høiland-Jørgensen
e80da14433 Merge pull request #31 from simosund/pping_loader_improvements
PPing loader improvements
2022-01-17 19:27:40 +01:00
Simon Sundberg
cfdf224d93 pping: Remove usage of deprecated libbpf API
The libbpf API has deprecated a number of functions used by the pping
loader. While a couple of functions have simply been renamed,
bpf_object__find_program_by_title has been completely deprecated in
favor of bpf_object__find_program_by_name. Therefore, change so that
BPF programs are found based on the C function names rather than
section names.

Also remove defines of section names as they are no longer used, and
change the section names in pping_kern.c to use "tc" instead of
"classifier/ingress" and "classifier/egress".

Finally replace the flags json_format and json_ppviz in pping_config
with a single enum for the different output formats. This makes the
logic for which output format to use clearer compared to relying on
multiple (supposedly) mutually exclusive flags (and implicitly
assuming standard format if neither flag was set).

One potential concern with this commit is that it introduces some
"magical strings". In case the function names in pping_kern.c are
changed it will require multiple changes in pping.c.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 18:43:04 +01:00
Simon Sundberg
9ae5606e18 pping: Check bounds on passed float arguments
The rate-limit and cleanup-interval arguments were only verified to be
positive. Add a check for an upper bound to avoid user being able to
pass values that result in an internal overflow. The limits for both
rate-limit and cleanup-interval have been set to one week which should
be more then enough for any reasonable user.

Additionally, disable the period cleanup entirely if the value 0 is
passed to cleanup-interval.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
Simon Sundberg
cbfc3c9a9e pping: Improve XDP and tc attach/detach process
Make several changes to functions related to attaching and detaching
the BPF programs:
- Check the BPF program id when detaching programs to ensure that the
  correct programs are removed.
- When attaching tc-programs, keep track of if the clsact qdisc was
  created or existed previously. Attempt to delete the qdisc if it was
  created and attaching failed. If the --force argument was given, also
  attempt to delete qdisc on shutdown in case it did not previously
  exist.
- Rely on XDP flags to replace existing XDP program if --force is used
  rather than explicitly detaching any XDP program first.
- Print out hints for why pping might have failed attaching the XDP
  program.

Also, use libbpf_strerror instead of strerror to better display
libbpf-specific error codes, and for more reliable error handling in
general (don't need to ensure the error codes are positive).

Finally, change return codes of tc programs to TC_ACT_UNSPEC from
TC_ACT_OK to allow other TC-BPF programs to be used on the same
interface as pping.

Concerns with this commit:
- When attaching a tc program libbpf will emit a warning if the
  clsact qdisc already exists on the interface. The fact that the
  clsact already exists is not an issue, and is handled in tc_attach
  by checking for EEXIST, so the warning could be a bit
  misleading/confusing for the user.
- The tc_attach and xdp_attach functions attempt to return the u32
  prog_id in an int. In case the programs are assigned a very high
  id (> 2^31) this may cause it to be interpreted as an error instead.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
Simon Sundberg
2f5c3fc5b0 pping: Add tc ingress hook as alternative to XDP
For some machines, XDP may not be suitable due to ex. lack of XDP
support in NIC drivers or another program already being attached to
the XDP hook on the desired interface. Therefore, add an option to use
the tc-ingress hook instead of XDP to attach the pping ingress BPF
program on.

In practice, this adds an additional BPF program to the object file (a
TC ingress program). To avoid loading an unnecessary BPF program, also
explicitly disable autoloading for the ingress program not selected.

Also, change the tc programs to return TC_ACT_OK instead of
BPF_OK. While both should be compatible, the TC_ACT_* return codes
seem to be more commonly used for TC-BPF programs.

Concerns with this commit:
- The error messages for XDP attach failure has gotten slightly less
  descriptive. I plan to improve the code for attaching and detaching
  XDP programs in a separate commit, and will then address that.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
Simon Sundberg
bd29a246b9 pping: Use libbpf to attach tc program
libbpf v0.4 added an API for attaching/detaching TC-BPF programs. So
use the new API to attach the tc program instead of calling on an
external script (which uses the tc command line utility).

Avoid removing the clsact qdisc on program shutdown or error, as
there's currently no convenient way to ensure the qdisc isn't used by
other programs as well. This means pping will not completely clean up
after itself, but this is a safer alternative than always destroying
the qdsic as done by the external script, which may pull the rug out
underneath other programs using the qdisc.

Finally, remove the pin_dir member from the configuration as pping no
longer pins any programs or maps, and remove deleted tc loading
scripts from README.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
Simon Sundberg
2465e3e0df pping: Refactor cleanup code
Add cleanup code to load_attach_bpfprogs function, so it should always
unpin tc program, and additionally detach the tc and xdp programs in
case of any failure.

Also unpin tc program directly after attaching it (rather than on
program shutdown), so that multiple instances of pping can be run
simultaneously (on different interfaces).

Finally, rename some of the functions for attaching/detaching tc
programs to be more consistent with the xdp ones.

Note: Still need to keep a copy of most of the cleanup code in main as
well, as the tc and xdp programs also need to be detached on program
shutdown or if later functions fail.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
Toke Høiland-Jørgensen
c04f6934cf Update headers/linux/btf.h
Newer libbpf uses constants from the newer kernel header file, so
compilation breaks unless we have the newest version of the kernel header.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-01-17 13:12:53 +01:00
Toke Høiland-Jørgensen
d36c5f9254 lsm-nobpf: Stop using deprecated helper
The bpf_program__next() helper was deprecated in favour of
bpf_object__next_program(), so switch to that.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-01-17 13:11:27 +01:00
Toke Høiland-Jørgensen
8e9fc89bec libbpf: Update submodule version
Update the libbpf submodule to the latest version, and update the configure
script so we check for the newer bpf_object__next_program() helper (to fix
deprecation warnings).

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-01-17 13:11:27 +01:00
Jesper Dangaard Brouer
86b76f564f AF_XDP-interaction: workaround for detecting when AF_XDP is read for TX
I hope there exist a better API for determining when AF_XDP
is ready for transmitting packets.

This workaround keeps trying to send a single packet, and
check return value seen from sendto() syscall, until it
doesn't return an error.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 16:48:13 +01:00
Jesper Dangaard Brouer
6d6ac23f3b AF_XDP-interaction: warning if code completed more than possible
Give a print WARN if code/AF_XDP somehow have MORE packets to
complete from CQ than our counter for xsk->outstanding_tx packets.
This should not happen, but currently hunting for a TX issue.

The code (below) reset xsk->outstanding_tx, which were introduced
via a discussion on xdp-tutorial:
 https://github.com/xdp-project/xdp-tutorial/issues/180

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 14:33:11 +01:00
Jesper Dangaard Brouer
49c1efadf8 AF_XDP-interaction: Report warning when TX-kick via sendto fails
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 13:26:24 +01:00
Jesper Dangaard Brouer
b1b465a32f AF_XDP-interaction: Remove hack that started tv_nsec as zero
When interval goes below 1 sec this hack screwup first clock_nanosleep.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 11:30:50 +01:00
Jesper Dangaard Brouer
6367e82069 AF_XDP-interaction: Add param to adjust TX-cyclic interval
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 11:12:24 +01:00
Jesper Dangaard Brouer
2d86845b02 AF_XDP-interaction: Add option for debugging time
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-07 17:38:19 +01:00
Jesper Dangaard Brouer
42ea6e7938 AF_XDP-interaction: Hack to start next interval with nsec as zero
This is done to easier visually see the time difference
when debug printing the timespec's (via print_timespec).

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-07 17:38:19 +01:00
Jesper Dangaard Brouer
37e650cd72 AF_XDP-interaction: Handle if adjusting next_adj goes negative
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-07 17:38:19 +01:00
Jesper Dangaard Brouer
f53b5670a5 AF_XDP-interaction: Adjust for inaccuracy of clock_nanosleep
Measurements show that on test systems, clock_nanosleep fairly
consistently wakeup later (or after) the requested sleep time.

It is fairly trivial to simply adjust the sleep/wakeup time
with the measure inaccuracy of clock_nanosleep, and "ask"
clock_nanosleep to wakeup a bit earlier.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-07 17:38:19 +01:00
Jesper Dangaard Brouer
3d66217586 AF_XDP-interaction: Debug TX issue
Calling tx_pkt() before the link is ready, result in no packets
transmitted, but xsk_ring_prod__reserve() still succeeds.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-07 17:38:19 +01:00
Jesper Dangaard Brouer
9ba52af3b4 AF_XDP-interaction: Enable libbpf pr_debug via --debug
Like described in guide:
 https://facebookmicrosites.github.io/bpf/blog/2020/02/20/bcc-to-libbpf-howto-guide.html#libbpf-log

Enable extra libbpf debug printing when --debug gets
specified as option to our program.

This is acheived via setting a custom log handler via
libbpf API call libbpf_set_print().

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-07 17:30:53 +01:00
Jesper Dangaard Brouer
303e6f59c3 Merge pull request #35 from xdp-project/vestas03_AF_XDP_example
AF_XDP-interaction: Implement TX-cyclic sending
2022-01-04 17:49:47 +01:00
Jesper Dangaard Brouer
f3d5d3ca93 AF_XDP-interaction: cmdline options for MAC-addresses
Change Ethernet MAC in transmitted frames
 via cmdline options (-G|--tx-dmac) or (-H|--tx-smac)

Based on suggestion from: Ong Boon Leong <boon.leong.ong@intel.com>
 https://lore.kernel.org/all/20211124091821.3916046-3-boon.leong.ong@intel.com/

Suggested-by: Ong Boon Leong <boon.leong.ong@intel.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-14 13:52:27 +01:00
Jesper Dangaard Brouer
b71f7f8cac AF_XDP-interaction: Add cmdline option for enable/disabling busy-poll mode
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-14 12:26:12 +01:00
Jesper Dangaard Brouer
3685d5ea93 AF_XDP-interaction: Try preferred busy-polling trick
The apply_setsockopt() was taken from samples/bpf/xdpsock_user.c

Testing with --zero-copy this unfortunately doesn't solve
the issue of 8 packets bulks when requesting 4.
Notice this test was with driver igc and chip i225.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-13 23:01:09 +01:00
Jesper Dangaard Brouer
842c707c4e AF_XDP-interaction: Try adding XDP_USE_NEED_WAKEUP
Measurements on a receiver shows that TX doesn't happen immediately.
Even when calling sendto() for doing TX kick.

Added bind flag XDP_USE_NEED_WAKEUP, but this didn't help.

TX burst 4 packets, but in --zero-copy mode we often observe
8 packets arriving in a burst.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-13 21:34:14 +01:00
Jesper Dangaard Brouer
185431e6d8 AF_XDP-interaction: convert to tx_cyclic_and_rx_process
Function now also RX process packet after cyclic TX.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-13 20:45:11 +01:00
Jesper Dangaard Brouer
95a5a31c90 AF_XDP-interaction: add tx_cyclic_batch
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-13 20:03:39 +01:00
Jesper Dangaard Brouer
1750679402 AF_XDP-interaction: Move invent_tx_pkts() out of tx_batch_pkts
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-13 18:25:58 +01:00
Jesper Dangaard Brouer
56ba3a10df AF_XDP-interaction: Implement a TX batching function
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-07 18:12:11 +01:00
Jesper Dangaard Brouer
8b02218dde AF_XDP-interaction: Move function tx_pkt
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-07 15:55:30 +01:00
Jesper Dangaard Brouer
bd49ff6ca8 AF_XDP-interaction: Issue with XDP link down/up
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-12-07 15:35:51 +01:00