Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751702AbbD3Kxi (ORCPT ); Thu, 30 Apr 2015 06:53:38 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:14370 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751271AbbD3Kxd (ORCPT ); Thu, 30 Apr 2015 06:53:33 -0400 From: Wang Nan To: , , , , , , CC: , , , Subject: [RFC PATCH 10/22] perf bpf: collect config section in object. Date: Thu, 30 Apr 2015 10:52:33 +0000 Message-ID: <1430391165-30267-11-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.554209AB.0089,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: c542db5f4b68f42c4a7f2d3927281dfb Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3380 Lines: 119 eBPF programs are allowed to include 'config' sections, which contain strings describe each bpf program. Config strings have identical format as 'perf probe' defined. They describe positions and arguments used by bpf programs. Defining config strings separatly is allowed. For example: #define SEC(NAME) __attribute__((section(NAME), used)) char _bpf_prog1_config[] SEC("config") = "bpf_prog1=kmem_cache_free%return"; SEC("bpf_prog1") int bpf_prog1(struct pt_rets *ctx) { .... } char _bpf_prog2_config[] SEC("config") = "bpf_prog2=kmem_cache_free"; SEC("bpf_prog2") int bpf_prog2(struct pt_rets *ctx) { .... } char other_config[] SEC("config") = "bpf_prog3=kmem_cache_alloc\n" "bpf_prog4=__alloc_pages_nodemask%return"; To make further processing easiler, this patch converts '\0' in the whole config strings into '\n' Signed-off-by: Wang Nan --- tools/perf/util/bpf-loader.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 1 + 2 files changed, 45 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index bf3b793..b913d6f 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -67,6 +67,8 @@ static void bpf_obj_close(struct bpf_obj *obj) free(obj->path); if (obj->maps) free(obj->maps); + if (obj->config_str) + free(obj->config_str); free(obj); } @@ -211,6 +213,45 @@ static int bpf_obj_maps_init(struct bpf_obj *obj, void *data, return 0; } +static int bpf_obj_config_init(struct bpf_obj *obj, void *data, + size_t size) +{ + char *config_str; + char *p, *pend; + + if (size == 0) { + pr_debug("bpf: config section in %s empty\n", + obj->path); + return 0; + } + if (obj->config_str) { + pr_err("bpf: multiple config section in %s\n", + obj->path); + return -EEXIST; + } + + config_str = malloc(size + 1); + if (!config_str) { + pr_err("bpf: malloc config string failed\n"); + return -ENOMEM; + } + + memcpy(config_str, data, size); + + /* + * It is possible that config section contains multiple + * Make it a big string by converting all '\0' to '\n' and + * append final '\0'. + */ + pend = config_str + size; + for (p = config_str; p < pend; p++) + *p == '\0' ? *p = '\n' : 0 ; + *pend = '\0'; + + obj->config_str = config_str; + return 0; +} + static int bpf_obj_elf_collect(struct bpf_obj *obj) { Elf *elf = obj->elf.elf; @@ -268,6 +309,9 @@ static int bpf_obj_elf_collect(struct bpf_obj *obj) else if (strcmp(name, "maps") == 0) err = bpf_obj_maps_init(obj, data->d_buf, data->d_size); + else if (strcmp(name, "config") == 0) + err = bpf_obj_config_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 6c5c8d6..086f28d 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -28,6 +28,7 @@ struct bpf_obj { u32 kern_version; struct bpf_map_def *maps; size_t nr_maps; + char *config_str; /* * 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/