Skip to contentSkip to conversation

Command parser batch buffer copy

PATCH Superseded [email protected] 4 participants 21 messages Dec 8, 2014 – Dec 11, 2014

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover Command parser batch buffer copy

From: "Michael H. Nguyen" <[email protected]>

This is v6 in response to
http://lists.freedesktop.org/archives/intel-gfx/2014-November/056314.html

- Simplified pool_get() code
Use single cache list to manage pool
s/active_list/cache_list
Use single loop instead of an inner & outer

- Squashed debugfs patches into 1/5

Brad Volkin (5):
drm/i915: Implement a framework for batch buffer pools drm/i915: Use batch pools with the command parser drm/i915: Use batch length instead of object size in command parser drm/i915: Mark shadow batch buffers as purgeable drm/i915: Tidy up execbuffer command parsing code

 Documentation/DocBook/drm.tmpl             |   5 ++
 drivers/gpu/drm/i915/Makefile              |   1 +
 drivers/gpu/drm/i915/i915_cmd_parser.c     |  99 +++++++++++++++++----
 drivers/gpu/drm/i915/i915_debugfs.c        |  71 +++++++++++++--
 drivers/gpu/drm/i915/i915_dma.c            |   1 +
 drivers/gpu/drm/i915/i915_drv.h            |  23 +++++
 drivers/gpu/drm/i915/i915_gem.c            |   3 +
 drivers/gpu/drm/i915/i915_gem_batch_pool.c | 134 +++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  98 +++++++++++++++++----
 9 files changed, 393 insertions(+), 42 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_gem_batch_pool.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 v6 1/5 drm/i915: Implement a framework for batch buffer pools

From: Brad Volkin <[email protected]>

This adds a small module for managing a pool of batch buffers. The only current use case is for the command parser, as described in the kerneldoc in the patch. The code is simple, but separating it out makes it easier to change the underlying algorithms and to extend to future use cases should they arise.

The interface is simple: init to create an empty pool, fini to clean it up, get to obtain a new buffer. Note that all buffers are expected to be inactive before cleaning up the pool.

Locking is currently based on the caller holding the struct_mutex. We already do that in the places where we will use the batch pool for the command parser.

v2:
- s/BUG_ON/WARN_ON/ for locking assertions
- Remove the cap on pool size
- Switch from alloc/free to init/fini

v3:
- Idiomatic looping structure in _fini
- Correct handling of purged objects
- Don't return a buffer that's too much larger than needed

v4:
- Rebased to latest -nightly

v5:
- Remove _put() function and clean up comments to match

v6:
- Move purged check inside the loop (danvet, from v4 1/7 feedback)

v7:
- Use single list instead of two. (Chris W)
- s/active_list/cache_list
- Squashed in debug patches (Chris W)
drm/i915: Add a batch pool debugfs file

It provides some useful information about the buffers in the global command parser batch pool.

v2: rebase on global pool instead of per-ring pools
v3: rebase

drm/i915: Add batch pool details to i915_gem_objects debugfs

To better account for the potentially large memory consumption of the batch pool.

Issue: VIZ-4719

---
 Documentation/DocBook/drm.tmpl             |   5 ++
 drivers/gpu/drm/i915/Makefile              |   1 +
 drivers/gpu/drm/i915/i915_debugfs.c        |  71 ++++++++++++++--
 drivers/gpu/drm/i915/i915_drv.h            |  21 +++++
 drivers/gpu/drm/i915/i915_gem.c            |   1 +
 drivers/gpu/drm/i915/i915_gem_batch_pool.c | 132 +++++++++++++++++++++++++++++
 6 files changed, 222 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_gem_batch_pool.c
Documentation/DocBook/drm.tmpl +5 -0
index 85287cb..022923a 100644
@@ -4029,6 +4029,11 @@ int num_ioctls;</synopsis>
 !Idrivers/gpu/drm/i915/i915_cmd_parser.c
       </sect2>
       <sect2>
+        <title>Batchbuffer Pools</title>
+!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
+!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
+      </sect2>
+      <sect2>
         <title>Logical Rings, Logical Ring Contexts and Execlists</title>
 !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists
 !Idrivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/Makefile +1 -0
index e4083e4..c8dbb37d 100644
@@ -19,6 +19,7 @@ i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o
 
 # GEM code
 i915-y += i915_cmd_parser.o \
+	  i915_gem_batch_pool.o \
 	  i915_gem_context.o \
 	  i915_gem_render_state.o \
 	  i915_gem_debug.o \
drivers/gpu/drm/i915/i915_debugfs.c +62 -9

101 lines not on this page · raw message

drivers/gpu/drm/i915/i915_drv.h +21 -0
index 11e85cb..f3e27e9 100644
@@ -1129,6 +1129,11 @@ struct intel_l3_parity {
 	int which_slice;
 };
 
+struct i915_gem_batch_pool {
+	struct drm_device *dev;
+	struct list_head cache_list;
+};
+
 struct i915_gem_mm {
 	/** Memory allocator for GTT stolen memory */
 	struct drm_mm stolen;
@@ -1142,6 +1147,13 @@ struct i915_gem_mm {
 	 */
 	struct list_head unbound_list;
 
+	/*
+	 * A pool of objects to use as shadow copies of client batch buffers
+	 * when the command parser is enabled. Prevents the client from
+	 * modifying the batch contents after software parsing.
+	 */
+	struct i915_gem_batch_pool batch_pool;
+
 	/** Usable portion of the GTT for GEM */
 	unsigned long stolen_base; /* limited to low memory (32-bit) */
 
@@ -1872,6 +1884,8 @@ struct drm_i915_gem_object {
 	/** Used in execbuf to temporarily hold a ref */
 	struct list_head obj_exec_link;
 
+	struct list_head batch_pool_list;
+
 	/**
 	 * This is set if the object is on the active lists (has pending
 	 * rendering and so a non-zero seqno), and is not set if it i s on
@@ -2876,6 +2890,13 @@ void i915_destroy_error_state(struct drm_device *dev);
 void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
 const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
 
+/* i915_gem_batch_pool.c */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool);
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool);
+struct drm_i915_gem_object*
+i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool, size_t size);
+
 /* i915_cmd_parser.c */
 int i915_cmd_parser_get_version(void);
 int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
drivers/gpu/drm/i915/i915_gem.c +1 -0
index de241eb..2f14ae1 100644
@@ -4384,6 +4384,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
 	INIT_LIST_HEAD(&obj->ring_list);
 	INIT_LIST_HEAD(&obj->obj_exec_link);
 	INIT_LIST_HEAD(&obj->vma_list);
+	INIT_LIST_HEAD(&obj->batch_pool_list);
 
 	obj->ops = ops;
 
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +132 -0

132 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
#2 lore raw

Re: [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Quoted 392 lines · On Mon, Dec 08, 2014 at 02:33:46PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

This adds a small module for managing a pool of batch buffers. The only current use case is for the command parser, as described in the kerneldoc in the patch. The code is simple, but separating it out makes it easier to change the underlying algorithms and to extend to future use cases should they arise.

The interface is simple: init to create an empty pool, fini to clean it up, get to obtain a new buffer. Note that all buffers are expected to be inactive before cleaning up the pool.

Locking is currently based on the caller holding the struct_mutex. We already do that in the places where we will use the batch pool for the command parser.

v2:
- s/BUG_ON/WARN_ON/ for locking assertions
- Remove the cap on pool size
- Switch from alloc/free to init/fini

v3:
- Idiomatic looping structure in _fini
- Correct handling of purged objects
- Don't return a buffer that's too much larger than needed

v4:
- Rebased to latest -nightly

v5:
- Remove _put() function and clean up comments to match

v6:
- Move purged check inside the loop (danvet, from v4 1/7 feedback)

v7:
- Use single list instead of two. (Chris W)
- s/active_list/cache_list
- Squashed in debug patches (Chris W)
drm/i915: Add a batch pool debugfs file

It provides some useful information about the buffers in the global command parser batch pool.

v2: rebase on global pool instead of per-ring pools
v3: rebase

drm/i915: Add batch pool details to i915_gem_objects debugfs

To better account for the potentially large memory consumption of the batch pool.

Issue: VIZ-4719

---
 Documentation/DocBook/drm.tmpl             |   5 ++
 drivers/gpu/drm/i915/Makefile              |   1 +
 drivers/gpu/drm/i915/i915_debugfs.c        |  71 ++++++++++++++--
 drivers/gpu/drm/i915/i915_drv.h            |  21 +++++
 drivers/gpu/drm/i915/i915_gem.c            |   1 +
 drivers/gpu/drm/i915/i915_gem_batch_pool.c | 132 +++++++++++++++++++++++++++++
 6 files changed, 222 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_gem_batch_pool.c
Documentation/DocBook/drm.tmpl +5 -0
index 85287cb..022923a 100644
@@ -4029,6 +4029,11 @@ int num_ioctls;</synopsis>
 !Idrivers/gpu/drm/i915/i915_cmd_parser.c
       </sect2>
       <sect2>
+        <title>Batchbuffer Pools</title>
+!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
+!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
+      </sect2>
+      <sect2>
         <title>Logical Rings, Logical Ring Contexts and Execlists</title>
 !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists
 !Idrivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/Makefile +1 -0
index e4083e4..c8dbb37d 100644
@@ -19,6 +19,7 @@ i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o
 
 # GEM code
 i915-y += i915_cmd_parser.o \
+	  i915_gem_batch_pool.o \
 	  i915_gem_context.o \
 	  i915_gem_render_state.o \
 	  i915_gem_debug.o \
drivers/gpu/drm/i915/i915_debugfs.c +62 -9
index d0e445e..3c3bf98 100644
@@ -359,6 +359,33 @@ static int per_file_stats(int id, void *ptr, void *data)
 	return 0;
 }
 
+#define print_file_stats(m, name, stats) \
+	seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
+		   name, \
+		   stats.count, \
+		   stats.total, \
+		   stats.active, \
+		   stats.inactive, \
+		   stats.global, \
+		   stats.shared, \
+		   stats.unbound)
+
+static void print_batch_pool_stats(struct seq_file *m,
+				   struct drm_i915_private *dev_priv)
+{
+	struct drm_i915_gem_object *obj;
+	struct file_stats stats;
+
+	memset(&stats, 0, sizeof(stats));
+
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list)
+		per_file_stats(0, obj, &stats);
+
+	print_file_stats(m, "batch pool", stats);
+}
+
 #define count_vmas(list, member) do { \
 	list_for_each_entry(vma, list, member) { \
 		size += i915_gem_obj_ggtt_size(vma->obj); \
@@ -441,6 +468,9 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 		   dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
 
 	seq_putc(m, '\n');
+	print_batch_pool_stats(m, dev_priv);
+
+	seq_putc(m, '\n');
 	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
 		struct file_stats stats;
 		struct task_struct *task;
@@ -458,15 +488,7 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 		 */
 		rcu_read_lock();
 		task = pid_task(file->pid, PIDTYPE_PID);
-		seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n",
-			   task ? task->comm : "<unknown>",
-			   stats.count,
-			   stats.total,
-			   stats.active,
-			   stats.inactive,
-			   stats.global,
-			   stats.shared,
-			   stats.unbound);
+		print_file_stats(m, task ? task->comm : "<unknown>", stats);
 		rcu_read_unlock();
 	}
 
@@ -583,6 +605,36 @@ static int i915_gem_pageflip_info(struct seq_file *m, void *data)
 	return 0;
 }
 
