From patchwork Mon Mar 25 21:56:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870123 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 790421575 for ; Mon, 25 Mar 2019 21:59:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CF5F26E16 for ; Mon, 25 Mar 2019 21:59:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CD7A284C3; Mon, 25 Mar 2019 21:59:35 +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 C67EB26E16 for ; Mon, 25 Mar 2019 21:59:34 +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=2n64817kBFRLbBs7h6JjR4bFTcbm3o2/p+rWVZRKBuM=; b=u4J1r51fNXpS93vXAlP8Z0PChT wVJRrUdQxVSgpIEfU2tRQkFqXKPUAHAaC1rORXpilx/bPQr51Bdsv3viYVeJK9Q/zsOxkF0E7Td1Z CtpwTL47gK1hnve6+wsdeh/0MThaMwvWjEOtvd0bp5RqFeAqDEnmF90LBBIl0TNtSz+kF+OhraxqE V3Ct5IEBRbUuTIxIgQvg12Q/voaZjCi23Yjb8LOkaHXj2tjzL2E0FWtXm8D8I54/kC10huVB5mmG0 GBr9iwRVCymgKw+n6qfB4hBg40N32mcU3HfMaifovdl3+tRHOnQJp9GzOGRn/Ciw74KeMC2SUOiaG zy72xROw==; 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 1h8Xcr-0007PU-TI; Mon, 25 Mar 2019 21:59:25 +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 1h8XaR-00040F-Bx for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:57:08 +0000 Received: by mail-pl1-x642.google.com with SMTP id b65so587044plb.6 for ; Mon, 25 Mar 2019 14:56:54 -0700 (PDT) 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=sdDt/HRF6MLGkuxtGtaVQsmhDK4+MNWevaRbT+jK8kU=; b=IGClc5M9zhSt/zZtnDHqjJnwdmi73yo7WwX7rK0ctpzRZz7wcrLQreOOTnlLCPKgt/ jbG3K/oLDaSO8zzKaLXFSYEBqQFpEUDqZQYH8eHnBom3FHd0hNp7SvGSmgJ+/tn3iZjq CTW1bWo74G+ean4EntP0UOgvm0zV6XdnyRtTXgiSvDJZzlGWtEaSvD7CfzBKix1MjO5f T59HLnLYrX/XwOZe01r0ZMT7Sq6Sw2av65IUS33iSDwUGVLDGEREkBRWDERqAoJszi7u Ty4PvbRgFzUkka/WLBfOksaNj/hmzVDoHfYS0MuJTlLDKolpC+NBjfZkKFACNy8J4zDG oecw== 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=sdDt/HRF6MLGkuxtGtaVQsmhDK4+MNWevaRbT+jK8kU=; b=LAuxK+ODn5Jh7MAvUhmEWU/x/WFtJnNQQaqL3lcsdJ8t8DiRDK27gipkrhUUzFvcCI DInFX7dPHA9tghrPnWHHUZXQQgWVrJCuA8Za84NMIWMSa3nZIwgFZe4MDWLNC9+PLHxZ AcXpvdYa3YKYV/r1XkFoz77X7o5FWrdH5uc0BwyBKU0qvbX7DROborY9xvppNnfZ1M9B hRnjKp51UR7zNDGGlb7ebRDg2p3x1GF7yRuHXHN2nrx5nwCWcDVLmFnuG8/blPdLj/v5 LVvo93+MJ0DFTY/RbgwyrJgWcDrjmxdGgVPrACgNIqWKk8zTFe0thaKpHcajCXgd80Sr lNGA== X-Gm-Message-State: APjAAAUNmzICfgpZNJSgaqcTtohfh4f10Rr8qc8tv2hzP+T/ld/R045M AKRmwrznl9ZlFNeLFgZMt/+Q4hHtQEk= X-Google-Smtp-Source: APXvYqwYoFrcWKiplK8jsgdHh6wkanoj0E/rlKL6xVTh7z3hgOWJlsLG2UaHA+hpBkm6/MG74bsGIA== X-Received: by 2002:a17:902:8349:: with SMTP id z9mr7851629pln.144.1553551013416; Mon, 25 Mar 2019 14:56:53 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:52 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 15/16] coresight: tmc-etf: Add support for CPU-wide trace scenarios Date: Mon, 25 Mar 2019 15:56:31 -0600 Message-Id: <20190325215632.17013-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145655_967672_1A32B8FD X-CRM114-Status: GOOD ( 20.16 ) 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: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.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 adds support for CPU-wide trace scenarios by making sure that only the sources monitoring the same process have access to a common sink. Because the sink is shared between sources, the first source to use the sink switches it on while the last one does the cleanup. Any attempt to modify the HW is overlooked for as long as more than one source is using a sink. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etf.c | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 1df1f8fade71..2527b5d3b65e 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -223,6 +223,7 @@ static int tmc_enable_etf_sink_sysfs(struct coresight_device *csdev) static int tmc_enable_etf_sink_perf(struct coresight_device *csdev, void *data) { int ret = 0; + pid_t pid; unsigned long flags; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct perf_output_handle *handle = data; @@ -233,18 +234,39 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev, void *data) if (drvdata->reading) break; /* - * In Perf mode there can be only one writer per sink. There - * is also no need to continue if the ETB/ETF is already - * operated from sysFS. + * No need to continue if the ETB/ETF is already operated + * from sysFS. */ - if (drvdata->mode != CS_MODE_DISABLED) + if (drvdata->mode == CS_MODE_SYSFS) { + ret = -EBUSY; break; + } + + /* Get a handle on the pid of the process to monitor */ + pid = task_pid_nr(handle->event->owner); + + if (drvdata->pid != -1 && drvdata->pid != pid) { + ret = -EBUSY; + break; + } ret = tmc_set_etf_buffer(csdev, handle); if (ret) break; + + /* + * No HW configuration is needed if the sink is already in + * use for this session. + */ + if (drvdata->pid == pid) { + atomic_inc(csdev->refcnt); + break; + } + ret = tmc_etb_enable_hw(drvdata); if (!ret) { + /* Associate with monitored process. */ + drvdata->pid = pid; drvdata->mode = CS_MODE_PERF; atomic_inc(csdev->refcnt); } @@ -300,6 +322,8 @@ static int tmc_disable_etf_sink(struct coresight_device *csdev) /* Complain if we (somehow) got out of sync */ WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); tmc_etb_disable_hw(drvdata); + /* Dissociate from monitored process. */ + drvdata->pid = -1; drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -414,7 +438,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, u32 *buf_ptr; u64 read_ptr, write_ptr; u32 status; - unsigned long offset, to_read, flags; + unsigned long offset, to_read = 0, flags; struct cs_buffers *buf = sink_config; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -426,6 +450,11 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, return 0; spin_lock_irqsave(&drvdata->spinlock, flags); + + /* Don't do anything if another tracer is using this sink */ + if (atomic_read(csdev->refcnt) != 1) + goto out; + CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); @@ -519,6 +548,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, to_read = buf->nr_pages << PAGE_SHIFT; } CS_LOCK(drvdata->base); +out: spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read;