From patchwork Thu Oct 8 08:29:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54631 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 96EC622FF8 for ; Thu, 8 Oct 2015 08:34:02 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf6740524wic.3 for ; Thu, 08 Oct 2015 01:34:01 -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=SrccF5myx9J9gIAdI8v1kIid0IetcN2F/mM7cAkWtSo=; b=gciiaZ8QlGDJ1yXB0A3icxUE4a7zclbyShvC1pKR7MmZ++WOOopkxOdi9SfUSYpnyW U0T5qhU/1y6mOawFTArI8HV24VPXygvgj1JK8VlMZLxzGAsIrwvK8K/LGJar8CUXP0Ny JP432z3O8V0Eu9PUvc7MlatWTlJnggk23kYC0jZLkHuly+DtJ1318ILHNoIPTUsMfKvv hEmGWYSW44Ru006bOrLdWZj9mw8HW5wiClCO3ygP+YFSndvuldE1WHXi53w598ZuhGT8 bdsLlowpi1kUnZAE5W4q65fYd7PGoQcdtWqwMGjK0iR+xcfM/tAYr5Rz3Y1YtMyc0EEv 6e9Q== X-Gm-Message-State: ALoCoQlU8DYp+Kx37mipIaR4pSQHBlqQka2XAAyLtYAMZzNbuYeuWV0nxvStkktvelTV5p4TemQu X-Received: by 10.180.35.132 with SMTP id h4mr428626wij.5.1444293241967; Thu, 08 Oct 2015 01:34:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.22.162 with SMTP id 34ls165953lfw.11.gmail; Thu, 08 Oct 2015 01:34:01 -0700 (PDT) X-Received: by 10.25.41.72 with SMTP id p69mr1882811lfp.111.1444293241781; Thu, 08 Oct 2015 01:34:01 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id 38si28811009lft.44.2015.10.08.01.34.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 01:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbwr8 with SMTP id r8so38323360lbw.2 for ; Thu, 08 Oct 2015 01:34:01 -0700 (PDT) X-Received: by 10.25.205.198 with SMTP id d189mr1940109lfg.72.1444293241581; Thu, 08 Oct 2015 01:34:01 -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 w3csp438980lbq; Thu, 8 Oct 2015 01:34:00 -0700 (PDT) X-Received: by 10.66.121.110 with SMTP id lj14mr6590988pab.61.1444293240312; Thu, 08 Oct 2015 01:34:00 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vb4si25033064pbc.53.2015.10.08.01.33.59; Thu, 08 Oct 2015 01:34:00 -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 S1754414AbbJHId6 (ORCPT + 30 others); Thu, 8 Oct 2015 04:33:58 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:51753 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754390AbbJHIdz (ORCPT ); Thu, 8 Oct 2015 04:33:55 -0400 Received: from 172.24.1.48 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.48]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CTW16118; Thu, 08 Oct 2015 16:29:57 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Oct 2015 16:29:28 +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 Subject: [PATCH 05/22] perf record: Load eBPF object into kernel Date: Thu, 8 Oct 2015 08:29:27 +0000 Message-ID: <1444292984-13135-6-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444292984-13135-1-git-send-email-wangnan0@huawei.com> References: <1444292984-13135-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected 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.217.178 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 56f6fe8..7279558 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -243,6 +243,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)\ @@ -275,3 +287,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 5be1dc9..cfeaa7b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -556,6 +556,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. Following patches will replace