From patchwork Wed Nov 28 22:01:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152350 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1632673ljp; Wed, 28 Nov 2018 14:01:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/VmQmeuIITycrVZxGT0uTzpQeSMOsAlFZGhdxeGJjsYL5hxCakfWCa3DCSgZTF178vXKkJs X-Received: by 2002:a63:ef47:: with SMTP id c7mr34974092pgk.386.1543442486104; Wed, 28 Nov 2018 14:01:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543442486; cv=none; d=google.com; s=arc-20160816; b=tDgNVOkuoES+SjEug6XmGEONc5rswQz29vW4PS+mv9J13b+hGxzBjp0MN3aFozEoDn J7d4pZCTiffx2c9wHDd5OlYaeZveQhWv9T8gbUD2aZlpy1CQgxoS2wmJmWh+tG8lyf9C g2EvazHPKsCKNKoS2cNq19q5uN8S+o6lbrm8HkoGmrXMPvU6IiKyAl/ZmGZ7h9uqQ8Ci pyUKn/uOYojCCdPyQsRbZD/1xVi01pbMeh4xsVV0368geybfhyiPsPvzz/RflkTsKaO9 0StqSY1b/6/cLAOwxsaFymb5JMTdcZ48t4lxJWxkmhLesEq044/eXBbZeWYS1J/eeZ0+ P1lg== 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=eueZ6W2njB74JvX/8hNBYwCtCguZgj9QXyJ/Slfihak=; b=eD1BkZsc2rnd7KmQlqEsH+0kF8PJGodhnrrjm0K9T/BznE7XE25mRizl0JJ94DULc9 n2qhOyPt5YGSVA/TLYENSaF20HghpNxK4HFAx/XmHY8o5NEk0p3EysVGrPIuTzEpxGG+ SGBFn0l2OZC6gHO9wtxqADu6e4gcCnA4WOCaQPE6o+i8TNiULgWCdBME4uj745nQFZ9E eg3Gden9/fGbsq8BrA3y/APdTPfugMnBl6zP7KY3U/ylniH3ISqLXXguObAqfU+hFNm8 Hvu8zs9KxDT2204oCfgUwAkqe6NzPV+cfGz4jhc/bSnBlx2q51IrgNgYuZigDlI3orTn LsAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IqXuzvI8; 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 x23si8452803pln.100.2018.11.28.14.01.25; Wed, 28 Nov 2018 14:01:26 -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=IqXuzvI8; 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 S1726598AbeK2JE2 (ORCPT + 32 others); Thu, 29 Nov 2018 04:04:28 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34385 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbeK2JE1 (ORCPT ); Thu, 29 Nov 2018 04:04:27 -0500 Received: by mail-pg1-f193.google.com with SMTP id 17so10109608pgg.1 for ; Wed, 28 Nov 2018 14:01:22 -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=eueZ6W2njB74JvX/8hNBYwCtCguZgj9QXyJ/Slfihak=; b=IqXuzvI8sZmoSzDTRIroeYklOjkcok3XwjvmzBpMLij3wxHT3C8rlZx3taYzRctJvA RlVvxw5cmlLiYERph2+vXCyd1VH2ymbssjgiwRzuCOlQMsLo/A02Ey5ajzFE5Kw1eEZe JpmIed5MQ13g1k6EbXX1/U11Pb71l3goGBy4w= 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=eueZ6W2njB74JvX/8hNBYwCtCguZgj9QXyJ/Slfihak=; b=m862NNFJbtJenCLhOMF5N1c+bCmZBIi9dPlLalRDdcHSk2YkOAXHSOWiZnIYe62yUP jKbhM298uWAVQtkHRQtdQpXsbOqJZEu1lFexy7bw6lEsCxEnr/46wBt2vCvmYoYY+o6e LCtzRO/PBi/o1HEjKz2eZ9dG2HWkm4HVfNuyh126d281leWsRRhAjPFyIGyp38JD/IPg n5z9SVkHLMEHhZI0KCP4cL/mt5qX+U3DPUrYIQSuX02hfxAgUPnT0oFM2SbCbwNZlMoF g/E/tVgxzGi1+3GyGp+wGsnJNfByx0zEbJcbwh+AK0TrMWG/GFL1DFcygyH9GZvDh/+n TTuQ== X-Gm-Message-State: AA+aEWZm+GJ/VNcMHbxAFRJ6iklk0Bvl41JtqG9654xJhDPVjaVOHq3K pwqe4uvaL5vVJY41Z/7DLpmgsw== X-Received: by 2002:a63:8c2:: with SMTP id 185mr35273310pgi.26.1543442482168; Wed, 28 Nov 2018 14:01:22 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 12sm8698051pgd.35.2018.11.28.14.01.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 14:01:21 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/6] perf: Introduce ioctl to communicate driver configuration to kernel Date: Wed, 28 Nov 2018 15:01:13 -0700 Message-Id: <1543442478-31465-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543442478-31465-1-git-send-email-mathieu.poirier@linaro.org> References: <1543442478-31465-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..bb558caeb33b 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, char *) enum perf_event_ioc_flags { PERF_IOC_FLAG_GROUP = 1U << 0, diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h index 9de8780ac8d9..bb558caeb33b 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, char *) enum perf_event_ioc_flags { PERF_IOC_FLAG_GROUP = 1U << 0, From patchwork Wed Nov 28 22:01:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152351 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1632703ljp; Wed, 28 Nov 2018 14:01:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/UerzLoHBlM15x7WSsKc2Q7HpdxP281HpTIBsJZaTiW/es1XwQHt3YOcHM24DLADie7aiMn X-Received: by 2002:a62:8949:: with SMTP id v70mr4816113pfd.85.1543442487593; Wed, 28 Nov 2018 14:01:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543442487; cv=none; d=google.com; s=arc-20160816; b=frRtJDrLxhQHJcHWU1e6YXCKQDcBPZhJZqeZrAZPk9j5/5uR95kVwDPHaebL5DGaRL xmivZ2Iu71AMZrGoeURxpGdoR3sQO8NEr1CX+8tqKxT428M+shkGugL6k2too+MQ+kcc wn44GjbzWGnRi0T8lkuIiOm1uRzOECjaHp+5RwKyleOdLbjd9EfTJxhFJ7q4syjg7ije O0yYHOGQkh2LySxbknqGIWCPWFkE8jBWnju2aEEK/4utNZ4kZ1qIoZm0JqH2WOF1t7ks 0VZ1mfDfSDmrevyG6KaFuj4+hucagAEVGVH++2u/D0H37HYu/5aL/FOHyPgSI9voR+ui jlBg== 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=9ArLK6lkyYJGZT2BBz1S2MAD3wdLFqaTbbWFM/1RhoE=; b=xT1Ql3TjE8W20gz14N6Xivqy/z9BRkVzUHUIOAtkNAz6wwPt5E9EGNE9pp1KYRWHxR bvBgUEyKQ/7IUG1RUG0z8NQ0rlzEbLalmq7m1lxhnI1yAkKevgOiTw1SWHcxPOCqwIU3 q0o4y7Y3ClsNxkEZbOfM6LrUgbAtQrRbTBG2TKDBLQAF5Fidw8osO7sVwQvOak8uk4yJ d30EAyyTMslN2SbI/lA3sg+pT6hRhHi2vKtPnMacjYJoDCpc5pHW8xEjeN953gIAsuWN KvccCDwuQHbq4TNDhSvrqGhDAqA8AR6GLfZ7Fp4qwKOD7zyDLRg8dre3uYzYTm1Fne4L XrMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JvaGhXCa; 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 o127si10155655pfo.251.2018.11.28.14.01.27; Wed, 28 Nov 2018 14:01:27 -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=JvaGhXCa; 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 S1726623AbeK2JE3 (ORCPT + 32 others); Thu, 29 Nov 2018 04:04:29 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37079 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbeK2JE2 (ORCPT ); Thu, 29 Nov 2018 04:04:28 -0500 Received: by mail-pg1-f196.google.com with SMTP id 80so10109966pge.4 for ; Wed, 28 Nov 2018 14:01:24 -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=9ArLK6lkyYJGZT2BBz1S2MAD3wdLFqaTbbWFM/1RhoE=; b=JvaGhXCakBbgKtMuu7Am5WMIKyL1OD2YnkifjxC6dd5PMwaDyoS43382toposAuZ7F 7bZkjfvqkB2o70f5BnoJI6GvdJ634Yi8Fc4/P8AXBwzcJbS3j8tj7iZ+iHWsjnoC4he3 roYh+HXd59ZaRQ7y9WJ64ySRMP0dCOyTh3iZs= 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=9ArLK6lkyYJGZT2BBz1S2MAD3wdLFqaTbbWFM/1RhoE=; b=I9XfabEI6He3j3r+ZyFGzykPMTiryXwMTPoiAuqs0BcbnWmjpHYtRdtTesNckWeS0J 22rKkH/kgpcPN/nqMnhE00d39xSvpVh9skeIhawGpP6pAmFhmibjSUT4YpQKQpmiWEBC 8/r5L3UCvSEyUiyy09t37gS+hLwe6fY4GIBKgo+iLGqVDI3GqlfGMDIe5Uo9eTpCaNhM ZpBEk4vGrsotvSUTTWTNMsg8YuA4mKhu3NJ7j7sD+AvZ3Oq2i4bKg6vNhW7x64Bh/aLs Yx9z5H4PelSDKvVRc4Y/RGDh5DkRwGv+lrdQDlB4eVqXOujTNKtTld1D6MIOnqtkCAyG DLCw== X-Gm-Message-State: AA+aEWZP73KN6eSzxWT7rPDZFlzfk5aJBraIUt0T3LZ1MI0+KabFQpAq Gug0ny/t7vIXJjS6yePdMW9XqA== X-Received: by 2002:a65:41c2:: with SMTP id b2mr34325372pgq.67.1543442483779; Wed, 28 Nov 2018 14:01:23 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 12sm8698051pgd.35.2018.11.28.14.01.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 14:01:23 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/6] perf/core: Use ioctl to communicate driver configuration to kernel Date: Wed, 28 Nov 2018 15:01:14 -0700 Message-Id: <1543442478-31465-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543442478-31465-1-git-send-email-mathieu.poirier@linaro.org> References: <1543442478-31465-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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) -- 2.7.4 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 53c500f0ca79..629fa1e1d6cf 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, + char *config_str); }; 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..a76c0ce39c4e 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,68 @@ 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, char *config_str) +{ + int ret = -EINVAL; + void *drv_data; + + /* Make sure ctx.mutex is held */ + lockdep_assert_held(&event->ctx->mutex); + + /* Children take their configuration from their parent */ + if (WARN_ON_ONCE(event->parent)) + goto out; + + drv_data = event->pmu->drv_config_validate(event, config_str); + if (IS_ERR(drv_data)) { + ret = PTR_ERR(drv_data); + goto out; + } + + perf_drv_config_replace(event, drv_data); + + ret = 0; +out: + return ret; +} + +static int perf_event_set_drv_config(struct perf_event *event, void __user *arg) +{ + int ret = -EINVAL; + char *config_str; + + if (!has_drv_config(event)) + return ret; + + config_str = strndup_user(arg, PAGE_SIZE); + if (IS_ERR(config_str)) + return PTR_ERR(config_str); + + ret = perf_event_process_drv_config(event, config_str); + + kfree(config_str); + return ret; +} + /* * hrtimer based swevent callback */ @@ -10052,6 +10120,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, if (attr->freq && attr->sample_freq) hwc->sample_period = 1; hwc->last_period = hwc->sample_period; + raw_spin_lock_init(&hwc->drv_config.lock); local64_set(&hwc->period_left, hwc->sample_period); From patchwork Wed Nov 28 22:01:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152352 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1632740ljp; Wed, 28 Nov 2018 14:01:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/WtJg6Gc7WTxUO3cC0pqDktaHEw7x8epB+ODyjvAeeG/Uilkqi77syJNa2BDi9TB5syeYJf X-Received: by 2002:a62:6d84:: with SMTP id i126mr7264547pfc.109.1543442489595; Wed, 28 Nov 2018 14:01:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543442489; cv=none; d=google.com; s=arc-20160816; b=pgCg+2/wSu3IdQ082WxS2DGNoK9ITh7v9Z+4Ea8hoUDrWgXIla1TcAUOp9DRw5gDPx fPmg1aqMpX2C7nxrllFCmFQLLmADsbCHrlAKgzLG/x0CjjouMKalhHXsJLdPtT4q7STi 1HkB71J0pvBY8QF4Xw+ZNfcFKZaBjuqnzChS9sKoN7uOtQkph7gh98rfRgzLYKk4S3V5 SNju4+uvmk8QYYnsn5h8x3t5jwzCjafyzQ9YLqk/J9g2OsSpU8Uvqd8lfkXCC5JLQP8Q 0TnswMoVs1t9tB4BvtG1rVXj2jT8UGfTeiiGZ9JpJB0vPcPpFDnJm2IJlN/kFLhoNXaT dtag== 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=aO5e9mjvolCn0fX+5uiKyzMENpxHFbYAI7Gf3JIbCzs=; b=UVdkXuAbOmuPVtoTEaghsNC+FOJlg4szLwJGuWofgn0aMzSmqkUc50mYSl1GGoXiIO gTwkya27eJo4A+iyTUHY9Vcywt6ZJNdfjp8RyNUFijVaTPsDRfnbUH888WHqWCz89gFi bzR0wZjUdlfxU6660SsIL+DndWOdU4JfnU49mO6D5SpRd1UW11EpQ+LWmTSQyfzbXazq j8el6zD8JKRnaJhaaJY9sKO5WmizmzDXdMxdHO5g50fPx5dUQbVvKFPcTQrNcjXwoYeA wKkwuQXMF/OHc5TFMCkPoJeQU3Vm7Cl/3g2fXMAhxJ2GqDEoWmbfoC72WomU/b8fsoep Q2UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LIb69zDp; 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 t12si8624407plq.190.2018.11.28.14.01.29; Wed, 28 Nov 2018 14:01:29 -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=LIb69zDp; 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 S1726654AbeK2JEc (ORCPT + 32 others); Thu, 29 Nov 2018 04:04:32 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45842 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbeK2JEa (ORCPT ); Thu, 29 Nov 2018 04:04:30 -0500 Received: by mail-pg1-f196.google.com with SMTP id y4so10091815pgc.12 for ; Wed, 28 Nov 2018 14:01:25 -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=aO5e9mjvolCn0fX+5uiKyzMENpxHFbYAI7Gf3JIbCzs=; b=LIb69zDpggSwsrnZSXdw8fh5h+VMymg+tQ/k0aNgoR6l/uHrM4162nNKZvlbpmIw5g ZlElfNOqSjbdVimuRuq3q8KtWKFXv0rltF9cDv4lpqtSEHIco4MFKXtRmgYpcubkFWTe PUG4mWjcMpM15A/3BcFb2kl9Ex/SoU00fElbQ= 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=aO5e9mjvolCn0fX+5uiKyzMENpxHFbYAI7Gf3JIbCzs=; b=m+5BJIQ7t4jBxb44Zg4CRVHqhn+Z7q82qHC6uiIVcGk6t5v4Y1D1oal4xRdXPY2qWy 5x9eO5jscoIXpKZTAeH4FojsqncoQlGOySMKW6701E/N/zWEEsEGgbzcKaBCsRS5z/Ci NVSRJQKN3X3K5Ul4Zn4IVm0o85D6NgIBGFfkwdOaYFprzsM8I0/WbID1nBfZHz6Iinw4 Ttdimws+7ldnMA3O/+dNXWw4jjm8EThQVsmcfAJ0F5poAeru72DY5ExNfCV1dYLYW6bb naos2G1s26THV8RhffV+8bFiAEMfqqNY9kju5A9VplyuFxHIIuOQqeDgiJaQRkEYdtMn PrJA== X-Gm-Message-State: AGRZ1gJ/f40Aoj3EQ0tWKC+ZSqJtwUhDRq1N6lN3yewno2X7sOTnOHeU L9EqUL8SLORpAw5bNK8hibOUVg== X-Received: by 2002:a62:d2c1:: with SMTP id c184mr39554719pfg.248.1543442485402; Wed, 28 Nov 2018 14:01:25 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 12sm8698051pgd.35.2018.11.28.14.01.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 14:01:24 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/6] perf/aux: Make perf_event accessible to setup_aux() Date: Wed, 28 Nov 2018 15:01:15 -0700 Message-Id: <1543442478-31465-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543442478-31465-1-git-send-email-mathieu.poirier@linaro.org> References: <1543442478-31465-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 629fa1e1d6cf..c17cbba10b30 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 Wed Nov 28 22:01:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152353 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1632780ljp; Wed, 28 Nov 2018 14:01:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/VVq/GLT0LnaWMBXBANeMn0OV+MnfTxDIVz2n5vAK8GBD0OYE++UYFsD6HGJZ+OhJIkL1Mt X-Received: by 2002:a63:160d:: with SMTP id w13mr35541418pgl.43.1543442491117; Wed, 28 Nov 2018 14:01:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543442491; cv=none; d=google.com; s=arc-20160816; b=PxoPlUIBnNNlsnA5+4lP0t855rLGkg40RF/y6Jqt7bvd5+efKlm8MK2hLR5QLzRG4b x8E51nQFBxQac6hz47cTWW/HUTsrcFl3MvTuVJB6EEkGdqFfsdfdlxpPwXm3ipjrvvrN +EHT3y/JTREgKKgJxDNUGTxDuMJPrWQ8uPLHEj0YM/4yPeNJaSZIKfWq1YG+3TxLWdYU ozwU/GatMrAHDATYg4I0wKKRSD696l065M444/qshA8efArtXvBfx2K6LBE4rIpqwjOY NNTsVpx9/lH3wbTbXdoYqVpnqYh+pGdC8+/p6wHknFdxflg9QYJbX5LwACEpETUmOv/8 4sWg== 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=xnEBPlZvLoiwiqqm9S9JUInQL+RU7pyQ/G1YI/wchKg=; b=MIB7uWU3CDEuX5fkm+mgpGXWPzdVcyy0QwVvdWjMp+25o5niHos92O0FgupbjugtwM KySb4O0PJ7MgDhgYEEp80kBW6/e4uHW29F32IPCKOgCrxnoZHsrU0Y/VBpUwhA3H1+o3 K7+wVs9tOTlN3xnWkMYPcOeuQCMbXZDy0mpuG5AXpoHJre0NGMIWmAAUk2a8DXaoeK/c qH2jPJPZENh/oLjJ/e5LhhfFM37sjFtQqYrjmxI+K9Q5VQMwGfIdrB12cx0Vft6ggXpG 9UWZPJyXLPHi1TrpZsNlLfuaBvcOlIqY469RV3MaaR1LY9fstdvpdolfuIogV7HOo7yC Mx1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S8hfGFdH; 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 12-v6si9045089pfu.2.2018.11.28.14.01.30; Wed, 28 Nov 2018 14:01:31 -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=S8hfGFdH; 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 S1726683AbeK2JEc (ORCPT + 32 others); Thu, 29 Nov 2018 04:04:32 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34393 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726628AbeK2JEc (ORCPT ); Thu, 29 Nov 2018 04:04:32 -0500 Received: by mail-pg1-f194.google.com with SMTP id 17so10109716pgg.1 for ; Wed, 28 Nov 2018 14:01:27 -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=xnEBPlZvLoiwiqqm9S9JUInQL+RU7pyQ/G1YI/wchKg=; b=S8hfGFdHktHmbFUcmAAAToL1GHM1166VP0cPbnSTtGAShRAN8OGq7+DzzlKUPc1kwm q9tTlNGl+LwEQxzx0YOB8iSxeNATA+URaq8VoYLMLfwpyHTC4jdI4KnTuEVdJ+ZjLypr DaZFMb38dcGUgHztaRy4p8mUcekTLvtnA3v0k= 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=xnEBPlZvLoiwiqqm9S9JUInQL+RU7pyQ/G1YI/wchKg=; b=oXc2Zmna+s4TAuRjsyhwuNUL8vGxQOySWnBUhO/kYgxRBnCt/K9J6YmW/ScPsCSQ6J hcgqldaPcWHijPG3UlNxB1zbF88CtPl9AjshrxpDtIiVJyJ/AkgZ/1HzezWWIZGxHFlo VY6EYn8QJEhg0VF8PeVuGrrKdzERuDDAzJ++dQv187378wTlt1zSVFOZJUcucn0ELn+z c4bqBU5JdMUHVv1LOG3K+Z7db+qs+RZmVJyPvHeEuecObMvo2JoZ7trOWzfFgtBgVtms 0LZdN3w6DNCR7LuaBY2oknFyR+QTR18fhzGNJw5iED+A790yYvfKkCREoCV6cGeDQyI/ Hgjw== X-Gm-Message-State: AGRZ1gInzalu48WPNDcDa1miFrxEO0q+euNxGTdvK6ZsnHkwDZ+GrOoU pnVRmP2+9g2En+gMXKjd13ssMQ== X-Received: by 2002:a63:42c1:: with SMTP id p184mr34369774pga.202.1543442487192; Wed, 28 Nov 2018 14:01:27 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 12sm8698051pgd.35.2018.11.28.14.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 14:01:26 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 4/6] coresight: Use PMU driver configuration for sink selection Date: Wed, 28 Nov 2018 15:01:16 -0700 Message-Id: <1543442478-31465-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543442478-31465-1-git-send-email-mathieu.poirier@linaro.org> References: <1543442478-31465-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 | 58 +++++++++++++++++++----- 1 file changed, 46 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..0fbff912d515 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -177,6 +178,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 +211,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 +468,25 @@ static void etm_addr_filters_sync(struct perf_event *event) filters->nr_filters = i; } +static void *etm_drv_config_validate(struct perf_event *event, char *cstr) +{ + char drv_config[NAME_MAX]; + struct device *dev; + struct coresight_device *sink; + + strncpy(drv_config, cstr, NAME_MAX); + + /* Look for the device with that name on the CS bus. */ + dev = bus_find_device_by_name(&coresight_bustype, NULL, drv_config); + 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 +531,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 Wed Nov 28 22:01:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152354 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1632832ljp; Wed, 28 Nov 2018 14:01:34 -0800 (PST) X-Google-Smtp-Source: AFSGD/U0SvsuFJ9ynu5Wsflg24nkON4p3rs6RoFHZuKArO7tOn2cUIJors9d7+GqEQAXnCJeV0n9 X-Received: by 2002:a17:902:4c85:: with SMTP id b5mr37324210ple.226.1543442493994; Wed, 28 Nov 2018 14:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543442493; cv=none; d=google.com; s=arc-20160816; b=lYYuAbzxlcbC6mxelufvquRv0xKqx+TpbhduZeIkcjfGZ1QSmfBMuusCHqVzrqQcUn jlesKXbwBeTVdtAqIDe07ULRHMMnh6CzX7Hlc4pljJjzrGXwyJddzXScf+Ol67QJuwjj UuMEmKC+AsA6nieHaGS1m3ACre5iOsjyQdTGl/fp8fH/Ex6y2CM+rxcRYcNUuMqZaMA1 OfxDHutAowSRpXYmNKHZlvqKhUIq7dzgZknX6nu+WiiWsJedUvWfxP4D9Oz8GmVOe32/ Gh0lGlGXCPZZRWV9adPwqzfN2OCdaBjj4USJJ17HHhgmGZJB2m6Tq7+eRPLiUjFdu/N0 AeJw== 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=bqWWE8oDDsur3iw1IVu4lixcd5g9livs3xGkCvK8TEtMOWQgSvYqCahfA/gkMJ4F1Q 7qzsh8UifevclSi2hIIDRE5KY1L4P1sYgtq9oitewjx7p/1CgnAJTZOBzLafZsqmELXe oxFwhZ0oWyWEnnHwY7sZtn+WFWsKNfmajPfIteH1nHKT1xOs8T1j0cXoxZBrpE2jQn8k d/L8TmNvKG6mkJRccCVP4F8zc5CmT6Q7EE4Y8UF7SUeLNixQPZFeqGwOpATBF0dn3iEW mHf4Rs63FlGMbWbNEShwTAkWnaOLndRNRBRQ7ZgwBnF4JvMEHNuyDcedgBQ8ROErHQhZ wCwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IRMnBk/E"; 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 s19si8230002plp.151.2018.11.28.14.01.33; Wed, 28 Nov 2018 14:01:33 -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="IRMnBk/E"; 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 S1726724AbeK2JEf (ORCPT + 32 others); Thu, 29 Nov 2018 04:04:35 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40577 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbeK2JEe (ORCPT ); Thu, 29 Nov 2018 04:04:34 -0500 Received: by mail-pg1-f196.google.com with SMTP id z10so10100027pgp.7 for ; Wed, 28 Nov 2018 14:01:29 -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=IRMnBk/ELZHfdyqOzNiXDXXMFOgGNE01jpNMzoQRU9t1CwXX4MYuBvx1k25n4uQhJA X2BQ0yYsLtqDrktboR0ehpnwY1vRhaMx5/wAJqhlBjE41V31tso4ZKrXf4usxYPzKFew CHIiyE9STum4m75W01TsFRx3UeDFazllDTYkk= 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=mxTWqRwwNIO9fW9j+lqK4Z7UT/OHQkjSE32i9/n2I5ucHVJx6AyGaXL4Jg5EClT3dz crIXwbhwyqsZs9CVWxTjJe7X8peMRk+7+9kUTxhLam859T8a6qHd7ytDflcg+F4XO/3p T98vTTv0aMDrhOEZpoRvnan4W/IxmZFRXpjn+HDB9rOMLqDqSa1U8Ai7OHs0u6RDZh8r pJH7FNHwu+kSq3JbrZPK92pXKKYxYdaA+SIz0ZhrTHfaaZgIU5nOp7LrJrtt+tCqDb+8 FGImnVXKafDEFQpbeWDIfyApz7sLgDKWgEzTBn6mzTZFYilbVuCQyMI0SXiDTExC44uZ dFSA== X-Gm-Message-State: AA+aEWb17AwJzW8+JPLFXuP/8KkHgQ1HVZPBV5WGxP2Y5qw1KIKPv+We xszWx7Xo5eHUpZfrpLrqNQY4jg== X-Received: by 2002:a63:de46:: with SMTP id y6mr34645335pgi.198.1543442488773; Wed, 28 Nov 2018 14:01:28 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 12sm8698051pgd.35.2018.11.28.14.01.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 14:01:28 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 5/6] perf tools: Make perf_evsel accessible to PMU driver configuration code Date: Wed, 28 Nov 2018 15:01:17 -0700 Message-Id: <1543442478-31465-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543442478-31465-1-git-send-email-mathieu.poirier@linaro.org> References: <1543442478-31465-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 Wed Nov 28 22:01:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 152355 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1632846ljp; Wed, 28 Nov 2018 14:01:34 -0800 (PST) X-Google-Smtp-Source: AJdET5fdaN5NXI5+f8Nin/phpJOKJ/tJDDbDSscJO9PBx4r70+Ql0GUO9OkzS/zemJQRQzDp5udr X-Received: by 2002:a62:14d1:: with SMTP id 200mr39724915pfu.103.1543442494401; Wed, 28 Nov 2018 14:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543442494; cv=none; d=google.com; s=arc-20160816; b=MUz0KBB9nnrbIVShJZ+kSv6pBLkkRs1UR1PqHMfKINwTWePUnjPh48pYR8hjoawiFh sIihapg/mCjV90t9l9ioFFUZWj3wF5JiBueyD26Tw4cOlfUCdQ+sbmK8hP+57DXQGEum 2YBAaLPYkOp0Pme53QyXiUvsC24UQdwRNzlTiIPfjSH3vQy0NJUt6tws+ZiJoADHClcI MJZsKKmilhO6WRuPzya8ZXq9qKMfXkHi6GdGr9+KFVQbjcqj8EEqMaXfCMMnBdNX3y4S mTRJY7OoA1myPtYb1LygnIUCOCOo+L33f31hKcxu63Vbjhe3aIhbgGhx/7/FJJbYhAcF 0wqQ== 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=rRFTiKpTPNMFVfmzVrsI37RlXOAn7jocrARDPWf4AIU=; b=k59LIpA1N2oMlDocCPT75Wb9yeF/e94XYcjkqtcPCEwrAii27AMGtbAq3FNPXYDwVN R2QJ5Dr94TS0V8IYXNfBiKJ8OK0jJU8sfCmiodFLfP3pPeUNhO4Gm3MFVAlX+WO+hkmT ZV4ROdOSRtEf5mgAuubU9N8xikeTPyCuERxI4xn8qZuadmgzclkFqi8szfVaM+8u/CnA Omf9HofyAlDnuDTq6bm8F4JtWvtvNBPL2I2VdM/Q4mJTpAurbEdx/DpI6yxGZpkLTauu 58QHhh4XzzobNTDuL7IuYYMpmCxnvthdI8WmhhhS3ZuD8Y8TJXbDti4Swag0oOyawFuL egng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="iWfL/vzJ"; 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 s19si8230002plp.151.2018.11.28.14.01.34; Wed, 28 Nov 2018 14:01:34 -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="iWfL/vzJ"; 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 S1726751AbeK2JEg (ORCPT + 32 others); Thu, 29 Nov 2018 04:04:36 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37041 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726702AbeK2JEf (ORCPT ); Thu, 29 Nov 2018 04:04:35 -0500 Received: by mail-pl1-f193.google.com with SMTP id b5so18059936plr.4 for ; Wed, 28 Nov 2018 14:01:30 -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=rRFTiKpTPNMFVfmzVrsI37RlXOAn7jocrARDPWf4AIU=; b=iWfL/vzJqLH03KRjkz2aSQpdRp0VFGKWA4Txo78bHC7lxCTCElxAS3ptgxvjANWUI0 /4HbjaX0eZsQKtNpeDr3amrDJURrnCHtt6FgFeH1rGQo5h8uShBpLu01fBkxF/oHl+B/ 4gaGPOD4VTA35b6G/FqMFWCYXiycV35FIVACI= 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=rRFTiKpTPNMFVfmzVrsI37RlXOAn7jocrARDPWf4AIU=; b=a1E595x9zYKOxKFMZTECSS7xa85y/Mfh/vlb+IBXJE1Oec6bmcTObLDPQiL22casf2 yLU4giC/uR7hoVxdrULBUhFyl023BNi3QHC2JMaJCoyKcX4+HHWE77bgIeh6Kca5/V9X KwqnXKwR7b3PvaiLPZeohVIBPcMeQ3Hz/OXSkGc2Gfk+woE+DklTJX4P/QyZ1imCnq/F YVwVZvScfAOKQaBSgJINrI8i6ndLcS2w8QOYYzcdojatD6ialEtJfTI7DQ9eIWeFV+ui ch5NgvD8FYOBigABZJIMdYQ3QXTBFahOZtSaCYlhajbEFiv3lVwKQNPNCyiE60fsRby9 TXXA== X-Gm-Message-State: AA+aEWZrQH06VAWBUyvWfb91ymNBIfk8QryKK4rnmq3n5h6k/9uqwAd8 ST2srZSMpauPW2+KdkTbkk0hsw== X-Received: by 2002:a17:902:7c82:: with SMTP id y2mr38089963pll.33.1543442490423; Wed, 28 Nov 2018 14:01:30 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 12sm8698051pgd.35.2018.11.28.14.01.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 14:01:29 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com Cc: tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, gregkh@linuxfoundation.org, hpa@zytor.com, suzuki.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 6/6] perf tools: Use ioctl function to send sink configuration to kernel Date: Wed, 28 Nov 2018 15:01:18 -0700 Message-Id: <1543442478-31465-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543442478-31465-1-git-send-email-mathieu.poirier@linaro.org> References: <1543442478-31465-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 driver's sink configuration information and an ioctl command. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 49 +++++++++++++++++++++++++++++++++++++-- tools/perf/util/evsel.c | 7 ++++++ tools/perf/util/evsel.h | 1 + 3 files changed, 55 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..4f0563b99a07 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -619,6 +619,26 @@ static FILE *cs_device__open_file(const char *name) } +static int cs_etm_check_drv_config_term(const char *name) +{ + struct stat st; + char path[PATH_MAX]; + const char *sysfs; + + /* CS devices are all found under sysFS */ + sysfs = sysfs__mountpoint(); + if (!sysfs) + return -EINVAL; + + snprintf(path, PATH_MAX, + "%s" CS_BUS_DEVICE_PATH "%s", sysfs, name); + + if (stat(path, &st) < 0) + return -EINVAL; + + return 0; +} + static int __printf(2, 3) cs_device__print_file(const char *name, const char *fmt, ...) { va_list args; @@ -635,7 +655,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 +670,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) +{ + int ret; + const char *drv_cfg = term->val.drv_cfg; + + /* First check the input */ + ret = cs_etm_check_drv_config_term(drv_cfg); + if (ret) + return ret; + + /* All good, apply configuration */ + return perf_evsel__apply_drv_config(evsel, drv_cfg); +} + int cs_etm_set_drv_config(struct perf_evsel *evsel, struct perf_evsel_config_term **err_term) { @@ -660,7 +695,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..a0374dab843f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1195,6 +1195,13 @@ static int perf_evsel__append_filter(struct perf_evsel *evsel, return -1; } +int perf_evsel__apply_drv_config(struct perf_evsel *evsel, const char *config) +{ + return perf_evsel__run_ioctl(evsel, + PERF_EVENT_IOC_SET_DRV_CONFIG, + (void *)config); +} + int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter) { return perf_evsel__append_filter(evsel, "(%s) && (%s)", filter); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3147ca76c6fc..30083b0ae62c 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, const char *config); int perf_evsel__enable(struct perf_evsel *evsel); int perf_evsel__disable(struct perf_evsel *evsel);