From patchwork Tue Jan 22 18:11:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10775905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD08C13B4 for ; Tue, 22 Jan 2019 18:12:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BED92B8BD for ; Tue, 22 Jan 2019 18:12:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9026E2B99B; Tue, 22 Jan 2019 18:12:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D182E2B9AC for ; Tue, 22 Jan 2019 18:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=frrwcC2SHDNXD4LSayVTgRDnC36Ft8wcgob27Wbaibs=; b=na/j4753EN34XDxvlPQVk7JLor Xcn7IgNHS+1w0sTnXvBEpsu4aoGZaD09CL75nX8Tc64tnWH8Rth+p8Hro34ZyZPChdQGbooy5OSsp ynPugIq7wfwnYBfydxnFEoh/FF1opxIKcHhgffVt+b0whdd8CiUJ9Llg41l/nXE9Tzfn7bXEYGVxh Lx3/wqK/sVIh0xWDpXYnC53xJwu7xshqkX4aJ54vTkD03+lgOBvgC4JgFibEYKZrWr712ksC31x6/ NI6RDM1BTCuhJYsb0r/k/BOM1q26dQf2gHpYEQielniOzJSbQttenUKLV29FonxJLCdtPD0mWaqGJ 1pqvCTiA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gm0XN-00055g-Kb; Tue, 22 Jan 2019 18:12:37 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gm0We-0004I5-VE for linux-arm-kernel@lists.infradead.org; Tue, 22 Jan 2019 18:12:00 +0000 Received: by mail-pl1-x642.google.com with SMTP id b5so11862039plr.4 for ; Tue, 22 Jan 2019 10:11:52 -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=WD+b5Mm6yeuI88aSA3mrYBwAA3DBi7In9eqFESn15DU=; b=elnxxuCbq/YgY5Pr7eGe+AErOidyhvDqdlc5GkuWmcB1CVlDqEFQbKy3JKEtULu/as SH+9ZDtO9o9BFmiTBDcf7DH0ns1iv/tFr41XodKSsRPrlZDvA363X6H0nOQXHXuod64/ z19O662nB+dPd0mylCy+JlcXvcXf6rSHvLe9Y= 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=WD+b5Mm6yeuI88aSA3mrYBwAA3DBi7In9eqFESn15DU=; b=bXwxF8k3E9OQlkdlO8rd+Y3NPq1GxUvevQytZ5vICQG2c3IECF/86wRuXI52CLTDNV AK8Gjg1ISe2EfzuIsEGp2ZlRSMSaVmqX9pfP/KLWnYBH2jF+HDRbGDoUfbL3XDLPfRRZ /CS1vXWFABtuGaIRYe2n1oeVdfnGmdJ+mKQhLpB4A3DbwoPGvMxkNUsp1K0+NMpYcN49 d84A7Z4MUanLH9pRUpu7eUKcyNxT+zR8O8+S2PBduZU6vTFkV3682X1nVCAVxwktOdsi XS529xGJGMvAjI2pQbAVvddshoCkzNB85tNyXso18OjPcCpX88qv7SqWnSlFIIovhjNR 3TmA== X-Gm-Message-State: AJcUukdo4G2m3PsPKKM6vj2kEH7V82J/9HJ0Zqrgt9jFtmEKtAmetgbr +AjtPlbNXr20t97L3xDDJR9Byw== X-Google-Smtp-Source: ALg8bN4+Lt/EoUCyF+GWDLvxqQVSoIGZaCkRZ7fTfdtCKomAfnI7Qqe9ywNdAho//BSVgqgzN2sFew== X-Received: by 2002:a17:902:7296:: with SMTP id d22mr35979711pll.265.1548180712415; Tue, 22 Jan 2019 10:11:52 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id a18sm23489919pgj.30.2019.01.22.10.11.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 10:11:51 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org Subject: [PATCH v2 3/7] coresight: Use event attributes for sink selection Date: Tue, 22 Jan 2019 11:11:40 -0700 Message-Id: <20190122181144.26645-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190122181144.26645-1-mathieu.poirier@linaro.org> References: <20190122181144.26645-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190122_101153_399292_E8901CE0 X-CRM114-Status: GOOD ( 20.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, linux-s390@vger.kernel.org, suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, gregkh@linuxfoundation.org, heiko.carstens@de.ibm.com, adrian.hunter@intel.com, will.deacon@arm.com, ast@kernel.org, mingo@redhat.com, linux-arm-kernel@lists.infradead.org, hpa@zytor.com, schwidefsky@de.ibm.com, namhyung@kernel.org, tglx@linutronix.de, jolsa@redhat.com, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-etm-perf.c | 24 ++++++------ drivers/hwtracing/coresight/coresight-priv.h | 1 + drivers/hwtracing/coresight/coresight.c | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index c68a0036532c..ea031eb673b3 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..c5f2df186a19 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,44 @@ 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); + u32 hash; + + if (csdev->type == CORESIGHT_DEV_TYPE_SINK || + csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) { + /* + * See function etm_perf_sink_name_show() to know where this + * comes from. + */ + hash = hashlen_hash(hashlen_string(NULL, dev_name(dev))); + + if (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