Skip to contentSkip to conversation

RFCish: write only mappings (aka non-blocking)

PATCH In review Ben Widawsky 6 participants 28 messages Sep 20, 2011 – Sep 22, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 RFCish: write only mappings (aka non-blocking)

I'm going to keep this short...
Patch 5 is my test case.
On Gen6 I see slightly better performance. On Gen5 I see really really improvements (like 3x) for non GTT write only maps over regular mmaps. GTT mappings don't really show any improvements as a whole.

Better tests would be nice, but without more significant Mesa changes, or better benchmarks, I'm not sure how to get those. While I think these patches are mostly complete, ideas for better testing are very welcome. Also of course, general optimizations or pointing out my errors would be nice.

#1 lore raw

PATCH 1/6 drm/i915: object CPU flush interface

Add an interface to allow flushing. While clflush can be run by anyone, we have a potential for chipset specific requirements for flushing. The plan to use this is to have libdrm clients always call flush, and allow libdrm to decide whether or not to actually use this IOCTL.

---
 drivers/gpu/drm/i915/i915_dma.c |    1 +
 drivers/gpu/drm/i915/i915_drv.h |    2 ++
 drivers/gpu/drm/i915/i915_gem.c |    8 ++++++++
 include/drm/i915_drm.h          |    5 +++++
 4 files changed, 16 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -0
index 8a3942c..badb555 100644
@@ -2292,6 +2292,7 @@ struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(I915_GEM_FLUSH, i915_gem_flush_ioctl, DRM_UNLOCKED),
 };
 
 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 7916bd9..cee396c 100644
@@ -1108,6 +1108,8 @@ int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_priv);
 int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
 			   struct drm_file *file_priv);
+int i915_gem_flush_ioctl(struct drm_device *dev, void *data,
+			 struct drm_file *file_priv);
 int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
 			   struct drm_file *file_priv);
 int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/i915/i915_gem.c +8 -0
index a546a71..d4de7f7 100644
@@ -3674,6 +3674,14 @@ unlock:
 	return ret;
 }
 
+int
+i915_gem_flush_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)
+{
+	intel_gtt_chipset_flush();
+	return 0;
+}
+
 struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
 						  size_t size)
 {
include/drm/i915_drm.h +5 -0
index 28c0d11..14a633d 100644
@@ -198,6 +198,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_OVERLAY_PUT_IMAGE	0x27
 #define DRM_I915_OVERLAY_ATTRS	0x28
 #define DRM_I915_GEM_EXECBUFFER2	0x29
+#define DRM_I915_GEM_FLUSH	0x2a
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -239,6 +240,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_MADVISE	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MADVISE, struct drm_i915_gem_madvise)
 #define DRM_IOCTL_I915_OVERLAY_PUT_IMAGE	DRM_IOW(DRM_COMMAND_BASE + DRM_I915_OVERLAY_PUT_IMAGE, struct drm_intel_overlay_put_image)
 #define DRM_IOCTL_I915_OVERLAY_ATTRS	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
+#define DRM_IOCTL_I915_GEM_FLUSH	DRM_IOW  (DRM_COMMAND_BASE + DRM_I915_GEM_FLUSH , struct drm_i915_gem_flush)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -844,4 +846,7 @@ struct drm_intel_overlay_attrs {
 	__u32 gamma5;
 };
 
+struct drm_i915_gem_flush {
+	__u32 bo_handle;
+};
 #endif				/* _I915_DRM_H_ */
Signature · 1 line
1.7.6.1
#2 lore raw

PATCH 2/6 drm/i915: write only object tracking

In reply to Ben Widawsky

Add the struct member to track write only objects, and display them in our debugfs.

---
 drivers/gpu/drm/i915/i915_debugfs.c |   18 +++++++++++++-----
 drivers/gpu/drm/i915/i915_drv.h     |    2 ++
 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +13 -5
index 3c395a5..b0f1964 100644
@@ -138,12 +138,14 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
 	if (obj->gtt_space != NULL)
 		seq_printf(m, " (gtt offset: %08x, size: %08x)",
 			   obj->gtt_offset, (unsigned int)obj->gtt_space->size);
-	if (obj->pin_mappable || obj->fault_mappable) {
-		char s[3], *t = s;
+	if (obj->pin_mappable || obj->fault_mappable || obj->cpu_write_only) {
+		char s[4], *t = s;
 		if (obj->pin_mappable)
 			*t++ = 'p';
 		if (obj->fault_mappable)
 			*t++ = 'f';
+		if (obj->cpu_write_only)
+			*t++ = 'w';
 		*t = '\0';
 		seq_printf(m, " (%s mappable)", s);
 	}
@@ -224,8 +226,8 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_device *dev = node->minor->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	u32 count, mappable_count;
-	size_t size, mappable_size;
+	u32 count, mappable_count, womap_count;
+	size_t size, mappable_size, womap_size;
 	struct drm_i915_gem_object *obj;
 	int ret;
 
@@ -263,7 +265,7 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 	seq_printf(m, "  %u [%u] freed objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
-	size = count = mappable_size = mappable_count = 0;
+	size = count = mappable_size = mappable_count = womap_count = womap_size = 0;
 	list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) {
 		if (obj->fault_mappable) {
 			size += obj->gtt_space->size;
@@ -273,11 +275,17 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 			mappable_size += obj->gtt_space->size;
 			++mappable_count;
 		}
+		if (obj->cpu_write_only) {
+			womap_size += obj->gtt_space->size;
+			++womap_count;
+		}
 	}
 	seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
 		   mappable_count, mappable_size);
 	seq_printf(m, "%u fault mappable objects, %zu bytes\n",
 		   count, size);
+	seq_printf(m, "%u write-only mappable objects, %zu bytes\n",
+		   womap_count, womap_size);
 
 	seq_printf(m, "%zu [%zu] gtt total\n",
 		   dev_priv->mm.gtt_total, dev_priv->mm.mappable_gtt_total);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index cee396c..c960763 100644
@@ -883,6 +883,8 @@ struct drm_i915_gem_object {
 	 * reaches 0, dev_priv->pending_flip_queue will be woken up.
 	 */
 	atomic_t pending_flip;
+
+	int cpu_write_only;
 };
 
 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
Signature · 1 line
1.7.6.1
#3 lore raw

PATCH 3/6 drm/i915: Support write only mappings

In reply to Ben Widawsky

When doing a GTT mapping, the pages are not backed until taking a fault. If we know that the object is write only, when the fault happens we do not need to make the pages coherent with the CPU. This allows for semi fast prefaults to occur in libdrm at map time.

For the non-GTT case, there isn't much to do except make sure we handle things properly we we move an object out of the GTT.

Finally, modify the set domain IOCTL to actually mark objects as write only. Current limitation in that once an object is marked write only, it cannot be readable.

---
 drivers/gpu/drm/i915/i915_gem.c |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +24 -8
index d4de7f7..48ea4bc 100644
@@ -1047,6 +1047,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_gem_object *obj;
 	uint32_t read_domains = args->read_domains;
 	uint32_t write_domain = args->write_domain;
