Commit Graph

127 Commits

Author SHA1 Message Date
Simon Sundberg
1bb5a44152 pping: Create pin-folder and check if root
Create the /sys/fs/bpf/tc folder if it does not exist. Also check if
pping is run as root, otherwise inform user that it must run as root.

Libbpf will attempt to create the /sys/fs/bpf/tc/globals directory
when pinning the map, however it will not do so recursivly (so will
fail if /sys/fs/bpf/tc does not exist). So as a temporary solution,
attempt to create /sys/fs/bpf/tc (however, if sys/fs/bpf is not
mounted this will still fail).

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:56:49 +01:00
Simon Sundberg
c777287af2 pping: Minor refactor and whitespace fixes
Refactor tc_bpf_load and tc_bpf_clear to use a common run_program
function which does the fork+execv.

Enclose compound statement defines in parenthesis.

Removed argument CLOCK_MONOTONIC from callers to parameterless
function get_time_ns().

Also fix some weird spacing in pping_helpers.h, and fix some
formatting issues, using clang-format with the kernel source tree
.clang-format on the whole tree.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:52:40 +01:00
Simon Sundberg
7410d5cc2c pping: Various minor fixes
Perform various fixes and tweaks:
- Rename several defines to make them more informative
- Remove unrolling of loop in BPF programs
- Reuse defines for program sections between userspace and kernel
  space programs
- Perform fork+exec to run bpf_egress_loader script instead of
  system()
- Add comment to copied scripts indicating I've modified them
- Add pping.h and pping_helpers.h as dependencies in Makefile

Also, add a brief description of what PPing is and how it works to
README

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:48:01 +01:00
Simon Sundberg
71c6458712 pping: Fix incorrect printout of IP-address
Split the print statements for RTTs into two parts to avoid inet_ntoa
overwriting one of the IP-addresses (causing both source and
destitionation address to appear the same). Also flip the order of
source and destination to be the same as Pollere's pping.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:47:15 +01:00
Simon Sundberg
8b42ba1e22 pping: TC-BPF use BTF map if iproute has libbpf
Copy setup from traffic-pacing-edt to use BTF-defined map if configure
detects that iproute2 has libbpf support, otherwise fall back on
bpf_elf_map. Also fix a minor bug with setting default value for SEC
in bpf_egress_loader.sh.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:45:59 +01:00
Simon Sundberg
b920d72fe0 pping: Let libbpf pin map and clean up TC and map at end
Switch order so XDP program loads first, so the ts_start map is
automatically pinned by libbpf (solves issue with tc not preserving
the name of the map).

Unload the TCP-BPF program (or rather remove the entire clsact qdisc
it is attached to) using bpg_egress_loader script once program
exits. Also unpin ts_start map on program shutdown.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:44:33 +01:00
Simon Sundberg
337126306b pping: Switch to BTF-defined maps for XDP program
Make loader use libbpf's existing functionality for reusing pinned
maps. The name for map not kept by tc, so cannot get fd of map by
name. Use fd of first encountered map as temporary workaround.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:44:06 +01:00
Simon Sundberg
b1ce4ee69b pping: Format headers and fix TODO.md
Format the header files in the Linux kernel style (missed in previous
commit). Also fix a formating error in TODO.md that cause empty
checkboxes to not display correctly.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:43:39 +01:00
Simon Sundberg
d3a5de62c4 pping: Format code and add SPDX lincense tags
Format the code using the .clang-format from the kernel source tree,
with a few manual tweaks here and there. Also, remove the TODO list
from comment of pping.c and instead put it in TODO.md.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:43:03 +01:00
Simon Sundberg
1010e53065 pping: Share ts_start map, pping at working stage
Make tc pin the ts_start map when loading the TC-BPF program, and
rewrite XDP loader to reuse map pinned by tc.

Also add comment with TODO list in pping.c.

Testing pping by adding a delay through a netem qdisc in the test
environment shows that the reported RTT will approach 100ms for any
delay lower than 100ms, but the correct RTT for any delay over
100ms. Root cause is unknown, but Pollere's original pping
implementation (as well as a bpftrace based pping implementation)
shows the same issue. This issue has not been observed when running on
real interfaces without a netem qdisc.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:41:40 +01:00
Simon Sundberg
954c66b0e8 pping: Add TC-BPF program for egress
Split and rename files so there is one userspace program (pping) and
two kernel-space ones (one for XDP and one for TC-BPF).

Copy the shell script for loading the TC-BPF program from
traffic-pacing-edt folder, but add support for loading a specific
section.

The XDP and TC-BPF programs do not share the ts_start map, so program
does not work.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:39:16 +01:00
Simon Sundberg
45b138b6ab pping: Add perf-buffer
The XDP program pushes the calculated RTTs to userspace through the
perf-buffer and the userspace program polls it to print them out

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:38:23 +01:00
Simon Sundberg
8628004b6c pping: Add high-level design of eBPF pping to README
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:38:03 +01:00
Simon Sundberg
135ae974e9 pping: Start pping implementation
Add a XDP program to parse TCP timestamps and a simple loader

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:37:15 +01:00
Jesper Dangaard Brouer
76060f0cb8 Merge pull request #8 from xdp-project/cleanups02.public
Cleanups for bpf-examples V2
2021-01-14 14:05:42 +01:00
Jesper Dangaard Brouer
82183edc22 Merge pull request #4 from xdp-project/mtu-tests01.public
MTU-tests: Add some external use of BPF-helper bpf_check_mtu
2021-01-14 10:20:32 +01:00
Jesper Dangaard Brouer
74e549520a Change libbpf install location to fix "dirty" submodule
When installing libbpf headers into 'lib/libbpf/src/root/' then the git
submodule for libbpf is marked dirty. This result in stgit complains under
different operations.

This patch fix the issue by installing libbpf outside submodule directory.
Choose directory 'lib/libbpf-install/' to emphasize relation to 'lib/libbpf/'.

V2: Don't install the library only the header files as before. Also
installing the should be a separate commit.  Patch still statically
link with libbpf/src/libbpf.a.

Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-01-13 18:31:45 +01:00
Jesper Dangaard Brouer
4cbb4f56fe Makefile: clean target should also call clean for lib directory
Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-01-13 18:09:09 +01:00
Jesper Dangaard Brouer
3294cb8573 Makefile: add dependency on configure for config.mk
If configure file changes, then we need to regenerate config.mk.

Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-01-13 18:09:09 +01:00
Jesper Dangaard Brouer
cde146eed6 Makefile: trivial fixes
SPDX-License should be first line in file.