+static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj;
+	int count = 0;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_puts(m, "cache:\n");
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list) {
+		seq_puts(m, "   ");
+		describe_obj(m, obj);
+		seq_putc(m, '\n');
+		count++;
+	}
+
+	seq_printf(m, "total: %d\n", count);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
 static int i915_gem_request_info(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = m->private;
@@ -4324,6 +4376,7 @@ static const struct drm_info_list i915_debugfs_list[] = {
 	{"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
 	{"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
 	{"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
+	{"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
 	{"i915_frequency_info", i915_frequency_info, 0},
 	{"i915_drpc_info", i915_drpc_info, 0},
 	{"i915_emon_status", i915_emon_status, 0},
drivers/gpu/drm/i915/i915_drv.h +21 -0
index 11e85cb..f3e27e9 100644
@@ -1129,6 +1129,11 @@ struct intel_l3_parity {
 	int which_slice;
 };
 
+struct i915_gem_batch_pool {
+	struct drm_device *dev;
+	struct list_head cache_list;
+};
+
 struct i915_gem_mm {
 	/** Memory allocator for GTT stolen memory */
 	struct drm_mm stolen;
@@ -1142,6 +1147,13 @@ struct i915_gem_mm {
 	 */
 	struct list_head unbound_list;
 
+	/*
+	 * A pool of objects to use as shadow copies of client batch buffers
+	 * when the command parser is enabled. Prevents the client from
+	 * modifying the batch contents after software parsing.
+	 */
+	struct i915_gem_batch_pool batch_pool;
+
 	/** Usable portion of the GTT for GEM */
 	unsigned long stolen_base; /* limited to low memory (32-bit) */
 
@@ -1872,6 +1884,8 @@ struct drm_i915_gem_object {
 	/** Used in execbuf to temporarily hold a ref */
 	struct list_head obj_exec_link;
 
+	struct list_head batch_pool_list;
+
 	/**
 	 * This is set if the object is on the active lists (has pending
 	 * rendering and so a non-zero seqno), and is not set if it i s on
@@ -2876,6 +2890,13 @@ void i915_destroy_error_state(struct drm_device *dev);
 void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
 const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
 
+/* i915_gem_batch_pool.c */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool);
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool);
+struct drm_i915_gem_object*
+i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool, size_t size);
+
 /* i915_cmd_parser.c */
 int i915_cmd_parser_get_version(void);
 int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
drivers/gpu/drm/i915/i915_gem.c +1 -0
index de241eb..2f14ae1 100644
@@ -4384,6 +4384,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
 	INIT_LIST_HEAD(&obj->ring_list);
 	INIT_LIST_HEAD(&obj->obj_exec_link);
 	INIT_LIST_HEAD(&obj->vma_list);
+	INIT_LIST_HEAD(&obj->batch_pool_list);
 
 	obj->ops = ops;
 
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +119 -0
new file mode 100644
index 0000000..e9349e3
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "i915_drv.h"
+
+/**
+ * DOC: batch pool
+ *
+ * In order to submit batch buffers as 'secure', the software command parser
+ * must ensure that a batch buffer cannot be modified after parsing. It does
+ * this by copying the user provided batch buffer contents to a kernel owned
+ * buffer from which the hardware will actually execute, and by carefully
+ * managing the address space bindings for such buffers.
+ *
+ * The batch pool framework provides a mechanism for the driver to manage a
+ * set of scratch buffers to use for this purpose. The framework can be
+ * extended to support other uses cases should they arise.
+ */
+
+/**
+ * i915_gem_batch_pool_init() - initialize a batch buffer pool
+ * @dev: the drm device
+ * @pool: the batch buffer pool
+ */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool)
+{
+	pool->dev = dev;
+	INIT_LIST_HEAD(&pool->cache_list);
+}
+
+/**
+ * i915_gem_batch_pool_fini() - clean up a batch buffer pool
+ * @pool: the pool to clean up
+ *
+ * Note: Callers must hold the struct_mutex.
+ */
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool)
+{
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	while (!list_empty(&pool->cache_list)) {
+		struct drm_i915_gem_object *obj =
+			list_first_entry(&pool->cache_list,
+					 struct drm_i915_gem_object,
+					 batch_pool_list);
+
+		WARN_ON(obj->active);
+
+		list_del_init(&obj->batch_pool_list);
+		drm_gem_object_unreference(&obj->base);
+	}
+}
+
+/**
+ * i915_gem_batch_pool_get() - select a buffer from the pool
+ * @pool: the batch buffer pool
+ * @size: the minimum desired size of the returned buffer
+ *
+ * Finds or allocates a batch buffer in the pool with at least the requested
+ * size. The caller is responsible for any domain, active/inactive, or
+ * purgeability management for the returned buffer.
+ *
+ * Note: Callers must hold the struct_mutex
+ *
+ * Return: the selected batch buffer object
+ */
+struct drm_i915_gem_object *
+i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
+			size_t size)
+{
+	struct drm_i915_gem_object *obj = NULL;
+	struct drm_i915_gem_object *tmp, *next;
+
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	list_for_each_entry_safe(tmp, next,
+			&pool->cache_list, batch_pool_list) {
+
+		if (tmp->active)
+			continue;
+
+		/* While we're looping, do some clean up */
+		if (tmp->madv == __I915_MADV_PURGED) {
+			list_del(&tmp->batch_pool_list);
+			drm_gem_object_unreference(&tmp->base);
+			continue;
+		}
+
+		/*
+		 * Select a buffer that is at least as big as needed
+		 * but not 'too much' bigger. A better way to do this
+		 * might be to bucket the pool objects based on size.
+		 */
+		if (tmp->base.size >= size &&
+		    tmp->base.size <= (2 * size)) {
+			obj = tmp;
+			break;

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 129

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+		}
+	}
+
+	if (!obj) {
+		obj = i915_gem_alloc_object(pool->dev, size);
+		if (!obj)
+			return ERR_PTR(-ENOMEM);
+
+		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
+	}

Shouldn't we have a else list_move_tail here to keep the list in lru order?
-Daniel

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +3 -0
+
+	return obj;
+}
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

Re: [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Quoted 398 lines · Daniel Vetter
Quoted 397 lines · On Mon, Dec 08, 2014 at 02:33:46PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

This adds a small module for managing a pool of batch buffers. The only current use case is for the command parser, as described in the kerneldoc in the patch. The code is simple, but separating it out makes it easier to change the underlying algorithms and to extend to future use cases should they arise.

The interface is simple: init to create an empty pool, fini to clean it up, get to obtain a new buffer. Note that all buffers are expected to be inactive before cleaning up the pool.

Locking is currently based on the caller holding the struct_mutex. We already do that in the places where we will use the batch pool for the command parser.

v2:
- s/BUG_ON/WARN_ON/ for locking assertions
- Remove the cap on pool size
- Switch from alloc/free to init/fini

v3:
- Idiomatic looping structure in _fini
- Correct handling of purged objects
- Don't return a buffer that's too much larger than needed

v4:
- Rebased to latest -nightly

v5:
- Remove _put() function and clean up comments to match

v6:
- Move purged check inside the loop (danvet, from v4 1/7 feedback)

v7:
- Use single list instead of two. (Chris W)
- s/active_list/cache_list
- Squashed in debug patches (Chris W)
drm/i915: Add a batch pool debugfs file

It provides some useful information about the buffers in the global command parser batch pool.

v2: rebase on global pool instead of per-ring pools
v3: rebase

drm/i915: Add batch pool details to i915_gem_objects debugfs

To better account for the potentially large memory consumption of the batch pool.

Issue: VIZ-4719

---
  Documentation/DocBook/drm.tmpl             |   5 ++
  drivers/gpu/drm/i915/Makefile              |   1 +
  drivers/gpu/drm/i915/i915_debugfs.c        |  71 ++++++++++++++--
  drivers/gpu/drm/i915/i915_drv.h            |  21 +++++
  drivers/gpu/drm/i915/i915_gem.c            |   1 +
  drivers/gpu/drm/i915/i915_gem_batch_pool.c | 132 +++++++++++++++++++++++++++++
  6 files changed, 222 insertions(+), 9 deletions(-)

create mode 100644 drivers/gpu/drm/i915/i915_gem_batch_pool.c

Documentation/DocBook/drm.tmpl +5 -0
index 85287cb..022923a 100644
@@ -4029,6 +4029,11 @@ int num_ioctls;</synopsis>
  !Idrivers/gpu/drm/i915/i915_cmd_parser.c
        </sect2>
        <sect2>
+        <title>Batchbuffer Pools</title>
+!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
+!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
+      </sect2>
+      <sect2>
          <title>Logical Rings, Logical Ring Contexts and Execlists</title>
  !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists
  !Idrivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/Makefile +1 -0
index e4083e4..c8dbb37d 100644
@@ -19,6 +19,7 @@ i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o
 
  # GEM code
  i915-y += i915_cmd_parser.o \
+	  i915_gem_batch_pool.o \
  	  i915_gem_context.o \
  	  i915_gem_render_state.o \
  	  i915_gem_debug.o \
drivers/gpu/drm/i915/i915_debugfs.c +62 -9
index d0e445e..3c3bf98 100644
@@ -359,6 +359,33 @@ static int per_file_stats(int id, void *ptr, void *data)
  	return 0;
  }
 
+#define print_file_stats(m, name, stats) \
+	seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
+		   name, \
+		   stats.count, \
+		   stats.total, \
+		   stats.active, \
+		   stats.inactive, \
+		   stats.global, \
+		   stats.shared, \
+		   stats.unbound)
+
+static void print_batch_pool_stats(struct seq_file *m,
+				   struct drm_i915_private *dev_priv)
+{
+	struct drm_i915_gem_object *obj;
+	struct file_stats stats;
+
+	memset(&stats, 0, sizeof(stats));
+
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list)
+		per_file_stats(0, obj, &stats);
+
+	print_file_stats(m, "batch pool", stats);
+}
+
  #define count_vmas(list, member) do { \
  	list_for_each_entry(vma, list, member) { \
  		size += i915_gem_obj_ggtt_size(vma->obj); \
@@ -441,6 +468,9 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
  		   dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
 
  	seq_putc(m, '\n');
+	print_batch_pool_stats(m, dev_priv);
+
+	seq_putc(m, '\n');
  	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  		struct file_stats stats;
  		struct task_struct *task;
@@ -458,15 +488,7 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
  		 */
  		rcu_read_lock();
  		task = pid_task(file->pid, PIDTYPE_PID);
-		seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n",
-			   task ? task->comm : "<unknown>",
-			   stats.count,
-			   stats.total,
-			   stats.active,
-			   stats.inactive,
-			   stats.global,
-			   stats.shared,
-			   stats.unbound);
+		print_file_stats(m, task ? task->comm : "<unknown>", stats);
  		rcu_read_unlock();
  	}
 
@@ -583,6 +605,36 @@ static int i915_gem_pageflip_info(struct seq_file *m, void *data)
  	return 0;
  }
 
+static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj;
+	int count = 0;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_puts(m, "cache:\n");
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list) {
+		seq_puts(m, "   ");
+		describe_obj(m, obj);
+		seq_putc(m, '\n');
+		count++;
+	}
+
+	seq_printf(m, "total: %d\n", count);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
  static int i915_gem_request_info(struct seq_file *m, void *data)
  {
  	struct drm_info_node *node = m->private;
@@ -4324,6 +4376,7 @@ static const struct drm_info_list i915_debugfs_list[] = {
  	{"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
  	{"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
  	{"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
+	{"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
  	{"i915_frequency_info", i915_frequency_info, 0},
  	{"i915_drpc_info", i915_drpc_info, 0},
  	{"i915_emon_status", i915_emon_status, 0},
drivers/gpu/drm/i915/i915_drv.h +21 -0
index 11e85cb..f3e27e9 100644
@@ -1129,6 +1129,11 @@ struct intel_l3_parity {
  	int which_slice;
  };
 
+struct i915_gem_batch_pool {
+	struct drm_device *dev;
+	struct list_head cache_list;
+};
+
  struct i915_gem_mm {
  	/** Memory allocator for GTT stolen memory */
  	struct drm_mm stolen;
@@ -1142,6 +1147,13 @@ struct i915_gem_mm {
  	 */
  	struct list_head unbound_list;
 
+	/*
+	 * A pool of objects to use as shadow copies of client batch buffers
+	 * when the command parser is enabled. Prevents the client from
+	 * modifying the batch contents after software parsing.
+	 */
+	struct i915_gem_batch_pool batch_pool;
+
  	/** Usable portion of the GTT for GEM */
  	unsigned long stolen_base; /* limited to low memory (32-bit) */
 
@@ -1872,6 +1884,8 @@ struct drm_i915_gem_object {
  	/** Used in execbuf to temporarily hold a ref */
  	struct list_head obj_exec_link;
 
+	struct list_head batch_pool_list;
+
  	/**
  	 * This is set if the object is on the active lists (has pending
  	 * rendering and so a non-zero seqno), and is not set if it i s on
@@ -2876,6 +2890,13 @@ void i915_destroy_error_state(struct drm_device *dev);
  void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
  const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
 
+/* i915_gem_batch_pool.c */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool);
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool);
+struct drm_i915_gem_object*
+i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool, size_t size);
+
  /* i915_cmd_parser.c */
  int i915_cmd_parser_get_version(void);
  int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
drivers/gpu/drm/i915/i915_gem.c +1 -0
index de241eb..2f14ae1 100644
@@ -4384,6 +4384,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
  	INIT_LIST_HEAD(&obj->ring_list);
  	INIT_LIST_HEAD(&obj->obj_exec_link);
  	INIT_LIST_HEAD(&obj->vma_list);
+	INIT_LIST_HEAD(&obj->batch_pool_list);
 
  	obj->ops = ops;
 
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +124 -0
new file mode 100644
index 0000000..e9349e3
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "i915_drv.h"
+
+/**
+ * DOC: batch pool
+ *
+ * In order to submit batch buffers as 'secure', the software command parser
+ * must ensure that a batch buffer cannot be modified after parsing. It does
+ * this by copying the user provided batch buffer contents to a kernel owned
+ * buffer from which the hardware will actually execute, and by carefully
+ * managing the address space bindings for such buffers.
+ *
+ * The batch pool framework provides a mechanism for the driver to manage a
+ * set of scratch buffers to use for this purpose. The framework can be
+ * extended to support other uses cases should they arise.
+ */
+
+/**
+ * i915_gem_batch_pool_init() - initialize a batch buffer pool
+ * @dev: the drm device
+ * @pool: the batch buffer pool
+ */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool)
+{
+	pool->dev = dev;
+	INIT_LIST_HEAD(&pool->cache_list);
+}
+
+/**
+ * i915_gem_batch_pool_fini() - clean up a batch buffer pool
+ * @pool: the pool to clean up
+ *
+ * Note: Callers must hold the struct_mutex.
+ */
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool)
+{
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	while (!list_empty(&pool->cache_list)) {
+		struct drm_i915_gem_object *obj =
+			list_first_entry(&pool->cache_list,
+					 struct drm_i915_gem_object,
+					 batch_pool_list);
+
+		WARN_ON(obj->active);
+
+		list_del_init(&obj->batch_pool_list);
+		drm_gem_object_unreference(&obj->base);
+	}
+}
+
+/**
+ * i915_gem_batch_pool_get() - select a buffer from the pool
+ * @pool: the batch buffer pool
+ * @size: the minimum desired size of the returned buffer
+ *
+ * Finds or allocates a batch buffer in the pool with at least the requested
+ * size. The caller is responsible for any domain, active/inactive, or
+ * purgeability management for the returned buffer.
+ *
+ * Note: Callers must hold the struct_mutex
+ *
+ * Return: the selected batch buffer object
+ */
+struct drm_i915_gem_object *
+i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
+			size_t size)
+{
+	struct drm_i915_gem_object *obj = NULL;
+	struct drm_i915_gem_object *tmp, *next;
+
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	list_for_each_entry_safe(tmp, next,
+			&pool->cache_list, batch_pool_list) {
+
+		if (tmp->active)
+			continue;
+
+		/* While we're looping, do some clean up */
+		if (tmp->madv == __I915_MADV_PURGED) {
+			list_del(&tmp->batch_pool_list);
+			drm_gem_object_unreference(&tmp->base);
+			continue;
+		}
+
+		/*
+		 * Select a buffer that is at least as big as needed
+		 * but not 'too much' bigger. A better way to do this
+		 * might be to bucket the pool objects based on size.
+		 */
+		if (tmp->base.size >= size &&
+		    tmp->base.size <= (2 * size)) {
+			obj = tmp;
+			break;
+		}
+	}
+
+	if (!obj) {
+		obj = i915_gem_alloc_object(pool->dev, size);
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 129

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +5 -0
+		if (!obj)
+			return ERR_PTR(-ENOMEM);
+
+		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
+	}

Shouldn't we have a else list_move_tail here to keep the list in lru order?

Yes!

Quoted 8 lines

-Daniel

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +3 -1
+
+	return obj;
+}
--

1.9.1

Quoted 5 lines
Quoted 4 lines

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

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

#4 lore raw

Re: [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

In reply to Daniel Vetter
Quoted 118 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, December 09, 2014 1:18 PM
To: Nguyen, Michael H
Cc: Brad Volkin; [email protected]
Subject: Re: [Intel-gfx] [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void

Quoted 100 lines · On Mon, Dec 08, 2014 at 02:33:46PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

This adds a small module for managing a pool of batch buffers. The only current use case is for the command parser, as described in the kerneldoc in the patch. The code is simple, but separating it out makes it easier to change the underlying algorithms and to extend to future use cases should they arise.

The interface is simple: init to create an empty pool, fini to clean it up, get to obtain a new buffer. Note that all buffers are expected to be inactive before cleaning up the pool.

Locking is currently based on the caller holding the struct_mutex. We already do that in the places where we will use the batch pool for the command parser.

v2:
- s/BUG_ON/WARN_ON/ for locking assertions
- Remove the cap on pool size
- Switch from alloc/free to init/fini

v3:
- Idiomatic looping structure in _fini
- Correct handling of purged objects
- Don't return a buffer that's too much larger than needed

v4:
- Rebased to latest -nightly

v5:
- Remove _put() function and clean up comments to match

v6:
- Move purged check inside the loop (danvet, from v4 1/7 feedback)

v7:
- Use single list instead of two. (Chris W)
- s/active_list/cache_list
- Squashed in debug patches (Chris W)
drm/i915: Add a batch pool debugfs file

It provides some useful information about the buffers in the global command parser batch pool.

v2: rebase on global pool instead of per-ring pools
v3: rebase

drm/i915: Add batch pool details to i915_gem_objects debugfs

To better account for the potentially large memory consumption of the batch pool.

Issue: VIZ-4719

---
 Documentation/DocBook/drm.tmpl             |   5 ++
 drivers/gpu/drm/i915/Makefile              |   1 +
 drivers/gpu/drm/i915/i915_debugfs.c        |  71 ++++++++++++++--
 drivers/gpu/drm/i915/i915_drv.h            |  21 +++++
 drivers/gpu/drm/i915/i915_gem.c            |   1 +
 drivers/gpu/drm/i915/i915_gem_batch_pool.c | 132
+++++++++++++++++++++++++++++
 6 files changed, 222 insertions(+), 9 deletions(-)  create mode

100644 drivers/gpu/drm/i915/i915_gem_batch_pool.c

(quoted diff) +0 -0

b/Documentation/DocBook/drm.tmpl index 85287cb..022923a 100644

Documentation/DocBook/drm.tmpl +0 -0
@@ -4029,6 +4029,11 @@ int num_ioctls;</synopsis>

!Idrivers/gpu/drm/i915/i915_cmd_parser.c

       </sect2>
       <sect2>
Documentation/DocBook/drm.tmpl +5 -0
+        <title>Batchbuffer Pools</title>
+!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
+!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
+      </sect2>
+      <sect2>
         <title>Logical Rings, Logical Ring Contexts and

Execlists</title> !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists !Idrivers/gpu/drm/i915/intel_lrc.c

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile index e4083e4..c8dbb37d 100644

drivers/gpu/drm/i915/Makefile +1 -0
@@ -19,6 +19,7 @@ i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o
 
 # GEM code
 i915-y += i915_cmd_parser.o \
+	  i915_gem_batch_pool.o \
 	  i915_gem_context.o \
 	  i915_gem_render_state.o \
 	  i915_gem_debug.o \
drivers/gpu/drm/i915/i915_debugfs.c +0 -0
index d0e445e..3c3bf98 100644
@@ -359,6 +359,33 @@ static int per_file_stats(int id, void *ptr, void

*data)

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data)

Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c +2 -0
 	return 0;
 }
 
+#define print_file_stats(m, name, stats) \
+	seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive,

%zu global, %zu shared, %zu unbound)\n", \

Quoted 8 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 371

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +8 -0
+		   name, \
+		   stats.count, \
+		   stats.total, \
+		   stats.active, \
+		   stats.inactive, \
+		   stats.global, \
+		   stats.shared, \
+		   stats.unbound)

"print_file_stats" might be better named "print_obj_stats" or similar. As it stands there is nothing in its name to suggest its purpose is to describe an object.

Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +4 -0
+
+static void print_batch_pool_stats(struct seq_file *m,
+				   struct drm_i915_private *dev_priv) {
+	struct drm_i915_gem_object *obj;
Quoted 8 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 384

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +8 -0
+	struct file_stats stats;
+
+	memset(&stats, 0, sizeof(stats));
+
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list)
+		per_file_stats(0, obj, &stats);

Shouldn't we be holding the batch_pool lock here ?

Quoted 317 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data)

