From patchwork Mon Dec 3 22:54:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152790 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7389395ljp; Mon, 3 Dec 2018 14:55:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xd6NRVw6+DJFVMYrt3AQ/QTQOmNuzaBbJP3eY0WpbKLFKk3YXP71oeyXLFF2MzriA7topw X-Received: by 2002:a62:2b8b:: with SMTP id r133mr6316714pfr.246.1543877736020; Mon, 03 Dec 2018 14:55:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877736; cv=none; d=google.com; s=arc-20160816; b=wk3BIgB/i0YrXwdKyw5VmmMs1psGnD3/IwndrjEwCy1KpxLirt68ufVvxjodGQP09F negVCN1FdI9LeinmVJy1Uh/10K6QJtRQ4lNyGGOvHzY8Qdw89DtUvLhtGsjoaGb2E42z rKwzPCSBMHngdrE1rBuybpE52sO9bfF3EH7pbirYQcGk7WQuj2q3dysAlA217QHo+qRZ 2rPGnbYQb0ZIilhvGb07QU9SHx8CCNsEhnCKlVhF3TTVg3GC4yfecg/vcgVDv86gaTmD vWxNYTE3f/qr2M9ZbaXs8hjJM1bYVg9vZTxmoL0NBeiyShGNSrpJNMDVlc0hFHKi7Fqi BWZQ== 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=piAuFC3dXwAXwW7UITkDY5Jqfvk4m/3hePP7Q5Uy8R7rdoWWfX+yriD+EGk/1h60Zb aIJiuy0E+Z28n23YFe81s5iQVkXTaeT2qrVkmyph6jDNDHrUpZ9VlVEipSW+ZXSkjLZ3 ZyvpnXAZTbWcW/eVtizKx+mQmFh7WnduaJbFGPuLdu3treluzNA4CHVvSMwm2pEhSSVB 9HaZsjL+GW4lG8zV+E4PJ4F1AF1it9qL+l6fXG0CfyrRrr6afgy6cpkP2F1Grd0TCXrP 3LNl6DxZoiABaSP+htI7Qhls0XxqPbT0ik1yTGTyu2g/hZwXg9TGjdMlYm16fmyY6mOS WhoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EjQUylK1; 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 h5si15880451pfg.233.2018.12.03.14.55.35; Mon, 03 Dec 2018 14:55:36 -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=EjQUylK1; 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 S1726087AbeLCWzF (ORCPT + 32 others); Mon, 3 Dec 2018 17:55:05 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36007 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbeLCWzB (ORCPT ); Mon, 3 Dec 2018 17:55:01 -0500 Received: by mail-pg1-f194.google.com with SMTP id n2so6404634pgm.3 for ; Mon, 03 Dec 2018 14:55:01 -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=EjQUylK1BINMhHoByAtjuUYcrcMPz4Z0p6OJ+UuyZ4XGwa+b2BF+8GhR4rNhzouffc mxtwzG+5pp32+g9gzo0/5BWnQBltZmNyjF/k4csDBe6E7LE39h4e5Bg9/qk5gXu5+tS5 WqkbqVCttjr8cVwi7C7sKHvcIng56MShKw1lQ= 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=tAW5W0PY6n+uc1DUPeLoz1ZCBFOfMsdatyrsPH3pRwmm66tRBJNVK0ZVWpeB2915/u vBwd+y5dwzr0jC4RCAvJRmVxbIc9IQxYZg7mIa0G6SYgHVhC0COFRjC9Sn/rDTz8wMfN xbIY6hbgrK/ngmFSusvNUnxjP8x7KCV9115XBz2ATIJQBmH0Y4hdU5n1RuAxX/zGyELs rDzyL0tyjOb5tN1Puwv82YUJAmJMy6ZEfojmTcrV7h5+Ox8mmKHpJlgpX4tW7crhQ9mQ ZSgYKsqPofvEvV7rB481NBZhzEFRijVmHExALXOaLboJyWbkJtFXfr7jXpiwGh+ibkYB VGGg== X-Gm-Message-State: AA+aEWYaojlisAO251NS656eS++iNpq7kHyHdFLSI6MJTSR89OEO6HUI jvQbtMvPptpGY+wsAfzshm+4UA== X-Received: by 2002:a63:e5c:: with SMTP id 28mr2608108pgo.369.1543877700608; Mon, 03 Dec 2018 14:55:00 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id v9sm20933057pfg.144.2018.12.03.14.54.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Dec 2018 14:55:00 -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: [PATCH v5 1/6] perf: Introduce ioctl to communicate driver configuration to kernel Date: Mon, 3 Dec 2018 15:54:51 -0700 Message-Id: <1543877696-17174-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543877696-17174-1-git-send-email-mathieu.poirier@linaro.org> References: <1543877696-17174-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 3 22:54:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152785 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7389012ljp; Mon, 3 Dec 2018 14:55:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/VH8L5AsBCm8qZPYjMY3tBK1yL5BsFc08h+sXHTD2b/V7eO0jmjkWG44OBiWlo2YaHlXqU0 X-Received: by 2002:a63:5722:: with SMTP id l34mr14744277pgb.118.1543877708747; Mon, 03 Dec 2018 14:55:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877708; cv=none; d=google.com; s=arc-20160816; b=RJhIdg9Kqh9wqmCJpGuedRS1K8rhmbG7VCuk526za7xHUzMkXsziPjxY+x8NQQkxuG ZXRAb/xaj05Vla8oq3rLa51wDKGAHOfPHJXx45HuMITppL/g556GJRLTZvbDOQaD6wth b4tlr0xKfCwVIrTHcqmy7AhOHw9Nc/JhurloJXqndvZQ5v3bWBvXioHrfB9O22euoO1B drSlc9pyhss+Jj6szVDWEfVEGr97lU/i3t54GOXgdHJJMlYeaBzcKpY96+aUcU4zYP4L MNbdSVujRroKlP5ITsyhLCjQPF7aGcZNvood/mN16YODI+m0vBE0tZIE+zmp3jeb4tEK tnsw== 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=nEyAqL75rryrDbbW4LAuIOtxiD2rEl2XFyNOuTnLjBYeI6RET6AiYkVIj8zhS5XdD2 wgopDCvY2TlynGQVxltLKflXb0qgh8x3hqM3vpirs3mf1odBsm9VqIwFSzSgi1GCS07E Kt/ZdOf8JaGs4Ca7PELKyZyPrErQkapk6uUB7Gwk6wQyoei0AOB9fLQqz5LIhc7RLO9H I7rFQtf7YEWCwT82uvq3O8OnXP9M7I4lVvvrY5CL3zVJwKjX57mmmq+vldeQLiWcOeJx 6GYcx4AUIMss5AXzBXFKe+7/lwQhte+S3gxo59Q1fNmYrMbQxuUyOtwd07Q06FYMpKY9 eRzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RrOlJSG+; 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 e7si13222246pgi.263.2018.12.03.14.55.08; Mon, 03 Dec 2018 14:55:08 -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=RrOlJSG+; 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 S1726109AbeLCWzH (ORCPT + 32 others); Mon, 3 Dec 2018 17:55:07 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41581 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbeLCWzD (ORCPT ); Mon, 3 Dec 2018 17:55:03 -0500 Received: by mail-pf1-f194.google.com with SMTP id b7so7128494pfi.8 for ; Mon, 03 Dec 2018 14:55:02 -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=RrOlJSG+Y3gW+Hafk4V78OWWfljaTZ5GM8h7jKFhNzSrBGauShndYBsxuAvE5uJLyO 4DyEUr9wBXtcSPvf43JR49GhFDGwG0cvN3+CK3ONl/CwdPAtZJjuIT6zg2bZoVSPDpuv 870pz5JUGRNp4Yo84G2tgEbopj8SYXZGe+XCI= 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=k3GlnJGt5b44/U9qFYM2Yny4KCpyE84Bf6JVZju23FgDZPOlVU9Fmz+5bRS2Ufs0Sc XzDaREY2lGlrj8m4gNK2/24HzHwao2eHGNt2f1WZqTi2keVc927S0CU8/V/IQV/WpNgS u2A6rezNAeyVFsLTKFcvCAnd/lTW5iJcyJd/JInVoMo2LCMMfThXub3R2Lw76lh9o/FN o02BLAoXFCnAk7E1EDIGvMOwrCiT0IXDYomUBeTCoRIILf4lM8ZY95WknfuE2MGcWNIr a8dAmvikKmN20R9oeo/XQ3MGHtp5SR7JaVAiIoIJJDUznhuCNa91uQwPdpqU9Cs/fUub 2mnA== X-Gm-Message-State: AA+aEWaOmF990AzvZqiKEUBv/y3dTcdqxJvDHqdFSHeoWXMJ35UNDinP WB8OxfyTOS9seA3nhvD1lJECQg== X-Received: by 2002:a63:c10f:: with SMTP id w15mr14594722pgf.199.1543877702346; Mon, 03 Dec 2018 14:55:02 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id v9sm20933057pfg.144.2018.12.03.14.55.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Dec 2018 14:55:01 -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: [PATCH v5 2/6] perf/core: Use ioctl to communicate driver configuration to kernel Date: Mon, 3 Dec 2018 15:54:52 -0700 Message-Id: <1543877696-17174-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543877696-17174-1-git-send-email-mathieu.poirier@linaro.org> References: <1543877696-17174-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 3 22:54:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152786 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7389076ljp; Mon, 3 Dec 2018 14:55:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/X+cO2KkOKomIaaze2qE+68gXvU9SNUb3tfDwxz7fp9vlPPW0LkfnHNvg8qkrlXT/zAOZzN X-Received: by 2002:a62:8c11:: with SMTP id m17mr17691342pfd.224.1543877712521; Mon, 03 Dec 2018 14:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877712; cv=none; d=google.com; s=arc-20160816; b=A6n5MyvVXSYdKvXg0Ml19LwU0+sqLPa/vL5MU8cArdtpNSD3KbgDmerxsK0Da8lq0X 2S592YLxng62KHgqReD6IyNahSqR6sd7VsBvz2o1E+LGEEEyJhD9Dh1W6lN5qgafTUaa 2MhTW+SvLbAHlomi6LJY5HRbHnJFFinoqpxJErfhtUyPn7pExjNIQTiRapYuEdlohLqI VASi8xQ94sMdS/mo403yil6ILqaaoV63+D+k8tvEZDuX8AGZG5spLPbDy4DHmyZ0/mc4 WR3JCCh5/ET7xz1Yg4f8tfPedsCJF/yNWJ1VpptsYYEbOgb7w9N/eHw7OaYFjILd/HzF pJ/A== 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=g3ahJj2mEKU8g5ZoTKWBm8xwL6CUlf5FGT0+hOh6oRZb+xQd9y8XyV/ipDwkoh7Gaz 9XGc9ExA4PuGyhTuH6PxPxkWGnzxD3Q5Ahx2l4Z8ELGfwdTbflKFoJ6onl/adSjYiqq9 yDuU1XAQ1j47LiR3Pu3cwnNzkN0fRPNjNCAI+QwM65JVcHO5fdz51YazYV+PZQHnLjnX M6PEBtwEmer3fBXb1CNe1xz3nrYOYVF1OlLV9UjEJXwsIA2v6e4I/9DZsSmtsY87UvLy F1KQr3vP0JJOmbJhRE09aWYfq5ZQIpO/OYjGkVVwKewF8juI30nEQqLC0OFoP5Re/BhU O7/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BJ+WSKMK; 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 l63-v6si15175131plb.385.2018.12.03.14.55.12; Mon, 03 Dec 2018 14:55:12 -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=BJ+WSKMK; 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 S1726131AbeLCWzK (ORCPT + 32 others); Mon, 3 Dec 2018 17:55:10 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43194 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeLCWzE (ORCPT ); Mon, 3 Dec 2018 17:55:04 -0500 Received: by mail-pl1-f196.google.com with SMTP id gn14so7211520plb.10 for ; Mon, 03 Dec 2018 14:55:04 -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=BJ+WSKMKAaHZf2+4NraETCCroz5ZYFkeg7hzQcVhbUvs5kFkaYaHaPovFfb2Dl1o2E 3tM4XYu2uvdnzDFHNw20UtCragB4YutmTQLcBv7NTHRL2V7tWeOZ5hqc0cDsoxuaEwDF IFLPf7+NltDmTQRQXUAumL8Z+dsQLpeLzG6Rg= 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=gdSSpmoUIHwxLej9Jr6FxJAjm19X+7DARCavg2BXhUdhNPThdueji9G+gRvGkqnOl9 Pn38mOQ9J+oJUM2dGwdCVBi3pi68+auQvYUseGhacELQKNFrnJyCp7SFjV+XTjMcDJaF qKRqnSa61L2dpS00RR1b97poAXekISJkcpntoUHkh+xUE2Ov9Q39TAbeGvo21FGRqsG7 GpAOCL0wLqavkQ/x0NEbHf+PrnV4mC0hjwLD3Bi3JJ0oyKnGciSRJ1BMwjVe/SyeJlwB 1VIfZfACoB8VthqQBrKkjrIrrAyAP2INC0BlEL7IZGt8Glyy/nSVldr5KP+X+J7coXP/ t6jQ== X-Gm-Message-State: AA+aEWb6dBsxnzhfxyLHMBOENjhmGaty6CavHoTm+FR3aVm2dUSKnHWn JLRagb5ELv8VJhiHa0b8c0gKng== X-Received: by 2002:a17:902:6e16:: with SMTP id u22mr17497150plk.175.1543877703950; Mon, 03 Dec 2018 14:55:03 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id v9sm20933057pfg.144.2018.12.03.14.55.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Dec 2018 14:55:03 -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: [PATCH v5 3/6] perf/aux: Make perf_event accessible to setup_aux() Date: Mon, 3 Dec 2018 15:54:53 -0700 Message-Id: <1543877696-17174-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543877696-17174-1-git-send-email-mathieu.poirier@linaro.org> References: <1543877696-17174-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 3 22:54:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152787 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7389113ljp; Mon, 3 Dec 2018 14:55:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/U9HEKtCYofO7UawzGSYW6RlCN1aTHJHRpQLrCeMrNREfaSah2YY58FrCFyQlJuH4Am4s3R X-Received: by 2002:a62:99dd:: with SMTP id t90mr12921840pfk.179.1543877714730; Mon, 03 Dec 2018 14:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877714; cv=none; d=google.com; s=arc-20160816; b=dRT2iOGmuFKRo6JnqwE9zcSX1L0AAWmrxZ8nI9xoM7kaT/Cx3E7PNjZrwCQHk/NPma dkROBEWayK3wUGWd5JWPokaXGAzn1eqKueOKWBb1YBqkKSkvA3qcMV6PUAbq8Eb9CI53 iy3bhAoMUOJsOP/JWIhWcO7d5j5hc3JUbZlan3jfP2pLsHhsewkql8f7dNQj50F61MDd gS49Tx4sFacMxVndr0a8QO2ebBkH2+wq/LLm7l3wS57AUBCSOM3hzbGgmyQvanXfju7C mXG24c6v2ods5fiAncoyFY3nSl8g/XgBASc1wq/Dio1vOJfBTcY72EKtm9KF7wND79Ta TXOA== 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=UYNPd55V1I1p9xxKbf9xv8LJHoaiujCDj84D6eiEj3L3vRX83qyxmFceImcijJps5x iWKFAdbDUp7HPeQUKarl9pzUAr1saSG+xzHnmaRXPasngkZDpBRE+otousmptLNDKL2k 7MUIyxAbVMeUL7Xu95iMx9sS1Vj4xfLB3b4WTBQcqgC22FMwMBTJQXjnypzKFj7VRA1z qfy9+wzmJMBmTAk1nv6djUnPZ1Vk6MiHr/WuIDksn5HG4xBnYCqBmOZb41y07iEJ05U2 aVVaUxu4m4tW+yFjp0GyxVb0GOxdAV7eDXwakp6RHIRmx5LgLc5lGnLKWsmb3Qdu0Z10 ToTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g0Y2zniI; 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 l63-v6si15175131plb.385.2018.12.03.14.55.14; Mon, 03 Dec 2018 14:55:14 -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=g0Y2zniI; 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 S1726154AbeLCWzN (ORCPT + 32 others); Mon, 3 Dec 2018 17:55:13 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33855 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726094AbeLCWzG (ORCPT ); Mon, 3 Dec 2018 17:55:06 -0500 Received: by mail-pg1-f196.google.com with SMTP id 17so6409937pgg.1 for ; Mon, 03 Dec 2018 14:55:06 -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=g0Y2zniIHZPqzPi34F5QEJl2yeW/0zodTAfxbNORnXJt0S0KVyxJvSv4H1g1CLWEtm aROXaan93OC+wAYKmna1xkqior+VTPWlgj/X4hyf3FQiKsvn8NsHb/aTjW9pbXMU9nrX qPPwBX1Dx2qyas9w4R2jmHOAfQQA5z5UJnTQw= 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=il5RM6R+rlpAxbbO5qG3MXo05V5TseFF/RAE6zppffmdYXw7CqL6bAIMflwuKdbMlY kaYP6t7Qs7a0OG0bmIZRCqj5PGX6H+X72lidC5cRB7kMaVb3Z+H59LnQ6w1oCOAkl6LZ ODBNJhJG3iTsm2mU9VXfUqzLCXGqirnj5MQ+9Z2LFEi68F1ONrl62Fksz1hGBtTbwwLW QwXiS5ZmJH1FpqD0GsUj6QkdTUmZZKd5CLwuyiSVbRkshjbWdvPwfjRGZuhdRA2wBYPz ZYD2HD0LQqt1YygxH390UMDeqNY/9X2DCHjDfvoQBuGR/x51VYVi4nJO3T+M1C04Qdkn /GJQ== X-Gm-Message-State: AA+aEWYRlNusXaENXOxJZ42G2e/bIvHay9GPI3iq3tvNU5BWMFFMvSEm wmmd3Pf1YyWldyf3zBnvD88sSg== X-Received: by 2002:a63:e156:: with SMTP id h22mr13684257pgk.255.1543877705853; Mon, 03 Dec 2018 14:55:05 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id v9sm20933057pfg.144.2018.12.03.14.55.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Dec 2018 14:55:05 -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: [PATCH v5 4/6] coresight: Use PMU driver configuration for sink selection Date: Mon, 3 Dec 2018 15:54:54 -0700 Message-Id: <1543877696-17174-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543877696-17174-1-git-send-email-mathieu.poirier@linaro.org> References: <1543877696-17174-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 3 22:54:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152789 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7389283ljp; Mon, 3 Dec 2018 14:55:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/V99PBqMyvAKxIjp9xm9Qqsw7sEv3q1LeejyoGlIC9IQeS/M0lhcJVYS2+KBDIyeq+mxirf X-Received: by 2002:a17:902:ab92:: with SMTP id f18mr17004215plr.221.1543877728122; Mon, 03 Dec 2018 14:55:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877728; cv=none; d=google.com; s=arc-20160816; b=gnQf02utXFeft0lIxWXhyV6zh5sUc2jdyh0l5H17eNvd2V9Hhb0mUWm5VJ4O9i994L UXkvad/PwCCu/I0jrHA4CeifPfOzV00SCNsdQHRSWAcA4DVEloYJJV0FHoHOqn2+4zrv gnsYHSf5yhZYj9iDiXP8VswyQPLANpl/Ms7K5bGqN5v/BahmMT65IhsNs5Q5xYboy1R8 aWXtCsrjKLhqIFNuomV3/h9uUVK8jX4MCDQjaATzljbwJ9rnbf6AyGqsoKDL5Mf7SK0u zNfKnT2ZbtUIotf/Sw93hmIauzb+CQpnAWdwzY5CmZgNl1mJBxVUphk7osi5SkOL+0IN +LOA== 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=FUfS1RaNWRXjmkdl2KAF9Nzafx1FSt3pPdNp4K92aQRCnRNagqHR5tp4MuHI+JJnYp da8m/52ODfHfDfbDN7lIIGzcHJmoettGyCYOvvVKt/U/TCYbKbWQLZmSYTkBIrOpl+Ww LOpeHKJKxrp7lY0odxX6L1Ln2rHQMDD+eBpFw9L8cGtC9PXDWQWirMAj1Dqgt0Kz3XIF Lr8nlb+30rBcV4dbnEw4PlV+oNQRGoCwctgnBR46EHvyoeJgMKSDf4SraneRmCOJ3BIq /a6UKrn65DzoG6J7c7cesgFGGolX3oPOyZVtqaYzhYy3lszICvIMd7iAbnhHexDFBpYX KTkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AyRvDK8q; 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 r18si14058877pgo.9.2018.12.03.14.55.27; Mon, 03 Dec 2018 14:55:28 -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=AyRvDK8q; 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 S1726186AbeLCWz1 (ORCPT + 32 others); Mon, 3 Dec 2018 17:55:27 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40385 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726110AbeLCWzI (ORCPT ); Mon, 3 Dec 2018 17:55:08 -0500 Received: by mail-pg1-f195.google.com with SMTP id z10so6388763pgp.7 for ; Mon, 03 Dec 2018 14:55:07 -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=AyRvDK8qLksuCM5m5xpMuXurPSGg1u+IafeohsJhoxOT3eIogfCW4RPPjunRaMAGwA ad0IaHDWj2AA2p2wwYE60jkwPcCr9e70/BHSZiJ8R0M8uR68uXXN15McVkgGA9q+3a1N adTO7L8gepdaup8oxHXWsnOfnN8NrfqmKIdbE= 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=kkYt1TYVI3ZsejcNXiq3GpiYKTN3bf46nYLTnQ7WGd81UpcA/RaatHwjF3Neo8izjK NGSQncH5O9dIAPhksTotr6hIiLBS9qgGOsY0PUPZ8zxAra6zpPLDyBhsNFKra9yD++mA 3R6Q60Q/rnMDRei1rUy92W6Mj3LhV9bvdL+gKBD3haiYqsfx/wkZtLLu5x2uhUv5ex6w nmzvmrSscgYc5l1WBLSg9KJZFfbt0oucbQZG9EBEr+jUklsuYPweHm+r+hIIEOFa7BOd A83DSNrB+dXpOXOaleYzwnY7Q/Pibo80hC8t0Y3TmfkMeVX76M2zt56eoJFRESnLdhZ4 heMA== X-Gm-Message-State: AA+aEWYL9wDhYtsclZQenPDXdOsQ50cRl8oq1pxrmQtDn2pH2w0s1KlV NLI+qUVmze19eigRKQGdC0UhGg== X-Received: by 2002:a63:bc02:: with SMTP id q2mr14944296pge.116.1543877707458; Mon, 03 Dec 2018 14:55:07 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id v9sm20933057pfg.144.2018.12.03.14.55.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Dec 2018 14:55:06 -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: [PATCH v5 5/6] perf tools: Make perf_evsel accessible to PMU driver configuration code Date: Mon, 3 Dec 2018 15:54:55 -0700 Message-Id: <1543877696-17174-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543877696-17174-1-git-send-email-mathieu.poirier@linaro.org> References: <1543877696-17174-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 3 22:54:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152788 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7389184ljp; Mon, 3 Dec 2018 14:55:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/VpghC0Dn/upH41IJYUqghIXWouzUbDl4E0Uixr+SKRr+sv4IfhscVZ784c0aqPHoTawr1J X-Received: by 2002:a17:902:b01:: with SMTP id 1mr18019421plq.331.1543877721508; Mon, 03 Dec 2018 14:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877721; cv=none; d=google.com; s=arc-20160816; b=lptU8/+1Da8RKTCF1wFeLPNMvUjjuhAm3JCUtArzd11odrtizQrOOjDDl9nGI0DegV MwVA2h9wqyIpbwCbTVj/Cgw7MYkKi84X0l8OCRa+hufWw9R5fFzljlNDbnuwsx1hmD3e dOAKWFe4gF5ZYF4WzIMS3705FOCipjVHUxngYSEKkNB04ZAsX5yiRc6zUXLoSBsx4dWV Vc3U4yZeC2tKysQRK0P+5cCp2txYbe+aEJ42qWq2zXnhq7wGwUVdmb5hnC8840Bqrisp 65swsEEr2e0lY1I/b3KHfLe694dkE4fC0+oReBBbktvRjII+0Xls6JUePi3NQ7lN2ekS z+VQ== 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=Lu3z/xdk/IEqqSyvOawLQly5WF5T0BlsxSZ8WX81+S1hEAINDBP8yclkCc70TYAlwH TlFAMisuRsdxFTb9B1mP8sCaxiCmnpolU2ovqbYqxCV6+mv58vMXRM9xusBa7CIpOSzy HKknxua0tsq6Bi6QH3TUxoUJvtBGrffxljof1NLcTTJLjkCAh2mNYQa9ftmh+FBovl0O yoeu8U8HHDNVCyaWp+PrNQ514n90nDwKLGXl6esyRVd8E5BBVMacc9WYHcFiU/Y3NqXl NLPtRemtO3BrSr1c2tNTnuatKXtH0fFb6SVdcUsO6Mg/6yPKz/9z2rBcaQo0wRxMLMfk GU+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dKui9vrQ; 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 r18si14058877pgo.9.2018.12.03.14.55.21; Mon, 03 Dec 2018 14:55:21 -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=dKui9vrQ; 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 S1726169AbeLCWzT (ORCPT + 32 others); Mon, 3 Dec 2018 17:55:19 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41588 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbeLCWzK (ORCPT ); Mon, 3 Dec 2018 17:55:10 -0500 Received: by mail-pf1-f194.google.com with SMTP id b7so7128616pfi.8 for ; Mon, 03 Dec 2018 14:55:09 -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=dKui9vrQfBjN7EW8N937VokmclZqajH1JGzyoa16yHvUwKfx6Al5KjESQQs9Ro9+2P 0u5Q5IECHU3Oe8W2VZ3NlpD5cVMTOuoRtXXB7xacHUkJ7Xd0eM1m5cTJtRoS5bQexVb3 uDZslqp9Y9n/UVkr+tYme+8Uq+hgQNAolvrcU= 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=VQFl8ew+J45Yr30gOwJolVpktdyi7+INqu0Tq6z5uEvSj5fWLz4raZr8QuGt9jotV1 NKkRKyPNmqsBBRcuYC8vqN3MIZsuD1t3fIHfgC9FwkxkxPtayYaNiHKkTragBsFRKCx4 D+iN6toBgmXqw9E3d+BppE0Yk3RoHpCX+oACP0QEYtj8zLbQ0A07CLKkt/ueJAhY4BX/ TyHaFeUbi8Guvp2CnrVAzg9xxRqAQO25G64OxIqy1YafS/Dv/KLIKhh6Ea/1hCmvWaX4 aV3Ncv/8z2o1/SzY5+dDvNS228dPj2CHNYa8xXCjlJ5lzo2rc7Cns46WZ1nbCNvKdhGc tpNQ== X-Gm-Message-State: AA+aEWZ4AytAPHQy7hVXjZ6hhiDEYAtGZz9WiasbiCOfCJGf0EPud77y gwE/KSJTMqUtkK4VuWLLsO9LSrQC5+c= X-Received: by 2002:a63:e754:: with SMTP id j20mr14307610pgk.228.1543877709046; Mon, 03 Dec 2018 14:55:09 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id v9sm20933057pfg.144.2018.12.03.14.55.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Dec 2018 14:55:08 -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: [PATCH v5 6/6] perf tools: Use ioctl function to send sink information to kernel Date: Mon, 3 Dec 2018 15:54:56 -0700 Message-Id: <1543877696-17174-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543877696-17174-1-git-send-email-mathieu.poirier@linaro.org> References: <1543877696-17174-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);