Skip to contentSkip to conversation

Support for creating/using Stolen memory backed objects

PATCH Superseded [email protected] 2 participants 11 messages Apr 29, 2015 – May 5, 2015

Subsystems (3)

v2 of 22 Superseded Latest is v22 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support for creating/using Stolen memory backed objects

From: Ankitprasad Sharma <[email protected]>

This patch series adds support for creating/using Stolen memory backed objects.

Despite being a unified memory architecture (UMA) some bits of memory are more equal than others. In particular we have the thorny issue of stolen memory, memory stolen from the system by the BIOS and reserved for igfx use. Stolen memory is required for some functions of the GPU and display engine, but in general it goes wasted. Whilst we cannot return it back to the system, we need to find some other method for utilising it. As we do not support direct access to the physical address in the stolen region, it behaves like a different class of memory, closer in kin to local GPU memory. This strongly suggests that we need a placement model like TTM if we are to fully utilize these discrete chunks of differing memory.

To add support for creating Stolen memory backed objects, we extend the drm_i915_gem_create structure, by adding a new flag through which user can specify the preference to allocate the object from stolen memory, which if set, an attempt will be made to allocate the object from stolen memory subject to the availability of free space in the stolen region.

This patch series adds support for clearing buffer objects via blitter engines. This is particularly useful for clearing out the memory from stolen region, but can also be used for other shmem allocated objects. Also adding support for stealing purgable stolen pages, if we run out of stolen memory when trying to allocate an object.

This also adds support for read/write from/to objects not backed by shmem using the pread/pwrite interface.
Series also extends the current get_aperture ioctl to retrieve the total and available size of the stolen region

This can be verified using IGT tests: igt/gem_create_stolen

Ankitprasad Sharma (4):
drm/i915: Clearing buffer objects via blitter engine drm/i915: Support for creating Stolen memory backed objects drm/i915: Support for pread/pwrite from/to non shmem backed objects drm/i915: Add support for getting size of the stolen region

Chris Wilson (1):
drm/i915: Add support for stealing purgable stolen pages

 drivers/gpu/drm/i915/Makefile          |   1 +
 drivers/gpu/drm/i915/i915_dma.c        |   3 +
 drivers/gpu/drm/i915/i915_drv.h        |  17 +++
 drivers/gpu/drm/i915/i915_gem.c        | 171 +++++++++++++++++++++++++---
 drivers/gpu/drm/i915/i915_gem_exec.c   | 197 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_gem_stolen.c | 121 ++++++++++++++++++--
 drivers/gpu/drm/i915/intel_lrc.c       |   2 +-
 drivers/gpu/drm/i915/intel_lrc.h       |   2 +
 include/uapi/drm/i915_drm.h            |  21 ++++
 9 files changed, 509 insertions(+), 26 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_gem_exec.c
Signature · 6 lines
1.9.1

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

PATCH v2 1/5 drm/i915: Clearing buffer objects via blitter engine

From: Ankitprasad Sharma <[email protected]>

This patch adds support for clearing buffer objects via blitter engines. This is particularly useful for clearing out the memory from stolen region.

v2: Add support for using execlists & PPGTT

v3: Fix issues in legacy ringbuffer submission mode

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/Makefile        |   1 +
 drivers/gpu/drm/i915/i915_drv.h      |   4 +
 drivers/gpu/drm/i915/i915_gem_exec.c | 197 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_lrc.c     |   2 +-
 drivers/gpu/drm/i915/intel_lrc.h     |   2 +
 5 files changed, 205 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/i915_gem_exec.c
drivers/gpu/drm/i915/Makefile +1 -0
index a69002e..711a87d 100644
@@ -25,6 +25,7 @@ i915-y += i915_cmd_parser.o \
 	  i915_gem_debug.o \
 	  i915_gem_dmabuf.o \
 	  i915_gem_evict.o \
+	  i915_gem_exec.o \
 	  i915_gem_execbuffer.o \
 	  i915_gem_gtt.o \
 	  i915_gem.o \
drivers/gpu/drm/i915/i915_drv.h +4 -0
index eb38cd1..21a2b1f 100644
@@ -2927,6 +2927,10 @@ int __must_check i915_gem_evict_something(struct drm_device *dev,
 int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
 int i915_gem_evict_everything(struct drm_device *dev);
 
+/* i915_gem_exec.c */
+int i915_gem_exec_clear_object(struct drm_i915_gem_object *obj,
+			       struct drm_i915_file_private *file_priv);
+
 /* belongs in i915_gem_gtt.h */
 static inline void i915_gem_chipset_flush(struct drm_device *dev)
 {
drivers/gpu/drm/i915/i915_gem_exec.c new file +197 -0

197 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.c +1 -1
index fcb074b..5481638 100644
@@ -559,7 +559,7 @@ static int execlists_context_queue(struct intel_engine_cs *ring,
 	return 0;
 }
 
-static int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf,
+int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf,
 					      struct intel_context *ctx)
 {
 	struct intel_engine_cs *ring = ringbuf->ring;
drivers/gpu/drm/i915/intel_lrc.h +2 -0
index adb731e4..80a873b 100644
@@ -42,6 +42,8 @@ int intel_logical_rings_init(struct drm_device *dev);
 
 int logical_ring_flush_all_caches(struct intel_ringbuffer *ringbuf,
 				  struct intel_context *ctx);
+int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf,
+				       struct intel_context *ctx);
 /**
  * intel_logical_ring_advance() - advance the ringbuffer tail
  * @ringbuf: Ringbuffer to advance.
Signature · 6 lines
1.9.1

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

PATCH v2 2/5 drm/i915: Support for creating Stolen memory backed objects

In reply to [email protected]

From: Ankitprasad Sharma <[email protected]>

Extend the drm_i915_gem_create structure to add support for creating Stolen memory backed objects. Added a new flag through which user can specify the preference to allocate the object from stolen memory, which if set, an attempt will be made to allocate the object from stolen memory subject to the availability of free space in the stolen region.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_dma.c |  3 +++
 drivers/gpu/drm/i915/i915_gem.c | 31 +++++++++++++++++++++++++++----
 include/uapi/drm/i915_drm.h     | 15 +++++++++++++++
 3 files changed, 45 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +3 -0
index d49ed68..491c91f 100644
@@ -163,6 +163,9 @@ static int i915_getparam(struct drm_device *dev, void *data,
 		if (!value)
 			return -ENODEV;
 		break;
+	case I915_PARAM_CREATE_VERSION:
+		value = 1;
+		break;
 	default:
 		DRM_DEBUG("Unknown parameter %d\n", param->param);
 		return -EINVAL;
drivers/gpu/drm/i915/i915_gem.c +27 -4
index 84e2a23..81c5381 100644
@@ -391,7 +391,8 @@ static int
 i915_gem_create(struct drm_file *file,
 		struct drm_device *dev,
 		uint64_t size,
-		uint32_t *handle_p)
+		uint32_t *handle_p,
+		uint32_t flags)
 {
 	struct drm_i915_gem_object *obj;
 	int ret;
@@ -401,8 +402,29 @@ i915_gem_create(struct drm_file *file,
 	if (size == 0)
 		return -EINVAL;
 
+	if (flags & ~(I915_CREATE_PLACEMENT_STOLEN))
+		return -EINVAL;
+
 	/* Allocate the new object */
-	obj = i915_gem_alloc_object(dev, size);
+	if (flags & I915_CREATE_PLACEMENT_STOLEN) {
+		mutex_lock(&dev->struct_mutex);
+		obj = i915_gem_object_create_stolen(dev, size);
+		if (!obj) {
+			mutex_unlock(&dev->struct_mutex);
+			return -ENOMEM;
+		}
+
+		ret = i915_gem_exec_clear_object(obj, file->driver_priv);
+		if (ret) {
+			i915_gem_object_free(obj);
+			mutex_unlock(&dev->struct_mutex);
+			return ret;
+		}
+
+		mutex_unlock(&dev->struct_mutex);
+	} else
+		obj = i915_gem_alloc_object(dev, size);
+
 	if (obj == NULL)
 		return -ENOMEM;
 
@@ -425,7 +447,7 @@ i915_gem_dumb_create(struct drm_file *file,
 	args->pitch = ALIGN(args->width * DIV_ROUND_UP(args->bpp, 8), 64);
 	args->size = args->pitch * args->height;
 	return i915_gem_create(file, dev,
-			       args->size, &args->handle);
+			       args->size, &args->handle, 0);
 }
 
 /**
@@ -438,7 +460,8 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_gem_create *args = data;
 
 	return i915_gem_create(file, dev,
-			       args->size, &args->handle);
+			       args->size, &args->handle,
+			       args->flags);
 }
 
 static inline int
include/uapi/drm/i915_drm.h +15 -0
index 8d1be90..ab4f3a9 100644
@@ -350,6 +350,7 @@ typedef struct drm_i915_irq_wait {
 #define I915_PARAM_REVISION              32
 #define I915_PARAM_SUBSLICE_TOTAL	 33
 #define I915_PARAM_EU_TOTAL		 34
+#define I915_PARAM_CREATE_VERSION	 35
 
 typedef struct drm_i915_getparam {
 	int param;
@@ -445,6 +446,20 @@ struct drm_i915_gem_create {
 	 */
 	__u32 handle;
 	__u32 pad;
