Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1180696 > unrolled thread

[GIT PULL 00/39] perf tools: filtering events using eBPF programs

Started byWang Nan <wangnan0@huawei.com>
First post2015-07-09 14:40 +0200
Last post2015-07-15 13:30 +0200
Articles 11 on this page of 31 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [GIT PULL 00/39] perf tools: filtering events using eBPF programs Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:40 +0200
    [PATCH 36/39] perf tools: Use same BPF program if arguments are identical Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 25/39] perf tools: Attach eBPF program to perf event Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 27/39] perf record: Add clang options for compiling BPF scripts Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 34/39] perf tools: Add prologue for BPF programs for fetching arguments Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 31/39] perf tools: Move linux/filter.h to tools/include Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 26/39] perf tools: Suppress probing messages when probing by BPF loading Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 28/39] bpf tools: Load a program with different instances using preprocessor Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
      Re: [PATCH 28/39] bpf tools: Load a program with different instances  using preprocessor "Wangnan (F)" <wangnan0@huawei.com> - 2015-07-13 08:00 +0200
    [PATCH 13/39] perf tools: Call clang to compile C source to object code Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 32/39] perf tools: Add BPF_PROLOGUE config options for further patches Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 06/39] bpf tools: Create eBPF maps defined in an object file Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
      Re: [PATCH 06/39] bpf tools: Create eBPF maps defined in an object  file "Wangnan (F)" <wangnan0@huawei.com> - 2015-07-14 06:10 +0200
    [PATCH 35/39] perf tools: Generate prologue for BPF programs Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 30/39] perf probe: Reset args and nargs for probe_trace_event when failure Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 18/39] perf record: Enable passing bpf object file to --event Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 14/39] perf tools: Auto detecting kernel build directory Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 23/39] perf record: Load all eBPF object into kernel Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 24/39] perf tools: Add bpf_fd field to evsel and config it Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 22/39] perf record: Probe at kprobe points Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 15/39] perf tools: Auto detecting kernel include options Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 29/39] perf tools: Fix probe-event.h include Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 02/39] bpf tools: Collect eBPF programs from their own sections Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
      Re: [PATCH 02/39] bpf tools: Collect eBPF programs from their own  sections "Wangnan (F)" <wangnan0@huawei.com> - 2015-07-10 05:20 +0200
        Re: [PATCH 02/39] bpf tools: Collect eBPF programs from their own  sections "Wangnan (F)" <wangnan0@huawei.com> - 2015-07-14 06:10 +0200
    [PATCH 21/39] perf probe: Attach trace_probe_event with perf_probe_event Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 09/39] bpf tools: Load eBPF programs in object files into kernel Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    [PATCH 37/39] perf record: Support custom vmlinux path Wang Nan <wangnan0@huawei.com> - 2015-07-09 14:50 +0200
    perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering  events using eBPF programs Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-07-14 17:40 +0200
      Re: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering  events using eBPF programs "Wangnan (F)" <wangnan0@huawei.com> - 2015-07-15 13:10 +0200
        Re: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering  events using eBPF programs Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-07-15 13:30 +0200

Page 2 of 2 — ← Prev page 1 [2]


#1180724 — [PATCH 15/39] perf tools: Auto detecting kernel include options

FromWang Nan <wangnan0@huawei.com>
Date2015-07-09 14:50 +0200
Subject[PATCH 15/39] perf tools: Auto detecting kernel include options
Message-ID<pKjr6-dD-65@gated-at.bofh.it>
In reply to#1180696
To help user find correct kernel include options, this patch extracts
them from kbuild system by an embedded script kinc_fetch_script, which
creates a temporary directory, generates Makefile and an empty dummy.o
then use the Makefile to fetch $(NOSTDINC_FLAGS), $(LINUXINCLUDE) and
$(EXTRA_CFLAGS) options. The result is passed to compiler script using
'KERNEL_INC_OPTIONS' environment variable.

Because options from kbuild contains relative path like
'Iinclude/generated/uapi', the work directory must be changed. This is
done by previous patch.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
 tools/perf/util/llvm-utils.c | 59 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 2ca2bd6..b658896 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -218,15 +218,42 @@ static const char *kbuild_detector =
 "fi\n"
 "exit -1\n";
 
+static const char *kinc_fetch_script =
+"#!/usr/bin/env sh\n"
+"if ! test -d \"$KBUILD_DIR\"\n"
+"then\n"
+"	exit -1\n"
+"fi\n"
+"if ! test -f \"$KBUILD_DIR/include/generated/autoconf.h\"\n"
+"then\n"
+"	exit -1\n"
+"fi\n"
+"TMPDIR=`mktemp -d`\n"
+"if test -z \"$TMPDIR\"\n"
+"then\n"
+"    exit -1\n"
+"fi\n"
+"cat << EOF > $TMPDIR/Makefile\n"
+"obj-y := dummy.o\n"
+"\\$(obj)/%.o: \\$(src)/%.c\n"
+"\t@echo -n \"\\$(NOSTDINC_FLAGS) \\$(LINUXINCLUDE) \\$(EXTRA_CFLAGS)\"\n"
+"EOF\n"
+"touch $TMPDIR/dummy.c\n"
+"make -s -C $KBUILD_DIR M=$TMPDIR $KBUILD_OPTS dummy.o 2>/dev/null\n"
+"RET=$?\n"
+"rm -rf $TMPDIR\n"
+"exit $RET\n";
+
 static inline void
-get_kbuild_opts(char **kbuild_dir)
+get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
 {
 	int err;
 
-	if (!kbuild_dir)
+	if (!kbuild_dir || !kbuild_include_opts)
 		return;
 
 	*kbuild_dir = NULL;
+	*kbuild_include_opts = NULL;
 
 	if (llvm_param.kbuild_dir && !llvm_param.kbuild_dir[0]) {
 		pr_debug("[llvm.kbuild-dir] is set to \"\" deliberately.\n");
@@ -247,6 +274,26 @@ get_kbuild_opts(char **kbuild_dir)
 "     \tdetection.\n\n");
 		return;
 	}
