From patchwork Fri Sep 16 15:50:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 76399 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp565296qgf; Fri, 16 Sep 2016 08:51:28 -0700 (PDT) X-Received: by 10.66.76.65 with SMTP id i1mr24012476paw.51.1474041088040; Fri, 16 Sep 2016 08:51:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o69si5675107pfg.61.2016.09.16.08.51.27; Fri, 16 Sep 2016 08:51:28 -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 S965013AbcIPPvU (ORCPT + 27 others); Fri, 16 Sep 2016 11:51:20 -0400 Received: from mail-io0-f172.google.com ([209.85.223.172]:35930 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964879AbcIPPuS (ORCPT ); Fri, 16 Sep 2016 11:50:18 -0400 Received: by mail-io0-f172.google.com with SMTP id m79so30023740ioo.3 for ; Fri, 16 Sep 2016 08:50:18 -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=B0ai6LTCUu0Nlr3JyZ1hUwX0epeapy06267Bp8rlIBk=; b=AOK7uqiVz0A5DCN7c1pNb9N33ZVihAwMzflDCKHivx3OBp/hHPzXGPs6rR4LnDt0AW rNemlvAEjGdgUXrcytT4B3wOdxODTeCTfacJRTyGvDFMhCueynSh0Mto055Mkt7ZgEkh HqtKWbFtbZhRbW5TAnaRsOuwh9bj3Q+UVFMWA= 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=B0ai6LTCUu0Nlr3JyZ1hUwX0epeapy06267Bp8rlIBk=; b=F3Oc8ZKVAHz5JrKh1crw9XQtORlEid+ynjjruL+GWXvH/jFeBDanIlYqZ+2DHIark9 nu71Pf/mxL9vWD9oqODFShUdERHNGpikcjC6nOUfhtkTcEm9pe1w5o018Xhw8ePBI/M6 wHaWt7GZdcjKFt5Z/QTvkF2/bsWYB67LR3ynXMYVPAV6hfqrJ0vhbbazDVE8l8GzPIVe 9BDeKhkNklFzCbEIXhoGD2BOldtlhq4oW17M6XbrgTPvZRC2QFRb+Wah//EZGjIRN24H /+dDYLlD6AG24m4jvF7ID/FFDa7EwLzefsQTyi8llX5C1ZC3oo1RR3/UyEEPZ07Fz9AV iBbA== X-Gm-Message-State: AE9vXwPiba5KnQWAR/mPu/G4iqmrA9pYOSfSHFdXpVMpQYL7trl3awTevFDrSs4CZNi0SUOz X-Received: by 10.107.136.15 with SMTP id k15mr23813459iod.83.1474041017747; Fri, 16 Sep 2016 08:50:17 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id h63sm3177750ita.12.2016.09.16.08.50.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Sep 2016 08:50:16 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: acme@infradead.org, peterz@infradead.org, jolsa@kernel.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V8 5/7] perf tools: pushing configuration down to PMU driver Date: Fri, 16 Sep 2016 09:50:02 -0600 Message-Id: <1474041004-13956-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474041004-13956-1-git-send-email-mathieu.poirier@linaro.org> References: <1474041004-13956-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 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 --- 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 91c5f6e1af59..53cbbbb6ddb9 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -85,6 +85,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 {