From patchwork Wed Jul 18 21:48:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142303 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022307ljj; Wed, 18 Jul 2018 14:48:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfabwXCsGnyn18hezSvZrurVP5f2u9aKmsyOK0fNman6YRdAg01GuteZ0EW4zrPPBi6G9Ac X-Received: by 2002:a63:dc17:: with SMTP id s23-v6mr7503548pgg.40.1531950498198; Wed, 18 Jul 2018 14:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950498; cv=none; d=google.com; s=arc-20160816; b=NVVAHhp7iRc7qYnLPMBSBrUNlGHjYikS7tvlr6Y9277F9yeLbKTUGeKBy+BmB34rs/ gtU2dHaguDlx11Y37veMty+u6tq7pxvDh8etfqncQXURH0tbaV7ZkB4XGOAypwVRNu75 vqylNRpoa/kE2ctE1fsqc5SRK/O+QcUrAgt+Zru5vtpnW6+oGZmdXSMHrsgwWJ+ntq8d UFa1/6l2qdR0c6+OjTjIJS9qjedueoEqyj6kP/T5fUFxNbN3HNbi76ohy4D3otLrKai2 dnHLt/1QAj34AkHZk2cbIhqZd239iZfxihnCLdpHMd/VYiPqRBC7bFHCMbeQm8teELif OEYA== 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=b+RIY2UuP5aJSr2EjMCmde75UASQQURVa37fsARUKY8=; b=ECe1bIK/ZFQwnEXTjDkv2j27k//STaVCtIlh4aDozm2TTP5QPykZhJYq/Ntpfle5hU xkCw8rsc9VS9FSp3mTdEm9+5O93a0vSiUzbo0xvT3fJjgaZQ6pGrEcZdYyT3rq0qiJ81 NaKOsK54D3N1QsH8Wz0MoRXRbhcp8wxe/OtvHAGctwE8FOw/lEzpCjAJzY2mfYcrnhbT qnKLAFBRPYLvK82X/XMHJddg5KECz5EjZugSR2mqO0AOXc9W/qdjZ3Jw0zE8RCpPdXbz agJBwc97naeHcY/mdEvFapKbeABgYKg1S7E7hOJO3gewUUQ3hbNzQNqY2wpMwcvHd8Po xesw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U+vKzZpJ; 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 143-v6si4674416pfa.178.2018.07.18.14.48.17; Wed, 18 Jul 2018 14:48: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=U+vKzZpJ; 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 S1730273AbeGRW2F (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:05 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:55107 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729218AbeGRW2E (ORCPT ); Wed, 18 Jul 2018 18:28:04 -0400 Received: by mail-it0-f66.google.com with SMTP id s7-v6so6291021itb.4 for ; Wed, 18 Jul 2018 14:48:13 -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=b+RIY2UuP5aJSr2EjMCmde75UASQQURVa37fsARUKY8=; b=U+vKzZpJlQlYHPJlmfZfZONwUe7bQOIGrdw+YxEVhLk1t8p0L9wNAH+GYzJQSPiTZ3 P1y+buF7Kh/q+IeOQXRpGOONg2UjxUNJugY+uPB7utMV3/fdi+qjAa9ZEguVhKTvDOK/ eTk4ljhFqoC/3YyZaDKXyJd8SnWXhnVNI78M4= 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=b+RIY2UuP5aJSr2EjMCmde75UASQQURVa37fsARUKY8=; b=PrilneLj8aQ4dmaFQevzBebCCzpsc+GkLKiRD1ZwC+roQhGvEcETGN65BUhT7Udvxc wJv5Wm5lSkEas64kWyClum4DOUw4qkaPL3Rty0MxdX+Z1nHRACKd+tYGOVq3T9XwX3AB LUSVuCYMMODhTBo6VltRQlMWmF/E2mq3VSZMdQhuwRm/QZ8shjvDxLTbJfpZz07FfCP2 B4CwhFIR4WtYUpg1UF4jVwdmnUAVvGH1jkjlfXjDViVzcFOYNWgPtXcDr0ImxpsIEA4v YhDdWZrtXtbE/EzHEFRyTn+MRu9uBaPrL37hh2oK0n2JQSnZ2JvKCtXeIi3LkEOAsQzf xlHA== X-Gm-Message-State: AOUpUlFRUo44LhGGc5Bjpk9lh1WUOUL+w19lqX5G66Vls29gzgkUfk67 gXUCv0V1v+j36/4TZmkl7SJGgQ== X-Received: by 2002:a02:105:: with SMTP id c5-v6mr6941852jad.139.1531950493405; Wed, 18 Jul 2018 14:48:13 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:12 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/7] perf: Introduce ioctl to communicate driver configuration to kernel Date: Wed, 18 Jul 2018 15:48:01 -0600 Message-Id: <1531950487-24554-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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 Adding a new IOCTL command to communicate PMU specific configuration to PMU kernel drivers. This can be anything a PMU might need for configuration that doesn't fit in the perf_event_attr structure, such as the CoreSight sink to use for a session. Signed-off-by: Mathieu Poirier --- include/uapi/linux/perf_event.h | 1 + tools/include/uapi/linux/perf_event.h | 1 + 2 files changed, 2 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, From patchwork Wed Jul 18 21:48:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142304 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022332ljj; Wed, 18 Jul 2018 14:48:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfB1SZewehioDfn7ne8/0vSMAnGSL5ATHEXioZZP6+UxSab6u/i5wI4GvUAbOhU0stKxmXb X-Received: by 2002:a63:555:: with SMTP id 82-v6mr7478192pgf.25.1531950500679; Wed, 18 Jul 2018 14:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950500; cv=none; d=google.com; s=arc-20160816; b=lvEe33PBDIR9ck0aH6M/nORWZrE+RytcEnQ+fO1EpM6mgvCGiSJ+ZbLA97bMfYlV4c i6rfkL4RBA13ya5Zi9UB/xFk3IN826kRWQonjCZfQT74YbLntd6ME8rpgLRN4kKkPk8K 1Gcpurya/eGdOT04zt/mv9PoROioVYmzzsDnKu9BR852Zh9IYzwle+ChlCn7QZ82jWGV xRBvbW4oHcd4TZCkMY4X1bZooGLSKSl5b5yGfATGphq5tKNF7l9Y5VkDEpH5ALXYP+gw nNjZW2VmG+FkPm+yLd9vqSG9IsVhBEUfIDYw7qWlKOnhwidTx8O22hJR3gwyBcpSxurL f3Vg== 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=zKokYU1sqv2XQ4BO3FvTpjJgpxRIa8oNDIwHvFCAE7Y=; b=i4VwDRNoSKHc8qkRy4HIlcQ5W53y2yS9MsUCPPQVigfoqC8WhaJpiQ3X9x/PdLuJLt Mc0b79H9JJvj/UUAdcEA80zwSHLwkntPe1fp9/S9NronLI/i7MquqRFdbDfZYpWOGLG3 gLkZNYlLmae/dvk3GD6BsfCg207SenMi7ELT7cfwLhBj8iyOuu9+Bg8J7yiYRJ1bOegc txadxC/Xold+hoqMIEazZrZscWYydMIrGpXYD33TEGclVtSAa2gVyPRyjEge7voCpBJO 4QIkJYpLV81bfbCwvONTA7DqCDuaeeUiAInTsyH6+nM/yG4uDLUS9zf5Q42TlwoeJuV5 0YrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eBfH2OWN; 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 v25-v6si4411427pgk.555.2018.07.18.14.48.20; Wed, 18 Jul 2018 14:48:20 -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=eBfH2OWN; 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 S1730499AbeGRW2J (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:09 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:52106 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726834AbeGRW2I (ORCPT ); Wed, 18 Jul 2018 18:28:08 -0400 Received: by mail-it0-f68.google.com with SMTP id h2-v6so6325562itj.1 for ; Wed, 18 Jul 2018 14:48:16 -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=zKokYU1sqv2XQ4BO3FvTpjJgpxRIa8oNDIwHvFCAE7Y=; b=eBfH2OWNI4YFGwcqpGBiVneColENwVAO96kDQ4vimYQqVBWyOH9iMIXUWhSz5rcfFs F0/HwIOPIrbymw1yf5JbwS/gV10EKFhVgrCGfUAg+0042oEtfyXCwfnJvH6A0EzZAEqm +rMKGxPsYGflsBwWnUkLgxRZoZQgJbSG5IYAQ= 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=zKokYU1sqv2XQ4BO3FvTpjJgpxRIa8oNDIwHvFCAE7Y=; b=cXk9n+YSyMVAq4roQDYBIHrcd9TDKesiTUolhtgl75qoUKzGSO77ylg94PLEt6uwBD SYMfYsyfYBMcePTMaAyDDxKKT5NGpAeKuoIHtzWLJE3GHinERXDgeN7lnaAyzqylmcsT pwPY3JLtl0E+ZV0hKCIqPesYFBymjbNOeb+cDhY/Don0eVGPV5KLqg1p4pc+M+DA/pdL N44FFmV0IGsiS7UFE2SdoF4kmAJI0u4zRGGl4CA5DIaiB4QHN+9ObEU4eGCQ3LISvKIM j1w03kHEzLNgBtAIWYG6BGkKisPyDsVSx/9YimikiwvmlkVAXN9aMSAMs3MFV7t1cAZd ryFQ== X-Gm-Message-State: AOUpUlF2iTDrVMNiJ1b/lp4g9paHm6i6bxm1bS+PqT/tyDDQu/lnWJEX pwcJZ571mptlGaUTB2vQlFdiaw== X-Received: by 2002:a24:41a3:: with SMTP id b35-v6mr3395672itd.12.1531950496150; Wed, 18 Jul 2018 14:48:16 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:15 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/7] perf/core: Use ioctl to communicate driver configuration to kernel Date: Wed, 18 Jul 2018 15:48:02 -0600 Message-Id: <1531950487-24554-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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 the mechanic needed for user space to send PMU specific configuration to the kernel driver using an ioctl() command. That way events can keep track of options that don't fit in the perf_event_attr structure like the selection of a CoreSight sink to use for the session. Signed-off-by: Mathieu Poirier --- include/linux/perf_event.h | 45 ++++++++++++++++++++++++++ kernel/events/core.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) -- 2.7.4 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 1fa12887ec02..7064b513ca2b 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -114,6 +114,14 @@ struct hw_perf_event_extra { int idx; /* index in shared_regs->regs[] */ }; +/* + * PMU driver configuration + */ +struct pmu_drv_config { + void *config; + raw_spinlock_t lock; +}; + /** * struct hw_perf_event - performance event hardware details: */ @@ -178,6 +186,9 @@ struct hw_perf_event { /* Last sync'ed generation of filters */ unsigned long addr_filters_gen; + /* PMU driver configuration */ + struct pmu_drv_config drv_config; + /* * hw_perf_event::state flags; used to track the PERF_EF_* state. */ @@ -447,6 +458,23 @@ 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); + + /* + * Release PMU specific configuration acquired by + * drv_config_validate() + */ + void (*drv_config_free) (void *drv_data); }; enum perf_addr_filter_action_t { @@ -1234,6 +1262,12 @@ 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_free; +} + /* * An inherited event uses parent's filters */ @@ -1248,6 +1282,17 @@ perf_event_addr_filters(struct perf_event *event) return ifh; } +static inline struct pmu_drv_config * +perf_event_get_drv_config(struct perf_event *event) +{ + struct pmu_drv_config *cfg = &event->hw.drv_config; + + if (event->parent) + cfg = &event->parent->hw.drv_config; + + return cfg; +} + extern void perf_event_addr_filters_sync(struct perf_event *event); extern int perf_output_begin(struct perf_output_handle *handle, diff --git a/kernel/events/core.c b/kernel/events/core.c index a56f10b1e13b..4892246c3af2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4410,6 +4410,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_replace(struct perf_event *event, void *drv_data); static void _free_event(struct perf_event *event) { @@ -4440,6 +4441,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_replace(event, NULL); if (event->destroy) event->destroy(event); @@ -5002,6 +5004,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 +5092,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; } @@ -9090,6 +9098,75 @@ static int perf_event_set_filter(struct perf_event *event, void __user *arg) return ret; } +static void perf_drv_config_replace(struct perf_event *event, void *drv_data) +{ + unsigned long flags; + void *old_drv_data; + struct pmu_drv_config *drv_config = &event->hw.drv_config; + + if (!has_drv_config(event)) + return; + + /* Children take their configuration from their parent */ + if (event->parent) + return; + + /* Make sure the PMU doesn't get a handle on the data */ + raw_spin_lock_irqsave(&drv_config->lock, flags); + + old_drv_data = drv_config->config; + drv_config->config = drv_data; + + raw_spin_unlock_irqrestore(&drv_config->lock, flags); + + /* Free PMU private data allocated by pmu::drv_config_validate() */ + event->pmu->drv_config_free(old_drv_data); +} + +static int +perf_event_process_drv_config(struct perf_event *event, char *config_str) +{ + int ret = -EINVAL; + void *drv_data; + + /* Make sure ctx.mutex is 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 (IS_ERR(drv_data)) { + ret = PTR_ERR(drv_data); + goto out; + } + + perf_drv_config_replace(event, drv_data); + + 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; + + if (!has_drv_config(event)) + return ret; + + config_str = strndup_user(arg, PAGE_SIZE); + if (IS_ERR(config_str)) + return PTR_ERR(config_str); + + ret = perf_event_process_drv_config(event, config_str); + + kfree(config_str); + return ret; +} + /* * hrtimer based swevent callback */ @@ -10019,6 +10096,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, if (attr->freq && attr->sample_freq) hwc->sample_period = 1; hwc->last_period = hwc->sample_period; + raw_spin_lock_init(&hwc->drv_config.lock); local64_set(&hwc->period_left, hwc->sample_period); From patchwork Wed Jul 18 21:48:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142305 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022362ljj; Wed, 18 Jul 2018 14:48:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcu/d/bRmHk6FEza/hXsqI45Khi8wfax/BOZe8WxNnVEprYlewpIgr5LMs1bddyGN+pHouN X-Received: by 2002:a17:902:bc85:: with SMTP id bb5-v6mr7497113plb.229.1531950503859; Wed, 18 Jul 2018 14:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950503; cv=none; d=google.com; s=arc-20160816; b=qmandj96GUed1It8U3wDVgkFBuWrOYUsy7v5nl0meX0qd3GtMcOD5GQhb8a5+NW3yZ 5XiULjeyPqDm1T66yFbIotSCNnNnPEm1lEnkeklmzXtWiMHExyo7WVzcryGcjJzD3Uc1 pW9dTE91UiX2lVI40ziY66/bkpzANDGLmHuANU+zN2AHQ0y19tbsukIhSLt4zHcLESTa Iur6zfooeJeigY/pGhth1S2QOUUWQ6IMTxP8SRI6s4cRFwIyfXjgvnJ9n7KPvQn6WnZ7 qtyQkLkX8wn1RHtQG7y2lYQclbqmhmdpO29OE8N7TDLR6jXwp+xNDAHh1HuCg+zSoH4h uq4w== 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=7WnrWOlEDU+ZAtImQoRhxjXSprA05PTjN3muEnfClcE=; b=p1hUFcGdpuFScOvjZdWHaN4EoB2m8TZSrTEZO8zpECIMEwvOqnX3//UCEyYB1qJIuQ XsUeBWGnLCB8x0Te/kGNxGmjraehCVT747UijoB9rWo5vx4s9A1a64TJ4AshnfxVByx5 N/iJwghyP20dhz88XRir43uP2xuxb4js04MPZIyX+gaeQ5avcVDMwq2UJl4VdQe+ULa4 yuewoAlL0aajfwFbYg3Zh7r5LfLg+JzUFy9va56rk2+SrvS1A3xMfca+TOuuB/2WPBaB K51oWkP6FsT4oCRhljNKesixIybZJB27gnBsLYMFyF6w9yv+nvvmdNuS/C+dpetVDrMJ vK3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GEeTzdPy; 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 j189-v6si4017269pgd.498.2018.07.18.14.48.23; Wed, 18 Jul 2018 14:48:23 -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=GEeTzdPy; 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 S1730693AbeGRW2L (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:11 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:52109 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729753AbeGRW2K (ORCPT ); Wed, 18 Jul 2018 18:28:10 -0400 Received: by mail-it0-f66.google.com with SMTP id h2-v6so6325679itj.1 for ; Wed, 18 Jul 2018 14:48:19 -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=7WnrWOlEDU+ZAtImQoRhxjXSprA05PTjN3muEnfClcE=; b=GEeTzdPy9hJ3su3hBl1ScRWmFCT2STQdwtwRbc3xpRrQ1P01EQX8/dLFgWpUs5aZal KY7vgtzwE/TCB7RPyuH1KP6i3NCWfYpiQkqe+9fHKVngnIJUzYTzflBeYW8eagLo+Wod 4cmbSpZSY+ruucuCWi2Ij6ZMtqLzhf7Mp2qc8= 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=7WnrWOlEDU+ZAtImQoRhxjXSprA05PTjN3muEnfClcE=; b=LEcNhGTPFMHaKBB1ugW1HAGqC1jCwSHd1GY8A7ZNM9rGt4jxpm0W0DP5FtoSI3YF3/ yyypNUlZdsZ9X1AuW6C9oSrQxTWkGpJReuufFTSYaWVmO0RynxExjKKFYiz3gyEfqUrc 7FO8ckXjssdJ06m2Sm1nk6FWwyDd86xIJ5lHyoKZSMVhnnjcUQKrOItufmMXqpbhdPCn LmXMt6npZN7XjK5GoX8QpI4V+YFuCRqwWf1FjJKN/nWuQpRGe7oPe9A5/NZ3Df4qOR41 vf8T/u+1+gxeQ8L4gYMe6DSNY0+hmbWKADEvBmNb8+VaCK1ztfUmlhEzxEvJzlUcOLAI RtSg== X-Gm-Message-State: AOUpUlEq5FSJGxdwAcVv06iQnAqqccuYMfkKu5IBW1O3EGXwjiPd/yh1 XvbBku09O94iWLDOidiFW9aRYw== X-Received: by 2002:a24:7584:: with SMTP id y126-v6mr3530511itc.11.1531950498675; Wed, 18 Jul 2018 14:48:18 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:17 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 3/7] perf/aux: Make perf_event accessible to setup_aux() Date: Wed, 18 Jul 2018 15:48:03 -0600 Message-Id: <1531950487-24554-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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 When pmu::setup_aux() is called the coresight PMU needs to know which sink to use for the session by looking up the information in the drv_config field of the hw_perf_event structure. 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 | 6 +++--- 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, 17 insertions(+), 14 deletions(-) -- 2.7.4 diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c index 0292d68e7dde..2d55fc2bb185 100644 --- a/arch/s390/kernel/perf_cpum_sf.c +++ b/arch/s390/kernel/perf_cpum_sf.c @@ -1589,7 +1589,7 @@ static void aux_buffer_free(void *data) /* * aux_buffer_setup() - Setup AUX buffer for diagnostic mode sampling - * @cpu: On which to allocate, -1 means current + * @event: Event the buffer is setup for, event->cpu == -1 means current * @pages: Array of pointers to buffer pages passed from perf core * @nr_pages: Total pages * @snapshot: Flag for snapshot mode @@ -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 16b9c87d9d00..2bbd3240ff72 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -184,15 +184,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 7064b513ca2b..d67074f81c23 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -420,7 +420,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 Wed Jul 18 21:48:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142306 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022394ljj; Wed, 18 Jul 2018 14:48:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe4aJX/qFIQSc05ott14/sKA+LcP1ACeHR8XFeHf5fzPSgfIx5qJBwlzyEMjzSBCAD6eexR X-Received: by 2002:a63:c742:: with SMTP id v2-v6mr7347406pgg.331.1531950506155; Wed, 18 Jul 2018 14:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950506; cv=none; d=google.com; s=arc-20160816; b=hwE9JWSI/t97VUVej/oJaesIDeO6guKvz1rs7HLQRiH2QeHYpo6f4ewNmc9Kg/3Djf sQbnzogreLVJyQx6Kxl3yGJ0yCzPeqUggmtNDf1tzWNA3fdGonW3erTCdYW0iYt+hWeF IrdlVP9PIZBj35V0jyV6TWSoDr9e37mdtzcY5nAQqbd5QDovvtuDu5XrOjT+wOsmlXkn 2DUlnLzvh+d6tDCq+qrohgtS3Q3IyBDL6ObI++UNIyhvx1udYKo9AB600Oss9LMWGHUO Wg18DEPMDH0RI9gdSqUcq7/vrRcpb1FPyiDYJfhxmclensb79r5YU4Ok1XnsFMmWs4BA By6A== 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=ySUaw6WK6HJn4OLmu4qS8ThkDumjrACGVll+EE9ZBwc=; b=KIFH9uhmTEi/MHHkwKYs0L4RKKI36IsUNmq99E3YCwlZSjsHAEnwTi5devUVi8juGR 9WmKuA3txigVenIYFYTZcOQLM1ltaPvHSd3Zr4VoXfpKV3DCzmkJVWyUrYyga/6VA6pY MgV43dxD/bRa1CgGWEFdGN9GBykJCcTnYX45L1Yxo/uClinZISGbKpy3BC46na9p6VZU 2/fLIRlzGVpkfcj46qSDD3kohHQtFJ+nrKmFYWZzn2jdOUMzBRVSoZNqNskRsPTY68QS bp5FKCEIfN0juMzF1qmsyrasLhFwGKzs/JxVxrkVR32SCnjxXRLKyoCZr6SBqum7sOHs lyJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f21Gq0j7; 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 e3-v6si4059625pld.229.2018.07.18.14.48.25; Wed, 18 Jul 2018 14:48:26 -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=f21Gq0j7; 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 S1730813AbeGRW2O (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:14 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:39590 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729753AbeGRW2M (ORCPT ); Wed, 18 Jul 2018 18:28:12 -0400 Received: by mail-io0-f196.google.com with SMTP id o22-v6so4308866ioh.6 for ; Wed, 18 Jul 2018 14:48:21 -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=ySUaw6WK6HJn4OLmu4qS8ThkDumjrACGVll+EE9ZBwc=; b=f21Gq0j7oxGoi4J6LJ8WMyFY6cItX7gmyEk6P1lZ55s2ubgzQPN1/t6Pgz2mnRNZqf MjS3p6rQc9Hgm548qN4rnUQfCvd+l13GsoVPyXlhLqqqtxHGkvT4se1oV792KJyvGKHt 3WYR/Pf6L5Yf1vw28SMdZkCsOa3bIvDZFIzvk= 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=ySUaw6WK6HJn4OLmu4qS8ThkDumjrACGVll+EE9ZBwc=; b=Urwf4LrWbaybjA8iimWcbsTzzBm280XCTAEiMjkQrFEhpxMJNL5rVI3evLwcrbBuJR ofO3VsfHEbLJry/b6jfZkrRGz3h+xpOBMJfNvitSOgrx1fBD0BPRDcDVtMVDGvTqERwy Pgds2gtnQZKHC05Wruya4ZAdSlprHAeo9+15cIarjFcbHAup88JcC3wQiC6LLpVH8QUm 7u8n9z1RcMqzfYdCZU+q1DCVsGS0dq1ts60EmbusFTYRsIoSNt5CSbnJD1l0JvrC2plE jZC9XT7PgWMCDC/sBSx2guBjDXZ8wyikGwYTBcvNmWlx1CK6roH1//4JO5FdDXjOia9Y jwUA== X-Gm-Message-State: AOUpUlGgOyp8eieY36OezvNV9WL4cMyBhw/xKCl6wUyO/UuPmWxPwuWo wQvlGlkRjNIW5/ZEx0pwUtBN8A== X-Received: by 2002:a6b:b307:: with SMTP id c7-v6mr6415343iof.25.1531950501160; Wed, 18 Jul 2018 14:48:21 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:20 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 4/7] coresight: Use PMU driver configuration for sink selection Date: Wed, 18 Jul 2018 15:48:04 -0600 Message-Id: <1531950487-24554-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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 held in event::hw::drv_config 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 | 134 +++++++++++++++++++++-- drivers/hwtracing/coresight/coresight-etm-perf.h | 4 + 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 2bbd3240ff72..5c23b35a8ad0 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. @@ -184,6 +187,78 @@ static void etm_free_aux(void *data) schedule_work(&event_data->work); } +static char *etm_drv_config_sync(struct perf_event *event) +{ + char *sink; + int node = event->cpu == -1 ? -1 : cpu_to_node(event->cpu); + struct pmu_drv_config *drv_config = perf_event_get_drv_config(event); + + sink = kmalloc_node(CORESIGHT_DEVICE_MAX_NAME_LEN, GFP_KERNEL, node); + if (!sink) + return NULL; + + /* + * Make sure we don't race with perf_drv_config_replace() in + * kernel/events/core.c. + */ + raw_spin_lock(&drv_config->lock); + memcpy(sink, drv_config->config, CORESIGHT_DEVICE_MAX_NAME_LEN); + raw_spin_unlock(&drv_config->lock); + + return sink; +} + +static struct coresight_device *etm_event_get_sink(struct perf_event *event) +{ + struct pmu_drv_config *drv_config = perf_event_get_drv_config(event); + + /* CPU-wide scenarios aren't supported yet */ + if (event->cpu != -1) + return NULL; + + /* + * Try the preferred method first, i.e getting the sink information + * using the ioctl() method. + */ + if (drv_config->config) { + char *drv_config; + struct device *dev; + struct coresight_device *sink; + + /* + * Get sink from event->hw.drv_config.config - see + * _perf_ioctl() _SET_DRV_CONFIG. + */ + drv_config = etm_drv_config_sync(event); + if (!drv_config) + goto out; + + /* Look for the device of that name on the CS bus. */ + dev = bus_find_device_by_name(&coresight_bustype, NULL, + drv_config); + kfree(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. + */ +out: + return coresight_get_enabled_sink(true); +} + static void *etm_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) { @@ -197,18 +272,8 @@ 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); + /* First get the sink to use for this event */ + sink = etm_event_get_sink(event); if (!sink) goto err; @@ -445,6 +510,49 @@ 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_free(void *drv_data) +{ + kfree(drv_data); +} + int etm_perf_symlink(struct coresight_device *csdev, bool link) { char entry[sizeof("cpu9999999")]; @@ -489,6 +597,8 @@ 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_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..37a98230fc34 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -42,6 +42,10 @@ struct etm_filters { bool ssstatus; }; +enum etm_config_elem_type { + ETM_CFG_NONE = -1, + ETM_CFG_SINK, +}; #ifdef CONFIG_CORESIGHT int etm_perf_symlink(struct coresight_device *csdev, bool link); From patchwork Wed Jul 18 21:48:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142307 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022405ljj; Wed, 18 Jul 2018 14:48:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd9zt39hNgiz3fPzmr0qkj+KwnyyD2EUwzNYSbYiNyW5JrkTCbUUJWWTUnSBm9EDOCqFTqI X-Received: by 2002:a65:64d7:: with SMTP id t23-v6mr7474022pgv.207.1531950507255; Wed, 18 Jul 2018 14:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950507; cv=none; d=google.com; s=arc-20160816; b=gzWCgxmg+EEGUwMpT3xbDy6w1N+ouGhcUKlY1PTa5RUoqRRUjKNGDDw5HJcnhnBRuv yW/i9eg6drd0w3Jn0EGebKuiHg0jVbXT68J6S9cJJPMzBzAek13oyzoLhSfw5d2m12RX rzoiZnGis50I4ebO0p6kmJbZkGrtIOIVQrtIKEFpUCLhF0CppRCGLLLfcFKexk2LQyS5 DSeG3w/1FdTEap84Usa355fIW2Nl9qXV0vY8bPW5oAlsUCPDhk4tNCFUlef09H32Scxp BNPXUX3bA+wSOpNfylnF8Of/Vmm1sCnqwmlJ/H7XU6J2jnMKEO96+9L+3/71LcnRMBC8 6lgQ== 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=rzK96jeA/4D0TqFmCbkbkljgpAZZ6IWuPjpeEQCo8Fg=; b=VKVSzOV2kLpTCpQYHF05ZwC5rnKgX7K7o3EVS4OLGujgbdSzzIWT4ldRM4fMGgTEu7 nB8L3D2RkjgQByK82HsYi8vJtVMPGB9P8uaAX3UR0iByQkSnM8v4Cw5ILrQoXJq4LaRL uwbNh7LTrnEDELVdCp3p10NgDBwYBSxxfCBQ3KwbRBjNvsIFYdGhreNZwaHvjx4U8Mx0 Hv0sA4MYNXkqB/HtTRPjs+UD8/wpe8LyPvc6cPCJlecmbU+jIikglnO0ukyOiE7b0f0Q 8Cn6d9aDjDlon1OLgfZOdqotmHkcvKr0X+bR/c3YDaNvcKKO4ZvYfkzTRDyQTlYTN630 B6Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vx0Upq58; 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 x19-v6si4263678pgf.477.2018.07.18.14.48.27; Wed, 18 Jul 2018 14:48:27 -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=Vx0Upq58; 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 S1730889AbeGRW2P (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:15 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:37327 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730821AbeGRW2P (ORCPT ); Wed, 18 Jul 2018 18:28:15 -0400 Received: by mail-io0-f196.google.com with SMTP id z19-v6so5375329ioh.4 for ; Wed, 18 Jul 2018 14:48:23 -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=rzK96jeA/4D0TqFmCbkbkljgpAZZ6IWuPjpeEQCo8Fg=; b=Vx0Upq58oqevY3SqboDQJX1fA3xSX2npr5PrLEOKB8M9FghncKRiO0iKyekvaENNfz WAnEBn1VTZLtHjIGMf46eEoSxVTfv4q4VvS4xiIp4XV3e8AH8JKM83swgDGOQqtp3eWz T882tnnaP6Us+IWEgbLXmypBYppuKqwirvmBU= 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=rzK96jeA/4D0TqFmCbkbkljgpAZZ6IWuPjpeEQCo8Fg=; b=CuHXqnAwKj8pjTPuRaQzIhKal2eE1UZKFPFNnHW5NkNFOZgp5f/UZgz8AnwfYSGc7c 21L/jxOlByEWcZllRXNvH4ngtnu7X1N1aBHtpTa7jKL6kqWu298tP7ML0NMvu42dgXun p21jq1nSqOC0zoCA772bdnBrGEDCI719/cBMTT9JjQM8mLlMkzE4HAJWQZYmG7FKLtB2 21ABDcJtdLotEBULDEvOudeva9qTmKXMJ2Jyey1dIvgWzvGEv/6cQh+sLX3zCldLQ64J TwFJFTVc1uD/qt0+r+yCUo12/7tpiIIIRSl5v4jFy6zPld69YIKHFFXxvwWmPIKQ1CPR bH9Q== X-Gm-Message-State: AOUpUlFgWcRadMChVGJh2XF9FZxWFXXY+WLFDzo/MxZmLdqNn06G86BH i2uphsFU25RzxggRRf8KTJa/lQ== X-Received: by 2002:a6b:4f03:: with SMTP id d3-v6mr6822623iob.176.1531950503608; Wed, 18 Jul 2018 14:48:23 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:22 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 5/7] perf tools: Use ioctl to communicate driver configuration to kernel Date: Wed, 18 Jul 2018 15:48:05 -0600 Message-Id: <1531950487-24554-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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 such as CoreSight sink specification can be communicated to each event. Signed-off-by: Mathieu Poirier --- tools/perf/util/evsel.c | 7 +++++++ tools/perf/util/evsel.h | 1 + 2 files changed, 8 insertions(+) -- 2.7.4 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 Wed Jul 18 21:48:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142308 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022438ljj; Wed, 18 Jul 2018 14:48:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpezpqJeKZ3nqiygz09vEsVhnSI0t3MiPnBrFvWCnvLwMatUps3raLZnRHiSCulQ4oo3PUZ5 X-Received: by 2002:a17:902:708b:: with SMTP id z11-v6mr7425683plk.262.1531950510193; Wed, 18 Jul 2018 14:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950510; cv=none; d=google.com; s=arc-20160816; b=t6OSY+teD6QXLwkhdM7l270rNFSIpU87zCElKuC0eOZshad7ShIKpZxOlAA20FK4nt VZ4Q1Dh2hrmXJokvZFhJlj8acuTWVGS9pmtqZvzgEMRjjjmxpIcZix6nKUqrwIAEKPrS vcsHmWdWuelIadXa51wiyeOINIPHSP4Igc2iQGlQj2nc1sb0xKDTf41EcrHxAkK25hOR i7e5Y2aq/8Ng444YpNlXvLRA6djs8Xwtec1au9NUAnP633UokXgCo4wpHLkaEV7CW0AI PCCSYKV8fIWMJYDguMiZ3ZJmwCUDNfG8xQUMWdUW2QSk1fyZgEkKcx9dHaxs+yWWcgQ2 2L8w== 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=QrbgEjuuOCvF3fX4/IvssHlgw3WTtVZ1yc0e46uQZLKjTXboHc5YGRoSINwvXyu2Ut 1jBbhR5WCPk9lUuyzTNnRLvEk2Wwvbz/jJ75V1jRrjDA2a99STNaKKXCQ4zzuDnvwMr3 E+6VKEcDUrGaF7/wQjfmOX3ctZyeZiCxL1lt0m2sMxc9a34qnPlKFD9r1Qg0T6lJr1Dg OgO4XUYjcDpt/UsJ5e8MnyfLDbWBFJOJoy5nQHcTIBML2dmjq4yug1chLJNnJacQkEK0 87lVJbUCtQHlmCEZIJDUQJeOeC1c6pR8X7HiClnYpPjm0YoUk6MYpivQObF0LVyRHmCM QulQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IOCSYYCD; 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 q16-v6si4439752pfi.183.2018.07.18.14.48.29; Wed, 18 Jul 2018 14:48:30 -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=IOCSYYCD; 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 S1730926AbeGRW2S (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:18 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:32993 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730821AbeGRW2R (ORCPT ); Wed, 18 Jul 2018 18:28:17 -0400 Received: by mail-it0-f66.google.com with SMTP id y124-v6so253721itc.0 for ; Wed, 18 Jul 2018 14:48:26 -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=IOCSYYCDhtpAP51yrwIXCOrnAheFCri7FXo/wF12PyJQpLV/zi26WZb4qawpC1D4Tr 1wEq/NTg7lhbzERFueEVwjuxmYakZp4Mr6LEcaCUpW3uK+Tqaz0owx6P3p0eK/SiTpAr T/hJIlcIpMM+JaNjtVvpq9ExM7KPOsN0QXPdM= 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=KDb82N0yJ4gdpFI+wlPS2POJ1Nj004cOuT283s0oZZYxTZbMcQH9y8NaIY8iCcdX9H jP3v00UkIxAYHqKgpOY7/pJzlyHufM6XDXpNgvt8KZhoqtNAPJQrGH6DjfnbTUjbSZVM XSCu7US9gPRJ1oZmMAYknvC3kCX1UfByG+jpXNCYWrVT3NscF5pPLtyi84Ja4A25b6Dh BYNHq+ftBCD9CmnEPw0WPyHTsHei7O6qIpDBYymEBXYmoVVKQkUmEwY2OJ4lmZMvkx2X KWa4Clw+T6y2Go9dQVEiTXZqOpJj8F+W2+oE6eD/ApgHxEoEfQtTsEx3EbOIdcDH9A/8 yUoQ== X-Gm-Message-State: AOUpUlFNJMt4fM5JO5yx0VPzuJCQ8jOONj6hFbllSFZkmnwb0+m5yDOS ZEJrfgSoR0/zthE8aJ9SyPTzoQ== X-Received: by 2002:a24:83c6:: with SMTP id d189-v6mr2490711ite.75.1531950506126; Wed, 18 Jul 2018 14:48:26 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:25 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 6/7] perf tools: Make perf_evsel accessible to PMU driver configuration code Date: Wed, 18 Jul 2018 15:48:06 -0600 Message-Id: <1531950487-24554-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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 Wed Jul 18 21:48:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 142309 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1022469ljj; Wed, 18 Jul 2018 14:48:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfIlJ/09i+ZoRhXNU3w1C8dGh6ONm+INGa/IQNDNEhKu5MYL07BKAwBQBA9q8bG2lXKyMGc X-Received: by 2002:a17:902:aa8f:: with SMTP id d15-v6mr7589759plr.64.1531950512763; Wed, 18 Jul 2018 14:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531950512; cv=none; d=google.com; s=arc-20160816; b=smoURU8agShTql3FP3nW2pf6cdWpvZh0iqwkMQaz9BY6JQU16Rhy5SebPLf1iXQqUM 9uYqTcakW74jUkEGF0VNe6HD6svDrJ2tA9lMqwB4X5X9agNe4ePTjMbQ2mUmTGOA8Mfc MOYIPrVgfxOlROhkPcgcCz9/6H/ofqSG8f+sMJyjNCGiMBiPu0ocnUCae4nNs6A93pqe oQZHsIblDV1gj/eA1NXVafnnrcEQAwIPJOwLKhPAKq1d0JtuuMIB1RpWyg7hHp+LYB97 ZVHkO5FsnunBII7xYlsmVJnrLkrl5qgT4g0FE1nlPIan6oF7qNS0lvPx2xfQYkNb/nFu lE8A== 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=Ssk15r/wVyFabVOEmVABQIGp1LVox6RX+qDbU91TvSLHDno4t2V6YNapAjWkkW9eDO 3/33DzuwTm5MhOnH1ArPxX9G2xBTVxGSkljpkffmRFSPYRrpgI0sYmDNw2kuqovicedM YRP2qaLgUTATSkBbSxCgX8ucDjtU5J67sx31J83hPSHXw6qMgBDejYE7fR8LfeT811r+ HLEAr41xsX07jRbEss20OGDiso+u2cfFO0hNWIIB8SZb8pn4HQ3UypMT/60hAnUnpCpE ryBWWzWmBtWecjw8O+jkSDfNnlaZAJZA2spfcBdpdMCuUmKPRUvmwpNtRdGcCAEMNcgi KNmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QpFjYGj5; 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 f59-v6si4061668plf.500.2018.07.18.14.48.32; Wed, 18 Jul 2018 14:48:32 -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=QpFjYGj5; 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 S1731028AbeGRW2V (ORCPT + 31 others); Wed, 18 Jul 2018 18:28:21 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:37349 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730947AbeGRW2T (ORCPT ); Wed, 18 Jul 2018 18:28:19 -0400 Received: by mail-it0-f65.google.com with SMTP id p17-v6so6494240itc.2 for ; Wed, 18 Jul 2018 14:48:29 -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=QpFjYGj58tqSM0njnd7/94/7ydOBwDzbQljaZ9pOexmY3tQF0TItQ96N+rY+2nRgFM 5xpWdjR2vbBseICvWcFcDktGDve0u6kU6fKEVGgcwuhTTOIoflGrU+7YBoy+ztf1KhnA 7fqkLFy7OgO6214hrfqstwbkoX+v0vRf2YE/E= 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=EEg5JqDBi5zIibVxXYp9MwenLLMflRH9jCFWcoMER8DK8pVdoL5kdyJvcCtyEBHM46 TcBDZ+dE/0n0p3H1Qe/CLpa0ZgwTkYYCXx+Drk2PteULusUuxCShWNgmtiCUhhDJdFmE oSXuGsDE0CteE+NkxMqnDNBFpRXYKEi5QMF75mkMXVZpaqzSO3knSNxmpcS9ht9zI3Zn Yqyge0RYbUxqxFQi4sbbNAKSdqBpEuCzJLgc61F5CCAY3bp49r1rUcsALzZXO5PaFBKi L3okypubkiUztdC8y+ighLedPIqGr0poz05tbAc/4sZ9MtVWn1iR+ERJ1GrkgE9/d+GS mp5w== X-Gm-Message-State: AOUpUlHf/mAQUnj3hylpvdOu9Tkg3jLIZv4RUchmtgKIsUepztSRd1Q8 pMYWYGZNrtmHA1r5oOl5U6WCUA== X-Received: by 2002:a24:a43:: with SMTP id 64-v6mr3577718itw.140.1531950508662; Wed, 18 Jul 2018 14:48:28 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w193-v6sm2093386ita.35.2018.07.18.14.48.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jul 2018 14:48:27 -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, kim.phillips@arm.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 7/7] perf tools: Use ioctl function to send sink configuration to kernel Date: Wed, 18 Jul 2018 15:48:07 -0600 Message-Id: <1531950487-24554-8-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531950487-24554-1-git-send-email-mathieu.poirier@linaro.org> References: <1531950487-24554-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;