+
+	pr_debug("Kernel build dir is set to %s\n", *kbuild_dir);
+	force_set_env("KBUILD_DIR", *kbuild_dir);
+	err = read_from_pipe(kinc_fetch_script,
+			     (void **)kbuild_include_opts,
+			     NULL);
+	if (err) {
+		pr_warning(
+"WARNING:\tunable to get kernel include directories from '%s'\n"
+"Hint:\tTry set clang include options using 'clang-bpf-cmd-template'\n"
+"     \toption in [llvm] section of ~/.perfconfig and set 'kbuild-dir'\n"
+"     \toption in [llvm] to \"\" to suppress this detection.\n\n",
+			*kbuild_dir);
+
+		free(*kbuild_dir);
+		*kbuild_dir = NULL;
+		return;
+	}
+
+	pr_debug("include option is set to %s\n", *kbuild_include_opts);
 }
 
 int llvm__compile_bpf(const char *path, void **p_obj_buf,
@@ -256,7 +303,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	char clang_path[PATH_MAX];
 	const char *clang_opt = llvm_param.clang_opt;
 	const char *template = llvm_param.clang_bpf_cmd_template;
-	char *kbuild_dir = NULL;
+	char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
 	void *obj_buf = NULL;
 	size_t obj_buf_sz;
 
@@ -278,11 +325,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	 * This is an optional work. Even it fail we can continue our
 	 * work. Needn't to check error return.
 	 */
-	get_kbuild_opts(&kbuild_dir);
+	get_kbuild_opts(&kbuild_dir, &kbuild_include_opts);
 
 	force_set_env("CLANG_EXEC", clang_path);
 	force_set_env("CLANG_OPTIONS", clang_opt);
-	force_set_env("KERNEL_INC_OPTIONS", NULL);
+	force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
 	force_set_env("WORKING_DIR", kbuild_dir ? : ".");
 
 	/*
@@ -305,6 +352,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	}
 
 	free(kbuild_dir);
+	free(kbuild_include_opts);
 	if (!p_obj_buf)
 		free(obj_buf);
 	else
@@ -315,6 +363,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	return 0;
 errout:
 	free(kbuild_dir);
+	free(kbuild_include_opts);
 	free(obj_buf);
 	if (p_obj_buf)
 		*p_obj_buf = NULL;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1180725 — [PATCH 29/39] perf tools: Fix probe-event.h include

FromWang Nan <wangnan0@huawei.com>
Date2015-07-09 14:50 +0200
Subject[PATCH 29/39] perf tools: Fix probe-event.h include
Message-ID<pKjr6-dD-67@gated-at.bofh.it>
In reply to#1180696
Commit 7b6ff0bdbf4f7f429c2116cca92a6d171217449e ("perf probe ppc64le:
Fixup function entry if using kallsyms lookup") adds 'struct map' into
probe-event.h but not include "util/map.h" in it. This patch fixes it.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
 tools/perf/util/probe-event.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 116b0aa..e9b7190 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -5,6 +5,7 @@
 #include "intlist.h"
 #include "strlist.h"
 #include "strfilter.h"
+#include "map.h"
 
 /* Probe related configurations */
 struct probe_conf {
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1180726 — [PATCH 02/39] bpf tools: Collect eBPF programs from their own sections

FromWang Nan <wangnan0@huawei.com>
Date2015-07-09 14:50 +0200
Subject[PATCH 02/39] bpf tools: Collect eBPF programs from their own sections
Message-ID<pKjr6-dD-69@gated-at.bofh.it>
In reply to#1180696
This patch collects all programs in an object file into an array of
'struct bpf_program' for further processing. That structure is for
representing each eBPF program. 'bpf_prog' should be a better name, but
it has been used by linux/filter.h. Although it is a kernel space name,
I still prefer to call it 'bpf_program' to prevent possible confusion.

bpf_program__new() creates a new 'struct bpf_program' object. It first
init a variable in stack using __bpf_program__new(), then if success,
enlarges obj->programs array and copy the new object in.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1435716878-189507-13-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/bpf/libbpf.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 9b016c0..3b717de 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -78,12 +78,27 @@ void libbpf_set_print(libbpf_print_fn_t warn,
 # define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
 #endif
 
+/*
+ * bpf_prog should be a better name but it has been used in
+ * linux/filter.h.
+ */
+struct bpf_program {
+	/* Index in elf obj file, for relocation use. */
+	int idx;
+	char *section_name;
+	struct bpf_insn *insns;
+	size_t insns_cnt;
+};
+
 struct bpf_object {
 	char license[64];
 	u32 kern_version;
 	void *maps_buf;
 	size_t maps_buf_sz;
 
+	struct bpf_program *programs;
+	size_t nr_programs;
+
 	/*
 	 * Information when doing elf related work. Only valid if fd
 	 * is valid.
@@ -100,6 +115,84 @@ struct bpf_object {
 };
 #define obj_elf_valid(o)	((o)->efile.elf)
 
+static void bpf_program__clear(struct bpf_program *prog)
+{
+	if (!prog)
+		return;
+
+	zfree(&prog->section_name);
+	zfree(&prog->insns);
+	prog->insns_cnt = 0;
+	prog->idx = -1;
+}
+
+static int
+__bpf_program__new(void *data, size_t size, char *name, int idx,
+		   struct bpf_program *prog)
+{
+	if (size < sizeof(struct bpf_insn)) {
+		pr_warning("corrupted section '%s'\n", name);
+		return -EINVAL;
+	}
+
+	bzero(prog, sizeof(*prog));
+
+	prog->section_name = strdup(name);
+	if (!prog->section_name) {
+		pr_warning("failed to alloc name for prog %s\n",
+			   name);
+		goto errout;
+	}
+
+	prog->insns = malloc(size);
+	if (!prog->insns) {
+		pr_warning("failed to alloc insns for %s\n", name);
+		goto errout;
+	}
+	prog->insns_cnt = size / sizeof(struct bpf_insn);
+	memcpy(prog->insns, data,
+	       prog->insns_cnt * sizeof(struct bpf_insn));
+	prog->idx = idx;
+
+	return 0;
+errout:
+	bpf_program__clear(prog);
+	return -ENOMEM;
+}
+
+static struct bpf_program *
+bpf_program__new(struct bpf_object *obj, void *data, size_t size,
+		 char *name, int idx)
+{
+	struct bpf_program prog, *progs;
+	int nr_progs, err;
+
+	err = __bpf_program__new(data, size, name, idx, &prog);
+	if (err)
+		return NULL;
+
+	progs = obj->programs;
+	nr_progs = obj->nr_programs;
+
+	progs = realloc(progs, sizeof(progs[0]) * (nr_progs + 1));
+	if (!progs) {
+		/*
+		 * In this case the original obj->programs
+		 * is still valid, so don't need special treat for
+		 * bpf_close_object().
+		 */
+		pr_warning("failed to alloc a new program '%s'\n",
+			   name);
+		bpf_program__clear(&prog);
+		return NULL;
+	}
+
+	obj->programs = progs;
+	obj->nr_programs = nr_progs + 1;
+	progs[nr_progs] = prog;
+	return &progs[nr_progs];
+}
+
 static struct bpf_object *bpf_object__new(const char *path,
 					  void *obj_buf,
 					  size_t obj_buf_sz)
@@ -342,6 +435,21 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
 				err = -EEXIST;
 			} else
 				obj->efile.symbols = data;
+		} else if ((sh.sh_type == SHT_PROGBITS) &&
+			   (sh.sh_flags & SHF_EXECINSTR) &&
+			   (data->d_size > 0)) {
+			struct bpf_program *prog;
+
+			prog = bpf_program__new(obj, data->d_buf,
+						data->d_size, name,
+						idx);
+			if (!prog) {
+				pr_warning("failed to alloc program %s (%s)",
+					   name, obj->path);
+				err = -ENOMEM;
+			} else
+				pr_debug("found program %s\n",
+					 prog->section_name);
 		}
 		if (err)
 			goto out;
