From patchwork Tue Feb 5 23:24:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 157540 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5755183jaa; Tue, 5 Feb 2019 15:25:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IZmdqYfK6fg0Bgr0PtxC/mjE+8A4QE9zv/0KSIY4OMu4QWXvMBoQed5BshRcz8KNnKkzmYu X-Received: by 2002:a17:902:12f:: with SMTP id 44mr7778665plb.74.1549409114259; Tue, 05 Feb 2019 15:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549409114; cv=none; d=google.com; s=arc-20160816; b=kYrF5OfknKJJoVmK6m+h8AQXAfXELvp+VWY1/eufbKwwy+s16rkJd7LzzUlKzQHQkI aDz6uyD+3eOPk2nOtWY04kpodnqqeaD8SczoOLJ2TcKVH1v9qChh1M6+vxYPRgNAzb7N NYlu/jMdM0Ji2T6uHK0Efk4JCVGzBvXnmHuCfjBK/W9xtASGNdttiaz+P9eyDuTDKJrB 4pEY4m0JDvFwq3+gnRWh7+Fh/Nj2WHRAgjileiD9N0sGyHefIF/t5CGD7YaLQ7aEoubI T9fH20LzIowzwtsD+5xIoGUyAG3vJaVDj7CR33SYE86GQFV8U9RUApEtHEZhZQy66Vwh Ac3w== 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=N6pe95av2ZaxCRt4t70S8VXcNlePxrKU9faHcT9k6+Q=; b=gQA9RzaLyRORs4IqWFDyxeXiZGdLPeQUqZFZamjJTYAVzYjy+OKHTAEY3dOfhl799Z VL/fxHV6vLlVaZy34/oA8uwcPA5mPuu42oFABD1EMTTIl2vbEb+jh9mtodIr0IVR0Dso UhA2eUWQpTiHJZX2lihdVGbn0vvgAE1tT9heWrrkw98RrBlD4qQ8/8Jk6BBPPPnek46u iia4t6K3X6dKSUaJV4w0JGCt/Qa94lmgmDuCGM66YlmVkhppAws7iin8HUSJ4EIFzidC cjN8L3jSLAhyJv8kRZOSy3oj99kzmBBMDoMUyuNYO4jbdE+MUamu6o9HU5bCPDiz8L7X vb7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nKSAFr42; 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 k5si4317040plt.111.2019.02.05.15.25.13; Tue, 05 Feb 2019 15:25: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=nKSAFr42; 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 S1729084AbfBEXZL (ORCPT + 31 others); Tue, 5 Feb 2019 18:25:11 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39975 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728835AbfBEXZH (ORCPT ); Tue, 5 Feb 2019 18:25:07 -0500 Received: by mail-pf1-f193.google.com with SMTP id i12so2221807pfo.7 for ; Tue, 05 Feb 2019 15:25: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=N6pe95av2ZaxCRt4t70S8VXcNlePxrKU9faHcT9k6+Q=; b=nKSAFr42nOBNte/OECKW7C/3ULUCj/hdXa4iDp84xR69pqTX0DkvGCui5oBwVKqDCq IZfdzIesQdAroG1WnMQUiVjtqbt76/Ipf0REoBuyDlMN2cKbjja4KB3ObAm3xcZVIB7w nh6MdNPclZNb9XvNH9ADuxJWmuhs9j4g0kQ/rF/EfIFdomcDKoSOmhamCbQFjSdX/qSY DZK8fx2xXkSlQfJRzpVDGiWbUMJHWGe751F0A9z4+sv39gSXu4iFBcWb7rCrWUmNDjPG QEUWRv644vXdp690L5BF8N9P3WAH1Sk5nIC7xV0vCwTvx53tYq7x/3N+1Mumz61J0fqv XxHg== 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=N6pe95av2ZaxCRt4t70S8VXcNlePxrKU9faHcT9k6+Q=; b=a0QIsW0fe3GIQ5tArMb7KThnkHNpaVxw8q+7H8Bhxn56o/B4K0IHsoZZS6VPA+29Vj QGKhddqihxrGIJVKSsq/VqdmfbMvkAExGKX5aP+MDQP62qcYk05V2DVjgOOUm8hgvU06 T1Zh/irHyG8Qh9WZtm2JpZZNfo1WWEGIAoVUS8QLqvV0/e5CNhXic3WbLEulqjSYWX+3 fKP6Mmh5vutnYouR366w4ckQmXlrAEe+He8nyETtzxnJTkZ/Yzw9PRBYUCg09Us2P4LI 9JpOdgM817D3V4Yh3RBBKhTobbGNxiEjTsQ4y+mfExGGYjaMurDhoohnYRTNQpv291sg VskA== X-Gm-Message-State: AHQUAuaTQVSxEF0RS9IfX9tJbN+5HCOqh775KidWCC6mu0T4v/OsLY0c 5/7oWeUGFuanwiN4ARtX9kWLSA== X-Received: by 2002:a63:1c09:: with SMTP id c9mr6598223pgc.200.1549409106867; Tue, 05 Feb 2019 15:25:06 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id g136sm5926917pfb.154.2019.02.05.15.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 15:25:06 -0800 (PST) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] coresight: Use event attributes for sink selection Date: Tue, 5 Feb 2019 16:24:58 -0700 Message-Id: <20190205232458.7074-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190205232458.7074-1-mathieu.poirier@linaro.org> References: <20190205232458.7074-1-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 information conveyed by perf_event::attr::config2 to select a sink to use for the session. That way a sink can easily be selected to be used by more than one source, something that isn't currently possible with the sysfs implementation. Signed-off-by: Mathieu Poirier Acked-by: Peter Zijlstra (Intel) Reviewed-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-etm-perf.c | 24 +++++------ drivers/hwtracing/coresight/coresight-priv.h | 1 + drivers/hwtracing/coresight/coresight.c | 42 +++++++++++++++++++ 3 files changed, 55 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index cdbdb28dc175..8c88bf0a1e5f 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -31,11 +31,14 @@ static DEFINE_PER_CPU(struct coresight_device *, csdev_src); PMU_FORMAT_ATTR(cycacc, "config:" __stringify(ETM_OPT_CYCACC)); PMU_FORMAT_ATTR(timestamp, "config:" __stringify(ETM_OPT_TS)); PMU_FORMAT_ATTR(retstack, "config:" __stringify(ETM_OPT_RETSTK)); +/* Sink ID - same for all ETMs */ +PMU_FORMAT_ATTR(sinkid, "config2:0-31"); static struct attribute *etm_config_formats_attr[] = { &format_attr_cycacc.attr, &format_attr_timestamp.attr, &format_attr_retstack.attr, + &format_attr_sinkid.attr, NULL, }; @@ -191,6 +194,7 @@ static void etm_free_aux(void *data) static void *etm_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) { + u32 id; int cpu = event->cpu; cpumask_t *mask; struct coresight_device *sink; @@ -201,18 +205,14 @@ 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 selected sink from user space. */ + if (event->attr.config2) { + id = (u32)event->attr.config2; + sink = coresight_get_sink_by_id(id); + } else { + sink = coresight_get_enabled_sink(true); + } + if (!sink || !sink_ops(sink)->alloc_buffer) goto err; diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 579f34943bf1..b936c6d7e13f 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -147,6 +147,7 @@ void coresight_disable_path(struct list_head *path); int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data); struct coresight_device *coresight_get_sink(struct list_head *path); struct coresight_device *coresight_get_enabled_sink(bool reset); +struct coresight_device *coresight_get_sink_by_id(u32 id); struct list_head *coresight_build_path(struct coresight_device *csdev, struct coresight_device *sink); void coresight_release_path(struct list_head *path); diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index d7fa90be6f42..29cef898afba 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -541,6 +542,47 @@ struct coresight_device *coresight_get_enabled_sink(bool deactivate) return dev ? to_coresight_device(dev) : NULL; } +static int coresight_sink_by_id(struct device *dev, void *data) +{ + struct coresight_device *csdev = to_coresight_device(dev); + unsigned long hash; + + if (csdev->type == CORESIGHT_DEV_TYPE_SINK || + csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) { + + if (!csdev->ea) + return 0; + /* + * See function etm_perf_add_symlink_sink() to know where + * this comes from. + */ + hash = (unsigned long)csdev->ea->var; + + if ((u32)hash == *(u32 *)data) + return 1; + } + + return 0; +} + +/** + * coresight_get_sink_by_id - returns the sink that matches the id + * @id: Id of the sink to match + * + * The name of a sink is unique, whether it is found on the AMBA bus or + * otherwise. As such the hash of that name can easily be used to identify + * a sink. + */ +struct coresight_device *coresight_get_sink_by_id(u32 id) +{ + struct device *dev = NULL; + + dev = bus_find_device(&coresight_bustype, NULL, &id, + coresight_sink_by_id); + + return dev ? to_coresight_device(dev) : NULL; +} + /* * coresight_grab_device - Power up this device and any of the helper * devices connected to it for trace operation. Since the helper devices