Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Zongyao Bai <zongyao.bai@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v3 2/3] drm/xe/forcewake: flush delayed release at power and teardown boundaries
Date: Mon, 30 Nov 2026 16:50:28 -0500	[thread overview]
Message-ID: <aw3vpMnsONPcn_pf@intel.com> (raw)
In-Reply-To: <20261117002819.535438-3-zongyao.bai@intel.com>

On Tue, Nov 17, 2026 at 12:28:18AM +0000, Zongyao Bai wrote:
> Add xe_force_wake_flush(), which cancels the delayed release work and
> puts the domains it was holding to sleep. Use it, through a scoped class
> that flushes after the final put, in system suspend and runtime suspend,
> before the device is powered off. Delayed release stays enabled for use
> after resume.
> 
> Add xe_force_wake_stop(), which also disables the work for good. Use it
> in GT shutdown, after the reset, and on device removal and
> post-registration probe failure. A put_delay() after the stop puts the
> domain to sleep right away, so nothing is left awake after the stop.
> 

Please add what changed from v2 to v3 somewhere in the patch, then
resend as a new series, not a reply... CI didn't run on this final revision.

But everything looks good to me... I just want to double check on the
changes and ensure CI and sashiko both runs cleanly on that. Then I put
my rv-b and we get this merged.

Sorry for the delay.
Thanks,
Rodrigo.

