drm/i915: Broaden application of set-domain(GTT)
Subsystems (4)
PATCH 1/1 drm/i915: Broaden application of set-domain(GTT)
Previously, this was restricted to only operate on bound objects - to make pointer access through the GTT to the object coherent with writes to and from the GPU. A second usecase is drm_intel_bo_wait_rendering() which at present does not function unless the object also happens to be bound into the GGTT (on current systems that is becoming increasingly rare, especially for the typical requests from mesa). A third usecase is a future patch wishing to extend the coverage of the GTT domain to include objects not bound into the GGTT but still in its coherent cache domain. For the latter pair of requests, we need to operate on the object regardless of its bind state.
--- drivers/gpu/drm/i915/i915_gem.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +7 -16
@@ -1506,18 +1506,10 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (ret) goto unref; -if (read_domains &I915_GEM_DOMAIN_GTT ) { +if (read_domains &I915_GEM_DOMAIN_GTT ) ret =i915_gem_object_set_to_gtt_domain (obj, write_domain !=0 ); - -/* Silently promote "you're not bound, there was nothing to do" -* to success, since the client was just asking us to -* make sure everything was done. -*/ -if (ret == -EINVAL ) - ret =0 ; - }else { +else ret =i915_gem_object_set_to_cpu_domain (obj, write_domain !=0 ); - } unref:drm_gem_object_unreference (&obj->base);
@@ -3474,14 +3466,10 @@ i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj,int i915_gem_object_set_to_gtt_domain (struct drm_i915_gem_object *obj,bool write) { -struct i915_vma *vma =i915_gem_obj_to_ggtt (obj);uint32_t old_write_domain, old_read_domains; +struct i915_vma *vma;int ret; -/* Not valid to be called on unbound objects. */ -if (vma ==NULL ) -return -EINVAL ; -if (obj->base.write_domain ==I915_GEM_DOMAIN_GTT )return 0 ;
@@ -3518,7 +3506,10 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) old_write_domain);/* And bump the LRU for this access */ -if (i915_gem_object_is_inactive (obj)) + vma =i915_gem_obj_to_ggtt (obj); +if (vma && +drm_mm_node_allocated (&vma->node) && +i915_gem_object_is_inactive (obj))list_move_tail (&vma->mm_list, &to_i915 (obj->base.dev)->gtt.base.inactive_list);
Signature · 1 line
2.1.1
PATCH 1/1 drm/i915: Broaden application of set-domain(GTT)
Previously, this was restricted to only operate on bound objects - to make pointer access through the GTT to the object coherent with writes to and from the GPU. A second usecase is drm_intel_bo_wait_rendering() which at present does not function unless the object also happens to be bound into the GGTT (on current systems that is becoming increasingly rare, especially for the typical requests from mesa). A third usecase is a future patch wishing to extend the coverage of the GTT domain to include objects not bound into the GGTT but still in its coherent cache domain. For the latter pair of requests, we need to operate on the object regardless of its bind state.
v2: After discussion with Akash, we came to the conclusion that the get-pages was required in order for accurate domain tracking in the corner cases (like the shrinker) and also useful for ensuring memory coherency with earlier cached CPU mmaps in case userspace uses exotic cache bypass (non-temporal) instructions.
--- drivers/gpu/drm/i915/i915_gem.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +19 -16
@@ -1503,18 +1503,10 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (ret) goto unref; -if (read_domains &I915_GEM_DOMAIN_GTT ) { +if (read_domains &I915_GEM_DOMAIN_GTT ) ret =i915_gem_object_set_to_gtt_domain (obj, write_domain !=0 ); - -/* Silently promote "you're not bound, there was nothing to do" -* to success, since the client was just asking us to -* make sure everything was done. -*/ -if (ret == -EINVAL ) - ret =0 ; - }else { +else ret =i915_gem_object_set_to_cpu_domain (obj, write_domain !=0 ); - } unref:drm_gem_object_unreference (&obj->base);
@@ -3442,14 +3434,10 @@ i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj,int i915_gem_object_set_to_gtt_domain (struct drm_i915_gem_object *obj,bool write) { -struct i915_vma *vma =i915_gem_obj_to_ggtt (obj);uint32_t old_write_domain, old_read_domains; +struct i915_vma *vma;int ret; -/* Not valid to be called on unbound objects. */ -if (vma ==NULL ) -return -EINVAL ; -if (obj->base.write_domain ==I915_GEM_DOMAIN_GTT )return 0 ;
@@ -3457,6 +3445,18 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)if (ret)return ret; +/* Flush and acquire obj->pages so that we are coherent through +* direct access in memory with previous cached writes through +* shmemfs and that our cache domain tracking remains valid. +* For example, if the obj->filp was moved to swap without us +* being notified and releasing the pages, we would mistakenly +* continue to assume that the obj remained out of the CPU cached +* domain. +*/ + ret =i915_gem_object_get_pages (obj); +if (ret) +return ret; +i915_gem_object_flush_cpu_write_domain (obj, false);/* Serialise direct access to this object with the barriers for
@@ -3486,7 +3486,10 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) old_write_domain);/* And bump the LRU for this access */ -if (i915_gem_object_is_inactive (obj)) + vma =i915_gem_obj_to_ggtt (obj); +if (vma && +drm_mm_node_allocated (&vma->node) && +i915_gem_object_is_inactive (obj))list_move_tail (&vma->mm_list, &to_i915 (obj->base.dev)->gtt.base.inactive_list);
Signature · 1 line
2.1.1
PATCH 1/1 drm/i915: Support to create uncached user mapping for a Gem object
From: Akash Goel <[email protected]>
This patch provides support to create uncached virtual mappings for a Gem object. It intends to provide the same funtionality of 'mmap_gtt' interface without the constraints of a limited aperture space, but provided clients handles the linear to tile conversion on their own.
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with mmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed onto GPU, which will be the case if regular mmap ioctl interface is used.
This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated.
To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap shall automatically invalidate the cache lines, but this may not be true for non temporal write instructions and also not all pages of the object be updated at any given point of time through this mapping. Having a call to get_pages in set_to_gtt_domain function, as added by Chris in the earlier patch, would guarantee the clflush and so there will be no cache- lines holding the data for the object before it is accessed through this map. A new field 'flags' has been added to 'drm_i915_gem_mmap' structure, used in gem_mmap ioctl, which allows to convey the required mapping type as uncached. User can query the driver for the support of this mapping through the get_params. For that a new define I915_PARAM_HAS_UC_MMAP has been added.
--- drivers/gpu/drm/i915/i915_dma.c | 3 +++ drivers/gpu/drm/i915/i915_gem.c | 17 +++++++++++++++++ include/uapi/drm/i915_drm.h | 4 ++++ 3 files changed, 24 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +3 -0
@@ -1027,6 +1027,9 @@ static int i915_getparam(struct drm_device *dev, void *data,case I915_PARAM_CMD_PARSER_VERSION : value =i915_cmd_parser_get_version ();break ; +case I915_PARAM_HAS_UC_MMAP : + value =1 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;
drivers/gpu/drm/i915/i915_gem.c +17 -0
@@ -1492,6 +1492,23 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, addr =vm_mmap (obj->filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset); + +if (args->flags &I915_GEM_USE_UNCACHED_MMAP ) { +struct mm_struct *mm = current->mm; +struct vm_area_struct *vma; +down_write (&mm->mmap_sem); + vma =find_vma (mm, addr); +if (!vma) { +drm_gem_object_unreference_unlocked (obj); +return -EINVAL ; + } +/* Change the page attribute to uncached (along with +* write-combinning to get better performance) */ + vma->vm_page_prot = +pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); +up_write (&mm->mmap_sem); + } +drm_gem_object_unreference_unlocked (obj);if (IS_ERR ((void *)addr))return addr;
include/uapi/drm/i915_drm.h +4 -0
@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_HAS_UC_MMAP 29 typedef struct drm_i915_getparam { int param;
@@ -487,6 +488,9 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +#define I915_GEM_USE_UNCACHED_MMAP (1<<0) +__u64 flags; };struct drm_i915_gem_mmap_gtt {
Signature · 1 line
1.9.2
PATCH 1/1 intel: New libdrm interface to create uncached CPU mapping
From: Akash Goel <[email protected]>
A new libdrm interface 'drm_intel_gem_bo_map_uc' is provided
by this patch. Through this interface Gfx clients can create uncached virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own.
This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with mmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_uc_unsynchronized', through which uncached virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering
A new field 'flags' has been added to 'drm_i915_gem_mmap' structure, used in gem_mmap ioctl, which allows to convey the required mapping type as uncached type. User can query the driver for the support of this mapping through the get_params. For that a new define I915_PARAM_HAS_UC_MMAP has been added.
--- include/drm/i915_drm.h | 4 ++ intel/intel_bufmgr.h | 3 ++ intel/intel_bufmgr_gem.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+)
include/drm/i915_drm.h +4 -0
@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_HAS_UC_MMAP 29 typedef struct drm_i915_getparam { int param;
@@ -487,6 +488,9 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +#define I915_GEM_USE_UNCACHED_MMAP (1<<0) +__u64 flags; };struct drm_i915_gem_mmap_gtt {
intel/intel_bufmgr.h +3 -0
@@ -177,6 +177,9 @@ void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,int drm_intel_gem_bo_map_unsynchronized (drm_intel_bo *bo);int drm_intel_gem_bo_map_gtt (drm_intel_bo *bo);int drm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo); +int drm_intel_gem_bo_map_uc_unsynchronized (drm_intel_bo *bo); +int drm_intel_gem_bo_map_uc (drm_intel_bo *bo); +int drm_intel_gem_bo_unmap_uc (drm_intel_bo *bo);int drm_intel_gem_bo_get_reloc_count (drm_intel_bo *bo);void drm_intel_gem_bo_clear_relocs (drm_intel_bo *bo,int start);
intel/intel_bufmgr_gem.c +124 -0
148 lines not on this page · raw message
Signature · 1 line
1.9.2
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
In reply to [email protected]Quoted 8 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This patch provides support to create uncached virtual mappings for a Gem object. It intends to provide the same funtionality of '
mmap_gtt' interface without the constraints of a limited aperture space, but provided clients handles the linear to tile conversion on their own.
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt.
That seems like it should be easy to demonstrate with igt/gem_gtt_speed. You should also copy igt/gem_mmap_gtt to test the interface, and extend igt/gem_concurrent_blt to make sure that mmap(wc)+domain vs the GPU is correct.
Quoted 3 lines
Also it avoids the
Cache flush after update from CPU side, when object is passed onto GPU, which will be the case if regular mmap ioctl interface is used.
^CPU
Quoted 7 lines
This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated.
To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap shall automatically invalidate the cache lines, but this may not be true for non temporal write instructions and also not all
Quoted 8 lines
pages of the object be updated at any given point of time through this mapping. Having a call to
get_pagesinset_to_gtt_domainfunction, as added by Chris in the earlier patch, would guarantee the clflush and so there will be no cache- lines holding the data for the object before it is accessed through this map. A new field 'flags' has been added to 'drm_i915_gem_mmap' structure, used ingem_mmapioctl, which allows to convey the required mapping type as uncached. User can query the driver for the support of this mapping through theget_params. For that a new defineI915_PARAM_HAS_UC_MMAPhas been added.
I quibble over using the term uncached here, as what we mean is write-combining. They are quite different in terms of memory access!
I've put together a usecase in
http://cgit.freedesktop.org/~ickle/xf86-video-intel/commit/?h=wc-mmap&id=118e98a2d448469064cdcedf2013a91c3a69dab4
which I'll test shortly. It uses the new mmapping to allow direct access to larger than aperture buffers, prefers the unbound access for linear buffers and allows manual detiled uploads on !llc platforms.
Quoted 27 lines
Change-Id Ie883942f9e689525f72fe9a8d3780c3a9faa769aSigned-off-by Akash Goel <[email protected]>--- drivers/gpu/drm/i915/i915_dma.c | 3 +++ drivers/gpu/drm/i915/i915_gem.c | 17 +++++++++++++++++ include/uapi/drm/i915_drm.h | 4 ++++ 3 files changed, 24 insertions(+)drivers/gpu/drm/i915/i915_dma.c +3
-0@@ -1027,6 +1027,9 @@ static int i915_getparam(struct drm_device *dev, void *data,case I915_PARAM_CMD_PARSER_VERSION : value =i915_cmd_parser_get_version ();break ; +case I915_PARAM_HAS_UC_MMAP : + value =1 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;drivers/gpu/drm/i915/i915_gem.c +0
-0
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1498
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +4
-0@@ -1492,6 +1492,23 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, addr =vm_mmap (obj->filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset); + +if (args->flags &I915_GEM_USE_UNCACHED_MMAP ) { +struct mm_struct *mm = current->mm; +struct vm_area_struct *vma;
Newline please between variables and code.
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1503
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +5
-0+down_write (&mm->mmap_sem); + vma =find_vma (mm, addr); +if (!vma) { +drm_gem_object_unreference_unlocked (obj); +return -EINVAL ;
Eek returning with mmap_sem held.
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1509
Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +6
-0+ } +/* Change the page attribute to uncached (along with +* write-combinning to get better performance) */ + vma->vm_page_prot = +pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); +up_write (&mm->mmap_sem);
Perhaps,
down_write();
vma = find_vma(mm, addr);
if (vma && cpu_has_pat)
vma->vm_page_prot = pgprot_writecombing(); else addr = ERR_PTR(-ENODEV);
up_write();
I am pretty sure we can't do this trick on really old CPUs! -Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
In reply to [email protected]Quoted 24 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
drivers/gpu/drm/i915/i915_dma.c | 3 +++ drivers/gpu/drm/i915/i915_gem.c | 17 +++++++++++++++++ include/uapi/drm/i915_drm.h | 4 ++++ 3 files changed, 24 insertions(+)drivers/gpu/drm/i915/i915_dma.c +3
-0@@ -1027,6 +1027,9 @@ static int i915_getparam(struct drm_device *dev, void *data,case I915_PARAM_CMD_PARSER_VERSION : value =i915_cmd_parser_get_version ();break ; +case I915_PARAM_HAS_UC_MMAP : + value =1 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;drivers/gpu/drm/i915/i915_gem.c +0
-0
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1494
Quoted 3 lines
drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -1492,6 +1492,23 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, addr =vm_mmap (obj->filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset);
Forgot to mutter about:
if (args->flags & INVALID_FLAGS)
return -EINVAL;
and the param then makes better sense as I915_PARAM_HAS_EXT_MMAP (extended mmap interface, which we can then version)
In future we can test for EXT_MMAP support and mmap(RANDOM_FLAG) returning EINVAL for any new extension flags.
Quoted 33 lines
drivers/gpu/drm/i915/i915_gem.c +17
-0+ +if (args->flags &I915_GEM_USE_UNCACHED_MMAP ) { +struct mm_struct *mm = current->mm; +struct vm_area_struct *vma; +down_write (&mm->mmap_sem); + vma =find_vma (mm, addr); +if (!vma) { +drm_gem_object_unreference_unlocked (obj); +return -EINVAL ; + } +/* Change the page attribute to uncached (along with +* write-combinning to get better performance) */ + vma->vm_page_prot = +pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); +up_write (&mm->mmap_sem); + } +drm_gem_object_unreference_unlocked (obj);if (IS_ERR ((void *)addr))return addr;include/uapi/drm/i915_drm.h +1
-0@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_HAS_UC_MMAP 29 typedef struct drm_i915_getparam { int param;
include/uapi/drm/i915_drm.h struct drm_i915_gem_mmap { · line 492
Quoted 5 lines
include/uapi/drm/i915_drm.h +2
-0@@ -487,6 +488,9 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +#define I915_GEM_USE_UNCACHED_MMAP (1<<0)
#define I915_MMAP_WC is shorter
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
In reply to [email protected]Quoted 5 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with
mmap_gtt. Also it avoids the
I doubt it is the actual write that is faster. For example,
gtt wc Operation -------- ------ --------- 424000.0 1.30 ShmPutImage 10x10 square 29500.0 1.42 ShmPutImage 100x100 square 1510.0 0.95 ShmPutImage 500x500 square
It seems to reduce the overhead for small transfers (with an already mmaped pointer). That's interesting certainly, and probably a Clue for further improving performance. But it looks like peak throughput is limited by memory bandwidth, which has been my experience with the GTT mmap thus far.
I have some doubts as to whether it is coherent with the display though, and so whether it is truly write-combining...
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
Quoted 7 lines · Chris Wilson
Quoted 5 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with
mmap_gtt. Also it avoids the
Quoted 7 lines
I doubt it is the actual write that is faster. For example,
gtt wc Operation -------- ------ --------- 424000.0 1.30 ShmPutImage 10x10 square 29500.0 1.42 ShmPutImage 100x100 square 1510.0 0.95 ShmPutImage 500x500 square
Oops, bugs beware. I wasn't calling the ioctl correctly. Having re-run the test, I now get:
gtt wc Operation -------- ------ --------- 424000.0 1.30 ShmPutImage 10x10 square 29500.0 1.44 ShmPutImage 100x100 square 1510.0 1.38 ShmPutImage 500x500 square
Supporting your claims. Very nice.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
Quoted 12 lines · Chris Wilson
Quoted 6 lines · Chris Wilson
Quoted 5 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with
mmap_gtt. Also it avoids theOops, bugs beware. I wasn't calling the ioctl correctly. Having re-run the test, I now get:
Quoted 7 lines
gtt wc Operation -------- ------ --------- 424000.0 1.30 ShmPutImage 10x10 square 29500.0 1.44 ShmPutImage 100x100 square 1510.0 1.38 ShmPutImage 500x500 squareSupporting your claims. Very nice.
What are the units for these numbers?
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
Quoted 21 lines · Chad Versace
Quoted 18 lines · Chris Wilson
Quoted 6 lines · Chris Wilson
Quoted 5 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with
mmap_gtt. Also it avoids theOops, bugs beware. I wasn't calling the ioctl correctly. Having re-run the test, I now get:
gtt wc Operation -------- ------ --------- 424000.0 1.30 ShmPutImage 10x10 square 29500.0 1.44 ShmPutImage 100x100 square 1510.0 1.38 ShmPutImage 500x500 square
Quoted 3 lines
Quoted 1 line
Supporting your claims. Very nice.
What are the units for these numbers?
ops/s, relative factor on a baby byt.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/1 drm/i915: Support creation of unbound wc user mappings for objects
In reply to [email protected]From: Akash Goel <[email protected]>
This patch provides support to create write-combining virtual mappings of GEM object. It intends to provide the same funtionality of 'mmap_gtt' interface without the constraints and contention of a limited aperture space, but requires clients handles the linear to tile conversion on their own. This is for improving the CPU write operation performance, as with such mapping, writes and reads are almost 50% faster than with mmap_gtt. Similar to the GTT mmapping, unlike the regular CPU mmapping, it avoids the cache flush after update from CPU side, when object is passed onto GPU. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Using a CPU mmap in such cases would normally incur a clflush of the whole object, and using a GTT mmapping would likely require eviction of an active object or fence and thus stall. The write-combining CPU mmap avoids both.
To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap should automatically invalidate the cache lines, this may not be true for non-temporal write instructions and also not all pages of the object may be updated at any given point of time through this mapping. Having a call to get_pages in set_to_gtt_domain function, as added in the earlier patch 'drm/i915:
Broaden application of set-domain(GTT)', would guarantee the clflush and so there will be no cachelines holding the data for the object before it is accessed through this map.
The drm_i915_gem_mmap structure (for the DRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameter I915_PARAM_HAS_EXT_MMAP has been added for versioning the ioctl interface.
v2: Fix error handling, invalid flag detection, renaming (ickle)
The new mmapping is exercised by igt/gem_mmap_wc,
igt/gem_concurrent_blit and igt/gem_gtt_speed.
--- drivers/gpu/drm/i915/i915_dma.c | 3 +++ drivers/gpu/drm/i915/i915_gem.c | 19 +++++++++++++++++++ include/uapi/drm/i915_drm.h | 9 +++++++++ 3 files changed, 31 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +3 -0
@@ -1027,6 +1027,9 @@ static int i915_getparam(struct drm_device *dev, void *data,case I915_PARAM_CMD_PARSER_VERSION : value =i915_cmd_parser_get_version ();break ; +case I915_PARAM_MMAP_VERSION : + value =1 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;
drivers/gpu/drm/i915/i915_gem.c +19 -0
@@ -1485,6 +1485,12 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,struct drm_gem_object *obj;unsigned long addr; +if (args->flags & ~(I915_MMAP_WC )) +return -EINVAL ; + +if (args->flags &I915_MMAP_WC && !cpu_has_pat) +return -ENODEV ; + obj =drm_gem_object_lookup (dev, file, args->handle);if (obj ==NULL )return -ENOENT ;
@@ -1500,6 +1506,19 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, addr =vm_mmap (obj->filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset); +if (args->flags &I915_MMAP_WC ) { +struct mm_struct *mm = current->mm; +struct vm_area_struct *vma; + +down_write (&mm->mmap_sem); + vma =find_vma (mm, addr); +if (vma) + vma->vm_page_prot = +pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); +else + addr = -ENOMEM ; +up_write (&mm->mmap_sem); + }drm_gem_object_unreference_unlocked (obj);if (IS_ERR ((void *)addr))return addr;
include/uapi/drm/i915_drm.h +9 -0
@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_MMAP_VERSION 29 typedef struct drm_i915_getparam { int param;
@@ -487,6 +488,14 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +/** +* Flags for extended behaviour. +* +* Added in version 2. +*/ +__u64 flags; +#define I915_MMAP_WC 0x1 };struct drm_i915_gem_mmap_gtt {
Signature · 1 line
2.1.1
PATCH 1/3 igt/gem_evict_(alignment|everything): contend with GPU hangs
--- lib/igt_aux.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ lib/igt_aux.h | 4 +++ tests/gem_evict_alignment.c | 15 ++++++++++ tests/gem_evict_everything.c | 15 ++++++++++ 4 files changed, 103 insertions(+)
lib/igt_aux.c +69 -0
@@ -53,6 +53,7 @@#include "intel_chipset.h" #include "igt_aux.h" #include "igt_debugfs.h" +#include "igt_gt.h" #include "config.h" #include "intel_reg.h" #include "ioctl_wrappers.h"
@@ -131,6 +132,74 @@ void igt_stop_signal_helper(void) sig_stat =0 ; } +/* GPU abusers */ +static struct igt_helper_process hang_helper; +static void __attribute__((noreturn)) +hang_helper_process (pid_t pid,int fd,int gen) +{ +while (1 ) { +if (kill (pid,0 ))/* Parent has died, so must we. */ +exit (0 ); + +igt_post_hang_ring (fd, +igt_hang_ring (fd, gen,I915_EXEC_DEFAULT )); + +sleep (1 ); + } +} + +/** +* igt_fork_hang_helper: +* +* Fork a child process using #igt_fork_helper to hang the default engine +* of the GPU at regular intervals. +* +* This is useful to exercise slow running code (such as aperture placement) +* which needs to be robust against a GPU reset. +* +* In tests with subtests this function can be called outside of failure +* catching code blocks like #igt_fixture or #igt_subtest. +*/ +int igt_fork_hang_helper (void ) +{ +int fd, gen; + +if (igt_only_list_subtests ()) +return 1 ; + + fd =drm_open_any (); +if (fd ==-1 ) +return 0 ; + + gen =intel_gen (intel_get_drm_devid (fd)); +if (gen <5 ) { +close (fd); +return 0 ; + } + + igt_fork_helper(&hang_helper) +hang_helper_process (getppid (), fd, gen); + +close (fd); +return 1 ; +} + +/** +* igt_stop_hang_helper: +* +* Stops the child process spawned with igt_fork_hang_helper(). +* +* In tests with subtests this function can be called outside of failure +* catching code blocks like #igt_fixture or #igt_subtest. +*/ +void igt_stop_hang_helper (void ) +{ +if (igt_only_list_subtests ()) +return ; + +igt_stop_helper (&hang_helper); +} +/** * igt_check_boolean_env_var: * @env_var: environment variable name
lib/igt_aux.h +4 -0
@@ -35,6 +35,10 @@/* generally useful helpers */ void igt_fork_signal_helper (void );void igt_stop_signal_helper (void ); + +int igt_fork_hang_helper (void ); +void igt_stop_hang_helper (void ); +void igt_exchange_int (void *array,unsigned i,unsigned j); void igt_permute_array(void *array, unsigned size, void (*exchange_func)(void *array,
tests/gem_evict_alignment.c +15 -0
@@ -221,6 +221,21 @@ igt_main count =4 ;major_evictions (fd, size, count); } + +if (igt_fork_hang_helper ()) { + igt_subtest("minor-hang") { + size =1024 *1024 ; + count =3 *gem_aperture_size (fd) / size /4 ; +minor_evictions (fd, size, count); + } + + igt_subtest("major-hang") { + size =3 *gem_aperture_size (fd) /4 ; + count =4 ; +major_evictions (fd, size, count); + } +igt_stop_hang_helper (); + }igt_stop_signal_helper (); igt_fixture
tests/gem_evict_everything.c +15 -0
@@ -234,6 +234,21 @@ igt_maintest_major_evictions (fd, size, count); } +if (igt_fork_hang_helper ()) { + igt_subtest("swapping-hang") +test_swapping_evictions (fd, size, count); + + igt_subtest("minor-hang") +test_minor_evictions (fd, size, count); + + igt_subtest("major-hang") { + size =3 *gem_aperture_size (fd) /4 ; + count =4 ; +test_major_evictions (fd, size, count); + } + +igt_stop_hang_helper (); + }igt_stop_signal_helper (); igt_fixture {
Signature · 1 line
2.1.1
PATCH 2/3 lib/core: Check for kernel error messages and WARN if any are found
At the end of a subtest, check for any WARNs or ERRORs (or worse!) emitted since the start of our test and FAIL the subtest if any are found. This will prevent silent false test positives due to oops being missed or being falsely reported as TIMEOUTs.
--- lib/igt_core.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 106 insertions(+), 10 deletions(-)
lib/igt_core.c +106 -10
@@ -208,6 +208,7 @@ static char *run_single_subtest = NULL;static bool run_single_subtest_found = false;static const char *in_subtest =NULL ;static struct timespec subtest_time; +static int subtest_kmsg =-1 ;static bool in_fixture = false;static bool test_with_subtests = false; static enum {
@@ -229,14 +230,14 @@ enum { __attribute__((format (printf,1 ,2 ))) static void kmsg(const char *format, ...) -#define KERN_EMER "<0>" -#define KERN_ALERT "<1>" -#define KERN_CRIT "<2>" -#define KERN_ERR "<3>" -#define KERN_WARNING "<4>" -#define KERN_NOTICE "<5>" -#define KERN_INFO "<6>" -#define KERN_DEBUG "<7>" +#define KMSG_EMER "<0>" +#define KMSG_ALERT "<1>" +#define KMSG_CRIT "<2>" +#define KMSG_ERR "<3>" +#define KMSG_WARNING "<4>" +#define KMSG_NOTICE "<5>" +#define KMSG_INFO "<6>" +#define KMSG_DEBUG "<7>" {va_list ap;FILE *file;
@@ -545,7 +546,7 @@ out:exit (ret ==-1 ?0 :IGT_EXIT_INVALID );if (!list_subtests) { -kmsg (KERN_INFO "%s: executing\n" , command_str); +kmsg (KMSG_INFO "%s: executing\n" , command_str);print_version ();oom_adjust_for_doom ();
@@ -679,7 +680,11 @@ bool __igt_run_subtest(const char *subtest_name)return false; } -kmsg (KERN_INFO "%s: starting subtest %s\n" , command_str, subtest_name); +kmsg (KMSG_INFO "%s: starting subtest %s\n" , command_str, subtest_name); + + subtest_kmsg =open ("/dev/kmsg" ,O_RDONLY |O_NONBLOCK ); +if (subtest_kmsg !=-1 ) +lseek (subtest_kmsg,0 ,SEEK_END );gettime (&subtest_time);return (in_subtest = subtest_name);
@@ -712,6 +717,82 @@ static bool succeeded_one = false;static bool failed_one = false;static int igt_exitcode =IGT_EXIT_SUCCESS ; +static char *readfile (int fd) +{ +char *buf; +int len, end; + + end =0 ; + len =4096 ; + buf =malloc (4096 ); +if (buf ==NULL ) +return NULL ; + +do { +char *newbuf; +int rem = len - end -1 ; +int ret =read (fd, buf + end, rem); +if (ret <=0 ) +break ; + + end += ret; +if (ret < rem) +break ; + + newbuf =realloc (buf, len *=2 ); +if (newbuf ==NULL ) +break ; + + buf = newbuf; + }while (1 ); + +if (end ==0 ) { +free (buf); +return NULL ; + } + + buf[end] ='\0' ; +return buf; +} + +static int print_kernlog(char *log, int prio) +#define PRIO_EMER 0 +#define PRIO_ALERT 1 +#define PRIO_CRIT 2 +#define PRIO_ERR 3 +#define PRIO_WARNING 4 +#define PRIO_NOTICE 5 +#define PRIO_INFO 6 +#define PRIO_DEBUG 7 +{ +int count =0 ; + +do { +char *s, *t; +int lvl; + + s =strchr (log,';' ); +if (s ==NULL ) +break ; + + t =strchr (s +1 ,'\n' ); +if (t ==NULL ) +break ; + + *t ='\0' ; + + lvl =atoi (log); +if (lvl <= prio) { +puts (s+1 ); + count++; + } + + log = t +1 ; + }while (*log); + +return count; +} +static void exit_subtest (const char *) __attribute__((noreturn));static void exit_subtest (const char *result) {
@@ -722,7 +803,22 @@ static void exit_subtest(const char *result) elapsed = now.tv_sec - subtest_time.tv_sec; elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; +if (subtest_kmsg !=-1 ) { +char *log; + + log =readfile (subtest_kmsg); +if (log) { +if (print_kernlog (log,PRIO_WARNING ) && +strcmp (result,"FAIL" )) + result ="WARN" ; +free (log); + } +close (subtest_kmsg); + subtest_kmsg =-1 ; + } +printf ("Subtest %s: %s (%.3fs)\n" , in_subtest, result, elapsed); + in_subtest =NULL ;longjmp (igt_subtest_jmpbuf,1 ); }
Signature · 1 line
2.1.1
PATCH 3/3 reg-read-8
In reply to Chris Wilson--- tools/intel_reg_read.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-)
tools/intel_reg_read.c +30 -20
@@ -46,13 +46,19 @@ static void bit_decode(uint32_t reg)printf ("\n" ); } -static void dump_range (uint32_t start,uint32_t end) +static void dump_range (uint32_t start,uint32_t end,int readq) {int i; -for (i = start; i < end; i +=4 ) -printf ("0x%X : 0x%X\n" , i, - *(volatile uint32_t *)((volatile char *)mmio + i)); +if (readq) { +for (i = start; i < end; i +=8 ) +printf ("0x%X : 0x%llX\n" , i, + (long long unsigned )*(volatile uint64_t *)((volatile char *)mmio + i)); + }else { +for (i = start; i < end; i +=4 ) +printf ("0x%X : 0x%X\n" , i, + *(volatile uint32_t *)((volatile char *)mmio + i)); + } }static void usage (char *cmdname)
@@ -74,9 +80,13 @@ int main(int argc, char** argv)int full_dump =0 ;int decode_bits =0 ;int dwords =1 ; +int readq =0 ; -while ((ch =getopt (argc, argv,"dfhc:" )) !=-1 ) { +while ((ch =getopt (argc, argv,"8dfhc:" )) !=-1 ) {switch (ch) { +case '8' : + readq =1 ; +break ;case 'd' : decode_bits =1 ;break ;
@@ -110,24 +120,24 @@ int main(int argc, char** argv)intel_register_access_init (intel_get_pci_device (),0 );if (full_dump) { -dump_range (0x00000 ,0x00fff );/* VGA registers */ -dump_range (0x02000 ,0x02fff );/* instruction, memory, interrupt control registers */ -dump_range (0x03000 ,0x031ff );/* FENCE and PPGTT control registers */ -dump_range (0x03200 ,0x03fff );/* frame buffer compression registers */ -dump_range (0x05000 ,0x05fff );/* I/O control registers */ -dump_range (0x06000 ,0x06fff );/* clock control registers */ -dump_range (0x07000 ,0x07fff );/* 3D internal debug registers */ -dump_range (0x07400 ,0x088ff );/* GPE debug registers */ -dump_range (0x0a000 ,0x0afff );/* display palette registers */ -dump_range (0x10000 ,0x13fff );/* MMIO MCHBAR */ -dump_range (0x30000 ,0x3ffff );/* overlay registers */ -dump_range (0x60000 ,0x6ffff );/* display engine pipeline registers */ -dump_range (0x70000 ,0x72fff );/* display and cursor registers */ -dump_range (0x73000 ,0x73fff );/* performance counters */ +dump_range (0x00000 ,0x00fff ,0 );/* VGA registers */ +dump_range (0x02000 ,0x02fff ,0 );/* instruction, memory, interrupt control registers */ +dump_range (0x03000 ,0x031ff ,0 );/* FENCE and PPGTT control registers */ +dump_range (0x03200 ,0x03fff ,0 );/* frame buffer compression registers */ +dump_range (0x05000 ,0x05fff ,0 );/* I/O control registers */ +dump_range (0x06000 ,0x06fff ,0 );/* clock control registers */ +dump_range (0x07000 ,0x07fff ,0 );/* 3D internal debug registers */ +dump_range (0x07400 ,0x088ff ,0 );/* GPE debug registers */ +dump_range (0x0a000 ,0x0afff ,0 );/* display palette registers */ +dump_range (0x10000 ,0x13fff ,0 );/* MMIO MCHBAR */ +dump_range (0x30000 ,0x3ffff ,0 );/* overlay registers */ +dump_range (0x60000 ,0x6ffff ,0 );/* display engine pipeline registers */ +dump_range (0x70000 ,0x72fff ,0 );/* display and cursor registers */ +dump_range (0x73000 ,0x73fff ,0 );/* performance counters */ }else {for (i=0 ; i < argc; i++) {sscanf (argv[i],"0x%x" , ®); -dump_range (reg, reg + (dwords *4 )); +dump_range (reg, reg + dwords * (readq ?8 :4 ), readq);if (decode_bits)bit_decode (*(volatile uint32_t *)((volatile char *)mmio + reg));
Signature · 1 line
2.1.1
Re: [PATCH 1/3] igt/gem_evict_(alignment|everything): contend with GPU hangs
In reply to Chris WilsonThese are not the igt I was looking for.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 1/3 igt/gem_mmap_wc: Exercise mmap(wc) interface
In reply to Chris Wilson--- lib/ioctl_wrappers.c | 76 ++++++++++ lib/ioctl_wrappers.h | 7 +- tests/.gitignore | 1 + tests/Makefile.am | 2 + tests/Makefile.sources | 1 + tests/gem_mmap_wc.c | 365 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 tests/gem_mmap_wc.c
lib/ioctl_wrappers.c +76 -0
@@ -467,6 +467,82 @@ void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot)return ptr; } +struct local_i915_gem_mmap_v2 { +uint32_t handle; +uint32_t pad; +uint64_t offset; +uint64_t size; +uint64_t addr_ptr; +uint64_t flags; +#define I915_MMAP_WC 0x1 +}; +#define LOCAL_IOCTL_I915_GEM_MMAP_v2 DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MMAP, struct local_i915_gem_mmap_v2) + +bool gem_mmap__has_wc (int fd) +{ +static int has_wc =-1 ; + +if (has_wc ==-1 ) { +struct drm_i915_getparam gp; +int val =-1 ; + + has_wc =0 ; + +memset (&gp,0 ,sizeof (gp)); + gp.param =29 ;/* MMAP_VERSION */ + gp.value = &val; + +/* Do we have the new mmap_ioctl? */ +ioctl (fd,DRM_IOCTL_I915_GETPARAM , &gp); +if (val >=1 ) { +struct local_i915_gem_mmap_v2 arg; + +/* Does this device support wc-mmaps ? */ +memset (&arg,0 ,sizeof (arg)); + arg.handle =gem_create (fd,4096 ); + arg.offset =0 ; + arg.size =4096 ; + arg.flags =I915_MMAP_WC ; + has_wc =drmIoctl (fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg) ==0 ; +gem_close (fd, arg.handle); + } + } + +return has_wc >0 ; +} + +/** +* gem_mmap__wc: +* @fd: open i915 drm file descriptor +* @handle: gem buffer object handle +* @size: size of the gem buffer +* @prot: memory protection bits as used by mmap() +* +* This functions wraps up procedure to establish a memory mapping through +* direct cpu access, bypassing the gpu and cpu caches completely. +* +* Returns: A pointer to the created memory mapping. +*/ +void *gem_mmap__wc (int fd,uint32_t handle,int size,int prot) +{ +struct local_i915_gem_mmap_v2 arg; + + errno =ENOSYS ; +if (!gem_mmap__has_wc (fd)) +return NULL ; + +memset (&arg,0 ,sizeof (arg)); + arg.handle = handle; + arg.offset =0 ; + arg.size = size; + arg.flags =I915_MMAP_WC ; +if (drmIoctl (fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg)) +return NULL ; + + errno =0 ; +return (void *)(uintptr_t )arg.addr_ptr; +} +/** * gem_mmap__cpu: * @fd: open i915 drm file descriptor
lib/ioctl_wrappers.h +6 -1
@@ -60,8 +60,13 @@ uint32_t __gem_create(int fd, int size);uint32_t gem_create (int fd,int size);void gem_execbuf (int fd,struct drm_i915_gem_execbuffer2 *execbuf); -void *gem_mmap__gtt (int fd,uint32_t handle,int size,int prot);void *gem_mmap__cpu (int fd,uint32_t handle,int size,int prot); +void *gem_mmap__gtt (int fd,uint32_t handle,int size,int prot); + +bool gem_mmap__has_wc (int fd); +void *gem_mmap__wc (int fd,uint32_t handle,int size,int prot); +#define igt_require_mmap_wc (x) igt_require(gem_mmap__has_wc(fd)) +/** * gem_mmap: *
tests/.gitignore +1 -0
@@ -59,6 +59,7 @@ gem_madvise gem_media_fill gem_mmap gem_mmap_gtt +gem_mmap_wc gem_mmap_offset_exhaustion gem_multi_bsd_sync_loop gem_non_secure_batch
tests/Makefile.am +2 -0
@@ -58,6 +58,8 @@ gem_flink_race_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) gem_flink_race_LDADD = $(LDADD) -lpthread gem_mmap_gtt_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) gem_mmap_gtt_LDADD = $(LDADD) -lpthread +gem_mmap_wc_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) +gem_mmap_wc_LDADD = $(LDADD) -lpthread gem_threaded_access_tiled_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) gem_threaded_access_tiled_LDADD = $(LDADD) -lpthread gem_tiled_swapping_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
tests/Makefile.sources +1 -0
@@ -44,6 +44,7 @@ TESTS_progs_M = \ gem_madvise \ gem_mmap \ gem_mmap_gtt \ + gem_mmap_wc \ gem_partial_pwrite_pread \ gem_persistent_relocs \ gem_pipe_control_store_loop \
tests/gem_mmap_wc.c new file +365 -0
365 lines not on this page · raw message
Signature · 1 line
2.1.1
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/3 igt/gem_gtt_speed: compare against WC mmaps
--- tests/gem_gtt_speed.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-)
tests/gem_gtt_speed.c +62 -1
@@ -206,6 +206,27 @@ int main(int argc, char **argv)igt_info ("Time to read %dk through a GTT map: %7.3fµs\n" , size/1024 ,elapsed (&start, &end, loop)); +if (gem_mmap__has_wc (fd)) { +gettimeofday (&start,NULL ); +for (loop =0 ; loop <1000 ; loop++) { +uint32_t *base =gem_mmap__wc (fd, handle, size,PROT_READ |PROT_WRITE ); +volatile uint32_t *ptr = base; +int x =0 ; + +for (i =0 ; i < size/sizeof (*ptr); i++) + x += ptr[i]; + +/* force overtly clever gcc to actually compute x */ + ptr[0 ] = x; + +munmap (base, size); + } +gettimeofday (&end,NULL ); +igt_info ("Time to read %dk through a WC map: %7.3fµs\n" , + size/1024 ,elapsed (&start, &end, loop)); + } + +/* mmap write */ gettimeofday (&start,NULL );for (loop =0 ; loop <1000 ; loop++) {
@@ -221,6 +242,23 @@ int main(int argc, char **argv)igt_info ("Time to write %dk through a GTT map: %7.3fµs\n" , size/1024 ,elapsed (&start, &end, loop)); +if (gem_mmap__has_wc (fd)) { +/* mmap write */ +gettimeofday (&start,NULL ); +for (loop =0 ; loop <1000 ; loop++) { +uint32_t *base =gem_mmap__wc (fd, handle, size,PROT_READ |PROT_WRITE ); +volatile uint32_t *ptr = base; + +for (i =0 ; i < size/sizeof (*ptr); i++) + ptr[i] = i; + +munmap (base, size); + } +gettimeofday (&end,NULL ); +igt_info ("Time to write %dk through a WC map: %7.3fµs\n" , + size/1024 ,elapsed (&start, &end, loop)); + } +/* mmap clear */ gettimeofday (&start,NULL );for (loop =0 ; loop <1000 ; loop++) {
@@ -232,6 +270,19 @@ int main(int argc, char **argv)igt_info ("Time to clear %dk through a GTT map: %7.3fµs\n" , size/1024 ,elapsed (&start, &end, loop)); +if (gem_mmap__has_wc (fd)) { +/* mmap clear */ +gettimeofday (&start,NULL ); +for (loop =0 ; loop <1000 ; loop++) { +uint32_t *base =gem_mmap__wc (fd, handle, size,PROT_READ |PROT_WRITE ); +memset (base,0 , size); +munmap (base, size); + } +gettimeofday (&end,NULL ); +igt_info ("Time to clear %dk through a WC map: %7.3fµs\n" , + size/1024 ,elapsed (&start, &end, loop)); + } +gettimeofday (&start,NULL );{uint32_t *base =gem_mmap (fd, handle, size,PROT_READ |PROT_WRITE );for (loop =0 ; loop <1000 ; loop++)
@@ -241,6 +292,17 @@ int main(int argc, char **argv)igt_info ("Time to clear %dk through a cached GTT map: %7.3fµs\n" , size/1024 ,elapsed (&start, &end, loop)); +if (gem_mmap__has_wc (fd)) { +gettimeofday (&start,NULL );{ +uint32_t *base =gem_mmap__wc (fd, handle, size,PROT_READ |PROT_WRITE ); +for (loop =0 ; loop <1000 ; loop++) +memset (base,0 , size); +munmap (base, size); + }gettimeofday (&end,NULL ); +igt_info ("Time to clear %dk through a cached WC map: %7.3fµs\n" , + size/1024 ,elapsed (&start, &end, loop)); + } +/* mmap read */ gettimeofday (&start,NULL );for (loop =0 ; loop <1000 ; loop++) {
@@ -323,7 +385,6 @@ int main(int argc, char **argv) size *=4 ; } - }gem_close (fd, handle);
Signature · 1 line
2.1.1
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/3 igt/gem_concurrent_blit: Exercise wc mappings
In reply to Chris Wilson--- tests/gem_concurrent_blit.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tests/gem_concurrent_blit.c +14 -0
@@ -159,6 +159,18 @@ gttX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) }static drm_intel_bo * +wc_create_bo (drm_intel_bufmgr *bufmgr,int width,int height) +{ +drm_intel_bo *bo; + +igt_require_mmap_wc (fd); + + bo =unmapped_create_bo (bufmgr, width, height); + bo->virtual =gem_mmap__wc (fd, bo->handle, bo->size,PROT_READ |PROT_WRITE ); +return bo; +} + +static drm_intel_bo *gpu_create_bo (drm_intel_bufmgr *bufmgr,int width,int height) {return unmapped_create_bo (bufmgr, width, height);
@@ -287,6 +299,8 @@ struct access_mode access_modes[] = { .create_bo = gtt_create_bo, .name = "gtt" }, { .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo, .create_bo = gttX_create_bo, .name = "gttX" }, + { .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo, + .create_bo = wc_create_bo, .name = "wc" }, { .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo, .create_bo = gpu_create_bo, .name = "gpu" }, { .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo,
Signature · 1 line
2.1.1
PATCH 1/1 intel: New libdrm interface to create unbound wc user mappings for objects
In reply to Chris WilsonFrom: Akash Goel <[email protected]>
A new libdrm interface 'drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with mmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering
The drm_i915_gem_mmap structure (for the DRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameter I915_PARAM_HAS_EXT_MMAP has been added for versioning the ioctl interface.
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
--- include/drm/i915_drm.h | 9 ++++ intel/intel_bufmgr.h | 3 ++ intel/intel_bufmgr_gem.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+)
include/drm/i915_drm.h +9 -0
@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_MMAP_VERSION 29 typedef struct drm_i915_getparam { int param;
@@ -487,6 +488,14 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +/** +* Flags for extended behaviour. +* +* Added in version 2. +*/ +__u64 flags; +#define I915_MMAP_WC 0x1 };struct drm_i915_gem_mmap_gtt {
intel/intel_bufmgr.h +3 -0
@@ -177,6 +177,9 @@ void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,int drm_intel_gem_bo_map_unsynchronized (drm_intel_bo *bo);int drm_intel_gem_bo_map_gtt (drm_intel_bo *bo);int drm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc (drm_intel_bo *bo); +int drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo);int drm_intel_gem_bo_get_reloc_count (drm_intel_bo *bo);void drm_intel_gem_bo_clear_relocs (drm_intel_bo *bo,int start);
intel/intel_bufmgr_gem.c +124 -0
148 lines not on this page · raw message
Signature · 1 line
1.9.2
Re: [PATCH] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 25 lines · On Sat, Oct 25, 2014 at 05:21:53PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.
Quoted 6 lines
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>From a quick glance at the patch:
It looks like you copy/pasted the map() implementation and changed a few things here and there instead of adding flag to drm_intel_gem_bo_map() and reusing the current code.
Can we expose another version of map that takes flags (_WC, _UNSYNCHRONIZED, ...) instead of starting to have every single combination possible?
Do we really need a separate mem_wc_virtual? Using _map() or _map_wc() in an exclusively way makes some sense to me.
With the introduction of mem_wc_virtual, you left aside the vma cache handling and so we'll never end up unmapping it, drm_intel_gem_bo_free() doesn't unmap it either, ...
I'd just expect users to use _unmap().
Signature · 1 line
Damien
Quoted 210 lines
--- include/drm/i915_drm.h | 9 ++++ intel/intel_bufmgr.h | 3 ++ intel/intel_bufmgr_gem.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+)include/drm/i915_drm.h +9
-0@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_MMAP_VERSION 29 typedef struct drm_i915_getparam { int param;@@ -487,6 +488,14 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +/** +* Flags for extended behaviour. +* +* Added in version 2. +*/ +__u64 flags; +#define I915_MMAP_WC 0x1 };struct drm_i915_gem_mmap_gtt {intel/intel_bufmgr.h +3
-0@@ -177,6 +177,9 @@ void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,int drm_intel_gem_bo_map_unsynchronized (drm_intel_bo *bo);int drm_intel_gem_bo_map_gtt (drm_intel_bo *bo);int drm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc (drm_intel_bo *bo); +int drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo);int drm_intel_gem_bo_get_reloc_count (drm_intel_bo *bo);void drm_intel_gem_bo_clear_relocs (drm_intel_bo *bo,int start);intel/intel_bufmgr_gem.c +124
-0@@ -184,6 +184,8 @@ struct _drm_intel_bo_gem {int reloc_count;/** Mapped address for the buffer, saved across map/unmap cycles */ void *mem_virtual; +/** Uncached Mapped address for the buffer, saved across map/unmap cycles */ +void *mem_wc_virtual;/** GTT virtual address for the buffer, saved across map/unmap cycles */ void *gtt_virtual;/** @@ -1267,6 +1269,121 @@ static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) } } +static int +map_wc (drm_intel_bo *bo) +{ +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +int ret; + +if (bo_gem->is_userptr) +return -EINVAL ; + +if (bo_gem->map_count++ ==0 ) +drm_intel_gem_bo_open_vma (bufmgr_gem, bo_gem); + +/* Get a mapping of the buffer if we haven't before. */ +if (bo_gem->mem_wc_virtual ==NULL ) { +struct drm_i915_gem_mmap mmap_arg; + +DBG ("bo_map_wc: mmap %d (%s), map_count=%d\n" , + bo_gem->gem_handle, bo_gem->name, bo_gem->map_count); + +VG_CLEAR (mmap_arg); + mmap_arg.handle = bo_gem->gem_handle; +/* To indicate the uncached virtual mapping to KMD */ + mmap_arg.flags =I915_MMAP_WC ; + mmap_arg.offset =0 ; + mmap_arg.size = bo->size; + ret =drmIoctl (bufmgr_gem->fd, +DRM_IOCTL_I915_GEM_MMAP , + &mmap_arg); +if (ret !=0 ) { + ret = -errno; +DBG ("%s:%d: Error mapping buffer %d (%s): %s .\n" , + __FILE__, __LINE__, bo_gem->gem_handle, + bo_gem->name,strerror (errno)); +if (--bo_gem->map_count ==0 ) +drm_intel_gem_bo_close_vma (bufmgr_gem, bo_gem); +pthread_mutex_unlock (&bufmgr_gem->lock); +return ret; + } +VG (VALGRIND_MALLOCLIKE_BLOCK (mmap_arg.addr_ptr, mmap_arg.size,0 ,1 )); + bo_gem->mem_wc_virtual = (void *)(uintptr_t ) mmap_arg.addr_ptr; + } + + bo->virtual = bo_gem->mem_wc_virtual; + +DBG ("bo_map_wc: %d (%s) -> %p\n" , bo_gem->gem_handle, bo_gem->name, + bo_gem->mem_wc_virtual); + +return 0 ; +} + +/* To be used in a similar way to mmap_gtt */ +drm_public int +drm_intel_gem_bo_map_wc (drm_intel_bo *bo) { +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +struct drm_i915_gem_set_domain set_domain; +int ret; + +pthread_mutex_lock (&bufmgr_gem->lock); + + ret =map_wc (bo); +if (ret) { +pthread_mutex_unlock (&bufmgr_gem->lock); +return ret; + } + +/* Now move it to the GTT domain so that the GPU and CPU +* caches are flushed and the GPU isn't actively using the +* buffer. +* +* The domain change is done even for the objects which +* are not bounded. For them first the pages are acquired, +* before the domain change. +*/ +VG_CLEAR (set_domain); + set_domain.handle = bo_gem->gem_handle; + set_domain.read_domains =I915_GEM_DOMAIN_GTT ; + set_domain.write_domain =I915_GEM_DOMAIN_GTT ; + ret =drmIoctl (bufmgr_gem->fd, +DRM_IOCTL_I915_GEM_SET_DOMAIN , + &set_domain); +if (ret !=0 ) { +DBG ("%s:%d: Error setting domain %d: %s\n" , + __FILE__, __LINE__, bo_gem->gem_handle, +strerror (errno)); + } +drm_intel_gem_bo_mark_mmaps_incoherent (bo); +VG (VALGRIND_MAKE_MEM_DEFINED (bo_gem->mem_virtual, bo->size)); +pthread_mutex_unlock (&bufmgr_gem->lock); + +return 0 ; +} + +drm_public int +drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo) { +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +#ifdef HAVE_VALGRIND +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +#endif +int ret; + +pthread_mutex_lock (&bufmgr_gem->lock); + + ret =map_wc (bo); +if (ret ==0 ) { +drm_intel_gem_bo_mark_mmaps_incoherent (bo); +VG (VALGRIND_MAKE_MEM_DEFINED (bo_gem->gtt_virtual, bo->size)); + } + +pthread_mutex_unlock (&bufmgr_gem->lock); + +return ret; +} +static int drm_intel_gem_bo_map (drm_intel_bo *bo,int write_enable) {drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;@@ -1293,6 +1410,7 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)VG_CLEAR (mmap_arg); mmap_arg.handle = bo_gem->gem_handle; + mmap_arg.flags =0 ; mmap_arg.offset =0 ; mmap_arg.size = bo->size; ret = drmIoctl(bufmgr_gem->fd,@@ -1553,6 +1671,12 @@ static int drm_intel_gem_bo_unmap(drm_intel_bo *bo) } drm_public int +drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo) +{ +return drm_intel_gem_bo_unmap (bo); +} + +drm_public intdrm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo) {return drm_intel_gem_bo_unmap (bo);Signature · 6 lines
1.9.2 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 33 lines · Damien Lespiau
Quoted 25 lines · On Sat, Oct 25, 2014 at 05:21:53PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.Quoted 4 lines
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>From a quick glance at the patch:
Quoted 8 lines
It looks like you copy/pasted the
map()implementation and changed a few things here and there instead of adding flag todrm_intel_gem_bo_map()and reusing the current code.Can we expose another version of map that takes flags (
_WC,_UNSYNCHRONIZED, ...) instead of starting to have every single combination possible?
Thanks for the review. Yes its almost a copy-paste of the 'mmap_gtt' implementation.
Yes adding a new flag parameter could be an alternative.
Quoted 3 lines
Do we really need a separate
mem_wc_virtual? Using_map()or_map_wc()in an exclusively way makes some sense to me.
Initially made _map() & _map_wc() exclusive to each other. Had a discussion with Chris, he suggested to maintain all 3 mappings i.e allow them to co-exist.
Quoted 4 lines
With the introduction of
mem_wc_virtual, you left aside the vma cache handling and so we'll never end up unmapping it,drm_intel_gem_bo_free()doesn't unmap it either, ...
Sorry I completely missed this. Thanks for spotting this. Will do the needful.
Best Regards
Akash
Quoted 2 lines
I'd just expect users to use
_unmap().
Re: [PATCH] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 27 lines · Akash Goel
Quoted 26 lines · Damien Lespiau
Quoted 25 lines · On Sat, Oct 25, 2014 at 05:21:53PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>
I don't get s-o-b for header contributions ;-)
Quoted 15 lines
Quoted 10 lines
From a quick glance at the patch:
It looks like you copy/pasted the
map()implementation and changed a few things here and there instead of adding flag todrm_intel_gem_bo_map()and reusing the current code.Can we expose another version of map that takes flags (
_WC,_UNSYNCHRONIZED, ...) instead of starting to have every single combination possible?Thanks for the review. Yes its almost a copy-paste of the '
mmap_gtt' implementation.
Yes adding a new flag parameter could be an alternative.
Quoted 7 lines
Quoted 3 lines
Do we really need a separate
mem_wc_virtual? Using_map()or_map_wc()in an exclusively way makes some sense to me.Initially made
_map()&_map_wc()exclusive to each other. Had a discussion with Chris, he suggested to maintain all 3 mappings i.e allow them to co-exist.
For example, in the ddx we may want to use either GTT or WC mapping depending on the actual path. WC if we know we can use manual detiling, otherwise we use GTT and benefit from the linear view (or we have to wrap all tiled access with much slower accessors). We may even mix WC/CPU mappings - e.g. first write through the CPU mapping whilst we know the object is still in the CPU domain, and then switch to updating the object when it is on the GPU using WC. (Again see examples in the ddx). I can foresee that we can benefit from keeping each of the mmappings cached.
Quoted 6 lines
Quoted 4 lines
With the introduction of
mem_wc_virtual, you left aside the vma cache handling and so we'll never end up unmapping it,drm_intel_gem_bo_free()doesn't unmap it either, ...Sorry I completely missed this. Thanks for spotting this. Will do the needful.
Also, before trying to use the mmap(wc), you should check that it exists! Otherwise you just return an ordinary mmap(wb) to the user and corruption ensues.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH v3 1/1 intel: New libdrm interface to create unbound wc user mappings for objects
In reply to [email protected]From: Akash Goel <[email protected]>
A new libdrm interface 'drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with mmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering
The drm_i915_gem_mmap structure (for the DRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameter I915_PARAM_HAS_EXT_MMAP has been added for versioning the ioctl interface.
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping & reduced the vma limit (Chris)
--- include/drm/i915_drm.h | 9 +++ intel/intel_bufmgr.h | 3 + intel/intel_bufmgr_gem.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+)
include/drm/i915_drm.h +9 -0
@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_MMAP_VERSION 29 typedef struct drm_i915_getparam { int param;
@@ -487,6 +488,14 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +/** +* Flags for extended behaviour. +* +* Added in version 2. +*/ +__u64 flags; +#define I915_MMAP_WC 0x1 };struct drm_i915_gem_mmap_gtt {
intel/intel_bufmgr.h +3 -0
@@ -177,6 +177,9 @@ void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,int drm_intel_gem_bo_map_unsynchronized (drm_intel_bo *bo);int drm_intel_gem_bo_map_gtt (drm_intel_bo *bo);int drm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc (drm_intel_bo *bo); +int drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo);int drm_intel_gem_bo_get_reloc_count (drm_intel_bo *bo);void drm_intel_gem_bo_clear_relocs (drm_intel_bo *bo,int start);
intel/intel_bufmgr_gem.c +150 -0
222 lines not on this page · raw message
Signature · 6 lines
1.9.2 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 25 lines · On Tue, Oct 28, 2014 at 06:39:27PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.
Quoted 7 lines
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping & reduced the vma limit (Chris)Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>
I'm still not super convinced by the full copy and paste of the function where all I can see changing is the pointer storing the virtual address and the flags. Something I'm missing? What do others think (I'm not the maintainer of anything in libdrm).
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
In reply to [email protected]intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_purge_vma_cache(drm_intel_bufmgr_gem *bufmgr_gem) · line 1143
Quoted 9 lines · On Tue, Oct 28, 2014 at 06:39:27PM +0530, [email protected] wrote:
intel/intel_bufmgr_gem.c +2
-0@@ -1126,6 +1136,8 @@ static void drm_intel_gem_bo_purge_vma_cache(drm_intel_bufmgr_gem *bufmgr_gem)/* We may need to evict a few entries in order to create new mmaps */ limit = bufmgr_gem->vma_max -2 *bufmgr_gem->vma_open; +if (bufmgr_gem->has_ext_mmap) + limit -= bufmgr_gem->vma_open;if (limit <0 ) limit =0 ;
Aren't we being overly aggressive in purging the vma cache with this new code? I guess it depends on the workload but I don't think the WC mapping is likely to be used in addition to the other two often enough to warrant a max - 3 * open;
Quoted 30 lines
intel/intel_bufmgr_gem.c +30
-0+static int +map_wc (drm_intel_bo *bo) +{ +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +int ret; + +if (bo_gem->is_userptr) +return -EINVAL ; + +if (!bufmgr_gem->has_ext_mmap) +return -EINVAL ; + +if (bo_gem->map_count++ ==0 ) +drm_intel_gem_bo_open_vma (bufmgr_gem, bo_gem); + +/* Get a mapping of the buffer if we haven't before. */ +if (bo_gem->mem_wc_virtual ==NULL ) { +struct drm_i915_gem_mmap mmap_arg; + +DBG ("bo_map_wc: mmap %d (%s), map_count=%d\n" , + bo_gem->gem_handle, bo_gem->name, bo_gem->map_count); + +VG_CLEAR (mmap_arg); + mmap_arg.handle = bo_gem->gem_handle; +/* To indicate the uncached virtual mapping to KMD */ + mmap_arg.flags =I915_MMAP_WC ; + mmap_arg.offset =0 ; + mmap_arg.size = bo->size; + ret = drmIoctl(bufmgr_gem->fd,
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) · line 1330
Quoted 10 lines
intel/intel_bufmgr_gem.c +10
-0+DRM_IOCTL_I915_GEM_MMAP , + &mmap_arg); +if (ret !=0 ) { + ret = -errno; +DBG ("%s:%d: Error mapping buffer %d (%s): %s .\n" , + __FILE__, __LINE__, bo_gem->gem_handle, + bo_gem->name,strerror (errno)); +if (--bo_gem->map_count ==0 ) +drm_intel_gem_bo_close_vma (bufmgr_gem, bo_gem); +pthread_mutex_unlock (&bufmgr_gem->lock);
There's an unlock() here (and no lock()!), but the locking is hanled by the higher level functions.
Quoted 40 lines
intel/intel_bufmgr_gem.c +40
-0+return ret; + } +VG (VALGRIND_MALLOCLIKE_BLOCK (mmap_arg.addr_ptr, mmap_arg.size,0 ,1 )); + bo_gem->mem_wc_virtual = (void *)(uintptr_t ) mmap_arg.addr_ptr; + } + + bo->virtual = bo_gem->mem_wc_virtual; + +DBG ("bo_map_wc: %d (%s) -> %p\n" , bo_gem->gem_handle, bo_gem->name, + bo_gem->mem_wc_virtual); + +return 0 ; +} + +/* To be used in a similar way to mmap_gtt */ +drm_public int +drm_intel_gem_bo_map_wc (drm_intel_bo *bo) { +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +struct drm_i915_gem_set_domain set_domain; +int ret; + +pthread_mutex_lock (&bufmgr_gem->lock); + + ret =map_wc (bo); +if (ret) { +pthread_mutex_unlock (&bufmgr_gem->lock); +return ret; + } + +/* Now move it to the GTT domain so that the GPU and CPU +* caches are flushed and the GPU isn't actively using the +* buffer. +* +* The domain change is done even for the objects which +* are not bounded. For them first the pages are acquired, +* before the domain change. +*/ +VG_CLEAR (set_domain); + set_domain.handle = bo_gem->gem_handle;
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) · line 1380
Quoted 10 lines
intel/intel_bufmgr_gem.c +10
-0+ set_domain.read_domains =I915_GEM_DOMAIN_GTT ; + set_domain.write_domain =I915_GEM_DOMAIN_GTT ; + ret =drmIoctl (bufmgr_gem->fd, +DRM_IOCTL_I915_GEM_SET_DOMAIN , + &set_domain); +if (ret !=0 ) { +DBG ("%s:%d: Error setting domain %d: %s\n" , + __FILE__, __LINE__, bo_gem->gem_handle, +strerror (errno)); + }
Why move the buffer to the GTT domain and not the CPU domain here?
Quoted 53 lines
intel/intel_bufmgr_gem.c +35
-0+drm_intel_gem_bo_mark_mmaps_incoherent (bo); +VG (VALGRIND_MAKE_MEM_DEFINED (bo_gem->mem_wc_virtual, bo->size)); +pthread_mutex_unlock (&bufmgr_gem->lock); + +return 0 ; +} + +drm_public int +drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo) { +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +#ifdef HAVE_VALGRIND +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +#endif +int ret; + +pthread_mutex_lock (&bufmgr_gem->lock); + + ret =map_wc (bo); +if (ret ==0 ) { +drm_intel_gem_bo_mark_mmaps_incoherent (bo); +VG (VALGRIND_MAKE_MEM_DEFINED (bo_gem->mem_wc_virtual, bo->size)); + } + +pthread_mutex_unlock (&bufmgr_gem->lock); + +return ret; +} +static int drm_intel_gem_bo_map (drm_intel_bo *bo,int write_enable) {drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;@@ -1293,6 +1432,7 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)VG_CLEAR (mmap_arg); mmap_arg.handle = bo_gem->gem_handle; + mmap_arg.flags =0 ; mmap_arg.offset =0 ; mmap_arg.size = bo->size; ret = drmIoctl(bufmgr_gem->fd,@@ -1553,6 +1693,12 @@ static int drm_intel_gem_bo_unmap(drm_intel_bo *bo) } drm_public int +drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo) +{ +return drm_intel_gem_bo_unmap (bo); +} + +drm_public intdrm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo) {return drm_intel_gem_bo_unmap (bo);
intel/intel_bufmgr_gem.c drm_intel_bufmgr_gem_init(int fd, int batch_size) · line 3689
Quoted 6 lines
intel/intel_bufmgr_gem.c +3
-0@@ -3538,6 +3684,10 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size) ret =drmIoctl (bufmgr_gem->fd,DRM_IOCTL_I915_GETPARAM , &gp); bufmgr_gem->has_vebox = (ret ==0 ) & (*gp.value >0 ); + gp.param =I915_PARAM_MMAP_VERSION ; + ret =drmIoctl (bufmgr_gem->fd,DRM_IOCTL_I915_GETPARAM , &gp); + bufmgr_gem->has_ext_mmap = (ret ==0 ) & (*gp.value >0 );
It looks like this works, but can we have && instead?
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 30 lines · Damien Lespiau
Quoted 30 lines
intel/intel_bufmgr_gem.c +30
-0+/* To be used in a similar way to mmap_gtt */ +drm_public int +drm_intel_gem_bo_map_wc (drm_intel_bo *bo) { +drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; +drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; +struct drm_i915_gem_set_domain set_domain; +int ret; + +pthread_mutex_lock (&bufmgr_gem->lock); + + ret =map_wc (bo); +if (ret) { +pthread_mutex_unlock (&bufmgr_gem->lock); +return ret; + } + +/* Now move it to the GTT domain so that the GPU and CPU +* caches are flushed and the GPU isn't actively using the +* buffer. +* +* The domain change is done even for the objects which +* are not bounded. For them first the pages are acquired, +* before the domain change. +*/ +VG_CLEAR (set_domain); + set_domain.handle = bo_gem->gem_handle; + set_domain.read_domains =I915_GEM_DOMAIN_GTT ; + set_domain.write_domain =I915_GEM_DOMAIN_GTT ; + ret = drmIoctl(bufmgr_gem->fd, + DRM_IOCTL_I915_GEM_SET_DOMAIN,
Quoted 8 lines
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) · line 1380
Quoted 6 lines
intel/intel_bufmgr_gem.c +6
-0+ &set_domain); +if (ret !=0 ) { +DBG ("%s:%d: Error setting domain %d: %s\n" , + __FILE__, __LINE__, bo_gem->gem_handle, +strerror (errno)); + }Why move the buffer to the GTT domain and not the CPU domain here?
The entire point of the mmap(wc) interface is to access the buffer outside of the CPU cache domain, and not using the GTT indirection.
We have 3 cache domains: in GPU, in CPU, neither (aka GTT). -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
In reply to Damien LespiauQuoted 15 lines · Damien Lespiau
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_purge_vma_cache(drm_intel_bufmgr_gem *bufmgr_gem) · line 1143
Quoted 9 lines · On Tue, Oct 28, 2014 at 06:39:27PM +0530, [email protected] wrote:
intel/intel_bufmgr_gem.c +2
-0@@ -1126,6 +1136,8 @@ static void drm_intel_gem_bo_purge_vma_cache(drm_intel_bufmgr_gem *bufmgr_gem)/* We may need to evict a few entries in order to create new mmaps */ limit = bufmgr_gem->vma_max -2 *bufmgr_gem->vma_open; +if (bufmgr_gem->has_ext_mmap) + limit -= bufmgr_gem->vma_open;if (limit <0 ) limit =0 ;Aren't we being overly aggressive in purging the vma cache with this new code? I guess it depends on the workload but I don't think the WC mapping is likely to be used in addition to the other two often enough to warrant a max - 3 * open;
And if they do, you've just exceeded their limit. And it conceivably that you will have bo with all 3 vma mappings, though I only expect 2 to be active in any single lifetime. The patch is correct regarding the code as it exists, you may want to argue for finer tracking of vma_open and vma_cached, but that would require a different approach.
Quoted 14 lines
Quoted 14 lines
intel/intel_bufmgr_gem.c +14
-0+/* Now move it to the GTT domain so that the GPU and CPU +* caches are flushed and the GPU isn't actively using the +* buffer. +* +* The domain change is done even for the objects which +* are not bounded. For them first the pages are acquired, +* before the domain change. +*/ +VG_CLEAR (set_domain); + set_domain.handle = bo_gem->gem_handle; + set_domain.read_domains =I915_GEM_DOMAIN_GTT ; + set_domain.write_domain =I915_GEM_DOMAIN_GTT ; + ret = drmIoctl(bufmgr_gem->fd, + DRM_IOCTL_I915_GEM_SET_DOMAIN,
Quoted 8 lines
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) · line 1380
Quoted 6 lines
intel/intel_bufmgr_gem.c +6
-0+ &set_domain); +if (ret !=0 ) { +DBG ("%s:%d: Error setting domain %d: %s\n" , + __FILE__, __LINE__, bo_gem->gem_handle, +strerror (errno)); + }Why move the buffer to the GTT domain and not the CPU domain here?
There are 3 cache domains: GPU, CPU and NONE (aka GTT). The purpose of mmap(wc) is to be able to access the buffer without going through the CPU cache (and it should be out of the GPU cache to maintain coherency). The NONE cache domain is exactly what we want, or else you end up in clflush misery.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Damien Lespiau
Reviewed-byRe: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 46 lines · Chris Wilson
Quoted 15 lines · Damien Lespiau
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_purge_vma_cache(drm_intel_bufmgr_gem *bufmgr_gem) · line 1143
Quoted 9 lines · On Tue, Oct 28, 2014 at 06:39:27PM +0530, [email protected] wrote:
intel/intel_bufmgr_gem.c +2
-0@@ -1126,6 +1136,8 @@ static void drm_intel_gem_bo_purge_vma_cache(drm_intel_bufmgr_gem *bufmgr_gem)/* We may need to evict a few entries in order to create new mmaps */ limit = bufmgr_gem->vma_max -2 *bufmgr_gem->vma_open; +if (bufmgr_gem->has_ext_mmap) + limit -= bufmgr_gem->vma_open;if (limit <0 ) limit =0 ;Aren't we being overly aggressive in purging the vma cache with this new code? I guess it depends on the workload but I don't think the WC mapping is likely to be used in addition to the other two often enough to warrant a max - 3 * open;
And if they do, you've just exceeded their limit. And it conceivably that you will have bo with all 3 vma mappings, though I only expect 2 to be active in any single lifetime. The patch is correct regarding the code as it exists, you may want to argue for finer tracking of
vma_openandvma_cached, but that would require a different approach.Quoted 14 lines
Quoted 14 lines
intel/intel_bufmgr_gem.c +14
-0+/* Now move it to the GTT domain so that the GPU and CPU +* caches are flushed and the GPU isn't actively using the +* buffer. +* +* The domain change is done even for the objects which +* are not bounded. For them first the pages are acquired, +* before the domain change. +*/ +VG_CLEAR (set_domain); + set_domain.handle = bo_gem->gem_handle; + set_domain.read_domains =I915_GEM_DOMAIN_GTT ; + set_domain.write_domain =I915_GEM_DOMAIN_GTT ; + ret = drmIoctl(bufmgr_gem->fd, + DRM_IOCTL_I915_GEM_SET_DOMAIN,Quoted 8 lines
intel/intel_bufmgr_gem.c static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) · line 1380
Quoted 6 lines
intel/intel_bufmgr_gem.c +6
-0+ &set_domain); +if (ret !=0 ) { +DBG ("%s:%d: Error setting domain %d: %s\n" , + __FILE__, __LINE__, bo_gem->gem_handle, +strerror (errno)); + }Why move the buffer to the GTT domain and not the CPU domain here?
Quoted 5 lines
There are 3 cache domains: GPU, CPU and NONE (aka GTT). The purpose of mmap(wc) is to be able to access the buffer without going through the CPU cache (and it should be out of the GPU cache to maintain coherency). The NONE cache domain is exactly what we want, or else you end up in clflush misery.
Right that leaves the last point in my answer to v3. With that addressed this is:
--
Damien
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 1/1 intel: New libdrm interface to create unbound wc user mappings for objects
From: Akash Goel <[email protected]>
A new libdrm interface 'drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with mmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering
The drm_i915_gem_mmap structure (for the DRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameter I915_PARAM_HAS_EXT_MMAP has been added for versioning the ioctl interface.
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping & reduced the vma limit (Chris)
v4: Removed the extraneous unlock call from map_wc function (Damien)
--- include/drm/i915_drm.h | 9 +++ intel/intel_bufmgr.h | 3 + intel/intel_bufmgr_gem.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+)
include/drm/i915_drm.h +9 -0
@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_MMAP_VERSION 29 typedef struct drm_i915_getparam { int param;
@@ -487,6 +488,14 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; + +/** +* Flags for extended behaviour. +* +* Added in version 2. +*/ +__u64 flags; +#define I915_MMAP_WC 0x1 };struct drm_i915_gem_mmap_gtt {
intel/intel_bufmgr.h +3 -0
@@ -177,6 +177,9 @@ void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,int drm_intel_gem_bo_map_unsynchronized (drm_intel_bo *bo);int drm_intel_gem_bo_map_gtt (drm_intel_bo *bo);int drm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc (drm_intel_bo *bo); +int drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo);int drm_intel_gem_bo_get_reloc_count (drm_intel_bo *bo);void drm_intel_gem_bo_clear_relocs (drm_intel_bo *bo,int start);
intel/intel_bufmgr_gem.c +149 -0
221 lines not on this page · raw message
Signature · 6 lines
1.9.2 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 1/1 intel: New libdrm interface to create unbound wc user mappings for objects
From: Akash Goel <[email protected]>
A new libdrm interface 'drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than with mmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering
The drm_i915_gem_mmap structure (for the DRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameter I915_PARAM_HAS_EXT_MMAP has been added for versioning the ioctl interface.
v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping & reduced the vma limit (Chris)
v4: Removed the extraneous unlock call from map_wc function (Damien)
v5: Rebased.
--- intel/intel_bufmgr.h | 3 + intel/intel_bufmgr_gem.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+)
intel/intel_bufmgr.h +3 -0
@@ -183,6 +183,9 @@ void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr,int drm_intel_gem_bo_map_unsynchronized (drm_intel_bo *bo);int drm_intel_gem_bo_map_gtt (drm_intel_bo *bo);int drm_intel_gem_bo_unmap_gtt (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc_unsynchronized (drm_intel_bo *bo); +int drm_intel_gem_bo_map_wc (drm_intel_bo *bo); +int drm_intel_gem_bo_unmap_wc (drm_intel_bo *bo);int drm_intel_gem_bo_get_reloc_count (drm_intel_bo *bo);void drm_intel_gem_bo_clear_relocs (drm_intel_bo *bo,int start);
intel/intel_bufmgr_gem.c +147 -0
213 lines not on this page · raw message
Signature · 6 lines
1.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 32 lines · On 09/03/16 11:09, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space, but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping & reduced the vma limit (Chris)
v4: Removed the extraneous unlock call frommap_wcfunction (Damien)
v5: Rebased.
Quoted 3 lines
Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>Reviewed-by Damien Lespiau <[email protected]>
Chris, Damien,
Do you still stand by your S-o-b and R-b? If so, I can push the patch in the coming days.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 40 lines · Martin Peres
Quoted 39 lines · On 09/03/16 11:09, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space,
but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used.
This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has
been reused here. This provides the required Cache flush if the object is in
CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been
extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping &
reduced
the vma limit (Chris)
v4: Removed the extraneous unlock call frommap_wcfunction (Damien)
v5: Rebased.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>Reviewed-by Damien Lespiau <[email protected]>Chris, Damien,
Do you still stand by your S-o-b and R-b? If so, I can push the patch in the coming days.
Another ping, with both Chris and Damien CCed this time.
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v5] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 45 lines · Martin Peres
Quoted 44 lines · Martin Peres
Quoted 42 lines · On 09/03/16 11:09, [email protected] wrote:
From: Akash Goel <[email protected]>
A new libdrm interface '
drm_intel_gem_bo_map_wc' is provided by this patch. Through this interface Gfx clients can create write combining virtual mappings of the Gem object. It will provide the same funtionality of 'mmap_gtt' interface without the constraints of limited aperture space,
but provided clients handles the linear to tile conversion on their own. This patch is intended for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed on to GPU, which will be the case if regular mmap interface is used.
This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Also there is a support for the unsynchronized version of this interface named 'drm_intel_gem_bo_map_wc_unsynchronized', through which wc virtual mappings, but unsynchronized one, can be created of the Gem object. To ensure the cache coherency, before using this mapping, the GTT domain has
been reused here. This provides the required Cache flush if the object is in
CPU domain or synchronization against the concurrent renderingThe
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been
extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.v2: Aligned with the v2 of the corresponding kernel patch (Chris)
v3: Added the unmap calls for the wc mapping (Damien)
Added the param feature check before creating the wc mapping &
reduced
the vma limit (Chris)
v4: Removed the extraneous unlock call frommap_wcfunction (Damien)
v5: Rebased.Signed-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>Reviewed-by Damien Lespiau <[email protected]>
Quoted 6 lines
Quoted 4 lines
Chris, Damien,
Do you still stand by your S-o-b and R-b? If so, I can push the patch in the coming days.
Another ping, with both Chris and Damien CCed this time.
Not entirely sure, but we tended to not push libdrm patches if the open source userspace wasn't there yet. That's why this one was hanging in the air forever iirc.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
In reply to Damien LespiauQuoted 4 lines · Damien Lespiau
Right that leaves the last point in my answer to v3. With that addressed this is:
Reviewed-by Damien Lespiau <[email protected]>
Hum it seems that we've upstreamed the kernel part without the libdrm API. Is it time to fix this? Akash, Chris, any objection if I push this v3? is there a more up-to-date patch that was exercised by some driver?
Thanks,
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 9 lines · Damien Lespiau
Quoted 4 lines · Damien Lespiau
Right that leaves the last point in my answer to v3. With that addressed this is:
Reviewed-by Damien Lespiau <[email protected]>Hum it seems that we've upstreamed the kernel part without the libdrm API. Is it time to fix this? Akash, Chris, any objection if I push this v3? is there a more up-to-date patch that was exercised by some driver?
There's no actual user of the proposed libdrm API afaik. It should make a nice drop-in improvement for mesa, but we may need to better expose bufmgr_gem->has_ext_mmap (I don't think mesa needs to care about failure with old CPUs if it only focuses on mesa/i965).
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 7 lines · Chris Wilson
Quoted 6 lines · Damien Lespiau
Quoted 4 lines · Damien Lespiau
Right that leaves the last point in my answer to v3. With that addressed this is:
Reviewed-by Damien Lespiau <[email protected]>
Quoted 8 lines
Quoted 3 lines
Hum it seems that we've upstreamed the kernel part without the libdrm API. Is it time to fix this? Akash, Chris, any objection if I push this v3? is there a more up-to-date patch that was exercised by some driver?
There's no actual user of the proposed libdrm API afaik. It should make a nice drop-in improvement for mesa, but we may need to better expose
bufmgr_gem->has_ext_mmap(I don't think mesa needs to care about failure with old CPUs if it only focuses on mesa/i965).
We've cleared that with Dave last time and if there's the kernel API in place (because the DDX uses it) then we can upstream the libdrm one, for the sake of completeness.
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 12 lines · Damien Lespiau
Quoted 11 lines · Chris Wilson
Quoted 9 lines · Damien Lespiau
Quoted 4 lines · Damien Lespiau
Right that leaves the last point in my answer to v3. With that addressed this is:
Reviewed-by Damien Lespiau <[email protected]>Hum it seems that we've upstreamed the kernel part without the libdrm API. Is it time to fix this? Akash, Chris, any objection if I push this v3? is there a more up-to-date patch that was exercised by some driver?
Quoted 8 lines
Quoted 4 lines
There's no actual user of the proposed libdrm API afaik. It should make a nice drop-in improvement for mesa, but we may need to better expose
bufmgr_gem->has_ext_mmap(I don't think mesa needs to care about failure with old CPUs if it only focuses on mesa/i965).We've cleared that with Dave last time and if there's the kernel API in place (because the DDX uses it) then we can upstream the libdrm one, for the sake of completeness.
I meant in terms of whether the API is sufficient for mesa. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3] intel: New libdrm interface to create unbound wc user mappings for objects
Quoted 18 lines · Chris Wilson
Quoted 17 lines · Damien Lespiau
Quoted 15 lines · Chris Wilson
Quoted 9 lines · Damien Lespiau
Quoted 4 lines · Damien Lespiau
Right that leaves the last point in my answer to v3. With that addressed this is:
Reviewed-by Damien Lespiau <[email protected]>Hum it seems that we've upstreamed the kernel part without the libdrm API. Is it time to fix this? Akash, Chris, any objection if I push this v3? is there a more up-to-date patch that was exercised by some driver?
There's no actual user of the proposed libdrm API afaik. It should make a nice drop-in improvement for mesa, but we may need to better expose
bufmgr_gem->has_ext_mmap(I don't think mesa needs to care about failure with old CPUs if it only focuses on mesa/i965).
Quoted 5 lines
Quoted 3 lines
We've cleared that with Dave last time and if there's the kernel API in place (because the DDX uses it) then we can upstream the libdrm one, for the sake of completeness.
I meant in terms of whether the API is sufficient for mesa.
Next time, I'll actually read your comment :)
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Support creation of unbound wc user mappings for objects
In reply to Chris WilsonQuoted 35 lines · Chris Wilson
From: Akash Goel <[email protected]>
This patch provides support to create write-combining virtual mappings of GEM object. It intends to provide the same funtionality of '
mmap_gtt' interface without the constraints and contention of a limited aperture space, but requires clients handles the linear to tile conversion on their own. This is for improving the CPU write operation performance, as with such mapping, writes and reads are almost 50% faster than withmmap_gtt. Similar to the GTT mmapping, unlike the regular CPU mmapping, it avoids the cache flush after update from CPU side, when object is passed onto GPU. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Using a CPU mmap in such cases would normally incur a clflush of the whole object, and using a GTT mmapping would likely require eviction of an active object or fence and thus stall. The write-combining CPU mmap avoids both.To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap should automatically invalidate the cache lines, this may not be true for non-temporal write instructions and also not all pages of the object may be updated at any given point of time through this mapping. Having a call to
get_pagesinset_to_gtt_domainfunction, as added in the earlier patch 'drm/i915:
Broaden application of set-domain(GTT)', would guarantee the clflush and so there will be no cachelines holding the data for the object before it is accessed through this map.The
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.v2: Fix error handling, invalid flag detection, renaming (ickle)
Quoted 7 lines
The new mmapping is exercised by igt/gem_mmap_wc,
igt/gem_concurrent_blit and igt/gem_gtt_speed.Change-Id Ie883942f9e689525f72fe9a8d3780c3a9faa769aSigned-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>Cc Daniel Vetter <[email protected]>
Daniel, since both Akash and myself developed this, we need a third body for the review. Tag.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Support creation of unbound wc user mappings for objects
Quoted 39 lines · Chris Wilson
Quoted 38 lines · Chris Wilson
From: Akash Goel <[email protected]>
This patch provides support to create write-combining virtual mappings of GEM object. It intends to provide the same funtionality of '
mmap_gtt' interface without the constraints and contention of a limited aperture space, but requires clients handles the linear to tile conversion on their own. This is for improving the CPU write operation performance, as with such mapping, writes and reads are almost 50% faster than withmmap_gtt. Similar to the GTT mmapping, unlike the regular CPU mmapping, it avoids the cache flush after update from CPU side, when object is passed onto GPU. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Using a CPU mmap in such cases would normally incur a clflush of the whole object, and using a GTT mmapping would likely require eviction of an active object or fence and thus stall. The write-combining CPU mmap avoids both.To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap should automatically invalidate the cache lines, this may not be true for non-temporal write instructions and also not all pages of the object may be updated at any given point of time through this mapping. Having a call to
get_pagesinset_to_gtt_domainfunction, as added in the earlier patch 'drm/i915:
Broaden application of set-domain(GTT)', would guarantee the clflush and so there will be no cachelines holding the data for the object before it is accessed through this map.The
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.v2: Fix error handling, invalid flag detection, renaming (ickle)
The new mmapping is exercised by igt/gem_mmap_wc,
igt/gem_concurrent_blit and igt/gem_gtt_speed.
Quoted 7 lines
Quoted 4 lines
Change-Id Ie883942f9e689525f72fe9a8d3780c3a9faa769aSigned-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>Cc Daniel Vetter <[email protected]>Daniel, since both Akash and myself developed this, we need a third body for the review. Tag.
Oh, patch itself looks good imo. It's the testcases that need review (which Akash could do since you've written them), plus the missing bits (like nasty invalid args checking for the mmap ioctl), which also Akash or you could supply. Once that's done (plus the review from Akash on your patch) I'll vavuum up all the kernel parts.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Support creation of unbound wc user mappings for objects
In reply to Chris WilsonHi,
Quoted 116 lines · Chris Wilson
From: Akash Goel <[email protected]>
This patch provides support to create write-combining virtual mappings of GEM object. It intends to provide the same funtionality of '
mmap_gtt' interface without the constraints and contention of a limited aperture space, but requires clients handles the linear to tile conversion on their own. This is for improving the CPU write operation performance, as with such mapping, writes and reads are almost 50% faster than withmmap_gtt. Similar to the GTT mmapping, unlike the regular CPU mmapping, it avoids the cache flush after update from CPU side, when object is passed onto GPU. This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated. Using a CPU mmap in such cases would normally incur a clflush of the whole object, and using a GTT mmapping would likely require eviction of an active object or fence and thus stall. The write-combining CPU mmap avoids both.To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap should automatically invalidate the cache lines, this may not be true for non-temporal write instructions and also not all pages of the object may be updated at any given point of time through this mapping. Having a call to
get_pagesinset_to_gtt_domainfunction, as added in the earlier patch 'drm/i915:
Broaden application of set-domain(GTT)', would guarantee the clflush and so there will be no cachelines holding the data for the object before it is accessed through this map.The
drm_i915_gem_mmapstructure (for theDRM_I915_GEM_MMAP_IOCTL) has been extended with a new flags field (defaulting to 0 for existent users). In order for userspace to detect the extended ioctl, a new parameterI915_PARAM_HAS_EXT_MMAPhas been added for versioning the ioctl interface.v2: Fix error handling, invalid flag detection, renaming (ickle)
The new mmapping is exercised by igt/gem_mmap_wc,
igt/gem_concurrent_blit and igt/gem_gtt_speed.Change-Id Ie883942f9e689525f72fe9a8d3780c3a9faa769aSigned-off-by Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>Cc Daniel Vetter <[email protected]>--- drivers/gpu/drm/i915/i915_dma.c | 3 +++ drivers/gpu/drm/i915/i915_gem.c | 19 +++++++++++++++++++ include/uapi/drm/i915_drm.h | 9 +++++++++ 3 files changed, 31 insertions(+)drivers/gpu/drm/i915/i915_dma.c +3
-0@@ -1027,6 +1027,9 @@ static int i915_getparam(struct drm_device *dev, void *data,case I915_PARAM_CMD_PARSER_VERSION : value =i915_cmd_parser_get_version ();break ; +case I915_PARAM_MMAP_VERSION : + value =1 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;drivers/gpu/drm/i915/i915_gem.c +19
-0@@ -1485,6 +1485,12 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,struct drm_gem_object *obj;unsigned long addr; +if (args->flags & ~(I915_MMAP_WC )) +return -EINVAL ; + +if (args->flags &I915_MMAP_WC && !cpu_has_pat) +return -ENODEV ; + obj =drm_gem_object_lookup (dev, file, args->handle);if (obj ==NULL )return -ENOENT ;@@ -1500,6 +1506,19 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, addr =vm_mmap (obj->filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset); +if (args->flags &I915_MMAP_WC ) { +struct mm_struct *mm = current->mm; +struct vm_area_struct *vma; + +down_write (&mm->mmap_sem); + vma =find_vma (mm, addr); +if (vma) + vma->vm_page_prot = +pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); +else + addr = -ENOMEM ; +up_write (&mm->mmap_sem); + }drm_gem_object_unreference_unlocked (obj);if (IS_ERR ((void *)addr))return addr;include/uapi/drm/i915_drm.h +2
-0@@ -340,6 +340,7 @@ typedef struct drm_i915_irq_wait {#define I915_PARAM_HAS_EXEC_HANDLE_LUT 26#define I915_PARAM_HAS_WT 27#define I915_PARAM_CMD_PARSER_VERSION 28 +#define I915_PARAM_MMAP_VERSION 29 typedef struct drm_i915_getparam { int param;@@ -487,6 +488,14 @@ struct drm_i915_gem_mmap {* This is a fixed-size type for 32/64 compatibility. */ __u64 addr_ptr; +
include/uapi/drm/i915_drm.h struct drm_i915_gem_mmap { · line 501
Quoted 10 lines
include/uapi/drm/i915_drm.h +7
-0+/** +* Flags for extended behaviour. +* +* Added in version 2. +*/ +__u64 flags; +#define I915_MMAP_WC 0x1 };struct drm_i915_gem_mmap_gtt {
I had to spend some time reading about stuff but eventually this looks good to me. So:
Just one thing to clarify - the same write combining speed up effect is already possible using the mentioned non-temporal instructions, this just makes it easier to use for a wider group of users?
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Support creation of unbound wc user mappings for objects
Quoted 3 lines · Tvrtko Ursulin
Just one thing to clarify - the same write combining speed up effect is already possible using the mentioned non-temporal instructions, this just makes it easier to use for a wider group of users?
Kind off. We did identify one corner case in the cache tracking that required the previous patch to "broaden set-domain(GTT)" and for userspace to remember to use set-domain(GTT) alongside movntaps. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
In reply to [email protected]Quoted 26 lines · On Thu, Oct 23, 2014 at 04:03:56PM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This patch provides support to create uncached virtual mappings for a Gem object. It intends to provide the same funtionality of '
mmap_gtt' interface without the constraints of a limited aperture space, but provided clients handles the linear to tile conversion on their own.
This is for improving the CPU write operation performance, as with such mapping, writes are almost 50% faster than withmmap_gtt. Also it avoids the Cache flush after update from CPU side, when object is passed onto GPU, which will be the case if regular mmap ioctl interface is used.
This type of mapping is specially useful in case of sub-region update, i.e. when only a portion of the object is to be updated.
To ensure the cache coherency, before using this mapping, the GTT domain has been reused here. This provides the required Cache flush if the object is in CPU domain or synchronization against the concurrent rendering. Although the access through an uncached mmap shall automatically invalidate the cache lines, but this may not be true for non temporal write instructions and also not all pages of the object be updated at any given point of time through this mapping. Having a call toget_pagesinset_to_gtt_domainfunction, as added by Chris in the earlier patch, would guarantee the clflush and so there will be no cache- lines holding the data for the object before it is accessed through this map. A new field 'flags' has been added to 'drm_i915_gem_mmap' structure, used ingem_mmapioctl, which allows to convey the required mapping type as uncached. User can query the driver for the support of this mapping through theget_params. For that a new defineI915_PARAM_HAS_UC_MMAPhas been added.
Quoted 2 lines
Change-Id Ie883942f9e689525f72fe9a8d3780c3a9faa769aSigned-off-by Akash Goel <[email protected]>
Yeah, I like this. And Chris has already gone ahead and added all the functional tests. So here's what seems to still be missing:
- Reviewing Chris' patches. Akash, can you please do that? This kind of cross-review usually works best.
- Polish for Akash' patch according to Chris' review. Commit message also needs to gain the performance data. And we need to have a "does PAT work" test I think like Chris suggested.
- ioctl argument check tests for the cpu mmap ioctl. We currently have absotutely nothing here (one of the very few cases left). So Akash, can you please take the AR to write a new igt testcase which does all the usual argument checking test like invalid buffer, invalid flags?
Cheers, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH] drm/i915: Support to create uncached user mapping for a Gem object
Quoted 3 lines · Daniel Vetter
- Polish for Akash' patch according to Chris' review. Commit message also needs to gain the performance data. And we need to have a "does PAT work" test I think like Chris suggested.
Done, see v2 I sent. Commit message contains relative performance data, and that holds true for snb,ivb,byt,bdw. pnv didn't show improvement and I suspect neither will gen5-. Performance in igt/gem_gtt_speed and x11perf show similar trends.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 11 lines · Chris Wilson
Previously, this was restricted to only operate on bound objects - to make pointer access through the GTT to the object coherent with writes to and from the GPU. A second usecase is
drm_intel_bo_wait_rendering()which at present does not function unless the object also happens to be bound into the GGTT (on current systems that is becoming increasingly rare, especially for the typical requests from mesa). A third usecase is a future patch wishing to extend the coverage of the GTT domain to include objects not bound into the GGTT but still in its coherent cache domain. For the latter pair of requests, we need to operate on the object regardless of its bind state.
Quoted 8 lines
v2: After discussion with Akash, we came to the conclusion that the get-pages was required in order for accurate domain tracking in the corner cases (like the shrinker) and also useful for ensuring memory coherency with earlier cached CPU mmaps in case userspace uses exotic cache bypass (non-temporal) instructions.
Cc Akash Goel <[email protected]>Signed-off-by Chris Wilson <[email protected]>
Akash, are you happy with this? Could you bless this with an r-b? -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx