Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751818AbbD3Kxu (ORCPT ); Thu, 30 Apr 2015 06:53:50 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:14324 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751257AbbD3Kxd (ORCPT ); Thu, 30 Apr 2015 06:53:33 -0400 From: Wang Nan To: , , , , , , CC: , , , Subject: [RFC PATCH 09/22] perf bpf: collect map definitions. Date: Thu, 30 Apr 2015 10:52:32 +0000 Message-ID: <1430391165-30267-10-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1430391165-30267-1-git-send-email-wangnan0@huawei.com> References: <1430391165-30267-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.210] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.554209AA.00DD,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 78df833ee27b109838956668c7ee0ff5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2786 Lines: 99 If maps are used by eBPF programs, corresponding object file(s) should contain a section named 'map'. Which contains map definitions, one for each map to describe its format. 'struct perf_bpf_map_def' is introduced as part of protocol between perf and eBPF programs. All map definitions are copied to obj->maps. bpf.h is introduced for common bpf operations. Signed-off-by: Wang Nan --- tools/perf/util/bpf-loader.c | 31 +++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 296fb06..bf3b793 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -65,6 +65,8 @@ static void bpf_obj_close(struct bpf_obj *obj) if (obj->path) free(obj->path); + if (obj->maps) + free(obj->maps); free(obj); } @@ -183,6 +185,32 @@ static int bpf_obj_kver_init(struct bpf_obj *obj, return 0; } +static int bpf_obj_maps_init(struct bpf_obj *obj, void *data, + size_t size) +{ + size_t map_def_sz = sizeof(struct bpf_map_def); + int nr_maps = size / map_def_sz; + + if (nr_maps == 0) { + pr_debug("bpf: %s doesn't need map definition\n", + obj->path); + return 0; + } + + obj->maps = malloc(nr_maps * map_def_sz); + if (!obj->maps) { + pr_err("bpf: malloc maps failed: %s\n", obj->path); + return -ENOMEM; + } + + obj->nr_maps = nr_maps; + memcpy(obj->maps, data, nr_maps * map_def_sz); + pr_debug("bpf: %d map%s in %s\n", nr_maps, + nr_maps > 1 ? "s" : "", + obj->path); + return 0; +} + static int bpf_obj_elf_collect(struct bpf_obj *obj) { Elf *elf = obj->elf.elf; @@ -237,6 +265,9 @@ static int bpf_obj_elf_collect(struct bpf_obj *obj) else if (strcmp(name, "version") == 0) err = bpf_obj_kver_init(obj, data->d_buf, data->d_size); + else if (strcmp(name, "maps") == 0) + err = bpf_obj_maps_init(obj, data->d_buf, + data->d_size); if (err) goto out; } diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index e1d5c42..6c5c8d6 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -14,6 +14,7 @@ #include "perf.h" #include "symbol.h" #include "probe-event.h" +#include "bpf.h" int bpf__load(const char *path); int bpf__run(void); @@ -25,6 +26,8 @@ struct bpf_obj { bool needs_swap; char license[64]; u32 kern_version; + struct bpf_map_def *maps; + size_t nr_maps; /* * Information when doing elf related work. Only valid if fd -- 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/