drm/i915: refactor i915_gem_object_pin_map()
Subsystems (2)
PATCH v4 1/2 drm/i915: refactor i915_gem_object_pin_map()
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]
--- drivers/gpu/drm/i915/i915_gem.c | 54 +++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +33 -21
@@ -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 );
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 2/2 drm/i915: optimise i915_gem_object_map() for small objects
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]
--- drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +10 -5
@@ -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; }
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 93 lines · Dave Gordon
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] ConvertWARN_ON()toGEM_BUG_ON()v4:
Drop the DEBUG messages [Tvrtko Ursulin]Signed-off-by Dave Gordon <[email protected]>Cc Tvrtko Ursulin <[email protected]>Cc Chris Wilson <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 54 +++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-)drivers/gpu/drm/i915/i915_gem.c +32
-15@@ -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,
drivers/gpu/drm/i915/i915_gem.c void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj) · line 2449
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +1
-6- 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 );
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Ro.CI.BAT: failure for series starting with [v4,1/2] drm/i915: refactor i915_gem_object_pin_map()
In reply to Dave Gordon== Series Details ==
== 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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: ✗ Ro.CI.BAT: failure for series starting with [v4,1/2] drm/i915: refactor i915_gem_object_pin_map()
Quoted 6 lines · Patchwork
== 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
Quoted 8 lines
== Summary ==
Series 7292v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/7292/revisions/1/mboxTest
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.
Quoted 19 lines
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
Quoted 8 lines
fi-snb-i7-2600 failed to connect after reboot
ro-bsw-n3050 failed to connect after rebootResults 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: refactori915_gem_object_pin_map()
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx