From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
To: Cristian Marussi <cristian.marussi@arm.com>
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
linux-doc@vger.kernel.org, sudeep.holla@kernel.org,
james.quinlan@broadcom.com, f.fainelli@gmail.com,
vincent.guittot@linaro.org, etienne.carriere@st.com,
peng.fan@oss.nxp.com, michal.simek@amd.com, d-gole@ti.com,
elif.topuz@arm.com, lukasz.luba@arm.com, philip.radford@arm.com,
david@kernel.org, souvik.chakravarty@arm.com, leitao@kernel.org,
kas@kernel.org, puranjay@kernel.org, usama.arif@linux.dev,
kernel-team@meta.com
Subject: Re: [PATCH v15 18/35] firmware: arm_scmi: Add Telemetry DataEvent read capabilities
Date: Tue, 10 Nov 2026 13:59:01 -0800 [thread overview]
Message-ID: <20261110135901.00002e53@oss.qualcomm.com> (raw)
In-Reply-To: <20261109091221.2532706-19-cristian.marussi@arm.com>
On Mon, 9 Nov 2026 09:12:04 +0000
Cristian Marussi <cristian.marussi@arm.com> wrote:
> Add support for Telemetry operations needed to read DataEvent values and
> timestamps as single entities or all together in a single bulk buffer.
> The returned values are effectiely retrieved from the platform only
> when strictly needed, i.e. when no fresh recent cached value was already
> available.
> The DataEvent values are fetched transparently from the platform origins
> using the proper synchronization and consistency primitives, directly from
> the SHMTIs areas or the FastChannels memory depending on the configuration.
>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
As far as I can spot there is nothing stopping you introducing the
struct scmi_telemetry_de_sample much earlier in the set and reducing
the churn here. Does looks like it would be too bad to do so
I'd suggest you do so.
> ---
> drivers/firmware/arm_scmi/telemetry.c | 678 ++++++++++++++++++++++++--
> include/linux/scmi_protocol.h | 24 +
> 2 files changed, 666 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/firmware/arm_scmi/telemetry.c b/drivers/firmware/arm_scmi/telemetry.c
> index 1f6505fff199..bf37faf99865 100644
> --- a/drivers/firmware/arm_scmi/telemetry.c
> +++ b/drivers/firmware/arm_scmi/telemetry.c
> @@ -695,8 +707,9 @@ scmi_telemetry_tde_cache_stale(struct telemetry_de *tde, u32 magic)
> }
>
> static void
> -scmi_telemetry_tde_cache_update(struct telemetry_de *tde, u64 val,
> - u64 *tstamp, u32 *magic)
> +scmi_telemetry_tde_cache_update(struct telemetry_de *tde,
> + struct scmi_telemetry_de_sample *sample,
Better to push this back to the patch that introduced this function. I don't
think it does any harm to always use the structure for passing in the
val and tstamp. Do this earlier will reduce churn here and doesn't
look that painful to do.
> + u32 *magic)
> {
> lockdep_assert_held(&tde->mtx);
>
> @@ -708,10 +721,37 @@ scmi_telemetry_tde_cache_update(struct telemetry_de *tde, u64 val,
> return;
>
> tde->last_magic = magic ? *magic : TDCF_BAD_END_SEQ;
> - tde->last_val = val;
> - tde->last_ts = tstamp && scmi_tde_has_tstamp(tde) ? *tstamp : 0;
> - if (tstamp)
> - *tstamp = tde->last_ts;
> + tde->last_val = sample->val;
> + tde->last_ts = scmi_tde_has_tstamp(tde) ? sample->tstamp : 0;
> + /* Update returned value too */
> + sample->tstamp = tde->last_ts;
This is currently rather circular. I guess the aim is to squash
any stale timestamps. Probably want a comment about that.
> +
> + trace_scmi_tlm_collect(tde->last_ts, tde->de.info->id,
> + tde->last_val, "CACHED_DE_UPDATED");
> +}
> +
> +static int
> +scmi_telemetry_tde_cache_lookup(struct telemetry_de *tde,
> + struct scmi_telemetry_de_sample *sample,
> + u32 *magic)
> +{
> + lockdep_assert_held(&tde->mtx);
> +
> + /*
> + * Bailout without providing any sample when the cache is
> + * stale, i.e. last_magic < *magic
Short line wrap.
> + */
> + if (magic && scmi_telemetry_tde_cache_stale(tde, *magic))
> + return -EAGAIN;
> +
> + sample->id = tde->de.info->id;
> + sample->val = tde->last_val;
> + sample->tstamp = tde->last_ts;
sample = (struct scmi_telemetry_de_sample) {
.id = tde.info->id,
.val = tde->last_val,
.tstamp = tde->last_ts,
};
perhaps so it is clear we are setting it all (clearing the padding
seems fine anyway...
> +
> + trace_scmi_tlm_collect(sample->tstamp, sample->id,
> + sample->val, "CACHED_DE_READ");
> +
> + return 0;
> }
>
> struct scmi_tlm_de_priv {
> @@ -2068,45 +2108,45 @@ scmi_telemetry_tde_allocate(struct telemetry_info *ti, u32 de_id,
>
> static inline int
> scmi_telemetry_line_data_parse(struct telemetry_de *tde, struct shmti_snap *snap,
> - u64 *val, u64 *tstamp, struct payload *payld,
> - struct payload *bts_payld, u32 magic)
> + struct scmi_telemetry_de_sample *sample,
Similar to above. Maybe makes sense to push the existence of the structure earlier
in the patch set to avoid churn at this point.
> + struct payload *payld, struct payload *bts_payld,
> + u32 magic)
> {
> u32 meta = PAYLD_META_RAW(payld);
>
> lockdep_assert_held(&tde->mtx);
>
> /* Clear returned values in case of errors */
> - *val = 0;
> -
> - if (tstamp) {
> - *tstamp = 0;
> - if (USE_BLK_TS_RAW(meta)) {
> - /* Read out the actual BLK_TS */
> - *tstamp = scmi_telemetry_blkts_read(magic, tde,
> - bts_payld, snap);
> - } else if (LINE_TS_VALID_RAW(meta)) {
> - /*
> - * Note that LINE_TS_VALID implies HAS_LINE_EXT and that
> - * the per DE line_ts_rate is advertised in the DE
> - * descriptor, BUT we check anyway against buggy FW.
> - */
> - if (!HAS_LINE_EXT_RAW(meta)) {
> - trace_scmi_tlm_access(tde->de.info->id,
> - "SHMTI_BAD_TS_LINE", 0, 0);
> - return -EPROTO;
> - }
> -
> - *tstamp = LINE_TSTAMP_GET_RAW(&payld->tsl);
> + sample->tstamp = 0;
> + sample->val = 0;
If we are clearing for errors, then maybe do the whole thing?
Generally I'd hope we never use values in error paths and the
clearing is unnecessary but if doing it seems like doing it general
makes most sense.
> +
> + if (USE_BLK_TS_RAW(meta)) {
> + /* Read out the actual BLK_TS */
> + sample->tstamp = scmi_telemetry_blkts_read(magic, tde,
> + bts_payld, snap);
> + } else if (LINE_TS_VALID_RAW(meta)) {
> + /*
> + * Note that LINE_TS_VALID implies HAS_LINE_EXT and that
> + * the per DE line_ts_rate is advertised in the DE
> + * descriptor, BUT we check anyway against buggy FW.
> + */
> + if (!HAS_LINE_EXT_RAW(meta)) {
> + trace_scmi_tlm_access(tde->de.info->id,
> + "SHMTI_BAD_TS_LINE", 0, 0);
> + return -EPROTO;
> }
> +
> + sample->tstamp = LINE_TSTAMP_GET_RAW(&payld->tsl);
> }
>
> /* Data is always valid since we are NOT handling BLK TS lines here */
> - *val = LINE_DATA_GET_RAW(&payld->l);
> + sample->val = LINE_DATA_GET_RAW(&payld->l);
>
> - trace_scmi_tlm_collect(tstamp ? *tstamp : 0, tde->de.info->id,
> - *val, "SHMTI_DE_READ");
> + /* Trace originally read tstamp */
> + trace_scmi_tlm_collect(sample->tstamp, tde->de.info->id,
> + sample->val, "SHMTI_DE_READ");
>
> - scmi_telemetry_tde_cache_update(tde, *val, tstamp, &magic);
> + scmi_telemetry_tde_cache_update(tde, sample, &magic);
>
> return 0;
> }
>
> +
> +static int scmi_telemetry_des_sample_get(const struct scmi_protocol_handle *ph,
> + int grp_id, unsigned int *num_samples,
> + struct scmi_telemetry_de_sample *samples)
> +{
> + struct telemetry_info *ti = ph->get_priv(ph);
> + struct scmi_msg_telemetry_config_set *msg;
> + struct scmi_xfer *t;
> + bool is_group;
> + u32 control;
> + int ret;
I guess it is prevented at a higher level, but perhaps some indication
of this one not needing to take the config_mtx and why would be helpful.
It's not locally obvious why other config messages can race with each
other to need the defense on those config_set calls but not this one.
> +
> + if (!ti->info.enabled || !num_samples || !samples ||
> + !ti->info.single_read_support)
> + return -EINVAL;
> +
> + is_group = grp_id != SCMI_TLM_GRP_INVALID;
> + if (is_group && grp_id >= ti->info.base.num_groups)
> + return -EINVAL;
> +
> + ret = ph->xops->xfer_get_init(ph, TELEMETRY_CONFIG_SET,
> + sizeof(*msg), 0, &t);
> + if (ret)
> + return ret;
> +
> + msg = t->tx.buf;
> + msg->group_identifier = cpu_to_le32(grp_id);
> + control = TELEMETRY_ENABLE;
> + control |= !is_group ? TELEMETRY_SET_SELECTOR_ALL :
> + TELEMETRY_SET_SELECTOR_GROUP;
> + control |= TELEMETRY_MODE_SINGLE;
Similar to earlier. I think this would be a lot more readable as appropriate
FIELD_PREP()
> + msg->control = cpu_to_le32(control);
> + msg->sampling_rate = 0;
> +
> + ret = ph->xops->do_xfer_with_response(ph, t);
> + /*
> + * PARTIAL_ERRORs are reported as -EBADMSG and related lines,
> + * marked as DATA_INVALID, will be properly skipped by
> + * scmi_telemetry_msg_payld_process.
> + */
> + if (!ret || ret == -EBADMSG) {
> + struct scmi_msg_resp_telemetry_reading_complete *r = t->rx.buf;
> + u32 num_dwords;
> +
> + if (ret == -EBADMSG)
> + trace_scmi_tlm_access(0, "BAD_SAMPLE_PARTIAL_ERROR", 0, 0);
> +
> + if (t->rx.len < sizeof(*r))
> + return -EPROTO;
> +
> + num_dwords = le32_to_cpu(r->num_dwords);
> + /* Update cached DEs values from payload */
> + if (num_dwords) {
> + size_t payld_sz = 0, dwords_sz;
> +
> + if (check_mul_overflow(num_dwords, sizeof(r->array[0]), &dwords_sz) ||
> + check_add_overflow(sizeof(*r), dwords_sz, &payld_sz) ||
> + payld_sz > t->rx.len) {
> + dev_err(ph->dev,
> + "Malformed Telemetry delayed response - num_dwords:%u payld_sz:%zd rx_len:%zd\n",
> + num_dwords, payld_sz, t->rx.len);
> + ret = -EPROTO;
> + goto out;
> + }
> +
> + scmi_telemetry_msg_payld_process(ti, num_dwords, r->array,
> + payld_sz - sizeof(*r), false);
> + }
> +
> + /* Scan and update SMHTIs and FCs */
> + scmi_telemetry_scan_update(ti);
> +
> + /* Collect all last cached values, override any PARTIAL_ERROR */
> + ret = scmi_telemetry_samples_collect(ti, grp_id, num_samples,
> + samples);
> + }
> +
> +out:
> + ph->xops->xfer_put(ph, t);
> +
> + return ret;
> +}
;
>
> /**
> diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
> index ce35734d2249..7177f739f062 100644
> --- a/include/linux/scmi_protocol.h
> +++ b/include/linux/scmi_protocol.h
> @@ -994,6 +994,13 @@ struct scmi_telemetry_info {
> enum scmi_telemetry_collection current_mode;
> };
>
> +struct scmi_telemetry_de_sample {
> + unsigned int id;
> + unsigned int pad;
> + unsigned long long tstamp;
> + unsigned long long val;
Why not the fixed size kernel types?
> +};
next prev parent reply other threads:[~2026-11-10 21:59 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 9:11 [PATCH v15 00/35] Introduce SCMI Telemetry support Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 01/35] firmware: arm_scmi: Harden iterators state parsing Cristian Marussi
2026-11-09 21:57 ` Jonathan Cameron
2026-11-10 8:19 ` Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 02/35] firmware: arm_scmi: Add new SCMIv4.0 error codes definitions Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 03/35] firmware: arm_scmi: Introduce a dedicated SCMI Errors header Cristian Marussi
2026-11-09 22:01 ` Jonathan Cameron
2026-11-10 8:23 ` Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 04/35] firmware: arm_scmi: Allow registration of unknown-size events/reports Cristian Marussi
2026-11-09 22:07 ` Jonathan Cameron
2026-11-10 8:27 ` Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 05/35] firmware: arm_scmi: Refactor __scmi_event_handler_get_ops helper Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 06/35] firmware: arm_scmi: Introduce protocol instance notifiers Cristian Marussi
2026-11-09 23:32 ` Jonathan Cameron
2026-11-09 9:11 ` [PATCH v15 07/35] dt-bindings: firmware: arm,scmi: Add support for telemetry protocol Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 08/35] include: trace: Add Telemetry trace events Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 09/35] firmware: arm_scmi: Add Telemetry basic attributes enumeration Cristian Marussi
2026-11-09 23:57 ` Jonathan Cameron
2026-11-09 9:11 ` [PATCH v15 10/35] firmware: arm_scmi: Add Telemetry resources enumeration Cristian Marussi
2026-11-10 1:36 ` Jonathan Cameron
2026-11-10 15:33 ` Cristian Marussi
2026-11-09 9:11 ` [PATCH v15 11/35] firmware: arm_scmi: Add Telemetry groups initialization Cristian Marussi
2026-11-10 1:53 ` Jonathan Cameron
2026-11-09 9:11 ` [PATCH v15 12/35] firmware: arm_scmi: Add Telemetry update intervals enumeration Cristian Marussi
2026-11-10 2:07 ` Jonathan Cameron
2026-11-09 9:11 ` [PATCH v15 13/35] firmware: arm_scmi: Add Telemetry SHMTI areas enumeration Cristian Marussi
2026-11-10 2:26 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 14/35] firmware: arm_scmi: Add Telemetry TDCF areas parsing support Cristian Marussi
2026-11-10 18:15 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 15/35] firmware: arm_scmi: Add Telemetry TDCF parsing for BLK_TS lines Cristian Marussi
2026-11-10 18:33 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 16/35] firmware: arm_scmi: Add Telemetry TDCF parsing for UUID lines Cristian Marussi
2026-11-10 18:49 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 17/35] firmware: arm_scmi: Add Telemetry configuration operations Cristian Marussi
2026-11-10 20:07 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 18/35] firmware: arm_scmi: Add Telemetry DataEvent read capabilities Cristian Marussi
2026-11-10 21:59 ` Jonathan Cameron [this message]
2026-11-09 9:12 ` [PATCH v15 19/35] firmware: arm_scmi: Add Telemetry reset logic Cristian Marussi
2026-11-10 22:07 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 20/35] firmware: arm_scmi: Add Telemetry notification support Cristian Marussi
2026-11-10 22:16 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 21/35] firmware: arm_scmi: Add Telemetry boot-on support Cristian Marussi
2026-11-10 22:25 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 22/35] firmware: arm-scmi: Add Telemetry generic event support Cristian Marussi
2026-11-10 22:33 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 23/35] firmware: arm_scmi: Add Telemetry generation counter event Cristian Marussi
2026-11-10 22:46 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 24/35] firmware: arm_scmi: Add common per-protocol debugfs support Cristian Marussi
2026-11-10 22:50 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 25/35] firmware: arm_scmi: Add Telemetry debugfs SHMTI dump support Cristian Marussi
2026-11-10 22:54 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 26/35] firmware: arm_scmi: Add Telemetry debugfs ABI documentation Cristian Marussi
2026-11-10 22:55 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 27/35] firmware: arm_scmi: Expose per-instance identifier Cristian Marussi
2026-11-10 22:57 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 28/35] firmware: arm_scmi: Add un-managed methods to get/put protocols operations Cristian Marussi
2026-11-10 23:01 ` Jonathan Cameron
2026-11-10 23:18 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 29/35] uapi: Add ARM SCMI Telemetry definitions Cristian Marussi
2026-11-10 23:13 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 30/35] firmware: arm_scmi: Add System Telemetry driver Cristian Marussi
2026-11-10 23:46 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 31/35] firmware: arm_scmi: Enable autoloading for " Cristian Marussi
2026-11-09 9:12 ` [PATCH v15 32/35] docs: ioctl-number: Add SCMI Ioctls Cristian Marussi
2026-11-09 9:12 ` [PATCH v15 33/35] Documentation: Add SCMI System Telemetry documentation Cristian Marussi
2026-11-10 23:54 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 34/35] [RFC] kselftest/arm64: Add SCMI Telemetry UAPI compliance testcases Cristian Marussi
2026-11-11 0:13 ` Jonathan Cameron
2026-11-09 9:12 ` [PATCH v15 35/35] [RFC] tools/testing/scmi: Add SCMI Telemetry testing tool Cristian Marussi
2026-11-11 0:16 ` Jonathan Cameron
2026-11-11 0:38 ` [PATCH v15 00/35] Introduce SCMI Telemetry support Jonathan Cameron
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=20261110135901.00002e53@oss.qualcomm.com \
--to=jonathan.cameron@oss.qualcomm.com \
--cc=arm-scmi@vger.kernel.org \
--cc=cristian.marussi@arm.com \
--cc=d-gole@ti.com \
--cc=david@kernel.org \
--cc=elif.topuz@arm.com \
--cc=etienne.carriere@st.com \
--cc=f.fainelli@gmail.com \
--cc=james.quinlan@broadcom.com \
--cc=kas@kernel.org \
--cc=kernel-team@meta.com \
--cc=leitao@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=michal.simek@amd.com \
--cc=peng.fan@oss.nxp.com \
--cc=philip.radford@arm.com \
--cc=puranjay@kernel.org \
--cc=souvik.chakravarty@arm.com \
--cc=sudeep.holla@kernel.org \
--cc=usama.arif@linux.dev \
--cc=vincent.guittot@linaro.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®