From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: <intel-xe@lists.freedesktop.org>, <kernel-dev@igalia.com>,
Matthew Brost <matthew.brost@intel.com>,
Thomas Hellstrom <thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH v2] drm/xe: Assign queue name in time for drm_sched_init
Date: Tue, 26 May 2026 15:31:06 -0400 [thread overview]
Message-ID: <ahX0-lRU99pynQDa@intel.com> (raw)
In-Reply-To: <20260523103418.61832-1-tvrtko.ursulin@igalia.com>
On Sat, May 23, 2026 at 11:34:18AM +0100, Tvrtko Ursulin wrote:
> Currently the queue name is only assigned after the drm scheduler instance
> has been created. This loses information with all logging or debug
> workqueue facilities so lets re-order things a bit so the name gets
> assigned in time.
>
> To be able to assign a GuC ID early we split the allocation into
> reservation and publish phases.
>
> First, with the submission state lock held, we reserve the ID in the GuC
> ID manager, which serves as an authoritative source of truth. Then we can
> drop the lock and reserve entries in the exec queue lookup XArray. This
> can be lockless since the NULL entries are invisible both to the kernel
> and userspace. Only after the queue has been fully created we replace the
> reserved entries with the queue pointer, which can be done locklessly for
> single width queues.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Thomas Hellstrom <thomas.hellstrom@linux.intel.com>
> ---
> v2:
> * Split the id allocation into reserve and publish. (Rodrigo)
Thank you
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
pushing right now...
> ---
> drivers/gpu/drm/xe/xe_guc_submit.c | 72 +++++++++++++++++-------------
> 1 file changed, 40 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
> index afd8cc7bd231..ab501513d806 100644
> --- a/drivers/gpu/drm/xe/xe_guc_submit.c
> +++ b/drivers/gpu/drm/xe/xe_guc_submit.c
> @@ -408,46 +408,43 @@ void xe_guc_submit_disable(struct xe_guc *guc)
> guc->submission_state.enabled = false;
> }
>
> -static void __release_guc_id(struct xe_guc *guc, struct xe_exec_queue *q, u32 xa_count)
> +static void __release_guc_id(struct xe_guc *guc, struct xe_exec_queue *q,
> + int count)
> {
> int i;
>
> - lockdep_assert_held(&guc->submission_state.lock);
> + mutex_lock(&guc->submission_state.lock);
>
> - for (i = 0; i < xa_count; ++i)
> - xa_erase(&guc->submission_state.exec_queue_lookup, q->guc->id + i);
> + for (i = 0; i < count; ++i)
> + xa_erase(&guc->submission_state.exec_queue_lookup,
> + q->guc->id + i);
>
> xe_guc_id_mgr_release_locked(&guc->submission_state.idm,
> q->guc->id, q->width);
>
> if (xa_empty(&guc->submission_state.exec_queue_lookup))
> wake_up(&guc->submission_state.fini_wq);
> +
> + mutex_unlock(&guc->submission_state.lock);
> }
>
> static int alloc_guc_id(struct xe_guc *guc, struct xe_exec_queue *q)
> {
> - int ret;
> - int i;
> -
> - /*
> - * Must use GFP_NOWAIT as this lock is in the dma fence signalling path,
> - * worse case user gets -ENOMEM on engine create and has to try again.
> - *
> - * FIXME: Have caller pre-alloc or post-alloc /w GFP_KERNEL to prevent
> - * failure.
> - */
> - lockdep_assert_held(&guc->submission_state.lock);
> + int ret, i;
>
> + mutex_lock(&guc->submission_state.lock);
> ret = xe_guc_id_mgr_reserve_locked(&guc->submission_state.idm,
> q->width);
> + mutex_unlock(&guc->submission_state.lock);
> if (ret < 0)
> return ret;
>
> q->guc->id = ret;
>
> + /* Reserve empty slots. */
> for (i = 0; i < q->width; ++i) {
> - ret = xa_err(xa_store(&guc->submission_state.exec_queue_lookup,
> - q->guc->id + i, q, GFP_NOWAIT));
> + ret = xa_insert(&guc->submission_state.exec_queue_lookup,
> + q->guc->id + i, NULL, GFP_KERNEL);
> if (ret)
> goto err_release;
> }
> @@ -460,11 +457,24 @@ static int alloc_guc_id(struct xe_guc *guc, struct xe_exec_queue *q)
> return ret;
> }
>
> +static void publish_guc_id(struct xe_guc *guc, struct xe_exec_queue *q)
> +{
> + int i;
> +
> + lockdep_assert_held(&guc->submission_state.lock);
> +
> + for (i = 0; i < q->width; ++i) {
> + void *old;
> +
> + old = xa_store(&guc->submission_state.exec_queue_lookup,
> + q->guc->id + i, q, GFP_NOWAIT);
> + XE_WARN_ON(old || xa_is_err(old));
> + }
> +}
> +
> static void release_guc_id(struct xe_guc *guc, struct xe_exec_queue *q)
> {
> - mutex_lock(&guc->submission_state.lock);
> __release_guc_id(guc, q, q->width);
> - mutex_unlock(&guc->submission_state.lock);
> }
>
> struct exec_queue_policy {
> @@ -1961,6 +1971,12 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
> timeout = (q->vm && xe_vm_in_lr_mode(q->vm)) ? MAX_SCHEDULE_TIMEOUT :
> msecs_to_jiffies(q->sched_props.job_timeout_ms);
>
> + err = alloc_guc_id(guc, q);
> + if (err)
> + goto err_free;
> +
> + xe_exec_queue_assign_name(q, q->guc->id);
> +
> /*
> * Use primary queue's submit_wq for all secondary queues of a
> * multi queue group. This serialization avoids any locking around
> @@ -1977,28 +1993,21 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
> timeout, guc_to_gt(guc)->ordered_wq, NULL,
> q->name, gt_to_xe(q->gt)->drm.dev);
> if (err)
> - goto err_free;
> + goto err_release_id;
>
> sched = &ge->sched;
> err = xe_sched_entity_init(&ge->entity, sched);
> if (err)
> goto err_sched;
>
> - mutex_lock(&guc->submission_state.lock);
> -
> - err = alloc_guc_id(guc, q);
> - if (err)
> - goto err_entity;
> -
> q->entity = &ge->entity;
>
> + mutex_lock(&guc->submission_state.lock);
> if (xe_guc_read_stopped(guc) || vf_recovery(guc))
> xe_sched_stop(sched);
> -
> + publish_guc_id(guc, q);
> mutex_unlock(&guc->submission_state.lock);
>
> - xe_exec_queue_assign_name(q, q->guc->id);
> -
> /*
> * Maintain secondary queues of the multi queue group in a list
> * for handling dependencies across the queues in the group.
> @@ -2021,11 +2030,10 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
>
> return 0;
>
> -err_entity:
> - mutex_unlock(&guc->submission_state.lock);
> - xe_sched_entity_fini(&ge->entity);
> err_sched:
> xe_sched_fini(&ge->sched);
> +err_release_id:
> + release_guc_id(guc, q);
> err_free:
> kfree(ge);
>
> --
> 2.54.0
>
prev parent reply other threads:[~2026-05-26 19:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 10:34 [PATCH v2] drm/xe: Assign queue name in time for drm_sched_init Tvrtko Ursulin
2026-05-23 10:39 ` ✗ CI.checkpatch: warning for drm/xe: Assign queue name in time for drm_sched_init (rev2) Patchwork
2026-05-23 10:41 ` ✓ CI.KUnit: success " Patchwork
2026-05-23 11:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-05-23 12:24 ` ✓ Xe.CI.FULL: " Patchwork
2026-05-26 19:31 ` Rodrigo Vivi [this message]
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=ahX0-lRU99pynQDa@intel.com \
--to=rodrigo.vivi@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=kernel-dev@igalia.com \
--cc=matthew.brost@intel.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tvrtko.ursulin@igalia.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