From patchwork Thu Sep 15 16:37:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 76335 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp48152qgf; Thu, 15 Sep 2016 09:38:12 -0700 (PDT) X-Received: by 10.66.161.132 with SMTP id xs4mr15950443pab.140.1473957492498; Thu, 15 Sep 2016 09:38:12 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si4919885pax.253.2016.09.15.09.38.12; Thu, 15 Sep 2016 09:38: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; 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 S1755998AbcIOQiD (ORCPT + 27 others); Thu, 15 Sep 2016 12:38:03 -0400 Received: from mail-it0-f41.google.com ([209.85.214.41]:36079 "EHLO mail-it0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755271AbcIOQhW (ORCPT ); Thu, 15 Sep 2016 12:37:22 -0400 Received: by mail-it0-f41.google.com with SMTP id o3so104612151ita.1 for ; Thu, 15 Sep 2016 09:37:22 -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=OJFAB6WXydlI14BMp5YWA0eyVRfTTbR9lbKHe3uJzpg=; b=Qf/2yEHdDcPFkGZUwqsu+PdxOyHuib/GAPxk+Vum4U5+0DJB9F/hy2cOidoRZB8VRL 2YMOxcsRa4sXpNWCmqYzK8mb95aBKlBdKQaU5uDtBt5LRsN5Uojayy81jDqKzaK917Tz 6Gn7NM0mQN5w2FfXtzfZLtLCKB0m57olLoONw= 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=OJFAB6WXydlI14BMp5YWA0eyVRfTTbR9lbKHe3uJzpg=; b=F0Wg/UVryERDfEU/LNUgQue7cJdpB60WAFOyKyHFLOHDfSSQIs0EtmGteOE8XvMJC/ IA3DOCPyvI+myK/jMamc1ilV6f+aMuMVtaz7gX2vIZGT2rdJAaJ7lQRDcT8LsGJnSQDo 9san8f+MkNNQUEcdtoOnFdoydrc1F7V8jh2TDyTr0fGKDa0nv73wyIlZTKE7afQnyHLj /DGQXFhrgo74vvvfFMblNN10se3QtOsWR8KmWAi55j7uSicZh372y6RvxHg61HV2S8/6 oMxnWLpdK1PCZZQsz5BE3f9CTvY8JLBzh1MvYcMFtTbeK+WJ7aEc2XgWNb7drJ4XfwQt LNWQ== X-Gm-Message-State: AE9vXwNjJhjunVfHxtqX37gQJRMoMy2x6HyXXvjyMGTcaAZ1D/nuftWT6B9YabpM9OTBo5gq X-Received: by 10.36.142.131 with SMTP id h125mr515638ite.105.1473957436555; Thu, 15 Sep 2016 09:37:16 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i80sm1253646ita.5.2016.09.15.09.37.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Sep 2016 09:37:15 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org, adrian.hunter@intel.com Cc: mingo@redhat.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, acme@infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V6 3/3] perf tools: adding support for address filters Date: Thu, 15 Sep 2016 10:37:08 -0600 Message-Id: <1473957428-28311-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473957428-28311-1-git-send-email-mathieu.poirier@linaro.org> References: <1473957428-28311-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 IntelPT can be communicated to the kernel drivers. Signed-off-by: Mathieu Poirier --- 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,