[PATCH v2] drm/xe/gt: Introduce runtime suspend/resume
Michal Wajdeczko
michal.wajdeczko at intel.com
Mon Aug 25 11:52:59 UTC 2025
On 8/25/2025 1:20 PM, Raag Jadav wrote:
> If power state is retained between suspend/resume cycle, we don't have
> to perform full gt re-initialization. Introduce runtime helpers for gt
> which greatly reduce suspend/resume delay.
>
> v2: Drop redundant xe_gt_sanitize() and xe_guc_ct_stop() (Daniele)
> Use runtime naming for guc helpers (Daniele)
> s/xe_guc_ct_enable/xe_guc_ct_register (Daniele)
>
> Originally-by: Riana Tauro <riana.tauro at intel.com>
> Signed-off-by: Raag Jadav <raag.jadav at intel.com>
> ---
> drivers/gpu/drm/xe/xe_gt.c | 49 ++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_gt.h | 2 ++
> drivers/gpu/drm/xe/xe_guc.c | 23 +++++++++++++++-
> drivers/gpu/drm/xe/xe_guc.h | 2 ++
> drivers/gpu/drm/xe/xe_guc_ct.c | 15 +++++++----
> drivers/gpu/drm/xe/xe_guc_ct.h | 3 ++-
> drivers/gpu/drm/xe/xe_pm.c | 4 +--
> drivers/gpu/drm/xe/xe_uc.c | 19 +++++++++++++
> drivers/gpu/drm/xe/xe_uc.h | 2 ++
> 9 files changed, 110 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
> index a3397f04abcc..9004af061af3 100644
> --- a/drivers/gpu/drm/xe/xe_gt.c
> +++ b/drivers/gpu/drm/xe/xe_gt.c
> @@ -943,6 +943,31 @@ int xe_gt_suspend(struct xe_gt *gt)
> return err;
> }
>
please add kernel-doc for all new public functions
> +int xe_gt_runtime_suspend(struct xe_gt *gt)
> +{
> + unsigned int fw_ref;
> + int err = -ETIMEDOUT;
this is only used in err_msg, maybe just hardcode it there
or use something else than %pe ?
note that if fw_get fails then there should be already big:
xe_gt_WARN(..."Forcewake domain%s %#x failed to acknowledge awake request
so this log with -ETIMEDOUT seems redundant
> +
> + xe_gt_dbg(gt, "runtime suspending\n");
> +
> + fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
> + if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
> + goto err_msg;
> +
> + xe_uc_runtime_suspend(>->uc);
> +
> + xe_force_wake_put(gt_to_fw(gt), fw_ref);
> + xe_gt_dbg(gt, "runtime suspended\n");
> +
> + return 0;
> +
> +err_msg:
> + xe_force_wake_put(gt_to_fw(gt), fw_ref);
> + xe_gt_err(gt, "runtime suspend failed (%pe)\n", ERR_PTR(err));
> +
> + return err;
> +}
> +
> void xe_gt_shutdown(struct xe_gt *gt)
> {
> unsigned int fw_ref;
> @@ -1002,6 +1027,30 @@ int xe_gt_resume(struct xe_gt *gt)
> return err;
> }
>
add kernel-doc
> +int xe_gt_runtime_resume(struct xe_gt *gt)
> +{
> + unsigned int fw_ref;
> + int err = -ETIMEDOUT;
see above comment
> +
> + xe_gt_dbg(gt, "runtime resuming\n");
> + fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
> + if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
> + goto err_msg;
> +
> + xe_uc_runtime_resume(>->uc);
> +
> + xe_force_wake_put(gt_to_fw(gt), fw_ref);
> + xe_gt_dbg(gt, "runtime resumed\n");
> +
> + return 0;
> +
> +err_msg:
> + xe_force_wake_put(gt_to_fw(gt), fw_ref);
> + xe_gt_err(gt, "runtime resume failed (%pe)\n", ERR_PTR(err));
> +
> + return err;
> +}
> +
> struct xe_hw_engine *xe_gt_hw_engine(struct xe_gt *gt,
> enum xe_engine_class class,
> u16 instance, bool logical)
> diff --git a/drivers/gpu/drm/xe/xe_gt.h b/drivers/gpu/drm/xe/xe_gt.h
> index 41880979f4de..3f793230e78a 100644
> --- a/drivers/gpu/drm/xe/xe_gt.h
> +++ b/drivers/gpu/drm/xe/xe_gt.h
> @@ -51,6 +51,8 @@ int xe_gt_suspend(struct xe_gt *gt);
> void xe_gt_shutdown(struct xe_gt *gt);
> int xe_gt_resume(struct xe_gt *gt);
> void xe_gt_reset_async(struct xe_gt *gt);
> +int xe_gt_runtime_resume(struct xe_gt *gt);
> +int xe_gt_runtime_suspend(struct xe_gt *gt);
> void xe_gt_sanitize(struct xe_gt *gt);
> int xe_gt_sanitize_freq(struct xe_gt *gt);
>
> diff --git a/drivers/gpu/drm/xe/xe_guc.c b/drivers/gpu/drm/xe/xe_guc.c
> index 37d06c51180c..70598df83ef3 100644
> --- a/drivers/gpu/drm/xe/xe_guc.c
> +++ b/drivers/gpu/drm/xe/xe_guc.c
> @@ -1355,7 +1355,7 @@ int xe_guc_enable_communication(struct xe_guc *guc)
> guc_enable_irq(guc);
> }
>
> - err = xe_guc_ct_enable(&guc->ct);
> + err = xe_guc_ct_register(&guc->ct);
> if (err)
> return err;
>
> @@ -1626,6 +1626,27 @@ void xe_guc_stop_prepare(struct xe_guc *guc)
> }
> }
>
add kernel-doc
> +void xe_guc_runtime_suspend(struct xe_guc *guc)
> +{
> + xe_guc_submit_pause(guc);
> + guc->submission_state.enabled = false;
> +
> + /*
> + * Since we're already in runtime suspend path, we shouldn't have pending
> + * messages. But in case there turn out to be any, we'd probably want them
> + * to be thrown as errors for further investigation.
> + */
> + xe_guc_ct_disable(&guc->ct);
maybe this should be just
xe_guc_ct_runtime_suspend()
and then comment will be also moved to ct.c where it belongs
> +}
> +
add kernel-doc
> +void xe_guc_runtime_resume(struct xe_guc *guc)
> +{
> + guc_enable_irq(guc);
> + xe_guc_ct_enable(&guc->ct);
> + guc->submission_state.enabled = true;
> + xe_guc_submit_unpause(guc);
> +}
> +
> void xe_guc_stop(struct xe_guc *guc)
> {
> xe_guc_ct_stop(&guc->ct);
> diff --git a/drivers/gpu/drm/xe/xe_guc.h b/drivers/gpu/drm/xe/xe_guc.h
> index 22cf019a11bf..e3736300ffd8 100644
> --- a/drivers/gpu/drm/xe/xe_guc.h
> +++ b/drivers/gpu/drm/xe/xe_guc.h
> @@ -35,6 +35,8 @@ int xe_guc_upload(struct xe_guc *guc);
> int xe_guc_min_load_for_hwconfig(struct xe_guc *guc);
> int xe_guc_enable_communication(struct xe_guc *guc);
> int xe_guc_opt_in_features_enable(struct xe_guc *guc);
> +void xe_guc_runtime_suspend(struct xe_guc *guc);
> +void xe_guc_runtime_resume(struct xe_guc *guc);
> int xe_guc_suspend(struct xe_guc *guc);
> void xe_guc_notify(struct xe_guc *guc);
> int xe_guc_auth_huc(struct xe_guc *guc, u32 rsa_addr);
> diff --git a/drivers/gpu/drm/xe/xe_guc_ct.c b/drivers/gpu/drm/xe/xe_guc_ct.c
> index 3f4e6a46ff16..f769245f91ae 100644
> --- a/drivers/gpu/drm/xe/xe_guc_ct.c
> +++ b/drivers/gpu/drm/xe/xe_guc_ct.c
> @@ -465,7 +465,15 @@ static void ct_exit_safe_mode(struct xe_guc_ct *ct)
> xe_gt_dbg(ct_to_gt(ct), "GuC CT safe-mode disabled\n");
> }
>
> -int xe_guc_ct_enable(struct xe_guc_ct *ct)
> +void xe_guc_ct_enable(struct xe_guc_ct *ct)
> +{
> + guc_ct_change_state(ct, XE_GUC_CT_STATE_ENABLED);
> +
> + if (ct_needs_safe_mode(ct))
> + ct_enter_safe_mode(ct);
> +}
> +
add kernel-doc
and maybe we should expose
xe_guc_ct_runtime_suspend
xe_guc_ct_runtime_resume
to make it clear when it should called and all logic related to
CT will be kept in the ct.c code
> +int xe_guc_ct_register(struct xe_guc_ct *ct)
> {
> struct xe_device *xe = ct_to_xe(ct);
> struct xe_gt *gt = ct_to_gt(ct);
> @@ -489,14 +497,11 @@ int xe_guc_ct_enable(struct xe_guc_ct *ct)
> if (err)
> goto err_out;
>
> - guc_ct_change_state(ct, XE_GUC_CT_STATE_ENABLED);
> + xe_guc_ct_enable(ct);
>
> smp_mb();
> wake_up_all(&ct->wq);
>
> - if (ct_needs_safe_mode(ct))
> - ct_enter_safe_mode(ct);
> -
> #if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
> /*
> * The CT has now been reset so the dumper can be re-armed
> diff --git a/drivers/gpu/drm/xe/xe_guc_ct.h b/drivers/gpu/drm/xe/xe_guc_ct.h
> index 18d4225e6502..32ce578b031c 100644
> --- a/drivers/gpu/drm/xe/xe_guc_ct.h
> +++ b/drivers/gpu/drm/xe/xe_guc_ct.h
> @@ -13,8 +13,9 @@ struct xe_device;
>
> int xe_guc_ct_init_noalloc(struct xe_guc_ct *ct);
> int xe_guc_ct_init(struct xe_guc_ct *ct);
> -int xe_guc_ct_enable(struct xe_guc_ct *ct);
> +void xe_guc_ct_enable(struct xe_guc_ct *ct);
> void xe_guc_ct_disable(struct xe_guc_ct *ct);
> +int xe_guc_ct_register(struct xe_guc_ct *ct);
> void xe_guc_ct_stop(struct xe_guc_ct *ct);
> void xe_guc_ct_fast_path(struct xe_guc_ct *ct);
>
> diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
> index 51ed7270994a..9a306b5fbdaa 100644
> --- a/drivers/gpu/drm/xe/xe_pm.c
> +++ b/drivers/gpu/drm/xe/xe_pm.c
> @@ -495,7 +495,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
> }
>
> for_each_gt(gt, xe, id) {
> - err = xe_gt_suspend(gt);
> + err = xe->d3cold.allowed ? xe_gt_suspend(gt) : xe_gt_runtime_suspend(gt);
> if (err)
> goto out_resume;
> }
> @@ -558,7 +558,7 @@ int xe_pm_runtime_resume(struct xe_device *xe)
> xe_irq_resume(xe);
>
> for_each_gt(gt, xe, id)
> - xe_gt_resume(gt);
> + xe->d3cold.allowed ? xe_gt_resume(gt) : xe_gt_runtime_resume(gt);
>
> xe_display_pm_runtime_resume(xe);
>
> diff --git a/drivers/gpu/drm/xe/xe_uc.c b/drivers/gpu/drm/xe/xe_uc.c
> index 465bda355443..e0ebe5e4fc49 100644
> --- a/drivers/gpu/drm/xe/xe_uc.c
> +++ b/drivers/gpu/drm/xe/xe_uc.c
> @@ -15,6 +15,7 @@
> #include "xe_guc.h"
> #include "xe_guc_pc.h"
> #include "xe_guc_engine_activity.h"
> +#include "xe_guc_submit.h"
> #include "xe_huc.h"
> #include "xe_sriov.h"
> #include "xe_uc_fw.h"
> @@ -301,6 +302,24 @@ int xe_uc_suspend(struct xe_uc *uc)
> return xe_guc_suspend(&uc->guc);
> }
>
add kernel-doc
> +void xe_uc_runtime_suspend(struct xe_uc *uc)
> +{
> + /* GuC submission not enabled, nothing to do */
do we need this ?
> + if (!xe_device_uc_enabled(uc_to_xe(uc)))
> + return;
> +
> + xe_guc_runtime_suspend(&uc->guc);
> +}
> +
add kernel-doc
> +void xe_uc_runtime_resume(struct xe_uc *uc)
> +{
> + /* GuC submission not enabled, nothing to do */
> + if (!xe_device_uc_enabled(uc_to_xe(uc)))
> + return;
> +
> + xe_guc_runtime_resume(&uc->guc);
> +}
> +
> /**
> * xe_uc_declare_wedged() - Declare UC wedged
> * @uc: the UC object
> diff --git a/drivers/gpu/drm/xe/xe_uc.h b/drivers/gpu/drm/xe/xe_uc.h
> index 21c9306098cf..5398da1a8097 100644
> --- a/drivers/gpu/drm/xe/xe_uc.h
> +++ b/drivers/gpu/drm/xe/xe_uc.h
> @@ -14,6 +14,8 @@ int xe_uc_init_post_hwconfig(struct xe_uc *uc);
> int xe_uc_load_hw(struct xe_uc *uc);
> void xe_uc_gucrc_disable(struct xe_uc *uc);
> int xe_uc_reset_prepare(struct xe_uc *uc);
> +void xe_uc_runtime_resume(struct xe_uc *uc);
> +void xe_uc_runtime_suspend(struct xe_uc *uc);
> void xe_uc_stop_prepare(struct xe_uc *uc);
> void xe_uc_stop(struct xe_uc *uc);
> int xe_uc_start(struct xe_uc *uc);
More information about the Intel-xe
mailing list