From patchwork Thu Apr 4 03:35: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: 10884827 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 8688C1800 for ; Thu, 4 Apr 2019 03:37:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B28628A1D for ; Thu, 4 Apr 2019 03:37:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F55F28A33; Thu, 4 Apr 2019 03:37:58 +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 E3EB828A38 for ; Thu, 4 Apr 2019 03:37:57 +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=Fi9Eg/dzApO0Mpr22l+xkmIScb BftagbCxX4bXWi3Dn0QAq76/3jVdlfgBBNoA5eRppO+BEtm8tbr26DaqPcdOoFSD89ayG3rA8At1s yFJaKWmH1IqmH2fU3SuXkf0Miq4l8Ucb9NAVpX50qqFfqw30DBJ122Z2l9OAGgeDERhwIC904jzxb eYmnVI8LRcoTv96b0tUEjd46OeHiyZX/WYoqiz8rfLq6JBeNZXrdTtEr372aMDpA65dH77LaX/XbS LNt/o+d4FQYXxc7mw8GehyJ1iZ+fHHEDlDTRCYWgYVNdE41upsSenxl8n/yUdfTIkzXhJWq6cqvnI miO9qtqQ==; 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 1hBtCN-0005JE-PG; Thu, 04 Apr 2019 03:37:55 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtBT-00049H-56 for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:37:28 +0000 Received: by mail-pl1-x644.google.com with SMTP id g12so426841pll.11 for ; Wed, 03 Apr 2019 20:36:59 -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=me0reGUHzjAiArUnM1m+8nwEBbmaHHIkK5QeHwjSxqEanx5sievn47DGQJOzluk7Yz K/wE+zAXLVZX25JzVwlb8I5DF7VoNep4JqOUhiEF6tKVxTglGMTWSx/2kOtKMRZGWWtU rWrGYYloH9wHtFC95pVDFDURHy5sWe5YpMK8noldYig6bHLwrX28/gnwoCfxbTPWKZrV wvLOpaiEh2v2HCbgfAr3HILmumCUA+Ur6oXsqnZO+uqgtmQBQ9+rFGJkjfHkdk6fJUoF LbkT9VmGoSqTCA7EQzoUYilV+6+7HCrBzOEMvWLp0f/vqap4uXJOqY7/b1erSZv/7/jN VgsQ== 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=JNTNer9aG1F6SB4+D/iIIi9lUcqK+PzNXT47GKO7rBYbkMYh0WHCOb62rnSWbmnqDk dvtkJrDoAHkN8ffOh/1K85vWlVKQ/jMgyzsOzSuyodX1Vl7hTvKCSXjRQTpRW3Ksiriv PKcr2Cu7YGB+bVTDMSJduL5VUBKBpbhWwMbTiLp+0jJaHKrlALswZhGUE1ELr/+JkcVH kmfo5xEaYMh6tJZihM5J+1kQztaZqFgXqwFuKEJrxF79GeI8dtPx+i+DIs8q2WRBIrsk 0mNiY0YxaAyIHjHsS2+0wGyHiUKoKSE9HjQAi+4yxrwCeaDmcBWi9A325PByYDyVKFC3 lU1w== X-Gm-Message-State: APjAAAUotvlfu2WnCKuMyLifSJzMR7sgrPSyBfMSe5aSIJRfE40KePPQ CV0bn4IGl7fxZhb5+SzYdeCiLoZRVq8= X-Google-Smtp-Source: APXvYqyK4MW2ELDtAddGQj/FriWe6wE+DJubczgxcSwbaMAob3whBlTlbA1CQ+CxPP+qJ7oQEL41dA== X-Received: by 2002:a17:902:7c8c:: with SMTP id y12mr3808185pll.209.1554349018449; Wed, 03 Apr 2019 20:36:58 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:57 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 19/20] coresight: tmc-etf: Add support for CPU-wide trace scenarios Date: Wed, 3 Apr 2019 21:35:40 -0600 Message-Id: <20190404033541.14072-20-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203659_512137_90A98139 X-CRM114-Status: GOOD ( 20.32 ) 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, linux-kernel@vger.kernel.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;