From: Matthew Auld <matthew.auld@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Matthew Brost" <matthew.brost@intel.com>
Subject: [PATCH 2/2] drm/xe/shrinker: hold a stable RPM ref across scan
Date: Fri, 25 Sep 2026 12:55:23 +0100 [thread overview]
Message-ID: <20260925115521.1018940-4-matthew.auld@intel.com> (raw)
In-Reply-To: <20260925115521.1018940-3-matthew.auld@intel.com>
Now that we use async RPM get, with the custom worker gone, we can
eliminate the get/put dance and just always hold a stable ref over the
entire scan, and just have the inner layer ping the async status with
if_active(), if required. If it's still not awake we skip just like
before, but when it does wake up we now don't need to worry about races
where the device potentially goes back to sleep, since at no point do we
drop the outer ref.
Assisted-by: LLM
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_shrinker.c | 44 +++++++++++++++-----------------
1 file changed, 21 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_shrinker.c b/drivers/gpu/drm/xe/xe_shrinker.c
index 518f77acf1dd..267b0290be8e 100644
--- a/drivers/gpu/drm/xe/xe_shrinker.c
+++ b/drivers/gpu/drm/xe/xe_shrinker.c
@@ -52,24 +52,6 @@ xe_shrinker_mod_pages(struct xe_shrinker *shrinker, long shrinkable, long purgea
write_unlock(&shrinker->lock);
}
-static bool __xe_shrinker_runtime_pm_get(struct xe_shrinker *shrinker)
-{
- struct xe_device *xe = shrinker->xe;
-
- if (xe_pm_runtime_get_if_active(xe))
- return true;
-
- if (xe_rpm_reclaim_safe(xe) && !ttm_bo_shrink_avoid_wait()) {
- xe_pm_runtime_get(xe);
- return true;
- }
-
- xe_pm_runtime_get_async(xe);
- xe_pm_runtime_put(xe);
-
- return false;
-}
-
static void xe_shrinker_runtime_pm_put(struct xe_shrinker *shrinker, bool runtime_pm)
{
if (runtime_pm)
@@ -102,7 +84,7 @@ static int __xe_shrinker_walk(struct xe_shrinker *shrinker,
if (mem_type != XE_PL_SYSTEM && !rpm &&
xe_device_is_l2_flush_optimized(xe)) {
- if (!__xe_shrinker_runtime_pm_get(shrinker))
+ if (!xe_pm_runtime_get_if_active(xe))
break;
rpm = true;
}
@@ -190,6 +172,13 @@ xe_shrinker_count(struct shrinker *shrink, struct shrink_control *sc)
return num_pages ? num_pages : SHRINK_EMPTY;
}
+static bool xe_shrinker_needs_rpm(struct xe_device *xe)
+{
+ return (!IS_DGFX(xe) && xe_device_has_flat_ccs(xe) &&
+ ttm_backup_bytes_avail()) ||
+ xe_device_is_l2_flush_optimized(xe);
+}
+
/*
* Check if we need runtime pm, and if so try to grab a reference if
* already active. If sync RPM get fails, queue an async RPM get that
@@ -202,19 +191,28 @@ static bool xe_shrinker_runtime_pm_get(struct xe_shrinker *shrinker, bool force,
{
struct xe_device *xe = shrinker->xe;
- if (IS_DGFX(xe) || !xe_device_has_flat_ccs(xe) ||
- !ttm_backup_bytes_avail())
+ if (!xe_shrinker_needs_rpm(xe))
return false;
if (!force) {
read_lock(&shrinker->lock);
- force = (nr_to_scan > shrinker->purgeable_pages && can_backup);
+ if (xe_device_is_l2_flush_optimized(xe))
+ force = shrinker->purgeable_pages || can_backup;
+ else
+ force = nr_to_scan > shrinker->purgeable_pages && can_backup;
read_unlock(&shrinker->lock);
if (!force)
return false;
}
- return __xe_shrinker_runtime_pm_get(shrinker);
+ if (!xe_pm_runtime_get_if_active(xe)) {
+ if (xe_rpm_reclaim_safe(xe) && !ttm_bo_shrink_avoid_wait())
+ xe_pm_runtime_get(xe);
+ else
+ xe_pm_runtime_get_async(xe);
+ }
+
+ return true;
}
static unsigned long xe_shrinker_scan(struct shrinker *shrink, struct shrink_control *sc)
--
2.55.0
next prev parent reply other threads:[~2026-09-25 11:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 11:55 [PATCH 1/2] drm/xe/shrinker: use async RPM get Matthew Auld
2026-09-25 11:55 ` Matthew Auld [this message]
2026-09-26 16:56 ` [PATCH 2/2] drm/xe/shrinker: hold a stable RPM ref across scan Karl Mehltretter
2026-09-28 11:37 ` Matthew Auld
2026-09-25 12:02 ` [PATCH 1/2] drm/xe/shrinker: use async RPM get sashiko-bot
2026-09-25 12:03 ` ✓ CI.KUnit: success for series starting with [1/2] " Patchwork
2026-09-25 13:43 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-25 21:07 ` ✗ Xe.CI.FULL: failure " 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=20260925115521.1018940-4-matthew.auld@intel.com \
--to=matthew.auld@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=thomas.hellstrom@linux.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