From patchwork Fri Sep 16 14:44:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 76388 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp534710qgf; Fri, 16 Sep 2016 07:44:40 -0700 (PDT) X-Received: by 10.98.73.22 with SMTP id w22mr23660587pfa.62.1474037080759; Fri, 16 Sep 2016 07:44:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p18si27029101pfd.230.2016.09.16.07.44.40; Fri, 16 Sep 2016 07:44:40 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964829AbcIPOo1 (ORCPT + 27 others); Fri, 16 Sep 2016 10:44:27 -0400 Received: from mail-it0-f53.google.com ([209.85.214.53]:37105 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933541AbcIPOoO (ORCPT ); Fri, 16 Sep 2016 10:44:14 -0400 Received: by mail-it0-f53.google.com with SMTP id 186so18342095itf.0 for ; Fri, 16 Sep 2016 07:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DfyI0JVwkZBXn8crqXwLSsX+0eqaVAy1F7lNm3lZ1h4=; b=fCSlU+cjwjAjI/r6XpvUEns73KnlfaHBlKVthgQCdfygtsCcpqQ8O9g1NhrpC1Oxvv 0AmSzP2FbafqdK4lFUMrJNmYYr9qMYdnU710jVtfjoqM+zC92vS8jXM1cKNLWkBUb9PV LsJxZ25N1x6gQ3hjC0g0nWI/yiqLaREtq7NoU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DfyI0JVwkZBXn8crqXwLSsX+0eqaVAy1F7lNm3lZ1h4=; b=IahPyFZBJYDTJcPgRX3QsbxOV6PEM9c3X7kr5aFHzyiUyaali3MPR/oRM9FDrMElh6 adngyyxL0qWZAYllyORAWF0p1DYc+rHLv+hwDIuwK5BXd/n/YgkcvxDs6BNboP+8G+lT XhAL0I1x5b2SDQkfyMSTMCusMQHBvFoz5MxiVjsIVrrD/cWMcXbFT3Woi0y2CPzNhAQ5 XEC94AiaYM9KeZi9Q0u3qpU6K0U9SUWYrZxazFCzCT1o1srBaGBD+LVjkiXbXJ/9srg7 z+Il0okmZyIj48gwwgUcLFklox7JCVglDpgqEDb9YuevNzliuOr1tlEgc4f5aZxgo411 uWNA== X-Gm-Message-State: AE9vXwM5fOMipF1q21G/TtKrn//pU1FwyAwDWnK6Y8zqmFPvIc0IitsUOLdE1OufWD7zucWl X-Received: by 10.36.110.196 with SMTP id w187mr6453160itc.28.1474037053397; Fri, 16 Sep 2016 07:44:13 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 88sm3811653iol.30.2016.09.16.07.44.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Sep 2016 07:44:12 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: adrian.hunter@intel.com, acme@infradead.org, mingo@redhat.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V7 3/3] perf tools: adding support for address filters Date: Fri, 16 Sep 2016 08:44:05 -0600 Message-Id: <1474037045-31730-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474037045-31730-1-git-send-email-mathieu.poirier@linaro.org> References: <1474037045-31730-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch makes it possible to use the current filter framework with address filters. That way address filters for HW tracers such as CoreSight and Intel PT can be communicated to the kernel drivers. Signed-off-by: Mathieu Poirier Acked-by: Adrian Hunter --- tools/perf/util/evsel.c | 5 +++++ tools/perf/util/evsel.h | 2 ++ tools/perf/util/parse-events.c | 39 ++++++++++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a99e82d97df2..e0bb399dcdd4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1067,6 +1067,11 @@ int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter) return perf_evsel__append_filter(evsel, "(%s) && (%s)", filter); } +int perf_evsel__append_addr_filter(struct perf_evsel *evsel, const char *filter) +{ + return perf_evsel__append_filter(evsel, "%s,%s", filter); +} + int perf_evsel__enable(struct perf_evsel *evsel) { int nthreads = thread_map__nr(evsel->threads); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 36ed0997e65b..49c51fb3d05c 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -234,6 +234,8 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel, int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter); int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter); +int perf_evsel__append_addr_filter(struct perf_evsel *evsel, + const char *filter); int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads, const char *filter); int perf_evsel__enable(struct perf_evsel *evsel); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 751b48fc641c..c23f2d5fc134 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1755,20 +1755,49 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist, static int set_filter(struct perf_evsel *evsel, const void *arg) { const char *str = arg; + bool found = false; + int nr_addr_filters = 0; + struct perf_pmu *pmu = NULL; - if (evsel == NULL || evsel->attr.type != PERF_TYPE_TRACEPOINT) { - fprintf(stderr, - "--filter option should follow a -e tracepoint option\n"); - return -1; + if (evsel == NULL) + goto err; + + if (evsel->attr.type == PERF_TYPE_TRACEPOINT) { + if (perf_evsel__append_tp_filter(evsel, str) < 0) { + fprintf(stderr, + "not enough memory to hold filter string\n"); + return -1; + } + + return 0; } - if (perf_evsel__append_tp_filter(evsel, str) < 0) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) + if (pmu->type == evsel->attr.type) { + found = true; + break; + } + + if (found) + perf_pmu__scan_file(pmu, "nr_addr_filters", + "%d", &nr_addr_filters); + + if (!nr_addr_filters) + goto err; + + if (perf_evsel__append_addr_filter(evsel, str) < 0) { fprintf(stderr, "not enough memory to hold filter string\n"); return -1; } return 0; + +err: + fprintf(stderr, + "--filter option should follow a -e tracepoint or HW tracer option\n"); + + return -1; } int parse_filter(const struct option *opt, const char *str,