From patchwork Thu Jul 5 22:13:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141231 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2427576ljj; Thu, 5 Jul 2018 15:14:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfeylPrjVIfCXOhhxYLjbXoT3lEKBW1Y0fAFyEscziXD92LcczyJcKsOZqnl4X0B2gWY0EH X-Received: by 2002:a63:9741:: with SMTP id d1-v6mr6967369pgo.403.1530828841322; Thu, 05 Jul 2018 15:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828841; cv=none; d=google.com; s=arc-20160816; b=A1lvP2EnCoy+FhmPuBUKX38eO3mgtm8fF920Ue8dYNS/UA23USsgaBPRYlnqzvHkp9 HTQHjEFlTLZiWTd2zBGi85dv1yeNJJovv+5vd0wHJLrbIFIzA79vCLeWP1Aa04MxmqZi JNa24Y4nmx7MAZEmV2YlJjQ7aXqrVTB51TAY6vo1zOiv5Y82Z8ck9Ud9ojGQW59dtiDV +JUUFtMl1yUg9bSiVdQG3aCTbYBa4mVJ4qGQAEsP/Rh/AaMeYyrg02NrB9mV8qZrZ8fJ 1o3k7y1CZ3e3aNWx5nDp63AbAyAkaKLR2kULx+70mGDueKEs7MjgUE/wJCrXmQfwphbj z1ig== 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=ldy0aXKde/8eV/7ipDJfRG/tyA7ZgVVezNDqh7gw7+4gmjoJ+IPQJKX/Nbg/IEkn/h HAgDaraF+hf0SISq6DNd1RD5BowAIPv+s5UmPFIEUXdOFoABfVayJDE+kdqr84K3zpek eQXefNvl8qRDrDJqdc4vbK2PMs5SiI5xit6j6Tj5e4PvXOasBrgEToXFMI3vXq9SdcSc TeZuYTvApmfkjyuK9JY/v0eLfp9aHDpyxqYfgvAsy4mOuod2Eyq8GMbqzLJI5JjTtSPS FsuObyjLk4YGrf9UnvxdF2PmGJ0UrTDKl0k3uHLXtNojD3YjrVLv39uE+HQ/dSVSbTX+ 83fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gI1CBvT0; 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 q35-v6si5198613pgb.219.2018.07.05.15.14.01; Thu, 05 Jul 2018 15:14:01 -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=gI1CBvT0; 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 S1753680AbeGEWN4 (ORCPT + 31 others); Thu, 5 Jul 2018 18:13:56 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:44349 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753549AbeGEWNx (ORCPT ); Thu, 5 Jul 2018 18:13:53 -0400 Received: by mail-pf0-f196.google.com with SMTP id j3-v6so6570312pfh.11 for ; Thu, 05 Jul 2018 15:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b+RIY2UuP5aJSr2EjMCmde75UASQQURVa37fsARUKY8=; b=gI1CBvT0BGibui7weucnBH3LCNGfiFEjOcmvqibEyCvMl054ZdQ2jCwPU/yu/2WJZc FkiB0FAfNtJC+uDKXMgMewYa20cNphm0HasaoZWNHabHHW+ZtOygyNGptShiaiO1AtWU YU5EwYNMBNv4BlYiIPHcoi2v5deJ3VoGN/I9U= 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=HJWrEKz+x0IXzfecCowWUtkjKRY+JOd76AAYn6/wM0Cq8+jMPxBAV6TkGEU6hDAvVf cijMykXIx9yCO+mwSjpz/nCkvn2n43irTGR5hQmH1PuAM7mZYdwGDlhi8YNmcNoFGx2d OoYKQtRT+eGUbsacncQpvIGE+oQ/tvX4WSawUiEb3J05qKNKcORQoJbtcTKI78e4/BSI 3x1ieDOhWOg/9ZCgGufxz94zrIApaibPtS/ptcxeDL0Jvo14BgFO5LKTsu2xGURBcYdn occtdccdcq6tsn8+52TlSSOWcsMfn8CGKp4/of7LGv4NVIxb0cJy7KrHskASuNr2yn+U XTYw== X-Gm-Message-State: APt69E04mBbkQ1Ui9MZeWvMqdyoXWnldOaOvu56mzh0evNEiN+M31oM/ Kdt42bd18xIgZxiEEwzJ9LgS1oioQ5o= X-Received: by 2002:a63:82c7:: with SMTP id w190-v6mr7128829pgd.253.1530828832914; Thu, 05 Jul 2018 15:13:52 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.13.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:13:52 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/7] perf: Introduce ioctl to communicate driver configuration to kernel Date: Thu, 5 Jul 2018 16:13:41 -0600 Message-Id: <1530828827-11604-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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 Thu Jul 5 22:13:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141237 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2428422ljj; Thu, 5 Jul 2018 15:15:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfXkkaYwYjN+eoh6AiETs3mrytMcY2WgVbOhRBXFW4ss+WGToTyqBj7JddMyCZUIqL33Hep X-Received: by 2002:a62:dc1d:: with SMTP id t29-v6mr8204300pfg.244.1530828911035; Thu, 05 Jul 2018 15:15:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828911; cv=none; d=google.com; s=arc-20160816; b=AGfC28B2E9C/9lPDZ2hX85ygWDZ/55YWsP1pfPSXxnwH8MD4Xy2XbtRqtsM0NnOT97 vMcqxOi1BnZQx/txj+KBldPIt9LVM/GvEYOxj6qmBE6zDv+YY9upp5RCRrlxYNjTTXKK e8FrrPTh162zqXwm4tgZw1eIUoAcvjKtwSuFBbInKFHRcCNyImS1V+oiCVpwGhBUypRq hXNLl71FBvz4lkkmfxnLoZ+vFMaYiVMejXHnlQFB0STBY//2ZJ+GJoMx0kPYKLrfqYmM BrXzowdzy8Hkf9N4GdebuJaBCn7lVas+ENiQjCqhFGkT3DBWcnaUzD5ZG8qaU+Rj+aG/ zM1w== 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=wcDXoRKxdMwlAIzFSSpqBc8nxIkjXr0IsYLBwG/+q2U=; b=oGjO6pN8r95fRYcFZEwD63h3zcrkHy950+i6vm+kMjDZJTc1feEENcIbk8XiCG7MOV AFzPNMBk5R6Kx/orRH8mGMhvTbh7Wb7w3zQqb6/WLKe0ZT3w9TQZZbANZ0cKdMtxkmLq EKxNylep99Z6Hu6kvIEOO8Xz4rPeAjaWNj6OJH1yq7p/wOkHLZwIlFgaPKtKuF3HnPPg NlGQ99bdVjk5XoDqOsZrwshcCnjczazRuifnlgnRf6YhBfDdGBu69wvCUqd1MDzfykqj C2AMUGIXZp1zNjdjsg6h0HNncEeRwTiMnkaVraPbHUaBRAEdVYL7Uf/5ObW8vjzJWIE7 rEWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g515saSV; 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 n24-v6si6691966pgb.665.2018.07.05.15.15.10; Thu, 05 Jul 2018 15:15:11 -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=g515saSV; 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 S1754068AbeGEWPJ (ORCPT + 31 others); Thu, 5 Jul 2018 18:15:09 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:32769 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753560AbeGEWNz (ORCPT ); Thu, 5 Jul 2018 18:13:55 -0400 Received: by mail-pf0-f196.google.com with SMTP id b17-v6so6583671pfi.0 for ; Thu, 05 Jul 2018 15:13:55 -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=wcDXoRKxdMwlAIzFSSpqBc8nxIkjXr0IsYLBwG/+q2U=; b=g515saSV+SQOiVWPIlKnHEln3zGX203o0OllfF3jPYTwfT0TLmDuh2/a1Q1ZK3m40J oSObJYoHfmABNAVOV4gR+qZSJhYFSpfpvtKyVg+5gNDpPNFqMxqwB1JMDjXjxiw2r2Ha eymyPBdmrcxaWn0QgxwnwlwYdtZwJgv4N2EIk= 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=wcDXoRKxdMwlAIzFSSpqBc8nxIkjXr0IsYLBwG/+q2U=; b=syg+9LbSvZWeTiEYudiKGPCn2InrklzYzbrAQ1L7SI5z7VIX1C5ROjn7l+2v0YwZNZ AYnbSpHk5hRVvoN0SbSsSqTW9aplUS+uZYHNuk5xBDBirGiZl2Oo20YCFi9Q+6IywpGs 7GBzUuktRZ4iZrVd943Dx4Ww/nHUDBoYa/Sq5I+g56tS2UvdVAlLWLTl+qq88nwKCOTT Y+fc8WCBPodCLup0sHzms9wmf690Rc1L8QOuEbyIyiYhNy65Z5nbjQxJZQxQXjC6+Xx8 xunliJuEimFhJ3rvorKRUbPLe/JhKktqtdL/VOSDNDRVIMZxZkaOQHXjYEaW0F3FTNIo sG3w== X-Gm-Message-State: APt69E3rseqOhCdmhAW7KpEJfcCHN+UDvrBNBPBzFyzwpj6uKSL/+lec h4JA+fS+ovuflwSbhfhYDyt154/HGVQ= X-Received: by 2002:a62:9849:: with SMTP id q70-v6mr8116643pfd.178.1530828835081; Thu, 05 Jul 2018 15:13:55 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.13.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:13:54 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/7] perf/core: Use ioctl to communicate driver configuration to kernel Date: Thu, 5 Jul 2018 16:13:42 -0600 Message-Id: <1530828827-11604-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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 | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 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 8f0434a9951a..ccff64e9451e 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; } @@ -9086,6 +9094,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 */ From patchwork Thu Jul 5 22:13:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141232 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2427625ljj; Thu, 5 Jul 2018 15:14:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpemF6Muqc5i/KNe1m2HqVSX7JeegoV+RVyBijxIpu8cFr9ySkcgMII6Hs8OxTcuN6se0mtT X-Received: by 2002:a62:930c:: with SMTP id b12-v6mr8079672pfe.193.1530828845237; Thu, 05 Jul 2018 15:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828845; cv=none; d=google.com; s=arc-20160816; b=T/8H7M/FAo0Et/Xc+M7htbApli5Ua6w0RSZEc44zwTXxwEvKLwfVi6nR7+Rx9SF+YG U6dRLFu3j0bLpy2SK2rPD016TL/Jd9p3oPyxr1qXDh9oh4eA0RhD7/5UOxjU4xRfM/9Z QQfGu0IPY0ZxHA/AkodTR5e4DLIiUWbjasIhi3zmxvjr7JH5+lDIKN7PFfVT0EjumPsh KMd2r0C9yQPsofxHINREWdwZiJCDBeonmKv/o/Gz217VnRML5QAmX/woF1eigiTIRnlh KEAR4tQChj7LoA3/Zi0TCr5Hft1LBPTazTAJwAUPBZjaboVclfaHz3YKdgCOI2d/CEG7 9OMg== 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=tl2nPFuLq8bk2g+y2jmt6bYP8uuyjskDl1MjLjXUIBs=; b=ZRVwWEHF4m1gZ+qKvIXB5wrjrtTgsg3rz04K76Hsb+hceiGjFQZH/nyV5GcC7+4Sf2 2Fs0Plcal+Rgtgk3LGPy3jSB2J/Cp36qQ45r1PG+3zVCsRzoz1DqQ9R5CfFSXmvf50CL n4g3E7oD8uUu+p+Fgqk0/UYggXQQ3dttfYq2oxeP9uMOtgS7GkA5sy9sbS7IDRLpwxSO dHykraKcwoUDgffxGFW9lRwwZwx3IJL3o4prV/2CZ2/PMft0jf86p/Vkj8aqhWSFHe9y 31BlkfW68pzvXkGntsi+g9HcvoDQwF7foeenDYQ5hhW4pZCSZOHuf6pODq5Q2rxygHnf cBiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FTUmKl+S; 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 62-v6si7532839pfu.79.2018.07.05.15.14.04; Thu, 05 Jul 2018 15:14:05 -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=FTUmKl+S; 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 S1753801AbeGEWOB (ORCPT + 31 others); Thu, 5 Jul 2018 18:14:01 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39978 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753439AbeGEWN5 (ORCPT ); Thu, 5 Jul 2018 18:13:57 -0400 Received: by mail-pf0-f193.google.com with SMTP id z24-v6so6579559pfe.7 for ; Thu, 05 Jul 2018 15:13:57 -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=tl2nPFuLq8bk2g+y2jmt6bYP8uuyjskDl1MjLjXUIBs=; b=FTUmKl+Su3xkTm9qCLJVOtO43Ck72h5TnxqbW48DH85h1BZtNZKYBpBWaS5BW9MwYO hxvpFLcfAUSMI3TcRy3B4Doah+fsXghiXaHmdwk+l4H2RiVcLWZ/x+NLQdTe7EVorsJT uwEGbC5Yzv8CYCuYYgJKAQqpzEdO26+FYOOTE= 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=tl2nPFuLq8bk2g+y2jmt6bYP8uuyjskDl1MjLjXUIBs=; b=SwiLYYjSd92rbhurFUPa/K2Ln/vM/o7Lumph3+4pHdfWpKy8q4On+mzDey/M/EdvN6 Gezs7bYzd2Vea07wf426PTBzqtimJWB5MJZcrGaK9LRvIFwff2x97HmBakfEamVdnM1T gxr2RLDeWhq/lGbrBD/Lkft6ubtuIH2BHTszQSoc0zDJ3nhN546ldwKbKoTeprqS+5jD xTsqynYNwow8pFBB277bHetWM7vwmgkOFqZpRpK4OSyL3pqLgioYNN5rweMTEWIU5RWj V5fW0aUMkrZXLzeYB0CdCJzBuIyNeQYxryxoZN+Q+TqZKDEB89K53Ux7Z6FAF6oIoTm6 H1eQ== X-Gm-Message-State: APt69E23hQUi5lGTwL47SPb5CjhDN2D6z5+WUPPcGl+KBYd7jvuytlkL 5egxyeHGPqgGPbYgUoZb8ti/Uw== X-Received: by 2002:a62:170c:: with SMTP id 12-v6mr8074871pfx.139.1530828837126; Thu, 05 Jul 2018 15:13:57 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.13.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:13:56 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 3/7] perf/aux: Make perf_event accessible to setup_aux() Date: Thu, 5 Jul 2018 16:13:43 -0600 Message-Id: <1530828827-11604-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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 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 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 Thu Jul 5 22:13:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141236 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2428224ljj; Thu, 5 Jul 2018 15:14:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpflPwcLc3ah920l2EAXzR3wYISUWZG8XsFITFFCL1vuXY9k1Ts5NJth4n5n1ySujRmM23wh X-Received: by 2002:a17:902:2884:: with SMTP id f4-v6mr7882789plb.204.1530828894676; Thu, 05 Jul 2018 15:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828894; cv=none; d=google.com; s=arc-20160816; b=OSY7OLn2AsfBWaOM9ZqdHzXGoegjZtPF3NMeVVBZ0zS33o4P0/U/1fuFcoeyFG2jm2 X3T+KzKuIkvk6LJzjXS30nC+vWoxwjw7r6ufS3PZAeKgBpAaFX8U2AQ17nTBWk1JRwA0 OdINQHOX5n2SCuY8W3sIq0xSaB78NOxz/N4en+i3TuuiFMqR2KgFV0gI9/lF5Xsmqz4T BgaDEFUi3NA5++Re6ZtzGIJeFNRWBwPpRvjG/67RMhdFrO1SJvuCIGRv4PZA9YShTvK8 eAuQQbqFoTcH54nUurcETiWeEK0upjkP0sfhfOQo5KmAEr1kdDaoKLfdP5Rf0J87f3LO fhmw== 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=Kk6/eBloN+GMp0gLJQKhKtW9m+CvB3cMWKDmf3yGyio=; b=yelcidYALb9BPoUGTrcm7mKF1mP/Xjrj6sj6iXaNrMQQ/IV9lgV1pAje87jMhE1oOb ppEIsei7NccjpWs7DS4zT9/2EQR/hdDasRXNI1IU7rdxkCZqMveM0nCwLfOKSZ8WiQiw OtvAOveetJS/0zuIyA+z1jwNrcncaOuke7FsiBNTW/eb1TjsFSJFvhqDD+EtyIgHwYeM WLXsVEOliVV/SEi701tsdUYHGbKX/A+eE62ya+H4ehix2Gj3Ip1W92H9XzYxXxHmy4rm HJaV5p1HyosQluYADSxc2QLBT5ofwd3mTMqkcJPRFHXFt+Xj9ozGF0rp9EpTAi4mJLud 96Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=chvJv8Ds; 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 v41-v6si6997435plg.451.2018.07.05.15.14.54; Thu, 05 Jul 2018 15:14:54 -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=chvJv8Ds; 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 S1754001AbeGEWOw (ORCPT + 31 others); Thu, 5 Jul 2018 18:14:52 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:41509 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753690AbeGEWN7 (ORCPT ); Thu, 5 Jul 2018 18:13:59 -0400 Received: by mail-pf0-f195.google.com with SMTP id c21-v6so1963173pfn.8 for ; Thu, 05 Jul 2018 15:13:59 -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=Kk6/eBloN+GMp0gLJQKhKtW9m+CvB3cMWKDmf3yGyio=; b=chvJv8Ds64iPM66o60/uixPQfAvmU4aIQ4uWC/54Y/t4B/38HSBLiuRzLQ2YLiUzwg Rvsnd4yy6dciFJvcldWdQfbmyNoIzjDYXja9EWgRfOj1nC1v58HC91n61EXJuu8zkjRV ox6RbuoL5ViOOy4HU15BzTRtAcS+Em0M2msGU= 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=Kk6/eBloN+GMp0gLJQKhKtW9m+CvB3cMWKDmf3yGyio=; b=lHX9murhLgqkYSU2sWqw/wLrPU96hdTfrLl+LCkNCQQPmWH6xH74s1NQ5BvmPk58bR kIzFSa54Mq2OaDmDEegKlbHUa5NU5SiYxoIUzWoYFmES0nQuZeymcKebh9ZzcpSOcOga s+C8KPdnw55N3TGZCRBrahqxgDExo/E1wpcbUjtoEQFSpCx2fzwk+Pgs/wxo+faagfgi MqQ5b0cLgzdBJNIYK3T3ZG/j8I5Wq5B5dug/hW1QkOXb6J8GVmFGgiW7qn3jgj+FSQb+ yaPraOjgyDemDy5pIZ3mzt8G+AMGZDW+yN8vl6dkeUeagyD/v+whsV7rCsVyGAhZJ+iK hcwg== X-Gm-Message-State: APt69E3zRR5oDugeZDp2SEgIqp/Xp4VUZ2SvN65TgJhsYb7PVmD9InFd UV4nt5JjTCj8oT1DWkMOn2BVLA== X-Received: by 2002:aa7:83d1:: with SMTP id j17-v6mr8214065pfn.236.1530828839257; Thu, 05 Jul 2018 15:13:59 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.13.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:13:58 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 4/7] coresight: Use PMU driver configuration for sink selection Date: Thu, 5 Jul 2018 16:13:44 -0600 Message-Id: <1530828827-11604-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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 | 130 ++++++++++++++++++++--- drivers/hwtracing/coresight/coresight-etm-perf.h | 4 + 2 files changed, 122 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..5c2cce60da5e 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. @@ -181,6 +184,74 @@ 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); + + /* + * 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) { @@ -194,18 +265,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; @@ -442,6 +503,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")]; @@ -486,6 +590,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 Thu Jul 5 22:13:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141233 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2427650ljj; Thu, 5 Jul 2018 15:14:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpebmprkilWg7maeU3egyZfimapdCb1JytehtwPGgWXVZMkF2ejmgoHA6HN7zEfhCppsqFJt X-Received: by 2002:a17:902:aa87:: with SMTP id d7-v6mr7834753plr.215.1530828847064; Thu, 05 Jul 2018 15:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828847; cv=none; d=google.com; s=arc-20160816; b=A5SPOpy6qXVnKRrp01hpi8JDsYH0BqcZtE6jTKaUtSJ4ilIu0sT7/MmiladJaIQ2NA nB7fRJpn8YoG65N1k1YUl8zEJN6A6dCFQ3S3vmS4RnBPV8Tp2H/dyr1rZG3Txi3FtOUF BsPsYstr2/u8Ms4h1Fv/s42feIRsW+sc4/Ebs4ArYYqS2/IJueHDSIqnwW3Upz5fA+hV bbAbVBS5MIRl6/W+UEHubC96zpc5A5A9bk2kgw4BzGP9aLPpTaMlgxGZrwv3YE6/+Ort Y0rGixxdKAg9w9/qGF3fCo3agzYO7a2LsF7nz2jQ/iU/82nqD8o1j3z9/ZrGg1SF8h94 cRjg== 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=UvLGDKdO/h//3Arbt8FtlqOWoQhtL23DgvWKlB4YJmbXDONBLQ9L+2cHUIXrFnp4Um hrqdDSr7wNad0i4WbCOa/nJcC6gm5e5nib3C7ME7Ou5zbF/l+OpQN+QdMEZo1gs2u50k vXDjKDDl8Y3aTtRdK7NdXLS3/HOVexHjit3FNuw7x0MvEA+Kg3SIqZLS37KA05Mrc+De tzN8e5Bnz7adbr8lU1YDCeZ4fC1HL9PMPxoycalOqUcyuen13Dd/2F6SmZHA895o5t7h qb9nZ79Sf6BtXq6VTblAsSuDvZi+Jw0g+xHpK0c6EZwAZVbKKrC1qHs042FuUm23ADYG ppVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQiALokg; 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 q9-v6si6575941pll.370.2018.07.05.15.14.06; Thu, 05 Jul 2018 15:14:07 -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=dQiALokg; 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 S1753870AbeGEWOF (ORCPT + 31 others); Thu, 5 Jul 2018 18:14:05 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:39188 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753806AbeGEWOB (ORCPT ); Thu, 5 Jul 2018 18:14:01 -0400 Received: by mail-pl0-f68.google.com with SMTP id s24-v6so1874717plq.6 for ; Thu, 05 Jul 2018 15:14:01 -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=dQiALokgXK8v8B5m27XiIPV2jXkQuoMjG/LxQNrLoJWmpqdU2+2GRo6CcYqnTNJhkl mlYzFQeuN4jRUnFk+/f64BbrXsIeRV08+p7/H4rX6HnCr0FQvU5Cksr2inOxLVsLHUh6 Z+u79nfsE7hykfUK2giLjnkVWvBjmyrVrINXc= 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=RJ1g1sxpiFHZpX4ESEpaEUUjSk3LCLXvG/SprgsceR1sghWTHbr14bkqUEkXnNG7RG r4y4bZ28okWISmd8FSAMBu9CJUMidenpkKHD0GLuucsbRcyEzMW8IZZkpzzmC6AGcFnN 1z/SDoHC76BxBvVjgdqNEn+/+HIN00nQHTHBj2E4VY7pC032XvpbvqitkhLV9cIDEJaO KBqTGSThcHaEBVFsyon0j47nEFYbMzYn87xUiOXHkm/fPCIOiVX84k8suD05NiGvs82Z aIO4gY47B6+AhzzPj2l8x6tHQP5bSTxQd3/nR3Cv76ZA9LXU9ynpG+7W+OyhTgCdJpd7 JY3A== X-Gm-Message-State: APt69E0zCcfM1OBZWFCGDNNVJs21c7zYAAanx0We29fUQtZ/sv1Dvs5A 4VZYiyOcFdLROMUiOhKoJlyOxw== X-Received: by 2002:a17:902:e101:: with SMTP id cc1-v6mr7764642plb.96.1530828841321; Thu, 05 Jul 2018 15:14:01 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.13.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:14:00 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 5/7] perf tools: Use ioctl to communicate driver configuration to kernel Date: Thu, 5 Jul 2018 16:13:45 -0600 Message-Id: <1530828827-11604-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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 Thu Jul 5 22:13:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141235 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2427962ljj; Thu, 5 Jul 2018 15:14:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdaFAEE6jolirhmkPVDWQgM7qy3x8xniBJCZaJ/O8zALBikfOf2eQTKgJEYqF1MNXhez0TE X-Received: by 2002:a17:902:b583:: with SMTP id a3-v6mr4107427pls.243.1530828873340; Thu, 05 Jul 2018 15:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828873; cv=none; d=google.com; s=arc-20160816; b=wcQoRlg4gNNgy2ynICeBQ2xv8iz8B9TugnxYS60AfoAMp+vZ0mHmerKiT+vBkJnWao gB6Rar4OvxchcpvfB9+ZG3ZwSxwNPwU+DlQYJmc09lfIzojWtR//VUZl9OPvDJZbMxKy iX9VxXPR7/CSWpnRpc0DN32OmxuyI9c95cgMKL0j9LDmKR8zCe0Olm/7zH1E9dRMyfXf Bz3SZtK8WDQGZPIT33V9jqRXXZT3TlyWU9n4b+i4XNMZJpKL9dNF8b3cNeX/VmAVSNsn 4irxYtfEPaKX/fx4DCc8vcsTsitcCC0j8HmLa5EIZZ52DUeKp38OK6LK4ZtgRQM+p5oE 42+w== 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=aYZjkpi8k6JEMG02ywtlLwzo9iU1xbkbXUFCcDkDJlF4UPo8bA+BPqnLdyeMK09Imk IbtVuvn9bJmU78DIf9axwRO4/1HobBfTtSJHgIy1buST6MTiFf3r1weEc91/qG/2w0r0 DNeWzlB4NFjO0qNyFKXjSn+r/3P1f9+g03aYgZJdTVcXkI311B1/yue5HzvQAACkGnkh BTCEzEQYhMpTQNCvALnJcOvw676nHtlhZ1kgE8BuX3vxYEvQKoPT84F++rDciR+z5jHZ U1N+BPzjqYzvpwzoKTvHdsrmJ9j42MvDuglX33zxhlv00mszoosBbSL3Jlr41R9cJXCm p3bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MxkYtm14; 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 c14-v6si7503425pfl.319.2018.07.05.15.14.32; Thu, 05 Jul 2018 15:14:33 -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=MxkYtm14; 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 S1753943AbeGEWOb (ORCPT + 31 others); Thu, 5 Jul 2018 18:14:31 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:35745 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753813AbeGEWOD (ORCPT ); Thu, 5 Jul 2018 18:14:03 -0400 Received: by mail-pl0-f65.google.com with SMTP id k1-v6so1873199plt.2 for ; Thu, 05 Jul 2018 15:14:03 -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=MxkYtm14vqBDd1L4AMxbTZoCA2DMyV8Wr40xpsY936dcV1rFQscw0ocDVOZPudiNwB ptZBCYXp89alS5RnEUZS32CX++cGboHybRNc8mQZC7mvWgOS1YEql0a2OFCPpyuVB7/b AWxe5xmN2GjplCbR4ixgzoPw4Gtr5NaBJp8Mo= 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=ogQuk4op+f+TEjH7RHXtRvzowx6H1MHvtUyMy1rlPCZYLfTPwtFyWwGSqFmmEqPBxk p8Bw98xhD/wOMqSZOz4cc29R04LLCOSiz024f17azeuAiPR5pNPdzg6ySoRjiflziuXl TyiTGVuAJskcprQnBWcvhRnUYyVcjKOmIHgDWFZDfbizmaJ3TRGufg56AdxT05NJrmI7 qaROeJ5eYFK5SOlnocQKYCVzKDcaFtmFubY4fhTwqKiRF+0ESeBE+de8xvsJbhUMkXMO BR/LTWYtmh42rG3xbKyxCLlxM8i3QfUDfDy5cJLW0ccMArMmq+qM6Ib695cFUoHx2hCz UCZw== X-Gm-Message-State: APt69E1XrL5nulQ181jRWilDWBSZ/oCnetB40edAvwwE/MvbdRdtCCUf TTZvPTIMgQbnPrkgEese0qPkJQ== X-Received: by 2002:a17:902:7606:: with SMTP id k6-v6mr7747802pll.56.1530828843405; Thu, 05 Jul 2018 15:14:03 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.14.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:14:02 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 6/7] perf tools: Make perf_evsel accessible to PMU driver configuration code Date: Thu, 5 Jul 2018 16:13:46 -0600 Message-Id: <1530828827-11604-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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 Thu Jul 5 22:13:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 141234 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2427720ljj; Thu, 5 Jul 2018 15:14:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd8+QVjEU1/A699P/CdANvdnshk8Di/xTyJU9R65l+S1cp3H9nCXHLNjZJJWFKi1bbbbSl9 X-Received: by 2002:a65:4d05:: with SMTP id i5-v6mr7021575pgt.58.1530828852955; Thu, 05 Jul 2018 15:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530828852; cv=none; d=google.com; s=arc-20160816; b=fBVn9Zlslpj0LO6A0arsG0jm1+Djh4kBH0LVa3/L+tyzhoYKMZNh9qXk/6VgqA82xA 74sjzX9XC/GbUZhSwE++DfMFtK1VfW1FZt+IQVV84vkwDXfmjFm81hmREBhepuG/bRQ3 wn46i2/sb6/y+qpx+3qXgn953NYP0gBbJ6Y809/evXOuL0y/GlgSefJwGW0uoDYdBB1h lSsH7HaqLMpm52kx71cyc6pu6TMfPB/3GioYY0Dy2JUEb8fXaM65X/KpuvyV7HEn6/BC hRKx9+RglNnQw7VoNiba4os9jdgXs0mpC/XMWM098SGzpviuDidLDfoDJhQxu9RknySm vxsA== 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=Icr8EEQvx5gvkC1wjPIJlKjiCgS2qY2Ts/josrb27ohVMACqshYfum72Z5qqiqst5B feP0TSnUtCpLhuA1Dot94Cl56RlzFzB2/tvz8h5TGXCxZS00mNJJlz0j/PvAU9Ph05M7 6vmsqd4cCTBeiELfFc3nn7OKl3tGWrNTwV1gvhvGJZxXRloCwA+EAYMyzgwvgmSwAkRQ rPGZMCy2cwqF78pZvgDU0QY1PVZD/TbeaFdabXwlC+3OJxMXWptqbAn3r1D7qQ7e8gV/ 7n+N51/M0GcHXaAqZjBHlhH/j3uEiiFgCTPI5STQkHbUHtUNAfvUFcirr+uhYFlLHpAx r5JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=frAb5TSw; 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 c14-v6si7503425pfl.319.2018.07.05.15.14.12; Thu, 05 Jul 2018 15:14:12 -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=frAb5TSw; 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 S1753914AbeGEWOJ (ORCPT + 31 others); Thu, 5 Jul 2018 18:14:09 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40363 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753806AbeGEWOG (ORCPT ); Thu, 5 Jul 2018 18:14:06 -0400 Received: by mail-pl0-f65.google.com with SMTP id t6-v6so1873980plo.7 for ; Thu, 05 Jul 2018 15:14:05 -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=frAb5TSwjMgxydpfosxygvBWPmg0eUmVPDThn/GV3Isixjgz7WPl42pQEiQAxacSKK DFOVZRAS+2rEXlltTbyOCdveE/mNQ2aplWXdUVtDtBkteFNuXaDgi/l3wHP0ZlhFhKkV p5AMECl8lk8ysopogVD8LdDRRlEmbXzZXV+zw= 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=HnvdmIRI/VNHg/eGsVhUz5tcCMY/WxiGk8RwhdBtfsJWnNK+J3dCZ7mXxBHZH4DunP wTHrH+pJ0qgCNeVur1u4NmzuHMhanJbDM+QXu2rjcMRXhxrM1kc0tYqVOHsI3EF/Faef PXa5o48P2agInyPXbMWHS9/jiAEMLgHDkcygezDr2l2b82nmaohaFgFZ0LamyQZqdrwk 4hn2l8nIGSaPifQ+sJ4rsWbIAv5WWPWyzoR4ivgcillQJOQ/sAyl6lTCcxHxXqMA7hTV PA3ujUPFIXtWQakZ9mvKaxKJBPPk8RqLRFILc05YbCdTQ/i9MYohA1YZA0cutz3GPSV7 YXyQ== X-Gm-Message-State: APt69E0idyIingajdNvFmo/NShyg58C77dNk576AuXIM9h/+lVAkQ/LZ mt7aU4G2O1jtHAAkRVQySe9nkA== X-Received: by 2002:a17:902:8a4:: with SMTP id 33-v6mr7735563pll.343.1530828845525; Thu, 05 Jul 2018 15:14:05 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id r89-v6sm13297486pfa.75.2018.07.05.15.14.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jul 2018 15:14:04 -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, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 7/7] perf tools: Use ioctl function to send sink configuration to kernel Date: Thu, 5 Jul 2018 16:13:47 -0600 Message-Id: <1530828827-11604-8-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530828827-11604-1-git-send-email-mathieu.poirier@linaro.org> References: <1530828827-11604-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;