From patchwork Thu Sep 22 21:12:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 76815 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp241410qgf; Thu, 22 Sep 2016 14:14:45 -0700 (PDT) X-Received: by 10.66.121.131 with SMTP id lk3mr6616595pab.139.1474578885481; Thu, 22 Sep 2016 14:14:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2si2543419pfb.292.2016.09.22.14.14.45; Thu, 22 Sep 2016 14:14:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034831AbcIVVOm (ORCPT + 27 others); Thu, 22 Sep 2016 17:14:42 -0400 Received: from merlin.infradead.org ([205.233.59.134]:46366 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965470AbcIVVNj (ORCPT ); Thu, 22 Sep 2016 17:13:39 -0400 Received: from [2804:14d:1283:1e7e:6af7:28ff:fed8:7f22] (helo=jouet.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnBJI-0003Yc-IZ; Thu, 22 Sep 2016 21:13:36 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id 565701401CE; Thu, 22 Sep 2016 18:13:00 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Mathieu Poirier , Alexander Shishkin , Peter Zijlstra , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 06/15] perf pmu: Push configuration down to PMU driver Date: Thu, 22 Sep 2016 18:12:50 -0300 Message-Id: <1474578779-14095-7-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474578779-14095-1-git-send-email-acme@kernel.org> References: <1474578779-14095-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Poirier This patch adds a PMU callback and the required mechanic so that drivers can process the command line configuration elements found in evsel::config_terms. Signed-off-by: Mathieu Poirier Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Peter Zijlstra Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1474041004-13956-6-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/Build | 1 + tools/perf/util/drv_configs.c | 77 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/drv_configs.h | 26 +++++++++++++++ tools/perf/util/pmu.h | 2 ++ 4 files changed, 106 insertions(+) create mode 100644 tools/perf/util/drv_configs.c create mode 100644 tools/perf/util/drv_configs.h -- 2.7.4 diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 96f99d608d00..eb60e613d795 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -86,6 +86,7 @@ libperf-y += term.o libperf-y += help-unknown-cmd.o libperf-y += mem-events.o libperf-y += vsprintf.o +libperf-y += drv_configs.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o diff --git a/tools/perf/util/drv_configs.c b/tools/perf/util/drv_configs.c new file mode 100644 index 000000000000..1647f285c629 --- /dev/null +++ b/tools/perf/util/drv_configs.c @@ -0,0 +1,77 @@ +/* + * drv_configs.h: Interface to apply PMU specific configuration + * Copyright (c) 2016-2018, Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +#include "drv_configs.h" +#include "evlist.h" +#include "evsel.h" +#include "pmu.h" + +static 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_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; +} diff --git a/tools/perf/util/drv_configs.h b/tools/perf/util/drv_configs.h new file mode 100644 index 000000000000..32bc9babc2e0 --- /dev/null +++ b/tools/perf/util/drv_configs.h @@ -0,0 +1,26 @@ +/* + * drv_configs.h: Interface to apply PMU specific configuration + * Copyright (c) 2016-2018, Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +#ifndef __PERF_DRV_CONFIGS_H +#define __PERF_DRV_CONFIGS_H + +#include "drv_configs.h" +#include "evlist.h" +#include "evsel.h" + +int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, + struct perf_evsel **err_evsel, + struct perf_evsel_config_term **term); +#endif 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 {