From patchwork Wed Apr 20 18:01:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 66241 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2596017qge; Wed, 20 Apr 2016 11:04:24 -0700 (PDT) X-Received: by 10.98.13.77 with SMTP id v74mr14217731pfi.162.1461175464142; Wed, 20 Apr 2016 11:04:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si19013551pfb.112.2016.04.20.11.04.23; Wed, 20 Apr 2016 11:04:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752434AbcDTSCi (ORCPT + 29 others); Wed, 20 Apr 2016 14:02:38 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:22018 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752378AbcDTSCg (ORCPT ); Wed, 20 Apr 2016 14:02:36 -0400 Received: from 172.24.1.50 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.50]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DFS43773; Thu, 21 Apr 2016 02:02:18 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Thu, 21 Apr 2016 02:02:07 +0800 From: Wang Nan To: , , CC: , , Wang Nan , Arnaldo Carvalho de Melo , "Alexei Starovoitov" , Jiri Olsa , Li Zefan Subject: [RFC PATCH 11/13] perf bpf: Accept ubpf programs Date: Wed, 20 Apr 2016 18:01:51 +0000 Message-ID: <1461175313-38310-12-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> References: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.5717C42B.005A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: a096aed917b1775759225a3d3415cc68 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/perf/util/bpf-loader.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- 1.8.3.4 diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 493307d..20a0370 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"); @@ -607,6 +620,9 @@ int bpf__probe(struct bpf_object *obj) if (err) goto out; + if (bpf_program__is_ubpf(prog)) + continue; + err = bpf_program__get_private(prog, (void **)&priv); if (err || !priv) goto out; @@ -650,6 +666,9 @@ int bpf__unprobe(struct bpf_object *obj) bpf_object__for_each_program(prog, obj) { int i; + if (bpf_program__is_ubpf(prog)) + continue; + err = bpf_program__get_private(prog, (void **)&priv); if (err || !priv) continue; @@ -707,6 +726,9 @@ int bpf__foreach_tev(struct bpf_object *obj, struct bpf_prog_priv *priv; int i, fd; + if (bpf_program__is_ubpf(prog)) + continue; + err = bpf_program__get_private(prog, (void **)&priv); if (err || !priv) {