Commit 6dd42aa1 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'runqslower'



Andrii Nakryiko says:

====================
Based on recent BPF CO-RE, tp_btf, and BPF skeleton changes, re-implement
BCC-based runqslower tool as a portable pre-compiled BPF CO-RE-based tool.
Make sure it's built as part of selftests to ensure it doesn't bit rot.

As part of this patch set, augment `format c` output of `bpftool btf dump`
sub-command with applying `preserve_access_index` attribute to all structs and
unions. This makes all such structs and unions automatically relocatable under
BPF CO-RE, which improves user experience of writing TRACING programs with
direct kernel memory read access.

Also, further clean up selftest/bpf Makefile output and make it conforming to
libbpf and bpftool succinct output format.

v1->v2:
- build in-tree bpftool for runqslower (Yonghong);
- drop `format core` and augment `format c` instead (Alexei);
- move runqslower under tools/bpf (Daniel).
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents ac065870 3a0d3092
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -158,8 +158,6 @@ class HeaderParser(object):
                break

        self.reader.close()
        print('Parsed description of %d helper function(s)' % len(self.helpers),
              file=sys.stderr)

###############################################################################

+15 −5
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ FEATURE_TESTS = libbfd disassembler-four-args
FEATURE_DISPLAY = libbfd disassembler-four-args

check_feat := 1
NON_CHECK_FEAT_TARGETS := clean bpftool_clean
NON_CHECK_FEAT_TARGETS := clean bpftool_clean runqslower_clean
ifdef MAKECMDGOALS
ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
  check_feat := 0
@@ -73,7 +73,7 @@ $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c

PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm

all: $(PROGS) bpftool
all: $(PROGS) bpftool runqslower

$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
@@ -89,7 +89,7 @@ $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c

clean: bpftool_clean
clean: bpftool_clean runqslower_clean
	$(call QUIET_CLEAN, bpf-progs)
	$(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
	       $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
@@ -97,7 +97,7 @@ clean: bpftool_clean
	$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
	$(Q)$(RM) -r -- $(OUTPUT)feature

install: $(PROGS) bpftool_install
install: $(PROGS) bpftool_install runqslower_install
	$(call QUIET_INSTALL, bpf_jit_disasm)
	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
	$(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
@@ -115,4 +115,14 @@ bpftool_install:
bpftool_clean:
	$(call descend,bpftool,clean)

.PHONY: all install clean bpftool bpftool_install bpftool_clean
runqslower:
	$(call descend,runqslower)

runqslower_install:
	$(call descend,runqslower,install)

runqslower_clean:
	$(call descend,runqslower,clean)

.PHONY: all install clean bpftool bpftool_install bpftool_clean \
	runqslower runqslower_install runqslower_clean
+8 −0
Original line number Diff line number Diff line
@@ -370,6 +370,10 @@ static int dump_btf_c(const struct btf *btf,
	if (IS_ERR(d))
		return PTR_ERR(d);

	printf("#ifndef BPF_NO_PRESERVE_ACCESS_INDEX\n");
	printf("#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)\n");
	printf("#endif\n\n");

	if (root_type_cnt) {
		for (i = 0; i < root_type_cnt; i++) {
			err = btf_dump__dump_type(d, root_type_ids[i]);
@@ -386,6 +390,10 @@ static int dump_btf_c(const struct btf *btf,
		}
	}

	printf("#ifndef BPF_NO_PRESERVE_ACCESS_INDEX\n");
	printf("#pragma clang attribute pop\n");
	printf("#endif\n");

done:
	btf_dump__free(d);
	return err;
+1 −0
Original line number Diff line number Diff line
/.output
+80 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
OUTPUT := .output
CLANG := clang
LLC := llc
LLVM_STRIP := llvm-strip
DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
BPFTOOL ?= $(DEFAULT_BPFTOOL)
LIBBPF_SRC := $(abspath ../../lib/bpf)
CFLAGS := -g -Wall

# Try to detect best kernel BTF source
KERNEL_REL := $(shell uname -r)
ifneq ("$(wildcard /sys/kernel/btf/vmlinux)","")
VMLINUX_BTF := /sys/kernel/btf/vmlinux
else ifneq ("$(wildcard /boot/vmlinux-$(KERNEL_REL))","")
VMLINUX_BTF := /boot/vmlinux-$(KERNEL_REL)
else
$(error "Can't detect kernel BTF, use VMLINUX_BTF to specify it explicitly")
endif

abs_out := $(abspath $(OUTPUT))
ifeq ($(V),1)
Q =
msg =
else
Q = @
msg = @printf '  %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
MAKEFLAGS += --no-print-directory
submake_extras := feature_display=0
endif

.DELETE_ON_ERROR:

.PHONY: all clean runqslower
all: runqslower

runqslower: $(OUTPUT)/runqslower

clean:
	$(call msg,CLEAN)
	$(Q)rm -rf $(OUTPUT) runqslower

$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(OUTPUT)/libbpf.a
	$(call msg,BINARY,$@)
	$(Q)$(CC) $(CFLAGS) -lelf -lz $^ -o $@

$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
			$(OUTPUT)/runqslower.bpf.o

$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h

$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
	$(call msg,GEN-SKEL,$@)
	$(Q)$(BPFTOOL) gen skeleton $< > $@

$(OUTPUT)/%.bpf.o: %.bpf.c $(OUTPUT)/libbpf.a | $(OUTPUT)
	$(call msg,BPF,$@)
	$(Q)$(CLANG) -g -O2 -target bpf -I$(OUTPUT) -I$(LIBBPF_SRC)	      \
		 -c $(filter %.c,$^) -o $@ &&				      \
	$(LLVM_STRIP) -g $@

$(OUTPUT)/%.o: %.c | $(OUTPUT)
	$(call msg,CC,$@)
	$(Q)$(CC) $(CFLAGS) -I$(LIBBPF_SRC) -I$(OUTPUT) -c $(filter %.c,$^) -o $@

$(OUTPUT):
	$(call msg,MKDIR,$@)
	$(Q)mkdir -p $(OUTPUT)

$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF) | $(OUTPUT) $(BPFTOOL)
	$(call msg,GEN,$@)
	$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@

$(OUTPUT)/libbpf.a: | $(OUTPUT)
	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)			       \
		    OUTPUT=$(abs_out)/ $(abs_out)/libbpf.a

$(DEFAULT_BPFTOOL):
	$(Q)$(MAKE) $(submake_extras) -C ../bpftool			      \
		    prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install
Loading