From patchwork Wed Sep 23 11:22:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54033 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 4C16E22E14 for ; Wed, 23 Sep 2015 11:23:56 +0000 (UTC) Received: by wisv5 with SMTP id v5sf22778140wis.0 for ; Wed, 23 Sep 2015 04:23:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=9uJ7tf9uD0LvC8kfxvSGnAVJysTtdvhGBrQj+0RQBc0=; b=fOJ73aY5Qu3JlkYSkAhOEojOFQ9ZCijiIFq/G/iAbZ7pX16UD7wa3udRJHJtYl/gDB 9Wg8FO9jktAecYj/DWD6Ms1pcN+4wajOnJ5hZtcx7bUtrJIbxFyZ3ictRI5LjgV2jeTc Ag6gdGmkY1i8M3fCkcuSwQEAqaydAcyYXW8C8Wbzi2E2rSI8RL/rbL4f7T/3JqYJf//y s+pm1lbG/koi4SPFWLv3EjYjQu7OIEOq/A4i5Cw9XJFREVOXIgynJkS5TsK6TCUp/KuV JCdddAxMJfIQhOjYfcX4ZuXFhkJ75roB6R4yS+rRM79CVCq8faVfJGuoeIjT1PCmXha3 w0MQ== X-Gm-Message-State: ALoCoQnKoQwtum+qF3CvPIKwkyUIy+WtkTSlD/ZivmZqoI3wA9XN9rrDBLe5T2eaRAqWD9LVtVNe X-Received: by 10.112.12.132 with SMTP id y4mr5176339lbb.0.1443007435531; Wed, 23 Sep 2015 04:23:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.66 with SMTP id x2ls49734laa.107.gmail; Wed, 23 Sep 2015 04:23:55 -0700 (PDT) X-Received: by 10.112.51.142 with SMTP id k14mr9493188lbo.76.1443007435367; Wed, 23 Sep 2015 04:23:55 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id d5si3506183lah.47.2015.09.23.04.23.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2015 04:23:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lahg1 with SMTP id g1so46372906lah.1 for ; Wed, 23 Sep 2015 04:23:55 -0700 (PDT) X-Received: by 10.25.210.206 with SMTP id j197mr3754946lfg.86.1443007435192; Wed, 23 Sep 2015 04:23:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1043243lbq; Wed, 23 Sep 2015 04:23:54 -0700 (PDT) X-Received: by 10.67.4.9 with SMTP id ca9mr8733447pad.90.1443007430838; Wed, 23 Sep 2015 04:23:50 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kb6si9923551pad.33.2015.09.23.04.23.50; Wed, 23 Sep 2015 04:23:50 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754443AbbIWLXo (ORCPT + 30 others); Wed, 23 Sep 2015 07:23:44 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:56802 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754362AbbIWLXl (ORCPT ); Wed, 23 Sep 2015 07:23:41 -0400 Received: from 172.24.1.48 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BNW12490; Wed, 23 Sep 2015 19:23:07 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Wed, 23 Sep 2015 19:22:58 +0800 From: Wang Nan To: CC: , , Wang Nan , Alexei Starovoitov , Brendan Gregg , Daniel Borkmann , "David Ahern" , He Kuang , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , "Paul Mackerras" , Peter Zijlstra , Zefan Li Subject: [PATCH 04/22] perf record: Load eBPF object into kernel Date: Wed, 23 Sep 2015 11:22:25 +0000 Message-ID: <1443007363-124182-5-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1443007363-124182-1-git-send-email-wangnan0@huawei.com> References: <1443007363-124182-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.0A010202.56028B9C.0047, 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: ff431d9e7d38699dc4c60758f50ad788 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch utilizes bpf_object__load() provided by libbpf to load all objects into kernel. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Cc: Arnaldo Carvalho de Melo Link: http://lkml.kernel.org/n/ebpf-6yw9eg0ej3l4jnqhinngkw86@git.kernel.org --- tools/perf/util/bpf-loader.c | 22 ++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 11 +++++++++++ tools/perf/util/parse-events.c | 6 ++++++ 3 files changed, 39 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 1a10b6c..39732a4 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -242,6 +242,18 @@ int bpf__unprobe(struct bpf_object *obj) return ret; } +int bpf__load(struct bpf_object *obj) +{ + int err; + + err = bpf_object__load(obj); + if (err) { + pr_debug("bpf: load objects failed\n"); + return err; + } + return 0; +} + #define bpf__strerror_head(err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\ @@ -274,3 +286,13 @@ int bpf__strerror_probe(struct bpf_object *obj __maybe_unused, bpf__strerror_end(buf, size); return 0; } + +int bpf__strerror_load(struct bpf_object *obj __maybe_unused, + int err, char *buf, size_t size) +{ + bpf__strerror_head(err, buf, size); + bpf__strerror_entry(EINVAL, "%s: Are you root and runing a CONFIG_BPF_SYSCALL kernel?", + emsg) + bpf__strerror_end(buf, size); + return 0; +} diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index b819622..b091ceb 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -23,6 +23,9 @@ int bpf__unprobe(struct bpf_object *obj); int bpf__strerror_probe(struct bpf_object *obj, int err, char *buf, size_t size); +int bpf__load(struct bpf_object *obj); +int bpf__strerror_load(struct bpf_object *obj, int err, + char *buf, size_t size); #else static inline struct bpf_object * bpf__prepare_load(const char *filename __maybe_unused) @@ -35,6 +38,7 @@ static inline void bpf__clear(void) { } static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} +static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } static inline int __bpf_strerror(char *buf, size_t size) @@ -55,5 +59,12 @@ bpf__strerror_probe(struct bpf_object *obj __maybe_unused, { return __bpf_strerror(buf, size); } + +static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, + int err __maybe_unused, + char *buf, size_t size) +{ + return __bpf_strerror(buf, size); +} #endif #endif diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 354da59..a7152f3 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -542,6 +542,12 @@ int parse_events_load_bpf_obj(struct parse_events_evlist *data, registered_unprobe_atexit = true; } + err = bpf__load(obj); + if (err) { + bpf__strerror_load(obj, err, errbuf, sizeof(errbuf)); + goto errout; + } + /* * Temporary add a dummy event here so we can check whether * basic bpf loader works. Will be removed in following patch.