+	/**
+	 * Requested flags (currently used for placement
+	 * (which memory domain))
+	 *
+	 * You can request that the object be created from special memory
+	 * rather than regular system pages using this parameter. Such
+	 * irregular objects may have certain restrictions (such as CPU
+	 * access to a stolen object is verboten).
+	 *
+	 * This can be used in the future for other purposes too
+	 * e.g. specifying tiling/caching/madvise
+	 */
+	__u32 flags;
+#define I915_CREATE_PLACEMENT_STOLEN (1<<0) /* Cannot use CPU mmaps or pread/pwrite */
 };
 
 struct drm_i915_gem_pread {
Signature · 6 lines
1.9.1

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

PATCH v2 3/5 drm/i915: Add support for stealing purgable stolen pages

In reply to [email protected]

From: Chris Wilson <[email protected]>

If we run out of stolen memory when trying to allocate an object, see if we can reap enough purgeable objects to free up enough contiguous free space for the allocation. This is in principle very much like evicting objects to free up enough contiguous space in the vma when binding a new object - and you will be forgiven for thinking that the code looks very similar.

At the moment, we do not allow userspace to allocate objects in stolen, so there is neither the memory pressure to trigger stolen eviction nor any purgeable objects inside the stolen arena. However, this will change in the near future, and so better management and defragmentation of stolen memory will become a real issue.

v2: Remember to remove the drm_mm_node.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_gem_stolen.c | 121 ++++++++++++++++++++++++++++++---
 1 file changed, 110 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_gem_stolen.c +110 -11
index f8da716..0a38d71 100644
@@ -430,18 +430,29 @@ cleanup:
 	return NULL;
 }
 