Quoted 6 lines
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
+
+	print_file_stats(m, "batch pool", stats); }
+
 #define count_vmas(list, member) do { \
 	list_for_each_entry(vma, list, member) { \
 		size += i915_gem_obj_ggtt_size(vma->obj); \ @@ -441,6

+468,9 @@

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_object_info(struct seq_file *m,

Quoted 11 lines

static int i915_gem_object_info(struct seq_file *m, void* data)

drivers/gpu/drm/i915/i915_debugfs.c +3 -0
 		   dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
 
 	seq_putc(m, '\n');
+	print_batch_pool_stats(m, dev_priv);
+
+	seq_putc(m, '\n');
 	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
 		struct file_stats stats;
 		struct task_struct *task;
@@ -458,15 +488,7 @@ static int i915_gem_object_info(struct seq_file *m,

void* data)

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_object_info(struct seq_file *m, void* data)

Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +0 -1
 		 */
 		rcu_read_lock();
 		task = pid_task(file->pid, PIDTYPE_PID);
-		seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu

inactive, %zu global, %zu shared, %zu unbound)\n",

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_pageflip_info(struct seq_file

Quoted 13 lines
drivers/gpu/drm/i915/i915_debugfs.c +1 -8
-			   task ? task->comm : "<unknown>",
-			   stats.count,
-			   stats.total,
-			   stats.active,
-			   stats.inactive,
-			   stats.global,
-			   stats.shared,
-			   stats.unbound);
+		print_file_stats(m, task ? task->comm : "<unknown>", stats);
 		rcu_read_unlock();
 	}
 
@@ -583,6 +605,36 @@ static int i915_gem_pageflip_info(struct seq_file

*m, void *data)

drivers/gpu/drm/i915/i915_drv.h void i915_destroy_error_state(struct

Quoted 82 lines
drivers/gpu/drm/i915/i915_debugfs.c +30 -0
 	return 0;
 }
 
+static int i915_gem_batch_pool_info(struct seq_file *m, void *data) {
+	struct drm_info_node *node = m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj;
+	int count = 0;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_puts(m, "cache:\n");
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list) {
+		seq_puts(m, "   ");
+		describe_obj(m, obj);
+		seq_putc(m, '\n');
+		count++;
+	}
+
+	seq_printf(m, "total: %d\n", count);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
 static int i915_gem_request_info(struct seq_file *m, void *data)  {
 	struct drm_info_node *node = m->private; @@ -4324,6 +4376,7 @@
 static const struct drm_info_list i915_debugfs_list[] = {
 	{"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
 	{"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
 	{"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
+	{"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
 	{"i915_frequency_info", i915_frequency_info, 0},
 	{"i915_drpc_info", i915_drpc_info, 0},
 	{"i915_emon_status", i915_emon_status, 0}, diff --git

a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 11e85cb..f3e27e9 100644

drivers/gpu/drm/i915/i915_drv.h +14 -0
@@ -1129,6 +1129,11 @@ struct intel_l3_parity {
 	int which_slice;
 };
 
+struct i915_gem_batch_pool {
+	struct drm_device *dev;
+	struct list_head cache_list;
+};
+
 struct i915_gem_mm {
 	/** Memory allocator for GTT stolen memory */
 	struct drm_mm stolen;
@@ -1142,6 +1147,13 @@ struct i915_gem_mm {
 	 */
 	struct list_head unbound_list;
 
+	/*
+	 * A pool of objects to use as shadow copies of client batch buffers
+	 * when the command parser is enabled. Prevents the client from
+	 * modifying the batch contents after software parsing.
+	 */
+	struct i915_gem_batch_pool batch_pool;
+
 	/** Usable portion of the GTT for GEM */
 	unsigned long stolen_base; /* limited to low memory (32-bit) */
 
@@ -1872,6 +1884,8 @@ struct drm_i915_gem_object {
 	/** Used in execbuf to temporarily hold a ref */
 	struct list_head obj_exec_link;
 
+	struct list_head batch_pool_list;
+
 	/**
 	 * This is set if the object is on the active lists (has pending
 	 * rendering and so a non-zero seqno), and is not set if it i s on
@@ -2876,6 +2890,13 @@ void i915_destroy_error_state(struct

drm_device

drivers/gpu/drm/i915/i915_gem.c void i915_gem_object_init(struct

Quoted 19 lines
drivers/gpu/drm/i915/i915_drv.h +7 -0
 *dev);  void i915_get_extra_instdone(struct drm_device *dev, uint32_t
 *instdone);  const char *i915_cache_level_str(struct drm_i915_private
 *i915, int type);
 
+/* i915_gem_batch_pool.c */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool); void
+i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool); struct
+drm_i915_gem_object* i915_gem_batch_pool_get(struct
+i915_gem_batch_pool *pool, size_t size);
+
 /* i915_cmd_parser.c */
 int i915_cmd_parser_get_version(void);

int i915_cmd_parser_init_ring(struct intel_engine_cs *ring); diff
--git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index de241eb..2f14ae1 100644

drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -4384,6 +4384,7 @@ void i915_gem_object_init(struct

drm_i915_gem_object *obj,

Quoted 26 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
 	INIT_LIST_HEAD(&obj->ring_list);
 	INIT_LIST_HEAD(&obj->obj_exec_link);
 	INIT_LIST_HEAD(&obj->vma_list);
+	INIT_LIST_HEAD(&obj->batch_pool_list);
 
 	obj->ops = ops;
 
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +12 -0
new file mode 100644
index 0000000..e9349e3
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
+"Software"),
+ * to deal in the Software without restriction, including without
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 22

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including
+the next
+ * paragraph) shall be included in all copies or substantial portions
+of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY

KIND,

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 26

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +4 -0
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN

NO EVENT

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 28

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,

DAMAGES

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 30

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 32

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 105 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +105 -0
+OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "i915_drv.h"
+
+/**
+ * DOC: batch pool
+ *
+ * In order to submit batch buffers as 'secure', the software command
+parser
+ * must ensure that a batch buffer cannot be modified after parsing.
+It does
+ * this by copying the user provided batch buffer contents to a
+kernel owned
+ * buffer from which the hardware will actually execute, and by
+carefully
+ * managing the address space bindings for such buffers.
+ *
+ * The batch pool framework provides a mechanism for the driver to
+manage a
+ * set of scratch buffers to use for this purpose. The framework can
+be
+ * extended to support other uses cases should they arise.
+ */
+
+/**
+ * i915_gem_batch_pool_init() - initialize a batch buffer pool
+ * @dev: the drm device
+ * @pool: the batch buffer pool
+ */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool) {
+	pool->dev = dev;
+	INIT_LIST_HEAD(&pool->cache_list);
+}
+
+/**
+ * i915_gem_batch_pool_fini() - clean up a batch buffer pool
+ * @pool: the pool to clean up
+ *
+ * Note: Callers must hold the struct_mutex.
+ */
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool) {
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	while (!list_empty(&pool->cache_list)) {
+		struct drm_i915_gem_object *obj =
+			list_first_entry(&pool->cache_list,
+					 struct drm_i915_gem_object,
+					 batch_pool_list);
+
+		WARN_ON(obj->active);
+
+		list_del_init(&obj->batch_pool_list);
+		drm_gem_object_unreference(&obj->base);
+	}
+}
+
+/**
+ * i915_gem_batch_pool_get() - select a buffer from the pool
+ * @pool: the batch buffer pool
+ * @size: the minimum desired size of the returned buffer
+ *
+ * Finds or allocates a batch buffer in the pool with at least the
+requested
+ * size. The caller is responsible for any domain, active/inactive,
+or
+ * purgeability management for the returned buffer.
+ *
+ * Note: Callers must hold the struct_mutex
+ *
+ * Return: the selected batch buffer object  */ struct
+drm_i915_gem_object * i915_gem_batch_pool_get(struct
+i915_gem_batch_pool *pool,
+			size_t size)
+{
+	struct drm_i915_gem_object *obj = NULL;
+	struct drm_i915_gem_object *tmp, *next;
+
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	list_for_each_entry_safe(tmp, next,
+			&pool->cache_list, batch_pool_list) {
+
+		if (tmp->active)
+			continue;
+
+		/* While we're looping, do some clean up */
+		if (tmp->madv == __I915_MADV_PURGED) {
+			list_del(&tmp->batch_pool_list);
+			drm_gem_object_unreference(&tmp->base);
+			continue;
+		}
+
+		/*
+		 * Select a buffer that is at least as big as needed
+		 * but not 'too much' bigger. A better way to do this
+		 * might be to bucket the pool objects based on size.
+		 */
+		if (tmp->base.size >= size &&
+		    tmp->base.size <= (2 * size)) {
+			obj = tmp;
+			break;

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 129

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+		}
+	}
+
+	if (!obj) {
+		obj = i915_gem_alloc_object(pool->dev, size);
+		if (!obj)
+			return ERR_PTR(-ENOMEM);
+
+		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
+	}

Shouldn't we have a else list_move_tail here to keep the list in lru order? -Daniel

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +3 -1
+
+	return obj;
+}
--

1.9.1

Quoted 13 lines
Quoted 4 lines

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

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

#5 lore raw

Re: [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Hi Jon,

Quoted 118 lines · Jon
Quoted 118 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, December 09, 2014 1:18 PM
To: Nguyen, Michael H
Cc: Brad Volkin; [email protected]
Subject: Re: [Intel-gfx] [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void

Quoted 100 lines · On Mon, Dec 08, 2014 at 02:33:46PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

This adds a small module for managing a pool of batch buffers. The only current use case is for the command parser, as described in the kerneldoc in the patch. The code is simple, but separating it out makes it easier to change the underlying algorithms and to extend to future use cases should they arise.

The interface is simple: init to create an empty pool, fini to clean it up, get to obtain a new buffer. Note that all buffers are expected to be inactive before cleaning up the pool.

Locking is currently based on the caller holding the struct_mutex. We already do that in the places where we will use the batch pool for the command parser.

v2:
- s/BUG_ON/WARN_ON/ for locking assertions
- Remove the cap on pool size
- Switch from alloc/free to init/fini

v3:
- Idiomatic looping structure in _fini
- Correct handling of purged objects
- Don't return a buffer that's too much larger than needed

v4:
- Rebased to latest -nightly

v5:
- Remove _put() function and clean up comments to match

v6:
- Move purged check inside the loop (danvet, from v4 1/7 feedback)

v7:
- Use single list instead of two. (Chris W)
- s/active_list/cache_list
- Squashed in debug patches (Chris W)
drm/i915: Add a batch pool debugfs file

It provides some useful information about the buffers in the global command parser batch pool.

v2: rebase on global pool instead of per-ring pools
v3: rebase

drm/i915: Add batch pool details to i915_gem_objects debugfs

To better account for the potentially large memory consumption of the batch pool.

Issue: VIZ-4719

---
  Documentation/DocBook/drm.tmpl             |   5 ++
  drivers/gpu/drm/i915/Makefile              |   1 +
  drivers/gpu/drm/i915/i915_debugfs.c        |  71 ++++++++++++++--
  drivers/gpu/drm/i915/i915_drv.h            |  21 +++++
  drivers/gpu/drm/i915/i915_gem.c            |   1 +
  drivers/gpu/drm/i915/i915_gem_batch_pool.c | 132
+++++++++++++++++++++++++++++
  6 files changed, 222 insertions(+), 9 deletions(-)  create mode

100644 drivers/gpu/drm/i915/i915_gem_batch_pool.c

(quoted diff) +0 -0

b/Documentation/DocBook/drm.tmpl index 85287cb..022923a 100644

Documentation/DocBook/drm.tmpl +0 -0
@@ -4029,6 +4029,11 @@ int num_ioctls;</synopsis>

!Idrivers/gpu/drm/i915/i915_cmd_parser.c

        </sect2>
        <sect2>
Documentation/DocBook/drm.tmpl +5 -0
+        <title>Batchbuffer Pools</title>
+!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
+!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
+      </sect2>
+      <sect2>
          <title>Logical Rings, Logical Ring Contexts and

Execlists</title> !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists !Idrivers/gpu/drm/i915/intel_lrc.c

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile index e4083e4..c8dbb37d 100644

drivers/gpu/drm/i915/Makefile +1 -0
@@ -19,6 +19,7 @@ i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o
 
  # GEM code
  i915-y += i915_cmd_parser.o \
+	  i915_gem_batch_pool.o \
  	  i915_gem_context.o \
  	  i915_gem_render_state.o \
  	  i915_gem_debug.o \
drivers/gpu/drm/i915/i915_debugfs.c +0 -0
index d0e445e..3c3bf98 100644
@@ -359,6 +359,33 @@ static int per_file_stats(int id, void *ptr, void

*data)

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data)

Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c +2 -0
  	return 0;
  }
 
+#define print_file_stats(m, name, stats) \
+	seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive,

%zu global, %zu shared, %zu unbound)\n", \

Quoted 11 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 371

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +8 -0
+		   name, \
+		   stats.count, \
+		   stats.total, \
+		   stats.active, \
+		   stats.inactive, \
+		   stats.global, \
+		   stats.shared, \
+		   stats.unbound)

"print_file_stats" might be better named "print_obj_stats" or similar. As it stands there is nothing in its name to suggest its purpose is to describe an object.

I guess the fnc name 'print_file_stats' was chosen b/c it takes a 'stats' parameter of type 'struct file_stats' and prints the members. Seems fair to leave it I think as its generic.

Quoted 16 lines
Quoted 14 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +2 -0
+
+static void print_batch_pool_stats(struct seq_file *m,

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 384

Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +10 -0
+				   struct drm_i915_private *dev_priv) {
+	struct drm_i915_gem_object *obj;
+	struct file_stats stats;
+
+	memset(&stats, 0, sizeof(stats));
+
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list)
+		per_file_stats(0, obj, &stats);

Shouldn't we be holding the batch_pool lock here ?

Think we're okay here. The callers of print_batch_pool_stats() hold dev->struct_mutex.

Thanks,
-Mike

Quoted 319 lines
Quoted 319 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data)

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
+
+	print_file_stats(m, "batch pool", stats); }
+
  #define count_vmas(list, member) do { \
  	list_for_each_entry(vma, list, member) { \
  		size += i915_gem_obj_ggtt_size(vma->obj); \ @@ -441,6

+468,9 @@

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_object_info(struct seq_file *m,

Quoted 11 lines

static int i915_gem_object_info(struct seq_file *m, void* data)
dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);

  	seq_putc(m, '\n');
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
+	print_batch_pool_stats(m, dev_priv);
+
+	seq_putc(m, '\n');
  	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  		struct file_stats stats;
  		struct task_struct *task;
@@ -458,15 +488,7 @@ static int i915_gem_object_info(struct seq_file *m,

void* data)

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_object_info(struct seq_file *m, void* data)

Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +0 -1
  		 */
  		rcu_read_lock();
  		task = pid_task(file->pid, PIDTYPE_PID);
-		seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu

inactive, %zu global, %zu shared, %zu unbound)\n",

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_pageflip_info(struct seq_file

Quoted 13 lines
drivers/gpu/drm/i915/i915_debugfs.c +1 -8
-			   task ? task->comm : "<unknown>",
-			   stats.count,
-			   stats.total,
-			   stats.active,
-			   stats.inactive,
-			   stats.global,
-			   stats.shared,
-			   stats.unbound);
+		print_file_stats(m, task ? task->comm : "<unknown>", stats);
  		rcu_read_unlock();
  	}
 
@@ -583,6 +605,36 @@ static int i915_gem_pageflip_info(struct seq_file

*m, void *data)

drivers/gpu/drm/i915/i915_drv.h void i915_destroy_error_state(struct

Quoted 82 lines
drivers/gpu/drm/i915/i915_debugfs.c +30 -0
  	return 0;
  }
 
+static int i915_gem_batch_pool_info(struct seq_file *m, void *data) {
+	struct drm_info_node *node = m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj;
+	int count = 0;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_puts(m, "cache:\n");
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list) {
+		seq_puts(m, "   ");
+		describe_obj(m, obj);
+		seq_putc(m, '\n');
+		count++;
+	}
+
+	seq_printf(m, "total: %d\n", count);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
  static int i915_gem_request_info(struct seq_file *m, void *data)  {
  	struct drm_info_node *node = m->private; @@ -4324,6 +4376,7 @@
 static const struct drm_info_list i915_debugfs_list[] = {
  	{"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
  	{"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
  	{"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
+	{"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
  	{"i915_frequency_info", i915_frequency_info, 0},
  	{"i915_drpc_info", i915_drpc_info, 0},
  	{"i915_emon_status", i915_emon_status, 0}, diff --git

a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 11e85cb..f3e27e9 100644

drivers/gpu/drm/i915/i915_drv.h +14 -0
@@ -1129,6 +1129,11 @@ struct intel_l3_parity {
  	int which_slice;
  };
 
+struct i915_gem_batch_pool {
+	struct drm_device *dev;
+	struct list_head cache_list;
+};
+
  struct i915_gem_mm {
  	/** Memory allocator for GTT stolen memory */
  	struct drm_mm stolen;
@@ -1142,6 +1147,13 @@ struct i915_gem_mm {
  	 */
  	struct list_head unbound_list;
 
+	/*
+	 * A pool of objects to use as shadow copies of client batch buffers
+	 * when the command parser is enabled. Prevents the client from
+	 * modifying the batch contents after software parsing.
+	 */
+	struct i915_gem_batch_pool batch_pool;
+
  	/** Usable portion of the GTT for GEM */
  	unsigned long stolen_base; /* limited to low memory (32-bit) */
 
@@ -1872,6 +1884,8 @@ struct drm_i915_gem_object {
  	/** Used in execbuf to temporarily hold a ref */
  	struct list_head obj_exec_link;
 
+	struct list_head batch_pool_list;
+
  	/**
  	 * This is set if the object is on the active lists (has pending
  	 * rendering and so a non-zero seqno), and is not set if it i s on
@@ -2876,6 +2890,13 @@ void i915_destroy_error_state(struct

drm_device

drivers/gpu/drm/i915/i915_gem.c void i915_gem_object_init(struct

Quoted 19 lines
drivers/gpu/drm/i915/i915_drv.h +7 -0
 *dev);  void i915_get_extra_instdone(struct drm_device *dev, uint32_t
 *instdone);  const char *i915_cache_level_str(struct drm_i915_private
 *i915, int type);
 
+/* i915_gem_batch_pool.c */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool); void
+i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool); struct
+drm_i915_gem_object* i915_gem_batch_pool_get(struct
+i915_gem_batch_pool *pool, size_t size);
+
  /* i915_cmd_parser.c */
  int i915_cmd_parser_get_version(void);

int i915_cmd_parser_init_ring(struct intel_engine_cs *ring); diff
--git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index de241eb..2f14ae1 100644

drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -4384,6 +4384,7 @@ void i915_gem_object_init(struct

drm_i915_gem_object *obj,

Quoted 26 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
  	INIT_LIST_HEAD(&obj->ring_list);
  	INIT_LIST_HEAD(&obj->obj_exec_link);
  	INIT_LIST_HEAD(&obj->vma_list);
+	INIT_LIST_HEAD(&obj->batch_pool_list);
 
  	obj->ops = ops;
 
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +12 -0
new file mode 100644
index 0000000..e9349e3
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
+"Software"),
+ * to deal in the Software without restriction, including without
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 22

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including
+the next
+ * paragraph) shall be included in all copies or substantial portions
+of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY

KIND,

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 26

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +4 -0
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN

NO EVENT

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 28

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,

DAMAGES

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 30

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 32

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 105 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +105 -0
+OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "i915_drv.h"
+
+/**
+ * DOC: batch pool
+ *
+ * In order to submit batch buffers as 'secure', the software command
+parser
+ * must ensure that a batch buffer cannot be modified after parsing.
+It does
+ * this by copying the user provided batch buffer contents to a
+kernel owned
+ * buffer from which the hardware will actually execute, and by
+carefully
+ * managing the address space bindings for such buffers.
+ *
+ * The batch pool framework provides a mechanism for the driver to
+manage a
+ * set of scratch buffers to use for this purpose. The framework can
+be
+ * extended to support other uses cases should they arise.
+ */
+
+/**
+ * i915_gem_batch_pool_init() - initialize a batch buffer pool
+ * @dev: the drm device
+ * @pool: the batch buffer pool
+ */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool) {
+	pool->dev = dev;
+	INIT_LIST_HEAD(&pool->cache_list);
+}
+
+/**
+ * i915_gem_batch_pool_fini() - clean up a batch buffer pool
+ * @pool: the pool to clean up
+ *
+ * Note: Callers must hold the struct_mutex.
+ */
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool) {
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	while (!list_empty(&pool->cache_list)) {
+		struct drm_i915_gem_object *obj =
+			list_first_entry(&pool->cache_list,
+					 struct drm_i915_gem_object,
+					 batch_pool_list);
+
+		WARN_ON(obj->active);
+
+		list_del_init(&obj->batch_pool_list);
+		drm_gem_object_unreference(&obj->base);
+	}
+}
+
+/**
+ * i915_gem_batch_pool_get() - select a buffer from the pool
+ * @pool: the batch buffer pool
+ * @size: the minimum desired size of the returned buffer
+ *
+ * Finds or allocates a batch buffer in the pool with at least the
+requested
+ * size. The caller is responsible for any domain, active/inactive,
+or
+ * purgeability management for the returned buffer.
+ *
+ * Note: Callers must hold the struct_mutex
+ *
+ * Return: the selected batch buffer object  */ struct
+drm_i915_gem_object * i915_gem_batch_pool_get(struct
+i915_gem_batch_pool *pool,
+			size_t size)
+{
+	struct drm_i915_gem_object *obj = NULL;
+	struct drm_i915_gem_object *tmp, *next;
+
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	list_for_each_entry_safe(tmp, next,
+			&pool->cache_list, batch_pool_list) {
+
+		if (tmp->active)
+			continue;
+
+		/* While we're looping, do some clean up */
+		if (tmp->madv == __I915_MADV_PURGED) {
+			list_del(&tmp->batch_pool_list);
+			drm_gem_object_unreference(&tmp->base);
+			continue;
+		}
+
+		/*
+		 * Select a buffer that is at least as big as needed
+		 * but not 'too much' bigger. A better way to do this
+		 * might be to bucket the pool objects based on size.
+		 */
+		if (tmp->base.size >= size &&
+		    tmp->base.size <= (2 * size)) {
+			obj = tmp;
+			break;

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 129

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+		}
+	}
+
+	if (!obj) {
+		obj = i915_gem_alloc_object(pool->dev, size);
+		if (!obj)
+			return ERR_PTR(-ENOMEM);
+
+		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
+	}

Shouldn't we have a else list_move_tail here to keep the list in lru order? -Daniel

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +3 -1
+
+	return obj;
+}
--

1.9.1

Quoted 13 lines
Quoted 5 lines
Quoted 4 lines

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

Quoted 8 lines

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

#6 lore raw

Re: [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Quoted 142 lines

-----Original Message-----
From: Nguyen, Michael H
Sent: Wednesday, December 10, 2014 4:34 PM
To: Bloomfield, Jon
Cc: Daniel Vetter; [email protected]
Subject: Re: [Intel-gfx] [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Hi Jon,

Quoted 120 lines · Jon
Quoted 120 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, December 09, 2014 1:18 PM
To: Nguyen, Michael H
Cc: Brad Volkin; [email protected]
Subject: Re: [Intel-gfx] [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Quoted 100 lines · On Mon, Dec 08, 2014 at 02:33:46PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

This adds a small module for managing a pool of batch buffers. The only current use case is for the command parser, as described in the kerneldoc in the patch. The code is simple, but separating it out makes it easier to change the underlying algorithms and to extend to future use cases should they arise.

The interface is simple: init to create an empty pool, fini to clean it up, get to obtain a new buffer. Note that all buffers are expected to be inactive before cleaning up the pool.

Locking is currently based on the caller holding the struct_mutex. We already do that in the places where we will use the batch pool for the command parser.

v2:
- s/BUG_ON/WARN_ON/ for locking assertions
- Remove the cap on pool size
- Switch from alloc/free to init/fini

v3:
- Idiomatic looping structure in _fini
- Correct handling of purged objects
- Don't return a buffer that's too much larger than needed

v4:
- Rebased to latest -nightly

v5:
- Remove _put() function and clean up comments to match

v6:
- Move purged check inside the loop (danvet, from v4 1/7 feedback)

v7:
- Use single list instead of two. (Chris W)
- s/active_list/cache_list
- Squashed in debug patches (Chris W)
drm/i915: Add a batch pool debugfs file

It provides some useful information about the buffers in the global command parser batch pool.

v2: rebase on global pool instead of per-ring pools
v3: rebase

drm/i915: Add batch pool details to i915_gem_objects debugfs

To better account for the potentially large memory consumption of the batch pool.

Issue: VIZ-4719

---
  Documentation/DocBook/drm.tmpl             |   5 ++
  drivers/gpu/drm/i915/Makefile              |   1 +
  drivers/gpu/drm/i915/i915_debugfs.c        |  71 ++++++++++++++--
  drivers/gpu/drm/i915/i915_drv.h            |  21 +++++
  drivers/gpu/drm/i915/i915_gem.c            |   1 +
  drivers/gpu/drm/i915/i915_gem_batch_pool.c | 132
+++++++++++++++++++++++++++++
  6 files changed, 222 insertions(+), 9 deletions(-)  create mode

100644 drivers/gpu/drm/i915/i915_gem_batch_pool.c

(quoted diff) +0 -0

b/Documentation/DocBook/drm.tmpl index 85287cb..022923a 100644

Documentation/DocBook/drm.tmpl +0 -0
@@ -4029,6 +4029,11 @@ int num_ioctls;</synopsis>

!Idrivers/gpu/drm/i915/i915_cmd_parser.c

        </sect2>
        <sect2>
Documentation/DocBook/drm.tmpl +5 -0
+        <title>Batchbuffer Pools</title>
+!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
+!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
+      </sect2>
+      <sect2>
          <title>Logical Rings, Logical Ring Contexts and

Execlists</title> !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists !Idrivers/gpu/drm/i915/intel_lrc.c

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile index e4083e4..c8dbb37d 100644

drivers/gpu/drm/i915/Makefile +1 -0
@@ -19,6 +19,7 @@ i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o
 
  # GEM code
  i915-y += i915_cmd_parser.o \
+	  i915_gem_batch_pool.o \
  	  i915_gem_context.o \
  	  i915_gem_render_state.o \
  	  i915_gem_debug.o \
drivers/gpu/drm/i915/i915_debugfs.c +0 -0
index d0e445e..3c3bf98 100644
@@ -359,6 +359,33 @@ static int per_file_stats(int id, void *ptr,
Quoted 1 line

void

*data)

drivers/gpu/drm/i915/i915_debugfs.c

Quoted 6 lines
  	return 0;
  }
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
+#define print_file_stats(m, name, stats) \
+	seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu
+inactive,

%zu global, %zu shared, %zu unbound)\n", \

Quoted 11 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 371

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +8 -0
+		   name, \
+		   stats.count, \
+		   stats.total, \
+		   stats.active, \
+		   stats.inactive, \
+		   stats.global, \
+		   stats.shared, \
+		   stats.unbound)

"print_file_stats" might be better named "print_obj_stats" or similar. As it stands there is nothing in its name to suggest its purpose is to describe

Quoted 4 lines

an object.
I guess the fnc name 'print_file_stats' was chosen b/c it takes a 'stats' parameter of type 'struct file_stats' and prints the members. Seems fair to leave it I think as its generic.

Ok, agreed.

Quoted 16 lines
Quoted 16 lines
Quoted 14 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +2 -0
+
+static void print_batch_pool_stats(struct seq_file *m,

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 384

Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +10 -0
+				   struct drm_i915_private *dev_priv) {
+	struct drm_i915_gem_object *obj;
+	struct file_stats stats;
+
+	memset(&stats, 0, sizeof(stats));
+
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list)
+		per_file_stats(0, obj, &stats);

Shouldn't we be holding the batch_pool lock here ?

Quoted 5 lines

Think we're okay here. The callers of print_batch_pool_stats() hold dev->struct_mutex.

Thanks,
-Mike

But then, why do we take the batch_pool lock in i915_gem_batch_pool_info() ?

Quoted 189 lines
Quoted 189 lines
Quoted 189 lines

drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data)

Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
+
+	print_file_stats(m, "batch pool", stats); }
+
  #define count_vmas(list, member) do { \
  	list_for_each_entry(vma, list, member) { \
  		size += i915_gem_obj_ggtt_size(vma->obj); \ @@ -441,6

+468,9 @@

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_object_info(struct seq_file · line 488

Quoted 12 lines

static int i915_gem_object_info(struct seq_file *m, void* data)
dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);

  	seq_putc(m, '\n');
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
+	print_batch_pool_stats(m, dev_priv);
+
+	seq_putc(m, '\n');
  	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  		struct file_stats stats;
  		struct task_struct *task;
@@ -458,15 +488,7 @@ static int i915_gem_object_info(struct seq_file
 *m,

void* data)

drivers/gpu/drm/i915/i915_debugfs.c static int i915_gem_object_info(struct seq_file *m, void* data)

Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +0 -1
  		 */
  		rcu_read_lock();
  		task = pid_task(file->pid, PIDTYPE_PID);
-		seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu

inactive, %zu global, %zu shared, %zu unbound)\n",

Quoted 13 lines
drivers/gpu/drm/i915/i915_debugfs.c +1 -8
-			   task ? task->comm : "<unknown>",
-			   stats.count,
-			   stats.total,
-			   stats.active,
-			   stats.inactive,
-			   stats.global,
-			   stats.shared,
-			   stats.unbound);
+		print_file_stats(m, task ? task->comm : "<unknown>", stats);
  		rcu_read_unlock();
  	}
@@ -583,6 +605,36 @@ static int i915_gem_pageflip_info(struct
Quoted 1 line

seq_file

*m, void *data)

Quoted 81 lines
  	return 0;
  }