+	int write_only = 0;
 	int ret;
 
 	if (!(dev->driver->driver_features & DRIVER_GEM))
@@ -1059,11 +1060,15 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	if (read_domains & I915_GEM_GPU_DOMAINS)
 		return -EINVAL;
 
-	/* Having something in the write domain implies it's in the read
-	 * domain, and only that read domain.  Enforce that in the request.
-	 */
-	if (write_domain != 0 && read_domains != write_domain)
+	if (write_domain != 0 && read_domains == 0) {
+		write_only = 1;
+	} else if (write_domain != 0 && read_domains != write_domain) {
+		/* Having something in the write domain implies it's in the read
+		 * domain, and only that read domain. Enforce that in the
+		 * request.
+		 */
 		return -EINVAL;
+	}
 
 	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)
@@ -1084,6 +1089,13 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 		 */
 		if (ret == -EINVAL)
 			ret = 0;
+	} else if (obj->cpu_write_only && !write_only) {
+		DRM_ERROR("Not yet supported\n");
+		ret = -EINVAL;
+		goto unlock;
+	} else if (write_only) {
+		atomic_set(&obj->cpu_write_only, 1);
+		obj->base.read_domains = 0;
 	} else {
 		ret = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0);
 	}
@@ -1217,9 +1229,13 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 		if (ret)
 			goto unlock;
 
-		ret = i915_gem_object_set_to_gtt_domain(obj, write);
-		if (ret)
-			goto unlock;
+		if (obj->cpu_write_only) {
+			i915_gem_object_flush_cpu_write_domain(obj);
+		} else {
+			ret = i915_gem_object_set_to_gtt_domain(obj, write);
+			if (ret)
+				goto unlock;
+		}
 	}
 
 	if (obj->tiling_mode == I915_TILING_NONE)
@@ -1586,7 +1602,7 @@ i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj)
 		obj->dirty = 0;
 
 	for (i = 0; i < page_count; i++) {
-		if (obj->dirty)
+		if (obj->dirty || obj->cpu_write_only)
 			set_page_dirty(obj->pages[i]);
 
 		if (obj->madv == I915_MADV_WILLNEED)
Signature · 1 line
1.7.6.1
#4 lore raw

Re: [PATCH 3/6] drm/i915: Support write only mappings

Quoted 4 lines · Ben Widawsky

When doing a GTT mapping, the pages are not backed until taking a fault. If we know that the object is write only, when the fault happens we do not need to make the pages coherent with the CPU. This allows for semi fast prefaults to occur in libdrm at map time.

Every time I see this stuff, I get confused by the term 'write-only'. Reading through the code, I remind myself that what you're actually promising is that any CPU accesses to the object will not overlap any potential writes by the GPU. The CPU could be reading or writing, it really doesn't matter.

Really what you want is a kernel call that does everything except block on the GPU, right?

Signature · 1 line
[email protected]

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

Re: [PATCH 3/6] drm/i915: Support write only mappings

Quoted 11 lines · Keith Packard
Quoted 4 lines · Ben Widawsky

When doing a GTT mapping, the pages are not backed until taking a fault. If we know that the object is write only, when the fault happens we do not need to make the pages coherent with the CPU. This allows for semi fast prefaults to occur in libdrm at map time.

Every time I see this stuff, I get confused by the term 'write-only'. Reading through the code, I remind myself that what you're actually promising is that any CPU accesses to the object will not overlap any potential writes by the GPU. The CPU could be reading or writing, it really doesn't matter.

I think of it as, we (libdrm + kernel) promise that the buffer is not guaranteed to be coherent with the GPU. Mesa/client is who should be making the promise to not write to a part of the buffer that the GPU may be accessing.

Quoted 3 lines

Really what you want is a kernel call that does everything except block on the GPU, right?

Yes, exactly.

Ben

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

Re: [PATCH 3/6] drm/i915: Support write only mappings

In reply to Ben Widawsky
Quoted 11 lines · Ben Widawsky

When doing a GTT mapping, the pages are not backed until taking a fault. If we know that the object is write only, when the fault happens we do not need to make the pages coherent with the CPU. This allows for semi fast prefaults to occur in libdrm at map time.

For the non-GTT case, there isn't much to do except make sure we handle things properly we we move an object out of the GTT.

Finally, modify the set domain IOCTL to actually mark objects as write only. Current limitation in that once an object is marked write only, it cannot be readable.

I couldn't see any reason for this restriction and it does impose a significant burden on the userspace cache; any buffer used for write-only mappings must be purged and can't be reused.

Quoted 18 lines
---
 drivers/gpu/drm/i915/i915_gem.c |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +1 -0
index d4de7f7..48ea4bc 100644
@@ -1047,6 +1047,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_gem_object *obj;
 	uint32_t read_domains = args->read_domains;
 	uint32_t write_domain = args->write_domain;
+	int write_only = 0;
 	int ret;
 
 	if (!(dev->driver->driver_features & DRIVER_GEM))

drivers/gpu/drm/i915/i915_gem.c i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, · line 1063

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +1 -4
@@ -1059,11 +1060,15 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	if (read_domains & I915_GEM_GPU_DOMAINS)
 		return -EINVAL;
 
-	/* Having something in the write domain implies it's in the read
-	 * domain, and only that read domain.  Enforce that in the request.
-	 */
-	if (write_domain != 0 && read_domains != write_domain)
+	if (write_domain != 0 && read_domains == 0) {

Neat extension of the existing ioctl. Just a little wary of the potential for mass foot shootings - but this whole extension is about giving them a machinegun.

Quoted 12 lines
drivers/gpu/drm/i915/i915_gem.c +7 -0
+		write_only = 1;
+	} else if (write_domain != 0 && read_domains != write_domain) {
+		/* Having something in the write domain implies it's in the read
+		 * domain, and only that read domain. Enforce that in the
+		 * request.
+		 */
 		return -EINVAL;
+	}
 
 	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)

drivers/gpu/drm/i915/i915_gem.c i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, · line 1097

Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +6 -0
@@ -1084,6 +1089,13 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 		 */
 		if (ret == -EINVAL)
 			ret = 0;
+	} else if (obj->cpu_write_only && !write_only) {
+		DRM_ERROR("Not yet supported\n");
+		ret = -EINVAL;
+		goto unlock;
+	} else if (write_only) {
+		atomic_set(&obj->cpu_write_only, 1);

Atomic? Did you intend for obj->cpu_write_only be atomic_t?

Quoted 22 lines
drivers/gpu/drm/i915/i915_gem.c +8 -3
+		obj->base.read_domains = 0;
 	} else {
 		ret = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0);
 	}
@@ -1217,9 +1229,13 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 		if (ret)
 			goto unlock;
 