-struct drm_i915_gem_object *
-i915_gem_object_create_stolen(struct drm_device *dev, u32 size)
+static bool mark_free(struct drm_i915_gem_object *obj, struct list_head *unwind)
+{
+	if (obj->stolen == NULL)
+		return false;
+
+	if (obj->madv != I915_MADV_DONTNEED)
+		return false;
+
+	if (i915_gem_obj_is_pinned(obj))
+		return false;
+
+	list_add(&obj->obj_exec_link, unwind);
+	return drm_mm_scan_add_block(obj->stolen);
+}
+
+static struct drm_mm_node *
+stolen_alloc(struct drm_i915_private *dev_priv, u32 size)
 {
-	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct drm_i915_gem_object *obj;
 	struct drm_mm_node *stolen;
+	struct drm_i915_gem_object *obj;
+	struct list_head unwind, evict;
 	int ret;
 
-	if (!drm_mm_initialized(&dev_priv->mm.stolen))
-		return NULL;
-
-	DRM_DEBUG_KMS("creating stolen object: size=%x\n", size);
 	if (size == 0)
 		return NULL;
 
@@ -451,11 +462,99 @@ i915_gem_object_create_stolen(struct drm_device *dev, u32 size)
 
 	ret = drm_mm_insert_node(&dev_priv->mm.stolen, stolen, size,
 				 4096, DRM_MM_SEARCH_DEFAULT);
-	if (ret) {
-		kfree(stolen);
-		return NULL;
+	if (ret == 0)
+		return stolen;
+
+	/* No more stolen memory available, or too fragmented.
+	 * Try evicting purgeable objects and search again.
+	 */
+
+	drm_mm_init_scan(&dev_priv->mm.stolen, size, 4096, 0);
+	INIT_LIST_HEAD(&unwind);
+
+	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
+		if (mark_free(obj, &unwind))
+			goto found;
+
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
+		if (mark_free(obj, &unwind))
+			goto found;
+
+found:
+	INIT_LIST_HEAD(&evict);
+	while (!list_empty(&unwind)) {
+		obj = list_first_entry(&unwind,
+				       struct drm_i915_gem_object,
+				       obj_exec_link);
+		list_del_init(&obj->obj_exec_link);
+
+		if (drm_mm_scan_remove_block(obj->stolen)) {
+			list_add(&obj->obj_exec_link, &evict);
+			drm_gem_object_reference(&obj->base);
+		}
 	}
 
+	ret = 0;
+	while (!list_empty(&evict)) {
+		obj = list_first_entry(&evict,
+				       struct drm_i915_gem_object,
+				       obj_exec_link);
+		list_del_init(&obj->obj_exec_link);
+
+		if (ret == 0) {
+			struct i915_vma *vma, *vma_next;
+
+			list_for_each_entry_safe(vma, vma_next,
+						 &obj->vma_list,
+						 vma_link)
+				if (i915_vma_unbind(vma))
+					break;
+
+			/* Stolen pins its pages to prevent the
+			 * normal shrinker from processing stolen
+			 * objects.
+			 */
+			i915_gem_object_unpin_pages(obj);
+
+			ret = i915_gem_object_put_pages(obj);
+			if (ret == 0) {
+				i915_gem_object_release_stolen(obj);
+				obj->madv = __I915_MADV_PURGED;
+			} else
+				i915_gem_object_pin_pages(obj);
+		}
+
+		drm_gem_object_unreference(&obj->base);
+	}
+
+	if (ret == 0)
+		ret = drm_mm_insert_node(&dev_priv->mm.stolen, stolen, size,
+					 4096, DRM_MM_SEARCH_DEFAULT);
+	if (ret == 0)
+		return stolen;
+
+	kfree(stolen);
+	return NULL;
+}
+
+struct drm_i915_gem_object *
+i915_gem_object_create_stolen(struct drm_device *dev, u32 size)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj;
+	struct drm_mm_node *stolen;
+
+	lockdep_assert_held(&dev->struct_mutex);
+
+	if (!drm_mm_initialized(&dev_priv->mm.stolen))
+		return NULL;
+
+	DRM_DEBUG_KMS("creating stolen object: size=%x\n", size);
+
+	stolen = stolen_alloc(dev_priv, size);
+	if (stolen == NULL)
+		return NULL;
+
 	obj = _i915_gem_object_create_stolen(dev, stolen);
 	if (obj)
 		return obj;
Signature · 6 lines
1.9.1

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

PATCH v2 4/5 drm/i915: Support for pread/pwrite from/to non shmem backed objects

In reply to [email protected]

From: Ankitprasad Sharma <[email protected]>

This patch adds support for extending the pread/pwrite functionality for objects not backed by shmem. The access will be made through gtt interface.
This will cover prime objects as well as stolen memory backed objects but for userptr objects it is still forbidden.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_drv.h |   7 +++
 drivers/gpu/drm/i915/i915_gem.c | 125 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 123 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +7 -0
index 21a2b1f..a568cd1 100644
@@ -3270,4 +3270,11 @@ static inline void i915_trace_irq_get(struct intel_engine_cs *ring,
 		i915_gem_request_assign(&ring->trace_irq_req, req);
 }
 
+/* Checking if pread/pwrite is allowed for the object */
+inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
+{
+	/* pread/pwrite is forbidden for userptrs */
+	return !obj->userptr.mm;
+}
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +116 -9

155 lines not on this page · raw message

Signature · 6 lines
1.9.1

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

Re: [PATCH 4/5] drm/i915: Support for pread/pwrite from/to non shmem backed objects

Quoted 21 lines · On Wed, Apr 29, 2015 at 03:01:58PM +0530, [email protected] wrote:

From: Ankitprasad Sharma <[email protected]>

This patch adds support for extending the pread/pwrite functionality for objects not backed by shmem. The access will be made through gtt interface.
This will cover prime objects as well as stolen memory backed objects but for userptr objects it is still forbidden.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_drv.h |   7 +++
 drivers/gpu/drm/i915/i915_gem.c | 125 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 123 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -0
index 21a2b1f..a568cd1 100644

drivers/gpu/drm/i915/i915_drv.h static inline void i915_trace_irq_get(struct intel_engine_cs *ring, · line 3278

Quoted 9 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
@@ -3270,4 +3270,11 @@ static inline void i915_trace_irq_get(struct intel_engine_cs *ring,
 		i915_gem_request_assign(&ring->trace_irq_req, req);
 }
 
+/* Checking if pread/pwrite is allowed for the object */
+inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
+{
+	/* pread/pwrite is forbidden for userptrs */
+	return !obj->userptr.mm;
+}

Not quite. Just wasn't implemented (as there wasn't much point since we couldn't provide other CPU access) but there is no reason to arbitrary limit the API - especially as you are in the process of removing that arbitrary limitation!

Quoted 70 lines
drivers/gpu/drm/i915/i915_drv.h +1 -0
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +60 -0
index 81c5381..3491bd3 100644
@@ -631,6 +631,96 @@ shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length,
 	return ret ? - EFAULT : 0;
 }
 
+static inline int
+slow_user_access(struct io_mapping *mapping,
+		 loff_t page_base, int page_offset,
+		 char __user *user_data,
+		 int length, bool write)
+{
+	void __iomem *vaddr_inatomic;
+	void *vaddr;
+	unsigned long unwritten;
+
+	vaddr_inatomic = io_mapping_map_wc(mapping, page_base);
+	/* We can use the cpu mem copy function because this is X86. */
+	vaddr = (void __force *)vaddr_inatomic + page_offset;
+	if (write)
+		unwritten = __copy_from_user(vaddr, user_data, length);
+	else
+		unwritten = __copy_to_user(user_data, vaddr, length);
+
+	io_mapping_unmap(vaddr_inatomic);
+	return unwritten;
+}
+
+static int
+i915_gem_gtt_pread_pwrite(struct drm_device *dev,
+			  struct drm_i915_gem_object *obj, uint64_t size,
+			  uint64_t data_offset, uint64_t data_ptr, bool write)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	char __user *user_data;
+	ssize_t remain;
+	loff_t offset, page_base;
+	int page_offset, page_length, ret = 0;
+
+	ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_MAPPABLE);
+	if (ret)
+		goto out;
+
+	ret = i915_gem_object_set_to_gtt_domain(obj, write);
+	if (ret)
+		goto out_unpin;
+
+	ret = i915_gem_object_put_fence(obj);
+	if (ret)
+		goto out_unpin;
+
+	user_data = to_user_ptr(data_ptr);
+	remain = size;
+
+	offset = i915_gem_obj_ggtt_offset(obj) + data_offset;
+
+	if (write)
+		intel_fb_obj_invalidate(obj, NULL, ORIGIN_GTT);
+
+	while (remain > 0) {
+		/* Operation in this page
+		 *
+		 * page_base = page offset within aperture
+		 * page_offset = offset within page
+		 * page_length = bytes to copy for this page
+		 */

drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 703

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+		page_base = offset & PAGE_MASK;
+		page_offset = offset_in_page(offset);
+		page_length = remain;
+		if ((page_offset + remain) > PAGE_SIZE)
+			page_length = PAGE_SIZE - page_offset;
+
+		/* This is a slow read/write as it tries to read from
+		 * and write to user memory which may result into page
+		 * faults
+		 */

Hmm, I am in the process of rewriting this function (GTT pwrite) to reduce aperture pressure (which will also be important here). However for your use case, we do need to drop the locks around slow_user_access() so that we can use non-atomic copy functions and *pagefault*. We do need the full level of complexity like i915_gem_shmem_pread()
-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
#6 lore raw

Re: [PATCH 4/5] drm/i915: Support for pread/pwrite from/to non shmem backed objects

Quoted 16 lines · Chris Wilson
Quoted 15 lines · On Wed, Apr 29, 2015 at 03:01:58PM +0530, [email protected] wrote:
drivers/gpu/drm/i915/i915_gem.c +15 -0
+	while (remain > 0) {
+		/* Operation in this page
+		 *
+		 * page_base = page offset within aperture
+		 * page_offset = offset within page
+		 * page_length = bytes to copy for this page
+		 */
+		page_base = offset & PAGE_MASK;
+		page_offset = offset_in_page(offset);
+		page_length = remain;
+		if ((page_offset + remain) > PAGE_SIZE)
+			page_length = PAGE_SIZE - page_offset;
+
+		/* This is a slow read/write as it tries to read from
+		 * and write to user memory which may result into page
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 703

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +2 -0
+		 * faults
+		 */

Hmm, I am in the process of rewriting this function (GTT pwrite) to reduce aperture pressure (which will also be important here). However for your use case, we do need to drop the locks around slow_user_access() so that we can use non-atomic copy functions and *pagefault*. We do need the full level of complexity like i915_gem_shmem_pread()

It would be a good exercise to try and reproduce the fautling failure condition with igt/gem_stolen.
-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
#7 lore raw

PATCH v2 5/5 drm/i915: Add support for getting size of the stolen region

In reply to [email protected]

From: Ankitprasad Sharma <[email protected]>

This patch extends the get_aperture_ioctl to add support for getting total size of the stolen region and available size of the stolen region.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_drv.h |  6 ++++++
 drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++++++-
 include/uapi/drm/i915_drm.h     |  6 ++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +6 -0
index a568cd1..a40b44f 100644
@@ -3277,4 +3277,10 @@ inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
 	return !obj->userptr.mm;
 }
 
+inline static bool i915_gem_obj_is_stolen_used(struct drm_i915_gem_object *obj)
+{
+	return obj->stolen && (i915_gem_obj_is_pinned(obj)
+			       || obj->madv == I915_MADV_WILLNEED);
+}
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +14 -1
index 3491bd3..ee93508 100644
@@ -150,17 +150,30 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_get_aperture *args = data;
 	struct drm_i915_gem_object *obj;
-	size_t pinned;
+	size_t pinned, pinned_stolen;
 
 	pinned = 0;
+	pinned_stolen = 0;
 	mutex_lock(&dev->struct_mutex);
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
 		if (i915_gem_obj_is_pinned(obj))
 			pinned += i915_gem_obj_ggtt_size(obj);
+
+	/* Calculating available stolen size */
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
+	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
 	mutex_unlock(&dev->struct_mutex);
 
 	args->aper_size = dev_priv->gtt.base.total;
 	args->aper_available_size = args->aper_size - pinned;
+	args->stolen_size = dev_priv->gtt.stolen_size;
+	args->stolen_available_size = args->stolen_size - pinned_stolen;
 
 	return 0;
 }