@@ -415,11 +523,20 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf,
 
 void bpf_object__close(struct bpf_object *obj)
 {
+	size_t i;
+
 	if (!obj)
 		return;
 
 	bpf_object__elf_finish(obj);
 
 	zfree(&obj->maps_buf);
+
+	if (obj->programs && obj->nr_programs) {
+		for (i = 0; i < obj->nr_programs; i++)
+			bpf_program__clear(&obj->programs[i]);
+	}
+	zfree(&obj->programs);
+
 	free(obj);
 }
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1181185 — Re: [PATCH 02/39] bpf tools: Collect eBPF programs from their own sections

From"Wangnan (F)" <wangnan0@huawei.com>
Date2015-07-10 05:20 +0200
SubjectRe: [PATCH 02/39] bpf tools: Collect eBPF programs from their own sections
Message-ID<pKx10-tH-5@gated-at.bofh.it>
In reply to#1180726

On 2015/7/9 23:58, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jul 09, 2015 at 12:35:05PM +0000, Wang Nan escreveu:
>> This patch collects all programs in an object file into an array of
>> 'struct bpf_program' for further processing. That structure is for
>> representing each eBPF program. 'bpf_prog' should be a better name, but
>> it has been used by linux/filter.h. Although it is a kernel space name,
>> I still prefer to call it 'bpf_program' to prevent possible confusion.
>>
>> bpf_program__new() creates a new 'struct bpf_program' object. It first
>> init a variable in stack using __bpf_program__new(), then if success,
>> enlarges obj->programs array and copy the new object in.
>>
>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>> Acked-by: Alexei Starovoitov <ast@plumgrid.com>
>> Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
>> Cc: Daniel Borkmann <daniel@iogearbox.net>
>> Cc: David Ahern <dsahern@gmail.com>
>> Cc: He Kuang <hekuang@huawei.com>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Cc: Kaixu Xia <xiakaixu@huawei.com>
>> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Paul Mackerras <paulus@samba.org>
>> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
>> Cc: Zefan Li <lizefan@huawei.com>
>> Cc: pi3orama@163.com
>> Link: http://lkml.kernel.org/r/1435716878-189507-13-git-send-email-wangnan0@huawei.com
>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>> ---
>>   tools/lib/bpf/libbpf.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 117 insertions(+)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 9b016c0..3b717de 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -78,12 +78,27 @@ void libbpf_set_print(libbpf_print_fn_t warn,
>>   # define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
>>   #endif
>>   
>> +/*
>> + * bpf_prog should be a better name but it has been used in
>> + * linux/filter.h.
>> + */
>> +struct bpf_program {
>> +	/* Index in elf obj file, for relocation use. */
>> +	int idx;
>> +	char *section_name;
>> +	struct bpf_insn *insns;
>> +	size_t insns_cnt;
>> +};
>> +
>>   struct bpf_object {
>>   	char license[64];
>>   	u32 kern_version;
>>   	void *maps_buf;
>>   	size_t maps_buf_sz;
>>   
>> +	struct bpf_program *programs;
>> +	size_t nr_programs;
>> +
>>   	/*
>>   	 * Information when doing elf related work. Only valid if fd
>>   	 * is valid.
>> @@ -100,6 +115,84 @@ struct bpf_object {
>>   };
>>   #define obj_elf_valid(o)	((o)->efile.elf)
>>   
>> +static void bpf_program__clear(struct bpf_program *prog)
>> +{
>> +	if (!prog)
>> +		return;
>> +
>> +	zfree(&prog->section_name);
>> +	zfree(&prog->insns);
>> +	prog->insns_cnt = 0;
>> +	prog->idx = -1;
>> +}
> So in perf land we use 'bpf_program__exit()' as the counterpart of
> bpf_program__init(), i.e. one just initializes fields, allocating
> memory for 'struct bpf_program' members, but does not allocates the
> struct bpf_program itself, because sometimes we embed it inside other
> structs, or we have it in arrays, as you do.
>
> So, to keep that convention, please rename bpf_program__clear() to
> bpf_program__exit() and the next function, __bpf_program__new() to
> bpf_program__init(), with 'struct bpf_program *prog' as the first
> parameter.
>
> To speed things up, from now on, when I see such stuff, I will do the
> changes, put them in a branch with a commiter note, and wait for your
> Ack (or not, if you disagree with something).
>
> One more comment below.
>
>> +
>> +static int
>> +__bpf_program__new(void *data, size_t size, char *name, int idx,
>> +		   struct bpf_program *prog)
>> +{
>> +	if (size < sizeof(struct bpf_insn)) {
>> +		pr_warning("corrupted section '%s'\n", name);
>> +		return -EINVAL;
>> +	}
>> +
>> +	bzero(prog, sizeof(*prog));
>> +
>> +	prog->section_name = strdup(name);
>> +	if (!prog->section_name) {
>> +		pr_warning("failed to alloc name for prog %s\n",
>> +			   name);
>> +		goto errout;
>> +	}
>> +
>> +	prog->insns = malloc(size);
>> +	if (!prog->insns) {
>> +		pr_warning("failed to alloc insns for %s\n", name);
>> +		goto errout;
>> +	}
>> +	prog->insns_cnt = size / sizeof(struct bpf_insn);
>> +	memcpy(prog->insns, data,
>> +	       prog->insns_cnt * sizeof(struct bpf_insn));
>> +	prog->idx = idx;
>> +
>> +	return 0;
>> +errout:
>> +	bpf_program__clear(prog);
>> +	return -ENOMEM;
>> +}
>> +
>> +static struct bpf_program *
>> +bpf_program__new(struct bpf_object *obj, void *data, size_t size,
>> +		 char *name, int idx)
> This, as well, is not a 'bpf_program' method, it is a 'struct
> bpf_object' one, that will manipulate 'struct bpf_object' internal
> state, changing its struct members to get space for an extra bpf_program
> that was initialized on the stack, if the initialization of such
> bpf_program went well, or bail out otherwise.
>
> So I suggest you rename this to:
>
> int bpf_object__add_program(struct bpf_object *obj, void *data, size_t size, char *name, int idx)
>
> And probably move that debug that uses prog->section_name to just after
> the realloc, here in this function.
>
> I will look at the other patches after lunch, thanks for providing the
> git tree, I will try and use it before looking at the patches
> individually, to get a feel of the whole thing.

I didn't find your code, so I updated my git tree. Please see:

  https://github.com/WangNan0/linux/commit/e5ffa4f070ee36cce5130d08622dc305ad9cdb31

And I also resolved a confliction in the next patch.

I think you can comment on current patchset since the modification is 
too small to
send again.

And following is new pull request:

The following changes since commit 3381a29cbec5447086c0f726ee9a88c02e60becc:

   bpf tools: Collect map definitions from 'maps' section (2015-07-07 
13:41:45 -0300)

are available in the git repository at:

   https://github.com/WangNan0/linux.git perf/ebpf-for-acme

for you to fetch changes up to ecc453e27f60ff59e0c2d1cdf64fb595b72d2f68:

   perf tools: Support attach BPF program on uprobe events (2015-07-10 
02:52:57 +0000)

Thank you.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1183338 — Re: [PATCH 02/39] bpf tools: Collect eBPF programs from their own sections

From"Wangnan (F)" <wangnan0@huawei.com>
Date2015-07-14 06:10 +0200
SubjectRe: [PATCH 02/39] bpf tools: Collect eBPF programs from their own sections
Message-ID<pLZHz-5Td-1@gated-at.bofh.it>
In reply to#1181185

On 2015/7/14 3:51, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jul 10, 2015 at 11:07:53AM +0800, Wangnan (F) escreveu:
>> On 2015/7/9 23:58, Arnaldo Carvalho de Melo wrote:
>>> Em Thu, Jul 09, 2015 at 12:35:05PM +0000, Wang Nan escreveu:
>>>> This patch collects all programs in an object file into an array of
>>>> 'struct bpf_program' for further processing. That structure is for
>>>> representing each eBPF program. 'bpf_prog' should be a better name, but
>>>> it has been used by linux/filter.h. Although it is a kernel space name,
>>>> I still prefer to call it 'bpf_program' to prevent possible confusion.
>>>>
>>>> bpf_program__new() creates a new 'struct bpf_program' object. It first
>>>> init a variable in stack using __bpf_program__new(), then if success,
>>>> enlarges obj->programs array and copy the new object in.
>>>>
>>>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>>>> Acked-by: Alexei Starovoitov <ast@plumgrid.com>
>>>> Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
>>>> Cc: Daniel Borkmann <daniel@iogearbox.net>
>>>> Cc: David Ahern <dsahern@gmail.com>
>>>> Cc: He Kuang <hekuang@huawei.com>
>>>> Cc: Jiri Olsa <jolsa@kernel.org>
>>>> Cc: Kaixu Xia <xiakaixu@huawei.com>
>>>> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>>>> Cc: Namhyung Kim <namhyung@kernel.org>
>>>> Cc: Paul Mackerras <paulus@samba.org>
>>>> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
>>>> Cc: Zefan Li <lizefan@huawei.com>
>>>> Cc: pi3orama@163.com
>>>> Link: http://lkml.kernel.org/r/1435716878-189507-13-git-send-email-wangnan0@huawei.com
>>>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>>>> ---
>>>>   tools/lib/bpf/libbpf.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
>>>>   1 file changed, 117 insertions(+)
>>>>
>>>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>>>> index 9b016c0..3b717de 100644
>>>> --- a/tools/lib/bpf/libbpf.c
>>>> +++ b/tools/lib/bpf/libbpf.c
>>>> @@ -78,12 +78,27 @@ void libbpf_set_print(libbpf_print_fn_t warn,
>>>>   # define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
>>>>   #endif
>>>> +/*
>>>> + * bpf_prog should be a better name but it has been used in
>>>> + * linux/filter.h.
>>>> + */
>>>> +struct bpf_program {
>>>> +	/* Index in elf obj file, for relocation use. */
>>>> +	int idx;
>>>> +	char *section_name;
>>>> +	struct bpf_insn *insns;
>>>> +	size_t insns_cnt;
>>>> +};
>>>> +
>>>>   struct bpf_object {
>>>>   	char license[64];
>>>>   	u32 kern_version;
>>>>   	void *maps_buf;
>>>>   	size_t maps_buf_sz;
>>>> +	struct bpf_program *programs;
>>>> +	size_t nr_programs;
>>>> +
>>>>   	/*
>>>>   	 * Information when doing elf related work. Only valid if fd
>>>>   	 * is valid.
>>>> @@ -100,6 +115,84 @@ struct bpf_object {
>>>>   };
>>>>   #define obj_elf_valid(o)	((o)->efile.elf)
>>>> +static void bpf_program__clear(struct bpf_program *prog)
>>>> +{
>>>> +	if (!prog)
>>>> +		return;
>>>> +
>>>> +	zfree(&prog->section_name);
>>>> +	zfree(&prog->insns);
>>>> +	prog->insns_cnt = 0;
>>>> +	prog->idx = -1;
>>>> +}
>>> So in perf land we use 'bpf_program__exit()' as the counterpart of
>>> bpf_program__init(), i.e. one just initializes fields, allocating
>>> memory for 'struct bpf_program' members, but does not allocates the
>>> struct bpf_program itself, because sometimes we embed it inside other
>>> structs, or we have it in arrays, as you do.
>>>
>>> So, to keep that convention, please rename bpf_program__clear() to
>>> bpf_program__exit() and the next function, __bpf_program__new() to
>>> bpf_program__init(), with 'struct bpf_program *prog' as the first
>>> parameter.
>>>
>>> To speed things up, from now on, when I see such stuff, I will do the
>>> changes, put them in a branch with a commiter note, and wait for your
>>> Ack (or not, if you disagree with something).
>>>
>>> One more comment below.
>>>
>>>> +
>>>> +static int
>>>> +__bpf_program__new(void *data, size_t size, char *name, int idx,
>>>> +		   struct bpf_program *prog)
>>>> +{
>>>> +	if (size < sizeof(struct bpf_insn)) {
>>>> +		pr_warning("corrupted section '%s'\n", name);
>>>> +		return -EINVAL;
>>>> +	}
>>>> +
>>>> +	bzero(prog, sizeof(*prog));
>>>> +
>>>> +	prog->section_name = strdup(name);
>>>> +	if (!prog->section_name) {
>>>> +		pr_warning("failed to alloc name for prog %s\n",
>>>> +			   name);
>>>> +		goto errout;
>>>> +	}
>>>> +
>>>> +	prog->insns = malloc(size);
>>>> +	if (!prog->insns) {
>>>> +		pr_warning("failed to alloc insns for %s\n", name);
>>>> +		goto errout;
>>>> +	}
>>>> +	prog->insns_cnt = size / sizeof(struct bpf_insn);
>>>> +	memcpy(prog->insns, data,
>>>> +	       prog->insns_cnt * sizeof(struct bpf_insn));
>>>> +	prog->idx = idx;
>>>> +
>>>> +	return 0;
>>>> +errout:
>>>> +	bpf_program__clear(prog);
>>>> +	return -ENOMEM;
>>>> +}
>>>> +
>>>> +static struct bpf_program *
>>>> +bpf_program__new(struct bpf_object *obj, void *data, size_t size,
>>>> +		 char *name, int idx)
>>> This, as well, is not a 'bpf_program' method, it is a 'struct
>>> bpf_object' one, that will manipulate 'struct bpf_object' internal
>>> state, changing its struct members to get space for an extra bpf_program
>>> that was initialized on the stack, if the initialization of such
>>> bpf_program went well, or bail out otherwise.
>>>
>>> So I suggest you rename this to:
>>>
>>> int bpf_object__add_program(struct bpf_object *obj, void *data, size_t size, char *name, int idx)
>>>
>>> And probably move that debug that uses prog->section_name to just after
>>> the realloc, here in this function.
>>>
>>> I will look at the other patches after lunch, thanks for providing the
>>> git tree, I will try and use it before looking at the patches
>>> individually, to get a feel of the whole thing.
>> I didn't find your code, so I updated my git tree. Please see:
>>
>>   https://github.com/WangNan0/linux/commit/e5ffa4f070ee36cce5130d08622dc305ad9cdb31
> Ok, so used bpf_object__add_program, but you still return a bpf_program
> pointer, that you do not use for anything, i.e. the failure of
> bpf_object__add_program is reported only via a NULL return and you then
> assume this was because ENOMEM was the reason, when there are multiple
> errors that can cause bpf_object__add_program to fail.
>
> Noted that with a comment on that patch, checked that no later patches
> use that return, etc.

I saw your modification ann it looks good to me. I'll collect it into my 
patchset.

Thank you.

> - Arnaldo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1180727 — [PATCH 21/39] perf probe: Attach trace_probe_event with perf_probe_event

FromWang Nan <wangnan0@huawei.com>
Date2015-07-09 14:50 +0200
Subject[PATCH 21/39] perf probe: Attach trace_probe_event with perf_probe_event
Message-ID<pKjr6-dD-71@gated-at.bofh.it>
In reply to#1180696
This patch drops struct __event_package structure. Instead, it adds
trace_probe_event into 'struct perf_probe_event'.

trace_probe_event information gives further patches a chance to access
actual probe points and actual arguments. Using them, bpf_loader will
be able to attach one bpf program to different probing points of a
inline functions (which has multiple probing points) and glob
functions. Moreover, by reading arguments information, bpf code for
reading those arguments can be generated.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
 tools/perf/builtin-probe.c    |  4 ++-
 tools/perf/util/probe-event.c | 60 +++++++++++++++++++++----------------------
 tools/perf/util/probe-event.h |  6 ++++-
 3 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index b81cec3..826d452 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -496,7 +496,9 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
 			usage_with_options(probe_usage, options);
 		}
 
-		ret = add_perf_probe_events(params.events, params.nevents);
+		ret = add_perf_probe_events(params.events,
+					    params.nevents,
+					    true);
 		if (ret < 0) {
 			pr_err_with_code("  Error: Failed to add events.", ret);
 			return ret;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 381f23a..083e8b4 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1930,6 +1930,9 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
 	struct perf_probe_arg_field *field, *next;
 	int i;
 
+	if (pev->ntevs)
+		cleanup_perf_probe_event(pev);
+
 	free(pev->event);
 	free(pev->group);
 	free(pev->target);
@@ -2778,61 +2781,58 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
 	return find_probe_trace_events_from_map(pev, tevs);
 }
 
-struct __event_package {
-	struct perf_probe_event		*pev;
-	struct probe_trace_event	*tevs;
-	int				ntevs;
-};
-
-int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
+int cleanup_perf_probe_event(struct perf_probe_event *pev)
 {
-	int i, j, ret;
-	struct __event_package *pkgs;
+	int i;
 
-	ret = 0;
-	pkgs = zalloc(sizeof(struct __event_package) * npevs);
+	if (!pev || !pev->ntevs)
+		return 0;
 
-	if (pkgs == NULL)
-		return -ENOMEM;
+	for (i = 0; i < pev->ntevs; i++)
+		clear_probe_trace_event(&pev->tevs[i]);
+
+	zfree(&pev->tevs);
+	pev->ntevs = 0;
+	return 0;
+}
+
+int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
+			  bool cleanup)
+{
+	int i, ret;
 
 	ret = init_symbol_maps(pevs->uprobes);
-	if (ret < 0) {
-		free(pkgs);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* Loop 1: convert all events */
 	for (i = 0; i < npevs; i++) {
-		pkgs[i].pev = &pevs[i];
 		/* Init kprobe blacklist if needed */
-		if (!pkgs[i].pev->uprobes)
+		if (pevs[i].uprobes)
 			kprobe_blacklist__init();
 		/* Convert with or without debuginfo */
-		ret  = convert_to_probe_trace_events(pkgs[i].pev,
-						     &pkgs[i].tevs);
-		if (ret < 0)
+		ret  = convert_to_probe_trace_events(&pevs[i], &pevs[i].tevs);
+		if (ret < 0) {
+			cleanup = true;
 			goto end;
-		pkgs[i].ntevs = ret;
+		}
+		pevs[i].ntevs = ret;
 	}
 	/* This just release blacklist only if allocated */
 	kprobe_blacklist__release();
 
 	/* Loop 2: add all events */
 	for (i = 0; i < npevs; i++) {
-		ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
-					       pkgs[i].ntevs,
+		ret = __add_probe_trace_events(&pevs[i], pevs[i].tevs,
+					       pevs[i].ntevs,
 					       probe_conf.force_add);
 		if (ret < 0)
 			break;
 	}
 end:
 	/* Loop 3: cleanup and free trace events  */
-	for (i = 0; i < npevs; i++) {
-		for (j = 0; j < pkgs[i].ntevs; j++)
-			clear_probe_trace_event(&pkgs[i].tevs[j]);
-		zfree(&pkgs[i].tevs);
-	}
-	free(pkgs);
+	for (i = 0; cleanup && (i < npevs); i++)
+		cleanup_perf_probe_event(&pevs[i]);
 	exit_symbol_maps();
 
 	return ret;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 31db6ee..4b7a951 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -86,6 +86,8 @@ struct perf_probe_event {
 	bool			uprobes;	/* Uprobe event flag */
 	char			*target;	/* Target binary */
 	struct perf_probe_arg	*args;	/* Arguments */
+	struct probe_trace_event *tevs;
+	int			ntevs;
 };
 
 /* Line range */
@@ -131,8 +133,10 @@ extern void line_range__clear(struct line_range *lr);
 /* Initialize line range */
 extern int line_range__init(struct line_range *lr);
 
-extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);
+extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
+				 bool cleanup);
 extern int del_perf_probe_events(struct strfilter *filter);
+extern int cleanup_perf_probe_event(struct perf_probe_event *pev);
 extern int show_perf_probe_events(struct strfilter *filter);
 extern int show_line_range(struct line_range *lr, const char *module,
 			   bool user);
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1180728 — [PATCH 09/39] bpf tools: Load eBPF programs in object files into kernel

FromWang Nan <wangnan0@huawei.com>
Date2015-07-09 14:50 +0200
Subject[PATCH 09/39] bpf tools: Load eBPF programs in object files into kernel
Message-ID<pKjr6-dD-73@gated-at.bofh.it>
In reply to#1180696
This patch utilizes previous introduced bpf_load_program to load
programs in the ELF file into kernel. Result is stored in 'fd' field in
'struct bpf_program'.

During loading, it allocs a log buffer and free it before return.  Note
that that buffer is not passed to bpf_load_program() if the first
loading try is successful. Doesn't use a statically allocated log buffer
to avoid potention multi-thread problem.

Instructions collected during opening is cleared after loading.

load_program() is created for loading a 'struct bpf_insn' array into
kernel, bpf_program__load() calls it. By this design we have a function
loads instructions into kernel. It will be used by further patches,
which creates different instances from a program and load them into
kernel.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: <acme@kernel.org>
Cc: <pi3orama@163.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/r/1435716878-189507-20-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/bpf/libbpf.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index cd40ae0..d826d5b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -96,6 +96,8 @@ struct bpf_program {
 		int map_idx;
 	} *reloc_desc;
 	int nr_reloc;
+
+	int fd;
 };
 
 struct bpf_object {
@@ -135,11 +137,20 @@ struct bpf_object {
 };
 #define obj_elf_valid(o)	((o)->efile.elf)
 
+static void bpf_program__unload(struct bpf_program *prog)
+{
+	if (!prog)
+		return;
+
+	zclose(prog->fd);
+}
+
 static void bpf_program__clear(struct bpf_program *prog)
 {
 	if (!prog)
 		return;
 
+	bpf_program__unload(prog);
 	zfree(&prog->section_name);
 	zfree(&prog->insns);
 	zfree(&prog->reloc_desc);
@@ -176,6 +187,7 @@ __bpf_program__new(void *data, size_t size, char *name, int idx,
 	memcpy(prog->insns, data,
 	       prog->insns_cnt * sizeof(struct bpf_insn));
 	prog->idx = idx;
+	prog->fd = -1;
 
 	return 0;
 errout:
@@ -721,6 +733,79 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
 	return 0;
 }
 
+static int
+load_program(struct bpf_insn *insns, int insns_cnt,
+	     char *license, u32 kern_version, int *pfd)
+{
+	int ret;
+	char *log_buf;
+
+	if (!insns || !insns_cnt)
+		return -EINVAL;
+
+	log_buf = malloc(BPF_LOG_BUF_SIZE);
+	if (!log_buf)
+		pr_warning("Alloc log buffer for bpf loader error, continue without log\n");
+
+	ret = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns,
+			       insns_cnt, license, kern_version,
+			       log_buf, BPF_LOG_BUF_SIZE);
+
+	if (ret >= 0) {
+		*pfd = ret;
+		ret = 0;
+		goto out;
+	}
+
+	ret = -EINVAL;
+	pr_warning("load bpf program failed: %s\n", strerror(errno));
+
+	if (log_buf) {
+		pr_warning("-- BEGIN DUMP LOG ---\n");
+		pr_warning("\n%s\n", log_buf);
+		pr_warning("-- END LOG --\n");
+	}
+
+out:
+	free(log_buf);
+	return ret;
+}
+
+static int
+bpf_program__load(struct bpf_program *prog,
+		  char *license, u32 kern_version)
+{
+	int err, fd;
+
+	err = load_program(prog->insns, prog->insns_cnt,
+			   license, kern_version, &fd);
+	if (!err)
+		prog->fd = fd;
+
+	if (err)
+		pr_warning("failed to load program '%s'\n",
+			   prog->section_name);
+	zfree(&prog->insns);
+	prog->insns_cnt = 0;
+	return err;
+}
+
+static int
+bpf_object__load_progs(struct bpf_object *obj)
+{
+	size_t i;
+	int err;
+
+	for (i = 0; i < obj->nr_programs; i++) {
+		err = bpf_program__load(&obj->programs[i],
+					obj->license,
+					obj->kern_version);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
 static int bpf_object__validate(struct bpf_object *obj)
 {
 	if (obj->kern_version == 0) {
@@ -798,6 +883,9 @@ int bpf_object__unload(struct bpf_object *obj)
 	zfree(&obj->map_fds);
 	obj->nr_map_fds = 0;
 
+	for (i = 0; i < obj->nr_programs; i++)
+		bpf_program__unload(&obj->programs[i]);
+
 	return 0;
 }
 
@@ -816,6 +904,8 @@ int bpf_object__load(struct bpf_object *obj)
 		goto out;
 	if (bpf_object__relocate(obj))
 		goto out;
+	if (bpf_object__load_progs(obj))
+		goto out;
 
 	return 0;
 out:
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1180730 — [PATCH 37/39] perf record: Support custom vmlinux path

FromWang Nan <wangnan0@huawei.com>
Date2015-07-09 14:50 +0200
Subject[PATCH 37/39] perf record: Support custom vmlinux path
Message-ID<pKjr6-dD-77@gated-at.bofh.it>
In reply to#1180696
From: He Kuang <hekuang@huawei.com>

Make perf-record command support --vmlinux option if BPF_PROLOGUE is on.

'perf record' needs vmlinux as the source of DWARF info to generate
prologue for BPF programs, so path of vmlinux should be specified.

Short name 'k' has been taken by 'clockid'. This patch skips the short
option name and use '--vmlinux' for vmlinux path.

Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
 tools/perf/builtin-record.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e89c045..e613f2e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1079,6 +1079,10 @@ struct option __record_options[] = {
 		   "clang binary to use for compiling BPF scriptlets"),
 	OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options",
 		   "options passed to clang when compiling BPF scriptlets"),
+#ifdef HAVE_BPF_PROLOGUE
+	OPT_STRING(0, "vmlinux", &symbol_conf.vmlinux_name,
+		   "file", "vmlinux pathname"),
+#endif
 #endif
 	OPT_END()
 };
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1183792 — perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-07-14 17:40 +0200
Subjectperf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs
Message-ID<pMatk-4pB-35@gated-at.bofh.it>
In reply to#1180696
Em Thu, Jul 09, 2015 at 12:35:03PM +0000, Wang Nan escreveu:
> Hi Arnaldo,
> 
> The following changes since commit 3381a29cbec5447086c0f726ee9a88c02e60becc:
> 
>   bpf tools: Collect map definitions from 'maps' section (2015-07-07 13:41:45 -0300)
> 
> are available in the git repository at:
> 
>   https://github.com/WangNan0/linux.git perf/ebpf-for-acme
> 
> for you to fetch changes up to 072b826c5dc6b2031f4f21c59c57eb6ca1dfa7c0:

So, this is really nice:

38: Test LLVM searching and compiling                        :ERROR:	unable to find clang.
Hint:	Try to install latest clang/llvm to support BPF. Check your $PATH
     	and 'clang-path' option in [llvm] section of ~/.perfconfig.
     	LLVM 3.7 or newer is required. Which can be found from http://llvm.org
     	You may want to try git trunk:
     		git clone http://llvm.org/git/llvm.git
     		     and
     		git clone http://llvm.org/git/clang.git

     	Or fetch the latest clang/llvm 3.7 from pre-built llvm packages for
     	debian/ubuntu:
     		http://llvm.org/apt

     	If you are using old version of clang, change 'clang-bpf-cmd-template'
     	option in [llvm] section of ~/.perfconfig to:

     	  "$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \
     	     -working-directory $WORKING_DIR -c $CLANG_SOURCE \
     	     -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -"
     	(Replace /path/to/llc with path to your llc)

 FAILED!
[acme@zoo linux]$ 

I have the trees cloned and plan to follow these instructions to have this test
passing, to then move on to the next patches, but one request, please change
the above to produce:

38: Test LLVM searching and compiling                        :(no clang) Ok	run 'perf test -v LLVM' for instructions on having a clang environment

'perf test' will accept either '38' or any substring in the test description and
will run just the ones specified, and with -v we will spare people not interested
in this eBPF support of these nice verbose instructions :-)

If we find clang but then fail to build, ok, then this is a hard error, I think,
and 'perf test' should FAIL that test.

Regards,

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1184687 — Re: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs

From"Wangnan (F)" <wangnan0@huawei.com>
Date2015-07-15 13:10 +0200
SubjectRe: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs
Message-ID<pMsJz-5F0-1@gated-at.bofh.it>
In reply to#1183792

On 2015/7/14 23:36, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jul 09, 2015 at 12:35:03PM +0000, Wang Nan escreveu:
>> Hi Arnaldo,
>>
>> The following changes since commit 3381a29cbec5447086c0f726ee9a88c02e60becc:
>>
>>    bpf tools: Collect map definitions from 'maps' section (2015-07-07 13:41:45 -0300)
>>
>> are available in the git repository at:
>>
>>    https://github.com/WangNan0/linux.git perf/ebpf-for-acme
>>
>> for you to fetch changes up to 072b826c5dc6b2031f4f21c59c57eb6ca1dfa7c0:
> So, this is really nice:
>
> 38: Test LLVM searching and compiling                        :ERROR:	unable to find clang.
> Hint:	Try to install latest clang/llvm to support BPF. Check your $PATH
>       	and 'clang-path' option in [llvm] section of ~/.perfconfig.
>       	LLVM 3.7 or newer is required. Which can be found from http://llvm.org
>       	You may want to try git trunk:
>       		git clone http://llvm.org/git/llvm.git
>       		     and
>       		git clone http://llvm.org/git/clang.git
>
>       	Or fetch the latest clang/llvm 3.7 from pre-built llvm packages for
>       	debian/ubuntu:
>       		http://llvm.org/apt
>
>       	If you are using old version of clang, change 'clang-bpf-cmd-template'
>       	option in [llvm] section of ~/.perfconfig to:
>
>       	  "$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \
>       	     -working-directory $WORKING_DIR -c $CLANG_SOURCE \
>       	     -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -"
>       	(Replace /path/to/llc with path to your llc)
>
>   FAILED!
> [acme@zoo linux]$
>
> I have the trees cloned and plan to follow these instructions to have this test
> passing, to then move on to the next patches, but one request, please change
> the above to produce:
>
> 38: Test LLVM searching and compiling                        :(no clang) Ok	run 'perf test -v LLVM' for instructions on having a clang environment

The output format you desire is hard to implement, because 'Ok' is printed
by the parent process. We have to find a way to allow child process to pass
'run 'perf test -v LLVM' for ...' to parent, then parent can print it
after 'Ok'.

I change this test as follow:


*Case 1*
When user don't set any [llvm] option in his/her ~/.perfconfig, and 'clang'
is not found in $PATH:

# perf test 'LLVM'
38: Test LLVM searching and compiling                        : (no 
clang, try 'perf test -v LLVM') Skip

and:

# perf test -v 'LLVM'
38: Test LLVM searching and compiling                        :
--- start ---
test child forked, pid 163505
ERROR:    unable to find clang.
Hint:    Try to install latest clang/llvm to support BPF. Check your $PATH
...

test child finished with -1
---- end ----
Test LLVM searching and compiling: FAILED!

*Case 2*

If clang can be found or user set something in his/her ~/.perfconfig:
# cat << EOF > ~/.perfconfig
 > [llvm]
 > clang-path = "/usr/bin/false"
 > EOF
# perf test 'LLVM'
38: Test LLVM searching and compiling                        : (use -v 
to see error message) FAILED!

# perf test -v 'LLVM'
38: Test LLVM searching and compiling                        :
--- start ---
test child forked, pid 20712
Kernel build dir is set to /lib/modules/3.12.28-4-default/build
set env: KBUILD_DIR=/lib/modules/3.12.28-4-default/build
...
ERROR:    unable to compile -
Hint:    Check error message shown above.
          LLVM 3.7 or newer is required. Which can be found from 
http://llvm.org
...
test child finished with -1
---- end ----
Test LLVM searching and compiling: FAILED!

*Case 3*
If everything is okay:
# perf test 'LLVM'
38: Test LLVM searching and compiling                        : Ok

Here is the newest pull request:

The following changes since commit 101ef9b4f5c70dbfffa0186102c1014bd81a4ec7:

   bpf tools: Link all bpf objects onto a list (2015-07-13 18:48:17 -0300)

are available in the git repository at:

   https://github.com/WangNan0/linux.git perf/ebpf-for-acme

for you to fetch changes up to a20f387a54aa38c3cae70775273ff9d69a16d0c6:

   perf tools: Support attach BPF program on uprobe events (2015-07-15 
10:39:24 +0000)

----------------------------------------------------------------

I'll posted a new 'perf tests: Add LLVM test for eBPF on-the-fly 
compiling' by replying
the old one, so you can leave your comment message there if you want.

Thank you.

> 'perf test' will accept either '38' or any substring in the test description and
> will run just the ones specified, and with -v we will spare people not interested
> in this eBPF support of these nice verbose instructions :-)
>
> If we find clang but then fail to build, ok, then this is a hard error, I think,
> and 'perf test' should FAIL that test.
>
> Regards,
>
> - Arnaldo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1184701 — Re: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-07-15 13:30 +0200
SubjectRe: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs
Message-ID<pMt2W-62p-5@gated-at.bofh.it>
In reply to#1184687
Em Wed, Jul 15, 2015 at 06:49:40PM +0800, Wangnan (F) escreveu:
> On 2015/7/14 23:36, Arnaldo Carvalho de Melo wrote:
> >I have the trees cloned and plan to follow these instructions to have this test
> >passing, to then move on to the next patches, but one request, please change
> >the above to produce:

> >38: Test LLVM searching and compiling                        :(no clang) Ok	run 'perf test -v LLVM' for instructions on having a clang environment

> The output format you desire is hard to implement, because 'Ok' is printed
> by the parent process. We have to find a way to allow child process to pass
> 'run 'perf test -v LLVM' for ...' to parent, then parent can print it
> after 'Ok'.
 
> I change this test as follow:

From a quick look: excellent, thanks for improving this, I downloaded
llvm and clang, built it, and the test passes, will apply this new patch
and continue from there,

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | linux.kernel


csiph-web