-		ret = i915_gem_object_set_to_gtt_domain(obj, write);
-		if (ret)
-			goto unlock;
+		if (obj->cpu_write_only) {
+			i915_gem_object_flush_cpu_write_domain(obj);
+		} else {
+			ret = i915_gem_object_set_to_gtt_domain(obj, write);
+			if (ret)
+				goto unlock;
+		}
 	}
 
 	if (obj->tiling_mode == I915_TILING_NONE)

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj) · line 1605

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -1586,7 +1602,7 @@ i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj)
 		obj->dirty = 0;
 
 	for (i = 0; i < page_count; i++) {
-		if (obj->dirty)
+		if (obj->dirty || obj->cpu_write_only)

Could this be simplified by marking the bo as dirty upon setting the object write-only?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#7 lore raw

PATCH 4/6 intel: write only map support

In reply to Ben Widawsky

Support the kernel write only interface. Also add an interface to ease user flushing for non LLC coherent architectures.

---
 include/drm/i915_drm.h   |    5 ++
 intel/intel_bufmgr.h     |    9 ++++
 intel/intel_bufmgr_gem.c |  105 ++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 115 insertions(+), 4 deletions(-)
include/drm/i915_drm.h +5 -0
index adc2392..576d419 100644
@@ -189,6 +189,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_OVERLAY_PUT_IMAGE	0x27
 #define DRM_I915_OVERLAY_ATTRS	0x28
 #define DRM_I915_GEM_EXECBUFFER2	0x29
+#define DRM_I915_GEM_FLUSH	0x2a
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -230,6 +231,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_MADVISE	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MADVISE, struct drm_i915_gem_madvise)
 #define DRM_IOCTL_I915_OVERLAY_PUT_IMAGE	DRM_IOW(DRM_COMMAND_BASE + DRM_IOCTL_I915_OVERLAY_ATTRS, struct drm_intel_overlay_put_image)
 #define DRM_IOCTL_I915_OVERLAY_ATTRS	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
+#define DRM_IOCTL_I915_GEM_FLUSH	DRM_IOW  (DRM_COMMAND_BASE + DRM_I915_GEM_FLUSH , struct drm_i915_gem_flush)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -835,4 +837,7 @@ struct drm_intel_overlay_attrs {
 	__u32 gamma5;
 };
 
+struct drm_i915_gem_flush {
+	__u32 bo_handle;
+};
 #endif				/* _I915_DRM_H_ */
intel/intel_bufmgr.h +9 -0
index 889ef46..c6fd907 100644
@@ -81,6 +81,9 @@ struct _drm_intel_bo {
 	 * MM-specific handle for accessing object
 	 */
 	int handle;
+
+	/** Buffer is only writable from CPU */
+	int write_only;
 };
 
 #define BO_ALLOC_FOR_RENDER (1<<0)
@@ -145,6 +148,12 @@ drm_intel_bo *drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
 						unsigned int handle);
 void drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr);
 void drm_intel_bufmgr_gem_enable_fenced_relocs(drm_intel_bufmgr *bufmgr);
+int drm_intel_gem_bo_flush(drm_intel_bo *bo, uint32_t offset, size_t size);
+#define drm_intel_gem_bo_flush_obj(bo) drm_intel_gem_bo_flush(bo, 0, bo->size);
+int drm_intel_gem_bo_map_wo(drm_intel_bo *bo);
+int drm_intel_gem_bo_map_gtt_wo(drm_intel_bo *bo,
+				uint32_t prefault_offset,
+				int prefault_pages);
 int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
 int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
intel/intel_bufmgr_gem.c +101 -4

141 lines not on this page · raw message

Signature · 1 line
1.7.6.1
#8 lore raw

PATCH 5/6 write-only mappings

In reply to Ben Widawsky

This test probably won't get pushed. It's a very synthetic test to help me benchmark

---
 tests/Makefile.am  |    1 +
 tests/gem_wo_map.c |  311 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/test.sh      |   10 ++
 3 files changed, 322 insertions(+), 0 deletions(-)
 create mode 100644 tests/gem_wo_map.c
 create mode 100755 tests/test.sh
tests/Makefile.am +1 -0
index 80a9c94..65cf128 100644
@@ -44,6 +44,7 @@ TESTS = getversion \
 	gen3_mixed_blits \
 	gem_storedw_loop \
 	gem_storedw_batches_loop \
+	gem_wo_map \
 	$(NULL)
 
 HANG = \
tests/gem_wo_map.c new file +311 -0

311 lines not on this page · raw message

tests/test.sh new file +10 -0
new file mode 100755
index 0000000..8a03249
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+echo "Map"
+time ./gem_wo_map -s -c 50
+echo "Map GTT"
+time ./gem_wo_map -sg -c 50
+echo "Map WO"
+time ./gem_wo_map -sw -c 50
+echo "Map GTT WO"
+time ./gem_wo_map -sgw -c 50
Signature · 6 lines
1.7.6.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

PATCH 6/6 intel: use write only maps for MapRangeBuffer

In reply to Ben Widawsky
---
 src/mesa/drivers/dri/intel/intel_buffer_objects.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
src/mesa/drivers/dri/intel/intel_buffer_objects.c +10 -4
index d35a50e..18bed4d 100644
@@ -296,8 +296,6 @@ intel_bufferobj_get_subdata(struct gl_context * ctx,
    }
 }
 