include/uapi/drm/i915_drm.h +6 -0
index ab4f3a9..49766b8 100644
@@ -932,6 +932,12 @@ struct drm_i915_gem_get_aperture {
 	 * bytes
 	 */
 	__u64 aper_available_size;
+
+	/** Total size of the stolen region, in bytes */
+	__u64 stolen_size;
+
+	/* Available space in the stolen region, in bytes */
+	__u64 stolen_available_size;
 };
 
 struct drm_i915_get_pipe_from_crtc_id {
Signature · 6 lines
1.9.1

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

Re: [PATCH 5/5] drm/i915: Add support for getting size of the stolen region

Quoted 46 lines · On Wed, Apr 29, 2015 at 03:01:59PM +0530, [email protected] wrote:

From: Ankitprasad Sharma <[email protected]>

This patch extends the get_aperture_ioctl to add support for getting total size of the stolen region and available size of the stolen region.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_drv.h |  6 ++++++
 drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++++++-
 include/uapi/drm/i915_drm.h     |  6 ++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +6 -0
index a568cd1..a40b44f 100644
@@ -3277,4 +3277,10 @@ inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
 	return !obj->userptr.mm;
 }
 
+inline static bool i915_gem_obj_is_stolen_used(struct drm_i915_gem_object *obj)
+{
+	return obj->stolen && (i915_gem_obj_is_pinned(obj)
+			       || obj->madv == I915_MADV_WILLNEED);
+}
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +2 -1
index 3491bd3..ee93508 100644
@@ -150,17 +150,30 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_get_aperture *args = data;
 	struct drm_i915_gem_object *obj;
