mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: He Kuang <hekuang@huawei.com>
To: <ast@plumgrid.com>, <davem@davemloft.net>, <acme@kernel.org>,
	<mingo@redhat.com>, <a.p.zijlstra@chello.nl>,
	<masami.hiramatsu.pt@hitachi.com>, <jolsa@kernel.org>
Cc: <wangnan0@huawei.com>, <lizefan@kernel.org>,
	<linux-kernel@vger.kernel.org>, <pi3orama@163.com>
Subject: [RFC PATCH 6/6] perf bpf: Generate bpf prologue for arguments
Date: Tue, 5 May 2015 10:10:12 +0000	[thread overview]
Message-ID: <1430820612-84443-7-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1430820612-84443-1-git-send-email-hekuang@huawei.com>

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 <hekuang@huawei.com>
---
 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


  parent reply	other threads:[~2015-05-05 10:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-05 10:10 [RFC PATCH 0/6] perf bpf: Probing with local variable He Kuang
2015-05-05 10:10 ` [RFC PATCH 1/6] perf bpf: Add headers for generate bpf bytecode He Kuang
2015-05-05 22:38   ` Alexei Starovoitov
2015-05-05 10:10 ` [RFC PATCH 2/6] perf bpf: Add pt_regs convert table for x86 He Kuang
2015-05-05 22:44   ` Alexei Starovoitov
2015-05-08  8:02   ` Masami Hiramatsu
2015-05-05 10:10 ` [RFC PATCH 3/6] perf bpf: Save pt_regs info from debuginfo He Kuang
2015-05-05 10:10 ` [RFC PATCH 4/6] perf bpf: Convert arglist to bpf prologue He Kuang
2015-05-05 22:54   ` Alexei Starovoitov
2015-05-05 10:10 ` [RFC PATCH 5/6] perf bpf: Process debuginfo for generating " He Kuang
2015-05-05 10:10 ` He Kuang [this message]
2015-05-05 22:31 ` [RFC PATCH 0/6] perf bpf: Probing with local variable Alexei Starovoitov
2015-05-06  3:58   ` Wang Nan
2015-05-06  4:10     ` Alexei Starovoitov
2015-05-06  4:41       ` Wang Nan
2015-05-06  1:37 ` Masami Hiramatsu
2015-05-06  1:44   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430820612-84443-7-git-send-email-hekuang@huawei.com \
    --to=hekuang@huawei.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=ast@plumgrid.com \
    --cc=davem@davemloft.net \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=pi3orama@163.com \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®