From patchwork Sun Sep 6 05:56:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53163 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 748A3212FE for ; Sun, 6 Sep 2015 06:03:16 +0000 (UTC) Received: by wisv5 with SMTP id v5sf17381001wis.0 for ; Sat, 05 Sep 2015 23:03: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=xxVvPsVuNsU93s1STz89ODwkV38HcMszM75yvxwsQEk=; b=QWgY2SJpkJXtmUeiSZf4Zr5un3GGJP90T1tobDYQzDMFzVoU41zKHbBzxmTvKeIohC NKjJdBAZnGBU/T220IYIhjcm6HoKS9Xt4Ouk8GpSaLk/iMg0h8rlBPncv5zbcetv9AWu JFDtbPwFeIfdmfFtHhvd4JN50Suu4O30FJHmbTYaMPmyL0lhX0e3aHj/wW9akrf/toSG rbAjJAYS3h0Qc/4m27MVe8GibmYJ3qmj7ZRUnp71vGg6nqUb8Cw6VkQTVFKL1cM6Yt+V 7lpvR1JJ7YafOa5fe6/+Vzak9FloSliPew1Q0jCj076yEspc4IU3vsLkHes8T1dFqQId LtVg== X-Gm-Message-State: ALoCoQkMoJBlluW6GSpdfF/gRZNLRriUh13Ii2RZZCoOTOp67rp69rkC6ljLCf2V579rtIwb/fMk X-Received: by 10.180.89.104 with SMTP id bn8mr3358056wib.4.1441519395763; Sat, 05 Sep 2015 23:03:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.168 with SMTP id u8ls270940lag.63.gmail; Sat, 05 Sep 2015 23:03:15 -0700 (PDT) X-Received: by 10.112.235.130 with SMTP id um2mr11537405lbc.72.1441519395558; Sat, 05 Sep 2015 23:03: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 tn10si7110675lbb.38.2015.09.05.23.03.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Sep 2015 23:03: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 lanb10 with SMTP id b10so34753192lan.3 for ; Sat, 05 Sep 2015 23:03:15 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr11416883lbb.36.1441519395388; Sat, 05 Sep 2015 23:03:15 -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 yn10csp821636lbb; Sat, 5 Sep 2015 23:03:14 -0700 (PDT) X-Received: by 10.68.106.197 with SMTP id gw5mr29942242pbb.1.1441519394195; Sat, 05 Sep 2015 23:03:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jg9si13501298pac.170.2015.09.05.23.03.13; Sat, 05 Sep 2015 23:03:14 -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 S1751037AbbIFGCu (ORCPT + 28 others); Sun, 6 Sep 2015 02:02:50 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:24212 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750804AbbIFGCo (ORCPT ); Sun, 6 Sep 2015 02:02:44 -0400 Received: from 172.24.1.50 (EHLO szxeml432-hub.china.huawei.com) ([172.24.1.50]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUK84279; Sun, 06 Sep 2015 14:01:11 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.235.1; Sun, 6 Sep 2015 13:56:43 +0800 From: Wang Nan To: CC: , Wang Nan , "Alexei Starovoitov" , Brendan Gregg , Daniel Borkmann , David Ahern , "He Kuang" , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Zefan Li , Subject: [PATCH] perf tools: Sync setting of real bpf events with placeholder Date: Sun, 6 Sep 2015 05:56:35 +0000 Message-ID: <1441518995-149427-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1441518918-149316-1-git-send-email-wangnan0@huawei.com> References: <1441518918-149316-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 --- 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,