-
-
 /**
  * Called via glMapBufferRange and glMapBuffer
  *
@@ -401,8 +399,16 @@ intel_bufferobj_map_range(struct gl_context * ctx,
    }
 
    if (!(access & GL_MAP_READ_BIT)) {
-      drm_intel_gem_bo_map_gtt(intel_obj->buffer);
-      intel_obj->mapped_gtt = GL_TRUE;
+      if (intel->gen >= 6) {
+	 drm_intel_gem_bo_map_wo(intel_obj->buffer);
+	 intel_obj->mapped_gtt = GL_FALSE;
+      } else if (access & GL_MAP_UNSYNCHRONIZED_BIT) {
+         drm_intel_gem_bo_map_gtt_wo(intel_obj->buffer, 0, 1);
+         intel_obj->mapped_gtt = GL_TRUE;
+      } else {
+         drm_intel_gem_bo_map_gtt(intel_obj->buffer);
+         intel_obj->mapped_gtt = GL_TRUE;
+      }
    } else {
       drm_intel_bo_map(intel_obj->buffer, (access & GL_MAP_WRITE_BIT) != 0);
       intel_obj->mapped_gtt = GL_FALSE;
Signature · 1 line
1.7.6.1
#10 lore raw
In reply to Ben Widawsky
Quoted 11 lines · Ben Widawsky

I'm going to keep this short...
Patch 5 is my test case.
On Gen6 I see slightly better performance. On Gen5 I see really really improvements (like 3x) for non GTT write only maps over regular mmaps. GTT mappings don't really show any improvements as a whole.

Better tests would be nice, but without more significant Mesa changes, or better benchmarks, I'm not sure how to get those. While I think these patches are mostly complete, ideas for better testing are very welcome. Also of course, general optimizations or pointing out my errors would be nice.

Ok, I'm gonna be the dense annoying bastard here:

- Can we stop calling this mappings write-only. Afaics the distinguishing feature is that they're non-blocking. And yes, current users only use non-blocking paths to upload data because the amount of data we're currently downloading is so small. Hence we can use on bo for each download without wasting too much space and still avoid unnecessary blocking. Bit I think this will change, e.g. with designs like sna that tightly integrate gpu and sw rendering. Or OpenCL.

- Why do we need any patches for gtt non-blocking mmaps? I've re-read our code, and afaics we're only calling wait_rendering from gem_fault if obj->gtt_space == NULL. I.e. there's no way the gpu is currently using the data and hence no way for us to block on it. I think the only thing needed is a small libdrm batch to enable non-blocking gtt mmaps

void drm_intel_enable_non_blocking_gtt_mmap(obj)

which sets a bit somewhere and moves the obj (once) into the gtt domain. And a corresponding change in gtt_mmap to disable the set_domain call. This only works as long as no one else access the object from the cpu domain, but afaics we'll use non-blocking mmaps only for unshared buffers, so that should be fine.

I might also just be dense and not see the issue ...

- I'm sorry having suggested to implement the clflush ioctl, I think it's a foolish idea, now. Non-blocking mmaps is a performance optimization, needing to sync caches with clflush is very much the opposite. So I think we can dustbin this.

Now non-blocking cpu mmaps make very much sense on llc/snooped buffer objects. So I think we actually need an ioctl to get obj->cache_level so userspace can decide whether it should use non-blocking gtt mmaps or cpu (non-blocking) cpu mmaps. We might as well go full-circle, make Chris happy and merge the corresponding set_cache_level ioclt to enable snooped buffers on machines with ilk-like coherency (i.e. that atom thing I'm hearing about ...). But imo that's material for non-blocking mmaps, step 2.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#11 lore raw
Quoted 8 lines · Daniel Vetter

- Why do we need any patches for gtt non-blocking mmaps? I've re-read our code, and afaics we're only calling wait_rendering from gem_fault if obj->gtt_space == NULL. I.e. there's no way the gpu is currently using the data and hence no way for us to block on it. I think the only thing needed is a small libdrm batch to enable non-blocking gtt mmaps

void drm_intel_enable_non_blocking_gtt_mmap(obj)

Quoted 7 lines

which sets a bit somewhere and moves the obj (once) into the gtt domain. And a corresponding change in gtt_mmap to disable the set_domain call. This only works as long as no one else access the object from the cpu domain, but afaics we'll use non-blocking mmaps only for unshared buffers, so that should be fine.

I might also just be dense and not see the issue ...

This was what I was looking for. Ben was concerned that while warming up towards steady state, the page faults for new pages of the giant vertex buffer (for example) would end up blocking in the fault handler. I really have a hard time caring about that case.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#12 lore raw
Quoted 15 lines · Eric Anholt
Quoted 14 lines · Daniel Vetter

- Why do we need any patches for gtt non-blocking mmaps? I've re-read our code, and afaics we're only calling wait_rendering from gem_fault if obj->gtt_space == NULL. I.e. there's no way the gpu is currently using the data and hence no way for us to block on it. I think the only thing needed is a small libdrm batch to enable non-blocking gtt mmaps

void drm_intel_enable_non_blocking_gtt_mmap(obj)

which sets a bit somewhere and moves the obj (once) into the gtt domain. And a corresponding change in gtt_mmap to disable the set_domain call. This only works as long as no one else access the object from the cpu domain, but afaics we'll use non-blocking mmaps only for unshared buffers, so that should be fine.

Quoted 6 lines
Quoted 1 line

I might also just be dense and not see the issue ...

This was what I was looking for. Ben was concerned that while warming up towards steady state, the page faults for new pages of the giant vertex buffer (for example) would end up blocking in the fault handler. I really have a hard time caring about that case.

Well, that can easily be handled by just prefaulting the full range on the enable_non_blocking call. The thing I was concerned about was when we need to move around the bo in the gtt to make some space and shoot down the mappings to do so: On the first fault the bo is naturally not busy, but on subsequent faults on other parts of the bo the gpu might already be using it. But I've double-checked, and it looks like with your revert (commit e92d03bf) we should be safe.

Now for cpu coherent mmaps on machines/kernels support llc caching: Would you prefer libdrm to transparently use that for non-blocking maps if available, or is an explicit feature-check with a sepearte cpu map function preferred? I'm thinking of adding a new map_non_blocking functions to add to libdrm that either uses gtt mmaps, or cpu mmaps if they're coherent. The risk I'm seeing with that approach is that future hw gens might have slightly different semantics for these (e.g funny games with swizzling) so transparently using one instead of the other may end up in headaches. Otoh for untiled buffers to upload vertices, pixels, whatnoelse, we should be fairly safe. And cpu mmaps for tiled buffers are broken already, thanks to bit17 swizzling.

I think I can etch out a bit of time and whip up an rfc patchset in the coming days.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#13 lore raw

PATCH 1/1 intel: non-blocking mmaps on the cheap

This adds a new mode to map gem objects in a non-blocking way. This needs to be enabled on a per-object basis with object_enable_nonblocking.

The new kernel interface required to get the caching level/coherency is not yet wired up. All the code to transparently choose between gtt mappings or (if coherent) cpu mappings is already in place, though.

Cc Eric Anholt <[email protected]>
Cc Ben Widawsky <[email protected]>

---
Hi Eric,

Not really tested, but can you please take a quick lock and see if this is suitable for mesa and ack the general approach?

Thanks, Daniel

 intel/intel_bufmgr.h     |    4 +
 intel/intel_bufmgr_gem.c |  165 +++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 152 insertions(+), 17 deletions(-)
intel/intel_bufmgr.h +4 -0
index 889ef46..95216dd 100644
@@ -149,6 +149,10 @@ int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
 int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
 
+int drm_intel_gem_bo_enable_nonblocking_map(drm_intel_bo *bo);
+int drm_intel_gem_bo_map_nonblocking(drm_intel_bo *bo);
+int drm_intel_gem_bo_unmap_nonblocking(drm_intel_bo *bo);
+
 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
 
 int drm_intel_get_aperture_sizes(int fd, size_t *mappable, size_t *total);
intel/intel_bufmgr_gem.c +148 -17

243 lines not on this page · raw message

Signature · 1 line
1.7.6.2
#14 lore raw

Re: [PATCH] intel: non-blocking mmaps on the cheap

Quoted 7 lines · Daniel Vetter

This adds a new mode to map gem objects in a non-blocking way. This needs to be enabled on a per-object basis with object_enable_nonblocking.

The new kernel interface required to get the caching level/coherency is not yet wired up. All the code to transparently choose between gtt mappings or (if coherent) cpu mappings is already in place, though.

Quoted 8 lines
Cc Eric Anholt <[email protected]>
Cc Ben Widawsky <[email protected]>

---
Hi Eric,

Not really tested, but can you please take a quick lock and see if this is suitable for mesa and ack the general approach?

It doesn't quite look like what I want for Mesa, but close.

Don't-block-I-know-what-I'm-doing is not a long-term property of a mapping for GL, it's something you say when you're getting a pointer to a piece of the existing mapping, and you may ask for normal blocking mode again later. So I'd rather see the the map/unmap track "oh, we already set to GTT and we haven't done something that would have knocked it out of there, so no need to go set to GTT again", instead of setting a flag. Also, I think you need to re-set to GTT after a CPU mapping on !llc, since clflushing is coarser granularity than GL buffer mappings (byte boundary).

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#15 lore raw

PATCH 1/1 intel: non-blocking mmaps on the cheap

This adds a new mode to map gem objects in a non-blocking way.

The new kernel interface required to get the caching level/coherency is not yet wired up. All the code to transparently choose between gtt mappings or (if coherent) cpu mappings is already in place, though.

To make this useable for mesa, we need to allow other buffer acces in between non-blocking modes. It's not a big problem if this accidentaly blocks once when switching back to non-blocking maps, but domains need to be correctly tracked.

I've gone through historical kernel versions and luckily the only place we move a bo from the gtt domain to the cpu domain is in the set_ioctl. pwrite/pread don't move objects into the cpu domain as long as they're untiled or llc cached.

So track whether an object is in the gtt domain and invalidate this only on access to cpu mappings.

Cc Eric Anholt <[email protected]>
Cc Ben Widawsky <[email protected]>
---
 intel/intel_bufmgr.h     |    3 +
 intel/intel_bufmgr_gem.c |  156 +++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 142 insertions(+), 17 deletions(-)
intel/intel_bufmgr.h +3 -0
index 889ef46..47f3416 100644
@@ -149,6 +149,9 @@ int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
 int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
 
+int drm_intel_gem_bo_map_nonblocking(drm_intel_bo *bo);
+int drm_intel_gem_bo_unmap_nonblocking(drm_intel_bo *bo);
+
 int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
 
 int drm_intel_get_aperture_sizes(int fd, size_t *mappable, size_t *total);
intel/intel_bufmgr_gem.c +139 -17

233 lines not on this page · raw message

Signature · 1 line
1.7.6.2
#16 lore raw

PATCH 1/1 intel: non-blocking mmaps on the cheap

The drm patch goes on top of Daniel's patch. I'll squash before pushing, it's just separate for review.

The kernel stuff is straight forward, just an IOCTL to query the cache level.

Both patches will get better commit messages when resubmitted.

I ran a modified version of the test I posted earlier. On Sandybridge I see no improvements on the test I posted earlier. On Ironlake, improvement over regular GTT mappings:
21.7486% +/- 1.17445%

These results are similar to my earlier patch series.

Overall, I like this series much better. Do we want to sneak in a set cache level with the same IOCTL while we're at it?

Ben

#17 lore raw

PATCH 1/1 on top of daniel

Daniel Vetter <[email protected]>

---
 include/drm/i915_drm.h   |    7 +++++++
 intel/intel_bufmgr_gem.c |   36 ++++++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 6 deletions(-)
include/drm/i915_drm.h +7 -0
index adc2392..4b62222 100644
@@ -189,6 +189,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_OVERLAY_PUT_IMAGE	0x27
 #define DRM_I915_OVERLAY_ATTRS	0x28
 #define DRM_I915_GEM_EXECBUFFER2	0x29
+#define DRM_I915_GEM_GET_CACHE_TYPE	0x2a
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -230,6 +231,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_MADVISE	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MADVISE, struct drm_i915_gem_madvise)
 #define DRM_IOCTL_I915_OVERLAY_PUT_IMAGE	DRM_IOW(DRM_COMMAND_BASE + DRM_IOCTL_I915_OVERLAY_ATTRS, struct drm_intel_overlay_put_image)
 #define DRM_IOCTL_I915_OVERLAY_ATTRS	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
+#define DRM_IOCTL_I915_GEM_GET_CACHE_TYPE	DRM_IOR  (DRM_COMMAND_BASE + DRM_I915_GEM_GET_CACHE_TYPE, struct drm_i915_gem_get_cache_type)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -835,4 +837,9 @@ struct drm_intel_overlay_attrs {
 	__u32 gamma5;
 };
 
+struct drm_i915_gem_get_cache_type {
+	__u32 handle;
+	__u32 cache_level;
+};
+
 #endif				/* _I915_DRM_H_ */
intel/intel_bufmgr_gem.c +30 -6
index ff4b663..65a77d6 100644
@@ -1032,6 +1032,30 @@ static int do_mmap_cpu(drm_intel_bufmgr_gem *bufmgr_gem,
 	return 0;
 }
 
+enum i915_cache_level {
+	I915_CACHE_NONE,
+	I915_CACHE_LLC,
+	I915_CACHE_LLC_MLC, /* gen6+ */
+};
+
+static int get_cache_type(drm_intel_bo *bo)
+{
+	struct drm_i915_gem_get_cache_type cache = {0, 0};
+	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 = 0;
+
+	cache.handle = bo_gem->gem_handle;
+	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_GET_CACHE_TYPE,
+		       &cache);
+
+	/* This should maintain old behavior */
+	if (ret)
+		return 0;
+
+	return cache.cache_level;
+}
+
 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;
@@ -1065,8 +1089,8 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)
 		    strerror(errno));
 	}
 
-	/* TODO ask kernel if llc cached, in that case don't clear this */
-	bo_gem->in_gtt_domain = 0;
+	if (get_cache_type(bo) != I915_CACHE_LLC)
+		bo_gem->in_gtt_domain = 0;
 
 	pthread_mutex_unlock(&bufmgr_gem->lock);
 
@@ -1335,14 +1359,14 @@ int drm_intel_gem_bo_map_nonblocking(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 gpu_coherent_cpu_map;
+	int gpu_coherent_cpu_map = 0;
 	int ret;
 
 	pthread_mutex_lock(&bufmgr_gem->lock);
-	assert(bo_gem->tiling_mode != I915_TILING_NONE);
+	assert(bo_gem->tiling_mode == I915_TILING_NONE);
 
-	/* TODO ask the kernel about this */
-	gpu_coherent_cpu_map = 1;
+	if (bufmgr_gem->gen >= 6)
+		gpu_coherent_cpu_map = 1;
 
 	if (gpu_coherent_cpu_map) {
 		ret = do_mmap_cpu(bufmgr_gem, bo_gem);
Signature · 1 line
1.7.6.3
#18 lore raw

Re: [PATCH] on top of daniel

Quoted 55 lines · Ben Widawsky

Daniel Vetter <[email protected]>

---
 include/drm/i915_drm.h   |    7 +++++++
 intel/intel_bufmgr_gem.c |   36 ++++++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 6 deletions(-)
include/drm/i915_drm.h +7 -0
index adc2392..4b62222 100644
@@ -189,6 +189,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_OVERLAY_PUT_IMAGE	0x27
 #define DRM_I915_OVERLAY_ATTRS	0x28
 #define DRM_I915_GEM_EXECBUFFER2	0x29
+#define DRM_I915_GEM_GET_CACHE_TYPE	0x2a
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -230,6 +231,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_MADVISE	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MADVISE, struct drm_i915_gem_madvise)
 #define DRM_IOCTL_I915_OVERLAY_PUT_IMAGE	DRM_IOW(DRM_COMMAND_BASE + DRM_IOCTL_I915_OVERLAY_ATTRS, struct drm_intel_overlay_put_image)
 #define DRM_IOCTL_I915_OVERLAY_ATTRS	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
+#define DRM_IOCTL_I915_GEM_GET_CACHE_TYPE	DRM_IOR  (DRM_COMMAND_BASE + DRM_I915_GEM_GET_CACHE_TYPE, struct drm_i915_gem_get_cache_type)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -835,4 +837,9 @@ struct drm_intel_overlay_attrs {
 	__u32 gamma5;
 };
 
