From patchwork Sun Sep 6 07:13:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53193 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 0B93322B05 for ; Sun, 6 Sep 2015 07:20:16 +0000 (UTC) Received: by wisv5 with SMTP id v5sf17653227wis.0 for ; Sun, 06 Sep 2015 00:20:15 -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=LuaAId3Vf/ILs1IoapATMxx4zf/9fTpAIsV90puU9Lo=; b=jqXNCaWJFhmYx2DKO5bLX1Sho4YgAHCE4pwE4RFD22WibHMmtfwrko0FR1o5qIl+G8 SLWMZwgfg4stgbCrr9TKZD+Wb1vNBYcnpqH4SkKeWZhmpQA93ch8lzcV0dL0SO3u788Z 4QPeHBTcMn3vvLi47SOht4t/yHvVnWbZX8yAX1lhLWANNdBjudDFX+izjxPgwVRNklkU uj24dDlWWte2cJLNAogtXeOABd4rkHzY3FPH5onZXwnVfkBsx/+v/X5yelzvBwGDcRTW FfOA+HylPleOMw8le4CEgd+MArQkihC8WZtG5FXrXd3lXRNHAdzLHCLeaECQyDVROz6n fViQ== X-Gm-Message-State: ALoCoQmtrIZm/8wlixOEWyUndUWgxl8tTW3HOFrCVBrgMMdST4EQAmfPeW9NyfJ6T/DkYaCmZndA X-Received: by 10.180.99.196 with SMTP id es4mr3384565wib.1.1441524015287; Sun, 06 Sep 2015 00:20:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.226 with SMTP id e2ls444460lah.14.gmail; Sun, 06 Sep 2015 00:20:15 -0700 (PDT) X-Received: by 10.112.138.170 with SMTP id qr10mr11716792lbb.14.1441524015087; Sun, 06 Sep 2015 00:20:15 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id ut10si7219174lbb.145.2015.09.06.00.20.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 00:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lagj9 with SMTP id j9so35932434lag.2 for ; Sun, 06 Sep 2015 00:20:15 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr11314864lbc.41.1441524014980; Sun, 06 Sep 2015 00:20:14 -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 yn10csp845123lbb; Sun, 6 Sep 2015 00:20:14 -0700 (PDT) X-Received: by 10.68.109.2 with SMTP id ho2mr29461362pbb.158.1441524013880; Sun, 06 Sep 2015 00:20:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vm1si13749035pbc.123.2015.09.06.00.20.12; Sun, 06 Sep 2015 00:20:13 -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 S1753348AbbIFHUL (ORCPT + 28 others); Sun, 6 Sep 2015 03:20:11 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7317 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751287AbbIFHOm (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 CUK94048; Sun, 06 Sep 2015 15:14:15 +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:04 +0800 From: Wang Nan To: , , , CC: , , , , , , , , , , , Subject: [PATCH 11/27] perf tools: Sync setting of real bpf events with placeholder Date: Sun, 6 Sep 2015 07:13:27 +0000 Message-ID: <1441523623-152703-12-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.53 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: , In this patch, when adding real events described in BPF objects, sync filter and tracking settings with previous dummy placeholder. After this patch, command like: # perf record --test-filter.o --exclude-perf ls work as we expect. After all settings are synced, we remove those placeholder from evlist so they won't appear in the final perf.data. 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: Link: http://lkml.kernel.org/n/1441518995-149427-1-git-send-email-wangnan0@huawei.com --- tools/perf/util/bpf-loader.c | 8 ++++- tools/perf/util/bpf-loader.h | 1 + tools/perf/util/evlist.c | 75 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 2880dbf..3400538 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -325,6 +325,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].o"; + bpf_object__for_each_program(prog, obj) { struct probe_trace_event *tev; struct perf_probe_event *pev; @@ -348,7 +354,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..5bac423 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -13,6 +13,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 29212dc..7e36563 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -197,7 +197,54 @@ error: return -ENOMEM; } -static int add_bpf_event(struct probe_trace_event *tev, int fd, +static void sync_with_bpf_placeholder(struct perf_evlist *evlist, + const char *obj_name, + struct list_head *list) +{ + struct perf_evsel *dummy_evsel, *pos; + + const char *filter; + bool tracking_set = false; + bool found = false; + + evlist__for_each(evlist, dummy_evsel) { + if (!perf_evsel__is_bpf_placeholder(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; + + list_for_each_entry(pos, list, node) { + if (filter && perf_evsel__set_filter(pos, filter)) { + pr_debug("Failed to set filter '%s' to evsel %s\n", + filter, pos->name); + } + + /* Sync tracking */ + if (dummy_evsel->tracking && !tracking_set) + pos->tracking = tracking_set = true; + + /* + * If someday we allow to add config terms or modifiers + * to placeholder, we should sync them with real events + * here. Currently only tracking needs to be considered. + */ + } +} + +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 +252,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,13 +275,33 @@ 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_bpf_placeholder(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; } int perf_evlist__add_bpf(struct perf_evlist *evlist) { - return bpf__foreach_tev(add_bpf_event, evlist); + struct perf_evsel *pos, *n; + int err; + + err = bpf__foreach_tev(add_bpf_event, evlist); + + evlist__for_each_safe(evlist, n, pos) { + if (perf_evsel__is_bpf_placeholder(pos)) { + list_del_init(&pos->node); + perf_evsel__delete(pos); + evlist->nr_entries--; + } + } + return err; } static int perf_evlist__add_attrs(struct perf_evlist *evlist,