> Signed-off-by: Zongyao Bai <zongyao.bai@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_device.c           | 11 ++++++
>  drivers/gpu/drm/xe/xe_force_wake.c       | 44 ++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_force_wake.h       | 18 ++++++++++
>  drivers/gpu/drm/xe/xe_force_wake_types.h | 29 ++++++++++++++++
>  drivers/gpu/drm/xe/xe_gt.c               | 10 +++---
>  5 files changed, 108 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index 273e2c45fea9..f6d769900e43 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -897,6 +897,15 @@ static void xe_uid_probe(struct xe_device *xe)
>  		xe->device_uid = xe_mmio_read64_2x32(xe_root_tile_mmio(xe), CRI_DEVICE_UID);
>  }
>  
> +static void xe_device_force_wake_stop(struct xe_device *xe)
> +{
> +	struct xe_gt *gt;
> +	u8 id;
> +
> +	for_each_gt(gt, xe, id)
> +		xe_force_wake_stop(gt_to_fw(gt));
> +}
> +
>  int xe_device_probe(struct xe_device *xe)
>  {
>  	struct xe_tile *tile;
> @@ -1112,6 +1121,7 @@ int xe_device_probe(struct xe_device *xe)
>  err_unregister_display:
>  	xe_display_unregister(xe);
>  	drm_dev_unregister(&xe->drm);
> +	xe_device_force_wake_stop(xe);
>  
>  	return err;
>  }
> @@ -1121,6 +1131,7 @@ void xe_device_remove(struct xe_device *xe)
>  	xe_display_unregister(xe);
>  
>  	drm_dev_unplug(&xe->drm);
> +	xe_device_force_wake_stop(xe);
>  
>  	xe_bo_pci_dev_remove_all(xe);
>  }
> diff --git a/drivers/gpu/drm/xe/xe_force_wake.c b/drivers/gpu/drm/xe/xe_force_wake.c
> index 1b69e8e1e8eb..e5dcfcdf6605 100644
> --- a/drivers/gpu/drm/xe/xe_force_wake.c
> +++ b/drivers/gpu/drm/xe/xe_force_wake.c
> @@ -414,6 +414,50 @@ static void xe_force_wake_delayed_release_work(struct work_struct *work)
>  		xe_pm_runtime_put(xe);
>  }
>  
> +static void xe_force_wake_settle_delayed(struct xe_force_wake *fw)
> +{
> +	unsigned int ack_fail;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&fw->lock, flags);
> +	ack_fail = xe_force_wake_sleep_locked(fw, fw->delayed_domains);
> +	fw->delayed_domains = 0;
> +	spin_unlock_irqrestore(&fw->lock, flags);
> +
> +	xe_force_wake_warn_sleep_fail(fw->gt, ack_fail);
> +}
> +
> +/**
> + * xe_force_wake_flush - Put all delayed domains to sleep now
> + * @fw: Pointer to the force wake structure
> + *
> + * Cancel the pending delayed release and put the domains it was holding awake
> + * to sleep right away. Delayed release stays enabled, so it can be used again
> + * after resume.
> + *
> + * Used before powering the device off, once no forcewake reference is held
> + * and no new delayed release can start.
> + */
> +void xe_force_wake_flush(struct xe_force_wake *fw)
> +{
> +	cancel_delayed_work_sync(&fw->delayed_release_work);
> +	xe_force_wake_settle_delayed(fw);
> +}
> +
> +/**
> + * xe_force_wake_stop - Stop delayed release for good
> + * @fw: Pointer to the force wake structure
> + *
> + * Like xe_force_wake_flush(), but also disable delayed release, so it cannot
> + * start again. Used on device removal and shutdown, once no forcewake
> + * user that may release with xe_force_wake_put_delay() is left.
> + */
> +void xe_force_wake_stop(struct xe_force_wake *fw)
> +{
> +	xe_force_wake_disable_delayed(fw);
> +	xe_force_wake_settle_delayed(fw);
> +}
> +
>  const char *xe_force_wake_domain_to_str(enum xe_force_wake_domain_id id)
>  {
>  	switch (id) {
> diff --git a/drivers/gpu/drm/xe/xe_force_wake.h b/drivers/gpu/drm/xe/xe_force_wake.h
> index fc504af9d219..481416bd6c60 100644
> --- a/drivers/gpu/drm/xe/xe_force_wake.h
> +++ b/drivers/gpu/drm/xe/xe_force_wake.h
> @@ -19,6 +19,8 @@ unsigned int __must_check xe_force_wake_get(struct xe_force_wake *fw,
>  					    enum xe_force_wake_domains domains);
>  void xe_force_wake_put(struct xe_force_wake *fw, unsigned int fw_ref);
>  void xe_force_wake_put_delay(struct xe_force_wake *fw, unsigned int fw_ref);
> +void xe_force_wake_flush(struct xe_force_wake *fw);
> +void xe_force_wake_stop(struct xe_force_wake *fw);
>  
>  const char *xe_force_wake_domain_to_str(enum xe_force_wake_domain_id id);
>  
> @@ -105,6 +107,22 @@ DEFINE_CLASS(xe_force_wake, struct xe_force_wake_ref,
>  #define xe_with_force_wake(ref, fw, domains) \
>  	__xe_with_force_wake(ref, fw, domains, __UNIQUE_ID(done))
>  
> +/*
> + * Same as the xe_force_wake class, but flush the delayed release after the
> + * domains are put. For paths that power the device off.
> + */
> +static inline void xe_force_wake_put_and_flush(struct xe_force_wake *fw,
> +					       unsigned int fw_ref)
> +{
> +	xe_force_wake_put(fw, fw_ref);
> +	xe_force_wake_flush(fw);
> +}
> +
> +DEFINE_CLASS(xe_force_wake_flush, struct xe_force_wake_ref,
> +	     xe_force_wake_put_and_flush(_T.fw, _T.domains),
> +	     xe_force_wake_constructor(fw, domains),
> +	     struct xe_force_wake *fw, unsigned int domains);
> +
>  /*
>   * Same as the xe_force_wake class, but the domains are released with
>   * xe_force_wake_put_delay().
> diff --git a/drivers/gpu/drm/xe/xe_force_wake_types.h b/drivers/gpu/drm/xe/xe_force_wake_types.h
> index 95bcc9ec2d74..5ad289670319 100644
> --- a/drivers/gpu/drm/xe/xe_force_wake_types.h
> +++ b/drivers/gpu/drm/xe/xe_force_wake_types.h
> @@ -99,6 +99,35 @@ struct xe_force_wake_domain {
>   * Currently only used for GT power domains (where the term "forcewake" is used
>   * in the hardware documentation), although the interface could be extended to
>   * power wells in other parts of the hardware in the future.
> + *
> + * Delayed-release state flow of a domain, protected by @lock:
> + *
> + *  +------------+                                  +--------------+
> + *  |   ASLEEP   | ------- get: wake -------------> |  REFERENCED  |
> + *  |  ref == 0  | <------ final put: sleep ------- |   ref > 0    |
> + *  +------------+                                  +--------------+
> + *        ^                                           |         ^
> + *        |                         final put_delay   |         |
> + *        |                                           |         | get: reuse
> + *        |                                           |         | no MMIO
> + *        |                                           v         |
> + *        |                                         +--------------+
> + *        |                                         | DELAYED HOLD |
> + *        +---- worker after @hold_until, --------- |   ref == 0   |
> + *              or flush/stop: sleep                +--------------+
> + *                                                    |          ^
> + *                                                    |          |
> + *                                                    +----------+
> + *                                         worker before @hold_until: requeue
> + *
> + * Once @delayed_enabled is cleared, a final put_delay behaves like a final
> + * put and DELAYED HOLD becomes unreachable.
> + *
> + * ASLEEP:       neither @awake_domains nor @delayed_domains has the domain.
> + * REFERENCED:   @awake_domains has the domain, @delayed_domains does not.
> + * DELAYED HOLD: both masks have the domain; @delayed_release_work is
> + *               pending or running. Each final put_delay moves
> + *               @hold_until forward.
>   */
>  struct xe_force_wake {
>  	/** @gt: back pointers to GT */
> diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
> index 98c4464d9cd0..2be58bb09180 100644
> --- a/drivers/gpu/drm/xe/xe_gt.c
> +++ b/drivers/gpu/drm/xe/xe_gt.c
> @@ -1008,7 +1008,7 @@ int xe_gt_suspend(struct xe_gt *gt)
>  	xe_gt_dbg(gt, "suspending\n");
>  	xe_gt_sanitize(gt);
>  
> -	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
> +	CLASS(xe_force_wake_flush, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
>  	if (!xe_force_wake_ref_has_domain(fw_ref.domains, XE_FORCEWAKE_ALL)) {
>  		xe_gt_err(gt, "suspend failed (%pe)\n", ERR_PTR(-ETIMEDOUT));
>  		return -ETIMEDOUT;
> @@ -1031,8 +1031,10 @@ int xe_gt_suspend(struct xe_gt *gt)
>  
>  void xe_gt_shutdown(struct xe_gt *gt)
>  {
> -	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
> -	do_gt_reset(gt);
> +	xe_with_force_wake(fw_ref, gt_to_fw(gt), XE_FORCEWAKE_ALL)
> +		do_gt_reset(gt);
> +
> +	xe_force_wake_stop(gt_to_fw(gt));
>  }
>  
>  /**
> @@ -1100,7 +1102,7 @@ int xe_gt_runtime_suspend(struct xe_gt *gt)
>  {
>  	xe_gt_dbg(gt, "runtime suspending\n");
>  
> -	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
> +	CLASS(xe_force_wake_flush, fw_ref)(gt_to_fw(gt), XE_FORCEWAKE_ALL);
>  	if (!xe_force_wake_ref_has_domain(fw_ref.domains, XE_FORCEWAKE_ALL)) {
>  		xe_gt_err(gt, "runtime suspend failed (%pe)\n", ERR_PTR(-ETIMEDOUT));
>  		return -ETIMEDOUT;
> -- 
> 2.43.0
> 

  reply	other threads:[~2026-11-30 21:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17  3:18 [PATCH 0/3] drm/xe/forcewake: add delayed release for engine-cycle queries Zongyao Bai
2026-10-17  3:18 ` [PATCH 1/3] drm/xe/forcewake: add delayed release with hysteresis Zongyao Bai
2026-11-09 20:55   ` Rodrigo Vivi
2026-11-10  1:00     ` Bai, Zongyao
2026-10-17  3:18 ` [PATCH 2/3] drm/xe/forcewake: flush delayed release at power and teardown boundaries Zongyao Bai
2026-10-17  3:18 ` [PATCH 3/3] drm/xe/query: use delayed forcewake release for engine-cycle queries Zongyao Bai
2026-10-17  3:25 ` ✗ CI.checkpatch: warning for drm/xe/forcewake: add delayed " Patchwork
2026-10-17  3:27 ` ✓ CI.KUnit: success " Patchwork
2026-10-17  3:27 ` [PATCH 0/3] " Simon Richter
2026-10-17  4:07 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-10-17  5:48 ` ✓ Xe.CI.FULL: " Patchwork
2026-11-10 22:05 ` [PATCH v2 0/3] " Zongyao Bai
2026-11-10 22:05   ` [PATCH v2 1/3] drm/xe/forcewake: add delayed release with hysteresis Zongyao Bai
2026-11-10 22:34     ` sashiko-bot
2026-11-16 22:51       ` Bai, Zongyao
2026-11-10 22:05   ` [PATCH v2 2/3] drm/xe/forcewake: flush delayed release at power and teardown boundaries Zongyao Bai
2026-11-10 22:26     ` sashiko-bot
2026-11-16 22:54       ` Bai, Zongyao
2026-11-10 22:05   ` [PATCH v2 3/3] drm/xe/query: use delayed forcewake release for engine-cycle queries Zongyao Bai
2026-11-17  0:28 ` [PATCH v3 0/3] drm/xe/forcewake: add delayed " Zongyao Bai
2026-11-17  0:28   ` [PATCH v3 1/3] drm/xe/forcewake: add delayed release with hysteresis Zongyao Bai
2026-11-17  0:28   ` [PATCH v3 2/3] drm/xe/forcewake: flush delayed release at power and teardown boundaries Zongyao Bai
2026-11-30 21:50     ` Rodrigo Vivi [this message]
2026-11-17  0:28   ` [PATCH v3 3/3] drm/xe/query: use delayed forcewake release for engine-cycle queries Zongyao Bai

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=aw3vpMnsONPcn_pf@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=zongyao.bai@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