juagargi / esdx-scion

1 stars 0 forks source link

Bandwidth Monitor #6

Closed lschulz closed 2 years ago

lschulz commented 2 years ago

Adds a prototype ESDX contract bandwidth monitor in BPF/XDP and Go

juagargi commented 2 years ago

I have a compiler error when running go generate:

$ go generate
/home/juagargi/devel/ETH/esdx-scion/monitor/bpf/monitor.c:83:18: error: use of undeclared identifier 'BPF_MAP_TYPE_RINGBUF'
    __uint(type, BPF_MAP_TYPE_RINGBUF);
                 ^
1 error generated.
Error: clang: exit status 1
exit status 1
monitor.go:26: running "go": exit status 1

When looking at the contents of monitor/libbpf I see this:

monitor/libbpf ((HEAD detached at b78c75f)) $ git grep BPF_MAP_TYPE_RINGBUF
.github/actions/build-selftests/vmlinux.h:      BPF_MAP_TYPE_RINGBUF = 27,
include/uapi/linux/bpf.h:       BPF_MAP_TYPE_RINGBUF,
src/libbpf.c:   [BPF_MAP_TYPE_RINGBUF]                  = "ringbuf",
src/libbpf.c:   /* Kernel expects BPF_MAP_TYPE_RINGBUF's max_entries to be
src/libbpf.c:   case BPF_MAP_TYPE_RINGBUF:
src/libbpf_probes.c:    case BPF_MAP_TYPE_RINGBUF:
src/ringbuf.c:  if (info.type != BPF_MAP_TYPE_RINGBUF) {
src/ringbuf.c:          pr_warn("ringbuf: map fd=%d is not BPF_MAP_TYPE_RINGBUF\n",
travis-ci/vmtest/configs/blacklist/BLACKLIST-5.5.0:map_ptr                      # test uses BPF_MAP_TYPE_RINGBUF, added in 5.8
travis-ci/vmtest/configs/blacklist/BLACKLIST-5.5.0:ringbuf                      # BPF_MAP_TYPE_RINGBUF is supported in 5.8+

What should we change? the #include <linux/bpf.h> in the sources or initializing the libbpf to another commit?

lschulz commented 2 years ago

The problem is that eBPF ring buffers were only introduced in kernel 5.8, I think. Of all Ubuntu releases that currently receive support, only Ubuntu 22.04 and the upcoming Ubuntu 20.04.5 have recent enough kernels.

I have updated the requirements in the README and fixed some includes. For me, the project now builds without issues on a fresh Ubuntu 22.04.

It would also be possible to replace the ring buffer with the older perf events, then we could support older kernels.