From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752574AbcFZLWM (ORCPT ); Sun, 26 Jun 2016 07:22:12 -0400 Received: from szxga04-in.huawei.com ([58.251.152.52]:21224 "EHLO szxga04-in.huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752337AbcFZLWE (ORCPT ); Sun, 26 Jun 2016 07:22:04 -0400 From: He Kuang To: , , , , , , , , CC: Subject: [RFC PATCH v2 20/26] perf bpf: Accept uBPF programs Date: Sun, 26 Jun 2016 11:21:12 +0000 Message-ID: <1466940078-65581-21-git-send-email-hekuang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1466940078-65581-1-git-send-email-hekuang@huawei.com> References: <1466940078-65581-1-git-send-email-hekuang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.576FBACF.0056,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 12fb24111bb3bb4079beb424653a680d Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan This patch allows user passing a uBPF function through bpf file with section name leading with 'UBPF;'. For example: #define SEC(NAME) __attribute__((section(NAME), used)) SEC("UBPF;perf_record_exit") void record_exit(int *samples) { char fmt[] = "Hello! receive %d samples\n"; ubpf_printf(fmt, *samples); } Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Jiri Olsa Cc: Li Zefan Signed-off-by: He Kuang --- tools/perf/util/bpf-loader.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 2ac73e3..288b941 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -305,6 +305,19 @@ config_bpf_program(struct bpf_program *prog) return PTR_ERR(config_str); } + if (strncmp(config_str, "UBPF;", 5) == 0) { + pr_debug("bpf: load a UBPF program %s\n", config_str); + err = bpf_program__set_ubpf(prog); + if (err) { + char errbuf[BUFSIZ]; + + libbpf_strerror(err, errbuf, sizeof(errbuf)); + pr_warning("Set %s to ubpf failed: %s\n", config_str, errbuf); + return err; + } + return 0; + } + priv = calloc(sizeof(*priv), 1); if (!priv) { pr_debug("bpf: failed to alloc priv\n"); @@ -604,6 +617,9 @@ int bpf__probe(struct bpf_object *obj) if (err) goto out; + if (bpf_program__is_ubpf(prog)) + continue; + priv = bpf_program__priv(prog); if (IS_ERR(priv) || !priv) { err = PTR_ERR(priv); @@ -649,6 +665,9 @@ int bpf__unprobe(struct bpf_object *obj) struct bpf_prog_priv *priv = bpf_program__priv(prog); int i; + if (bpf_program__is_ubpf(prog)) + continue; + if (IS_ERR(priv) || !priv) continue; @@ -705,6 +724,9 @@ int bpf__foreach_tev(struct bpf_object *obj, struct perf_probe_event *pev; int i, fd; + if (bpf_program__is_ubpf(prog)) + continue; + if (IS_ERR(priv) || !priv) { pr_debug("bpf: failed to get private field\n"); return -BPF_LOADER_ERRNO__INTERNAL; -- 1.8.5.2