From patchwork Sat Aug 29 04:21:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 52848 Return-Path: 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 ; Sat, 29 Aug 2015 04:44:10 +0000 (UTC) Received: by laboe4 with SMTP id oe4sf9827085lab.3 for ; 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 (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 ; 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 + 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 ); 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 To: , , CC: , , , Wang Nan , Brendan Gregg , Daniel Borkmann , David Ahern , "He Kuang" , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra 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 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 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 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-26-git-send-email-wangnan0@huawei.com --- tools/perf/util/evsel.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; /*