This Makefile is for bpf-examples not xdp-tools.

Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-01-13 18:09:09 +01:00
Jesper Dangaard Brouer
ae7b0948f9 MTU-tests: Makefile detect if TC have libbpf
Only strip BTF info when TC don't have libbpf support.

Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-01-13 18:09:06 +01:00
Toke Høiland-Jørgensen
afcc607e64 .gitmodules: Add ignore=dirty for libbpf
We run 'make install' inside the libbpf subdirectory which will mark it as
'dirty' as far as the parent repo is concerned. Since we're not doing any
libbpf development in this repository, just ignoring it should not bring
any issues; we'll still get a notification if the committed content of the
submodule changes.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-01-13 17:10:20 +01:00
Toke Høiland-Jørgensen
175fb4ad6c configure: Add variable to force submodule
Also don't call removed check for perf_buffer__consume() when using system
libbpf.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-01-12 21:45:29 +01:00
Toke Høiland-Jørgensen
378dcd476b Update libbpf submodule to latest upstream 2021-01-12 21:45:03 +01:00
Jesper Dangaard Brouer
e90c94c492 Merge branch 'netoptimizer-master' 2021-01-08 14:55:37 +01:00
Jesper Dangaard Brouer
a47528b709 Merge branch 'master' of https://github.com/netoptimizer/bpf-examples into netoptimizer-master
Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-01-08 14:54:40 +01:00
Jesper D. Brouer
904c820e7e traffic-pacing-edt: Propagate define that enables BTF maps
Two errors:
- Wrong define in config.mk
- Use BPF_CFLAGS to reach llvm compile cflags

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-22 19:16:10 +01:00
Jesper D. Brouer
39ab41d0d6 Add CPU mapping layer to allow excluding some CPUs
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-18 22:09:24 +01:00
Jesper D. Brouer
47e5cb1c39 traffic-pacing-edt: playing with hash initval
It didn't help kept the original value.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-18 20:13:55 +01:00
Jesper D. Brouer
3b6a0c0aa9 traffic-pacing-edt: Exclude CPU-6 in the code
On production setup i40e driver sends all packets to CPU-6 (RX).
Thus, we want to exclude CPU-6 itself from processing/pacing
packets itself.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-16 21:24:14 +01:00
Jesper D. Brouer
a16ab11e70 traffic-pacing-edt: Use hash function to calc cpu_dest
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-16 21:09:28 +01:00
Jesper D. Brouer
74a47be697 traffic-pacing-edt: Add "SuperFastHash" based on Paul Hsieh design
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-16 20:42:37 +01:00
Jesper D. Brouer
e8ae6a9287 traffic-pacing-edt: implement spead across CPUs
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-16 16:40:15 +01:00
Jesper Dangaard Brouer
12dc740a1a MTU-tests: Add tc_mtu_enforce.c
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2020-12-16 11:39:16 +01:00
Jesper D. Brouer
b3ebc2c18c traffic-pacing-edt: implement option for --remove
Need quick way to remove before testing on production.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-15 19:34:03 +01:00
Jesper D. Brouer
c8682ec27f traffic-pacing-edt: userspace loader for xdp_cpumap_qinq
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-15 17:55:24 +01:00
Jesper D. Brouer
e9c45d7f64 traffic-pacing-edt: start working on xdp_cpumap_qinq
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-15 16:49:57 +01:00
Jesper D. Brouer
89aeeafa0e Update UAPI header file bpf.h
I need the struct bpf_cpumap_val definition for the next example.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-15 16:34:26 +01:00
Jesper D. Brouer
e7401bb500 traffic-pacing-edt: Remove test program edt_pacer01.c
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 15:36:54 +01:00
Jesper D. Brouer
5aab70b25d traffic-pacing-edt: Adjust after file rename
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 15:31:08 +01:00
Jesper D. Brouer
9d52254be6 traffic-pacing-edt: rename edt_pacer02.c to edt_pacer_vlan.c
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 15:29:04 +01:00
Jesper D. Brouer
048c960756 iproute2 tc util have recently gotten libbpf support
Implement configure script that detect support, and Makefile
defines that propagate to BPF-C file, making it possible to
use and compile with BTF type maps.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 14:28:45 +01:00
Jesper D. Brouer
23f73c86ac traffic-pacing-edt: Use bpf_ktime_get_boot_ns
The bpftrace programs use bpf_ktime_get_boot_ns, for underlying 'nsecs'
keyword.  Switch TC-BPF prog to use the same, to make sure that we
don't report false result when detecting/measureing EDT accuracy.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 12:13:24 +01:00
Jesper D. Brouer
79466715cf traffic-pacing-edt: Use SKB->mark to identify different stages
This can be used by bpftrace programs to identify different
stages, when trying to determine the EDT accuracy.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 10:07:25 +01:00
Jesper D. Brouer
b84b89dc4b bpftrace/edt_tstamp_diff_advanced.bt: add doc comments
Also found measurement tool can disturb timing.
I might have to write this in BPF-C directly to avoid overhead.

Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-12-01 09:34:18 +01:00
Jesper D. Brouer
381dd9a512 Add more advanced version of script edt_tstamp_diff_advanced.bt
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-11-30 12:43:14 +01:00
Jesper D. Brouer
93116e0fb2 Add bpftrace dir and program developed last night
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-11-30 12:41:48 +01:00
Jesper D. Brouer
dea36b9d8f Add practical script for loading on all outer VLAN devices
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-11-28 15:45:52 +01:00
Jesper D. Brouer
3248b60248 Do EDT pacing on all inner VLAN ids
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-11-28 15:09:12 +01:00
Jesper D. Brouer
2786f8af65 Extend the sqrt lookup table with more entries
Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
2020-11-28 14:38:48 +01:00