From patchwork Wed Apr 21 12:04:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiss X-Patchwork-Id: 12216045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 307A5C433ED for ; Wed, 21 Apr 2021 12:07:32 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC6326140C for ; Wed, 21 Apr 2021 12:07:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC6326140C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nvFlTMQJUK2wp/ovpOkvIvp+GvakBurpDUHvQ1yeQrg=; b=dnzsNUT3k5L0cfmS8kLKeS3zI 5ElM/dMOTThnb5nZQeSdChkOfkNsgFWDb3d1kG0A4cRTS+odiSz5Y1jM30s1HMYWAozdt7pQfGfu/ Zsfg4nxw+GdfUWzsd8JMykBYlXZfHsGv8PHJVlsWCOKy2TH9Pj2TJYbt0niGi5ArGqr6JAbJbjolG O1GuL3BH++L+Se9W+33EVsN3DFjCsCykrUxi5IEiKPPLjZ7ArjB0b5WelSyEYdrN/qWX/M9VZAk3M PPOx7bf4RWzqkqyOogtDiZlu8vyIGqdGyG1xsldLtP5q19hNIvm0VD4KTcpEY+CRE7hkp3cUhLblP j3Cs/ORgw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbX-00ELoM-EV; Wed, 21 Apr 2021 12:05:15 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbD-00ELmx-I7 for linux-arm-kernel@desiato.infradead.org; Wed, 21 Apr 2021 12:04:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=04vr+WfDSmTH4e1GGR/cAOG29KP+Eq2W2copaLAyp1Y=; b=SLB2FtkwOr7fe7chXGkfAEg7iW W93VWNXObBgKArqrEa2+JHbOE5ZAvq2ZSnRPHprr3SqZhc79BC3l4bpYH/A3YhC7rBmTShGMinR1k 5rNTqiDxalvXsBwEMk4+e7tq734T7nSuA8dFxO+kXX/dpymHgYZ0NRHjk+yPv+XjkQFPS0srrW9uj qEp6HJ/axxVvKGQ/3eF48kSlG5g3U3Dp62faMzpcrBMQhEWVNb/P/hGPalyPc7jlmY7CKBGgG4TYz OBsd1jtoSA4+30BUVXzhGgZiVLcLedtvSYRlux72h4kTtAAB4XnNeL4uwHApoHBFbBf8AE3Q9/XHy Z9RJMj0Q==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBb7-00CqzG-Od for linux-arm-kernel@lists.infradead.org; Wed, 21 Apr 2021 12:04:54 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BE40211FB; Wed, 21 Apr 2021 05:04:46 -0700 (PDT) Received: from e120529.arm.com (unknown [10.37.12.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 313573F694; Wed, 21 Apr 2021 05:04:45 -0700 (PDT) From: Daniel Kiss To: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, mike.leach@linaro.org, leo.yan@linaro.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: denik@google.com, Daniel Kiss , Branislav Rankov Subject: [PATCH 1/4] coresight: tmc-etr: Advance buffer pointer in sync buffer. Date: Wed, 21 Apr 2021 14:04:10 +0200 Message-Id: <20210421120413.3110775-2-daniel.kiss@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210421120413.3110775-1-daniel.kiss@arm.com> References: <20210421120413.3110775-1-daniel.kiss@arm.com> MIME-Version: 1.0 X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_050449_862421_8702CB8A X-CRM114-Status: GOOD ( 11.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With polling the sync could called multiple times in a row. Without this change the data will be overwritten at the beginning of the buffer. Signed-off-by: Daniel Kiss Signed-off-by: Branislav Rankov Reviewed-by: Leo Yan --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index ea5027e397d02..dd19d1d1c3b38 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1442,7 +1442,7 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf, { long bytes; long pg_idx, pg_offset; - unsigned long head = etr_perf->head; + unsigned long head; char **dst_pages, *src_buf; struct etr_buf *etr_buf = etr_perf->etr_buf; @@ -1465,7 +1465,7 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf, bytes = tmc_etr_buf_get_data(etr_buf, src_offset, to_copy, &src_buf); if (WARN_ON_ONCE(bytes <= 0)) - break; + return; bytes = min(bytes, (long)(PAGE_SIZE - pg_offset)); memcpy(dst_pages[pg_idx] + pg_offset, src_buf, bytes); @@ -1483,6 +1483,7 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf, /* Move source pointers */ src_offset += bytes; } + etr_perf->head = (pg_idx << PAGE_SHIFT) + pg_offset; } /* From patchwork Wed Apr 21 12:04:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiss X-Patchwork-Id: 12216051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A83A3C433B4 for ; Wed, 21 Apr 2021 12:08:09 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E039613E0 for ; Wed, 21 Apr 2021 12:08:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E039613E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=G1SrJW5eutIYYW3W1zvAfSOsgYiy7o4fgQE4E/YlxuI=; b=HDOp3cG7D+L4IRNRub2uJ+GlB sHNall8Zb5FW1VPC7hzqFI+JA73nWbd1IgICpJBxM/sN5BKi7Ls+I0typdwj27ExMtFeU9Q48U9UE c9klmkjZDit06G+fCE5drSgpwrDFVcZV2b6X3WiMudwNwCD2P0IBelLK0OzR0uXdOMpunajXDWDLN P8VUhW1tr/w8GaTftUg36K8n3peCTnFlRSBh1Ci5kSS1ud2vCae+02UqVma6oEBZU0pxU26FMyx+g g4G5xYdR0v6cC0Scr4WArSXRqQtyoMeGoDG9wLwWK49/br5iF9PMnw1UnAesTRKxyyGY3aaeUl0RC yUpwBFT2w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBc6-00ELsS-Hj; Wed, 21 Apr 2021 12:05:50 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbH-00ELnD-L1 for linux-arm-kernel@desiato.infradead.org; Wed, 21 Apr 2021 12:05:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=UuZJZ/rSA2GqmmAl4AA0D8Sm+Gfjwrq8e9EJJwxZWug=; b=441Ie6iDPmrbuXyhStjnsXnMVW fWC3sspWx+etGE3jUCAy/Q1Wt2OynCverFZmfXHxhpDDCTTm5RetPMnayzbtlPAt/B3+y9dSSaRUi o9CKW3ici2WqpcFhkLNNHgPiNaCDnMKoUFC/T2pOrFKOU4XCFnJwykkU00wJE8PFqGloGaf65jlDL rzKXiQw5/hQqrQviey3J1LUl28BgebUov1f1dN3Q3wpAgLHuy5vRTNwXLNX0kvvL719xy+FEKgBVj jX22ctZSKfk3FcDFzPG2FmkKOlTZsvdteOL9YRXooTb1CcPagT48gp6w1M5a3yIzc+Hs4ajGSAYCe OdcmXCuA==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBb9-00Cqzh-5j for linux-arm-kernel@lists.infradead.org; Wed, 21 Apr 2021 12:04:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 97DA313A1; Wed, 21 Apr 2021 05:04:48 -0700 (PDT) Received: from e120529.arm.com (unknown [10.37.12.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0C6A53F694; Wed, 21 Apr 2021 05:04:46 -0700 (PDT) From: Daniel Kiss To: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, mike.leach@linaro.org, leo.yan@linaro.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: denik@google.com, Daniel Kiss , Branislav Rankov Subject: [PATCH 2/4] coresight: tmc-etr: Track perf handler. Date: Wed, 21 Apr 2021 14:04:11 +0200 Message-Id: <20210421120413.3110775-3-daniel.kiss@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210421120413.3110775-1-daniel.kiss@arm.com> References: <20210421120413.3110775-1-daniel.kiss@arm.com> MIME-Version: 1.0 X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_050451_278531_980BBE66 X-CRM114-Status: GOOD ( 12.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Keep track of the perf handler that is registred by the first tracer. This will be used by the update call from polling. Signed-off-by: Daniel Kiss Signed-off-by: Branislav Rankov --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 8 ++++++++ drivers/hwtracing/coresight/coresight-tmc.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index dd19d1d1c3b38..bf9f6311d8663 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1511,6 +1511,12 @@ tmc_update_etr_buffer(struct coresight_device *csdev, goto out; } + /* Serve only the tracer with the right handler */ + if (drvdata->perf_handle != handle) { + spin_unlock_irqrestore(&drvdata->spinlock, flags); + goto out; + } + if (WARN_ON(drvdata->perf_buf != etr_buf)) { lost = true; spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -1623,6 +1629,7 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) drvdata->pid = pid; drvdata->mode = CS_MODE_PERF; drvdata->perf_buf = etr_perf->etr_buf; + drvdata->perf_handle = handle; atomic_inc(csdev->refcnt); } @@ -1670,6 +1677,7 @@ static int tmc_disable_etr_sink(struct coresight_device *csdev) drvdata->mode = CS_MODE_DISABLED; /* Reset perf specific data */ drvdata->perf_buf = NULL; + drvdata->perf_handle = NULL; spin_unlock_irqrestore(&drvdata->spinlock, flags); diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index b91ec7dde7bc9..81583ffb973dc 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -184,6 +184,7 @@ struct etr_buf { * @idr_mutex: Access serialisation for idr. * @sysfs_buf: SYSFS buffer for ETR. * @perf_buf: PERF buffer for ETR. + * @perf_handle: PERF handle for ETR. */ struct tmc_drvdata { void __iomem *base; @@ -207,6 +208,7 @@ struct tmc_drvdata { struct mutex idr_mutex; struct etr_buf *sysfs_buf; struct etr_buf *perf_buf; + struct perf_output_handle *perf_handle; }; struct etr_buf_operations { From patchwork Wed Apr 21 12:04:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiss X-Patchwork-Id: 12216047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,TVD_SPACE_RATIO, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45623C433B4 for ; Wed, 21 Apr 2021 12:07:44 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EDBBF61448 for ; Wed, 21 Apr 2021 12:07:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDBBF61448 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gaXd8zJHR9UtEd2TX+NQoOY3vcMg9/hhKVOzlFrtz1c=; b=Am4MHOY76AW+iJx8XX6uT+KCy MUCYPcS3UYCL3MEDolMNI5kJJVeT6jbBD10MZeu8guddthXcV6o0ukhtk7lHslizYPC1H/k4Cv0io vbr2dv8flRZWplliSNHl9PF/Bvggt3SultODzpLTOnGxFT/n86i7QM6cB05/ecGqaiRAmEoYtgLDp deTT/83jpvlYHucopXpq0jZSrPa8zoYIWc5xW+I2IkCiqyJgT1vLbvBEwez+8cfFVFAKOjqbV4sLB BCWTW+IYKzah6h6FSEGo7X/R4F3thIZQlmNiuneXkLC2y2m7RAEL0+93HpJEcJV5nzacHawrgd+hW zp6xVQmgQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbt-00ELqK-OX; Wed, 21 Apr 2021 12:05:40 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbH-00ELnE-LK for linux-arm-kernel@desiato.infradead.org; Wed, 21 Apr 2021 12:05:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=EqKQMQv4iqHYS9kG6zJCWnRHTW6KkgJD0Ua4NGsgY+A=; b=Ap/kxM62OwpKG3QJLWlI7Q46ci UcWo4XKc8NxwW+1wywekAd6SNmA+V3C3GiJJYHr/blw51zldztbzbiTfjBnKG9+h3cXKudYFVPd1b eEZXG+lK4clMMxqm4fD9I+xdeeoOmcct0o7frM+BxuocM86XesxzDvHK/wDdPqWTHRGIbeoUdYkSD mFoJHUTqTiEfhmWa+hgBBpT1wco1zcegR3OSA3wqyAqXzleEB/L4FAn8KBFRu2lMGcOrXPguZ3B6W bGy1weRhXSKqa4RvkagRZzCxcEkr9xYyoXHuqVohe13yeVoeoFTAG3Hu4AVNvlfTgaQuR5dkbwgDP YBL6K+tg==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbA-00Cqzz-74 for linux-arm-kernel@lists.infradead.org; Wed, 21 Apr 2021 12:04:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7898A1424; Wed, 21 Apr 2021 05:04:50 -0700 (PDT) Received: from e120529.arm.com (unknown [10.37.12.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA2533F694; Wed, 21 Apr 2021 05:04:48 -0700 (PDT) From: Daniel Kiss To: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, mike.leach@linaro.org, leo.yan@linaro.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: denik@google.com, Daniel Kiss , Branislav Rankov Subject: [PATCH 3/4] coresight: etm-perf: Export etm_event_cpu_path. Date: Wed, 21 Apr 2021 14:04:12 +0200 Message-Id: <20210421120413.3110775-4-daniel.kiss@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210421120413.3110775-1-daniel.kiss@arm.com> References: <20210421120413.3110775-1-daniel.kiss@arm.com> MIME-Version: 1.0 X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_050452_317275_C180B7A9 X-CRM114-Status: UNSURE ( 9.62 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Signed-off-by: Daniel Kiss Signed-off-by: Branislav Rankov --- drivers/hwtracing/coresight/coresight-etm-perf.c | 2 +- drivers/hwtracing/coresight/coresight-etm-perf.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index f123c26b9f549..78a55fc2bcab5 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -117,7 +117,7 @@ etm_event_cpu_path_ptr(struct etm_event_data *data, int cpu) return per_cpu_ptr(data->path, cpu); } -static inline struct list_head * +struct list_head * etm_event_cpu_path(struct etm_event_data *data, int cpu) { return *etm_event_cpu_path_ptr(data, cpu); diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 3e4f2ad5e193d..6d02abbad1b0f 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -69,6 +69,7 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle) return data->snk_config; return NULL; } +struct list_head *etm_event_cpu_path(struct etm_event_data *data, int cpu); #else static inline int etm_perf_symlink(struct coresight_device *csdev, bool link) { return -EINVAL; } From patchwork Wed Apr 21 12:04:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiss X-Patchwork-Id: 12216049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D0E0C433B4 for ; Wed, 21 Apr 2021 12:07:49 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4061061447 for ; Wed, 21 Apr 2021 12:07:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4061061447 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7392dcv3C0siD8+QN703rtm+MYJhHQmVkZxX8pFtQ3c=; b=VOuEOrwxkTGL712RrhOayUBTt 7kzXPQ3SJc6Ht65d2x5Eh7m4hoWXethoEW5mffRdImqA6wMVFGs/gSRm8whYFEkqbZk0YWivUM50h GSkuzGIbQq8WKslKUgpaLY6k/3otI2QT79UBkHW3XevpLGXlTzij/1UyQhJ+CCI9I8ifC2yVSmVFU cd90AJ4scGFVzxrELhnf20ibY1rYgyLnMeRUVBqS6rGfxH9MUoiAP7jDQ2Ckygh5Y5hzqovIxeiVD pCfOmUwMel3G9ar3VvqKvOVHAEHfHySik9AluknNE68Zt/TOOVuP+IqYpEz+dQpMxSkc3f/iZLzi1 V1aitRrNQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbk-00ELp7-09; Wed, 21 Apr 2021 12:05:28 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbI-00ELnF-LA for linux-arm-kernel@desiato.infradead.org; Wed, 21 Apr 2021 12:05:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kx/tynhQDS4i6k4Tzsl3YzY4bKOaltk+IFbq5UnKaVw=; b=TO0XNDtZqfZPloA2GV4YSR1tP4 hJQM9PiLwKLnSjL96KUBxtH2Wuy5Zq0nylSi/rRdNTR1+1nhQImOyS/j2zjXJWkh/1Lr6c/F508VF TiLWXcnggwMdYtIlSK8QjnI5jIWznp+afPLj/KOUMr7x07helLRebEkmAYCB9/YP9bkgUvYJBQ56/ a/gXzcHKBlptAr6TEsYquSXT08bI4mpc3nAOuHcBGwW4YeR3A8HKl0ajEauf4dWj6BvmyUew5MZvV VxxSXdIETzDW9gY6hwe8LzRsRiRjny3xstgIuTLMquUi73Was8Iqzg5hWugVNsUItIrBBwXO3BJFk wz2PHrnw==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZBbD-00Cr0l-0M for linux-arm-kernel@lists.infradead.org; Wed, 21 Apr 2021 12:04:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8DBA21474; Wed, 21 Apr 2021 05:04:52 -0700 (PDT) Received: from e120529.arm.com (unknown [10.37.12.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC30A3F694; Wed, 21 Apr 2021 05:04:50 -0700 (PDT) From: Daniel Kiss To: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, mike.leach@linaro.org, leo.yan@linaro.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: denik@google.com, Daniel Kiss , Branislav Rankov Subject: [PATCH 4/4] coresight: Add ETR-PERF polling. Date: Wed, 21 Apr 2021 14:04:13 +0200 Message-Id: <20210421120413.3110775-5-daniel.kiss@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210421120413.3110775-1-daniel.kiss@arm.com> References: <20210421120413.3110775-1-daniel.kiss@arm.com> MIME-Version: 1.0 X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_050455_180703_E13DD10A X-CRM114-Status: GOOD ( 29.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org ETR might fill up the buffer sooner than an event makes perf to trigger the synchronisation especially in system wide trace. Polling runs periodically to sync the ETR buffer. Period is configurable via sysfs, disabled by default. Signed-off-by: Daniel Kiss Signed-off-by: Branislav Rankov Tested-by: Denis Nikitin --- .../testing/sysfs-bus-coresight-devices-tmc | 8 + drivers/hwtracing/coresight/Makefile | 2 +- .../hwtracing/coresight/coresight-etm-perf.c | 8 + .../coresight/coresight-etr-perf-polling.c | 316 ++++++++++++++++++ .../coresight/coresight-etr-perf-polling.h | 42 +++ .../hwtracing/coresight/coresight-tmc-core.c | 2 + .../hwtracing/coresight/coresight-tmc-etr.c | 9 + 7 files changed, 386 insertions(+), 1 deletion(-) create mode 100644 drivers/hwtracing/coresight/coresight-etr-perf-polling.c create mode 100644 drivers/hwtracing/coresight/coresight-etr-perf-polling.h diff --git a/Documentation/ABI/testing/sysfs-bus-coresight-devices-tmc b/Documentation/ABI/testing/sysfs-bus-coresight-devices-tmc index 6aa527296c710..4ca7af22a3686 100644 --- a/Documentation/ABI/testing/sysfs-bus-coresight-devices-tmc +++ b/Documentation/ABI/testing/sysfs-bus-coresight-devices-tmc @@ -91,3 +91,11 @@ Contact: Mathieu Poirier Description: (RW) Size of the trace buffer for TMC-ETR when used in SYSFS mode. Writable only for TMC-ETR configurations. The value should be aligned to the kernel pagesize. + +What: /sys/bus/coresight/devices/.tmc/polling/period +Date: April 2021 +KernelVersion: 5.13 +Contact: Daniel Kiss +Description: (RW) Time in milliseconds when the TMC-ETR is synced. + Default value is 0, means the feature is disabled. + Writable only for TMC-ETR configurations. diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index d60816509755c..4df90b71d98cd 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -4,7 +4,7 @@ # obj-$(CONFIG_CORESIGHT) += coresight.o coresight-y := coresight-core.o coresight-etm-perf.o coresight-platform.o \ - coresight-sysfs.o + coresight-sysfs.o coresight-etr-perf-polling.o obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \ coresight-tmc-etr.o diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 78a55fc2bcab5..910a99944eea8 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -19,6 +19,7 @@ #include #include "coresight-etm-perf.h" +#include "coresight-etr-perf-polling.h" #include "coresight-priv.h" static struct pmu etm_pmu; @@ -438,6 +439,8 @@ static void etm_event_start(struct perf_event *event, int flags) /* Tell the perf core the event is alive */ event->hw.state = 0; + etr_perf_polling_event_start(event, event_data, handle); + /* Finally enable the tracer */ if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF)) goto fail_disable_path; @@ -497,6 +500,8 @@ static void etm_event_stop(struct perf_event *event, int mode) if (!sink) return; + etr_perf_polling_event_stop(event, event_data); + /* stop tracer */ source_ops(csdev)->disable(csdev, event); @@ -741,6 +746,8 @@ int __init etm_perf_init(void) etm_pmu.addr_filters_validate = etm_addr_filters_validate; etm_pmu.nr_addr_filters = ETM_ADDR_CMP_MAX; + etr_perf_polling_init(); + ret = perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1); if (ret == 0) etm_perf_up = true; @@ -750,5 +757,6 @@ int __init etm_perf_init(void) void __exit etm_perf_exit(void) { + etr_perf_polling_exit(); perf_pmu_unregister(&etm_pmu); } diff --git a/drivers/hwtracing/coresight/coresight-etr-perf-polling.c b/drivers/hwtracing/coresight/coresight-etr-perf-polling.c new file mode 100644 index 0000000000000..aa0352908873a --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-etr-perf-polling.c @@ -0,0 +1,316 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright(C) 2021 Arm Limited. All rights reserved. + * Author: Daniel Kiss + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "coresight-etr-perf-polling.h" +#include "coresight-priv.h" +#include "coresight-tmc.h" + +#if defined(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) || \ + defined(CONFIG_CORESIGHT_LINK_AND_SINK_TMC_MODULE) + +struct polling_event_list { + struct perf_event *perf_event; + struct etm_event_data *etm_event_data; + struct perf_output_handle *ctx_handle; + void (*tmc_etr_reset_hw)(struct tmc_drvdata *); + struct list_head list; +}; + +struct polling { + int cpu; + struct list_head polled_events; + struct delayed_work delayed_work; +}; + +static atomic_t period; +static spinlock_t spinlock_re; +static struct list_head registered_events; + +static DEFINE_PER_CPU(struct polling, polling); + +static ssize_t period_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int temp; + struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); + + if (drvdata->config_type != TMC_CONFIG_TYPE_ETR) + return -EPERM; + + temp = atomic_read(&period); + return sprintf(buf, "%i\n", temp); +} + +static ssize_t period_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int temp = 0; + struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); + + if (drvdata->config_type != TMC_CONFIG_TYPE_ETR) + return -EPERM; + + if ((1 == sscanf(buf, "%i", &temp)) && (temp >= 0)) + atomic_set(&period, temp); + return count; +} + +static DEVICE_ATTR_RW(period); + +static struct attribute *coresight_tmc_polling_attrs[] = { + &dev_attr_period.attr, + NULL, +}; +const struct attribute_group coresight_tmc_polling_group = { + .attrs = coresight_tmc_polling_attrs, + .name = "polling", +}; +EXPORT_SYMBOL_GPL(coresight_tmc_polling_group); + +static inline void polling_sched_worker(struct polling *p) +{ + int tickrate = atomic_read(&period); + if (!list_empty(&p->polled_events) && (tickrate > 0)) + schedule_delayed_work_on(p->cpu, &p->delayed_work, + msecs_to_jiffies(tickrate)); +} + +static inline bool is_etr_related(struct etm_event_data *etm_event_data, int cpu) +{ + struct list_head *path; + struct coresight_device *sink; + struct tmc_drvdata *drvdata; + path = etm_event_cpu_path(etm_event_data, cpu); + if (WARN_ON(!path)) + return false; + sink = coresight_get_sink(path); + if (WARN_ON(!sink)) + return false; + drvdata = dev_get_drvdata(sink->dev.parent); + if (drvdata->config_type != TMC_CONFIG_TYPE_ETR) + return false; + return true; +} + +/* + * Adds the event to the polled events list. + */ +void etr_perf_polling_event_start(struct perf_event *event, + struct etm_event_data *etm_event_data, + struct perf_output_handle *ctx_handle) +{ + int cpu = smp_processor_id(); + struct polling *p = per_cpu_ptr(&polling, cpu); + struct polling_event_list *element; + struct list_head *i, *tmp; + + if (!is_etr_related(etm_event_data, cpu)) + return; + + spin_lock(&spinlock_re); + list_for_each_safe (i, tmp, ®istered_events) { + element = list_entry(i, struct polling_event_list, list); + if (element->ctx_handle == ctx_handle) { + element->perf_event = event; + element->etm_event_data = etm_event_data; + list_del(&element->list); + spin_unlock(&spinlock_re); + list_add(&element->list, &p->polled_events); + polling_sched_worker(p); + return; + } + } + spin_unlock(&spinlock_re); +} +EXPORT_SYMBOL_GPL(etr_perf_polling_event_start); + +/* + * Removes the event from the to be polled events list. + */ +void etr_perf_polling_event_stop(struct perf_event *event, + struct etm_event_data *etm_event_data) +{ + int cpu = smp_processor_id(); + struct list_head *i, *tmp; + struct polling *p = per_cpu_ptr(&polling, cpu); + + if (!is_etr_related(etm_event_data, cpu)) + return; + + list_for_each_safe (i, tmp, &p->polled_events) { + struct polling_event_list *element = + list_entry(i, struct polling_event_list, list); + if (element->perf_event == event) { + list_del(&element->list); + element->perf_event = NULL; + element->etm_event_data = NULL; + spin_lock(&spinlock_re); + list_add(&element->list, ®istered_events); + spin_unlock(&spinlock_re); + if (list_empty(&p->polled_events)) { + cancel_delayed_work(&p->delayed_work); + } + return; + } + } +} +EXPORT_SYMBOL_GPL(etr_perf_polling_event_stop); + +/* + * The polling worker is a workqueue job which is periodically + * woken up to update the perf aux buffer from the etr shrink. + */ +static void etr_perf_polling_worker(struct work_struct *work) +{ + unsigned long flags; + int cpu = smp_processor_id(); + struct polling *p = per_cpu_ptr(&polling, cpu); + struct list_head *i, *tmp; + + if (!atomic_read(&period)) + return; + + /* + * Scheduling would do the same from the perf hooks, + * this should be done in one go. + */ + local_irq_save(flags); + preempt_disable(); + /* Perf requires rcu lock. */ + rcu_read_lock(); + + polling_sched_worker(p); + + list_for_each_safe (i, tmp, &p->polled_events) { + struct list_head *path; + struct coresight_device *sink; + struct polling_event_list *element = + list_entry(i, struct polling_event_list, list); + + path = etm_event_cpu_path(element->etm_event_data, cpu); + if (WARN_ON(!path)) + continue; + sink = coresight_get_sink(path); + if (WARN_ON(!sink)) + continue; + if (sink_ops(sink)->update_buffer) { + int size, refcnt; + struct tmc_drvdata *drvdata = dev_get_drvdata(sink->dev.parent); + + /* + * Act as now we are the only users of the sink. Due to the locks + * we are safe. + */ + refcnt = atomic_xchg(sink->refcnt, 1); + size = sink_ops(sink)->update_buffer( + sink, element->ctx_handle, + element->etm_event_data->snk_config); + refcnt = atomic_xchg(sink->refcnt, refcnt); + /* + * Restart the trace. + */ + if (element->tmc_etr_reset_hw) + element->tmc_etr_reset_hw(drvdata); + + WARN_ON(size < 0); + if (size > 0) { + struct etm_event_data *new_event_data; + + perf_aux_output_end(element->ctx_handle, size); + new_event_data = perf_aux_output_begin( + element->ctx_handle, + element->perf_event); + if (WARN_ON(new_event_data == NULL)) + continue; + element->etm_event_data = new_event_data; + WARN_ON(new_event_data->snk_config != + element->etm_event_data->snk_config); + } + } + } + + rcu_read_unlock(); + preempt_enable(); + local_irq_restore(flags); +} + +void etr_perf_polling_handle_register(struct perf_output_handle *handle, + void (*tmc_etr_reset_hw)(struct tmc_drvdata *drvdata)) +{ + struct polling_event_list *element; + + element = kmalloc(sizeof(*element), GFP_KERNEL); + if (WARN_ON(!element)) + return; + memset(element, 0, sizeof(*element)); + element->ctx_handle = handle; + element->tmc_etr_reset_hw = tmc_etr_reset_hw; + spin_lock(&spinlock_re); + list_add(&element->list, ®istered_events); + spin_unlock(&spinlock_re); +} +EXPORT_SYMBOL_GPL(etr_perf_polling_handle_register); + +void etr_perf_polling_handle_deregister(struct perf_output_handle *handle) +{ + struct list_head *i, *tmp; + + spin_lock(&spinlock_re); + list_for_each_safe (i, tmp, ®istered_events) { + struct polling_event_list *element = + list_entry(i, struct polling_event_list, list); + if (element->ctx_handle == handle) { + list_del(&element->list); + spin_unlock(&spinlock_re); + kfree(element); + return; + } + } + spin_unlock(&spinlock_re); +} +EXPORT_SYMBOL_GPL(etr_perf_polling_handle_deregister); + +void etr_perf_polling_init(void) +{ + int cpu; + spin_lock_init(&spinlock_re); + INIT_LIST_HEAD(®istered_events); + atomic_set(&period, 0); + for_each_possible_cpu (cpu) { + struct polling *p = per_cpu_ptr(&polling, cpu); + p->cpu = cpu; + INIT_LIST_HEAD(&p->polled_events); + INIT_DELAYED_WORK(&p->delayed_work, etr_perf_polling_worker); + } +} +EXPORT_SYMBOL_GPL(etr_perf_polling_init); + +void etr_perf_polling_exit(void) +{ + int cpu; + for_each_possible_cpu (cpu) { + struct polling *p = per_cpu_ptr(&polling, cpu); + cancel_delayed_work_sync(&p->delayed_work); + WARN_ON(!list_empty(&p->polled_events)); + } + WARN_ON(!list_empty(®istered_events)); +} +EXPORT_SYMBOL_GPL(etr_perf_polling_exit); + +#endif diff --git a/drivers/hwtracing/coresight/coresight-etr-perf-polling.h b/drivers/hwtracing/coresight/coresight-etr-perf-polling.h new file mode 100644 index 0000000000000..5917e1fa408bb --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-etr-perf-polling.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright(C) 2021 Arm Limited. All rights reserved. + * Author: Daniel Kiss + */ + +#ifndef _CORESIGHT_ETM_PERF_POLLING_H +#define _CORESIGHT_ETM_PERF_POLLING_H + +#include +#include +#include "coresight-etm-perf.h" +#include "coresight-tmc.h" + +#if defined(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) || \ + defined(CONFIG_CORESIGHT_LINK_AND_SINK_TMC_MODULE) + +void etr_perf_polling_init(void); +void etr_perf_polling_exit(void); +void etr_perf_polling_handle_register(struct perf_output_handle *handle, + void (*tmc_etr_reset_hw)(struct tmc_drvdata *drvdata)); +void etr_perf_polling_handle_deregister(struct perf_output_handle *handle); +void etr_perf_polling_event_start(struct perf_event *event, + struct etm_event_data *etm_event_data, + struct perf_output_handle *ctx_handle); +void etr_perf_polling_event_stop(struct perf_event *event, + struct etm_event_data *etm_event_data); + +extern const struct attribute_group coresight_tmc_polling_group; +#define CORESIGHT_TMP_POLLING_GROUP &coresight_tmc_polling_group, + +#else /* !CONFIG_CORESIGHT_LINK_AND_SINK_TMC */ +#define etr_perf_polling_init() +#define etr_perf_polling_exit() +#define etr_perf_polling_handle_register(...) +#define etr_perf_polling_handle_deregister(...) +#define etr_perf_polling_event_start(...) +#define etr_perf_polling_event_stop(...) +#define CORESIGHT_TMP_POLLING_GROUP +#endif + +#endif diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c index 74c6323d4d6ab..51e705ef3ffa3 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -26,6 +26,7 @@ #include "coresight-priv.h" #include "coresight-tmc.h" +#include "coresight-etr-perf-polling.h" DEFINE_CORESIGHT_DEVLIST(etb_devs, "tmc_etb"); DEFINE_CORESIGHT_DEVLIST(etf_devs, "tmc_etf"); @@ -365,6 +366,7 @@ static const struct attribute_group coresight_tmc_mgmt_group = { static const struct attribute_group *coresight_tmc_groups[] = { &coresight_tmc_group, &coresight_tmc_mgmt_group, + CORESIGHT_TMP_POLLING_GROUP NULL, }; diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index bf9f6311d8663..021b594e38e71 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -16,6 +16,7 @@ #include #include "coresight-catu.h" #include "coresight-etm-perf.h" +#include "coresight-etr-perf-polling.h" #include "coresight-priv.h" #include "coresight-tmc.h" @@ -1139,6 +1140,12 @@ void tmc_etr_disable_hw(struct tmc_drvdata *drvdata) drvdata->etr_buf = NULL; } +static void tmc_etr_reset_hw(struct tmc_drvdata *drvdata) +{ + __tmc_etr_disable_hw(drvdata); + __tmc_etr_enable_hw(drvdata); +} + static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) { int ret = 0; @@ -1630,6 +1637,7 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) drvdata->mode = CS_MODE_PERF; drvdata->perf_buf = etr_perf->etr_buf; drvdata->perf_handle = handle; + etr_perf_polling_handle_register(handle, tmc_etr_reset_hw); atomic_inc(csdev->refcnt); } @@ -1677,6 +1685,7 @@ static int tmc_disable_etr_sink(struct coresight_device *csdev) drvdata->mode = CS_MODE_DISABLED; /* Reset perf specific data */ drvdata->perf_buf = NULL; + etr_perf_polling_handle_deregister(drvdata->perf_handle); drvdata->perf_handle = NULL; spin_unlock_irqrestore(&drvdata->spinlock, flags);