drivers/gpu/drm/i915/i915_debugfs.c +29 -0
+static int i915_gem_batch_pool_info(struct seq_file *m, void *data) {
+	struct drm_info_node *node = m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj;
+	int count = 0;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_puts(m, "cache:\n");
+	list_for_each_entry(obj,
+			    &dev_priv->mm.batch_pool.cache_list,
+			    batch_pool_list) {
+		seq_puts(m, "   ");
+		describe_obj(m, obj);
+		seq_putc(m, '\n');
+		count++;
+	}
+
+	seq_printf(m, "total: %d\n", count);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
  static int i915_gem_request_info(struct seq_file *m, void *data)  {
  	struct drm_info_node *node = m->private; @@ -4324,6 +4376,7 @@

static const struct drm_info_list i915_debugfs_list[] = {
{"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS}, {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS}, {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},

drivers/gpu/drm/i915/i915_debugfs.c +1 -0
+	{"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
  	{"i915_frequency_info", i915_frequency_info, 0},
  	{"i915_drpc_info", i915_drpc_info, 0},
  	{"i915_emon_status", i915_emon_status, 0}, diff --git

a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 11e85cb..f3e27e9 100644

drivers/gpu/drm/i915/i915_drv.h +14 -0
@@ -1129,6 +1129,11 @@ struct intel_l3_parity {
  	int which_slice;
  };
 
+struct i915_gem_batch_pool {
+	struct drm_device *dev;
+	struct list_head cache_list;
+};
+
  struct i915_gem_mm {
  	/** Memory allocator for GTT stolen memory */
  	struct drm_mm stolen;
@@ -1142,6 +1147,13 @@ struct i915_gem_mm {
  	 */
  	struct list_head unbound_list;
 
+	/*
+	 * A pool of objects to use as shadow copies of client batch buffers
+	 * when the command parser is enabled. Prevents the client from
+	 * modifying the batch contents after software parsing.
+	 */
+	struct i915_gem_batch_pool batch_pool;
+
  	/** Usable portion of the GTT for GEM */
  	unsigned long stolen_base; /* limited to low memory (32-bit) */
 
@@ -1872,6 +1884,8 @@ struct drm_i915_gem_object {
  	/** Used in execbuf to temporarily hold a ref */
  	struct list_head obj_exec_link;
 
+	struct list_head batch_pool_list;
+
  	/**
  	 * This is set if the object is on the active lists (has pending
  	 * rendering and so a non-zero seqno), and is not set if it i s
Quoted 1 line

on @@ -2876,6 +2890,13 @@ void i915_destroy_error_state(struct

drm_device

drivers/gpu/drm/i915/i915_gem.c void i915_gem_object_init(struct

Quoted 19 lines

*dev); void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone); const char *i915_cache_level_str(struct drm_i915_private *i915, int type);

drivers/gpu/drm/i915/i915_drv.h +7 -1
+/* i915_gem_batch_pool.c */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool); void
+i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool); struct
+drm_i915_gem_object* i915_gem_batch_pool_get(struct
+i915_gem_batch_pool *pool, size_t size);
+
  /* i915_cmd_parser.c */
  int i915_cmd_parser_get_version(void);
  int i915_cmd_parser_init_ring(struct intel_engine_cs *ring); diff
--git a/drivers/gpu/drm/i915/i915_gem.c

b/drivers/gpu/drm/i915/i915_gem.c index de241eb..2f14ae1 100644

drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -4384,6 +4384,7 @@ void i915_gem_object_init(struct

drm_i915_gem_object *obj,

Quoted 26 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
  	INIT_LIST_HEAD(&obj->ring_list);
  	INIT_LIST_HEAD(&obj->obj_exec_link);
  	INIT_LIST_HEAD(&obj->vma_list);
+	INIT_LIST_HEAD(&obj->batch_pool_list);
 
  	obj->ops = ops;
 
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +12 -0
new file mode 100644
index 0000000..e9349e3
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
+"Software"),
+ * to deal in the Software without restriction, including without
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 22

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including
+the next
+ * paragraph) shall be included in all copies or substantial
+portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY

KIND,

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 26

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +4 -0
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN

NO EVENT

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Quoted 146 lines
Quoted 6 lines
Quoted 6 lines

DAMAGES

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 30

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +2 -0
+ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE

USE

Quoted 139 lines
Quoted 139 lines

OR

Quoted 105 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +105 -0
+OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "i915_drv.h"
+
+/**
+ * DOC: batch pool
+ *
+ * In order to submit batch buffers as 'secure', the software
+command parser
+ * must ensure that a batch buffer cannot be modified after parsing.
+It does
+ * this by copying the user provided batch buffer contents to a
+kernel owned
+ * buffer from which the hardware will actually execute, and by
+carefully
+ * managing the address space bindings for such buffers.
+ *
+ * The batch pool framework provides a mechanism for the driver to
+manage a
+ * set of scratch buffers to use for this purpose. The framework
+can be
+ * extended to support other uses cases should they arise.
+ */
+
+/**
+ * i915_gem_batch_pool_init() - initialize a batch buffer pool
+ * @dev: the drm device
+ * @pool: the batch buffer pool
+ */
+void i915_gem_batch_pool_init(struct drm_device *dev,
+			      struct i915_gem_batch_pool *pool) {
+	pool->dev = dev;
+	INIT_LIST_HEAD(&pool->cache_list);
+}
+
+/**
+ * i915_gem_batch_pool_fini() - clean up a batch buffer pool
+ * @pool: the pool to clean up
+ *
+ * Note: Callers must hold the struct_mutex.
+ */
+void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool) {
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	while (!list_empty(&pool->cache_list)) {
+		struct drm_i915_gem_object *obj =
+			list_first_entry(&pool->cache_list,
+					 struct drm_i915_gem_object,
+					 batch_pool_list);
+
+		WARN_ON(obj->active);
+
+		list_del_init(&obj->batch_pool_list);
+		drm_gem_object_unreference(&obj->base);
+	}
+}
+
+/**
+ * i915_gem_batch_pool_get() - select a buffer from the pool
+ * @pool: the batch buffer pool
+ * @size: the minimum desired size of the returned buffer
+ *
+ * Finds or allocates a batch buffer in the pool with at least the
+requested
+ * size. The caller is responsible for any domain, active/inactive,
+or
+ * purgeability management for the returned buffer.
+ *
+ * Note: Callers must hold the struct_mutex
+ *
+ * Return: the selected batch buffer object  */ struct
+drm_i915_gem_object * i915_gem_batch_pool_get(struct
+i915_gem_batch_pool *pool,
+			size_t size)
+{
+	struct drm_i915_gem_object *obj = NULL;
+	struct drm_i915_gem_object *tmp, *next;
+
+	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
+
+	list_for_each_entry_safe(tmp, next,
+			&pool->cache_list, batch_pool_list) {
+
+		if (tmp->active)
+			continue;
+
+		/* While we're looping, do some clean up */
+		if (tmp->madv == __I915_MADV_PURGED) {
+			list_del(&tmp->batch_pool_list);
+			drm_gem_object_unreference(&tmp->base);
+			continue;
+		}
+
+		/*
+		 * Select a buffer that is at least as big as needed
+		 * but not 'too much' bigger. A better way to do this
+		 * might be to bucket the pool objects based on size.
+		 */
+		if (tmp->base.size >= size &&
+		    tmp->base.size <= (2 * size)) {
+			obj = tmp;
+			break;

drivers/gpu/drm/i915/i915_gem_batch_pool.c line 129

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +10 -0
+		}
+	}
+
+	if (!obj) {
+		obj = i915_gem_alloc_object(pool->dev, size);
+		if (!obj)
+			return ERR_PTR(-ENOMEM);
+
+		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
+	}

Shouldn't we have a else list_move_tail here to keep the list in lru order? -Daniel

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_batch_pool.c new file +3 -1
+
+	return obj;
+}
--

1.9.1

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

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

#7 lore raw

Re: [PATCH v6 1/5] drm/i915: Implement a framework for batch buffer pools

Quoted 1 line · Jon

why do we take the batch_pool lock in i915_gem_batch_pool_info() ?

i915_gem_batch_pool_info() is a new debugfs entry while print_batch_pool_stats() is just an internal fnc, called from the debugfs entry i915_gem_object_info(). i915_gem_object_info() handles the locks.
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

PATCH v6 2/5 drm/i915: Use batch pools with the command parser

In reply to [email protected]

From: Brad Volkin <[email protected]>

This patch sets up all of the tracking and copying necessary to use batch pools with the command parser and dispatches the copied (shadow) batch to the hardware.

After this patch, the parser is in 'enabling' mode.

Note that performance takes a hit from the copy in some cases and will likely need some work. At a rough pass, the memcpy appears to be the bottleneck. Without having done a deeper analysis, two ideas that come to mind are:
1) Copy sections of the batch at a time, as they are reached by parsing. Might improve cache locality.
2) Copy only up to the userspace-supplied batch length and memset the rest of the buffer. Reduces the number of reads.

v2:
- Remove setting the capacity of the pool
- One global pool instead of per-ring pools
- Replace batch_obj with shadow_batch_obj and hook into eb->vmas
- Memset any space in the shadow batch beyond what gets copied
- Rebased on execlist prep refactoring

v3:
- Rebase on chained batch handling
- Squash in setting the secure dispatch flag
- Add a note about the interaction w/secure dispatch pinning
- Check for request->batch_obj == NULL in i915_gem_free_request

v4:
- Fix read domains for shadow_batch_obj
- Remove the set_to_gtt_domain call from i915_parse_cmds
- ggtt_pin/unpin in the parser block to simplify error handling
- Check USES_FULL_PPGTT before setting DISPATCH_SECURE flag
- Remove i915_gem_batch_pool_put calls

v5:
- Move 'pending_read_domains |= I915_GEM_DOMAIN_COMMAND' after the parser (danvet, from v4 0/7 feedback)

Issue: VIZ-4719

---
 drivers/gpu/drm/i915/i915_cmd_parser.c     | 79 +++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_dma.c            |  1 +
 drivers/gpu/drm/i915/i915_drv.h            |  1 +
 drivers/gpu/drm/i915/i915_gem.c            |  2 +
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 52 +++++++++++++++++---
 5 files changed, 112 insertions(+), 23 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +62 -17
index 6e9eac4..ac5f5af 100644
@@ -840,6 +840,56 @@ finish:
 	return (u32*)addr;
 }
 
+/* Returns a vmap'd pointer to dest_obj, which the caller must unmap */
+static u32 *copy_batch(struct drm_i915_gem_object *dest_obj,
+		       struct drm_i915_gem_object *src_obj)
+{
+	int ret = 0;
+	int needs_clflush = 0;
+	u32 *src_addr, *dest_addr = NULL;
+
+	ret = i915_gem_obj_prepare_shmem_read(src_obj, &needs_clflush);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: failed to prep read\n");
+		return ERR_PTR(ret);
+	}
+
+	src_addr = vmap_batch(src_obj);
+	if (!src_addr) {
+		DRM_DEBUG_DRIVER("CMD: Failed to vmap batch\n");
+		ret = -ENOMEM;
+		goto unpin_src;
+	}
+
+	if (needs_clflush)
+		drm_clflush_virt_range((char *)src_addr, src_obj->base.size);
+
+	ret = i915_gem_object_set_to_cpu_domain(dest_obj, true);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: Failed to set batch CPU domain\n");
+		goto unmap_src;
+	}
+
+	dest_addr = vmap_batch(dest_obj);
+	if (!dest_addr) {
+		DRM_DEBUG_DRIVER("CMD: Failed to vmap shadow batch\n");
+		ret = -ENOMEM;
+		goto unmap_src;
+	}
+
+	memcpy(dest_addr, src_addr, src_obj->base.size);
+	if (dest_obj->base.size > src_obj->base.size)
+		memset((u8 *)dest_addr + src_obj->base.size, 0,
+		       dest_obj->base.size - src_obj->base.size);
+
+unmap_src:
+	vunmap(src_addr);
+unpin_src:
+	i915_gem_object_unpin_pages(src_obj);
+
+	return ret ? ERR_PTR(ret) : dest_addr;
+}
+
 /**
  * i915_needs_cmd_parser() - should a given ring use software command parsing?
  * @ring: the ring in question
@@ -956,6 +1006,7 @@ static bool check_cmd(const struct intel_engine_cs *ring,
  * i915_parse_cmds() - parse a submitted batch buffer for privilege violations
  * @ring: the ring on which the batch is to execute
  * @batch_obj: the batch buffer in question
+ * @shadow_batch_obj: copy of the batch buffer in question
  * @batch_start_offset: byte offset in the batch at which execution starts
  * @is_master: is the submitting process the drm master?
  *
@@ -967,32 +1018,28 @@ static bool check_cmd(const struct intel_engine_cs *ring,
  */
 int i915_parse_cmds(struct intel_engine_cs *ring,
 		    struct drm_i915_gem_object *batch_obj,
+		    struct drm_i915_gem_object *shadow_batch_obj,
 		    u32 batch_start_offset,
 		    bool is_master)
 {
 	int ret = 0;
 	u32 *cmd, *batch_base, *batch_end;
 	struct drm_i915_cmd_descriptor default_desc = { 0 };
-	int needs_clflush = 0;
 	bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
 
-	ret = i915_gem_obj_prepare_shmem_read(batch_obj, &needs_clflush);
-	if (ret) {
-		DRM_DEBUG_DRIVER("CMD: failed to prep read\n");
-		return ret;
+	batch_base = copy_batch(shadow_batch_obj, batch_obj);
+	if (IS_ERR(batch_base)) {
+		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
+		return PTR_ERR(batch_base);
 	}
 
-	batch_base = vmap_batch(batch_obj);
-	if (!batch_base) {
-		DRM_DEBUG_DRIVER("CMD: Failed to vmap batch\n");
-		i915_gem_object_unpin_pages(batch_obj);
-		return -ENOMEM;
-	}
-
-	if (needs_clflush)
-		drm_clflush_virt_range((char *)batch_base, batch_obj->base.size);
-
 	cmd = batch_base + (batch_start_offset / sizeof(*cmd));
+
+	/*
+	 * We use the source object's size because the shadow object is as
+	 * large or larger and copy_batch() will write MI_NOPs to the extra
+	 * space. Parsing should be faster in some cases this way.
+	 */
 	batch_end = cmd + (batch_obj->base.size / sizeof(*batch_end));
 
 	while (cmd < batch_end) {
@@ -1054,8 +1101,6 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 
 	vunmap(batch_base);
 
-	i915_gem_object_unpin_pages(batch_obj);
-
 	return ret;
 }
 
drivers/gpu/drm/i915/i915_dma.c +1 -0
index 887d88f..52730ed 100644
@@ -928,6 +928,7 @@ int i915_driver_unload(struct drm_device *dev)
 
 		mutex_lock(&dev->struct_mutex);
 		i915_gem_cleanup_ringbuffer(dev);
+		i915_gem_batch_pool_fini(&dev_priv->mm.batch_pool);
 		i915_gem_context_fini(dev);
 		mutex_unlock(&dev->struct_mutex);
 		i915_gem_cleanup_stolen(dev);
drivers/gpu/drm/i915/i915_drv.h +1 -0
index f3e27e9..6e3d354 100644
@@ -2904,6 +2904,7 @@ void i915_cmd_parser_fini_ring(struct intel_engine_cs *ring);
 bool i915_needs_cmd_parser(struct intel_engine_cs *ring);
 int i915_parse_cmds(struct intel_engine_cs *ring,
 		    struct drm_i915_gem_object *batch_obj,
+		    struct drm_i915_gem_object *shadow_batch_obj,
 		    u32 batch_start_offset,
 		    bool is_master);
 
drivers/gpu/drm/i915/i915_gem.c +2 -0
index 2f14ae1..f6ef436 100644
@@ -4997,6 +4997,8 @@ i915_gem_load(struct drm_device *dev)
 	dev_priv->mm.oom_notifier.notifier_call = i915_gem_shrinker_oom;
 	register_oom_notifier(&dev_priv->mm.oom_notifier);
 
+	i915_gem_batch_pool_init(dev, &dev_priv->mm.batch_pool);
+
 	mutex_init(&dev_priv->fb_tracking.lock);
 }
 
drivers/gpu/drm/i915/i915_gem_execbuffer.c +46 -6

80 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
#9 lore raw

PATCH v6 3/5 drm/i915: Use batch length instead of object size in command parser

In reply to [email protected]

From: Brad Volkin <[email protected]>

Previously we couldn't trust the user-supplied batch length because it came directly from userspace (i.e. untrusted code). It would have affected what commands software parsed without regard to what hardware would actually execute, leaving a potential hole.

With the parser now copying the user supplied batch buffer and writing MI_NOP commands to any space after the copied region, we can safely use the batch length input. This should be a performance win as the actual batch length is frequently much smaller than the allocated object size.

v2: Fix handling of non-zero batch_start_offset

Issue: VIZ-4719

---
 drivers/gpu/drm/i915/i915_cmd_parser.c     | 48 ++++++++++++++++++++----------
 drivers/gpu/drm/i915/i915_drv.h            |  1 +
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  1 +
 3 files changed, 34 insertions(+), 16 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +32 -16
index ac5f5af..118079d 100644
@@ -842,11 +842,19 @@ finish:
 
 /* Returns a vmap'd pointer to dest_obj, which the caller must unmap */
 static u32 *copy_batch(struct drm_i915_gem_object *dest_obj,
-		       struct drm_i915_gem_object *src_obj)
+		       struct drm_i915_gem_object *src_obj,
+		       u32 batch_start_offset,
+		       u32 batch_len)
 {
 	int ret = 0;
 	int needs_clflush = 0;
-	u32 *src_addr, *dest_addr = NULL;
+	u32 *src_base, *dest_base = NULL;
+	u32 *src_addr, *dest_addr;
+	u32 offset = batch_start_offset / sizeof(*dest_addr);
+	u32 end = batch_start_offset + batch_len;
+
+	if (end > dest_obj->base.size || end > src_obj->base.size)
+		return ERR_PTR(-E2BIG);
 
 	ret = i915_gem_obj_prepare_shmem_read(src_obj, &needs_clflush);
 	if (ret) {
@@ -854,15 +862,17 @@ static u32 *copy_batch(struct drm_i915_gem_object *dest_obj,
 		return ERR_PTR(ret);
 	}
 
-	src_addr = vmap_batch(src_obj);
-	if (!src_addr) {
+	src_base = vmap_batch(src_obj);
+	if (!src_base) {
 		DRM_DEBUG_DRIVER("CMD: Failed to vmap batch\n");
 		ret = -ENOMEM;
 		goto unpin_src;
 	}
 
+	src_addr = src_base + offset;
+
 	if (needs_clflush)
-		drm_clflush_virt_range((char *)src_addr, src_obj->base.size);
+		drm_clflush_virt_range((char *)src_addr, batch_len);
 
 	ret = i915_gem_object_set_to_cpu_domain(dest_obj, true);
 	if (ret) {
@@ -870,24 +880,27 @@ static u32 *copy_batch(struct drm_i915_gem_object *dest_obj,
 		goto unmap_src;
 	}
 
-	dest_addr = vmap_batch(dest_obj);
-	if (!dest_addr) {
+	dest_base = vmap_batch(dest_obj);
+	if (!dest_base) {
 		DRM_DEBUG_DRIVER("CMD: Failed to vmap shadow batch\n");
 		ret = -ENOMEM;
 		goto unmap_src;
 	}
 
-	memcpy(dest_addr, src_addr, src_obj->base.size);
-	if (dest_obj->base.size > src_obj->base.size)
-		memset((u8 *)dest_addr + src_obj->base.size, 0,
-		       dest_obj->base.size - src_obj->base.size);
+	dest_addr = dest_base + offset;
+
+	if (batch_start_offset != 0)
+		memset((u8 *)dest_base, 0, batch_start_offset);
+
+	memcpy(dest_addr, src_addr, batch_len);
+	memset((u8 *)dest_addr + batch_len, 0, dest_obj->base.size - end);
 
 unmap_src:
-	vunmap(src_addr);
+	vunmap(src_base);
 unpin_src:
 	i915_gem_object_unpin_pages(src_obj);
 
-	return ret ? ERR_PTR(ret) : dest_addr;
+	return ret ? ERR_PTR(ret) : dest_base;
 }
 
 /**
@@ -1008,6 +1021,7 @@ static bool check_cmd(const struct intel_engine_cs *ring,
  * @batch_obj: the batch buffer in question
  * @shadow_batch_obj: copy of the batch buffer in question
  * @batch_start_offset: byte offset in the batch at which execution starts
+ * @batch_len: length of the commands in batch_obj
  * @is_master: is the submitting process the drm master?
  *
  * Parses the specified batch buffer looking for privilege violations as
@@ -1020,6 +1034,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 		    struct drm_i915_gem_object *batch_obj,
 		    struct drm_i915_gem_object *shadow_batch_obj,
 		    u32 batch_start_offset,
+		    u32 batch_len,
 		    bool is_master)
 {
 	int ret = 0;
@@ -1027,7 +1042,8 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	struct drm_i915_cmd_descriptor default_desc = { 0 };
 	bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
 
-	batch_base = copy_batch(shadow_batch_obj, batch_obj);
+	batch_base = copy_batch(shadow_batch_obj, batch_obj,
+				batch_start_offset, batch_len);
 	if (IS_ERR(batch_base)) {
 		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
 		return PTR_ERR(batch_base);
@@ -1036,11 +1052,11 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	cmd = batch_base + (batch_start_offset / sizeof(*cmd));
 
 	/*
-	 * We use the source object's size because the shadow object is as
+	 * We use the batch length as size because the shadow object is as
 	 * large or larger and copy_batch() will write MI_NOPs to the extra
 	 * space. Parsing should be faster in some cases this way.
 	 */
-	batch_end = cmd + (batch_obj->base.size / sizeof(*batch_end));
+	batch_end = cmd + (batch_len / sizeof(*batch_end));
 
 	while (cmd < batch_end) {
 		const struct drm_i915_cmd_descriptor *desc;
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 6e3d354..de0e002 100644
@@ -2906,6 +2906,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 		    struct drm_i915_gem_object *batch_obj,
 		    struct drm_i915_gem_object *shadow_batch_obj,
 		    u32 batch_start_offset,
+		    u32 batch_len,
 		    bool is_master);
 
 /* i915_suspend.c */
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
index a108184..fccfff5 100644
@@ -1418,6 +1418,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 				      batch_obj,
 				      shadow_batch_obj,
 				      args->batch_start_offset,
+				      args->batch_len,
 				      file->is_master);
 		i915_gem_object_ggtt_unpin(shadow_batch_obj);
 
Signature · 6 lines
1.9.1

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

PATCH v6 4/5 drm/i915: Mark shadow batch buffers as purgeable

In reply to [email protected]

From: Brad Volkin <[email protected]>

By adding a new exec_entry flag, we cleanly mark the shadow objects as purgeable after they are on the active list.

v2:
- Move 'shadow_batch_obj->madv = I915_MADV_WILLNEED' inside _get fnc (danvet, from v4 6/7 feedback)

Issue: VIZ-4719

---
 drivers/gpu/drm/i915/i915_gem_batch_pool.c |  2 ++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_batch_pool.c +2 -0
index e9349e3..9e0ec4b 100644
@@ -128,5 +128,7 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
 		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
 	}
 
+	obj->madv = I915_MADV_WILLNEED;
+
 	return obj;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -1
index fccfff5..2071938 100644
@@ -37,6 +37,7 @@
 #define  __EXEC_OBJECT_HAS_FENCE (1<<30)
 #define  __EXEC_OBJECT_NEEDS_MAP (1<<29)
 #define  __EXEC_OBJECT_NEEDS_BIAS (1<<28)
+#define  __EXEC_OBJECT_PURGEABLE (1<<27)
 
 #define BATCH_OFFSET_BIAS (256*1024)
 
@@ -226,7 +227,12 @@ i915_gem_execbuffer_unreserve_vma(struct i915_vma *vma)
 	if (entry->flags & __EXEC_OBJECT_HAS_PIN)
 		vma->pin_count--;
 
-	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN);
+	if (entry->flags & __EXEC_OBJECT_PURGEABLE)
+		obj->madv = I915_MADV_DONTNEED;
+
+	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
+			  __EXEC_OBJECT_HAS_PIN |
+			  __EXEC_OBJECT_PURGEABLE);
 }
 
 static void eb_destroy(struct eb_vmas *eb)
@@ -1410,6 +1416,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 			goto err;
 		}
 
+		shadow_batch_obj->madv = I915_MADV_WILLNEED;
+
 		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
 		if (ret)
 			goto err;
@@ -1433,6 +1441,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 
 			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
 			vma->exec_entry = &shadow_exec_entry;
+			vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
 			drm_gem_object_reference(&shadow_batch_obj->base);
 			list_add_tail(&vma->exec_list, &eb->vmas);
 
Signature · 6 lines
1.9.1

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

Re: [PATCH v6 4/5] drm/i915: Mark shadow batch buffers as purgeable

Quoted 8 lines · On Mon, Dec 08, 2014 at 02:33:49PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

By adding a new exec_entry flag, we cleanly mark the shadow objects as purgeable after they are on the active list.

v2:
- Move 'shadow_batch_obj->madv = I915_MADV_WILLNEED' inside _get fnc (danvet, from v4 6/7 feedback)

Seems duplicated now.
-Daniel

Quoted 70 lines

Issue: VIZ-4719

---
 drivers/gpu/drm/i915/i915_gem_batch_pool.c |  2 ++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_batch_pool.c +2 -0
index e9349e3..9e0ec4b 100644
@@ -128,5 +128,7 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
 		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
 	}
 
+	obj->madv = I915_MADV_WILLNEED;
+
 	return obj;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -1
index fccfff5..2071938 100644
@@ -37,6 +37,7 @@
 #define  __EXEC_OBJECT_HAS_FENCE (1<<30)
 #define  __EXEC_OBJECT_NEEDS_MAP (1<<29)
 #define  __EXEC_OBJECT_NEEDS_BIAS (1<<28)
+#define  __EXEC_OBJECT_PURGEABLE (1<<27)
 
 #define BATCH_OFFSET_BIAS (256*1024)
 
@@ -226,7 +227,12 @@ i915_gem_execbuffer_unreserve_vma(struct i915_vma *vma)
 	if (entry->flags & __EXEC_OBJECT_HAS_PIN)
 		vma->pin_count--;
 
-	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN);
+	if (entry->flags & __EXEC_OBJECT_PURGEABLE)
+		obj->madv = I915_MADV_DONTNEED;
+
+	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
+			  __EXEC_OBJECT_HAS_PIN |
+			  __EXEC_OBJECT_PURGEABLE);
 }
 
 static void eb_destroy(struct eb_vmas *eb)
@@ -1410,6 +1416,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 			goto err;
 		}
 
+		shadow_batch_obj->madv = I915_MADV_WILLNEED;
+
 		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
 		if (ret)
 			goto err;
@@ -1433,6 +1441,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 
 			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
 			vma->exec_entry = &shadow_exec_entry;
+			vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
 			drm_gem_object_reference(&shadow_batch_obj->base);
 			list_add_tail(&vma->exec_list, &eb->vmas);
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

Re: [PATCH v6 4/5] drm/i915: Mark shadow batch buffers as purgeable

Quoted 11 lines · Daniel Vetter
Quoted 8 lines · On Mon, Dec 08, 2014 at 02:33:49PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

By adding a new exec_entry flag, we cleanly mark the shadow objects as purgeable after they are on the active list.

v2:
- Move 'shadow_batch_obj->madv = I915_MADV_WILLNEED' inside _get fnc (danvet, from v4 6/7 feedback)

Seems duplicated now.

Good eyes! The duplicate does go away in 5/5 as part of moving much of the cmdparser code out of do_execbuffer() but it still doesn't make 4/5 right. Will fix.

Thanks,
Mike

Quoted 65 lines

-Daniel

Quoted 63 lines

Issue: VIZ-4719

---
  drivers/gpu/drm/i915/i915_gem_batch_pool.c |  2 ++
  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 ++++++++++-
  2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_batch_pool.c +2 -0
index e9349e3..9e0ec4b 100644
@@ -128,5 +128,7 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
  		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
  	}
 
+	obj->madv = I915_MADV_WILLNEED;
+
  	return obj;
  }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -1
index fccfff5..2071938 100644
@@ -37,6 +37,7 @@
  #define  __EXEC_OBJECT_HAS_FENCE (1<<30)
  #define  __EXEC_OBJECT_NEEDS_MAP (1<<29)
  #define  __EXEC_OBJECT_NEEDS_BIAS (1<<28)
+#define  __EXEC_OBJECT_PURGEABLE (1<<27)
 
  #define BATCH_OFFSET_BIAS (256*1024)
 
@@ -226,7 +227,12 @@ i915_gem_execbuffer_unreserve_vma(struct i915_vma *vma)
  	if (entry->flags & __EXEC_OBJECT_HAS_PIN)
  		vma->pin_count--;
 
-	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN);
+	if (entry->flags & __EXEC_OBJECT_PURGEABLE)
+		obj->madv = I915_MADV_DONTNEED;
+
+	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
+			  __EXEC_OBJECT_HAS_PIN |
+			  __EXEC_OBJECT_PURGEABLE);
  }
 
  static void eb_destroy(struct eb_vmas *eb)
@@ -1410,6 +1416,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
  			goto err;
  		}
 
+		shadow_batch_obj->madv = I915_MADV_WILLNEED;
+
  		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
  		if (ret)
  			goto err;
@@ -1433,6 +1441,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 
  			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
  			vma->exec_entry = &shadow_exec_entry;
+			vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
  			drm_gem_object_reference(&shadow_batch_obj->base);
  			list_add_tail(&vma->exec_list, &eb->vmas);
 
Quoted 8 lines
Quoted 7 lines

--
1.9.1

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

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

#13 lore raw

Re: [PATCH v6 4/5] drm/i915: Mark shadow batch buffers as purgeable

In reply to [email protected]
Quoted 67 lines

-----Original Message-----
From: Nguyen, Michael H
Sent: Monday, December 08, 2014 10:34 PM
To: [email protected]
Cc: Bloomfield, Jon; Brad Volkin
Subject: [PATCH v6 4/5] drm/i915: Mark shadow batch buffers as purgeable

From: Brad Volkin <[email protected]>

By adding a new exec_entry flag, we cleanly mark the shadow objects as purgeable after they are on the active list.

v2:
- Move 'shadow_batch_obj->madv = I915_MADV_WILLNEED' inside _get fnc (danvet, from v4 6/7 feedback)

Issue: VIZ-4719

---
 drivers/gpu/drm/i915/i915_gem_batch_pool.c |  2 ++
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_batch_pool.c +2 -0
index e9349e3..9e0ec4b 100644
@@ -128,5 +128,7 @@ i915_gem_batch_pool_get(struct
 i915_gem_batch_pool *pool,
 		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
 	}
 
+	obj->madv = I915_MADV_WILLNEED;
+
 	return obj;

}

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -0
index fccfff5..2071938 100644
@@ -37,6 +37,7 @@
 #define  __EXEC_OBJECT_HAS_FENCE (1<<30)  #define

__EXEC_OBJECT_NEEDS_MAP (1<<29) #define
__EXEC_OBJECT_NEEDS_BIAS (1<<28)

drivers/gpu/drm/i915/i915_gem_execbuffer.c +7 -1
+#define  __EXEC_OBJECT_PURGEABLE (1<<27)
 
 #define BATCH_OFFSET_BIAS (256*1024)
@@ -226,7 +227,12 @@ i915_gem_execbuffer_unreserve_vma(struct
 i915_vma *vma)
 	if (entry->flags & __EXEC_OBJECT_HAS_PIN)
 		vma->pin_count--;
 
-	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
 __EXEC_OBJECT_HAS_PIN);
+	if (entry->flags & __EXEC_OBJECT_PURGEABLE)
+		obj->madv = I915_MADV_DONTNEED;
+
+	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
+			  __EXEC_OBJECT_HAS_PIN |
+			  __EXEC_OBJECT_PURGEABLE);
 }

static void eb_destroy(struct eb_vmas *eb) @@ -1410,6 +1416,8 @@
i915_gem_do_execbuffer(struct drm_device *dev, void *data,

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_gem_do_execbuffer(struct drm_device *dev, void *data, · line 1420

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -0
 			goto err;
 		}
 
+		shadow_batch_obj->madv = I915_MADV_WILLNEED;
+

Hasn't i915_gem_batch_pool_get() has already marked the buffer as WILLNEED ?

Quoted 12 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
 		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
 		if (ret)
 			goto err;
@@ -1433,6 +1441,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,
 void *data,
 
 			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
 			vma->exec_entry = &shadow_exec_entry;
+			vma->exec_entry->flags =
 __EXEC_OBJECT_PURGEABLE;
 			drm_gem_object_reference(&shadow_batch_obj-
Quoted 1 line

base);

Quoted 4 lines

list_add_tail(&vma->exec_list, &eb->vmas);

--
1.9.1

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

#14 lore raw

Re: [PATCH v6 4/5] drm/i915: Mark shadow batch buffers as purgeable

Quoted 70 lines · Jon
Quoted 70 lines

-----Original Message-----
From: Nguyen, Michael H
Sent: Monday, December 08, 2014 10:34 PM
To: [email protected]
Cc: Bloomfield, Jon; Brad Volkin
Subject: [PATCH v6 4/5] drm/i915: Mark shadow batch buffers as purgeable

From: Brad Volkin <[email protected]>

By adding a new exec_entry flag, we cleanly mark the shadow objects as purgeable after they are on the active list.

v2:
- Move 'shadow_batch_obj->madv = I915_MADV_WILLNEED' inside _get fnc (danvet, from v4 6/7 feedback)

Issue: VIZ-4719

---
  drivers/gpu/drm/i915/i915_gem_batch_pool.c |  2 ++
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 ++++++++++-
  2 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_batch_pool.c +2 -0
index e9349e3..9e0ec4b 100644
@@ -128,5 +128,7 @@ i915_gem_batch_pool_get(struct
 i915_gem_batch_pool *pool,
  		list_add_tail(&obj->batch_pool_list, &pool->cache_list);
  	}
 
+	obj->madv = I915_MADV_WILLNEED;
+
  	return obj;
  }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -0
index fccfff5..2071938 100644
@@ -37,6 +37,7 @@
  #define  __EXEC_OBJECT_HAS_FENCE (1<<30)  #define

__EXEC_OBJECT_NEEDS_MAP (1<<29) #define
__EXEC_OBJECT_NEEDS_BIAS (1<<28)

drivers/gpu/drm/i915/i915_gem_execbuffer.c +7 -1
+#define  __EXEC_OBJECT_PURGEABLE (1<<27)
 
  #define BATCH_OFFSET_BIAS (256*1024)
@@ -226,7 +227,12 @@ i915_gem_execbuffer_unreserve_vma(struct
 i915_vma *vma)
  	if (entry->flags & __EXEC_OBJECT_HAS_PIN)
  		vma->pin_count--;
 
-	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
 __EXEC_OBJECT_HAS_PIN);
+	if (entry->flags & __EXEC_OBJECT_PURGEABLE)
+		obj->madv = I915_MADV_DONTNEED;
+
+	entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE |
+			  __EXEC_OBJECT_HAS_PIN |
+			  __EXEC_OBJECT_PURGEABLE);
  }

static void eb_destroy(struct eb_vmas *eb) @@ -1410,6 +1416,8 @@
i915_gem_do_execbuffer(struct drm_device *dev, void *data,
goto err;
}

