Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932816AbbHHIPd (ORCPT ); Sat, 8 Aug 2015 04:15:33 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53792 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754345AbbHHIOj (ORCPT ); Sat, 8 Aug 2015 04:14:39 -0400 Date: Sat, 8 Aug 2015 01:11:56 -0700 From: tip-bot for Wang Nan Message-ID: Cc: ast@plumgrid.com, brendan.d.gregg@gmail.com, xiakaixu@huawei.com, a.p.zijlstra@chello.nl, hekuang@huawei.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@kernel.org, lizefan@huawei.com, mingo@kernel.org, hpa@zytor.com, acme@redhat.com, linux-kernel@vger.kernel.org, masami.hiramatsu.pt@hitachi.com, dsahern@gmail.com, wangnan0@huawei.com, daniel@iogearbox.net Reply-To: namhyung@kernel.org, lizefan@huawei.com, jolsa@kernel.org, mingo@kernel.org, brendan.d.gregg@gmail.com, ast@plumgrid.com, hekuang@huawei.com, a.p.zijlstra@chello.nl, xiakaixu@huawei.com, tglx@linutronix.de, masami.hiramatsu.pt@hitachi.com, dsahern@gmail.com, wangnan0@huawei.com, daniel@iogearbox.net, acme@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org In-Reply-To: <1435716878-189507-11-git-send-email-wangnan0@huawei.com> References: <1435716878-189507-11-git-send-email-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] bpf tools: Collect map definitions from 'maps' section Git-Commit-ID: 0b3d1efade1b7e2ccaf79c40a7481c93cfb5090a X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3126 Lines: 98 Commit-ID: 0b3d1efade1b7e2ccaf79c40a7481c93cfb5090a Gitweb: http://git.kernel.org/tip/0b3d1efade1b7e2ccaf79c40a7481c93cfb5090a Author: Wang Nan AuthorDate: Wed, 1 Jul 2015 02:13:58 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 7 Aug 2015 10:16:57 -0300 bpf tools: Collect map definitions from 'maps' section If maps are used by eBPF programs, corresponding object file(s) should contain a section named 'map'. Which contains map definitions. This patch copies the data of the whole section. Map data parsing should be acted just before map loading. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1435716878-189507-11-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 95c8d8e..87f5054 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -81,6 +81,9 @@ void libbpf_set_print(libbpf_print_fn_t warn, struct bpf_object { char license[64]; u32 kern_version; + void *maps_buf; + size_t maps_buf_sz; + /* * Information when doing elf related work. Only valid if fd * is valid. @@ -250,6 +253,28 @@ bpf_object__init_kversion(struct bpf_object *obj, return 0; } +static int +bpf_object__init_maps(struct bpf_object *obj, void *data, + size_t size) +{ + if (size == 0) { + pr_debug("%s doesn't need map definition\n", + obj->path); + return 0; + } + + obj->maps_buf = malloc(size); + if (!obj->maps_buf) { + pr_warning("malloc maps failed: %s\n", obj->path); + return -ENOMEM; + } + + obj->maps_buf_sz = size; + memcpy(obj->maps_buf, data, size); + pr_debug("maps in %s: %ld bytes\n", obj->path, (long)size); + return 0; +} + static int bpf_object__elf_collect(struct bpf_object *obj) { Elf *elf = obj->efile.elf; @@ -305,6 +330,9 @@ static int bpf_object__elf_collect(struct bpf_object *obj) err = bpf_object__init_kversion(obj, data->d_buf, data->d_size); + else if (strcmp(name, "maps") == 0) + err = bpf_object__init_maps(obj, data->d_buf, + data->d_size); if (err) goto out; } @@ -382,5 +410,6 @@ void bpf_object__close(struct bpf_object *obj) bpf_object__elf_finish(obj); + zfree(&obj->maps_buf); free(obj); } -- 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/