* [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map()
@ 2016-05-17 12:51 Dave Gordon
2016-05-17 12:51 ` [PATCH v4 2/2] drm/i915: optimise i915_gem_object_map() for small objects Dave Gordon
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Dave Gordon @ 2016-05-17 12:51 UTC (permalink / raw)
To: intel-gfx
The recently-added i915_gem_object_pin_map() can be further optimised
for "small" objects. To facilitate this, and simplify the error paths
before adding the new code, this patch pulls out the "mapping" part of
the operation (involving local allocations which must be undone before
return) into its own subfunction.
The next patch will then insert the new optimisation into the middle of
the now-separated subfunction.
This reorganisation will probably not affect the generated code, as the
compiler will most likely inline it anyway, but it makes the logical
structure a bit clearer and easier to modify.
v2:
Restructure loop-over-pages & error check [Chris Wilson]
v3:
Add page count to debug messages [Chris Wilson]
Convert WARN_ON() to GEM_BUG_ON()
v4:
Drop the DEBUG messages [Tvrtko Ursulin]
Signed-off-by: Dave Gordon <david.s.gordon@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 54 +++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 24cab88..82a1bc4 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2398,6 +2398,38 @@ static void i915_gem_object_free_mmap_offset(struct drm_i915_gem_object *obj)
return 0;
}
+/* The 'mapping' part of i915_gem_object_pin_map() below */
+static void *i915_gem_object_map(const struct drm_i915_gem_object *obj)
+{
+ unsigned long n_pages = obj->base.size >> PAGE_SHIFT;
+ struct sg_table *sgt = obj->pages;
+ struct sg_page_iter sg_iter;
+ struct page **pages;
+ unsigned long i = 0;
+ void *addr;
+
+ /* A single page can always be kmapped */
+ if (n_pages == 1)
+ return kmap(sg_page(sgt->sgl));
+
+ pages = drm_malloc_gfp(n_pages, sizeof(*pages), GFP_TEMPORARY);
+ if (pages == NULL)
+ return NULL;
+
+ for_each_sg_page(sgt->sgl, &sg_iter, sgt->nents, 0)
+ pages[i++] = sg_page_iter_page(&sg_iter);
+
+ /* Check that we have the expected number of pages */
+ GEM_BUG_ON(i != n_pages);
+
+ addr = vmap(pages, n_pages, 0, PAGE_KERNEL);
+
+ drm_free_large(pages);
+
+ return addr;
+}
+
+/* get, pin, and map the pages of the object into kernel space */
void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj)
{
int ret;
@@ -2411,27 +2443,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj)
i915_gem_object_pin_pages(obj);
if (obj->mapping == NULL) {
- struct page **pages;
-
- pages = NULL;
- if (obj->base.size == PAGE_SIZE)
- obj->mapping = kmap(sg_page(obj->pages->sgl));
- else
- pages = drm_malloc_gfp(obj->base.size >> PAGE_SHIFT,
- sizeof(*pages),
- GFP_TEMPORARY);
- if (pages != NULL) {
- struct sg_page_iter sg_iter;
- int n;
-
- n = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter,
- obj->pages->nents, 0)
- pages[n++] = sg_page_iter_page(&sg_iter);
-
- obj->mapping = vmap(pages, n, 0, PAGE_KERNEL);
- drm_free_large(pages);
- }
+ obj->mapping = i915_gem_object_map(obj);
if (obj->mapping == NULL) {
i915_gem_object_unpin_pages(obj);
return ERR_PTR(-ENOMEM);
--
1.9.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 2/2] drm/i915: optimise i915_gem_object_map() for small objects
2016-05-17 12:51 [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Dave Gordon
@ 2016-05-17 12:51 ` Dave Gordon
2016-05-17 13:13 ` [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Tvrtko Ursulin
2016-05-17 13:23 ` ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] " Patchwork
2 siblings, 0 replies; 5+ messages in thread
From: Dave Gordon @ 2016-05-17 12:51 UTC (permalink / raw)
To: intel-gfx
We're using this function for ringbuffers and other "small" objects, so
it's worth avoiding an extra malloc()/free() cycle if the page array is
small enough to put on the stack. Here we've chosen an arbitrary cutoff
of 32 (4k) pages, which is big enough for a ringbuffer (4 pages) or a
context image (currently up to 22 pages).
v2:
change name of local array [Chris Wilson]
Signed-off-by: Dave Gordon <david.s.gordon@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 82a1bc4..dda7fe6 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2404,7 +2404,8 @@ static void *i915_gem_object_map(const struct drm_i915_gem_object *obj)
unsigned long n_pages = obj->base.size >> PAGE_SHIFT;
struct sg_table *sgt = obj->pages;
struct sg_page_iter sg_iter;
- struct page **pages;
+ struct page *stack_pages[32];
+ struct page **pages = stack_pages;
unsigned long i = 0;
void *addr;
@@ -2412,9 +2413,12 @@ static void *i915_gem_object_map(const struct drm_i915_gem_object *obj)
if (n_pages == 1)
return kmap(sg_page(sgt->sgl));
- pages = drm_malloc_gfp(n_pages, sizeof(*pages), GFP_TEMPORARY);
- if (pages == NULL)
- return NULL;
+ if (n_pages > ARRAY_SIZE(stack_pages)) {
+ /* Too big for stack -- allocate temporary array instead */
+ pages = drm_malloc_gfp(n_pages, sizeof(*pages), GFP_TEMPORARY);
+ if (pages == NULL)
+ return NULL;
+ }
for_each_sg_page(sgt->sgl, &sg_iter, sgt->nents, 0)
pages[i++] = sg_page_iter_page(&sg_iter);
@@ -2424,7 +2428,8 @@ static void *i915_gem_object_map(const struct drm_i915_gem_object *obj)
addr = vmap(pages, n_pages, 0, PAGE_KERNEL);
- drm_free_large(pages);
+ if (pages != stack_pages)
+ drm_free_large(pages);
return addr;
}
--
1.9.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map()
2016-05-17 12:51 [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Dave Gordon
2016-05-17 12:51 ` [PATCH v4 2/2] drm/i915: optimise i915_gem_object_map() for small objects Dave Gordon
@ 2016-05-17 13:13 ` Tvrtko Ursulin
2016-05-17 13:23 ` ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] " Patchwork
2 siblings, 0 replies; 5+ messages in thread
From: Tvrtko Ursulin @ 2016-05-17 13:13 UTC (permalink / raw)
To: Dave Gordon, intel-gfx
On 17/05/16 13:51, Dave Gordon wrote:
> The recently-added i915_gem_object_pin_map() can be further optimised
> for "small" objects. To facilitate this, and simplify the error paths
> before adding the new code, this patch pulls out the "mapping" part of
> the operation (involving local allocations which must be undone before
> return) into its own subfunction.
>
> The next patch will then insert the new optimisation into the middle of
> the now-separated subfunction.
>
> This reorganisation will probably not affect the generated code, as the
> compiler will most likely inline it anyway, but it makes the logical
> structure a bit clearer and easier to modify.
>
> v2:
> Restructure loop-over-pages & error check [Chris Wilson]
>
> v3:
> Add page count to debug messages [Chris Wilson]
> Convert WARN_ON() to GEM_BUG_ON()
>
> v4:
> Drop the DEBUG messages [Tvrtko Ursulin]
>
> Signed-off-by: Dave Gordon <david.s.gordon@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> ---
> drivers/gpu/drm/i915/i915_gem.c | 54 +++++++++++++++++++++++++----------------
> 1 file changed, 33 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 24cab88..82a1bc4 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -2398,6 +2398,38 @@ static void i915_gem_object_free_mmap_offset(struct drm_i915_gem_object *obj)
> return 0;
> }
>
> +/* The 'mapping' part of i915_gem_object_pin_map() below */
> +static void *i915_gem_object_map(const struct drm_i915_gem_object *obj)
> +{
> + unsigned long n_pages = obj->base.size >> PAGE_SHIFT;
> + struct sg_table *sgt = obj->pages;
> + struct sg_page_iter sg_iter;
> + struct page **pages;
> + unsigned long i = 0;
> + void *addr;
> +
> + /* A single page can always be kmapped */
> + if (n_pages == 1)
> + return kmap(sg_page(sgt->sgl));
> +
> + pages = drm_malloc_gfp(n_pages, sizeof(*pages), GFP_TEMPORARY);
> + if (pages == NULL)
> + return NULL;
> +
> + for_each_sg_page(sgt->sgl, &sg_iter, sgt->nents, 0)
> + pages[i++] = sg_page_iter_page(&sg_iter);
> +
> + /* Check that we have the expected number of pages */
> + GEM_BUG_ON(i != n_pages);
> +
> + addr = vmap(pages, n_pages, 0, PAGE_KERNEL);
> +
> + drm_free_large(pages);
> +
> + return addr;
> +}
> +
> +/* get, pin, and map the pages of the object into kernel space */
> void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj)
> {
> int ret;
> @@ -2411,27 +2443,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj)
> i915_gem_object_pin_pages(obj);
>
> if (obj->mapping == NULL) {
> - struct page **pages;
> -
> - pages = NULL;
> - if (obj->base.size == PAGE_SIZE)
> - obj->mapping = kmap(sg_page(obj->pages->sgl));
> - else
> - pages = drm_malloc_gfp(obj->base.size >> PAGE_SHIFT,
> - sizeof(*pages),
> - GFP_TEMPORARY);
> - if (pages != NULL) {
> - struct sg_page_iter sg_iter;
> - int n;
> -
> - n = 0;
> - for_each_sg_page(obj->pages->sgl, &sg_iter,
> - obj->pages->nents, 0)
> - pages[n++] = sg_page_iter_page(&sg_iter);
> -
> - obj->mapping = vmap(pages, n, 0, PAGE_KERNEL);
> - drm_free_large(pages);
> - }
> + obj->mapping = i915_gem_object_map(obj);
> if (obj->mapping == NULL) {
> i915_gem_object_unpin_pages(obj);
> return ERR_PTR(-ENOMEM);
>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 5+ messages in thread* ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] drm/i915: refactor i915_gem_object_pin_map()
2016-05-17 12:51 [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Dave Gordon
2016-05-17 12:51 ` [PATCH v4 2/2] drm/i915: optimise i915_gem_object_map() for small objects Dave Gordon
2016-05-17 13:13 ` [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Tvrtko Ursulin
@ 2016-05-17 13:23 ` Patchwork
2016-05-17 13:58 ` Dave Gordon
2 siblings, 1 reply; 5+ messages in thread
From: Patchwork @ 2016-05-17 13:23 UTC (permalink / raw)
To: Dave Gordon; +Cc: intel-gfx
== Series Details ==
Series: series starting with [v4,1/2] drm/i915: refactor i915_gem_object_pin_map()
URL : https://patchwork.freedesktop.org/series/7292/
State : failure
== Summary ==
Series 7292v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/7292/revisions/1/mbox
Test drv_hangman:
Subgroup error-state-basic:
pass -> FAIL (ro-ilk1-i5-650)
fi-bdw-i7-5557u total:219 pass:206 dwarn:0 dfail:0 fail:0 skip:13
fi-bsw-n3050 total:218 pass:174 dwarn:0 dfail:0 fail:2 skip:42
fi-byt-n2820 total:218 pass:175 dwarn:0 dfail:0 fail:2 skip:41
fi-hsw-i7-4770k total:219 pass:198 dwarn:0 dfail:0 fail:0 skip:21
fi-hsw-i7-4770r total:219 pass:193 dwarn:0 dfail:0 fail:0 skip:26
fi-kbl-y total:219 pass:191 dwarn:1 dfail:0 fail:2 skip:25
fi-skl-i7-6700k total:219 pass:191 dwarn:0 dfail:0 fail:0 skip:28
ro-bdw-i5-5250u total:219 pass:181 dwarn:0 dfail:0 fail:0 skip:38
ro-bdw-i7-5557U total:219 pass:206 dwarn:0 dfail:0 fail:0 skip:13
ro-bdw-i7-5600u total:219 pass:187 dwarn:0 dfail:0 fail:0 skip:32
ro-byt-n2820 total:218 pass:175 dwarn:0 dfail:0 fail:2 skip:41
ro-hsw-i3-4010u total:218 pass:193 dwarn:0 dfail:0 fail:0 skip:25
ro-hsw-i7-4770r total:219 pass:194 dwarn:0 dfail:0 fail:0 skip:25
ro-ilk-i7-620lm total:219 pass:151 dwarn:0 dfail:0 fail:1 skip:67
ro-ilk1-i5-650 total:214 pass:151 dwarn:0 dfail:0 fail:2 skip:61
ro-ivb-i7-3770 total:219 pass:183 dwarn:0 dfail:0 fail:0 skip:36
ro-ivb2-i7-3770 total:219 pass:187 dwarn:0 dfail:0 fail:0 skip:32
ro-skl-i7-6700hq total:214 pass:189 dwarn:0 dfail:0 fail:0 skip:25
ro-snb-i7-2620M total:219 pass:177 dwarn:0 dfail:0 fail:1 skip:41
fi-snb-i7-2600 failed to connect after reboot
ro-bsw-n3050 failed to connect after reboot
Results at /archive/results/CI_IGT_test/RO_Patchwork_918/
0d84413 drm-intel-nightly: 2016y-05m-17d-10h-26m-35s UTC integration manifest
cfa6373 drm/i915: optimise i915_gem_object_map() for small objects
1864abb drm/i915: refactor i915_gem_object_pin_map()
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] drm/i915: refactor i915_gem_object_pin_map()
2016-05-17 13:23 ` ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] " Patchwork
@ 2016-05-17 13:58 ` Dave Gordon
0 siblings, 0 replies; 5+ messages in thread
From: Dave Gordon @ 2016-05-17 13:58 UTC (permalink / raw)
To: intel-gfx
On 17/05/16 14:23, Patchwork wrote:
> == Series Details ==
>
> Series: series starting with [v4,1/2] drm/i915: refactor i915_gem_object_pin_map()
> URL : https://patchwork.freedesktop.org/series/7292/
> State : failure
>
> == Summary ==
>
> Series 7292v1 Series without cover letter
> http://patchwork.freedesktop.org/api/1.0/series/7292/revisions/1/mbox
>
> Test drv_hangman:
> Subgroup error-state-basic:
> pass -> FAIL (ro-ilk1-i5-650)
https://bugs.freedesktop.org/show_bug.cgi?id=94305
Seems to only happen on that one machine?
.Dave.
> fi-bdw-i7-5557u total:219 pass:206 dwarn:0 dfail:0 fail:0 skip:13
> fi-bsw-n3050 total:218 pass:174 dwarn:0 dfail:0 fail:2 skip:42
> fi-byt-n2820 total:218 pass:175 dwarn:0 dfail:0 fail:2 skip:41
> fi-hsw-i7-4770k total:219 pass:198 dwarn:0 dfail:0 fail:0 skip:21
> fi-hsw-i7-4770r total:219 pass:193 dwarn:0 dfail:0 fail:0 skip:26
> fi-kbl-y total:219 pass:191 dwarn:1 dfail:0 fail:2 skip:25
> fi-skl-i7-6700k total:219 pass:191 dwarn:0 dfail:0 fail:0 skip:28
> ro-bdw-i5-5250u total:219 pass:181 dwarn:0 dfail:0 fail:0 skip:38
> ro-bdw-i7-5557U total:219 pass:206 dwarn:0 dfail:0 fail:0 skip:13
> ro-bdw-i7-5600u total:219 pass:187 dwarn:0 dfail:0 fail:0 skip:32
> ro-byt-n2820 total:218 pass:175 dwarn:0 dfail:0 fail:2 skip:41
> ro-hsw-i3-4010u total:218 pass:193 dwarn:0 dfail:0 fail:0 skip:25
> ro-hsw-i7-4770r total:219 pass:194 dwarn:0 dfail:0 fail:0 skip:25
> ro-ilk-i7-620lm total:219 pass:151 dwarn:0 dfail:0 fail:1 skip:67
> ro-ilk1-i5-650 total:214 pass:151 dwarn:0 dfail:0 fail:2 skip:61
> ro-ivb-i7-3770 total:219 pass:183 dwarn:0 dfail:0 fail:0 skip:36
> ro-ivb2-i7-3770 total:219 pass:187 dwarn:0 dfail:0 fail:0 skip:32
> ro-skl-i7-6700hq total:214 pass:189 dwarn:0 dfail:0 fail:0 skip:25
> ro-snb-i7-2620M total:219 pass:177 dwarn:0 dfail:0 fail:1 skip:41
> fi-snb-i7-2600 failed to connect after reboot
> ro-bsw-n3050 failed to connect after reboot
>
> Results at /archive/results/CI_IGT_test/RO_Patchwork_918/
>
> 0d84413 drm-intel-nightly: 2016y-05m-17d-10h-26m-35s UTC integration manifest
> cfa6373 drm/i915: optimise i915_gem_object_map() for small objects
> 1864abb drm/i915: refactor i915_gem_object_pin_map()
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-05-17 13:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-17 12:51 [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Dave Gordon
2016-05-17 12:51 ` [PATCH v4 2/2] drm/i915: optimise i915_gem_object_map() for small objects Dave Gordon
2016-05-17 13:13 ` [PATCH v4 1/2] drm/i915: refactor i915_gem_object_pin_map() Tvrtko Ursulin
2016-05-17 13:23 ` ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] " Patchwork
2016-05-17 13:58 ` Dave Gordon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox