From patchwork Sun Sep 6 07:13:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53191 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id A87FB22B05 for ; Sun, 6 Sep 2015 07:19:49 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf17395533lbb.3 for ; Sun, 06 Sep 2015 00:19:48 -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=GouNBoFkBW2tgJctp4u/vseoo1Kz1VPdhObtcUrvPNg=; b=diECdxusTzH5fAXEv78B0D5HXfQKfi/LNSfCtRv6GXWQoxTBfEIMVzMSyiKc8dLoGm 23AF6GSUDUsYZegv3CijeMUZbIWgglZiNsdc7KqhJfwQQkCS98uzCLUQ99EApNg5+fI0 jykPeqCjbNoOFSASQnjdiMcz3pzzFaozON49Cmc8qug8tyAjpXtEOMnVtI48eLCci9pm 2Tj2CK4zctBsgwOIeBTTLdS86QVyajm70E8/rlLij7eLdbCpZY45V2y013APh/rp/34/ 1Es+NOGoaf/OufOtypfBY+RLuF/ZZryrIivBTS11BvslH1Sb1q+I4oL/aY+Gswkc0VqS dawQ== X-Gm-Message-State: ALoCoQlBU6ogNvaKrQVCcmzgQBBe+uXSaXJG81bzd7qSkL2w6Sv++wduk+ELX9kD6Wi4OqrXMbvL X-Received: by 10.112.172.70 with SMTP id ba6mr3306931lbc.1.1441523988611; Sun, 06 Sep 2015 00:19:48 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.202 with SMTP id u10ls485696lau.23.gmail; Sun, 06 Sep 2015 00:19:48 -0700 (PDT) X-Received: by 10.152.29.131 with SMTP id k3mr11475211lah.85.1441523988390; Sun, 06 Sep 2015 00:19:48 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id m5si7224980lam.100.2015.09.06.00.19.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 00:19:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by lamp12 with SMTP id p12so34709554lam.0 for ; Sun, 06 Sep 2015 00:19:48 -0700 (PDT) X-Received: by 10.112.169.66 with SMTP id ac2mr10590955lbc.32.1441523988284; Sun, 06 Sep 2015 00:19:48 -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.164.42 with SMTP id yn10csp844956lbb; Sun, 6 Sep 2015 00:19:47 -0700 (PDT) X-Received: by 10.66.244.230 with SMTP id xj6mr30640243pac.53.1441523987188; Sun, 06 Sep 2015 00:19:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si13810334pdf.9.2015.09.06.00.19.46; Sun, 06 Sep 2015 00:19:47 -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 S1753274AbbIFHTo (ORCPT + 28 others); Sun, 6 Sep 2015 03:19:44 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7627 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751336AbbIFHOm (ORCPT ); Sun, 6 Sep 2015 03:14:42 -0400 Received: from 172.24.1.48 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUK94037; Sun, 06 Sep 2015 15:14:11 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Sun, 6 Sep 2015 15:14:00 +0800 From: Wang Nan To: , , , CC: , , , , , , , , , , , Subject: [PATCH 07/27] perf record: Load all eBPF object into kernel Date: Sun, 6 Sep 2015 07:13:23 +0000 Message-ID: <1441523623-152703-8-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1441523623-152703-1-git-send-email-wangnan0@huawei.com> References: <1441523623-152703-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.215.50 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/1436445342-1402-24-git-send-email-wangnan0@huawei.com --- tools/perf/builtin-record.c | 15 +++++++++++++++ tools/perf/util/bpf-loader.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 10 ++++++++++ 3 files changed, 53 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index b56109f..7335ce0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1159,6 +1159,21 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) goto out_symbol_exit; } + /* + * bpf__probe() also calls symbol__init() if there are probe + * events in bpf objects, so calling symbol_exit when failure + * is safe. If there is no probe event, bpf__load() always + * success. + */ + err = bpf__load(); + if (err) { + pr_err("Loading BPF programs failed:\n"); + + bpf__strerror_load(err, errbuf, sizeof(errbuf)); + pr_err("\t%s\n", errbuf); + goto out_symbol_exit; + } + symbol__init(NULL); if (symbol_conf.kptr_restrict) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index ce95db8..754ed02 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -299,6 +299,25 @@ out_cleanup: goto out; } +int bpf__load(void) +{ + struct bpf_object *obj, *tmp; + int err = 0; + + bpf_object__for_each_safe(obj, tmp) { + err = bpf_object__load(obj); + if (err) { + pr_debug("bpf: load objects failed\n"); + goto errout; + } + } + return 0; +errout: + bpf_object__for_each_safe(obj, tmp) + bpf_object__unload(obj); + return err; +} + #define bpf__strerror_head(err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\ @@ -341,3 +360,12 @@ int bpf__strerror_probe(int err, char *buf, size_t size) bpf__strerror_end(buf, size); return 0; } + +int bpf__strerror_load(int err, char *buf, size_t size) +{ + bpf__strerror_head(err, buf, size); + bpf__strerror_entry(EINVAL, "%s: add -v to see detail. Run 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 6b09a85..4d7552e 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -19,6 +19,9 @@ int bpf__probe(void); int bpf__unprobe(void); int bpf__strerror_probe(int err, char *buf, size_t size); +int bpf__load(void); +int bpf__strerror_load(int err, char *buf, size_t size); + void bpf__clear(void); #else static inline int bpf__prepare_load(const char *filename __maybe_unused) @@ -29,6 +32,7 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused) static inline int bpf__probe(void) { return 0; } static inline int bpf__unprobe(void) { return 0; } +static inline int bpf__load(void) { return 0; } static inline void bpf__clear(void) { } static inline int @@ -56,5 +60,11 @@ static inline int bpf__strerror_probe(int err __maybe_unused, { return __bpf_strerror(buf, size); } + +static inline int bpf__strerror_load(int err __maybe_unused, + char *buf, size_t size) +{ + return __bpf_strerror(buf, size); +} #endif #endif