From 048c960756eb65301a72d2d7c41218906bd63204 Mon Sep 17 00:00:00 2001 From: "Jesper D. Brouer" Date: Tue, 1 Dec 2020 14:27:10 +0100 Subject: [PATCH] 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 --- traffic-pacing-edt/Makefile | 13 ++++++++++++- traffic-pacing-edt/configure | 29 ++++++++++++++++++++++++++++ traffic-pacing-edt/edt_pacer02.c | 22 +++++++++++++++++---- traffic-pacing-edt/iproute2_compat.h | 6 ++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100755 traffic-pacing-edt/configure diff --git a/traffic-pacing-edt/Makefile b/traffic-pacing-edt/Makefile index cb3def9..73c1306 100644 --- a/traffic-pacing-edt/Makefile +++ b/traffic-pacing-edt/Makefile @@ -4,11 +4,20 @@ USER_TARGETS := BPF_TARGETS := edt_pacer01 BPF_TARGETS += edt_pacer02 +EXTRA_DEPS += config.mk + LIB_DIR = ../lib include $(LIB_DIR)/common.mk +include config.mk -# The iproute2 'tc' tool doesn't understand BTF debug info +all: config.mk + +config.mk: configure + @sh configure + +ifndef HAVE_TC_LIBBPF +# If the iproute2 'tc' tool doesn't understand BTF debug info # use llvm-strip to remove this debug info from object file # # *BUT* cannot strip everything as it removes ELF elems needed for @@ -16,6 +25,8 @@ include $(LIB_DIR)/common.mk # .PHONY: strip_tc_obj strip_tc_obj: ${BPF_TARGETS:=.o} + $(Q) echo "TC don't support libbpf - strip BTF info" $(Q) llvm-strip --no-strip-all --remove-section .BTF $? all: strip_tc_obj +endif diff --git a/traffic-pacing-edt/configure b/traffic-pacing-edt/configure new file mode 100755 index 0000000..9b01369 --- /dev/null +++ b/traffic-pacing-edt/configure @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# This is not an autoconf generated configure +# + +# Output file which is input to Makefile +CONFIG=config.mk + +# Assume tc is in $PATH +TC=tc + +check_tc_libbpf() +{ + tc_version=$($TC -V) + if echo $tc_version | grep -q libbpf; then + libbpf_version=${tc_version##*libbpf } + echo "HAVE_TC_LIBBPF:=y" >> $CONFIG + echo "CFLAGS += -DHAVE_LIBBPF" >> $CONFIG + echo "yes ($libbpf_version)" + else + echo "no" + fi +} + +echo "# Generated config" > $CONFIG +echo "Detecting available features on system" + +echo -n " - libbpf support in tc tool: " +check_tc_libbpf diff --git a/traffic-pacing-edt/edt_pacer02.c b/traffic-pacing-edt/edt_pacer02.c index 5b89d4a..a361079 100644 --- a/traffic-pacing-edt/edt_pacer02.c +++ b/traffic-pacing-edt/edt_pacer02.c @@ -2,7 +2,6 @@ #include #include #include -#include "iproute2_compat.h" #include @@ -59,16 +58,31 @@ struct edt_val { struct codel_state codel; } __aligned(64); /* Align struct to cache-size to avoid false-sharing */ -/* The tc tool (iproute2) use another ELF map layout than libbpf (struct - * bpf_map_def), see struct bpf_elf_map from iproute2. +#ifdef HAVE_TC_LIBBPF /* detected by configure script in config.mk */ +/* Use BTF format to create map */ +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 4096); /* Max possible VLANs */ + __type(key, __u32); + __type(value, struct edt_val); +// __uint(pinning, LIBBPF_PIN_BY_NAME); +} time_delay_map SEC(".maps"); + +#else +/* The (iproute2) tc tool (without libbpf support) use another ELF map + * layout than libbpf (struct bpf_map_def), see struct bpf_elf_map + * from iproute2. */ +#include "iproute2_compat.h" struct bpf_elf_map SEC("maps") time_delay_map = { .type = BPF_MAP_TYPE_ARRAY, .size_key = sizeof(__u32), .size_value = sizeof(struct edt_val), .max_elem = 4096, /* Max possible VLANs */ - //.pinning = PIN_GLOBAL_NS, +// .pinning = PIN_GLOBAL_NS, }; +#endif + /* Role of EDT (Earliest Departure Time) is to schedule departure of packets to * be send in the future. diff --git a/traffic-pacing-edt/iproute2_compat.h b/traffic-pacing-edt/iproute2_compat.h index a535f5f..3d72546 100644 --- a/traffic-pacing-edt/iproute2_compat.h +++ b/traffic-pacing-edt/iproute2_compat.h @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ +/* Taken from from #include */ #ifndef __IPROUTE2_COMPAT_H #define __IPROUTE2_COMPAT_H @@ -8,6 +9,11 @@ * binary layout until "flags". Thus, BPF-progs can use both if careful. */ +/* Object pinning settings */ +#define PIN_NONE 0 +#define PIN_OBJECT_NS 1 +#define PIN_GLOBAL_NS 2 + /* ELF map definition (copied from iproute2 source code) */ struct bpf_elf_map { __u32 type;