From patchwork Mon Dec 17 17:21: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: 154025 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2716073ljp; Mon, 17 Dec 2018 09:22:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/VHdOUOWu6c9iCq6AJ6qd0UboA1qTCXLW4gvynf/oPXc6K3byDYYeWraw/KMLMikmqwfDn3 X-Received: by 2002:a63:990a:: with SMTP id d10mr12950271pge.279.1545067321803; Mon, 17 Dec 2018 09:22:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067321; cv=none; d=google.com; s=arc-20160816; b=Imksa9vU2PhFt6eUpf+EXIy+5p+hIvv3max6I61YN8WpHiRk9s4ZSc1bz1EUQh5sAt nyuasl+5S/I1TPte/1VLFp3w2JJowXKQbo+QVwAJBMZKla56fKRBpD1ZoZWRFV+e/5Br fo1bHTlx8j0BqD4ke2VRq95IKgQgxEolL2SVpy9qNhFoqUFIVAKURNY2JAUY1iRBXyYC KS443fJT5n2w7hQaBLpCquQLpdAZCqROukLq4PxNohfqCWva3BfHdupjdjjq2H62EYVS +AQASLqrywXGIOHEunpr90rDkLz7EZpVm3rV8+UHVVzmiBfD4JNiBG4/u5f807eainy+ o+6g== 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; bh=m66nW8iS1E+go7FhvR8iwCr/rCMmVZB6DxxcxVV5OJA=; b=hZPeMAzOYYfTPOMfvTgpfhy17QezuP5FdIlb5jsit9ciIrgE91f7OrYzDjdM2cz18O r7/WKSDl4ApgGzSNGW9C1ne1A8aN9yqnerPiWNCOVEd1zWkYIjvHzjT0+7bRHPJBAw/G UBqylof/sG8+HcDCTNn0peoSVvXZKDROIkhHhvm2OwcM8s0n0oLQu98aSN9a86OIwdxM Qwk/JN7GgecXGAT7vzAzqoDJj5J8QCpDjoa1ZVgluocWcM0Bb+GNT/CEBlVBk+upPn3t DgqLqMyIJEQ61ROPG8kgWCXcUbF3SjFCHTeJhh1jf5Mifu/6TcA7mgWxKRHetYDAmTqC FjXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jUvOrxtH; 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 l66si11943562pfi.5.2018.12.17.09.22.01; Mon, 17 Dec 2018 09:22:01 -0800 (PST) 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=jUvOrxtH; 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 S2388374AbeLQRV7 (ORCPT + 31 others); Mon, 17 Dec 2018 12:21:59 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38547 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388299AbeLQRVv (ORCPT ); Mon, 17 Dec 2018 12:21:51 -0500 Received: by mail-pg1-f196.google.com with SMTP id g189so6427518pgc.5 for ; Mon, 17 Dec 2018 09:21:51 -0800 (PST) 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=m66nW8iS1E+go7FhvR8iwCr/rCMmVZB6DxxcxVV5OJA=; b=jUvOrxtHlUgY/BFT4v3ZK6gRAks785QtJRvw46Ep6IRQVOgDtruq4cxZlhLqUy+z1T PMFlT99Q/QaWBntvS9KUjESXmSD26TxOwa91kqwylbOHv2NZUuW19Pg2YICcEl5lSy9f 8pcK3qsHFRwG7jQRlZjsinIo2nFdnH1gvNWg8= 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=m66nW8iS1E+go7FhvR8iwCr/rCMmVZB6DxxcxVV5OJA=; b=MLJROg8fbqp4GbfacShWvNWYgBVED0QzOz/EiKlPax5pdkv4olfRhU2jTPHVupJbuH Wv3KhQSM5WCyYgBrsCpFYs4Cso84KRqC1dWi9bbBePdftcWN4uYYhHROUMmd6T3FHtZg v1akBBwRL3narj3Yz4n5Wn1DkGCopNSFIGtP/FqW8w2tllEv3Fo8FdXfNqgp0e03h0Gj KkHFhGcYMzXXSzOu6qIxV7w/+w29Syz7xfUuTvJNQXyz/xLMpS+4wEZpvx8ZWHuAlaQo awFK9yQN9fn80YR3sNncbXuXnrK6x0b7U51Rzrd4jeY7EQDLEtTNf6UUL8rDEXHuIwXN CFyA== X-Gm-Message-State: AA+aEWYK6WOBv9AD0HmgbOB515lbFlwqiI0acBGyw8hz8GIDI9rZD6Y9 0JDE7Ep4evW9QnMg0bP3G5BU0g== X-Received: by 2002:a62:7086:: with SMTP id l128mr13520574pfc.68.1545067311075; Mon, 17 Dec 2018 09:21:51 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:50 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.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, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 1/6] perf: Introduce ioctl to communicate driver configuration to kernel Date: Mon, 17 Dec 2018 10:21:41 -0700 Message-Id: <1545067306-31687-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-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 9de8780ac8d9..a39d8dc2e7a9 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -462,6 +462,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, __u64 *) 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 9de8780ac8d9..a39d8dc2e7a9 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -462,6 +462,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, __u64 *) enum perf_event_ioc_flags { PERF_IOC_FLAG_GROUP = 1U << 0, From patchwork Mon Dec 17 17:21: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: 154024 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2716038ljp; Mon, 17 Dec 2018 09:21:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/U599MomyiHEt8ymXmUprDhJllNX2hOJobkyTKL2M3/43C7PxDWVjdy4q2Ibry2swcOsNEY X-Received: by 2002:a63:bd51:: with SMTP id d17mr13092774pgp.443.1545067319830; Mon, 17 Dec 2018 09:21:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067319; cv=none; d=google.com; s=arc-20160816; b=wPeRPQupPrQX+oMzO5p/E2hpWCmvrrDmBfRTXUDRYfCTB8gt+UjftRWWy/TKz+bXnn obJvYOxiBeEAfX0sp5jIguLxZemwYVMxacKHUzCVjNfSv/WBxpJ65iG8LB4gOGDhNUJM Um3hZCjPvOEBDbBazFoGU4BMl9OUldDRj8OJfR92ZrHOSNc+fjYl4+t6BCW+h6tuqoZK z52vPcHwuMCnRy8zkvU//W6f8MBjqUA4ZbiOSdV2BsgP8oiaarY67/mw0uXFwUwvcQ8P Y7LPftITf76G8njMwp4WAcBC5YyeF19Uh9/Nb/CFgjhyfL5egKNEMmnvz5XPOpm4umVe yFIw== 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; bh=BBqRtwO6PGFlctrxGALj04LHSsu+aeiHiAedSoB+rfE=; b=NKWPV8rrrrY7nbpN+3w+bhVM1xw8J1E5DlNFQAKYPj6LVI0mrjC6TmRmsKApe4uAM6 ZJRb6zaMaGn97l0Buq9NjWRgeBKqioS9oDVcoNzl1jdOVUjt0n8fF3He1CpjWQw1GoxC 8J90puGPPiyLfWjygGkYcL+ld1ZwgFmnLMuSMg0yugYdPhLF6xyZEHwX0RSGMWVexEVT J6X0iPslklS6W/dgkexiDxFon4yVYSXOHgCjCehOlaLS1hIIVH7N19fcqhP5ytFvdtlG fxYPhldbvau+frzB5M/V4ri0r8aUhW/ohTqx+uHb6/EPIObuaHqfU/HNGA0chsvBca7z +wiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C4nqGzh5; 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 j10si10453411pgn.365.2018.12.17.09.21.59; Mon, 17 Dec 2018 09:21:59 -0800 (PST) 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=C4nqGzh5; 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 S2388361AbeLQRV5 (ORCPT + 31 others); Mon, 17 Dec 2018 12:21:57 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46676 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388315AbeLQRVx (ORCPT ); Mon, 17 Dec 2018 12:21:53 -0500 Received: by mail-pl1-f195.google.com with SMTP id t13so6418896ply.13 for ; Mon, 17 Dec 2018 09:21:53 -0800 (PST) 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=BBqRtwO6PGFlctrxGALj04LHSsu+aeiHiAedSoB+rfE=; b=C4nqGzh5cPKSL5/IPhN70S1CecaokCmGiC2UXWLUIX8Jb+zGXeG8cV3FViYapKUt9P JtXBFdraKVQej2cL9Lsa2nSV/XFm0HcIRBNqSIoye+CvqslcB3S9Hu7O2Q+1Ljkw7MqG +LqxmQIWHJywbSjjqIz9NvNmGwKFJsf96HVaU= 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=BBqRtwO6PGFlctrxGALj04LHSsu+aeiHiAedSoB+rfE=; b=gsWhQ/eebuDS2Nw+92rS64u54cmtSG8+WXQTP/rh6+FaLbJi0nRHms91oAu+034bhN sNw4BbUg0laO7YzKRvOLZ1gp2zK/uXOsW7pvv42sd4UdYDFIvf8Q6BIwYBcxeYCTl52K iDGLElcNcDT2QRkZqv0/oiTDAqEWfSFVheST5saLo2nyyHi7pXYe3ZiXvG3og9JP7ruy e43TSR5m0HZrooS7LpUzuJ4ig1tDhwl3kxVYzCSdQ3YPm3+WBHSys7VAqt4ih/z4W4JK OjQ7SNkKbuGCjNIcAKnT1b+PEyCdUpJyenrDKgFU4czzMeh282k9wryHasx8jZXfb5RS 2fwQ== X-Gm-Message-State: AA+aEWYojb9XL3he1GUIOge4jeTYXe2MHcYHTGD0iEEJn0lznc75+Ctw 1246HmdkzGW8n6RiZPWz9vcxig== X-Received: by 2002:a17:902:128c:: with SMTP id g12mr12797936pla.146.1545067312998; Mon, 17 Dec 2018 09:21:52 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:52 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.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, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 2/6] perf/core: Use ioctl to communicate driver configuration to kernel Date: Mon, 17 Dec 2018 10:21:42 -0700 Message-Id: <1545067306-31687-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-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 | 38 ++++++++++++++++++++++++++ kernel/events/core.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) -- 2.7.4 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 53c500f0ca79..8e69b7e309e7 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,17 @@ struct pmu { * Filter events for PMU-specific reasons. */ int (*filter_match) (struct perf_event *event); /* optional */ + + /* + * Validate 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, + u64 value); }; enum perf_addr_filter_action_t { @@ -1235,6 +1257,11 @@ 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; +} + /* * An inherited event uses parent's filters */ @@ -1249,6 +1276,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 84530ab358c3..af7a53c97744 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5003,6 +5003,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); @@ -5089,6 +5091,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; } @@ -9128,6 +9134,66 @@ 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; + 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); + drv_config->config = drv_data; + raw_spin_unlock_irqrestore(&drv_config->lock, flags); +} + +static int +perf_event_process_drv_config(struct perf_event *event, u64 value) +{ + 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, value); + 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; + u64 value; + + if (!has_drv_config(event)) + return -EINVAL; + + if (copy_from_user(&value, arg, sizeof(value))) + return -EFAULT; + + ret = perf_event_process_drv_config(event, value); + + return ret; +} + /* * hrtimer based swevent callback */ @@ -10052,6 +10118,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 Mon Dec 17 17:21: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: 154023 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2715995ljp; Mon, 17 Dec 2018 09:21:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/VSCQAyfE2TH/Uny60DpZivtGYaMOUkzkNZ8EF0c9OspE2FuO9a6n9PaKc6L6LmaQPkZ9+g X-Received: by 2002:a17:902:6b09:: with SMTP id o9mr13392175plk.208.1545067317525; Mon, 17 Dec 2018 09:21:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067317; cv=none; d=google.com; s=arc-20160816; b=CZddo2gg/506QgGjdbp7FqSDmpampHxcfq/pn+fOnGqJY+NONGPukbQYPBSWNk0SMD PrQYZ+P/rn5PUN7ScLzjqWRwxVUKsOHJj48FW85TCmGJ5vcVUZKVHSjQq6nEY93fxsSR 3AxfB1BHsPlrqmlkfQErRZKqJa3y5En19kzO3ULyTjGIQHCqnV5B46M63Po89UYJKdec AKEuNQB/JBvpe2ugSuLD16bAXyDPZ/xZdfphv7+QFfmJNtGCwJJUFAIOQXn3YoThBx4x 7SiRCy3GAL+WsWnOm3wUEx99Br8fqJoDBqRYK8tjY2miR3bsxIi5BoerWEZfR1rXL/K7 MfVg== 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; bh=ydPIIvwp7JBz3247k2TeCqAjfpttVF2V+RHCfDoclY8=; b=oA+0h25djz1g+3DAVPgILqu9czCJfyPsALgj7zun2WJRGhcvSwvrq7z0Utbx95tkoZ IjKXcOGfH27WhT2Vr6gA5S67d+srsxxoVKfk/gBmqcX6JDuaa11/3HHDTOLSrnZNwTbD PxUzLEkLiu067gJQf3SEj6+50EN4bJIXkZ/LvAuAP+gti2xBeA3E4EoBzNnCi4BqtAhW wlC0OkkQFX6eVr9BvRKzMcRE2PHkhpquECg6encY6qo44oFcZxe5hLixeKjLxauozRS1 +UgK81BhbT3+f02c1fGXkThWig9qykkBspq5APROwAddP6POW4LmTDwpH3Ex1TR46AT8 bnTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bFXHmWDg; 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 g12si11206338pgd.567.2018.12.17.09.21.57; Mon, 17 Dec 2018 09:21:57 -0800 (PST) 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=bFXHmWDg; 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 S2388348AbeLQRV4 (ORCPT + 31 others); Mon, 17 Dec 2018 12:21:56 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34051 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387698AbeLQRVz (ORCPT ); Mon, 17 Dec 2018 12:21:55 -0500 Received: by mail-pl1-f195.google.com with SMTP id w4so6450076plz.1 for ; Mon, 17 Dec 2018 09:21:55 -0800 (PST) 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=ydPIIvwp7JBz3247k2TeCqAjfpttVF2V+RHCfDoclY8=; b=bFXHmWDgkZqoXIobAE+FI43Ux8IdZjsFC39FgIUq/Kr8vG1aXSlYrZMeGMkvMMVmbc FX+9kU9osL2/DFcIxUBiUDVlrz9H0rYNIEcIwwT/IyZP7ILrWbQAqAR7uwtuNAk7Uvzb OSqQEJ/43Bn+uyCieHa6d0zJ+GUJahZUjSnKA= 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=ydPIIvwp7JBz3247k2TeCqAjfpttVF2V+RHCfDoclY8=; b=lJA30JDbVbuVsFr5l5m6TkBic5G6Fm9SzgreSz9JCJynQ1OFmBJc+Da6ntSFaH01ho qyE/iqPkIjsxcfk8ObrNjUctJ38QTHkPrBxxnhCCIluQU4uVG8KRMLPn0ctVk7x0xUel 1V+Lv9KYQ3MiNZrN8F7mkUqnBEWQh+fvhvtWfRBd0X8UuJ09GyMY+3E8AN2a3nTfV04t pfIFDFmEvQII1ZYhkhQfNMrkvfcgCV7yY16jJWW8LPCHpeQAbNnwfIu8UxAF31UZ1llt 2ERM17Pg1kryODpTzUJwXMSgeEyRH8Ga54nqDfFoNg9CQCN2T5mX8E40X8hv87u4xxDA pM6A== X-Gm-Message-State: AA+aEWb2LIB3ZipH6fFB7qNLnJIPxG7Kr0jIFm4EIswYnWGgQUDYiVmM hLCKCpLqFRTem0Jrqz5jJvDvgQ== X-Received: by 2002:a17:902:d202:: with SMTP id t2mr13608602ply.193.1545067314681; Mon, 17 Dec 2018 09:21:54 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:54 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.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, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 3/6] perf/aux: Make perf_event accessible to setup_aux() Date: Mon, 17 Dec 2018 10:21:43 -0700 Message-Id: <1545067306-31687-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-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 7bf604ff50a1..df92c2af99b6 100644 --- a/arch/s390/kernel/perf_cpum_sf.c +++ b/arch/s390/kernel/perf_cpum_sf.c @@ -1600,7 +1600,7 @@ static void aux_sdb_init(unsigned long sdb) /* * 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 @@ -1612,8 +1612,8 @@ static void aux_sdb_init(unsigned long sdb) * * 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 3a0aa83cbd07..f7ec5c5fbf0a 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 abe8249b893b..f21eb28b6782 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -177,15 +177,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 8e69b7e309e7..b772ea2441a7 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 4a9937076331..857308295f63 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -658,7 +658,7 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event, goto out; } - rb->aux_priv = event->pmu->setup_aux(event->cpu, rb->aux_pages, nr_pages, + rb->aux_priv = event->pmu->setup_aux(event, rb->aux_pages, nr_pages, overwrite); if (!rb->aux_priv) goto out; From patchwork Mon Dec 17 17:21: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: 154028 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2716400ljp; Mon, 17 Dec 2018 09:22:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/UOIUYsYMTEpaV+uUUkdbixtNDY0SkFHTG0nSySUZTKPdM7hqIjN9SJZglhy0Fd+o6GH0M/ X-Received: by 2002:a62:cf02:: with SMTP id b2mr14109669pfg.183.1545067340054; Mon, 17 Dec 2018 09:22:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067340; cv=none; d=google.com; s=arc-20160816; b=uCZctZuPFItJdQphOsxULBK9FYjJQTBC2VAt4/2olBsAEcvNN+ev9lhpWNH6p3vUGg U+xehrPuDgJ9saD6hqzcn1EEUtZV0LiUKxFnnYpNjuK84HDPfqgzLS8HWwgwnL4NmfJA TRdawTdYSMsyFVTdF63GFAr9FohkRBUisfLN8DWrAySH6ESPn9YzjHETKfVkATXQ8tNt TIE0KLW9M7EM8e/Ai03H+zvaxiQ90diPPeeVK7BIlNUKF0CNv+w3wlvo3vMF81/U/17E 5FuGsFtr296wo4MySXox5mz2nefkKaMeit2MbYww7IMQAGHJbRBPgn8Njiz/QKLuu/Bp 3Qjg== 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; bh=vffhfUlrlCExin749UjB4Nm/CBeftT0GbW0095v/Xho=; b=w4aYYTLDZakkvUNvXdXEvUa2weD95Ha9PADwCCq/6XbkpgGuwuL+brFgGkaCFpqkns xY6R4D4LjBuYnhJ64UVpGAyGKjM+Z5YCU8YOmiTukZM4BvTH0oFl3n2fDFEecktISZCN WsQodyAJTHWq2MWKMo8IoMGZk7l9y4YDI4BC1sdrdopHyPbTxncy95xrxLUzCHdkqm01 7YpPaVQWR8YquQ6hhXxkwl31ttv02X5swPq1eYlcDEl9Mx4A5MjmUNosrWPZgwgG/VJI N6NdSPme/jjZ4UjIIazXjd4Y2TDRzuKw/L1QWuZpBRe/5gbom/e4e2jYykKeznsmJFhj Y1bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C+6xK+0a; 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 r17si11117837pls.380.2018.12.17.09.22.19; Mon, 17 Dec 2018 09:22:20 -0800 (PST) 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=C+6xK+0a; 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 S2388410AbeLQRWR (ORCPT + 31 others); Mon, 17 Dec 2018 12:22:17 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43950 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388354AbeLQRV5 (ORCPT ); Mon, 17 Dec 2018 12:21:57 -0500 Received: by mail-pl1-f196.google.com with SMTP id gn14so6435618plb.10 for ; Mon, 17 Dec 2018 09:21:56 -0800 (PST) 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=vffhfUlrlCExin749UjB4Nm/CBeftT0GbW0095v/Xho=; b=C+6xK+0a+lPk9/Jka+QJIqeB/MDgk+NIwssQyhCsdKazJTK6n7oJHufE+4M2VUaOta VuCjWVMB0oSrl6eYfOVL2IMEbPjH9hRfS3UyN2MKJx6Bz1TAu1BJaQ8+hJsCkFxVmDEG n4zktOwuQ/RU4YR/amHmjcaCwvJTzliiG4kyI= 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=vffhfUlrlCExin749UjB4Nm/CBeftT0GbW0095v/Xho=; b=ZDmWZeTLOvYyurwE3gfv3Jyqcj2P0tkCUkPmkC88w1XNIZTwmMFc7OpX9XA8Z+avz6 N5jHFKgHkD+QBi13Q/T7XQK8YWzjV6qBeTddWOGhp5G+k9E684LJO8jfvZ7+HpL50yKX MhyKgDNo9zguGqSzzi1jAVuWkAELRlQHXrT8uBkXWPhdUwfHIhK05YPygcd9h0FE6FE0 8I1tm/3xCdNcwlJ7bzMhME5zmIBaEXThWlyeaXmNUDKjONfdcJLpdupbYetpS1MDpo1I TSj2zOcjaicRJOvrzrH0z4qPOe8+dXKlgLVpBF/MmhD6pw5qkxumaKROlnrYRUpR+LJL PxQw== X-Gm-Message-State: AA+aEWbKxPntRZyYmmtaT7oTC7q7vqEz/m3+pe9puGpqB0ieOe5f/Mlc FQlcY0QucqRPf4j8LVCA5FbE+g== X-Received: by 2002:a17:902:9a9:: with SMTP id 38mr13171952pln.204.1545067316335; Mon, 17 Dec 2018 09:21:56 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:55 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.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, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 4/6] coresight: Use PMU driver configuration for sink selection Date: Mon, 17 Dec 2018 10:21:44 -0700 Message-Id: <1545067306-31687-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-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 | 74 ++++++++++++++++++++---- 1 file changed, 62 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 f21eb28b6782..a7e1fdef07f2 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -4,6 +4,7 @@ * Author: Mathieu Poirier */ +#include #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -177,6 +179,26 @@ static void etm_free_aux(void *data) schedule_work(&event_data->work); } +static struct coresight_device *etm_drv_config_sync(struct perf_event *event) +{ + struct coresight_device *sink = NULL; + struct pmu_drv_config *drv_config = perf_event_get_drv_config(event); + + /* + * Make sure we don't race with perf_drv_config_replace() in + * kernel/events/core.c. + */ + raw_spin_lock(&drv_config->lock); + + /* Copy what we got from user space if applicable. */ + if (drv_config->config) + sink = drv_config->config; + + raw_spin_unlock(&drv_config->lock); + + return sink; +} + static void *etm_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) { @@ -190,18 +212,11 @@ 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 config from user space. */ + sink = etm_drv_config_sync(event); + if (!sink) + sink = coresight_get_enabled_sink(true); + if (!sink || !sink_ops(sink)->alloc_buffer) goto err; @@ -454,6 +469,40 @@ static void etm_addr_filters_sync(struct perf_event *event) filters->nr_filters = i; } +static int etm_drv_config_find_sink(struct device *dev, void *data) +{ + struct amba_device *adev = to_amba_device(dev->parent); + struct resource *res = &adev->res; + u64 value = *((u64 *)data); + + /* + * The HW mapping of a component is unique. If the value we've been + * given matches the component's start address, then we must have found + * the device we are looking for. + */ + if (res->start == value) + return 1; + + return 0; +} + +static void *etm_drv_config_validate(struct perf_event *event, u64 value) +{ + struct device *dev; + struct coresight_device *sink; + + /* Look for the device with a res->start equal to @value. */ + dev = bus_find_device(&coresight_bustype, NULL, + &value, etm_drv_config_find_sink); + if (!dev) + return ERR_PTR(-EINVAL); + + sink = to_coresight_device(dev); + put_device(dev); + + return sink; +} + int etm_perf_symlink(struct coresight_device *csdev, bool link) { char entry[sizeof("cpu9999999")]; @@ -498,6 +547,7 @@ 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; ret = perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1); if (ret == 0) From patchwork Mon Dec 17 17:21: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: 154027 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2716238ljp; Mon, 17 Dec 2018 09:22:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/XG10Nd5p6CgFD12R7GKCLdU8EFms1cafSoIGxyAkb16KOK9W6bGs5ai0hCSoKiczDuCFXA X-Received: by 2002:a63:82c6:: with SMTP id w189mr13058906pgd.344.1545067330847; Mon, 17 Dec 2018 09:22:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067330; cv=none; d=google.com; s=arc-20160816; b=gb7hlVNhWfNfLCidxq1e/GDp55/5ZwdybL2yhcb0Sny1L/D28gMKLFPTFWPmVM9kTp H+G5AP2flmZSH0xur4NweAJWSAwsiAF4fFyLbLHt8yxNPl1Xv/Kz00dBJugEf9kBrF31 OcZZc02K/BQGxgdzzzHzRe/aFSE5oevtld3HZ67xIP6WU3+WEQubrsWQA0EoEc2OhY7o nmxRGiDVAuiPh3Hn1ZCDTUYLDFfIboK1s5hjL7vzg5WObYlM/q+8GH/0WUqbDKADZ7vK kWBl+sRYr02E+mRT4izJ6XBb8U/MXM+jHNqp7/c2QSQDa/5Ju5hDfQozpmlXY0ONmkpi Ixhw== 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; bh=OR+Emv/hXsuIpqoetjY/PmsPRuVeBGeNKk4nTUUJUzU=; b=HWnBGa1x6rGGGm1/kS2g1IVVeTh1b3qx+fIttsoq8YroTyfuyz2xrDQZWcGyXRY+P+ Otu9shRfXF/kJPgAshX335+gZvvHqQ9/8M8HCGaRsPtefYWEu0jVl4dDinxciCW78Pw8 +FX5cmmtztQOlRpSyZGCB7sU/zHxpeZq4knX0jMX5d0aojsjmr7L69HN+5Vfxc0Q6rMr My7szUhwtl6gsO28+I+dB2v4dWimJ+6n7uYiVatW0QdolP6bBPIfhJCN5gbro7T5KiNQ HxASBPqQLkAzbRxXFOfI1VxMnDvaEGfQM7fsqkQ3q17mRi5YNWcxQuZlDGUg7BZAgKDU 3Lug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dPgpo2wa; 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 a28si11454942pgl.530.2018.12.17.09.22.10; Mon, 17 Dec 2018 09:22:10 -0800 (PST) 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=dPgpo2wa; 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 S2388398AbeLQRWJ (ORCPT + 31 others); Mon, 17 Dec 2018 12:22:09 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36705 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388353AbeLQRV7 (ORCPT ); Mon, 17 Dec 2018 12:21:59 -0500 Received: by mail-pf1-f194.google.com with SMTP id b85so6696144pfc.3 for ; Mon, 17 Dec 2018 09:21:58 -0800 (PST) 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=OR+Emv/hXsuIpqoetjY/PmsPRuVeBGeNKk4nTUUJUzU=; b=dPgpo2waSyuc9a3TJA/V7dNAXshyYck6CqdnbQRgU5Z8zar4mMIWk+eTFg6ZmMowMJ N/bIULoBUbIuAso+anc3LL6Q/cNO7lU7KHqQv4YNR3XXy6mQ39XEDbAqytopUKvgrQ7B eIMoJAqVvSn1Ft50WIl077RWF3ZxDBIV6F5nc= 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=OR+Emv/hXsuIpqoetjY/PmsPRuVeBGeNKk4nTUUJUzU=; b=WfpuNIZOsHmNXSQ5131Tg2z2ZPtS2X8spQp6mCWFSGjNEEau0SxlqhiKfS61s8Yiy4 2A0nENvG+MA/Nr9UnU4vMnlGCYFG1bA0T7rnB31dAsX0GIXILYbvzJkHXZct8WDbKMig /vp6EwV6TAW05EYPvFhSbUnHay6jJbHqOT4gNrE0kW7O8xkej/PuIG6C+Zp7R3N6f1+t 33CzGcpgzCQpMD7cJKzVfYoJQIgnfuCzbQX4F9obknSftM+ArqzTh3bBqeEiPNy6mjr1 Xc19nBOH2TEBWLBjuBhSdgI09Y6WQUhzJJdDlh3AZaZorwcuQAgY3E4qL/hl0BZGggXs 64zg== X-Gm-Message-State: AA+aEWY6Ng5vvlKERKwXt3G9xuiJcWgbkqB50sELWgh/AhsUiTndNQcq O9+HKa2NKq88z1DBdSx2UiNDuA== X-Received: by 2002:a63:f901:: with SMTP id h1mr12824226pgi.154.1545067318085; Mon, 17 Dec 2018 09:21:58 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:57 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.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, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 5/6] perf tools: Make perf_evsel accessible to PMU driver configuration code Date: Mon, 17 Dec 2018 10:21:45 -0700 Message-Id: <1545067306-31687-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-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 the perf_evsel available to the PMU driver configuration code. That way function perf_evsel__run_ioctl() can be used from there and information pertaining to the perf_evsel_config_term is still available. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 22 +++++++++++++++++++++- tools/perf/arch/arm/util/cs-etm.h | 3 ++- tools/perf/util/drv_configs.c | 30 +++++++----------------------- tools/perf/util/pmu.h | 3 ++- 4 files changed, 32 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 2f595cd73da6..d8081c2e6d44 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -635,7 +635,7 @@ static int __printf(2, 3) cs_device__print_file(const char *name, const char *fm return ret; } -int cs_etm_set_drv_config(struct perf_evsel_config_term *term) +static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) { int ret; char enable_sink[ENABLE_SINK_MAX]; @@ -649,3 +649,23 @@ int cs_etm_set_drv_config(struct perf_evsel_config_term *term) return 0; } + +int cs_etm_set_drv_config(struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term) +{ + int err = 0; + struct perf_evsel_config_term *term; + + list_for_each_entry(term, &evsel->config_terms, list) { + if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) + continue; + + err = cs_etm_set_drv_config_term(term); + if (err) { + *err_term = term; + break; + } + } + + return err; +} diff --git a/tools/perf/arch/arm/util/cs-etm.h b/tools/perf/arch/arm/util/cs-etm.h index 1a12e64f5127..a3f8dde6ccef 100644 --- a/tools/perf/arch/arm/util/cs-etm.h +++ b/tools/perf/arch/arm/util/cs-etm.h @@ -10,6 +10,7 @@ #include "../../util/evsel.h" struct auxtrace_record *cs_etm_record_init(int *err); -int cs_etm_set_drv_config(struct perf_evsel_config_term *term); +int cs_etm_set_drv_config(struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term); #endif diff --git a/tools/perf/util/drv_configs.c b/tools/perf/util/drv_configs.c index eec754243f4d..f7c1bcf08549 100644 --- a/tools/perf/util/drv_configs.c +++ b/tools/perf/util/drv_configs.c @@ -25,7 +25,6 @@ perf_evsel__apply_drv_configs(struct perf_evsel *evsel, { bool found = false; int err = 0; - struct perf_evsel_config_term *term; struct perf_pmu *pmu = NULL; while ((pmu = perf_pmu__scan(pmu)) != NULL) @@ -34,29 +33,14 @@ perf_evsel__apply_drv_configs(struct perf_evsel *evsel, break; } - list_for_each_entry(term, &evsel->config_terms, list) { - if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) - continue; + /* + * No need to continue if we didn't get a match or if there is no + * driver configuration function for this PMU. + */ + if (!found || !pmu->set_drv_config) + return err; - /* - * We have a configuration term, report an error if we - * can't find the PMU or if the PMU driver doesn't support - * cmd line driver configuration. - */ - if (!found || !pmu->set_drv_config) { - err = -EINVAL; - *err_term = term; - break; - } - - err = pmu->set_drv_config(term); - if (err) { - *err_term = term; - break; - } - } - - return err; + return pmu->set_drv_config(evsel, err_term); } int perf_evlist__apply_drv_configs(struct perf_evlist *evlist, diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 76fecec7b3f9..47f44394042b 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -29,7 +29,8 @@ struct perf_pmu { struct list_head format; /* HEAD struct perf_pmu_format -> list */ struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */ struct list_head list; /* ELEM */ - int (*set_drv_config) (struct perf_evsel_config_term *term); + int (*set_drv_config) (struct perf_evsel *evsel, + struct perf_evsel_config_term **err_term); }; struct perf_pmu_info { From patchwork Mon Dec 17 17:21: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: 154026 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2716137ljp; Mon, 17 Dec 2018 09:22:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/UprZ4ka1hfupW8C7cdwCdWLFKcDxSuOVYfEmN/XDm8W6c5yJ0u1QhPGiQaTrkd9Hm1Q1qn X-Received: by 2002:a63:9749:: with SMTP id d9mr12510628pgo.415.1545067326078; Mon, 17 Dec 2018 09:22:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067326; cv=none; d=google.com; s=arc-20160816; b=TCt3PDRqkneH/+NvprVRr3pacK9Ymj+g694MphQ+Hnl5Xu5sDNjKV7817SwhbLHlSx AWOR3SdqrAwYY5BiwlX//ID9+yZWxJqzZKHMkQZBEukem6wgBolwJmnHDmwaDbrXuk06 Doi9CDL14MvdTE+dVe+9BqfM2KuGzkv/IW39BDfQDFTdPt3VXd2a2vDLsXlU5/DCnA8r 4by/1smgSia4m06NkFRAy6jUCclmswZ25yuPcCfcKYBoTC16jbZOGr3Yz7YdCRXfAAuG N4FdoL7rZ+IDsJEH5+oIjESsy6mJ23CEEvL86HWTCTN1OyaKyOFYrc97Wr2qlVO3Lk1x CwzA== 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; bh=3vpJNza9or+DqAPy2Ouz+IaFpD2uwWIrDBJByTZlu+A=; b=bXkAMsApwkikShF2+RFggRUBQx1OgRQ6TRFdxu+k0AwsZ9etmu1wVDCIAHfJutSOMd +L73Fg3AYW7+lloec2J3W49gvJbOptjs1oEIynM7T31zPLi8+qys5rNN+27iFjASzVN+ p/ZC5XBm6zxdLpQ4PJD8pxXrVfGxmcHDfpHl1Z4H9YpDgrPMi3nATHzPzPIPJg+xbLU9 YaIHkYrf9jztAAC+JNcwK6SJA3IBm9H4XQQeswPHiZ/6KW8HdNFk/E6JZ56g9XI1P0sG ac/vyUwwhA1SQMr9IIi6DnI3U7y/PGMCvZdIojg4jIoPyDby1n8DS8AiFh2OVyfaTNQ6 gKwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WBT0TGuz; 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 a28si11454942pgl.530.2018.12.17.09.22.05; Mon, 17 Dec 2018 09:22:06 -0800 (PST) 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=WBT0TGuz; 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 S2388388AbeLQRWD (ORCPT + 31 others); Mon, 17 Dec 2018 12:22:03 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45964 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388299AbeLQRWA (ORCPT ); Mon, 17 Dec 2018 12:22:00 -0500 Received: by mail-pl1-f196.google.com with SMTP id a14so6428730plm.12 for ; Mon, 17 Dec 2018 09:22:00 -0800 (PST) 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=3vpJNza9or+DqAPy2Ouz+IaFpD2uwWIrDBJByTZlu+A=; b=WBT0TGuzBRScvsuhIEQeJ4p5P/ED7pvZwMP1kvAA1n//d+x1KAuFV92CjrST4/Vzml 25yzhLdHeKYAFk+jZaWo74/5nIrkljnJhwDC1jFUIYhUQ0fpKf/FUzzRyUGlPuGnpcSo WmX62nnHyUDu8zelXpQJOHbYsDzeBAAXBsq0E= 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=3vpJNza9or+DqAPy2Ouz+IaFpD2uwWIrDBJByTZlu+A=; b=V4yfm0rdLHuG5VLmdMfSkXTaacOnIqrsWTk6pioI3tVS4tS95CTD02lb3kBmoxJ3wh STZVCpNG0QY1TEpUk4GCzB5pKr310rCy7qyYR6NI0hnaV2P/FHNCDmqgLd3lGtxMYmO5 r52z9rtdtjUYhD4ZNWt81CjigttoKc25SSTnwWpy5i55gPEVtn2C2/5pyG8m2xVnnufJ vfzAQn4D4bfAsyUp8bCZVE06szb3dxXQZVW8K8NPoI38Ocw8YRTD/+GwN4QPSJmpjny3 micuyFdmYbFp9YX+m6dDILMUXP32x07+cXlqv/+y5F7N2yv83McWPuvhudOiT7cgoR65 rPAw== X-Gm-Message-State: AA+aEWakXC0vDV84P9i2Vkh7culdjm1zfDxFtS7obAq/yaqog/ZM0uvG L3ppmuFg1JlGlW0UOrpU0Oaoqg== X-Received: by 2002:a17:902:4681:: with SMTP id p1mr13799807pld.184.1545067319819; Mon, 17 Dec 2018 09:21:59 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:59 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.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, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 6/6] perf tools: Use ioctl function to send sink information to kernel Date: Mon, 17 Dec 2018 10:21:46 -0700 Message-Id: <1545067306-31687-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-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 The communication of sink information for a trace session doesn't work when more than one CPU is involved in the scenario due to the static nature of sysfs. As such communicate the sink information to each event by using the an ioctl command. The information sent to the kernel is the component's HW address, which is guaranteed to be unique on the CoreSight bus and known to the kernel. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 66 +++++++++++++++++++++++++++++++++++++-- tools/perf/util/evsel.c | 6 ++++ tools/perf/util/evsel.h | 1 + 3 files changed, 71 insertions(+), 2 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..41e394806707 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -22,11 +22,13 @@ #include "../../util/thread_map.h" #include "../../util/cs-etm.h" +#include #include #include #define ENABLE_SINK_MAX 128 #define CS_BUS_DEVICE_PATH "/bus/coresight/devices/" +#define AMBA_BUS_DEVICE_PATH "/bus/amba/devices/" struct cs_etm_recording { struct auxtrace_record itr; @@ -619,6 +621,41 @@ static FILE *cs_device__open_file(const char *name) } +static int cs_etm_check_drv_config_term(const char *name, u64 *addr) +{ + char path[PATH_MAX]; + const char *sysfs; + int err; + FILE *file; + u64 start; + + /* CS devices are all found under sysFS */ + sysfs = sysfs__mountpoint(); + if (!sysfs) + return -EINVAL; + + /* The resource file contains the HW start address of this component */ + snprintf(path, PATH_MAX, + "%s" AMBA_BUS_DEVICE_PATH "%s" "/resource", sysfs, name); + + file = fopen(path, "r"); + if (!file) { + pr_debug("Unable to open file: %s\n", path); + return -EINVAL; + } + + /* We just need the first value */ + err = fscanf(file, "%016lx", &start); + if (err != 1) { + pr_debug("Unable to get resource start value for: %s\n", path); + return -EINVAL; + } + + *addr = start; + + return 0; +} + static int __printf(2, 3) cs_device__print_file(const char *name, const char *fmt, ...) { va_list args; @@ -635,7 +672,7 @@ static int __printf(2, 3) cs_device__print_file(const char *name, const char *fm return ret; } -static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) +static int cs_etm_set_drv_config_term_sysfs(struct perf_evsel_config_term *term) { int ret; char enable_sink[ENABLE_SINK_MAX]; @@ -650,6 +687,21 @@ static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) return 0; } +static int cs_etm_set_drv_config_term_ioctl(struct perf_evsel *evsel, + struct perf_evsel_config_term *term) +{ + u64 addr; + int ret; + + /* First check the input */ + ret = cs_etm_check_drv_config_term(term->val.drv_cfg, &addr); + if (ret) + return ret; + + /* All good, apply configuration */ + return perf_evsel__apply_drv_config(evsel, addr); +} + int cs_etm_set_drv_config(struct perf_evsel *evsel, struct perf_evsel_config_term **err_term) { @@ -660,7 +712,17 @@ 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); + /* First try the new interface, i.e ioctl() */ + err = cs_etm_set_drv_config_term_ioctl(evsel, term); + if (!err) + continue; + + /* + * Something went wrong, we are probably working with an older + * kernel. As such use the sysFS interface, which will only + * work for per-thread scenarios. + */ + err = cs_etm_set_drv_config_term_sysfs(term); if (err) { *err_term = term; break; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 6d187059a373..8aa2b79c3314 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1195,6 +1195,12 @@ static int perf_evsel__append_filter(struct perf_evsel *evsel, return -1; } +int perf_evsel__apply_drv_config(struct perf_evsel *evsel, u64 addr) +{ + return perf_evsel__run_ioctl(evsel, + PERF_EVENT_IOC_SET_DRV_CONFIG, &addr); +} + 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 3147ca76c6fc..6be7560bc986 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -276,6 +276,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, u64 addr); int perf_evsel__enable(struct perf_evsel *evsel); int perf_evsel__disable(struct perf_evsel *evsel);