From patchwork Sun Sep 6 07:13: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: 53172 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 55AC822B05 for ; Sun, 6 Sep 2015 07:15:54 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf17380527lbc.1 for ; Sun, 06 Sep 2015 00:15:53 -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=1l9aAj+BegClw7ojh5Zk9mkdNKxHd9D03HRni9x43yg=; b=PSNzPAKWLpXQn9veumc2dJ+FcaeQ7bXNOenMxSgl3Trckkfz9u+GVKFLkqbGrjegjM s0fJyjZzlLz8B62zPuXkjJZWWoxEbFvjnDS5mXK8/18yi0AQUVfRFQee+2zqSqXX5ikn T5gRQrMsWwuraoN7tF4jN2xNaWWikJ93okzDk/TsLNBo+cVL9QebMjIvwKuHZUtPX/Q4 Gemq/WHfIL3bdTmrLqRX+YZA9x9z79ZPwGOEndNbnLtcQ7miEp7a6C5xMYLqd+DvepGP Z9yBa9toXj2piNnKZ0vR7SXvLZQkn/LqqrmkFh11ggTnAVBD4DJsQvXsjjcOZF5Lw+1n yHNw== X-Gm-Message-State: ALoCoQlXjGfyUMk2w3qfW2Fo3qRzfPFamZZXFaWSFrXoF1estJ/v4FNhTQaNXcvh5L4+z1IwAmu/ X-Received: by 10.112.48.41 with SMTP id i9mr3294338lbn.23.1441523753228; Sun, 06 Sep 2015 00:15:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.225 with SMTP id e1ls91851laa.108.gmail; Sun, 06 Sep 2015 00:15:52 -0700 (PDT) X-Received: by 10.112.235.130 with SMTP id um2mr11748507lbc.72.1441523752909; Sun, 06 Sep 2015 00:15:52 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id r5si7217735lbw.126.2015.09.06.00.15.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 00:15:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lagj9 with SMTP id j9so35903189lag.2 for ; Sun, 06 Sep 2015 00:15:52 -0700 (PDT) X-Received: by 10.152.9.200 with SMTP id c8mr10706894lab.76.1441523752770; Sun, 06 Sep 2015 00:15:52 -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 yn10csp843618lbb; Sun, 6 Sep 2015 00:15:51 -0700 (PDT) X-Received: by 10.68.114.34 with SMTP id jd2mr30686084pbb.94.1441523751105; Sun, 06 Sep 2015 00:15:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yr4si13732023pbc.140.2015.09.06.00.15.50; Sun, 06 Sep 2015 00:15:51 -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 S1752175AbbIFHPj (ORCPT + 28 others); Sun, 6 Sep 2015 03:15:39 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7470 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751247AbbIFHOl (ORCPT ); Sun, 6 Sep 2015 03:14:41 -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 CUK94035; Sun, 06 Sep 2015 15:14:10 +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:02 +0800 From: Wang Nan To: , , , CC: , , , , , , , , , , , Subject: [PATCH 09/27] perf tools: Attach eBPF program to perf event Date: Sun, 6 Sep 2015 07:13:25 +0000 Message-ID: <1441523623-152703-10-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.47 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.o 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 1cf7c75..73cf9fc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1333,6 +1333,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; /*