Message ID | 1440822125-52691-14-git-send-email-wangnan0@huawei.com |
---|---|
State | New |
Headers | show
Return-Path: <patchwork-forward+bncBD2YXXXCQEBBBGPRQSXQKGQEN6X45VY@linaro.org> X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id E887720503 for <linaro@patches.linaro.org>; Sat, 29 Aug 2015 04:44:10 +0000 (UTC) Received: by laboe4 with SMTP id oe4sf9827085lab.3 for <linaro@patches.linaro.org>; Fri, 28 Aug 2015 21:44:09 -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=Ze15zRr93ycyFAJhSYidTKCKEMTqAPfAdBwWkvffioQ=; b=KQ1WMsLpC0Qu/BEMncMA/5AFM6H3Kf5dqMBjKX25OPU8/Ey0JdIf/gvap4ShqrlYID 5WmTwoj6ggSVGsHPQPKey+5VbWPLjLhceQtqX1C6VWtercoxrGwtypEcMPW91tZkPCEQ BX49tmF23CrnfKu4nZzfzdlMhqyPKW0PHB2h12iWhkr0PrD2yk5bRyJ3Wf9VojPk5zgB QrDWxTnpJWOxTLdkovttMTb8vq2rBPzT3GnW570IfVs4iLsQhiWMQM+Rt8FFOB0WNLIw z1wUsmd1t6fXTEP0ZgQLhOvXSNNgYf+5MkhLSSczuGn2bdmMcDfp6LNZjzj0HwaOZHTh VLzw== X-Gm-Message-State: ALoCoQmIc9ktYHnAV8sFgtrPIMq9Qi/Kndhx8xNoiR5zNzMzuW9VHyHl6hxpArkxD6xJyrM6M2Tf X-Received: by 10.180.35.162 with SMTP id i2mr2012373wij.6.1440823449877; Fri, 28 Aug 2015 21:44:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.232 with SMTP id d8ls295545lab.13.gmail; Fri, 28 Aug 2015 21:44:09 -0700 (PDT) X-Received: by 10.152.37.2 with SMTP id u2mr6264275laj.70.1440823449570; Fri, 28 Aug 2015 21:44:09 -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 w2si2840260laz.151.2015.08.28.21.44.09 for <patchwork-forward@linaro.org> (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2015 21:44:09 -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 lbcbn3 with SMTP id bn3so39496157lbc.2 for <patchwork-forward@linaro.org>; Fri, 28 Aug 2015 21:44:09 -0700 (PDT) X-Received: by 10.152.9.200 with SMTP id c8mr1246587lab.76.1440823449373; Fri, 28 Aug 2015 21:44:09 -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.151.194 with SMTP id us2csp273876lbb; Fri, 28 Aug 2015 21:44:08 -0700 (PDT) X-Received: by 10.68.139.226 with SMTP id rb2mr20623121pbb.49.1440823448296; Fri, 28 Aug 2015 21:44:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si13394674pdl.240.2015.08.28.21.44.07; Fri, 28 Aug 2015 21:44:08 -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 S1752370AbbH2Ens (ORCPT <rfc822;matthew.hart@linaro.org> + 28 others); Sat, 29 Aug 2015 00:43:48 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:43599 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752009AbbH2Enr (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 29 Aug 2015 00:43:47 -0400 Received: from 172.24.1.47 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CTY94469; Sat, 29 Aug 2015 12:23:17 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Sat, 29 Aug 2015 12:23:05 +0800 From: Wang Nan <wangnan0@huawei.com> To: <acme@redhat.com>, <mingo@kernel.org>, <ast@plumgrid.com> CC: <linux-kernel@vger.kernel.org>, <lizefan@huawei.com>, <pi3orama@163.com>, Wang Nan <wangnan0@huawei.com>, Brendan Gregg <brendan.d.gregg@gmail.com>, Daniel Borkmann <daniel@iogearbox.net>, David Ahern <dsahern@gmail.com>, "He Kuang" <hekuang@huawei.com>, Jiri Olsa <jolsa@kernel.org>, Kaixu Xia <xiakaixu@huawei.com>, Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>, Namhyung Kim <namhyung@kernel.org>, Paul Mackerras <paulus@samba.org>, Peter Zijlstra <a.p.zijlstra@chello.nl> Subject: [PATCH 13/31] perf tools: Attach eBPF program to perf event Date: Sat, 29 Aug 2015 04:21:47 +0000 Message-ID: <1440822125-52691-14-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1440822125-52691-1-git-send-email-wangnan0@huawei.com> References: <1440822125-52691-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: <patchwork-forward.linaro.org> 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: <http://groups.google.com/a/linaro.org/group/patchwork-forward/post>, <mailto:patchwork-forward@linaro.org> List-Help: <http://support.google.com/a/linaro.org/bin/topic.py?topic=25838>, <mailto:patchwork-forward+help@linaro.org> List-Archive: <http://groups.google.com/a/linaro.org/group/patchwork-forward/> List-Unsubscribe: <mailto:googlegroups-manage+836684582541+unsubscribe@googlegroups.com>, <http://groups.google.com/a/linaro.org/group/patchwork-forward/subscribe> |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 6fff961..5f59841 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1365,6 +1365,22 @@ retry_open: err); goto try_fallback; } + + if (evsel->bpf_fd >= 0) { + int evt_fd = FD(evsel, cpu, thread); + int bpf_fd = evsel->bpf_fd; + + err = ioctl(evt_fd, + PERF_EVENT_IOC_SET_BPF, + bpf_fd); + if (err && errno != EEXIST) { + pr_err("failed to attach bpf fd %d: %s\n", + bpf_fd, strerror(errno)); + err = -EINVAL; + goto out_close; + } + } + set_rlimit = NO_CHANGE; /*
This is the final patch which makes basic BPF filter work. After applying this patch, users are allowed to use BPF filter like: # perf record --event ./hello_world.c ls In this patch PERF_EVENT_IOC_SET_BPF ioctl is used to attach eBPF program to a newly created perf event. The file descriptor of the eBPF program is passed to perf record using previous patches, and stored into evsel->bpf_fd. It is possible that different perf event are created for one kprobe events for different CPUs. In this case, when trying to call the ioctl, EEXIST will be return. This patch doesn't treat it as an error. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Alexei Starovoitov <ast@plumgrid.com> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: David Ahern <dsahern@gmail.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kaixu Xia <xiakaixu@huawei.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Link: http://lkml.kernel.org/n/1436445342-1402-26-git-send-email-wangnan0@huawei.com --- tools/perf/util/evsel.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)