Quoted 4 lines

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_gem_do_execbuffer(struct drm_device *dev, void *data, · line 1420

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -0
+		shadow_batch_obj->madv = I915_MADV_WILLNEED;
+

Hasn't i915_gem_batch_pool_get() has already marked the buffer as WILLNEED ?

Yes, good eyes. It was actually corrected in 5/5 but that doesn't make this patch okay. Will fix.

Thanks,
Mike

Quoted 13 lines
Quoted 13 lines

  		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
  		if (ret)
  			goto err;
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
@@ -1433,6 +1441,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,
 void *data,
 
  			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
  			vma->exec_entry = &shadow_exec_entry;
+			vma->exec_entry->flags =
 __EXEC_OBJECT_PURGEABLE;
  			drm_gem_object_reference(&shadow_batch_obj-
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

base);

list_add_tail(&vma->exec_list, &eb->vmas);

--
1.9.1

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

#15 lore raw

PATCH v6 5/5 drm/i915: Tidy up execbuffer command parsing code

In reply to [email protected]

From: Brad Volkin <[email protected]>

Move it to a separate function since the main do_execbuffer function already has so much going on.

v2:
- Move pin/unpin calls inside i915_parse_cmds() (Chris W, v4 7/7 feedback)

Issue: VIZ-4719

Conflicts:

	drivers/gpu/drm/i915/i915_gem_execbuffer.c
---
 drivers/gpu/drm/i915/i915_cmd_parser.c     |   8 ++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 126 ++++++++++++++++-------------
 2 files changed, 77 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +8 -0
index 118079d..80b1b28 100644
@@ -1042,10 +1042,17 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	struct drm_i915_cmd_descriptor default_desc = { 0 };
 	bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
 
+	ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: Failed to pin shadow batch\n");
+		return -1;
+	}
+
 	batch_base = copy_batch(shadow_batch_obj, batch_obj,
 				batch_start_offset, batch_len);
 	if (IS_ERR(batch_base)) {
 		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
+		i915_gem_object_ggtt_unpin(shadow_batch_obj);
 		return PTR_ERR(batch_base);
 	}
 
@@ -1116,6 +1123,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	}
 
 	vunmap(batch_base);
+	i915_gem_object_ggtt_unpin(shadow_batch_obj);
 
 	return ret;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +69 -57

145 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
Tested-by on v6 5/5
#16 lore raw

Re: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

-------------------------------------Summary-------------------------------------
Platform Delta drm-intel-nightly Series Applied
PNV 364/364 364/364
ILK +1 365/366 366/366

SNB                                  450/450              450/450
IVB                 -17              498/498              481/498
BYT                                  289/289              289/289
HSW                                  564/564              564/564
BDW                                  417/417              417/417
-------------------------------------Detailed-------------------------------------
Platform  Test                                drm-intel-nightly          Series Applied
 ILK  igt_kms_flip_wf_vblank-ts-check      DMESG_WARN(2, M26)PASS(18, M26M37)      PASS(1, M37)
 IVB  igt_kms_3d      DMESG_WARN(4, M34)PASS(1, M34)      DMESG_WARN(1, M34)
 IVB  igt_kms_cursor_crc_cursor-128x128-onscreen      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-128x128-random      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-128x128-sliding      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-256x256-offscreen      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-256x256-onscreen      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-256x256-sliding      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-64x64-offscreen      NSPT(4, M34)PASS(2, M34M21)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-64x64-onscreen      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-64x64-random      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-64x64-sliding      FAIL(1, M21)NSPT(4, M34)PASS(2, M34M21)      NSPT(1, M34)
 IVB  igt_kms_cursor_crc_cursor-size-change      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_fence_pin_leak      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_mmio_vs_cs_flip_setcrtc_vs_cs_flip      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_mmio_vs_cs_flip_setplane_vs_cs_flip      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_rotation_crc_primary-rotation      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)
 IVB  igt_kms_rotation_crc_sprite-rotation      NSPT(4, M34)PASS(1, M34)      NSPT(1, M34)

Note: You need to pay more attention to line start with '*'
_______________________________________________
Intel-gfx mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#17 lore raw

Re: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

In reply to [email protected]
Quoted 9 lines · On Mon, Dec 08, 2014 at 02:33:50PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

Move it to a separate function since the main do_execbuffer function already has so much going on.

v2:
- Move pin/unpin calls inside i915_parse_cmds() (Chris W, v4 7/7 feedback)

Quoted 5 lines

Issue: VIZ-4719

Conflicts:

	drivers/gpu/drm/i915/i915_gem_execbuffer.c

Please remove those when rebasing. When actually something changed please mention that in the patch revlog, e.g.

v3: Rebase (conflicts with patch "foo" in execbuf code).

But if it's a boring rebase without any functional conflicts I wouldn't bother with a changelog entry.
-Daniel

Quoted 194 lines
---
 drivers/gpu/drm/i915/i915_cmd_parser.c     |   8 ++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 126 ++++++++++++++++-------------
 2 files changed, 77 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +8 -0
index 118079d..80b1b28 100644
@@ -1042,10 +1042,17 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	struct drm_i915_cmd_descriptor default_desc = { 0 };
 	bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
 
+	ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: Failed to pin shadow batch\n");
+		return -1;
+	}
+
 	batch_base = copy_batch(shadow_batch_obj, batch_obj,
 				batch_start_offset, batch_len);
 	if (IS_ERR(batch_base)) {
 		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
+		i915_gem_object_ggtt_unpin(shadow_batch_obj);
 		return PTR_ERR(batch_base);
 	}
 
@@ -1116,6 +1123,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	}
 
 	vunmap(batch_base);
+	i915_gem_object_ggtt_unpin(shadow_batch_obj);
 
 	return ret;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +69 -57
index 2071938..3d36465 100644
@@ -1069,6 +1069,65 @@ i915_emit_box(struct intel_engine_cs *ring,
 	return 0;
 }
 
+static struct drm_i915_gem_object*
+i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
+			  struct drm_i915_gem_exec_object2 *shadow_exec_entry,
+			  struct eb_vmas *eb,
+			  struct drm_i915_gem_object *batch_obj,
+			  u32 batch_start_offset,
+			  u32 batch_len,
+			  bool is_master,
+			  u32 *flags)
+{
+	struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev);
+	struct drm_i915_gem_object *shadow_batch_obj;
+	int ret;
+
+	shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
+						   batch_obj->base.size);
+	if (IS_ERR(shadow_batch_obj))
+		return shadow_batch_obj;
+
+	ret = i915_parse_cmds(ring,
+			      batch_obj,
+			      shadow_batch_obj,
+			      batch_start_offset,
+			      batch_len,
+			      is_master);
+	if (ret) {
+		if (ret == -EACCES)
+			return batch_obj;
+	} else {
+		struct i915_vma *vma;
+
+		memset(shadow_exec_entry, 0, sizeof(*shadow_exec_entry));
+
+		vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
+		vma->exec_entry = shadow_exec_entry;
+		vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
+		drm_gem_object_reference(&shadow_batch_obj->base);
+		list_add_tail(&vma->exec_list, &eb->vmas);
+
+		shadow_batch_obj->base.pending_read_domains =
+			batch_obj->base.pending_read_domains;
+
+		/*
+		 * Set the DISPATCH_SECURE bit to remove the NON_SECURE
+		 * bit from MI_BATCH_BUFFER_START commands issued in the
+		 * dispatch_execbuffer implementations. We specifically
+		 * don't want that set when the command parser is
+		 * enabled.
+		 *
+		 * FIXME: with aliasing ppgtt, buffers that should only
+		 * be in ggtt still end up in the aliasing ppgtt. remove
+		 * this check when that is fixed.
+		 */
+		if (USES_FULL_PPGTT(dev))
+			*flags |= I915_DISPATCH_SECURE;
+	}
+
+	return ret ? ERR_PTR(ret) : shadow_batch_obj;
+}
 
 int
 i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file *file,
@@ -1286,7 +1345,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct eb_vmas *eb;
 	struct drm_i915_gem_object *batch_obj;
-	struct drm_i915_gem_object *shadow_batch_obj = NULL;
 	struct drm_i915_gem_exec_object2 shadow_exec_entry;
 	struct intel_engine_cs *ring;
 	struct intel_context *ctx;
@@ -1406,63 +1464,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	}
 
 	if (i915_needs_cmd_parser(ring)) {
-		shadow_batch_obj =
-			i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
-						batch_obj->base.size);
-		if (IS_ERR(shadow_batch_obj)) {
-			ret = PTR_ERR(shadow_batch_obj);
-			/* Don't try to clean up the obj in the error path */
-			shadow_batch_obj = NULL;
-			goto err;
-		}
-
-		shadow_batch_obj->madv = I915_MADV_WILLNEED;
-
-		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
-		if (ret)
+		batch_obj = i915_gem_execbuffer_parse(ring,
+						      &shadow_exec_entry,
+						      eb,
+						      batch_obj,
+						      args->batch_start_offset,
+						      args->batch_len,
+						      file->is_master,
+						      &flags);
+		if (IS_ERR(batch_obj)) {
+			ret = PTR_ERR(batch_obj);
 			goto err;
-
-		ret = i915_parse_cmds(ring,
-				      batch_obj,
-				      shadow_batch_obj,
-				      args->batch_start_offset,
-				      args->batch_len,
-				      file->is_master);
-		i915_gem_object_ggtt_unpin(shadow_batch_obj);
-
-		if (ret) {
-			if (ret != -EACCES)
-				goto err;
-		} else {
-			struct i915_vma *vma;
-
-			memset(&shadow_exec_entry, 0,
-			       sizeof(shadow_exec_entry));
-
-			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
-			vma->exec_entry = &shadow_exec_entry;
-			vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
-			drm_gem_object_reference(&shadow_batch_obj->base);
-			list_add_tail(&vma->exec_list, &eb->vmas);
-
-			shadow_batch_obj->base.pending_read_domains =
-				batch_obj->base.pending_read_domains;
-
-			batch_obj = shadow_batch_obj;
-
-			/*
-			 * Set the DISPATCH_SECURE bit to remove the NON_SECURE
-			 * bit from MI_BATCH_BUFFER_START commands issued in the
-			 * dispatch_execbuffer implementations. We specifically
-			 * don't want that set when the command parser is
-			 * enabled.
-			 *
-			 * FIXME: with aliasing ppgtt, buffers that should only
-			 * be in ggtt still end up in the aliasing ppgtt. remove
-			 * this check when that is fixed.
-			 */
-			if (USES_FULL_PPGTT(dev))
-				flags |= I915_DISPATCH_SECURE;
 		}
 	}
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw

Re: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

Quoted 16 lines · Daniel Vetter
Quoted 9 lines · On Mon, Dec 08, 2014 at 02:33:50PM -0800, [email protected] wrote:

From: Brad Volkin <[email protected]>

Move it to a separate function since the main do_execbuffer function already has so much going on.

v2:
- Move pin/unpin calls inside i915_parse_cmds() (Chris W, v4 7/7 feedback)

Quoted 5 lines

Issue: VIZ-4719

Conflicts:

	drivers/gpu/drm/i915/i915_gem_execbuffer.c
Quoted 7 lines

Please remove those when rebasing. When actually something changed please mention that in the patch revlog, e.g.

v3: Rebase (conflicts with patch "foo" in execbuf code).

But if it's a boring rebase without any functional conflicts I wouldn't bother with a changelog entry.

Noted. In this case, its boring.

Thanks,
Mike

Quoted 189 lines

-Daniel

Quoted 187 lines
---
  drivers/gpu/drm/i915/i915_cmd_parser.c     |   8 ++
  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 126 ++++++++++++++++-------------
  2 files changed, 77 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +8 -0
index 118079d..80b1b28 100644
@@ -1042,10 +1042,17 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
  	struct drm_i915_cmd_descriptor default_desc = { 0 };
  	bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
 
+	ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: Failed to pin shadow batch\n");
+		return -1;
+	}
+
  	batch_base = copy_batch(shadow_batch_obj, batch_obj,
  				batch_start_offset, batch_len);
  	if (IS_ERR(batch_base)) {
  		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
+		i915_gem_object_ggtt_unpin(shadow_batch_obj);
  		return PTR_ERR(batch_base);
  	}
 
@@ -1116,6 +1123,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
  	}
 
  	vunmap(batch_base);
+	i915_gem_object_ggtt_unpin(shadow_batch_obj);
 
  	return ret;
  }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +69 -57
index 2071938..3d36465 100644
@@ -1069,6 +1069,65 @@ i915_emit_box(struct intel_engine_cs *ring,
  	return 0;
  }
 
+static struct drm_i915_gem_object*
+i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
+			  struct drm_i915_gem_exec_object2 *shadow_exec_entry,
+			  struct eb_vmas *eb,
+			  struct drm_i915_gem_object *batch_obj,
+			  u32 batch_start_offset,
+			  u32 batch_len,
+			  bool is_master,
+			  u32 *flags)
+{
+	struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev);
+	struct drm_i915_gem_object *shadow_batch_obj;
+	int ret;
+
+	shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
+						   batch_obj->base.size);
+	if (IS_ERR(shadow_batch_obj))
+		return shadow_batch_obj;
+
+	ret = i915_parse_cmds(ring,
+			      batch_obj,
+			      shadow_batch_obj,
+			      batch_start_offset,
+			      batch_len,
+			      is_master);
+	if (ret) {
+		if (ret == -EACCES)
+			return batch_obj;
+	} else {
+		struct i915_vma *vma;
+
+		memset(shadow_exec_entry, 0, sizeof(*shadow_exec_entry));
+
+		vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
+		vma->exec_entry = shadow_exec_entry;
+		vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
+		drm_gem_object_reference(&shadow_batch_obj->base);
+		list_add_tail(&vma->exec_list, &eb->vmas);
+
+		shadow_batch_obj->base.pending_read_domains =
+			batch_obj->base.pending_read_domains;
+
+		/*
+		 * Set the DISPATCH_SECURE bit to remove the NON_SECURE
+		 * bit from MI_BATCH_BUFFER_START commands issued in the
+		 * dispatch_execbuffer implementations. We specifically
+		 * don't want that set when the command parser is
+		 * enabled.
+		 *
+		 * FIXME: with aliasing ppgtt, buffers that should only
+		 * be in ggtt still end up in the aliasing ppgtt. remove
+		 * this check when that is fixed.
+		 */
+		if (USES_FULL_PPGTT(dev))
+			*flags |= I915_DISPATCH_SECURE;
+	}
+
+	return ret ? ERR_PTR(ret) : shadow_batch_obj;
+}
 
  int
  i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file *file,
@@ -1286,7 +1345,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
  	struct drm_i915_private *dev_priv = dev->dev_private;
  	struct eb_vmas *eb;
  	struct drm_i915_gem_object *batch_obj;
-	struct drm_i915_gem_object *shadow_batch_obj = NULL;
  	struct drm_i915_gem_exec_object2 shadow_exec_entry;
  	struct intel_engine_cs *ring;
  	struct intel_context *ctx;
@@ -1406,63 +1464,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
  	}
 
  	if (i915_needs_cmd_parser(ring)) {
-		shadow_batch_obj =
-			i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
-						batch_obj->base.size);
-		if (IS_ERR(shadow_batch_obj)) {
-			ret = PTR_ERR(shadow_batch_obj);
-			/* Don't try to clean up the obj in the error path */
-			shadow_batch_obj = NULL;
-			goto err;
-		}
-
-		shadow_batch_obj->madv = I915_MADV_WILLNEED;
-
-		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
-		if (ret)
+		batch_obj = i915_gem_execbuffer_parse(ring,
+						      &shadow_exec_entry,
+						      eb,
+						      batch_obj,
+						      args->batch_start_offset,
+						      args->batch_len,
+						      file->is_master,
+						      &flags);
+		if (IS_ERR(batch_obj)) {
+			ret = PTR_ERR(batch_obj);
  			goto err;
-
-		ret = i915_parse_cmds(ring,
-				      batch_obj,
-				      shadow_batch_obj,
-				      args->batch_start_offset,
-				      args->batch_len,
-				      file->is_master);
-		i915_gem_object_ggtt_unpin(shadow_batch_obj);
-
-		if (ret) {
-			if (ret != -EACCES)
-				goto err;
-		} else {
-			struct i915_vma *vma;
-
-			memset(&shadow_exec_entry, 0,
-			       sizeof(shadow_exec_entry));
-
-			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
-			vma->exec_entry = &shadow_exec_entry;
-			vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
-			drm_gem_object_reference(&shadow_batch_obj->base);
-			list_add_tail(&vma->exec_list, &eb->vmas);
-
-			shadow_batch_obj->base.pending_read_domains =
-				batch_obj->base.pending_read_domains;
-
-			batch_obj = shadow_batch_obj;
-
-			/*
-			 * Set the DISPATCH_SECURE bit to remove the NON_SECURE
-			 * bit from MI_BATCH_BUFFER_START commands issued in the
-			 * dispatch_execbuffer implementations. We specifically
-			 * don't want that set when the command parser is
-			 * enabled.
-			 *
-			 * FIXME: with aliasing ppgtt, buffers that should only
-			 * be in ggtt still end up in the aliasing ppgtt. remove
-			 * this check when that is fixed.
-			 */
-			if (USES_FULL_PPGTT(dev))
-				flags |= I915_DISPATCH_SECURE;
  		}
  	}
 
