From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: James Clark <james.clark@linaro.org>, Leo Yan <leo.yan@arm.com>
Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
Mike Leach <mike.leach@linaro.org>,
Yeoreum Yun <yeoreum.yun@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Yabin Cui <yabinc@google.com>,
Yuanfang Zhang <quic_yuanfang@quicinc.com>
Subject: Re: [PATCH v4 13/15] coresight: trbe: Save and restore state across CPU low power state
Date: Tue, 11 Nov 2025 14:16:35 +0000 [thread overview]
Message-ID: <b9ecd05c-094a-42d3-83fd-27d73a4713ee@arm.com> (raw)
In-Reply-To: <61dc6f04-41da-4272-82b1-1789201eb06d@linaro.org>
On 10/11/2025 12:01, James Clark wrote:
>
>
> On 04/11/2025 3:21 pm, Leo Yan wrote:
>> From: Yabin Cui <yabinc@google.com>
>>
>> Similar to ETE, TRBE may lose its context when a CPU enters low power
>> state. To make things worse, if ETE is restored without TRBE being
>> restored, an enabled source device with no enabled sink devices can
>> cause CPU hang on some devices (e.g., Pixel 9).
>>
>> The save and restore flows are described in the section K5.5 "Context
>> switching" of Arm ARM (ARM DDI 0487 L.a). This commit adds save and
>> restore callbacks with following the software usages defined in the
>> architecture manual.
>>
>> Signed-off-by: Yabin Cui <yabinc@google.com>
>> Co-developed-by: Leo Yan <leo.yan@arm.com>
>> Signed-off-by: Leo Yan <leo.yan@arm.com>
>> ---
>> drivers/hwtracing/coresight/coresight-trbe.c | 84 ++++++++++++++++++
>> +++++++++-
>> 1 file changed, 83 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/
>> hwtracing/coresight/coresight-trbe.c
>> index
>> 3c82ab4394fde1e3dd4371a9b1703da4d8f6db9d..9888a153bc2f99b4826f6103bdbc12304c9c94cb 100644
>> --- a/drivers/hwtracing/coresight/coresight-trbe.c
>> +++ b/drivers/hwtracing/coresight/coresight-trbe.c
>> @@ -116,6 +116,20 @@ static int trbe_errata_cpucaps[] = {
>> */
>> #define TRBE_WORKAROUND_OVERWRITE_FILL_MODE_SKIP_BYTES 256
>> +/*
>> + * struct trbe_save_state: Register values representing TRBE state
>> + * @trblimitr - Trace Buffer Limit Address Register value
>> + * @trbbaser - Trace Buffer Base Register value
>> + * @trbptr - Trace Buffer Write Pointer Register value
>> + * @trbsr - Trace Buffer Status Register value
>> + */
>> +struct trbe_save_state {
>> + u64 trblimitr;
>> + u64 trbbaser;
>> + u64 trbptr;
>> + u64 trbsr;
>> +};
>> +
>> /*
>> * struct trbe_cpudata: TRBE instance specific data
>> * @trbe_flag - TRBE dirty/access flag support
>> @@ -134,6 +148,7 @@ struct trbe_cpudata {
>> enum cs_mode mode;
>> struct trbe_buf *buf;
>> struct trbe_drvdata *drvdata;
>> + struct trbe_save_state save_state;
>> DECLARE_BITMAP(errata, TRBE_ERRATA_MAX);
>> };
>> @@ -1189,6 +1204,71 @@ static irqreturn_t arm_trbe_irq_handler(int
>> irq, void *dev)
>> return IRQ_HANDLED;
>> }
>> +static int arm_trbe_save(struct coresight_device *csdev)
>> +{
>> + struct trbe_cpudata *cpudata = dev_get_drvdata(&csdev->dev);
>> + struct trbe_save_state *state = &cpudata->save_state;
>> +
>> + if (cpudata->mode == CS_MODE_DISABLED)
>> + return 0;
>> +
>> + /*
>> + * According to the section K5.5 Context switching, Arm ARM (ARM DDI
>> + * 0487 L.a), the software usage VKHHY requires a TSB CSYNC
>> instruction
>> + * to ensure the program-flow trace is flushed, which has been
>> executed
>> + * in ETM driver.
>> + */
>> +
>> + /* Disable trace buffer unit */
>> + state->trblimitr = read_sysreg_s(SYS_TRBLIMITR_EL1);
>> + write_sysreg_s(state->trblimitr & ~TRBLIMITR_EL1_E,
>> SYS_TRBLIMITR_EL1);
>> +
>> + /*
>> + * Execute a further Context synchronization event. Ensure the
>> writes to
>> + * memory are complete.
>> + */
>> + trbe_drain_buffer();
>> +
>> + /* Synchronize the TRBE disabling */
>> + isb();
>
> Can we use set_trbe_disabled() here, and set_trbe_enabled() for restore
> below. There is a bit of duplication and they do the same thing except
> this version here always has trbe_drain_buffer() rather than it being
> conditional. I'm not sure if that is correct as they should both be the
> same?
>
> set_trbe_disabled() already reads TRBLIMITR_EL1 so you can return it.
+1
>> + if (trbe_needs_ctxt_sync_after_enable(cpudata))
>> + isb();
>
> Especially this double isb() part shouldn't be duplicated as that could
> get broken in a refactor in the future.
+1
Suzuki
next prev parent reply other threads:[~2025-11-11 14:16 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 15:21 [PATCH v4 00/15] CoreSight: Refactor power management for CoreSight path Leo Yan
2025-11-04 15:21 ` [PATCH v4 01/15] coresight: sysfs: Validate CPU online status for per-CPU sources Leo Yan
2025-11-04 15:21 ` [PATCH v4 02/15] coresight: Set per CPU source pointer Leo Yan
2025-11-04 15:21 ` [PATCH v4 03/15] coresight: Register CPU PM notifier in core layer Leo Yan
2025-11-10 10:49 ` James Clark
2025-11-11 12:13 ` Suzuki K Poulose
2025-11-12 18:09 ` Leo Yan
2025-11-04 15:21 ` [PATCH v4 04/15] coresight: etm4x: Hook CPU PM callbacks Leo Yan
2025-11-10 10:50 ` James Clark
2025-11-04 15:21 ` [PATCH v4 05/15] coresight: Add callback to determine if PM is needed Leo Yan
2025-11-10 10:54 ` James Clark
2025-11-04 15:21 ` [PATCH v4 06/15] coresight: etm4x: Remove redundant condition checks in save and restore Leo Yan
2025-11-04 15:21 ` [PATCH v4 07/15] coresight: syscfg: Use spinlock to protect active variables Leo Yan
2025-11-10 11:09 ` James Clark
2025-11-04 15:21 ` [PATCH v4 08/15] coresight: Introduce coresight_enable_source() helper Leo Yan
2025-11-10 11:09 ` James Clark
2025-11-04 15:21 ` [PATCH v4 09/15] coresight: Save activated path into source device Leo Yan
2025-11-10 11:18 ` James Clark
2025-11-17 14:19 ` Leo Yan
2025-11-10 12:29 ` James Clark
2025-11-11 14:10 ` Suzuki K Poulose
2025-11-17 15:16 ` Leo Yan
2025-11-04 15:21 ` [PATCH v4 10/15] coresight: Add 'in_idle' argument to enable/disable path functions Leo Yan
2025-11-10 11:25 ` James Clark
2025-11-10 11:48 ` James Clark
2025-11-18 9:25 ` Leo Yan
2025-11-04 15:21 ` [PATCH v4 11/15] coresight: Control path during CPU idle Leo Yan
2025-11-10 11:44 ` James Clark
2025-11-04 15:21 ` [PATCH v4 12/15] coresight: Add PM callbacks for percpu sink Leo Yan
2025-11-04 15:21 ` [PATCH v4 13/15] coresight: trbe: Save and restore state across CPU low power state Leo Yan
2025-11-10 12:01 ` James Clark
2025-11-11 14:16 ` Suzuki K Poulose [this message]
2025-11-04 15:21 ` [PATCH v4 14/15] coresight: Take hotplug lock in enable_source_store() for Sysfs mode Leo Yan
2025-11-04 15:21 ` [PATCH v4 15/15] coresight: Move CPU hotplug callbacks to core layer Leo Yan
2025-11-10 12:20 ` James Clark
2025-11-19 14:48 ` Leo Yan
2025-11-19 15:19 ` James Clark
2025-11-19 15:36 ` Leo Yan
2025-11-19 15:41 ` James Clark
2025-11-10 15:33 ` [PATCH v4 00/15] CoreSight: Refactor power management for CoreSight path James Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b9ecd05c-094a-42d3-83fd-27d73a4713ee@arm.com \
--to=suzuki.poulose@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=james.clark@linaro.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mike.leach@linaro.org \
--cc=quic_yuanfang@quicinc.com \
--cc=yabinc@google.com \
--cc=yeoreum.yun@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.