+struct drm_i915_gem_get_cache_type {
+	__u32 handle;
+	__u32 cache_level;
+};
+
 #endif				/* _I915_DRM_H_ */
intel/intel_bufmgr_gem.c +10 -0
index ff4b663..65a77d6 100644
@@ -1032,6 +1032,30 @@ static int do_mmap_cpu(drm_intel_bufmgr_gem *bufmgr_gem,
 	return 0;
 }
 
+enum i915_cache_level {
+	I915_CACHE_NONE,
+	I915_CACHE_LLC,
+	I915_CACHE_LLC_MLC, /* gen6+ */
+};
+
+static int get_cache_type(drm_intel_bo *bo)
+{
+	struct drm_i915_gem_get_cache_type cache = {0, 0};
+	drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;

intel/intel_bufmgr_gem.c static int do_mmap_cpu(drm_intel_bufmgr_gem *bufmgr_gem, · line 1054

Quoted 10 lines
intel/intel_bufmgr_gem.c +10 -0
+	drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
+	int ret = 0;
+
+	cache.handle = bo_gem->gem_handle;
+	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_GET_CACHE_TYPE,
+		       &cache);
+
+	/* This should maintain old behavior */
+	if (ret)
+		return 0;

Can you return I915_CACHE_NONE instead of this magic 0?

intel/intel_bufmgr_gem.c static int do_mmap_cpu(drm_intel_bufmgr_gem *bufmgr_gem, · line 1056

Quoted 1 line
intel/intel_bufmgr_gem.c +1 -0
+	return cache.cache_level;

Can we do

#define CACHE_LEVEL 0xff
return cache.cache_leve & CACHE_LEVEL

instead so that we retain a few bits for flags (e.g. gfdt or whatever other crazy stuff future hw might bring)? Alternatively, just add 64 bits of pad to the ioctl struct.

Quoted 17 lines
intel/intel_bufmgr_gem.c +4 -2
+}
+
 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;
@@ -1065,8 +1089,8 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)
 		    strerror(errno));
 	}
 
-	/* TODO ask kernel if llc cached, in that case don't clear this */
-	bo_gem->in_gtt_domain = 0;
+	if (get_cache_type(bo) != I915_CACHE_LLC)
+		bo_gem->in_gtt_domain = 0;
 
 	pthread_mutex_unlock(&bufmgr_gem->lock);
 

intel/intel_bufmgr_gem.c int drm_intel_gem_bo_map_nonblocking(drm_intel_bo *bo) · line 1366

Quoted 10 lines
intel/intel_bufmgr_gem.c +2 -2
@@ -1335,14 +1359,14 @@ int drm_intel_gem_bo_map_nonblocking(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 gpu_coherent_cpu_map;
+	int gpu_coherent_cpu_map = 0;
 	int ret;
 
 	pthread_mutex_lock(&bufmgr_gem->lock);
-	assert(bo_gem->tiling_mode != I915_TILING_NONE);
+	assert(bo_gem->tiling_mode == I915_TILING_NONE);

Oops, good catch ;-)

Quoted 7 lines
intel/intel_bufmgr_gem.c +2 -2
-	/* TODO ask the kernel about this */
-	gpu_coherent_cpu_map = 1;
+	if (bufmgr_gem->gen >= 6)
+		gpu_coherent_cpu_map = 1;
 
 	if (gpu_coherent_cpu_map) {
 		ret = do_mmap_cpu(bufmgr_gem, bo_gem);
Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#19 lore raw

PATCH 1/1 drm/i915: ioctl to query a bo's cache level

In reply to Ben Widawsky
---
 drivers/gpu/drm/i915/i915_dma.c |    1 +
 drivers/gpu/drm/i915/i915_drv.h |    2 ++
 drivers/gpu/drm/i915/i915_gem.c |   23 +++++++++++++++++++++++
 include/drm/i915_drm.h          |    7 +++++++
 4 files changed, 33 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -0
index 8a3942c..8178cbb 100644
@@ -2292,6 +2292,7 @@ struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHE_TYPE, i915_gem_get_cache_type_ioctl, DRM_UNLOCKED),
 };
 
 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 7916bd9..2dfcb3d 100644
@@ -1118,6 +1118,8 @@ int i915_gem_get_tiling(struct drm_device *dev, void *data,
 			struct drm_file *file_priv);
 int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 				struct drm_file *file_priv);
+int i915_gem_get_cache_type_ioctl(struct drm_device *dev, void *data,
+				  struct drm_file *file_priv);
 void i915_gem_load(struct drm_device *dev);
 int i915_gem_init_object(struct drm_gem_object *obj);
 int __must_check i915_gem_flush_ring(struct intel_ring_buffer *ring,
drivers/gpu/drm/i915/i915_gem.c +23 -0
index a546a71..362da16 100644
@@ -3777,6 +3777,29 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 }
 
 int
+i915_gem_get_cache_type_ioctl(struct drm_device *dev, void *data,
+			      struct drm_file *file_priv)
+{
+
+	struct drm_i915_gem_get_cache_type *args = data;
+	struct drm_i915_gem_object *obj;
+	int ret = 0;
+
+	obj = to_intel_bo(drm_gem_object_lookup(dev, file_priv, args->handle));
+	if (&obj->base == NULL) {
+		ret = -ENOENT;
+		goto out;
+	}
+
+	args->cache_level = obj->cache_level;
+
+	drm_gem_object_unreference(&obj->base);
+
+out:
+	return ret;
+}
+
+int
 i915_gem_idle(struct drm_device *dev)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
include/drm/i915_drm.h +7 -0
index 28c0d11..a0dff8a 100644
@@ -198,6 +198,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_OVERLAY_PUT_IMAGE	0x27
 #define DRM_I915_OVERLAY_ATTRS	0x28
 #define DRM_I915_GEM_EXECBUFFER2	0x29
+#define DRM_I915_GEM_GET_CACHE_TYPE	0x2a
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -239,6 +240,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_MADVISE	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MADVISE, struct drm_i915_gem_madvise)
 #define DRM_IOCTL_I915_OVERLAY_PUT_IMAGE	DRM_IOW(DRM_COMMAND_BASE + DRM_I915_OVERLAY_PUT_IMAGE, struct drm_intel_overlay_put_image)
 #define DRM_IOCTL_I915_OVERLAY_ATTRS	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
+#define DRM_IOCTL_I915_GEM_GET_CACHE_TYPE	DRM_IOR  (DRM_COMMAND_BASE + DRM_I915_GEM_GET_CACHE_TYPE, struct drm_i915_gem_get_cache_type)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -844,4 +846,9 @@ struct drm_intel_overlay_attrs {
 	__u32 gamma5;
 };
 
+struct drm_i915_gem_get_cache_type {
+	__u32 handle;
+	__u32 cache_level;
+};
+
 #endif				/* _I915_DRM_H_ */
