From patchwork Mon Mar 25 21:56:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870119 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 195261708 for ; Mon, 25 Mar 2019 21:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00C6626E16 for ; Mon, 25 Mar 2019 21:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8347284C3; Mon, 25 Mar 2019 21:59:19 +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 6C46226E16 for ; Mon, 25 Mar 2019 21:59:19 +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=pv8zWJQKoOHpYRTjY7HF6w63gTBgdzk7MI+YfiTEO0I=; b=pxYA9H7vhX2MGHE9YwPUAxf8Cf zsCcTn/NbLIRflCw33569s+rjlqkb+Uyoe/USmJL/MS5O6Dm1ef9w0jJbPj1yywtW3he5lJwKYkuD dLbRGr6HllVvsZnUk5XhgsZzT7dCuBNhND/8KH/1tgoX1IHfsC7eO5fEMuaxnGBRk6Fkk/4bGxc2L 9hL0XYZKc+NLyG/OumFQOCbDnTdLdEwUUTCeB7AtLUJs0CcM/5pImRB4aVzSgLF8mKiRq3iaVCA2M pJrLvuOIOG35mNSBgyvsH4bNCGlUCHLerLii48cixSVLo5hqvlo+yQLyVYiMw6BNnI/30PSWiG8+N 0VKu4vTQ==; 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 1h8Xci-0007C9-Mz; Mon, 25 Mar 2019 21:59:16 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaS-00043G-Tg for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:57:04 +0000 Received: by mail-pg1-x544.google.com with SMTP id r124so7225167pgr.3 for ; Mon, 25 Mar 2019 14:56:56 -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=DXJXs+4knPk/tA7or7zclZmTtg+ioeh357GrnSar9kA=; b=djepXZ6AJNIDtbCLxgLily6ohflcyelSSObFoqvFeYPGTcr/UvHnixruLBLw6BZj0Q /7e4owFROHNufLa3agTFuXrtqdLDqf08xjiBx/xZKycUVRQJoDTU2GjbQo5ez9qzeAsI RXXE/JFWRrxMEd9xbnN6Ss0sztuLcwgKtknL2cI/dtzsaJkuNGwBRE5FOPEB2zG+l2fa /2k9SJGECNc5Q1lWEfROiY/pwYB+lhVPqeheihXcLMRpJxABL2Kf8iKIsWjmDhQlAG0M 9u1J+1mz5+yDBXQRGJCm8eMpryX+LqIRv2Vjs8oPBcgSHdToxXf0mvbwq1GdLlSGhmXs bjXQ== 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=DXJXs+4knPk/tA7or7zclZmTtg+ioeh357GrnSar9kA=; b=pbmpiOA6QZl2HPhwD9pnk73o+Mup6jUfPE3I/oj1BkN+FsXeONDkdEaybHiN+Dr8X+ iKQoHabrHvNF+lwXTc+L2gaXhV4LjlkOAQPtVQRdXcAkjj76NTdmO/qFRQCZ0ZkRz7+T txO8kAYcv9CYS95oXURfOFd89JpijcHlT7gKwmCuNSNaDHVEohNOu2csLHmjjEUZdrhM uT2xC0Br2QmSsfZxW3q532c2PR2hZYGvwU7XLEZr+r7QCZIMUB9bnNKBsK6wxhbtTC1E zNdg0Lb45ffLhQL6W1KD3wte7Vk6u6Kmm7okedDcx/sR23pCERg6k+8IO/6tw5+cre57 +Qcw== X-Gm-Message-State: APjAAAUmbtO8l7iUxLBD2MpRv/KFdp46xmUCBZlI7GGjK/0sDQhE6JuN uMvr//BUH2QIS5/eLmfSt/scbwCOt24= X-Google-Smtp-Source: APXvYqzxDauwRP2coqGxJ0zScXl0rrkdJ1AByjn7L4cPOfUt2UVyV4sI64bG/0IgnJtnhvYkb2qYLw== X-Received: by 2002:a62:5789:: with SMTP id i9mr25604999pfj.75.1553551015199; Mon, 25 Mar 2019 14:56:55 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:54 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 16/16] coresight: etb10: Add support for CPU-wide trace scenarios Date: Mon, 25 Mar 2019 15:56:32 -0600 Message-Id: <20190325215632.17013-17-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_145657_711194_ED3062CF X-CRM114-Status: GOOD ( 23.00 ) 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 --- drivers/hwtracing/coresight/coresight-etb10.c | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 7d64c41cd8ac..a2379c00d635 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -72,6 +72,8 @@ * @miscdev: specifics to handle "/dev/xyz.etb" entry. * @spinlock: only one at a time pls. * @reading: synchronise user space access to etb buffer. + * @pid: Process ID of the process being monitored by the session + * that is using this component. * @buf: area of memory where ETB buffer content gets sent. * @mode: this ETB is being used. * @buffer_depth: size of @buf. @@ -85,6 +87,7 @@ struct etb_drvdata { struct miscdevice miscdev; spinlock_t spinlock; local_t reading; + pid_t pid; u8 *buf; u32 mode; u32 buffer_depth; @@ -177,28 +180,49 @@ static int etb_enable_sysfs(struct coresight_device *csdev) static int etb_enable_perf(struct coresight_device *csdev, void *data) { int ret = 0; + pid_t pid; unsigned long flags; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + struct perf_output_handle *handle = data; spin_lock_irqsave(&drvdata->spinlock, flags); - /* No need to continue if the component is already in use. */ - if (drvdata->mode != CS_MODE_DISABLED) { + /* No need to continue if the component is already in used by sysFS. */ + if (drvdata->mode == CS_MODE_SYSFS) { + ret = -EBUSY; + goto out; + } + + /* 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; goto out; } + /* + * No HW configuration is needed if the sink is already in + * use for this session. + */ + if (drvdata->pid == pid) { + atomic_inc(csdev->refcnt); + goto out; + } + /* * We don't have an internal state to clean up if we fail to setup * the perf buffer. So we can perform the step before we turn the * ETB on and leave without cleaning up. */ - ret = etb_set_buffer(csdev, (struct perf_output_handle *)data); + ret = etb_set_buffer(csdev, handle); if (ret) goto out; ret = etb_enable_hw(drvdata); if (!ret) { + /* Associate with monitored process. */ + drvdata->pid = pid; drvdata->mode = CS_MODE_PERF; atomic_inc(csdev->refcnt); } @@ -344,6 +368,8 @@ static int etb_disable(struct coresight_device *csdev) /* Complain if we (somehow) got out of sync */ WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); etb_disable_hw(drvdata); + /* Dissociate from monitored process. */ + drvdata->pid = -1; drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -414,7 +440,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, const u32 *barrier; u32 read_ptr, write_ptr, capacity; u32 status, read_data; - unsigned long offset, to_read, flags; + unsigned long offset, to_read = 0, flags; struct cs_buffers *buf = sink_config; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -424,6 +450,11 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, capacity = drvdata->buffer_depth * ETB_FRAME_SIZE_WORDS; 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; + __etb_disable_hw(drvdata); CS_UNLOCK(drvdata->base); @@ -534,6 +565,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, } __etb_enable_hw(drvdata); CS_LOCK(drvdata->base); +out: spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; @@ -742,6 +774,9 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id) if (!drvdata->buf) return -ENOMEM; + /* This device is not associated with a session */ + drvdata->pid = -1; + desc.type = CORESIGHT_DEV_TYPE_SINK; desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; desc.ops = &etb_cs_ops;