[Intel-gfx] [RFC PATCH 009/162] drm/i915: Introduce drm_i915_lock_isolated
Matthew Auld
matthew.auld at intel.com
Fri Nov 27 12:04:45 UTC 2020
From: Thomas Hellström <thomas.hellstrom at intel.com>
When an object is just created and not yet put on any lists, there's
a single owner and thus trylock will always succeed. Introduce
drm_i915_lock_isolated to annotate trylock in this situation.
This is similar to TTM's create_locked() functionality.
Signed-off-by: Thomas Hellström <thomas.hellstrom at intel.com>
Cc: Matthew Auld <matthew.auld at intel.com>
---
drivers/gpu/drm/i915/gem/i915_gem_object.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index be14486f63a7..d61194ef484e 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -107,6 +107,13 @@ i915_gem_object_put(struct drm_i915_gem_object *obj)
#define assert_object_held(obj) dma_resv_assert_held((obj)->base.resv)
+#define object_is_isolated(obj) \
+ (!IS_ENABLED(CONFIG_LOCKDEP) || \
+ ((kref_read(&obj->base.refcount) == 0) || \
+ ((kref_read(&obj->base.refcount) == 1) && \
+ list_empty_careful(&obj->mm.link) && \
+ list_empty_careful(&obj->vma.list))))
+
static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
struct i915_gem_ww_ctx *ww,
bool intr)
@@ -147,6 +154,15 @@ static inline bool i915_gem_object_trylock(struct drm_i915_gem_object *obj)
return dma_resv_trylock(obj->base.resv);
}
+static inline void i915_gem_object_lock_isolated(struct drm_i915_gem_object *obj)
+{
+ int ret;
+
+ WARN_ON(!object_is_isolated(obj));
+ ret = dma_resv_trylock(obj->base.resv);
+ GEM_WARN_ON(!ret);
+}
+
static inline void i915_gem_object_unlock(struct drm_i915_gem_object *obj)
{
dma_resv_unlock(obj->base.resv);
--
2.26.2
More information about the Intel-gfx
mailing list