Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757528AbbEEKLf (ORCPT ); Tue, 5 May 2015 06:11:35 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:4094 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757471AbbEEKK5 (ORCPT ); Tue, 5 May 2015 06:10:57 -0400 From: He Kuang To: , , , , , , CC: , , , Subject: [RFC PATCH 6/6] perf bpf: Generate bpf prologue for arguments Date: Tue, 5 May 2015 10:10:12 +0000 Message-ID: <1430820612-84443-7-git-send-email-hekuang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1430820612-84443-1-git-send-email-hekuang@huawei.com> References: <1430820612-84443-1-git-send-email-hekuang@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.5548972D.027D,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: 1cf37911922452311e7f83e25df0ca49 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2380 Lines: 101 Generate bpf prologue before attaching bpf progs to perf probe event. If prologue is generated, it will be pasted in front of the original bpf prog. Signed-off-by: He Kuang --- tools/perf/util/bpf-loader.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index c646ca4..8c746ef 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -900,6 +900,69 @@ bpf_perf_prog_load(struct bpf_obj *obj, struct bpf_perf_prog *prog) return 0; } +#ifdef HAVE_DWARF_SUPPORT +#if 0 +static void show_bpf_insn(char *buf, int len) +{ + int i, j; + char *ptr = buf; + + for (i = 0; i < len; i++) { + pr_debug("[%03d] ", i); + for (j = 0; j < 8; j++) + pr_debug("0x%02x, ", (*ptr++) & 0xff); + pr_debug("\\\n"); + } +} +#endif + +static int bpf_obj_prologue(struct bpf_obj *obj) +{ + struct bpf_perf_prog *prog; + int ret = -1; + + list_for_each_entry(prog, &obj->progs_list, list) { + int count; + char *result; + int new_count; + + if (!prog->pev) + continue; + + ret = get_bpf_prologue(prog->pev, &result, &count); + if (ret) + return ret; + + if (count > 0) { + bpf_dump_prog((struct bpf_insn *)result, count); + + new_count = prog->insns_cnt + count; + result = realloc(result, + new_count * sizeof(struct bpf_insn)); + if (!result) + return -ENOMEM; + + memcpy(result + count * sizeof(struct bpf_insn), + prog->insns, + prog->insns_cnt * sizeof(struct bpf_insn)); + + free(prog->insns); + prog->insns = (struct bpf_insn *)result; + prog->insns_cnt = new_count; + } else { + pr_debug("bpf: no prologue generated\n"); + } + } + + return ret; +} +#else +static int bpf_progs_prologue(struct bpf_obj *obj __maybe_unused) +{ + return 0; +} +#endif + static int bpf_obj_load_progs(struct bpf_obj *obj) { @@ -946,6 +1009,9 @@ int bpf__load(const char *path) goto out; if ((err = bpf_obj_relocate(obj))) goto out; + err = bpf_obj_prologue(obj); + if (err) + goto out; if ((err = bpf_obj_load_progs(obj))) goto out; -- 1.8.5.2 -- 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/