From patchwork Mon Jul 2 22:33:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 140856 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp465269ljj; Mon, 2 Jul 2018 15:34:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpca93khm0hoElTcp4WIHpDKt97FwUIdh9uzKeGwLWZ4yrfXQzZMuQNQTEVwQcKytT7SdXvQ X-Received: by 2002:a63:790b:: with SMTP id u11-v6mr21143606pgc.111.1530570877915; Mon, 02 Jul 2018 15:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530570877; cv=none; d=google.com; s=arc-20160816; b=ra+zuq+brnKMnc3wzLTyjpv9NekhZ66LOyhqMfFs0N+dKeVoPLCxEqc4zcDWAt6qIi FX90itcka27rJmCCF8mZkSvMfVglOa7OReKYs7uKFyOW2N6zOBHBa07kxTag+aJPEreT PEpW3zv66o0oBHy7MlpRWiPairIvn+3T/AILoCn172/P+hwHgDgmPETqPh8jBs9B7bm+ ZlcVrKYicguOtFzp4/vfV2dYfU10Ntcmg4rHVlya4w5k0ZL2u/SirGVJKuFMnmHhcyF+ ggneE6PxhcUxIjDs2ONGeNk/eQANvZBy96H+vquKqgdaNj+i3u8/tEkundR5iAtqBPPB dlcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=44uRkWGk/Osvmk24aNdLebhqCx/Gifs6WBek1wZDfO8=; b=SsyT8Vpyj+i/Jzgr5WzhcCEi8LMZ3gPI0K03ETHBSkXFsdK9jYmcBZ88gU617mJhq2 HSpgovIiYuQMF6ELR3Le32YE1LMtqk2vFJn8v3nbXYlfbAwpSWJIh0HvOERF2nmC5Xb/ QBFt6AifeijKIMdxi5BkEr3V7cIPer6rG2Cg4tZixyFjZjjpPEZNFsq9EzhQmxHSNk96 qFQzttlXL/eJUFG9jxZajQZaQASWEcsWyNvyhxhh+qqsNF4iaqtPYbCze0s3L5mBZQ+8 tWhcFGiTZ7adodk4y4646ETOD1QVPN299zp7y2C6ROm3kwNUhNQ4GwNnU0zhEMalpEqO 64Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EJsKreuL; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1-v6si15202669pge.80.2018.07.02.15.34.37; Mon, 02 Jul 2018 15:34:37 -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 header.s=google header.b=EJsKreuL; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932458AbeGBWef (ORCPT + 31 others); Mon, 2 Jul 2018 18:34:35 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34531 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753635AbeGBWdg (ORCPT ); Mon, 2 Jul 2018 18:33:36 -0400 Received: by mail-pf0-f193.google.com with SMTP id e10-v6so4033pfn.1 for ; Mon, 02 Jul 2018 15:33:36 -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=44uRkWGk/Osvmk24aNdLebhqCx/Gifs6WBek1wZDfO8=; b=EJsKreuLczzPxxAeQS9U4zc42OStBcWtV3mG5AtxdY4SiLAO2PnVUq3GAUizBO1Enm D9p3Mtz/f6Jy6HHYXEi6CIgtI8oTug41GeHaAue5xdq/4HF4Q2b5iUSXXw/mz3tKZpyq ANE35Koraq1X+XhyRcDJyFeQwMe2L5+XdZG0Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=44uRkWGk/Osvmk24aNdLebhqCx/Gifs6WBek1wZDfO8=; b=lxF1+HfSMhCXM5OZyZXybCNh8gsFdoP1KwmKHNqRVICcZkb58+S8GXLLvcZd9rDiAL f1unaJxP1nBOKCGOUz/ay4noHNYz8c5FWIxNOGcvHVQSCsFGS9NeWZsPr0QUjkxNHZoc +mrG/C9/MubV5jvE76gQQ8ybyxa7p2e0bknsY+Kx1M9yvOTYTNQy0bJMcbDLZnjb4PRt BWm1JbKv8AuceUqNNwWHJ3fs0hpC5TTepowT3jl5Yzchv4VS29g2VcX2pesyOJ6Qizcq vn8aS5i2pnRGoEfG+Ro5ewaRHoOhVpmHeNgMevjSyLkNcuMOvCl1bFCsDjAfehgQFn/e XXnw== X-Gm-Message-State: APt69E30EitTVydY7sAfcKCS7QjrebV8aPC0FfUwg0HemAaWLigbc1u1 JzJZvTKxi4RRfeQWvayXTOV/Xg== X-Received: by 2002:a62:a8e:: with SMTP id 14-v6mr27103338pfk.57.1530570815969; Mon, 02 Jul 2018 15:33:35 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p11-v6sm21764132pgu.16.2018.07.02.15.33.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 15:33:34 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, acme@kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, mathieu.poirier@linaro.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/6] perf tools: Use ioctl to communicate driver configuration to kernel Date: Mon, 2 Jul 2018 16:33:25 -0600 Message-Id: <1530570810-28929-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530570810-28929-1-git-send-email-mathieu.poirier@linaro.org> References: <1530570810-28929-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 Following in the footsteps of what was done for filters, adding the necessary mechanic needed to push down driver specific configuration to the kernel using an ioctl. By proceeding this way PMU specific configuration can be communicated to each event. Signed-off-by: Mathieu Poirier --- include/uapi/linux/perf_event.h | 1 + tools/include/uapi/linux/perf_event.h | 1 + tools/perf/util/evsel.c | 7 +++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 10 insertions(+) -- 2.7.4 diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index b8e288a1f740..b5b3241877df 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -460,6 +460,7 @@ struct perf_event_query_bpf { #define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32) #define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *) #define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *) +#define PERF_EVENT_IOC_SET_DRV_CONFIG _IOW('$', 12, char *) enum perf_event_ioc_flags { PERF_IOC_FLAG_GROUP = 1U << 0, diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h index b8e288a1f740..b5b3241877df 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -460,6 +460,7 @@ struct perf_event_query_bpf { #define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32) #define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *) #define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *) +#define PERF_EVENT_IOC_SET_DRV_CONFIG _IOW('$', 12, char *) enum perf_event_ioc_flags { PERF_IOC_FLAG_GROUP = 1U << 0, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 94fce4f537e9..534aca4c642c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1162,6 +1162,13 @@ static int perf_evsel__append_filter(struct perf_evsel *evsel, return -1; } +int perf_evsel__apply_drv_config(struct perf_evsel *evsel, const char *config) +{ + return perf_evsel__run_ioctl(evsel, + PERF_EVENT_IOC_SET_DRV_CONFIG, + (void *)config); +} + int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter) { return perf_evsel__append_filter(evsel, "(%s) && (%s)", filter); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index d277930b19a1..0f671bd2a988 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -271,6 +271,7 @@ 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, const char *filter); +int perf_evsel__apply_drv_config(struct perf_evsel *evsel, const char *config); int perf_evsel__enable(struct perf_evsel *evsel); int perf_evsel__disable(struct perf_evsel *evsel); From patchwork Mon Jul 2 22:33:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 140852 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp464671ljj; Mon, 2 Jul 2018 15:33:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpejKIymlX0wNKd6kuETMQq8o07L5I9SpSRM27CS8FNe5A2fbKsFa8e9a8XS06G6OhZrPewH X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr14890146pla.52.1530570824366; Mon, 02 Jul 2018 15:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530570824; cv=none; d=google.com; s=arc-20160816; b=M/eQXJ5vNo4hO+FCmLxuWFlNRLrKTQBIX45mGTMaKdbCKhaEeVQFyubsuhovFnl5wy 9tlJ1nqc4RvMMje2lYE7UPAKBBSS5ddTi7QZzqmvArIDwx1u5u1OnueDhu/72zEd+C1E V/iyS9AJuMkyAQXe2r9UKxseGvl3wWZEOhx+MOabf8c74wiEw9BAQVM0VKGZuudCdy6q kw1nMJZhjt4xSHM+uVHst1fa+IRs1dQuuu1ukjA0BeDVXIGwaxpMY/d73w4otRo6xa5P qvT18XuWUc8Z9BP6HPFtdeiKICmjmzl5irX8bJPUdsmKCcOE/crz7CVKqh6FtQyZs0Df aavg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=DQAmyMFajI++8HwoDa2U9XFg2UmDhXlRNwslkHRjsDM=; b=rqBKn9o8ErkB6iQflk6MN7fnK27Zfb5J/Qxmivu6Pvg4LxeNDUhOgJ0AN51gyLktRa KudceodmDrkyfeeWm79i5rkvyhi1Wg3jQ2tn1aKTkrJ5+7AjDPxYAn87egzjH1WD083m gfNgpV08FLPg0rdXUXs7upgY75DVIpZXHGYTCLh1UTvMTvVY+bgarT6peQUIY9lsMYRF p57LUfMRwCK9A+G5KvR0ZlB+JZObd8PqTiOsDeJMfMxSoq+wamNwSq5N7+PjQ6dpDZ9A Stot+SEgVObDUHHZR5MU4Ent7ri+W+drnL9YUb5iJwvs0p00Ufyjn65G2eDyU+cxG3vM Utyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B9iJPEF9; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s25-v6si15325273pgd.188.2018.07.02.15.33.44; Mon, 02 Jul 2018 15:33:44 -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 header.s=google header.b=B9iJPEF9; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932323AbeGBWdl (ORCPT + 31 others); Mon, 2 Jul 2018 18:33:41 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35392 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932100AbeGBWdi (ORCPT ); Mon, 2 Jul 2018 18:33:38 -0400 Received: by mail-pf0-f196.google.com with SMTP id z9-v6so2053pfh.2 for ; Mon, 02 Jul 2018 15:33:38 -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=DQAmyMFajI++8HwoDa2U9XFg2UmDhXlRNwslkHRjsDM=; b=B9iJPEF9XQXHuelfEi4/d9Hq5rjgt9W7TwvbSTapRurTpsFC9dODOqp3eqL2VsHqPD YeEfFT//XlDlhY9sFRnUAAOa99xyIo5rveYJsEnsXiAdFjSQa/JEHbg415PgRYx/QbV+ 6AsuDVTXjYwc+aC8Nz+eyVNvCGprL0Fi0HNWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DQAmyMFajI++8HwoDa2U9XFg2UmDhXlRNwslkHRjsDM=; b=SBc8C9It2OHc5H6YZgfFqsNfsk4dfw2uZgnYm/WxtPF5sgcw0u/yfL2FjSjUQVS+uf 5k9LZeJGajFHcnKI8BnevXHccHCJWrq7fqZlTBLZ4yH1M7MJgJJTOuzynjxTQ2/BI8N1 wwmXEeq7JOjLqtHHaj0NsluoGOzWQ2CdddaFA/0OlXD5QF3mPZGIMCe0F9K/e8rDM5JI bdxr7OKZ5U3ZkPU+sb8r5Rug0FxS6RgXQhdx5sdPhHaNrd95D71G4FFutgwbFr6RZa6Q VRzHJ+v8Rm4GSBIe9NDuQ8lsW/HNb0vp0iE19XKPX6s23nrv+tLao24WB0PiuChdxGn9 LlFA== X-Gm-Message-State: APt69E1PXa12MHEkKvg4Ph33t58QvktxS8J6ftIVzNbwqjs2WcyZNJx0 clv60ZKX0vpce6KD7jUFieunUQ== X-Received: by 2002:a62:df82:: with SMTP id d2-v6mr26302759pfl.189.1530570818156; Mon, 02 Jul 2018 15:33:38 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p11-v6sm21764132pgu.16.2018.07.02.15.33.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 15:33:37 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, acme@kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, mathieu.poirier@linaro.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/6] perf tools: Make perf_evsel accessible to PMU driver configuration code Date: Mon, 2 Jul 2018 16:33:26 -0600 Message-Id: <1530570810-28929-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530570810-28929-1-git-send-email-mathieu.poirier@linaro.org> References: <1530570810-28929-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 Make structure perf_evsel available to the PMU driver configuration code. That way function perf_evsel__apply_drv_config() can be used from within that code and information pertaining to the 'perf_evsel_config_term' is still available. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 22 +++++++++++++++++++++- tools/perf/arch/arm/util/cs-etm.h | 3 ++- tools/perf/util/drv_configs.c | 30 +++++++----------------------- tools/perf/util/pmu.h | 3 ++- 4 files changed, 32 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 2f595cd73da6..d8081c2e6d44 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -635,7 +635,7 @@ static int __printf(2, 3) cs_device__print_file(const char *name, const char *fm return ret; } -int cs_etm_set_drv_config(struct perf_evsel_config_term *term) +static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) { int ret; char enable_sink[ENABLE_SINK_MAX]; @@ -649,3 +649,23 @@ int cs_etm_set_drv_config(struct perf_evsel_config_term *term) return 0; } + +int cs_etm_set_drv_config(struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term) +{ + int err = 0; + struct perf_evsel_config_term *term; + + list_for_each_entry(term, &evsel->config_terms, list) { + if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) + continue; + + err = cs_etm_set_drv_config_term(term); + if (err) { + *err_term = term; + break; + } + } + + return err; +} diff --git a/tools/perf/arch/arm/util/cs-etm.h b/tools/perf/arch/arm/util/cs-etm.h index 1a12e64f5127..a3f8dde6ccef 100644 --- a/tools/perf/arch/arm/util/cs-etm.h +++ b/tools/perf/arch/arm/util/cs-etm.h @@ -10,6 +10,7 @@ #include "../../util/evsel.h" struct auxtrace_record *cs_etm_record_init(int *err); -int cs_etm_set_drv_config(struct perf_evsel_config_term *term); +int cs_etm_set_drv_config(struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term); #endif diff --git a/tools/perf/util/drv_configs.c b/tools/perf/util/drv_configs.c index eec754243f4d..f7c1bcf08549 100644 --- a/tools/perf/util/drv_configs.c +++ b/tools/perf/util/drv_configs.c @@ -25,7 +25,6 @@ perf_evsel__apply_drv_configs(struct perf_evsel *evsel, { bool found = false; int err = 0; - struct perf_evsel_config_term *term; struct perf_pmu *pmu = NULL; while ((pmu = perf_pmu__scan(pmu)) != NULL) @@ -34,29 +33,14 @@ perf_evsel__apply_drv_configs(struct perf_evsel *evsel, break; } - list_for_each_entry(term, &evsel->config_terms, list) { - if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) - continue; + /* + * No need to continue if we didn't get a match or if there is no + * driver configuration function for this PMU. + */ + if (!found || !pmu->set_drv_config) + return err; - /* - * 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; + return pmu->set_drv_config(evsel, err_term); } int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 76fecec7b3f9..47f44394042b 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -29,7 +29,8 @@ 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); + int (*set_drv_config) (struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term); }; struct perf_pmu_info { From patchwork Mon Jul 2 22:33:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 140855 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp465037ljj; Mon, 2 Jul 2018 15:34:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJy4ODoIB5zXpMNUM0wF1DdpFKW1B6wguOP10oLZ1PiruyYduqTWZeC2e/tfS2jZlBHupv3 X-Received: by 2002:a63:b305:: with SMTP id i5-v6mr23361076pgf.370.1530570858535; Mon, 02 Jul 2018 15:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530570858; cv=none; d=google.com; s=arc-20160816; b=y7UgpP6kMBxshTbUeOPEMnCwkAYAqsn0/sOB9ONUCYZ2u+mA9StZIkc0L6T+P2Zn27 2g1RV8D9ZVxtuhj8KmnnFhcSirmqILPpULDcylGX2bhi51Q/E2ri59b2BSvetrZcMhyt rutw3YxBxECjWU9lE+uJMO8FmEiWak4XRdsNsz/D6c1dn9GqSRcSnJQ2hSfYDFmv5DJV aR6sYLb806njWrt8C2YsX1St/Tpyy2RR0mIQalqsanvJWAFHYWsxfTJWQFVygM7F+/AF Wp98zoaC6rF+4hAl+yj/ksw8Y9vHpJPfrTG1C/F0CRr3IXpkyyOan14ugO04HOBOohkP fR2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=OWMIpVbHHUucjZTQ8WkuficHw0asDAcRYsZ+36nc5jY=; b=Mobc576Q9r/4l1aGeNqPfkWlj0kzjpv455USWUBfVfRlUgadOVjDpSYRQ9iz3IxHKl hBcqqFzPB7ziaMmnrRdZ4DdrH71BL5ks2+Ls5lcerGRfjw+miZoUHVhU+VIs56w6UGJW yP3pS2xNAejbzBfeIHoBZ2SwJQR5iPwIiypDit6WT4bVj4Omco/ERD8HIGwmIanxBCSa lwcLEDnqNDjCu8bERbxlEeCzQT5HbkR7ZM7AGR2UE25HGngSa4u6+X8z9ERgFcaVI6Wz jLKohthrVB262f5lFOYtgwkzS+8TZTfSCAFedTzqr716Sqf4QXTbn5IEjYEiywT3i8NM dfAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XHLhyH2K; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1-v6si15202669pge.80.2018.07.02.15.34.18; Mon, 02 Jul 2018 15:34:18 -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 header.s=google header.b=XHLhyH2K; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932424AbeGBWeQ (ORCPT + 31 others); Mon, 2 Jul 2018 18:34:16 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43686 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932263AbeGBWdl (ORCPT ); Mon, 2 Jul 2018 18:33:41 -0400 Received: by mail-pl0-f65.google.com with SMTP id c41-v6so8581247plj.10 for ; Mon, 02 Jul 2018 15:33:40 -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=OWMIpVbHHUucjZTQ8WkuficHw0asDAcRYsZ+36nc5jY=; b=XHLhyH2KP3lLTK/guTRSVHiMbf778wKy4jaVyunMI8WBQGllgdtTd/Y0BCMRoWSqkY BNFNXKBqOarjdxxxS8gPKE+vWLZsU5E9SsS24Q6gOc06ncho1aPEW6DQRtyhKug5co81 JTOUFAw5bkia7Q9PjEs9YYOOVErfWmtp1iJ1U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OWMIpVbHHUucjZTQ8WkuficHw0asDAcRYsZ+36nc5jY=; b=PPb57fBNGUYKe0GxhQ9Bs7t9noIz4ORVP8Hbo6dwFasB4HUCQpq7W6n9k8JbxARUqV yoXdgSzuilCF8R2Rt9BSkhV6AGCFYuBR5pW8o9B2sTa9WQGHCce6geYpbz6ZHxc72Iur sWpSDT39L8tkpvwilzevmeyGjXzoY6If3ZidaPPJUBwV8ypLdk441yfwws6epR5K8gk7 vMwbpU+4b4Nyzcn8XfErCP1/y4KxQvJfZ7WmrhTMuB6nntzY7yGAx6wgiwioht4Jd3Uz 0hox0CNT/5U+riuiYWaF1LHjY/1b6sUU7aVuSOKvEU+sFWYwth851CaJ0fVIbBNqUjRw X13A== X-Gm-Message-State: APt69E32AT0lkG/FiphzwTMo6EBDrA3c4BhkS5ghKCZRofVtqlY7FB9Y 5/wrDFVYDDktD/wOnDIbdI4Q9w== X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr27432493plo.91.1530570820538; Mon, 02 Jul 2018 15:33:40 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p11-v6sm21764132pgu.16.2018.07.02.15.33.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 15:33:39 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, acme@kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, mathieu.poirier@linaro.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/6] perf tools: Use ioctl function to send sink configuration to kernel Date: Mon, 2 Jul 2018 16:33:27 -0600 Message-Id: <1530570810-28929-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530570810-28929-1-git-send-email-mathieu.poirier@linaro.org> References: <1530570810-28929-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 Using sysFS to communicate sink information for a trace session doesn't work when more than one CPU is involved in the scenario. As such communicate the sink information to each event by using the SET_DRV_CONFIG ioctl command. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 54 ++++----------------------------------- 1 file changed, 5 insertions(+), 49 deletions(-) -- 2.7.4 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index d8081c2e6d44..cb0978eb7181 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -599,55 +599,10 @@ struct auxtrace_record *cs_etm_record_init(int *err) return NULL; } -static FILE *cs_device__open_file(const char *name) +static int cs_etm_set_drv_config_term(struct perf_evsel *evsel, + const char *term) { - struct stat st; - char path[PATH_MAX]; - const char *sysfs; - - sysfs = sysfs__mountpoint(); - if (!sysfs) - return NULL; - - snprintf(path, PATH_MAX, - "%s" CS_BUS_DEVICE_PATH "%s", sysfs, name); - - if (stat(path, &st) < 0) - return NULL; - - return fopen(path, "w"); - -} - -static int __printf(2, 3) cs_device__print_file(const char *name, const char *fmt, ...) -{ - va_list args; - FILE *file; - int ret = -EINVAL; - - va_start(args, fmt); - file = cs_device__open_file(name); - if (file) { - ret = vfprintf(file, fmt, args); - fclose(file); - } - va_end(args); - return ret; -} - -static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) -{ - int ret; - char enable_sink[ENABLE_SINK_MAX]; - - snprintf(enable_sink, ENABLE_SINK_MAX, "%s/%s", - term->val.drv_cfg, "enable_sink"); - - ret = cs_device__print_file(enable_sink, "%d", 1); - if (ret < 0) - return ret; - - return 0; + return perf_evsel__apply_drv_config(evsel, term); } int cs_etm_set_drv_config(struct perf_evsel *evsel, @@ -660,7 +615,8 @@ int cs_etm_set_drv_config(struct perf_evsel *evsel, if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) continue; - err = cs_etm_set_drv_config_term(term); + err = cs_etm_set_drv_config_term(evsel, + term->val.drv_cfg); if (err) { *err_term = term; break; From patchwork Mon Jul 2 22:33:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 140853 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp464767ljj; Mon, 2 Jul 2018 15:33:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLo1cPyHed0ZPWpRtwpKcAlFp7uck76xkG0/iTEeYt3iUFlSUQEdyJ0yp0QruGV1dnsUVMn X-Received: by 2002:a63:3201:: with SMTP id y1-v6mr23621293pgy.419.1530570831720; Mon, 02 Jul 2018 15:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530570831; cv=none; d=google.com; s=arc-20160816; b=TD8dETZSUPVVhwMYsDZwZoQrCwqw10POul8aae4DWeCyS0tjkWNASZ3Vg8yN7im9Qn zqNZhsELcVQDURPPYqMEphtF6nxY7IfxbV56FSsKVfVrJeVYy/fBSULbMhMfHkuE+2Uv Q6AKVVw08kmBLxPfrxcBqTMYBG6nMTKw7aiM6GGgAng/0yhgJLXa9mK6r2P4Jj5mcQdy 0e1cng3t5Zjo5Sv3AB2dKqwu1ZpyaiwtETVNBqIgEJ5Ne25Rxb+iWk7et+Tpy48oCn22 VbU8+EuoY01mp1/+je9+T/87iNxWmw9WS9r599wajVriQBfX1r61eT7KBKs6y+G3po8d 2gjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LYBWjD9MwZq6AeXds2cnbJ8nNRd/Ae3mKj4z54DE1Zs=; b=OjuyWqBxDHusEbjCwxv1CC514eyHCA5RPxBKHcCg0iwUF4kAGnYpzrINPxCcDxvt8c pJ2RkeOy56lgIxQzqntULP8tbY6hQpa16ZptVWc5eqAEWhwpr9vN4VBoyMGQrnESkOuD 1rSVcAnKJoCNnU7Jwi2st3DGA7TQxzfzbo+D15gVxsSp0bDrzC17Bhjj2i7YfWJq2BOP XDv1ypnBKaHl8UFyMKasy2c4TpHOBimgEzkIGmA4sMKjxqP01sYYxDu9oKF90GtzNeUz kTID6c19v7OjEXMkfI47T9VXuKW42nyygBEEoEsD0ztn0O9Rb6eG3Z9JW9YjyOb3JyS5 kf6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AtMKy3NQ; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s82-v6si17574261pfj.338.2018.07.02.15.33.51; Mon, 02 Jul 2018 15:33:51 -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 header.s=google header.b=AtMKy3NQ; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932379AbeGBWds (ORCPT + 31 others); Mon, 2 Jul 2018 18:33:48 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43689 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932100AbeGBWdn (ORCPT ); Mon, 2 Jul 2018 18:33:43 -0400 Received: by mail-pl0-f65.google.com with SMTP id c41-v6so8581279plj.10 for ; Mon, 02 Jul 2018 15:33:43 -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=LYBWjD9MwZq6AeXds2cnbJ8nNRd/Ae3mKj4z54DE1Zs=; b=AtMKy3NQmBdR9DRsALEIXaFSpIUgdc/SJ8gjwuATA71vLVImd02gY8iqPxZ+lzyH4c RekUEJmI3/Zb0q5IqvJ0Bw1x+73Tq+SYyPvCKR9bdKteSheDI6PMB4+7B6AUVdP4af0i qXPwUL6fdrsUn9rQI2ij7H1+EwhH9MTYTLxIk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LYBWjD9MwZq6AeXds2cnbJ8nNRd/Ae3mKj4z54DE1Zs=; b=t0ApM0VcHfMldFrcTyRjlyKHcrRmsuI+Z6ARQTjxiISEZvAdGSwqerKs5MiXwcGLif 0GvAc7h60F5ANdkeEQDV6w/gc2cCTW0S+AWG2SVLnsGFB9/cLoQFptQ+gOK3wfvN71TJ 7JyH+NuC1zvJVNbp2XklqH4khWFN+wIyo7ooxibe2Na0Y2/gLd/IYMscupHNpn8mrVL3 z1fcA1u3kpXpjOf8yW485wS5gH22/mKa7QnCRj3bM+j1WFWjbHmoBl/bZPWh9lJxRnxo /NfAyf3ByLSkRIZqRchCFa4yyoNHWFRTIPLeQrIgCoTx/fAa3j0TNfZpyaWuXdW132Tl uKcQ== X-Gm-Message-State: APt69E0T74wQyBkP/j0QUWr0MP6t5+zaihuZ1J63Nyo067j0zq+WqAy1 +U+I8aw7MXW8ZBn2NnVbFbVp9Q== X-Received: by 2002:a17:902:6ac7:: with SMTP id i7-v6mr28197745plt.288.1530570822617; Mon, 02 Jul 2018 15:33:42 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p11-v6sm21764132pgu.16.2018.07.02.15.33.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 15:33:41 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, acme@kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, mathieu.poirier@linaro.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/6] perf/aux: Make perf_event accessible to setup_aux() Date: Mon, 2 Jul 2018 16:33:28 -0600 Message-Id: <1530570810-28929-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530570810-28929-1-git-send-email-mathieu.poirier@linaro.org> References: <1530570810-28929-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 It can be advantagous to have access to all the information conveyed by a perf_event when setting up the AUX buffer, as it is the case when dealing with PMU specific driver configuration communicated to the kernel using an ioctl() call. As such simply replace the cpu information by the complete perf_event structure and change all affected customers. Signed-off-by: Mathieu Poirier --- arch/s390/kernel/perf_cpum_sf.c | 4 ++-- arch/x86/events/intel/bts.c | 4 +++- arch/x86/events/intel/pt.c | 5 +++-- drivers/hwtracing/coresight/coresight-etm-perf.c | 6 +++--- drivers/perf/arm_spe_pmu.c | 6 +++--- include/linux/perf_event.h | 2 +- kernel/events/ring_buffer.c | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c index 0292d68e7dde..e06daaa08894 100644 --- a/arch/s390/kernel/perf_cpum_sf.c +++ b/arch/s390/kernel/perf_cpum_sf.c @@ -1601,8 +1601,8 @@ static void aux_buffer_free(void *data) * * Return the private AUX buffer structure if success or NULL if fails. */ -static void *aux_buffer_setup(int cpu, void **pages, int nr_pages, - bool snapshot) +static void *aux_buffer_setup(struct perf_event *event, void **pages, + int nr_pages, bool snapshot); { struct sf_buffer *sfb; struct aux_buffer *aux; diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c index 24ffa1e88cf9..7139f6bf27ad 100644 --- a/arch/x86/events/intel/bts.c +++ b/arch/x86/events/intel/bts.c @@ -77,10 +77,12 @@ static size_t buf_size(struct page *page) } static void * -bts_buffer_setup_aux(int cpu, void **pages, int nr_pages, bool overwrite) +bts_buffer_setup_aux(struct perf_event *event, void **pages, + int nr_pages, bool overwrite) { struct bts_buffer *buf; struct page *page; + int cpu = event->cpu; int node = (cpu == -1) ? cpu : cpu_to_node(cpu); unsigned long offset; size_t size = nr_pages << PAGE_SHIFT; diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 8d016ce5b80d..8f4c98fdd03c 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -1104,10 +1104,11 @@ static int pt_buffer_init_topa(struct pt_buffer *buf, unsigned long nr_pages, * Return: Our private PT buffer structure. */ static void * -pt_buffer_setup_aux(int cpu, void **pages, int nr_pages, bool snapshot) +pt_buffer_setup_aux(struct perf_event *event, void **pages, + int nr_pages, bool snapshot) { struct pt_buffer *buf; - int node, ret; + int node, ret, cpu = event->cpu; if (!nr_pages) return NULL; diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 677695635211..0f5e03e4df22 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -181,15 +181,15 @@ static void etm_free_aux(void *data) schedule_work(&event_data->work); } -static void *etm_setup_aux(int event_cpu, void **pages, +static void *etm_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) { - int cpu; + int cpu = event->cpu; cpumask_t *mask; struct coresight_device *sink; struct etm_event_data *event_data = NULL; - event_data = alloc_event_data(event_cpu); + event_data = alloc_event_data(cpu); if (!event_data) return NULL; INIT_WORK(&event_data->work, free_event_data); diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index 54ec278d2fc4..4dcd7bf14dcc 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -824,10 +824,10 @@ static void arm_spe_pmu_read(struct perf_event *event) { } -static void *arm_spe_pmu_setup_aux(int cpu, void **pages, int nr_pages, - bool snapshot) +static void *arm_spe_pmu_setup_aux(struct perf_event *event, void **pages, + int nr_pages, bool snapshot) { - int i; + int i, cpu = event->cpu; struct page **pglist; struct arm_spe_pmu_buf *buf; diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 1fa12887ec02..4d9c8f30ca6c 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -409,7 +409,7 @@ struct pmu { /* * Set up pmu-private data structures for an AUX area */ - void *(*setup_aux) (int cpu, void **pages, + void *(*setup_aux) (struct perf_event *event, void **pages, int nr_pages, bool overwrite); /* optional */ diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 5d3cf407e374..4c96c7575224 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -648,7 +648,7 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event, goto out; } - rb->aux_priv = event->pmu->setup_aux(event->cpu, rb->aux_pages, nr_pages, + rb->aux_priv = event->pmu->setup_aux(event, rb->aux_pages, nr_pages, overwrite); if (!rb->aux_priv) goto out; From patchwork Mon Jul 2 22:33:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 140854 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp464897ljj; Mon, 2 Jul 2018 15:34:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJwqwiYpKT3p3+EtVtogFw6A6z1eC/4ZuoBB7NIa3zPZshNGLMmDq/qxD/vaZ/1G8TsMXDH X-Received: by 2002:a17:902:2d24:: with SMTP id o33-v6mr27723317plb.14.1530570844667; Mon, 02 Jul 2018 15:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530570844; cv=none; d=google.com; s=arc-20160816; b=Kr/JDwBTP5YdYYli7mR4Ir7RsG0iwAW8dEfQ9y9dxCHYOV17DGHhR3v5J8TVGoj50n HO9qzzAVfHOliL99P/o/6GogmqVDO27QttJEaKduv9gMOS10oAzIy5axeBCVF2rhiE28 n9hmRigBce34n10VMkiya39S0BwtvYFGNSLIF9KJQkCWaCae9lGRXzsJSdKcTXx/yXKW Y0O/8w0TEuPmaNNyTmCUW/uIpTPz+uhZoS7k8IVUf3/xajbfihz2W7WFjfGOz4bmRjqD LmqWhEOmt6wWrs0+jRJl98rZecgwXAkXh+DlWyZ7CvDC8BYP5fX5j+N7Bjfzs2U6CLR9 1ApA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Q++a8pnM3vWZhHlmb65vGbt0ms5aoh48STg7RZti8Mk=; b=szRxa9lQjeFx+WrryIuduYyFakd3zT4/9GrYV4q1t0WWxUc/9RAzlC0GARLbEZV506 ZiO1cXJ2SnTb0RLpssUvweC6W+fnhKaQ60AVZIrNWVr9awxHUyisRSv4xl+eSxsBXtde O3k5/svFaojcdRLF46dpLBJ18zSnJFDZX7lWCxwY7mjxB5KBaVJHA50o7AtrPkaXKrkJ kjzr4NPTYmbH5y0E8lyWng8jMtT7KacKbzLdMK+4QnXH34BWYjodmsD8B9pf2Jvohvbs dYP9q7gWDyF047c7iBxnOw2WmL2jghTA5dbTfpBrqlrWjhOjChFJY/Rg5RX5LgCpCaOj BsdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TsIEZLVF; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s82-v6si17574261pfj.338.2018.07.02.15.34.04; Mon, 02 Jul 2018 15:34:04 -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 header.s=google header.b=TsIEZLVF; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932399AbeGBWeC (ORCPT + 31 others); Mon, 2 Jul 2018 18:34:02 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:39728 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932338AbeGBWdq (ORCPT ); Mon, 2 Jul 2018 18:33:46 -0400 Received: by mail-pl0-f65.google.com with SMTP id s24-v6so8581818plq.6 for ; Mon, 02 Jul 2018 15:33:45 -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=Q++a8pnM3vWZhHlmb65vGbt0ms5aoh48STg7RZti8Mk=; b=TsIEZLVFXhRARBzI94DbO92h64u/7wC3/2MCEunX486sjOmqxce56QlxuOXVCQyw1s cHDmKoZrOYg1z0B0fAYCtvclXfSx4ivtEitkKUmzknwWz4IQ094xi83UNvQHtscVFWeL 7p3w1APQ+OlYxXibjMxK9jEzHxKTKe9Oc66m4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q++a8pnM3vWZhHlmb65vGbt0ms5aoh48STg7RZti8Mk=; b=s6V9t6TWCcciU3kUdF13TzLHG3E4bCuAqBBnMk6bt9GdLBLcdtgu9D5YHfzxNWQSHJ zgJjd5srDFI+Sq/sqHAf/0tMshw/LliCkM/klMZrjLFcYl3qmm6Alcs0KMvK3YjD1JGO ais52/cHetqZfq05dmUjNlfhdSG9k30Y+bprJqtQAVtxEceHIywjUHTxKBJA9FxclGsI yPaFi+O4kT/coLPEPdGfYfhqO4s1tE04piLwWw+vjgVyWt2mjA+v9ODaIXbu29rfYzG1 +yvqY8WP2PyUI6ZKE+Ww5ljbOfUNHyfjqrpDIQ0Gz/q7SBxeCKTI8zNRp2o4xSNJZcUl Qseg== X-Gm-Message-State: APt69E3FWrZNm1Wwd2R3zdulQorgNa9PZci1bf7AMRiVv3AVN2OV31pE rMyG6mFp7K1wHhi94LgEy2D0Tw== X-Received: by 2002:a17:902:1127:: with SMTP id d36-v6mr27855681pla.267.1530570824834; Mon, 02 Jul 2018 15:33:44 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p11-v6sm21764132pgu.16.2018.07.02.15.33.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 15:33:43 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, acme@kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, mathieu.poirier@linaro.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/6] perf/core: Use ioctl to communicate driver configuration to kernel Date: Mon, 2 Jul 2018 16:33:29 -0600 Message-Id: <1530570810-28929-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530570810-28929-1-git-send-email-mathieu.poirier@linaro.org> References: <1530570810-28929-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 follows what has been done for filters by adding an ioctl() option to communicate to the kernel arbitrary PMU specific configuration that don't fit in the conventional struct perf_event_attr to the kernel. Signed-off-by: Mathieu Poirier --- include/linux/perf_event.h | 54 ++++++++++++++++++++++ kernel/events/core.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) -- 2.7.4 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 4d9c8f30ca6c..6e06b63c262f 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -178,6 +178,12 @@ struct hw_perf_event { /* Last sync'ed generation of filters */ unsigned long addr_filters_gen; + /* PMU driver configuration */ + void *drv_config; + + /* Last sync'ed generation of driver config */ + unsigned long drv_config_gen; + /* * hw_perf_event::state flags; used to track the PERF_EF_* state. */ @@ -447,6 +453,26 @@ struct pmu { * Filter events for PMU-specific reasons. */ int (*filter_match) (struct perf_event *event); /* optional */ + + /* + * Valiate complex PMU configuration that don't fit in the + * perf_event_attr struct. Returns a PMU specific pointer or an error + * value < 0. + * + * As with addr_filters_validate(), runs in the context of the ioctl() + * process and is not serialized with the rest of the PMU callbacks. + */ + void *(*drv_config_validate) (struct perf_event *event, + char *config_str); + + /* Synchronize PMU driver configuration */ + void (*drv_config_sync) (struct perf_event *event); + + /* + * Release PMU specific configuration acquired by + * drv_config_validate() + */ + void (*drv_config_free) (void *drv_data); }; enum perf_addr_filter_action_t { @@ -489,6 +515,11 @@ struct perf_addr_filters_head { unsigned int nr_file_filters; }; +struct perf_drv_config { + void *drv_config; + raw_spinlock_t lock; +}; + /** * enum perf_event_state - the states of a event */ @@ -668,6 +699,10 @@ struct perf_event { unsigned long *addr_filters_offs; unsigned long addr_filters_gen; + /* PMU driver specific configuration */ + struct perf_drv_config drv_config; + unsigned long drv_config_gen; + void (*destroy)(struct perf_event *); struct rcu_head rcu_head; @@ -1234,6 +1269,13 @@ static inline bool has_addr_filter(struct perf_event *event) return event->pmu->nr_addr_filters; } +static inline bool has_drv_config(struct perf_event *event) +{ + return event->pmu->drv_config_validate && + event->pmu->drv_config_sync && + event->pmu->drv_config_free; +} + /* * An inherited event uses parent's filters */ @@ -1248,7 +1290,19 @@ perf_event_addr_filters(struct perf_event *event) return ifh; } +static inline struct perf_drv_config * +perf_event_get_drv_config(struct perf_event *event) +{ + struct perf_drv_config *cfg = &event->drv_config; + + if (event->parent) + cfg = &event->parent->drv_config; + + return cfg; +} + extern void perf_event_addr_filters_sync(struct perf_event *event); +extern void perf_event_drv_config_sync(struct perf_event *event); extern int perf_output_begin(struct perf_output_handle *handle, struct perf_event *event, unsigned int size); diff --git a/kernel/events/core.c b/kernel/events/core.c index 8f0434a9951a..701839866789 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2829,6 +2829,29 @@ void perf_event_addr_filters_sync(struct perf_event *event) } EXPORT_SYMBOL_GPL(perf_event_addr_filters_sync); +/* + * PMU driver configuration works the same way as filter management above, + * but without the need to deal with memory mapping. Driver configuration + * arrives through the SET_DRV_CONFIG ioctl() where it is validated and applied + * to the event. When the PMU is ready it calls perf_event_drv_config_sync() to + * bring the configuration information within reach of the PMU. + */ +void perf_event_drv_config_sync(struct perf_event *event) +{ + struct perf_drv_config *drv_config = perf_event_get_drv_config(event); + + if (!has_drv_config(event)) + return; + + raw_spin_lock(&drv_config->lock); + if (event->drv_config_gen != event->hw.drv_config_gen) { + event->pmu->drv_config_sync(event); + event->hw.drv_config_gen = event->drv_config_gen; + } + raw_spin_unlock(&drv_config->lock); +} +EXPORT_SYMBOL_GPL(perf_event_drv_config_sync); + static int _perf_event_refresh(struct perf_event *event, int refresh) { /* @@ -4410,6 +4433,7 @@ static bool exclusive_event_installable(struct perf_event *event, static void perf_addr_filters_splice(struct perf_event *event, struct list_head *head); +static void perf_drv_config_splice(struct perf_event *event, void *drv_data); static void _free_event(struct perf_event *event) { @@ -4440,6 +4464,7 @@ static void _free_event(struct perf_event *event) perf_event_free_bpf_prog(event); perf_addr_filters_splice(event, NULL); kfree(event->addr_filters_offs); + perf_drv_config_splice(event, NULL); if (event->destroy) event->destroy(event); @@ -5002,6 +5027,8 @@ static inline int perf_fget_light(int fd, struct fd *p) static int perf_event_set_output(struct perf_event *event, struct perf_event *output_event); static int perf_event_set_filter(struct perf_event *event, void __user *arg); +static int perf_event_set_drv_config(struct perf_event *event, + void __user *arg); static int perf_event_set_bpf_prog(struct perf_event *event, u32 prog_fd); static int perf_copy_attr(struct perf_event_attr __user *uattr, struct perf_event_attr *attr); @@ -5088,6 +5115,10 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon return perf_event_modify_attr(event, &new_attr); } + + case PERF_EVENT_IOC_SET_DRV_CONFIG: + return perf_event_set_drv_config(event, (void __user *)arg); + default: return -ENOTTY; } @@ -9086,6 +9117,85 @@ static int perf_event_set_filter(struct perf_event *event, void __user *arg) return ret; } +static void perf_drv_config_splice(struct perf_event *event, void *drv_data) +{ + unsigned long flags; + void *old_drv_data; + + if (!has_drv_config(event)) + return; + + /* Children take their configuration from their parent */ + if (event->parent) + return; + + raw_spin_lock_irqsave(&event->drv_config.lock, flags); + + old_drv_data = event->drv_config.drv_config; + event->drv_config.drv_config = drv_data; + + raw_spin_unlock_irqrestore(&event->drv_config.lock, flags); + + event->pmu->drv_config_free(old_drv_data); +} + +static void perf_event_drv_config_apply(struct perf_event *event) +{ + unsigned long flags; + struct perf_drv_config *drv_config = perf_event_get_drv_config(event); + + /* Notify event that a new configuration is available */ + raw_spin_lock_irqsave(&drv_config->lock, flags); + event->drv_config_gen++; + raw_spin_unlock_irqrestore(&drv_config->lock, flags); +} + +static int +perf_event_process_drv_config(struct perf_event *event, char *config_str) +{ + int ret = -EINVAL; + void *drv_data; + + /* Make sure ctx.mutex it held */ + lockdep_assert_held(&event->ctx->mutex); + + /* Children take their configuration from their parent */ + if (WARN_ON_ONCE(event->parent)) + goto out; + + drv_data = event->pmu->drv_config_validate(event, config_str); + if (!drv_data) + goto out; + if (IS_ERR(drv_data)) { + ret = PTR_ERR(drv_data); + goto out; + } + + perf_drv_config_splice(event, drv_data); + + perf_event_for_each_child(event, perf_event_drv_config_apply); + + ret = 0; +out: + return ret; +} + +static int perf_event_set_drv_config(struct perf_event *event, void __user *arg) +{ + int ret = -EINVAL; + char *config_str; + + config_str = strndup_user(arg, PAGE_SIZE); + if (IS_ERR(config_str)) + return PTR_ERR(config_str); + + if (has_drv_config(event)) + ret = perf_event_process_drv_config(event, config_str); + + kfree(config_str); + return ret; +} + /* * hrtimer based swevent callback */ From patchwork Mon Jul 2 22:33:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 140857 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp469961ljj; Mon, 2 Jul 2018 15:41:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfOi54Fue/sz9fTRDqgfwnanHov1ofKnB7aFydt+WitXxsqMDTSgyvQUUg37wP5xQ6gBJnz X-Received: by 2002:a17:902:5a4f:: with SMTP id f15-v6mr20559682plm.253.1530571291637; Mon, 02 Jul 2018 15:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530571291; cv=none; d=google.com; s=arc-20160816; b=k2lEUBdURnLAlAgG7bM+7XdLKg9wVc4zc15giqnVKDfzDJ7eWEFDWA05xkM0ubu19C vnb43pc17NzEq2BicSpUp8DQODfmx8VfJ6YdB+Mc9hDmmQFBcgZi9Nx3rAgkQBNZ3WWE GA/ceVLZw6GRS21tc/Gixl0V+4W3GQ4Ec/hutGQii9CPdI8LNjwSqLIs3bVpv7h7iJ5l KLWhxMfs6dwumeLYLpTVHyuf43dpkqluil5XuN6cTY3CJimBhux2d+DCNzpjFW53rZjZ cNBCKhPaYhMwIXa8WeBCcbwGIxt2BdD88/eseVY2TiXE5BPe6e+wSf2WZvqKIhFWwx8m /vLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MeRc7xJj3ZW4F+ziFAe3DIXl5dMAluw3Bs5u+H+VrdA=; b=uGDwViaKzR2fkpg4rJ9wOvJLrG4qNHQ4gzSweSpvZz7SSL6OLJiPlVK43wBLAUQzoL QIq8Lr9D6e+MYZpXKrfy47e9xaQVb8qKTh1mftkqwe8DmjwczYv8jtWOkDQfp9U5VXy4 ntLpeqkeN4qr5SyhcIVW1Qe2pdu4wXNKZuM8jhmoI+c0sOuQg22tjl5ozFS8uONCMCLg V+tDypvLiYqkMbPOxTwK8FbDbFHJ/AVbK9setbmMIZeo3u5u5TL2sk4KeoZLHFGn8h1p YBhQvD/6h+Lo3aenTtCnCjfKlXXAH6Yew5c75Yo82mwVSl8HzE8a3SpzvNnewONTwm2/ BAWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W0kO2NqS; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4-v6si14620627pgs.244.2018.07.02.15.41.31; Mon, 02 Jul 2018 15:41:31 -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 header.s=google header.b=W0kO2NqS; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932343AbeGBWl3 (ORCPT + 31 others); Mon, 2 Jul 2018 18:41:29 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:44074 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932100AbeGBWl2 (ORCPT ); Mon, 2 Jul 2018 18:41:28 -0400 Received: by mail-pg0-f68.google.com with SMTP id r1-v6so1098pgp.11 for ; Mon, 02 Jul 2018 15:41:28 -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=MeRc7xJj3ZW4F+ziFAe3DIXl5dMAluw3Bs5u+H+VrdA=; b=W0kO2NqSZVLscxE/sFSKBl1yVE7Bv51I4S47SM8GZXzO+J8YDCmVwG9/8fr0wtOD9o F1PUVruP2b/l/acc8/wboHLP1CuB6vmLVyqjagL/QchiajPqz/Utz8bB8b5NYe2O23hW tr/wsw/zKRqqYVUIEzGP/kVmyNBnee/ZDxY9o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MeRc7xJj3ZW4F+ziFAe3DIXl5dMAluw3Bs5u+H+VrdA=; b=Ca9Yr7OQnZTCKIXsoCvHnHdCPq4gYNvP5kQirEb94JdXFTOYiWdsimGdEMXslCtd5s G5OzrZAjZHv50bx2OcjtwN+I+ESfiQL0cufFZSlgHv4E1IZ3Uyg8T4M5/78oHFAfBNBK r6nHzkfGzEU2bV1iQgdlqkcnH4Vuu1YMHIN/VyKCnS7J1+d4LKmcVgU53VdL4mgYKGvO fiJJAN4P+f4fakC/JuBSllaESMcYLRryTERMA7XXCksx84fxHlbn0u1gH8u3qcjy21/P 7GWhDE8ciSv6N65TYmXXRIduyO/31rbvbjeNHjL8lGQrGTBpjKtpxw3eYVyw4AOQ96U1 M27g== X-Gm-Message-State: APt69E0VjXziTBD8grhIR657fR+DpMGK46xf/oGO2UYmQOEE4MhouQAE hfKi1zV7IvQItrVhGsHIbf0nzg== X-Received: by 2002:a62:1f8c:: with SMTP id l12-v6mr18551793pfj.143.1530570827112; Mon, 02 Jul 2018 15:33:47 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p11-v6sm21764132pgu.16.2018.07.02.15.33.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 15:33:46 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org, acme@kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, mathieu.poirier@linaro.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 6/6] coresight: Use PMU driver configuration for sink selection Date: Mon, 2 Jul 2018 16:33:30 -0600 Message-Id: <1530570810-28929-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530570810-28929-1-git-send-email-mathieu.poirier@linaro.org> References: <1530570810-28929-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 uses the PMU driver configuration API to select a sink for each event that is created (the old sysFS way of working is kept around for backward compatibility). By proceeding in this way a sink can be used by multiple sessions without having to play games with entries in sysFS. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm-perf.c | 128 ++++++++++++++++++++--- drivers/hwtracing/coresight/coresight-etm-perf.h | 10 ++ 2 files changed, 126 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 0f5e03e4df22..37c8b97d0449 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,8 @@ static struct pmu etm_pmu; static bool etm_perf_up; +#define CORESIGHT_DEVICE_MAX_NAME_LEN 256 + /** * struct etm_event_data - Coresight specifics associated to an event * @work: Handle to free allocated memory outside IRQ context. @@ -81,10 +84,29 @@ static int etm_addr_filters_alloc(struct perf_event *event) return 0; } +static int etm_drv_config_alloc(struct perf_event *event) +{ + char *sink; + int node = event->cpu == -1 ? -1 : cpu_to_node(event->cpu); + + sink = kzalloc_node(CORESIGHT_DEVICE_MAX_NAME_LEN, GFP_KERNEL, node); + if (!sink) + return -ENOMEM; + + if (event->parent) + memcpy(sink, event->parent->hw.addr_filters, + CORESIGHT_DEVICE_MAX_NAME_LEN); + + event->hw.drv_config = sink; + + return 0; +} + static void etm_event_destroy(struct perf_event *event) { kfree(event->hw.addr_filters); event->hw.addr_filters = NULL; + kfree(event->hw.drv_config); } static int etm_event_init(struct perf_event *event) @@ -100,6 +122,10 @@ static int etm_event_init(struct perf_event *event) if (ret) goto out; + ret = etm_drv_config_alloc(event); + if (ret) + goto out; + event->destroy = etm_event_destroy; out: return ret; @@ -181,6 +207,38 @@ static void etm_free_aux(void *data) schedule_work(&event_data->work); } +static struct coresight_device *etm_event_get_sink(struct perf_event *event) +{ + /* + * Try the preferred method first, i.e passing the sink information + * using the ioctl() method. + */ + if (event->hw.drv_config) { + struct device *dev; + struct coresight_device *sink; + + dev = bus_find_device_by_name(&coresight_bustype, NULL, + (char *)event->hw.drv_config); + if (dev) { + sink = to_coresight_device(dev); + /* Put reference from 'bus_find_device()' */ + put_device(dev); + return sink; + } + } + + /* + * No luck with the above method, so we are working with an older user + * space. See if a sink has been set using sysFS. If this is the case + * CPU-wide session will only be able to use a single sink. + * + * When operated from sysFS users are responsible to enable the sink + * while from perf, the perf tools will do it based on the choice made + * on the cmd line. As such the "enable_sink" flag in sysFS is reset. + */ + return coresight_get_enabled_sink(true); +} + static void *etm_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) { @@ -194,18 +252,10 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, return NULL; INIT_WORK(&event_data->work, free_event_data); - /* - * In theory nothing prevent tracers in a trace session from being - * associated with different sinks, nor having a sink per tracer. But - * until we have HW with this kind of topology we need to assume tracers - * in a trace session are using the same sink. Therefore go through - * the coresight bus and pick the first enabled sink. - * - * When operated from sysFS users are responsible to enable the sink - * while from perf, the perf tools will do it based on the choice made - * on the cmd line. As such the "enable_sink" flag in sysFS is reset. - */ - sink = coresight_get_enabled_sink(true); + perf_event_drv_config_sync(event); + + /* First get the sink to use for this event */ + sink = etm_event_get_sink(event); if (!sink) goto err; @@ -442,6 +492,57 @@ static void etm_addr_filters_sync(struct perf_event *event) filters->nr_filters = i; } +static const match_table_t config_tokens = { + { ETM_CFG_SINK, "%u.%s" }, + { ETM_CFG_NONE, NULL }, +}; + +static void *etm_drv_config_validate(struct perf_event *event, char *cstr) +{ + char *str, *to_parse, *sink = NULL; + int token, ret = -EINVAL; + substring_t args[MAX_OPT_ARGS]; + + to_parse = kstrdup(cstr, GFP_KERNEL); + if (!to_parse) + return ERR_PTR(-ENOMEM); + + while ((str = strsep(&to_parse, " ,\n")) != NULL) { + if (!*str) + continue; + + token = match_token(str, config_tokens, args); + switch (token) { + case ETM_CFG_SINK: + sink = kstrdup(str, GFP_KERNEL); + if (!sink) { + ret = -ENOMEM; + goto out; + } + break; + default: + goto out; + } + } + +out: + kfree(to_parse); + return sink ? sink : ERR_PTR(ret); +} + +static void etm_drv_config_sync(struct perf_event *event) +{ + struct perf_drv_config *drv_config = perf_event_get_drv_config(event); + + memcpy(event->hw.drv_config, drv_config->drv_config, + CORESIGHT_DEVICE_MAX_NAME_LEN); +} + +static void etm_drv_config_free(void *drv_data) +{ + kfree(drv_data); +} + int etm_perf_symlink(struct coresight_device *csdev, bool link) { char entry[sizeof("cpu9999999")]; @@ -486,6 +587,9 @@ static int __init etm_perf_init(void) etm_pmu.addr_filters_sync = etm_addr_filters_sync; etm_pmu.addr_filters_validate = etm_addr_filters_validate; etm_pmu.nr_addr_filters = ETM_ADDR_CMP_MAX; + etm_pmu.drv_config_validate = etm_drv_config_validate; + etm_pmu.drv_config_sync = etm_drv_config_sync; + etm_pmu.drv_config_free = etm_drv_config_free; ret = perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1); if (ret == 0) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 4197df4faf5e..175895c8d635 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -42,6 +42,16 @@ struct etm_filters { bool ssstatus; }; +enum etm_config_elem_type { + ETM_CFG_NONE = -1, + ETM_CFG_SINK, +}; + +struct etm_config_elem { + struct list_head entry; + enum etm_config_elem_type type; + void *config; +}; #ifdef CONFIG_CORESIGHT int etm_perf_symlink(struct coresight_device *csdev, bool link);