Signature · 1 line
1.7.6.3
#20 lore raw

Re: [PATCH] drm/i915: ioctl to query a bo's cache level

Quoted 48 lines · Ben Widawsky
---
 drivers/gpu/drm/i915/i915_dma.c |    1 +
 drivers/gpu/drm/i915/i915_drv.h |    2 ++
 drivers/gpu/drm/i915/i915_gem.c |   23 +++++++++++++++++++++++
 include/drm/i915_drm.h          |    7 +++++++
 4 files changed, 33 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -0
index 8a3942c..8178cbb 100644
@@ -2292,6 +2292,7 @@ struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHE_TYPE, i915_gem_get_cache_type_ioctl, DRM_UNLOCKED),
 };
 
 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 7916bd9..2dfcb3d 100644
@@ -1118,6 +1118,8 @@ int i915_gem_get_tiling(struct drm_device *dev, void *data,
 			struct drm_file *file_priv);
 int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 				struct drm_file *file_priv);
+int i915_gem_get_cache_type_ioctl(struct drm_device *dev, void *data,
+				  struct drm_file *file_priv);
 void i915_gem_load(struct drm_device *dev);
 int i915_gem_init_object(struct drm_gem_object *obj);
 int __must_check i915_gem_flush_ring(struct intel_ring_buffer *ring,
drivers/gpu/drm/i915/i915_gem.c +5 -0
index a546a71..362da16 100644
@@ -3777,6 +3777,29 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 }
 
 int
+i915_gem_get_cache_type_ioctl(struct drm_device *dev, void *data,
+			      struct drm_file *file_priv)
+{
+
+	struct drm_i915_gem_get_cache_type *args = data;

drivers/gpu/drm/i915/i915_gem.c void i915_gem_free_object(struct drm_gem_object *gem_obj) · line 3794

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+	struct drm_i915_gem_object *obj;
+	int ret = 0;
+
+	obj = to_intel_bo(drm_gem_object_lookup(dev, file_priv, args->handle));
+	if (&obj->base == NULL) {
+		ret = -ENOENT;
+		goto out;
+	}
+
+	args->cache_level = obj->cache_level;

Grab struct_mutex around this, obj->cache_level might change over the lifetime of the bo. Yeah, our locking is a mess, I know ;-)

Quoted 43 lines
drivers/gpu/drm/i915/i915_gem.c +7 -0
+	drm_gem_object_unreference(&obj->base);
+
+out:
+	return ret;
+}
+
+int
 i915_gem_idle(struct drm_device *dev)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
include/drm/i915_drm.h +7 -0
index 28c0d11..a0dff8a 100644
@@ -198,6 +198,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_I915_OVERLAY_PUT_IMAGE	0x27
 #define DRM_I915_OVERLAY_ATTRS	0x28
 #define DRM_I915_GEM_EXECBUFFER2	0x29
+#define DRM_I915_GEM_GET_CACHE_TYPE	0x2a
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -239,6 +240,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_MADVISE	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MADVISE, struct drm_i915_gem_madvise)
 #define DRM_IOCTL_I915_OVERLAY_PUT_IMAGE	DRM_IOW(DRM_COMMAND_BASE + DRM_I915_OVERLAY_PUT_IMAGE, struct drm_intel_overlay_put_image)
 #define DRM_IOCTL_I915_OVERLAY_ATTRS	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_OVERLAY_ATTRS, struct drm_intel_overlay_attrs)
+#define DRM_IOCTL_I915_GEM_GET_CACHE_TYPE	DRM_IOR  (DRM_COMMAND_BASE + DRM_I915_GEM_GET_CACHE_TYPE, struct drm_i915_gem_get_cache_type)
 
 /* Allow drivers to submit batchbuffers directly to hardware, relying
  * on the security mechanisms provided by hardware.
@@ -844,4 +846,9 @@ struct drm_intel_overlay_attrs {
 	__u32 gamma5;
 };
 
+struct drm_i915_gem_get_cache_type {
+	__u32 handle;
+	__u32 cache_level;
+};
+
 #endif				/* _I915_DRM_H_ */
Signature · 1 line
1.7.6.3
Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#21 lore raw

Re: [PATCH] drm/i915: ioctl to query a bo's cache level

Quoted 19 lines · Daniel Vetter
Quoted 18 lines · Ben Widawsky
drivers/gpu/drm/i915/i915_gem.c +10 -0
index a546a71..362da16 100644
@@ -3777,6 +3777,29 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 }
 
 int
+i915_gem_get_cache_type_ioctl(struct drm_device *dev, void *data,
+			      struct drm_file *file_priv)
+{
+
+	struct drm_i915_gem_get_cache_type *args = data;
+	struct drm_i915_gem_object *obj;
+	int ret = 0;
+
+	obj = to_intel_bo(drm_gem_object_lookup(dev, file_priv, args->handle));
+	if (&obj->base == NULL) {
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem.c void i915_gem_free_object(struct drm_gem_object *gem_obj) · line 3794

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+		ret = -ENOENT;
+		goto out;
+	}
+
+	args->cache_level = obj->cache_level;

Grab struct_mutex around this, obj->cache_level might change over the lifetime of the bo. Yeah, our locking is a mess, I know ;-)

I don't see how a lock by itself helps. The cache_level could change as soon as you release the lock which results in the same problem.

Ben

#22 lore raw

Re: [PATCH] drm/i915: ioctl to query a bo's cache level

Quoted 29 lines · Ben Widawsky
Quoted 19 lines · Daniel Vetter
Quoted 18 lines · Ben Widawsky
drivers/gpu/drm/i915/i915_gem.c +10 -0
index a546a71..362da16 100644
@@ -3777,6 +3777,29 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 }
 
 int
+i915_gem_get_cache_type_ioctl(struct drm_device *dev, void *data,
+			      struct drm_file *file_priv)
+{
+
+	struct drm_i915_gem_get_cache_type *args = data;
+	struct drm_i915_gem_object *obj;
+	int ret = 0;
+
+	obj = to_intel_bo(drm_gem_object_lookup(dev, file_priv, args->handle));
+	if (&obj->base == NULL) {
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem.c void i915_gem_free_object(struct drm_gem_object *gem_obj) · line 3794

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+		ret = -ENOENT;
+		goto out;
+	}
+
+	args->cache_level = obj->cache_level;

Grab struct_mutex around this, obj->cache_level might change over the lifetime of the bo. Yeah, our locking is a mess, I know ;-)

Quoted 2 lines

I don't see how a lock by itself helps. The cache_level could change as soon as you release the lock which results in the same problem.

Yes, you will always have the issue of coordination between processes, but you do need the look around the unref, or use
drm_gem_object_unreference_unlocked(&obj->base);
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#23 lore raw

