Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Charles <daniel.charles@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: x.wang@intel.com, jia.yao@intel.com, matthew.brost@intel.com,
	jonathan.cavitt@intel.com,
	Daniel Charles <daniel.charles@intel.com>
Subject: [PATCH v5 2/4] drm/xe: Notify scheduling-state waiters per exec queue
Date: Wed, 18 Nov 2026 16:04:44 -0800	[thread overview]
Message-ID: <20261119000446.696147-3-daniel.charles@intel.com> (raw)
In-Reply-To: <20261119000446.696147-1-daniel.charles@intel.com>

Wait for GuC scheduling state changes on the exec queue whose state is
being inspected. Wake its waiters after processing SCHED_DONE instead
of relying on a CT interrupt that can wake them before state changes.
Keep the existing CT notifications for their remaining users.

On submission stop, wedge and VF recovery, notify published queues.
Hold the lookup XArray lock with interrupts saved to prevent queue
removal during the walk, and skip parallel queue aliases.

v5: New prerequisite for early KILL and FD-close waits.
Signed-off-by: Daniel Charles <daniel.charles@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_sriov_vf.c          |  1 +
 drivers/gpu/drm/xe/xe_guc_exec_queue_types.h |  2 +
 drivers/gpu/drm/xe/xe_guc_submit.c           | 39 +++++++++++++++++---
 drivers/gpu/drm/xe/xe_guc_submit.h           |  1 +
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_vf.c b/drivers/gpu/drm/xe/xe_gt_sriov_vf.c
index 37899fcf5b227..fc853c195fdb8 100644
--- a/drivers/gpu/drm/xe/xe_gt_sriov_vf.c
+++ b/drivers/gpu/drm/xe/xe_gt_sriov_vf.c
@@ -910,6 +910,7 @@ static void vf_start_migration_recovery(struct xe_gt *gt)
 		smp_wmb();	/* Ensure above writes visible before wake */
 
 		xe_guc_ct_wake_waiters(&gt->uc.guc.ct);
