diff mbox

drm/i915/vma: Move the bind_count vs pin_count assertion to a helper

Message ID 20180605093420.30594-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson June 5, 2018, 9:34 a.m. UTC
To spare ourselves a long line later, refactor the repeated check of
bind_count vs pin_count to a helper.

Suggested-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Matthew Auld <matthew.william.auld@gmail.com>
---
 drivers/gpu/drm/i915/i915_vma.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Mika Kuoppala June 5, 2018, 9:38 a.m. UTC | #1
Chris Wilson <chris@chris-wilson.co.uk> writes:

> To spare ourselves a long line later, refactor the repeated check of
> bind_count vs pin_count to a helper.
>
> Suggested-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> Cc: Matthew Auld <matthew.william.auld@gmail.com>

Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Chris Wilson June 5, 2018, 9:40 a.m. UTC | #2
Quoting Chris Wilson (2018-06-05 10:34:20)
> To spare ourselves a long line later, refactor the repeated check of
> bind_count vs pin_count to a helper.
> 
> Suggested-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> Cc: Matthew Auld <matthew.william.auld@gmail.com>
> ---
>  drivers/gpu/drm/i915/i915_vma.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index 9324d476e0a7..0b3de2f19e1c 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -459,6 +459,17 @@ bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long cache_level)
>         return true;
>  }
>  
> +static void assert_bind_count(struct drm_i915_gem_object *obj)
> +{
> +       /*
> +        * Combine the assertion that the object is bound and that we have
> +        * pinned its pages. But we should never have pinned the pages

bound the object more than we have pinned its pages.

That makes more sense.
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 9324d476e0a7..0b3de2f19e1c 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -459,6 +459,17 @@  bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long cache_level)
 	return true;
 }
 
+static void assert_bind_count(struct drm_i915_gem_object *obj)
+{
+	/*
+	 * Combine the assertion that the object is bound and that we have
+	 * pinned its pages. But we should never have pinned the pages
+	 * more than we have bound the object. (This, of course, assumes that
+	 * no one else decides to pin the pages!)
+	 */
+	GEM_BUG_ON(atomic_read(&obj->mm.pages_pin_count) < obj->bind_count);
+}
+
 /**
  * i915_vma_insert - finds a slot for the vma in its address space
  * @vma: the vma
@@ -595,7 +606,7 @@  i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 	obj->bind_count++;
 	spin_unlock(&dev_priv->mm.obj_lock);
 
-	GEM_BUG_ON(atomic_read(&obj->mm.pages_pin_count) < obj->bind_count);
+	assert_bind_count(obj);
 
 	return 0;
 
@@ -633,7 +644,7 @@  i915_vma_remove(struct i915_vma *vma)
 	 * reaped by the shrinker.
 	 */
 	i915_gem_object_unpin_pages(obj);
-	GEM_BUG_ON(atomic_read(&obj->mm.pages_pin_count) < obj->bind_count);
+	assert_bind_count(obj);
 }
 
 int __i915_vma_do_pin(struct i915_vma *vma,