-	size_t pinned;
+	size_t pinned, pinned_stolen;
 
 	pinned = 0;
+	pinned_stolen = 0;
 	mutex_lock(&dev->struct_mutex);
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
 		if (i915_gem_obj_is_pinned(obj))

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

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +9 -0
 			pinned += i915_gem_obj_ggtt_size(obj);
+
+	/* Calculating available stolen size */
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
+	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);

Ah, here you will want to iterate over the stolen drm_mm range manager to get an accurate count.

Could you respin this on top of id:[email protected] ? -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
#9 lore raw

Re: [PATCH 5/5] drm/i915: Add support for getting size of the stolen region

Quoted 61 lines · Chris Wilson
Quoted 46 lines · On Wed, Apr 29, 2015 at 03:01:59PM +0530, [email protected] wrote:

From: Ankitprasad Sharma <[email protected]>

This patch extends the get_aperture_ioctl to add support for getting total size of the stolen region and available size of the stolen region.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_drv.h |  6 ++++++
 drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++++++-
 include/uapi/drm/i915_drm.h     |  6 ++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +6 -0
index a568cd1..a40b44f 100644
@@ -3277,4 +3277,10 @@ inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
 	return !obj->userptr.mm;
 }
 
+inline static bool i915_gem_obj_is_stolen_used(struct drm_i915_gem_object *obj)
+{
+	return obj->stolen && (i915_gem_obj_is_pinned(obj)
+			       || obj->madv == I915_MADV_WILLNEED);
+}
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +2 -1
index 3491bd3..ee93508 100644
@@ -150,17 +150,30 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_get_aperture *args = data;
 	struct drm_i915_gem_object *obj;
