From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Karthik Poosa <karthik.poosa@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <anshuman.gupta@intel.com>,
<badal.nilawar@intel.com>, <raag.jadav@intel.com>,
<riana.tauro@intel.com>, <sk.anirban@intel.com>,
<mallesh.koujalagi@intel.com>, <soham.purkait@intel.com>,
<ravi.kishore.koppuravuri@intel.com>
Subject: Re: [PATCH v6 03/10] drm/xe/pcode: Add ordered write batch helper
Date: Mon, 30 Nov 2026 15:59:42 -0500 [thread overview]
Message-ID: <aw3jvirGsZ1cyzYe@intel.com> (raw)
In-Reply-To: <20261130185050.36979-4-karthik.poosa@intel.com>
On Tue, Dec 01, 2026 at 12:20:43AM +0530, Karthik Poosa wrote:
> Add a pcode helper that issues an ordered sequence of mailbox writes
> while holding the pcode lock, so no other mailbox command can be
> interleaved.
>
> Some pcode interfaces keep state across mailbox commands. A fan table is
> written one point at a time with FSC_WRITE_FAN_TABLE and loaded by a
> final FSC_WRITE_NUM_FAN_CONTROL_POINTS write. pcode does not tie the
> staged points to a requester, so fan table writes from another caller
> in the middle of the sequence can be merged into it, and the commit then
> either fails with illegal data or loads a wrong table.
>
> Serialize all fan control table writes, for every fan, on the pcode
> lock rather than per fan. Caller-side locks such as the hwmon lock only
> order callers that take them; the pcode lock orders every mailbox user
> in the driver.
>
> Lock hold time is the sum of the pcode response times of the batch. Each
> write is bounded by PCODE_DEFAULT_TIMEOUT_MS, and a write that times out
> ends the batch, so the worst case is count * PCODE_DEFAULT_TIMEOUT_MS
> (110 ms for the largest fan table of 10 points plus the count write).
> Other pcode users wait on the lock with mutex_lock() and start their own
> mailbox timeout only after acquiring it, so a batch delays them but does
> not make them time out. This is in line with existing pcode lock users:
> xe_pcode_request() holds the lock for up to its base timeout plus 50 ms,
> and xe_pcode_init_min_freq_table() holds it across a loop of writes.
>
> This will be used to write fan tables atomically with respect to other
> pcode users.
>
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
>
> v2:
> - Explain why pcode needs the writes without interleaving, and the
> lock hold time impact on other pcode users. (sashiko)
>
> drivers/gpu/drm/xe/xe_pcode.c | 49 +++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_pcode.h | 12 +++++++++
> 2 files changed, 61 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_pcode.c b/drivers/gpu/drm/xe/xe_pcode.c
> index fa9f45d565cb..f465decbf946 100644
> --- a/drivers/gpu/drm/xe/xe_pcode.c
> +++ b/drivers/gpu/drm/xe/xe_pcode.c
> @@ -124,6 +124,55 @@ int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeout
> return err;
> }
>
> +/**
> + * xe_pcode_write_batch - issue pcode writes in order under the mailbox lock
> + * @tile: tile
> + * @writes: mailbox/data pairs to write
> + * @count: number of entries in @writes
> + *
> + * Some pcode interfaces keep state across mailbox commands; e.g. a fan table
> + * is written point by point and loaded by a final point count write. Holding
> + * the pcode lock across all writes keeps each such sequence atomic with
> + * respect to every other mailbox user, including fan table writes for any
> + * other fan, independent of caller-side locks.
> + *
> + * The lock is held for the sum of the pcode response times, bounded by
> + * @count * PCODE_DEFAULT_TIMEOUT_MS; a write that times out ends the batch.
> + * Other pcode users sleep on the lock and start their own mailbox timeout only
> + * once they own it, so they are delayed but do not time out. Keep @count small.
> + *
> + * Stops at the first failure; earlier writes are not reverted.
> + *
> + * Context: Process context. Takes and releases the pcode lock.
> + * Return: 0 on success, negative error code otherwise.
> + */
> +int xe_pcode_write_batch(struct xe_tile *tile, const struct xe_pcode_write *writes,
> + unsigned int count)
> +{
> + unsigned int i;
> + int err = 0;
> +
> + if (!count)
> + return -EINVAL;
> +
> + mutex_lock(&tile->pcode.lock);
> + for (i = 0; i < count; i++) {
> + u32 data = writes[i].data;
> +
> + err = pcode_mailbox_rw(tile, writes[i].mbox, &data, NULL, PCODE_DEFAULT_TIMEOUT_MS,
> + false, false);
> + if (err) {
> + xe_err(tile_to_xe(tile),
> + "pcode batch write %u/%u failed: mbox 0x%08x data 0x%08x, ret %pe\n",
> + i + 1, count, writes[i].mbox, writes[i].data, ERR_PTR(err));
> + break;
> + }
> + }
> + mutex_unlock(&tile->pcode.lock);
> +
> + return err;
> +}
> +
> int xe_pcode_write64_timeout(struct xe_tile *tile, u32 mbox, u32 data0, u32 data1, int timeout)
> {
> int err;
> diff --git a/drivers/gpu/drm/xe/xe_pcode.h b/drivers/gpu/drm/xe/xe_pcode.h
> index 7e43792b0037..c601a12baba6 100644
> --- a/drivers/gpu/drm/xe/xe_pcode.h
> +++ b/drivers/gpu/drm/xe/xe_pcode.h
> @@ -18,6 +18,16 @@ struct xe_pcode_version {
> u32 engg;
> };
>
> +/**
> + * struct xe_pcode_write - single pcode mailbox write
> + * @mbox: mailbox command
> + * @data: value written to PCODE_DATA0
> + */
> +struct xe_pcode_write {
> + u32 mbox;
> + u32 data;
> +};
> +
> #define PCODE_DEFAULT_TIMEOUT_MS 10
>
> int xe_pcode_init_early(struct xe_tile *tile);
> @@ -28,6 +38,8 @@ int xe_pcode_init_min_freq_table(struct xe_tile *tile, u32 min_gt_freq,
> int xe_pcode_read(struct xe_tile *tile, u32 mbox, u32 *val0, u32 *val1);
> int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 val,
> int timeout_ms);
> +int xe_pcode_write_batch(struct xe_tile *tile, const struct xe_pcode_write *writes,
> + unsigned int count);
> int xe_pcode_write64_timeout(struct xe_tile *tile, u32 mbox, u32 data0,
> u32 data1, int timeout);
> int xe_get_pcode_version(struct xe_device *xe, struct xe_pcode_version *version);
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-11-30 21:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 18:50 [PATCH v6 00/10] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-11-30 19:04 ` sashiko-bot
2026-11-30 18:50 ` [PATCH v6 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-11-30 20:59 ` Rodrigo Vivi [this message]
2026-11-30 18:50 ` [PATCH v6 04/10] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-11-30 21:00 ` Rodrigo Vivi
2026-11-30 18:50 ` [PATCH v6 07/10] drm/xe/hwmon: Restore fan user tables after resume Karthik Poosa
2026-11-30 21:03 ` Rodrigo Vivi
2026-11-30 18:50 ` [PATCH v6 08/10] drm/xe/hwmon: Refresh fan data after late binding Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 09/10] drm/xe: Expose tjmax_fan_control_enable device sysfs Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 10/10] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
2026-11-30 21:04 ` Rodrigo Vivi
2026-11-30 20:52 ` ✓ CI.KUnit: success for drm/xe/hwmon: Add fan control support (rev3) Patchwork
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=aw3jvirGsZ1cyzYe@intel.com \
--to=rodrigo.vivi@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=badal.nilawar@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=karthik.poosa@intel.com \
--cc=mallesh.koujalagi@intel.com \
--cc=raag.jadav@intel.com \
--cc=ravi.kishore.koppuravuri@intel.com \
--cc=riana.tauro@intel.com \
--cc=sk.anirban@intel.com \
--cc=soham.purkait@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox