From patchwork Thu Aug 25 20:20:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 9299925 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 99422607D8 for ; Thu, 25 Aug 2016 20:23:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A4552939E for ; Thu, 25 Aug 2016 20:23:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EFA2293A8; Thu, 25 Aug 2016 20:23:57 +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=ham 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 C1FA22939E for ; Thu, 25 Aug 2016 20:23:56 +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 1bd1AS-0004NP-FI; Thu, 25 Aug 2016 20:22:28 +0000 Received: from mail-it0-x229.google.com ([2607:f8b0:4001:c0b::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bd19F-0003sZ-6Y for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2016 20:21:19 +0000 Received: by mail-it0-x229.google.com with SMTP id f6so110290854ith.0 for ; Thu, 25 Aug 2016 13:20:53 -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=i5HSTbEs2y7j1OltcnpP69Ud1zn2LKNrt4oIO5wwEUM=; b=Lki+nG5Un07gz6zERVd3QPArY7O3r7FxF7bOtPXYzNcaWhNBYgBRKKy5prABIPSqDT /KGSGRJTQJPXz38XCLvFF4otcl3j3oEbSe6gfe9Oi0pIIj8Ic4FnrR0bJBoXqQm3Rg1S agd3ogy5pkkBuw29hYC/BI7SA+SOH6iDe7Qiw= 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=i5HSTbEs2y7j1OltcnpP69Ud1zn2LKNrt4oIO5wwEUM=; b=KDExk/3245DNokmoYGUQxpVPNyAJZUpzk81uGwLM0njEEXM2YgG7mBaLCT0kbNQ7cw /m2Vc95FGdQdFySraWyi+OUKywJVMgaXjB/k4Q3QdTsi50gis31c9tHSw3zqWKfZzviC rMLi8IBwdVsZyd1ur05jKdyKnYX+uL++Txdl/9p8h6Yr8mANsA+b2rTTI26MQlOka4pP g+JRYevoPHj1QIafWGFpET0tS7rBzsCk6CBQiQ8Rko3RJuWbVvdhpkvA4F4s5ertl42p gDAoQAesJ5a1Mhlb+lCocH1m4836i4qUpAeKCPjV0lZymERzKCH1kYL+mMzExSD3wPa+ usOQ== X-Gm-Message-State: AEkoousz3RGU82Kx+6oLtpWw3GMCEDdlYe5/ZySvoiZQny4BVYiVnGh/1Xfwd8lGsNO4rmJz X-Received: by 10.107.9.42 with SMTP id j42mr12146998ioi.33.1472156453199; Thu, 25 Aug 2016 13:20:53 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id t35sm6187910ioi.7.2016.08.25.13.20.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 13:20:52 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org Subject: [PATCH V6 4/5] perf tools: Pushing configuration down to PMU driver Date: Thu, 25 Aug 2016 14:20:44 -0600 Message-Id: <1472156445-24283-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472156445-24283-1-git-send-email-mathieu.poirier@linaro.org> References: <1472156445-24283-1-git-send-email-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160825_132113_540287_DF3EA937 X-CRM114-Status: GOOD ( 18.83 ) 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: alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, 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 adds a PMU callback so that drivers can process the command line configuration elements found in evsel::config_terms. The callback is then used in various places where events can be specified. Signed-off-by: Mathieu Poirier --- tools/perf/builtin-record.c | 9 +++++++++ tools/perf/builtin-stat.c | 8 ++++++++ tools/perf/builtin-top.c | 12 ++++++++++++ tools/perf/util/evlist.c | 18 ++++++++++++++++++ tools/perf/util/evlist.h | 3 +++ tools/perf/util/evsel.c | 40 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/evsel.h | 2 ++ tools/perf/util/pmu.h | 2 ++ 8 files changed, 94 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 6355902fbfc8..74927d6e147e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -383,6 +383,7 @@ static int record__open(struct record *rec) struct perf_evlist *evlist = rec->evlist; struct perf_session *session = rec->session; struct record_opts *opts = &rec->opts; + struct perf_evsel_config_term *err_term; int rc = 0; perf_evlist__config(evlist, opts, &callchain_param); @@ -412,6 +413,14 @@ try_again: goto out; } + if (perf_evlist__apply_drv_configs(evlist, &pos, &err_term)) { + error("failed to set config \"%s\" on event %s with %d (%s)\n", + err_term->val.drv_cfg, perf_evsel__name(pos), errno, + strerror_r(errno, msg, sizeof(msg))); + rc = -1; + goto out; + } + rc = record__mmap(rec); if (rc) goto out; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 3c7452b39f57..7f378c551ab6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -539,6 +539,7 @@ static int __run_perf_stat(int argc, const char **argv) int status = 0; const bool forks = (argc > 0); bool is_pipe = STAT_RECORD ? perf_stat.file.is_pipe : false; + struct perf_evsel_config_term *err_term; if (interval) { ts.tv_sec = interval / 1000; @@ -610,6 +611,13 @@ try_again: return -1; } + if (perf_evlist__apply_drv_configs(evsel_list, &counter, &err_term)) { + error("failed to set config \"%s\" on event %s with %d (%s)\n", + err_term->val.drv_cfg, perf_evsel__name(counter), errno, + strerror_r(errno, msg, sizeof(msg))); + return -1; + } + if (STAT_RECORD) { int err, fd = perf_data_file__fd(&perf_stat.file); diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 418ed94756d3..0e566fe95e1b 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -940,6 +940,10 @@ static int callchain_param__setup_sample_type(struct callchain_param *callchain) static int __cmd_top(struct perf_top *top) { + char msg[512]; + struct perf_evsel *pos; + struct perf_evsel_config_term *err_term; + struct perf_evlist *evlist = top->evlist; struct record_opts *opts = &top->record_opts; pthread_t thread; int ret; @@ -976,6 +980,14 @@ static int __cmd_top(struct perf_top *top) if (ret) goto out_delete; + ret = perf_evlist__apply_drv_configs(evlist, &pos, &err_term); + if (ret) { + error("failed to set config \"%s\" on event %s with %d (%s)\n", + err_term->val.drv_cfg, perf_evsel__name(pos), errno, + strerror_r(errno, msg, sizeof(msg))); + goto out_delete; + } + top->session->evlist = top->evlist; perf_session__set_id_hdr_size(top->session); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 097b3ed77fdd..d9d160324f50 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1415,6 +1415,24 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **e return err; } +int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, + struct perf_evsel **err_evsel, + struct perf_evsel_config_term **err_term) +{ + struct perf_evsel *evsel; + int err = 0; + + evlist__for_each_entry(evlist, evsel) { + err = perf_evsel__apply_drv_configs(evsel, err_term); + if (err) { + *err_evsel = evsel; + break; + } + } + + return err; +} + int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter) { struct perf_evsel *evsel; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 4fd034f22d2f..bf7ed0be3f33 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -232,6 +232,9 @@ void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus, struct thread_map *threads); int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target); int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel); +int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, + struct perf_evsel **err_evsel, + struct perf_evsel_config_term **term); void __perf_evlist__set_leader(struct list_head *list); void perf_evlist__set_leader(struct perf_evlist *evlist); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d9b80ef881cd..ea53f33a968c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -25,6 +25,7 @@ #include "thread_map.h" #include "target.h" #include "perf_regs.h" +#include "pmu.h" #include "debug.h" #include "trace-event.h" #include "stat.h" @@ -1062,6 +1063,45 @@ int perf_evsel__append_filter(struct perf_evsel *evsel, return -1; } +int perf_evsel__apply_drv_configs(struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term) +{ + bool found = false; + int err = 0; + struct perf_evsel_config_term *term; + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) + if (pmu->type == evsel->attr.type) { + found = true; + break; + } + + list_for_each_entry(term, &evsel->config_terms, list) { + if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) + continue; + + /* + * We have a configuration term, report an error if we + * can't find the PMU or if the PMU driver doesn't support + * cmd line driver configuration. + */ + if (!found || !pmu->set_drv_config) { + err = -EINVAL; + *err_term = term; + break; + } + + err = pmu->set_drv_config(term); + if (err) { + *err_term = term; + break; + } + } + + return err; +} + 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 323806082c58..8ceb7ebb51f5 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -239,6 +239,8 @@ 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, const char *filter); +int perf_evsel__apply_drv_configs(struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term); int perf_evsel__enable(struct perf_evsel *evsel); int perf_evsel__disable(struct perf_evsel *evsel); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 5d7e84466bee..743422ad900b 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -4,6 +4,7 @@ #include #include #include +#include "evsel.h" #include "parse-events.h" enum { @@ -25,6 +26,7 @@ struct perf_pmu { struct list_head format; /* HEAD struct perf_pmu_format -> list */ struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */ struct list_head list; /* ELEM */ + int (*set_drv_config) (struct perf_evsel_config_term *term); }; struct perf_pmu_info {