From patchwork Sat Aug 29 04:21:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 52847 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 3B6D920503 for ; Sat, 29 Aug 2015 04:35:15 +0000 (UTC) Received: by wicne3 with SMTP id ne3sf13898402wic.1 for ; Fri, 28 Aug 2015 21:35:14 -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=fDHF0apSXJgL12QOFRsCTs8jYLL3P6e4H6y6+V69Dwg=; b=WcjevKT+MBGi+3MGwlul68R3A9GvSV2jzeQASv6aV2Earv2d71g9OyU1wizLvxLQk2 uWdC/mla2UC1Xke9q6LK/bd3Sa7y7d2zLCAWgeb89JaHP0Eaf0QubWctIYZgjU94l0Jr w5Nodh/SM8d6NsicanFV7P45kMUHEhlloU6bDgwjeSjlfqion2frKU0hOF1lUdXcNzQw SQQbMVSHhPH6Ht4Vq9jkZKq5PbJuuqR3SirHtmb7l7hBHlzskU2MmwoayVakbwCVwJB5 amF7Y1+Mjy2HIJ5zsQT3UMSTRoxYs4rKf2ktXLKS4EtuNUdV0Nc9UgTgXVEy2blL1iQm UIIg== X-Gm-Message-State: ALoCoQmgSF4twbBNS65va6vSjGygWD/r+/aK1fuFAL9So44WsLSdFS40X7tUf6QfeIfRGFmWtC1T X-Received: by 10.194.173.3 with SMTP id bg3mr3552360wjc.5.1440822914391; Fri, 28 Aug 2015 21:35:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.135 with SMTP id ky7ls305367lac.20.gmail; Fri, 28 Aug 2015 21:35:14 -0700 (PDT) X-Received: by 10.152.18.232 with SMTP id z8mr6279502lad.66.1440822914206; Fri, 28 Aug 2015 21:35:14 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id lt3si7672823lac.124.2015.08.28.21.35.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2015 21:35:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbsx3 with SMTP id sx3so39564713lbb.0 for ; Fri, 28 Aug 2015 21:35:14 -0700 (PDT) X-Received: by 10.112.166.2 with SMTP id zc2mr6067294lbb.29.1440822913929; Fri, 28 Aug 2015 21:35:13 -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 us2csp271009lbb; Fri, 28 Aug 2015 21:35:12 -0700 (PDT) X-Received: by 10.68.143.70 with SMTP id sc6mr20264148pbb.87.1440822912799; Fri, 28 Aug 2015 21:35:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oh5si13344153pbb.168.2015.08.28.21.35.11; Fri, 28 Aug 2015 21:35:12 -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 S1752651AbbH2EfI (ORCPT + 28 others); Sat, 29 Aug 2015 00:35:08 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:42244 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751946AbbH2EfF (ORCPT ); Sat, 29 Aug 2015 00:35:05 -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 CTY94468; Sat, 29 Aug 2015 12:23:16 +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:04 +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 12/31] perf tools: Allow filter option to be applied to bof object Date: Sat, 29 Aug 2015 04:21:46 +0000 Message-ID: <1440822125-52691-13-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.174 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: , Before this patch, --filter options can't be applied to BPF object 'events'. For example, the following command: # perf record -e cycles -e test_bpf.o --exclude-perf -a sleep 1 doesn't apply '--exclude-perf' to events in test_bpf.o. Instead, the filter will be applied to 'cycles' event. This is caused by the delay manner of adding real BPF events. Because all BPF probing points are probed by one call, we can't add real events until all BPF objects are collected. In previous patch (perf tools: Enable passing bpf object file to --event), nothing is appended to evlist. This patch fixes this by utilizing the dummy event linked during parse_events(). Filter settings goes to dummy event, and be synced with real events in add_bpf_event(). 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/r/1440742821-44548-5-git-send-email-wangnan0@huawei.com --- tools/perf/builtin-record.c | 6 ++++- tools/perf/util/bpf-loader.c | 8 ++++++- tools/perf/util/bpf-loader.h | 2 ++ tools/perf/util/evlist.c | 53 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 5051d3b..fd56a5b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1113,7 +1113,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) argc = parse_options(argc, argv, record_options, record_usage, PARSE_OPT_STOP_AT_NON_OPTION); - perf_evlist__purge_dummy(rec->evlist); if (!argc && target__none(&rec->opts.target)) usage_with_options(record_usage, record_options); @@ -1178,6 +1177,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) pr_err("Failed to add events from BPF object(s)\n"); goto out_symbol_exit; } + /* + * Until now let's purge dummy event. Filter options should + * have been attached to real events by perf_evlist__add_bpf(). + */ + perf_evlist__purge_dummy(rec->evlist); symbol__init(NULL); diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 126aa71..c3bc0a8 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -293,6 +293,12 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg) int err; bpf_object__for_each_safe(obj, tmp) { + const char *obj_name; + + obj_name = bpf_object__get_name(obj); + if (!obj_name) + obj_name = "[unknown]"; + bpf_object__for_each_program(prog, obj) { struct probe_trace_event *tev; struct perf_probe_event *pev; @@ -316,7 +322,7 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg) return fd; } - err = func(tev, fd, arg); + err = func(tev, obj_name, fd, arg); if (err) { pr_debug("bpf: call back failed, stop iterate\n"); return err; diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index 34656f8..323e664 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -6,6 +6,7 @@ #define __BPF_LOADER_H #include +#include #include #include "probe-event.h" #include "debug.h" @@ -13,6 +14,7 @@ #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev, + const char *obj_name, int fd, void *arg); #ifdef HAVE_LIBBPF_SUPPORT diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index f79bbf8..c00e939 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -197,7 +197,45 @@ error: return -ENOMEM; } -static int add_bpf_event(struct probe_trace_event *tev, int fd, +static void +sync_with_dummy(struct perf_evlist *evlist, const char *obj_name, + struct list_head *list) +{ + struct perf_evsel *dummy_evsel, *pos; + const char *filter; + bool found = false; + int err; + + evlist__for_each(evlist, dummy_evsel) { + if (!perf_evsel__is_dummy(dummy_evsel)) + continue; + + if (strcmp(dummy_evsel->name, obj_name) == 0) { + found = true; + break; + } + } + + if (!found) { + pr_debug("Failed to find dummy event of '%s'\n", + obj_name); + return; + } + + filter = dummy_evsel->filter; + if (!filter) + return; + + list_for_each_entry(pos, list, node) { + err = perf_evsel__set_filter(pos, filter); + if (err) + pr_debug("Failed to set filter '%s' to evsel %s\n", + filter, pos->name); + } +} + +static int add_bpf_event(struct probe_trace_event *tev, + const char *obj_name, int fd, void *arg) { struct perf_evlist *evlist = arg; @@ -205,8 +243,8 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd, struct list_head list; int err, idx, entries; - pr_debug("add bpf event %s:%s and attach bpf program %d\n", - tev->group, tev->event, fd); + pr_debug("add bpf event %s:%s and attach bpf program %d (from %s)\n", + tev->group, tev->event, fd, obj_name); INIT_LIST_HEAD(&list); idx = evlist->nr_entries; @@ -228,6 +266,15 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd, list_for_each_entry(pos, &list, node) pos->bpf_fd = fd; entries = idx - evlist->nr_entries; + + sync_with_dummy(evlist, obj_name, &list); + + /* + * Currectly we don't need to link those new events at the + * same place where dummy node reside because order of + * events in cmdline won't be used after + * 'perf_evlist__add_bpf'. + */ perf_evlist__splice_list_tail(evlist, &list, entries); return 0; }