summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris.p.wilson@intel.com>2023-09-26 10:37:36 +0200
committerNirmoy Das <nirmoy.das@intel.com>2023-09-30 13:49:14 +0200
commit4cd64e9d2c7206db05e7162d0258b455726b7ec5 (patch)
treef13e3d4ef84e6127a274a486320ddab2dc2cbea8
parent0951dce656e2b3c4c9a5096cd2cedb39a5d6e637 (diff)
downloadlinux-4cd64e9d2c7206db05e7162d0258b455726b7ec5.tar.gz
linux-4cd64e9d2c7206db05e7162d0258b455726b7ec5.tar.bz2
linux-4cd64e9d2c7206db05e7162d0258b455726b7ec5.zip
drm/i915: Lift runtime-pm acquire callbacks out of intel_wakeref.mutex
When runtime pm is first woken, it will synchronously call the registered callbacks for the device. These callbacks may pull in their own forest of locks, which we do not want to conflate with the intel_wakeref.mutex. A second minor benefit to reducing the coverage of the mutex, is that it will reduce contention for frequent sleeps and wakes (such as when being used for soft-rc6). v2: remove usage of fetch_and_zero() and other improvements(Jani) Signed-off-by: Chris Wilson <chris.p.wilson@intel.com> Signed-off-by: Nirmoy Das <nirmoy.das@intel.com> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230926083742.14740-2-nirmoy.das@intel.com
-rw-r--r--drivers/gpu/drm/i915/intel_wakeref.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/drivers/gpu/drm/i915/intel_wakeref.c b/drivers/gpu/drm/i915/intel_wakeref.c
index 718f2f1b6174..623a69089386 100644
--- a/drivers/gpu/drm/i915/intel_wakeref.c
+++ b/drivers/gpu/drm/i915/intel_wakeref.c
@@ -10,21 +10,12 @@
#include "intel_wakeref.h"
#include "i915_drv.h"
-static void rpm_get(struct intel_wakeref *wf)
-{
- wf->wakeref = intel_runtime_pm_get(&wf->i915->runtime_pm);
-}
-
-static void rpm_put(struct intel_wakeref *wf)
-{
- intel_wakeref_t wakeref = fetch_and_zero(&wf->wakeref);
-
- intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
- INTEL_WAKEREF_BUG_ON(!wakeref);
-}
-
int __intel_wakeref_get_first(struct intel_wakeref *wf)
{
+ intel_wakeref_t wakeref;
+ int ret = 0;
+
+ wakeref = intel_runtime_pm_get(&wf->i915->runtime_pm);
/*
* Treat get/put as different subclasses, as we may need to run
* the put callback from under the shrinker and do not want to
@@ -32,41 +23,52 @@ int __intel_wakeref_get_first(struct intel_wakeref *wf)
* upon acquiring the wakeref.
*/
mutex_lock_nested(&wf->mutex, SINGLE_DEPTH_NESTING);
- if (!atomic_read(&wf->count)) {
- int err;
-
- rpm_get(wf);
- err = wf->ops->get(wf);
- if (unlikely(err)) {
- rpm_put(wf);
- mutex_unlock(&wf->mutex);
- return err;
+ if (!atomic_read(&wf->count)) {
+ INTEL_WAKEREF_BUG_ON(wf->wakeref);
+ wf->wakeref = wakeref;
+ wakeref = 0;
+
+ ret = wf->ops->get(wf);
+ if (ret) {
+ wakeref = xchg(&wf->wakeref, 0);
+ wake_up_var(&wf->wakeref);
+ goto unlock;
}
smp_mb__before_atomic(); /* release wf->count */
}
+
atomic_inc(&wf->count);
+ INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
+
+unlock:
mutex_unlock(&wf->mutex);
+ if (unlikely(wakeref))
+ intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
- INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
- return 0;
+ return ret;
}
static void ____intel_wakeref_put_last(struct intel_wakeref *wf)
{
+ intel_wakeref_t wakeref = 0;
+
INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
if (unlikely(!atomic_dec_and_test(&wf->count)))
goto unlock;
/* ops->put() must reschedule its own release on error/deferral */
if (likely(!wf->ops->put(wf))) {
- rpm_put(wf);
+ INTEL_WAKEREF_BUG_ON(!wf->wakeref);
+ wakeref = xchg(&wf->wakeref, 0);
wake_up_var(&wf->wakeref);
}
unlock:
mutex_unlock(&wf->mutex);
+ if (wakeref)
+ intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
}
void __intel_wakeref_put_last(struct intel_wakeref *wf, unsigned long flags)