Quoted 8 lines
Quoted 7 lines

--
1.9.1

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

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

#19 lore raw

Re: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

In reply to [email protected]
Quoted 91 lines

-----Original Message-----
From: Nguyen, Michael H
Sent: Monday, December 08, 2014 10:34 PM
To: [email protected]
Cc: Bloomfield, Jon; Brad Volkin
Subject: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

From: Brad Volkin <[email protected]>

Move it to a separate function since the main do_execbuffer function already has so much going on.

v2:
- Move pin/unpin calls inside i915_parse_cmds() (Chris W, v4 7/7 feedback)

Issue: VIZ-4719

Conflicts:

	drivers/gpu/drm/i915/i915_gem_execbuffer.c
---
 drivers/gpu/drm/i915/i915_cmd_parser.c     |   8 ++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 126 ++++++++++++++++---
----------
 2 files changed, 77 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +0 -0
index 118079d..80b1b28 100644
@@ -1042,10 +1042,17 @@ int i915_parse_cmds(struct intel_engine_cs
 *ring,
 	struct drm_i915_cmd_descriptor default_desc = { 0 };
 	bool oacontrol_set = false; /* OACONTROL tracking. See

check_cmd() */

drivers/gpu/drm/i915/i915_cmd_parser.c +8 -0
+	ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: Failed to pin shadow batch\n");
+		return -1;
+	}
+
 	batch_base = copy_batch(shadow_batch_obj, batch_obj,
 				batch_start_offset, batch_len);
 	if (IS_ERR(batch_base)) {
 		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
+		i915_gem_object_ggtt_unpin(shadow_batch_obj);
 		return PTR_ERR(batch_base);
 	}
@@ -1116,6 +1123,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
 	}
 
 	vunmap(batch_base);
+	i915_gem_object_ggtt_unpin(shadow_batch_obj);
 
 	return ret;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +18 -0
index 2071938..3d36465 100644
@@ -1069,6 +1069,65 @@ i915_emit_box(struct intel_engine_cs *ring,
 	return 0;
 }
 
+static struct drm_i915_gem_object*
+i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
+			  struct drm_i915_gem_exec_object2
 *shadow_exec_entry,
+			  struct eb_vmas *eb,
+			  struct drm_i915_gem_object *batch_obj,
+			  u32 batch_start_offset,
+			  u32 batch_len,
+			  bool is_master,
+			  u32 *flags)
+{
+	struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev);
+	struct drm_i915_gem_object *shadow_batch_obj;
+	int ret;
+
+	shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv-
 >mm.batch_pool,
+						   batch_obj->base.size);
+	if (IS_ERR(shadow_batch_obj))
+		return shadow_batch_obj;

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_emit_box(struct intel_engine_cs *ring, · line 1101

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -0
+
+	ret = i915_parse_cmds(ring,
+			      batch_obj,
+			      shadow_batch_obj,
+			      batch_start_offset,
+			      batch_len,
+			      is_master);
+	if (ret) {
+		if (ret == -EACCES)
+			return batch_obj;

Shouldn't this be returning an error code ?

Quoted 127 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +16 -0
+	} else {
+		struct i915_vma *vma;
+
+		memset(shadow_exec_entry, 0,
 sizeof(*shadow_exec_entry));
+
+		vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
+		vma->exec_entry = shadow_exec_entry;
+		vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
+		drm_gem_object_reference(&shadow_batch_obj->base);
+		list_add_tail(&vma->exec_list, &eb->vmas);
+
+		shadow_batch_obj->base.pending_read_domains =
+			batch_obj->base.pending_read_domains;
+
+		/*
+		 * Set the DISPATCH_SECURE bit to remove the

NON_SECURE

drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
+		 * bit from MI_BATCH_BUFFER_START commands issued in

the

drivers/gpu/drm/i915/i915_gem_execbuffer.c +13 -0
+		 * dispatch_execbuffer implementations. We specifically
+		 * don't want that set when the command parser is
+		 * enabled.
+		 *
+		 * FIXME: with aliasing ppgtt, buffers that should only
+		 * be in ggtt still end up in the aliasing ppgtt. remove
+		 * this check when that is fixed.
+		 */
+		if (USES_FULL_PPGTT(dev))
+			*flags |= I915_DISPATCH_SECURE;
+	}
+
+	return ret ? ERR_PTR(ret) : shadow_batch_obj; }
 
 int
 i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file

*file, @@ -1286,7 +1345,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,

drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -37
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct eb_vmas *eb;
 	struct drm_i915_gem_object *batch_obj;
-	struct drm_i915_gem_object *shadow_batch_obj = NULL;
 	struct drm_i915_gem_exec_object2 shadow_exec_entry;
 	struct intel_engine_cs *ring;
 	struct intel_context *ctx;
@@ -1406,63 +1464,17 @@ i915_gem_do_execbuffer(struct drm_device
 *dev, void *data,
 	}
 
 	if (i915_needs_cmd_parser(ring)) {
-		shadow_batch_obj =
-			i915_gem_batch_pool_get(&dev_priv-
 >mm.batch_pool,
-						batch_obj->base.size);
-		if (IS_ERR(shadow_batch_obj)) {
-			ret = PTR_ERR(shadow_batch_obj);
-			/* Don't try to clean up the obj in the error path */
-			shadow_batch_obj = NULL;
-			goto err;
-		}
-
-		shadow_batch_obj->madv = I915_MADV_WILLNEED;
-
-		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
-		if (ret)
+		batch_obj = i915_gem_execbuffer_parse(ring,
+						      &shadow_exec_entry,
+						      eb,
+						      batch_obj,
+						      args->batch_start_offset,
+						      args->batch_len,
+						      file->is_master,
+						      &flags);
+		if (IS_ERR(batch_obj)) {
+			ret = PTR_ERR(batch_obj);
 			goto err;
-
-		ret = i915_parse_cmds(ring,
-				      batch_obj,
-				      shadow_batch_obj,
-				      args->batch_start_offset,
-				      args->batch_len,
-				      file->is_master);
-		i915_gem_object_ggtt_unpin(shadow_batch_obj);
-
-		if (ret) {
-			if (ret != -EACCES)
-				goto err;
-		} else {
-			struct i915_vma *vma;
-
-			memset(&shadow_exec_entry, 0,
-			       sizeof(shadow_exec_entry));
-
-			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
-			vma->exec_entry = &shadow_exec_entry;
-			vma->exec_entry->flags =
 __EXEC_OBJECT_PURGEABLE;
-			drm_gem_object_reference(&shadow_batch_obj-
Quoted 1 line

base);

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -9
-			list_add_tail(&vma->exec_list, &eb->vmas);
-
-			shadow_batch_obj->base.pending_read_domains =
-				batch_obj->base.pending_read_domains;
-
-			batch_obj = shadow_batch_obj;
-
-			/*
-			 * Set the DISPATCH_SECURE bit to remove the

NON_SECURE

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -1
-			 * bit from MI_BATCH_BUFFER_START commands

issued in the

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -1
-			 * dispatch_execbuffer implementations. We

specifically

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -10
-			 * don't want that set when the command parser is
-			 * enabled.
-			 *
-			 * FIXME: with aliasing ppgtt, buffers that should only
-			 * be in ggtt still end up in the aliasing ppgtt. remove
-			 * this check when that is fixed.
-			 */
-			if (USES_FULL_PPGTT(dev))
-				flags |= I915_DISPATCH_SECURE;
 		}
 	}
 
--
Quoted 1 line

1.9.1

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

#20 lore raw

Re: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

Quoted 88 lines · Jon
Quoted 88 lines

-----Original Message-----
From: Nguyen, Michael H
Sent: Monday, December 08, 2014 10:34 PM
To: [email protected]
Cc: Bloomfield, Jon; Brad Volkin
Subject: [PATCH v6 5/5] drm/i915: Tidy up execbuffer command parsing code

From: Brad Volkin <[email protected]>

Move it to a separate function since the main do_execbuffer function already has so much going on.

v2:
- Move pin/unpin calls inside i915_parse_cmds() (Chris W, v4 7/7 feedback)

Issue: VIZ-4719

Conflicts:

	drivers/gpu/drm/i915/i915_gem_execbuffer.c
---
  drivers/gpu/drm/i915/i915_cmd_parser.c     |   8 ++
  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 126 ++++++++++++++++---
----------
  2 files changed, 77 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +0 -0
index 118079d..80b1b28 100644
@@ -1042,10 +1042,17 @@ int i915_parse_cmds(struct intel_engine_cs
 *ring,
  	struct drm_i915_cmd_descriptor default_desc = { 0 };
  	bool oacontrol_set = false; /* OACONTROL tracking. See

check_cmd() */

drivers/gpu/drm/i915/i915_cmd_parser.c +8 -0
+	ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
+	if (ret) {
+		DRM_DEBUG_DRIVER("CMD: Failed to pin shadow batch\n");
+		return -1;
+	}
+
  	batch_base = copy_batch(shadow_batch_obj, batch_obj,
  				batch_start_offset, batch_len);
  	if (IS_ERR(batch_base)) {
  		DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
+		i915_gem_object_ggtt_unpin(shadow_batch_obj);
  		return PTR_ERR(batch_base);
  	}
@@ -1116,6 +1123,7 @@ int i915_parse_cmds(struct intel_engine_cs *ring,
  	}
 
  	vunmap(batch_base);
+	i915_gem_object_ggtt_unpin(shadow_batch_obj);
 
  	return ret;
  }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +15 -0
index 2071938..3d36465 100644
@@ -1069,6 +1069,65 @@ i915_emit_box(struct intel_engine_cs *ring,
  	return 0;
  }
 
+static struct drm_i915_gem_object*
+i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
+			  struct drm_i915_gem_exec_object2
 *shadow_exec_entry,
+			  struct eb_vmas *eb,
+			  struct drm_i915_gem_object *batch_obj,
+			  u32 batch_start_offset,
+			  u32 batch_len,
+			  bool is_master,
+			  u32 *flags)
+{
+	struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev);
+	struct drm_i915_gem_object *shadow_batch_obj;
+	int ret;
+
+	shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv-
 > mm.batch_pool,
Quoted 15 lines

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_emit_box(struct intel_engine_cs *ring, · line 1099

Quoted 13 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +13 -0
+						   batch_obj->base.size);
+	if (IS_ERR(shadow_batch_obj))
+		return shadow_batch_obj;
+
+	ret = i915_parse_cmds(ring,
+			      batch_obj,
+			      shadow_batch_obj,
+			      batch_start_offset,
+			      batch_len,
+			      is_master);
+	if (ret) {
+		if (ret == -EACCES)
+			return batch_obj;

Shouldn't this be returning an error code ?

Good question. -EACCESS tells the caller of i915_parse_cmds() of a special case. There are some comments in its fnc header and implementation.

-EACCESS indicates that batch_obj contains a chained batch in which case we dispatch batch_obj as non-secure. We return batch_obj here b/c the logic below doesn't apply. I believe the reason we safely dispatch chained batches as non-secure is b/c Brad and others probably determined that there weren't any valid use cases where chained batches needed to be dispatched as secure. Leaving them non-secure, HW will NOP bad cmds and its not necessary for i915 to do parsing.

Thanks,
Mike

Quoted 129 lines
Quoted 129 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +16 -0
+	} else {
+		struct i915_vma *vma;
+
+		memset(shadow_exec_entry, 0,
 sizeof(*shadow_exec_entry));
+
+		vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
+		vma->exec_entry = shadow_exec_entry;
+		vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
+		drm_gem_object_reference(&shadow_batch_obj->base);
+		list_add_tail(&vma->exec_list, &eb->vmas);
+
+		shadow_batch_obj->base.pending_read_domains =
+			batch_obj->base.pending_read_domains;
+
+		/*
+		 * Set the DISPATCH_SECURE bit to remove the

NON_SECURE

drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
+		 * bit from MI_BATCH_BUFFER_START commands issued in

the

drivers/gpu/drm/i915/i915_gem_execbuffer.c +13 -0
+		 * dispatch_execbuffer implementations. We specifically
+		 * don't want that set when the command parser is
+		 * enabled.
+		 *
+		 * FIXME: with aliasing ppgtt, buffers that should only
+		 * be in ggtt still end up in the aliasing ppgtt. remove
+		 * this check when that is fixed.
+		 */
+		if (USES_FULL_PPGTT(dev))
+			*flags |= I915_DISPATCH_SECURE;
+	}
+
+	return ret ? ERR_PTR(ret) : shadow_batch_obj; }
 
  int
  i915_gem_ringbuffer_submission(struct drm_device *dev, struct drm_file

*file, @@ -1286,7 +1345,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
struct drm_i915_private *dev_priv = dev->dev_private; struct eb_vmas *eb;
struct drm_i915_gem_object *batch_obj;

drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -37
-	struct drm_i915_gem_object *shadow_batch_obj = NULL;
  	struct drm_i915_gem_exec_object2 shadow_exec_entry;
  	struct intel_engine_cs *ring;
  	struct intel_context *ctx;
@@ -1406,63 +1464,17 @@ i915_gem_do_execbuffer(struct drm_device
 *dev, void *data,
  	}
 
  	if (i915_needs_cmd_parser(ring)) {
-		shadow_batch_obj =
-			i915_gem_batch_pool_get(&dev_priv-
 > mm.batch_pool,
-						batch_obj->base.size);
-		if (IS_ERR(shadow_batch_obj)) {
-			ret = PTR_ERR(shadow_batch_obj);
-			/* Don't try to clean up the obj in the error path */
-			shadow_batch_obj = NULL;
-			goto err;
-		}
-
-		shadow_batch_obj->madv = I915_MADV_WILLNEED;
-
-		ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 4096, 0);
-		if (ret)
+		batch_obj = i915_gem_execbuffer_parse(ring,
+						      &shadow_exec_entry,
+						      eb,
+						      batch_obj,
+						      args->batch_start_offset,
+						      args->batch_len,
+						      file->is_master,
+						      &flags);
+		if (IS_ERR(batch_obj)) {
+			ret = PTR_ERR(batch_obj);
  			goto err;
-
-		ret = i915_parse_cmds(ring,
-				      batch_obj,
-				      shadow_batch_obj,
-				      args->batch_start_offset,
-				      args->batch_len,
-				      file->is_master);
-		i915_gem_object_ggtt_unpin(shadow_batch_obj);
-
-		if (ret) {
-			if (ret != -EACCES)
-				goto err;
-		} else {
-			struct i915_vma *vma;
-
-			memset(&shadow_exec_entry, 0,
-			       sizeof(shadow_exec_entry));
-
-			vma = i915_gem_obj_to_ggtt(shadow_batch_obj);
-			vma->exec_entry = &shadow_exec_entry;
-			vma->exec_entry->flags =
 __EXEC_OBJECT_PURGEABLE;
-			drm_gem_object_reference(&shadow_batch_obj-
Quoted 1 line

base);

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -9
-			list_add_tail(&vma->exec_list, &eb->vmas);
-
-			shadow_batch_obj->base.pending_read_domains =
-				batch_obj->base.pending_read_domains;
-
-			batch_obj = shadow_batch_obj;
-
-			/*
-			 * Set the DISPATCH_SECURE bit to remove the

NON_SECURE

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -1
-			 * bit from MI_BATCH_BUFFER_START commands

issued in the

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -1
-			 * dispatch_execbuffer implementations. We

specifically

drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -9
-			 * don't want that set when the command parser is
-			 * enabled.
-			 *
-			 * FIXME: with aliasing ppgtt, buffers that should only
-			 * be in ggtt still end up in the aliasing ppgtt. remove
-			 * this check when that is fixed.
-			 */
-			if (USES_FULL_PPGTT(dev))
-				flags |= I915_DISPATCH_SECURE;
  		}
  	}
Quoted 3 lines
Quoted 2 lines

--
1.9.1

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