Re: [PATCH cont'd] intel: non-blocking mmaps on the cheap

In reply to Ben Widawsky
Quoted 2 lines · Ben Widawsky

Overall, I like this series much better. Do we want to sneak in a set cache level with the same IOCTL while we're at it?

I think the set_cache_level can wait a tad bit, and this stuff here looks (almost) ready. A few nitpicks remains, though.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#24 lore raw
In reply to Daniel Vetter
Quoted 8 lines · Daniel Vetter

Now non-blocking cpu mmaps make very much sense on llc/snooped buffer objects. So I think we actually need an ioctl to get obj->cache_level so userspace can decide whether it should use non-blocking gtt mmaps or cpu (non-blocking) cpu mmaps. We might as well go full-circle, make Chris happy and merge the corresponding set_cache_level ioclt to enable snooped buffers on machines with ilk-like coherency (i.e. that atom thing I'm hearing about ...). But imo that's material for non-blocking mmaps, step 2.

That's not enough to make me completely happy. I also have the use-case of wanting to efficiently handle compositing with client allocated memory i.e. persistent ShmPixmaps, where coherency either needs to be transparent to the client or (worse) synchronicity imposed by the server. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#25 lore raw
Quoted 10 lines · Chris Wilson
Quoted 8 lines · Daniel Vetter

Now non-blocking cpu mmaps make very much sense on llc/snooped buffer objects. So I think we actually need an ioctl to get obj->cache_level so userspace can decide whether it should use non-blocking gtt mmaps or cpu (non-blocking) cpu mmaps. We might as well go full-circle, make Chris happy and merge the corresponding set_cache_level ioclt to enable snooped buffers on machines with ilk-like coherency (i.e. that atom thing I'm hearing about ...). But imo that's material for non-blocking mmaps, step 2.

Quoted 4 lines

That's not enough to make me completely happy. I also have the use-case of wanting to efficiently handle compositing with client allocated memory i.e. persistent ShmPixmaps, where coherency either needs to be transparent to the client or (worse) synchronicity imposed by the server.

I know, just snoopable bo support only makes you half-happy and you need fancy stuff in addition ;-) But if your sna branch can halfway easily profit from simle snoopable bo support on !llc machines, I think that'll give us an easy way to check api sanity for the new ioctl. -Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#26 lore raw
In reply to Daniel Vetter
Quoted 16 lines · On Tue, 20 Sep 2011 13:06:43 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 7 lines · Ben Widawsky

I'm going to keep this short...
Patch 5 is my test case.
On Gen6 I see slightly better performance. On Gen5 I see really really improvements (like 3x) for non GTT write only maps over regular mmaps. GTT mappings don't really show any improvements as a whole.

Quoted 5 lines

Better tests would be nice, but without more significant Mesa changes, or better benchmarks, I'm not sure how to get those. While I think these patches are mostly complete, ideas for better testing are very welcome. Also of course, general optimizations or pointing out my errors would be nice.

Ok, I'm gonna be the dense annoying bastard here:

Quoted 7 lines

- Can we stop calling this mappings write-only. Afaics the distinguishing feature is that they're non-blocking. And yes, current users only use non-blocking paths to upload data because the amount of data we're currently downloading is so small. Hence we can use on bo for each download without wasting too much space and still avoid unnecessary blocking. Bit I think this will change, e.g. with designs like sna that tightly integrate gpu and sw rendering. Or OpenCL.

I really wanted to argue this point, but you're right. I think what I'll do is make the libdrm stub be called non-blocking, and then per gen we can do whatever with set_domain.

Quoted 5 lines

- Why do we need any patches for gtt non-blocking mmaps? I've re-read our code, and afaics we're only calling wait_rendering from gem_fault if obj->gtt_space == NULL. I.e. there's no way the gpu is currently using the data and hence no way for us to block on it.

I think you're right. I misread this before, we take an early exit if its write domain is already GTT, so we don't sync flush at that point. I believe this is rooted in the fact that my original versions of the patch wouldn't call set domain at all (it used create() and mmap() ioctls to mark buffers as write only), but with those changes, I think this is unnecessary with prefaulting.

Quoted 5 lines

I think the only thing needed is a small libdrm batch to enable non-blocking gtt mmaps

void drm_intel_enable_non_blocking_gtt_mmap(obj)

Quoted 7 lines

which sets a bit somewhere and moves the obj (once) into the gtt domain. And a corresponding change in gtt_mmap to disable the set_domain call. This only works as long as no one else access the object from the cpu domain, but afaics we'll use non-blocking mmaps only for unshared buffers, so that should be fine.

I might also just be dense and not see the issue ...

I should have documented that these buffers should not be flinked. I should probably enforce that in the driver. I will take a note to change that. Anyway, I think you're right, and the result of this is to remove the hunk from i915_gem_fault, and prefault do you agree?

Quoted 5 lines

- I'm sorry having suggested to implement the clflush ioctl, I think it's a foolish idea, now. Non-blocking mmaps is a performance optimization, needing to sync caches with clflush is very much the opposite. So I think we can dustbin this.

I disagree. I think it's nice function to add for people too lazy to do micro-optimizations. The flushing of the full object is almost guaranteed to make performance worse though, that should really only be for testing purposes.

Quoted 9 lines

Now non-blocking cpu mmaps make very much sense on llc/snooped
buffer objects. So I think we actually need an ioctl to get obj->cache_level so userspace can decide whether it should use non-blocking gtt mmaps or cpu (non-blocking) cpu mmaps. We might as well go full-circle, make Chris happy and merge the corresponding set_cache_level ioclt to enable snooped buffers on machines with ilk-like coherency (i.e. that atom thing I'm hearing about ...). But imo that's material for non-blocking mmaps, step 2.

I'd need to research this a bit more, let me defer response on this part. By the way, which set_cache_level ioctl are you referring to?

Quoted 2 lines

Cheers, Daniel

Ben

#27 lore raw
Quoted 11 lines · Ben Widawsky
Quoted 4 lines · On Tue, 20 Sep 2011 13:06:43 +0200 Daniel Vetter <[email protected]> wrote:

- I'm sorry having suggested to implement the clflush ioctl, I think it's a foolish idea, now. Non-blocking mmaps is a performance optimization, needing to sync caches with clflush is very much the opposite. So I think we can dustbin this.

I disagree. I think it's nice function to add for people too lazy to do micro-optimizations. The flushing of the full object is almost guaranteed to make performance worse though, that should really only be for testing purposes.

Let me whip up a simple patch for libdrm to show why I think we don't need this.

Quoted 11 lines
Quoted 8 lines

Now non-blocking cpu mmaps make very much sense on llc/snooped
buffer objects. So I think we actually need an ioctl to get obj->cache_level so userspace can decide whether it should use non-blocking gtt mmaps or cpu (non-blocking) cpu mmaps. We might as well go full-circle, make Chris happy and merge the corresponding set_cache_level ioclt to enable snooped buffers on machines with ilk-like coherency (i.e. that atom thing I'm hearing about ...). But imo that's material for non-blocking mmaps, step 2.

I'd need to research this a bit more, let me defer response on this part. By the way, which set_cache_level ioctl are you referring to?

The set_cache_level ioctl that doesn't exist yet ;-) Essentially something to set/get obj->cache_level, so that Chris can use snoopable bos on !llc machines. But as I've said, that's probably something for the extend non-blocking mmap support and not something we need right away.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48