-	size_t pinned;
+	size_t pinned, pinned_stolen;
 
 	pinned = 0;
+	pinned_stolen = 0;
 	mutex_lock(&dev->struct_mutex);
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
 		if (i915_gem_obj_is_pinned(obj))

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

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +9 -0
 			pinned += i915_gem_obj_ggtt_size(obj);
+
+	/* Calculating available stolen size */
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
+	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);

Ah, here you will want to iterate over the stolen drm_mm range manager to get an accurate count.

Quoted 2 lines

Could you respin this on top of id:[email protected] ?

I have incorporated the comments suggested by you, as well as I went through Rodrigo's patch and as such there is no dependency between the two patches.

So how do I float this patch? Shall I resend this as a separate patch in the series ([email protected]) rebasing on top of Rodrigo's changes Or as a part of this series only?

-Ankit

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

#10 lore raw

Re: [PATCH 5/5] drm/i915: Add support for getting size of the stolen region

Quoted 62 lines · Ankitprasad Sharma
Quoted 61 lines · Chris Wilson
Quoted 46 lines · On Wed, Apr 29, 2015 at 03:01:59PM +0530, [email protected] wrote:

From: Ankitprasad Sharma <[email protected]>

This patch extends the get_aperture_ioctl to add support for getting total size of the stolen region and available size of the stolen region.

testcase: igt/gem_create_stolen

---
 drivers/gpu/drm/i915/i915_drv.h |  6 ++++++
 drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++++++-
 include/uapi/drm/i915_drm.h     |  6 ++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +6 -0
index a568cd1..a40b44f 100644
@@ -3277,4 +3277,10 @@ inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
 	return !obj->userptr.mm;
 }
 
+inline static bool i915_gem_obj_is_stolen_used(struct drm_i915_gem_object *obj)
+{
+	return obj->stolen && (i915_gem_obj_is_pinned(obj)
+			       || obj->madv == I915_MADV_WILLNEED);
+}
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +2 -1
index 3491bd3..ee93508 100644
@@ -150,17 +150,30 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_get_aperture *args = data;
 	struct drm_i915_gem_object *obj;
-	size_t pinned;
+	size_t pinned, pinned_stolen;
 
 	pinned = 0;
+	pinned_stolen = 0;
 	mutex_lock(&dev->struct_mutex);
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
 		if (i915_gem_obj_is_pinned(obj))

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

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +9 -0
 			pinned += i915_gem_obj_ggtt_size(obj);
+
+	/* Calculating available stolen size */
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
+	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);

Ah, here you will want to iterate over the stolen drm_mm range manager to get an accurate count.

Quoted 6 lines
Quoted 2 lines

Could you respin this on top of id:[email protected] ?

I have incorporated the comments suggested by you, as well as I went through Rodrigo's patch and as such there is no dependency between the two patches.

So how do I float this patch? Shall I resend this as a separate patch in the series ([email protected]) rebasing on top of Rodrigo's changes Or as a part of this series only?

I see this patch as primarily improving the get-aperture ioctl, in which case I would like to address the known deficiency in it as well. It can be more than one patche, though the ABI will have an implicit dependency on them all.

I honestly don't mind how you present it, I just want the mappable info through an ioctl as well...
-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