bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andriin@fb.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>
Cc: "andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 2/3] libbpf/tools: add runqslower tool to libbpf
Date: Thu, 19 Dec 2019 18:13:24 +0000	[thread overview]
Message-ID: <97ddb036-c717-82a3-4a3b-58180d34a8ae@fb.com> (raw)
In-Reply-To: <20191219070659.424273-3-andriin@fb.com>



On 12/18/19 11:06 PM, Andrii Nakryiko wrote:
> Convert one of BCC tools (runqslower [0]) to BPF CO-RE + libbpf. It matches
> its BCC-based counterpart 1-to-1, supporting all the same parameters and
> functionality.
> 
> runqslower tool utilizes BPF skeleton, auto-generated from BPF object file,
> as well as memory-mapped interface to global (read-only, in this case) data.
> Its makefile also ensures auto-generation of "relocatable" vmlinux.h, which is
> necessary for BTF-typed raw tracepoints with direct memory access.
> 
>    [0] https://github.com/iovisor/bcc/blob/11bf5d02c895df9646c117c713082eb192825293/tools/runqslower.py
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>   tools/lib/bpf/tools/runqslower/.gitignore     |   2 +
>   tools/lib/bpf/tools/runqslower/Makefile       |  60 ++++++
>   .../lib/bpf/tools/runqslower/runqslower.bpf.c | 101 ++++++++++
>   tools/lib/bpf/tools/runqslower/runqslower.c   | 187 ++++++++++++++++++
>   tools/lib/bpf/tools/runqslower/runqslower.h   |  13 ++
>   5 files changed, 363 insertions(+)
>   create mode 100644 tools/lib/bpf/tools/runqslower/.gitignore
>   create mode 100644 tools/lib/bpf/tools/runqslower/Makefile
>   create mode 100644 tools/lib/bpf/tools/runqslower/runqslower.bpf.c
>   create mode 100644 tools/lib/bpf/tools/runqslower/runqslower.c
>   create mode 100644 tools/lib/bpf/tools/runqslower/runqslower.h
> 
> diff --git a/tools/lib/bpf/tools/runqslower/.gitignore b/tools/lib/bpf/tools/runqslower/.gitignore
> new file mode 100644
> index 000000000000..404942cc9371
> --- /dev/null
> +++ b/tools/lib/bpf/tools/runqslower/.gitignore
> @@ -0,0 +1,2 @@
> +/.output
> +/runqslower
> diff --git a/tools/lib/bpf/tools/runqslower/Makefile b/tools/lib/bpf/tools/runqslower/Makefile
> new file mode 100644
> index 000000000000..b87b1f9fe9da
> --- /dev/null
> +++ b/tools/lib/bpf/tools/runqslower/Makefile
> @@ -0,0 +1,60 @@
> +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
> +CLANG := clang
> +LLC := llc
> +LLVM_STRIP := llvm-strip
> +BPFTOOL := bpftool

Maybe it is better to use in-tree bpftool? This will ensure we use the 
one shipped together with the source which should have needed functionality.

> +LIBBPF_SRC := ../..
> +CFLAGS := -g -Wall
> +
> +# Try to detect best kernel BTF source
> +KERNEL_REL := $(shell uname -r)
> +ifneq ("$(wildcard /sys/kenerl/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
> +
> +out := .output
> +abs_out := $(abspath $(out))
> +libbpf_src := $(abspath $(LIBBPF_SRC))
> +
> +.DELETE_ON_ERROR:
> +
> +.PHONY: all
> +all: runqslower
> +
> +.PHONY: clean
> +clean:
> +	rm -rf $(out) runqslower
> +
> +runqslower: $(out)/runqslower.o $(out)/libbpf.a
> +	$(CC) $(CFLAGS) -lelf -lz $^ -o $@
> +
> +$(out)/vmlinux.h: $(VMLINUX_BTF) | $(out)
> +	$(BPFTOOL) btf dump file $(VMLINUX_BTF) format core > $@
> +
> +$(out)/libbpf.a: | $(out)
> +	cd $(out) &&							      \
> +	$(MAKE) -C $(libbpf_src) OUTPUT=$(abs_out)/ $(abs_out)/libbpf.a
> +
> +$(out)/runqslower.o: runqslower.h $(out)/runqslower.skel.h		      \
> +		     $(out)/runqslower.bpf.o
> +
> +$(out)/runqslower.bpf.o: $(out)/vmlinux.h runqslower.h
> +
> +$(out)/%.skel.h: $(out)/%.bpf.o
> +	$(BPFTOOL) gen skeleton $< > $@
> +
> +$(out)/%.bpf.o: %.bpf.c | $(out)
> +	$(CLANG) -g -O2 -target bpf -I$(out) -I$(LIBBPF_SRC)		      \
> +		 -c $(filter %.c,$^) -o $@ &&				      \
> +	$(LLVM_STRIP) -g $@
> +
> +$(out)/%.o: %.c | $(out)
> +	$(CC) $(CFLAGS) -I$(LIBBPF_SRC) -I$(out) -c $(filter %.c,$^) -o $@
> +
> +$(out):
> +	mkdir -p $(out)
> +
[...]

  parent reply	other threads:[~2019-12-19 18:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19  7:06 [PATCH bpf-next 0/3] Implement runqslower BCC tool with BPF CO-RE Andrii Nakryiko
2019-12-19  7:06 ` [PATCH bpf-next 1/3] bpftool: add extra CO-RE mode to btf dump command Andrii Nakryiko
2019-12-19 17:06   ` Alexei Starovoitov
2019-12-19 21:07     ` Andrii Nakryiko
2019-12-19 22:04       ` Alexei Starovoitov
2019-12-20 17:40         ` Andrii Nakryiko
2019-12-21  3:21           ` Alexei Starovoitov
2019-12-21  5:40             ` Andrii Nakryiko
2019-12-19  7:06 ` [PATCH bpf-next 2/3] libbpf/tools: add runqslower tool to libbpf Andrii Nakryiko
2019-12-19 15:41   ` Daniel Borkmann
2019-12-19 21:14     ` Andrii Nakryiko
2019-12-19 22:04       ` Alexei Starovoitov
2019-12-19 18:13   ` Yonghong Song [this message]
2019-12-19 21:16     ` Andrii Nakryiko
2019-12-19  7:06 ` [PATCH bpf-next 3/3] selftests/bpf: build runqslower from selftests Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97ddb036-c717-82a3-4a3b-58180d34a8ae@fb.com \
    --to=yhs@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).