From patchwork Thu Sep 8 18:25:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 9321913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3641760752 for ; Thu, 8 Sep 2016 18:27:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 200DE298F8 for ; Thu, 8 Sep 2016 18:27:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14CCD29920; Thu, 8 Sep 2016 18:27:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 879C3298F8 for ; Thu, 8 Sep 2016 18:27:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bi41G-0004sa-ST; Thu, 08 Sep 2016 18:25:50 +0000 Received: from mail-oi0-x229.google.com ([2607:f8b0:4003:c06::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bi41C-0004Xv-Q9 for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2016 18:25:48 +0000 Received: by mail-oi0-x229.google.com with SMTP id y2so84344343oie.0 for ; Thu, 08 Sep 2016 11:25:25 -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; bh=SWD+LqzTcvmTtEj1TUeUcEK/a9YBFfgiMOhpa48LRgU=; b=Xe7S3DeZPsyYmQIbQzoDulsAxusKJSnn4KN++pNuf6upL/NJ1oEAZe38Hrnoiha7yK VktdvLhg0XC56qxznwMNTsIf1cknw98tL2PEX4gDU++SgRrxxqVeO0TzE4j2y4yuB9BG STcknuuuZIE1q5B4IbZYNKrGwQte9nAtbJv8U= 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; bh=SWD+LqzTcvmTtEj1TUeUcEK/a9YBFfgiMOhpa48LRgU=; b=OV+HdFQF1wF2Vahr5T8OI9xlUE7tNqFdu4brDga1Vq6srtFDHbdeAAkP+cQX6z6/OJ iAJ+rrCCvcKXIqZnpSt8d1GPtiKgET6x/Jq3DE0mkLw52dZPoS9cKW1H5km+exGds2Wh Fp8RTRnsRa/gmFr4m/p5XjI0a62v3Uuu+ZBrMeOWNtVoUXroKHhjmEdP+RPgveEReQCH HIxtfziDEdeTDYk62jC+wBxLpIFH5ItdMVgKKHpn7OMB0nAgWfX8NrCnH3i3V7z3zZ3G KVL0wk/nds+dBgwvThOpHvcBsoEXo4HVjUy/DqQDW/F8AlOODLfaM+/1OirJbX8hK6nu bLdg== X-Gm-Message-State: AE9vXwMa7Cv3X4Ki1XTLTZZfzcZ7lmkJVTj64AVgvfnzQuvrmbJWy3/cKtJAobwjVdIX/ijr X-Received: by 10.202.253.149 with SMTP id b143mr1282682oii.171.1473359125332; Thu, 08 Sep 2016 11:25:25 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id h86sm219777iod.2.2016.09.08.11.25.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Sep 2016 11:25:24 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Subject: [PATCH V4] perf tools: adding support for address filters Date: Thu, 8 Sep 2016 12:25:22 -0600 Message-Id: <1473359122-1045-1-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160908_112546_950383_AFE07590 X-CRM114-Status: GOOD ( 17.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: acme@infradead.org, peterz@infradead.org, adrian.hunter@intel.com, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, mingo@redhat.com, jolsa@kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. CC: Alexander Shishkin Signed-off-by: Mathieu Poirier --- Changes for V4: - Added support for address filters over more than one nibble. - Removed Jiri's ack, this version is too different from what was reviewed. Changes for V3: - Added Jiri's ack. - Rebased to v4.8-rc5. Changes for V2: - Rebased to v4.8-rc4. - Revisited error path. --- tools/perf/util/evsel.c | 17 +++++++++++++++++ tools/perf/util/evsel.h | 2 ++ tools/perf/util/parse-events.c | 39 ++++++++++++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d40f852d2de2..5d809ffb85bc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1046,6 +1046,23 @@ int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter) return -1; } +int perf_evsel__append_addr_filter(struct perf_evsel *evsel, + const char *filter) +{ + char *new_filter; + + if (evsel->filter == NULL) + return perf_evsel__set_filter(evsel, filter); + + if (asprintf(&new_filter, "%s,%s", evsel->filter, filter) > 0) { + free(evsel->filter); + evsel->filter = new_filter; + return 0; + } + + return -1; +} + int perf_evsel__append_filter(struct perf_evsel *evsel, const char *op, const char *filter) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 8ceb7ebb51f5..15ca5f85e946 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -235,6 +235,8 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel, bool use_sample_identifier); int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter); +int perf_evsel__append_addr_filter(struct perf_evsel *evsel, + const char *filter); int perf_evsel__append_filter(struct perf_evsel *evsel, const char *op, const char *filter); int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads, diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 2eb8b1ed4cc8..3e158ad7eeb8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1760,20 +1760,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_filter(evsel, "&&", str) < 0) { + fprintf(stderr, + "not enough memory to hold filter string\n"); + return -1; + } + + return 0; } - if (perf_evsel__append_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,