diff mbox

drm/i915: fixup i915_gem_object_get_page inline helper

Message ID 1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Vetter Oct. 9, 2012, 8:50 p.m. UTC
The obj->pages to obj->pages->sgl rework introduced this helper, but
it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.

For simplicity (and since right now I seem to be too stupid to see
the bug), let's just grab the right page with a for_each_sg loop.

This is exercised by the improved hangman tests and the gem_exec_big
test in i-g-t.

v2: Compared to v1, don't try to be clever since I seemingly only
manage to prove that I'm not clever.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Chris Wilson Oct. 9, 2012, 10:16 p.m. UTC | #1
On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> The obj->pages to obj->pages->sgl rework introduced this helper, but
> it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> 
> For simplicity (and since right now I seem to be too stupid to see
> the bug), let's just grab the right page with a for_each_sg loop.
> 
> This is exercised by the improved hangman tests and the gem_exec_big
> test in i-g-t.
> 
> v2: Compared to v1, don't try to be clever since I seemingly only
> manage to prove that I'm not clever.

Only I expect that loop to show up on profiles even higher than the
sg_next() from pwrite. :|

I expect it to have a measureable impact upon relocation throughput,
so I should measure it...
-Chris
Chris Wilson Oct. 10, 2012, 9:01 a.m. UTC | #2
On Tue, 09 Oct 2012 23:16:02 +0100, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > The obj->pages to obj->pages->sgl rework introduced this helper, but
> > it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> > 
> > For simplicity (and since right now I seem to be too stupid to see
> > the bug), let's just grab the right page with a for_each_sg loop.
> > 
> > This is exercised by the improved hangman tests and the gem_exec_big
> > test in i-g-t.
> > 
> > v2: Compared to v1, don't try to be clever since I seemingly only
> > manage to prove that I'm not clever.
> 
> Only I expect that loop to show up on profiles even higher than the
> sg_next() from pwrite. :|
> 
> I expect it to have a measureable impact upon relocation throughput,
> so I should measure it...
> -Chris
> 
> -- 
> Chris Wilson, Intel Open Source Technology Centre
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
From: Chris Wilson <chris@chris-wilson.co.uk>
Subject: Re: [PATCH] drm/i915: fixup i915_gem_object_get_page inline helper
To: Daniel Vetter <daniel.vetter@ffwll.ch>, Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
In-Reply-To: <1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch>
References: <84c8a8$624sk4@orsmga001.jf.intel.com> <1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch>

On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> The obj->pages to obj->pages->sgl rework introduced this helper, but
> it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> 
> For simplicity (and since right now I seem to be too stupid to see
> the bug), let's just grab the right page with a for_each_sg loop.
> 
> This is exercised by the improved hangman tests and the gem_exec_big
> test in i-g-t.
> 
> v2: Compared to v1, don't try to be clever since I seemingly only
> manage to prove that I'm not clever.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Looks like my worries are baseless. It can always be attacked latter if
need be. I'd still like to know what the mistake was...

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Daniel Vetter Oct. 10, 2012, 9:15 a.m. UTC | #3
On Wed, Oct 10, 2012 at 10:01:47AM +0100, Chris Wilson wrote:
> On Tue, 09 Oct 2012 23:16:02 +0100, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > > The obj->pages to obj->pages->sgl rework introduced this helper, but
> > > it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> > > 
> > > For simplicity (and since right now I seem to be too stupid to see
> > > the bug), let's just grab the right page with a for_each_sg loop.
> > > 
> > > This is exercised by the improved hangman tests and the gem_exec_big
> > > test in i-g-t.
> > > 
> > > v2: Compared to v1, don't try to be clever since I seemingly only
> > > manage to prove that I'm not clever.
> > 
> > Only I expect that loop to show up on profiles even higher than the
> > sg_next() from pwrite. :|
> > 
> > I expect it to have a measureable impact upon relocation throughput,
> > so I should measure it...
> > -Chris
> > 
> > -- 
> > Chris Wilson, Intel Open Source Technology Centre
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> From: Chris Wilson <chris@chris-wilson.co.uk>
> Subject: Re: [PATCH] drm/i915: fixup i915_gem_object_get_page inline helper
> To: Daniel Vetter <daniel.vetter@ffwll.ch>, Intel Graphics Development <intel-gfx@lists.freedesktop.org>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> In-Reply-To: <1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch>
> References: <84c8a8$624sk4@orsmga001.jf.intel.com> <1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch>
> 
> On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > The obj->pages to obj->pages->sgl rework introduced this helper, but
> > it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> > 
> > For simplicity (and since right now I seem to be too stupid to see
> > the bug), let's just grab the right page with a for_each_sg loop.
> > 
> > This is exercised by the improved hangman tests and the gem_exec_big
> > test in i-g-t.
> > 
> > v2: Compared to v1, don't try to be clever since I seemingly only
> > manage to prove that I'm not clever.
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
> Looks like my worries are baseless. It can always be attacked latter if
> need be. I'd still like to know what the mistake was...

I think it was two mistakes:
- One was the off-by-one fixed in v1.
- Second seemed to be the special case that if the table fits exactly,
  sg_alloc doesn't set a chain ptr with another sg table with just one
  entry.

But like the commit message says, I've failed to be clever enough
yesterday to make it work.
-Daniel
Daniel Vetter Oct. 10, 2012, 9:21 a.m. UTC | #4
On Wed, Oct 10, 2012 at 10:01:47AM +0100, Chris Wilson wrote:
> On Tue, 09 Oct 2012 23:16:02 +0100, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > > The obj->pages to obj->pages->sgl rework introduced this helper, but
> > > it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> > > 
> > > For simplicity (and since right now I seem to be too stupid to see
> > > the bug), let's just grab the right page with a for_each_sg loop.
> > > 
> > > This is exercised by the improved hangman tests and the gem_exec_big
> > > test in i-g-t.
> > > 
> > > v2: Compared to v1, don't try to be clever since I seemingly only
> > > manage to prove that I'm not clever.
> > 
> > Only I expect that loop to show up on profiles even higher than the
> > sg_next() from pwrite. :|
> > 
> > I expect it to have a measureable impact upon relocation throughput,
> > so I should measure it...
> > -Chris
> > 
> > -- 
> > Chris Wilson, Intel Open Source Technology Centre
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> From: Chris Wilson <chris@chris-wilson.co.uk>
> Subject: Re: [PATCH] drm/i915: fixup i915_gem_object_get_page inline helper
> To: Daniel Vetter <daniel.vetter@ffwll.ch>, Intel Graphics Development <intel-gfx@lists.freedesktop.org>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> In-Reply-To: <1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch>
> References: <84c8a8$624sk4@orsmga001.jf.intel.com> <1349815848-1824-1-git-send-email-daniel.vetter@ffwll.ch>
> 
> On Tue,  9 Oct 2012 22:50:48 +0200, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > The obj->pages to obj->pages->sgl rework introduced this helper, but
> > it doesn't actually work for n >= SG_MAX_SINGLE_ALLOC.
> > 
> > For simplicity (and since right now I seem to be too stupid to see
> > the bug), let's just grab the right page with a for_each_sg loop.
> > 
> > This is exercised by the improved hangman tests and the gem_exec_big
> > test in i-g-t.
> > 
> > v2: Compared to v1, don't try to be clever since I seemingly only
> > manage to prove that I'm not clever.
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
> Looks like my worries are baseless. It can always be attacked latter if
> need be. I'd still like to know what the mistake was...
> 
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

Merged to -fixes, with the missing regression-sha1 citation added.
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 4f2831a..32a2e47 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1340,12 +1340,14 @@  void i915_gem_lastclose(struct drm_device *dev);
 int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
 static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
 {
-	struct scatterlist *sg = obj->pages->sgl;
-	while (n >= SG_MAX_SINGLE_ALLOC) {
-		sg = sg_chain_ptr(sg + SG_MAX_SINGLE_ALLOC - 1);
-		n -= SG_MAX_SINGLE_ALLOC - 1;
+	struct scatterlist *sg;
+	int i;
+
+	for_each_sg(obj->pages->sgl, sg, obj->pages->nents, i) {
+		if (i == n)
+			return sg_page(sg);
 	}
-	return sg_page(sg+n);
+	return NULL;
 }
 static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
 {