+		xe_guc_submit_wake_state_waiters(&gt->uc.guc);
 
 		started = queue_work(gt->ordered_wq, &gt->sriov.vf.migration.worker);
 		xe_gt_sriov_info(gt, "VF migration recovery %s\n", started ?
diff --git a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
index 74b711abe2572..2b1a40e288f17 100644
--- a/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
+++ b/drivers/gpu/drm/xe/xe_guc_exec_queue_types.h
@@ -52,6 +52,8 @@ struct xe_guc_exec_queue {
 	u16 id;
 	/** @suspend_wait: wait queue used to wait on pending suspends */
 	wait_queue_head_t suspend_wait;
+	/** @state_wq: wait queue for scheduling enable/disable state changes */
+	wait_queue_head_t state_wq;
 	/**
 	 * @suspend_pending: a suspend of the exec_queue is pending.
 	 * Protected by @sched.msg_lock.
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
index c4ef3e9bf7a18..a3c2abb9254ff 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -551,6 +551,30 @@ static bool vf_recovery(struct xe_guc *guc)
 	return xe_gt_recovery_pending(guc_to_gt(guc));
 }
 
+/**
+ * xe_guc_submit_wake_state_waiters() - Wake all scheduling-state waiters
+ * @guc: the &xe_guc
+ *
+ * Notify per-queue waiters when a GuC-wide stop or recovery changes their
+ * wait conditions. May be called from interrupt context.
+ */
+void xe_guc_submit_wake_state_waiters(struct xe_guc *guc)
+{
+	struct xarray *lookup = &guc->submission_state.exec_queue_lookup;
+	struct xe_exec_queue *q;
+	unsigned long index, flags;
+
+	if (!guc->submission_state.initialized)
+		return;
+
+	/* Prevent removal and freeing of queues while waking their waiters. */
+	xa_lock_irqsave(lookup, flags);
+	xa_for_each(lookup, index, q)
+		if (q->guc->id == index)
+			wake_up_all(&q->guc->state_wq);
+	xa_unlock_irqrestore(lookup, flags);
+}
+
 static void xe_guc_exec_queue_trigger_cleanup(struct xe_exec_queue *q)
 {
 	struct xe_guc *guc = exec_queue_to_guc(q);
@@ -1372,7 +1396,7 @@ static void disable_scheduling_deregister(struct xe_guc *guc,
 		set_min_preemption_timeout(guc, q);
 
 	smp_rmb();
-	ret = wait_event_timeout(guc->ct.wq,
+	ret = wait_event_timeout(q->guc->state_wq,
 				 (!exec_queue_pending_enable(q) &&
 				  !exec_queue_pending_disable(q)) ||
 					 xe_guc_read_stopped(guc) ||
@@ -1433,6 +1457,7 @@ void xe_guc_submit_wedge(struct xe_guc *guc)
 			if (xe_exec_queue_get_unless_zero(q))
 				set_exec_queue_wedged(q);
 		mutex_unlock(&guc->submission_state.lock);
+		xe_guc_submit_wake_state_waiters(guc);
 	} else {
 		/* Forcefully kill any remaining exec queues, signal fences */
 		guc_submit_reset_prepare(guc);
@@ -1537,7 +1562,7 @@ static void enable_scheduling(struct xe_exec_queue *q)
 		xe_guc_ct_send(&guc->ct, action, ARRAY_SIZE(action),
 			       G2H_LEN_DW_SCHED_CONTEXT_MODE_SET, 1);
 
-	ret = wait_event_timeout(guc->ct.wq,
+	ret = wait_event_timeout(q->guc->state_wq,
 				 !exec_queue_pending_enable(q) ||
 				 xe_guc_read_stopped(guc) ||
 				 vf_recovery(guc), HZ * 5);
@@ -1683,7 +1708,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
 			 * Wait for any pending G2H to flush out before
 			 * modifying state
 			 */
-			ret = wait_event_timeout(guc->ct.wq,
+			ret = wait_event_timeout(primary->guc->state_wq,
 						 (!exec_queue_pending_enable(primary) &&
 						  !exec_queue_pending_disable(primary)) ||
 						 xe_guc_read_stopped(guc) ||
@@ -1705,7 +1730,7 @@ guc_exec_queue_timedout_job(struct drm_sched_job *drm_job)
 		 * lost. If this occurs, trigger a GT reset to recover.
 		 */
 		smp_rmb();
-		ret = wait_event_timeout(guc->ct.wq,
+		ret = wait_event_timeout(primary->guc->state_wq,
 					 !xe_uc_fw_is_running(&guc->fw) ||
 					 !exec_queue_pending_disable(primary) ||
 					 xe_guc_read_stopped(guc) ||
@@ -1980,7 +2005,7 @@ static void __guc_exec_queue_process_msg_suspend(struct xe_sched_msg *msg,
 
 	if (guc_exec_queue_allowed_to_change_state(q) && !exec_queue_suspended(q) &&
 	    exec_queue_enabled(q) && bound) {
-		wait_event(guc->ct.wq, vf_recovery(guc) ||
+		wait_event(q->guc->state_wq, vf_recovery(guc) ||
 			   ((q->guc->resume_time != RESUME_PENDING ||
 			   xe_guc_read_stopped(guc)) && !exec_queue_pending_disable(q)));
 
@@ -2129,6 +2154,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
 	ge->q = q;
 	init_rcu_head(&ge->rcu);
 	init_waitqueue_head(&ge->suspend_wait);
+	init_waitqueue_head(&ge->state_wq);
 
 	for (i = 0; i < MAX_STATIC_MSG_TYPE; ++i)
 		INIT_LIST_HEAD(&ge->static_msgs[i].link);
@@ -2787,6 +2813,7 @@ static int guc_submit_reset_prepare(struct xe_guc *guc)
 	ret = atomic_fetch_or(1, &guc->submission_state.stopped);
 	smp_wmb();
 	wake_up_all(&guc->ct.wq);
+	xe_guc_submit_wake_state_waiters(guc);
 
 	return ret;
 }
@@ -3350,6 +3377,7 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q,
 		clear_exec_queue_pending_enable(q);
 		smp_wmb();
 		wake_up_all(&guc->ct.wq);
+		wake_up_all(&q->guc->state_wq);
 	} else {
 		bool was_pending;
 
@@ -3385,6 +3413,7 @@ static void handle_sched_done(struct xe_guc *guc, struct xe_exec_queue *q,
 				clear_exec_queue_pending_disable(q);
 			}
 		}
+		wake_up_all(&q->guc->state_wq);
 	}
 }
 
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.h b/drivers/gpu/drm/xe/xe_guc_submit.h
index 29abf07d8f041..0749f7c400b63 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.h
+++ b/drivers/gpu/drm/xe/xe_guc_submit.h
@@ -28,6 +28,7 @@ void xe_guc_submit_unpause(struct xe_guc *guc);
 void xe_guc_submit_unpause_vf(struct xe_guc *guc);
 void xe_guc_submit_unpause_prepare_vf(struct xe_guc *guc);
 void xe_guc_submit_wedge(struct xe_guc *guc);
+void xe_guc_submit_wake_state_waiters(struct xe_guc *guc);
 
 int xe_guc_read_stopped(struct xe_guc *guc);
 int xe_guc_sched_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
-- 
2.43.0


  parent reply	other threads:[~2026-11-19  0:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  0:04 [PATCH v5 0/4] FD close cleanup for XE Daniel Charles
2026-11-19  0:04 ` [PATCH v5 1/4] drm/xe: Read scheduler message opcode under lock Daniel Charles
2026-11-19  0:04 ` Daniel Charles [this message]
2026-11-19  0:04 ` [PATCH v5 3/4] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade Daniel Charles
2026-11-19  0:04 ` [PATCH v5 4/4] drm/xe: Synchronously wait for queue kill on FD close Daniel Charles

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=20261119000446.696147-3-daniel.charles@intel.com \
    --to=daniel.charles@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jia.yao@intel.com \
    --cc=jonathan.cavitt@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=x.wang@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