From nobody Fri Dec 19 17:11:29 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6879C214A97; Tue, 1 Apr 2025 18:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743530850; cv=none; b=l3JBC0HHjT6ThNlmjpj6vwmdE5Ll81r5KvYx2MnvF8csjIpIF7pt7czLdu59YJB6Lm9rq7645onTY3xL6wucEm8Ki1ifv3lXUPIuRTtg+53JwFwZSuyFRMqfAvvA68gs6oF9DeDiYRyxfnHxx72QsBvLdHPqTHBPUNsS9DXGeas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743530850; c=relaxed/simple; bh=/PeLFzgF6cIQxdwwtfcBvZMjQQANd74DmwMtIiPMZQ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dpRb6ulnAxYbTUV9tU2vq2Gd4cPSC9GR/siuPAl5BMCoQ5hRqKQa1StUbVATm1gu+lGtyEYbAHaF3VJpyqAYuYKVSZ5sO4F26X+AU3BP8PBdKR6+pGRQHXboNTNn4fSTOUfSoXGSESoCoZX3fkxyH2/Zst4xB/kDLVAn0KH9Q3Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 81CD81655; Tue, 1 Apr 2025 11:07:31 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8FD143F59E; Tue, 1 Apr 2025 11:07:26 -0700 (PDT) From: Leo Yan To: Suzuki K Poulose , Mike Leach , James Clark , Jonathan Corbet , Alexander Shishkin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v4 6/7] coresight: perf: Update buffer on AUX pause Date: Tue, 1 Apr 2025 19:07:07 +0100 Message-Id: <20250401180708.385396-7-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250401180708.385396-1-leo.yan@arm.com> References: <20250401180708.385396-1-leo.yan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Due to sinks like ETR and ETB don't support interrupt handling, the hardware trace data might be lost for continuous running tasks. This commit takes advantage of the AUX pause for updating trace buffer to mitigate the trace data losing issue. The per CPU sink has its own interrupt handling. Thus, there will be a race condition between the updating buffer in NMI and sink's interrupt handler. To avoid the race condition, this commit disallows updating buffer on AUX pause for the per CPU sink. Currently, this is only applied for TRBE. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-etm-perf.c | 43 ++++++++++++++++++++= +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index 2dcf1809cb7f..f1551c08ecb2 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -574,14 +574,53 @@ static void etm_event_start(struct perf_event *event,= int flags) return; } =20 -static void etm_event_pause(struct coresight_device *csdev, +static void etm_event_pause(struct perf_event *event, + struct coresight_device *csdev, struct etm_ctxt *ctxt) { + int cpu =3D smp_processor_id(); + struct coresight_device *sink; + struct perf_output_handle *handle =3D &ctxt->handle; + struct coresight_path *path; + unsigned long size; + if (!ctxt->event_data) return; =20 /* Stop tracer */ coresight_pause_source(csdev); + + path =3D etm_event_cpu_path(ctxt->event_data, cpu); + sink =3D coresight_get_sink(path); + if (WARN_ON_ONCE(!sink)) + return; + + /* + * The per CPU sink has own interrupt handling, it might have + * race condition with updating buffer on AUX trace pause if + * it is invoked from NMI. To avoid the race condition, + * disallows updating buffer for the per CPU sink case. + */ + if (coresight_is_percpu_sink(sink)) + return; + + if (WARN_ON_ONCE(handle->event !=3D event)) + return; + + if (!sink_ops(sink)->update_buffer) + return; + + size =3D sink_ops(sink)->update_buffer(sink, handle, + ctxt->event_data->snk_config); + if (READ_ONCE(handle->event)) { + if (!size) + return; + + perf_aux_output_end(handle, size); + perf_aux_output_begin(handle, event); + } else { + WARN_ON_ONCE(size); + } } =20 static void etm_event_stop(struct perf_event *event, int mode) @@ -595,7 +634,7 @@ static void etm_event_stop(struct perf_event *event, in= t mode) struct coresight_path *path; =20 if (mode & PERF_EF_PAUSE) - return etm_event_pause(csdev, ctxt); + return etm_event_pause(event, csdev, ctxt); =20 /* * If we still have access to the event_data via handle, --=20 2.34.1