Skip to contentSkip to conversation

Extending GET_APERTURE ioctl

PATCH In review [email protected] 3 participants 12 messages Jul 8, 2015

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

v3 cover Extending GET_APERTURE ioctl

From: Ankitprasad Sharma <[email protected]>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

This set of patches extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

This is not quite what userspace wants to answer the question of whether this batch will fit as fences are also required to meet severe alignment constraints within the batch. For this purpose, a third conservative estimate of largest fence available is also provided. For when userspace needs more than one batch, we also provide the culmulative space available for fences such that it has some additional guidance to how much space it could allocate to fences. Conservatism still wins.

The patches also support for getting total size and available size of the stolen region as well as single largest block available in the stolen region.

It also adds a debugfs file for convenient testing and reporting.

v2: Rebased to the latest drm-intel-nightly

v3: Fixed compilation error

Ankitprasad Sharma (1):
drm/i915: Extend GET_APERTURE ioctl to report size of the stolen
region

Rodrigo Vivi (1):
drm/i915: Extend GET_APERTURE ioctl to report available map space

 drivers/gpu/drm/i915/i915_debugfs.c    |  33 +++++++++
 drivers/gpu/drm/i915/i915_drv.h        |   3 +
 drivers/gpu/drm/i915/i915_gem.c        | 123 +++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/i915_gem_stolen.c |  35 ++++++++++
 include/uapi/drm/i915_drm.h            |  40 +++++++++++
 5 files changed, 230 insertions(+), 4 deletions(-)
Signature · 6 lines
1.9.1

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

PATCH v3 1/2 drm/i915: Extend GET_APERTURE ioctl to report available map space

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

This is not quite what userspace wants to answer the question of whether this batch will fit as fences are also required to meet severe alignment constraints within the batch. For this purpose, a third conservative estimate of largest fence available is also provided. For when userspace needs more than one batch, we also provide the culmulative space available for fences such that it has some additional guidance to how much space it could allocate to fences. Conservatism still wins.

The patch also adds a debugfs file for convenient testing and reporting.

v2: The first object cannot end at offset 0, so we can use last==0 to detect the empty list.

v3: Expand all values to 64bit, just in case.
Report total mappable aperture size for userspace that cannot easily determine it by inspecting the PCI device.

v4: (Rodrigo) Fixed rebase conflicts.

Signed-off-by Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by Rodrigo Vivi <rodrigo.vivi at intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c |  27 +++++++++
 drivers/gpu/drm/i915/i915_gem.c     | 116 ++++++++++++++++++++++++++++++++++--
 include/uapi/drm/i915_drm.h         |  25 ++++++++
 3 files changed, 164 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +27 -0
index 31d8768..49ec438 100644
@@ -512,6 +512,32 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 	return 0;
 }
 
+static int i915_gem_aperture_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = m->private;
+	struct drm_i915_gem_get_aperture arg;
+	int ret;
+
+	ret = i915_gem_get_aperture_ioctl(node->minor->dev, &arg, NULL);
+	if (ret)
+		return ret;
+
+	seq_printf(m, "Total size of the GTT: %llu bytes\n",
+		   arg.aper_size);
+	seq_printf(m, "Available space in the GTT: %llu bytes\n",
+		   arg.aper_available_size);
+	seq_printf(m, "Available space in the mappable aperture: %llu bytes\n",
+		   arg.map_available_size);
+	seq_printf(m, "Single largest space in the mappable aperture: %llu bytes\n",
+		   arg.map_largest_size);
+	seq_printf(m, "Available space for fences: %llu bytes\n",
+		   arg.fence_available_size);
+	seq_printf(m, "Single largest fence available: %llu bytes\n",
+		   arg.fence_largest_size);
+
+	return 0;
+}
+
 static int i915_gem_gtt_info(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = m->private;
@@ -5030,6 +5056,7 @@ static int i915_debugfs_create(struct dentry *root,
 static const struct drm_info_list i915_debugfs_list[] = {
 	{"i915_capabilities", i915_capabilities, 0},
 	{"i915_gem_objects", i915_gem_object_info, 0},
+	{"i915_gem_aperture", i915_gem_aperture_info, 0},
 	{"i915_gem_gtt", i915_gem_gtt_info, 0},
 	{"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
 	{"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
drivers/gpu/drm/i915/i915_gem.c +112 -4

141 lines not on this page · raw message

include/uapi/drm/i915_drm.h +25 -0
index f88cc1c..3e7f4a3 100644
@@ -922,6 +922,31 @@ struct drm_i915_gem_get_aperture {
 	 * bytes
 	 */
 	__u64 aper_available_size;
+
+	/**
+	 * Total space in the mappable region of the aperture, in bytes
+	 */
+	__u64 map_total_size;
+
+	/**
+	 * Available space in the mappable region of the aperture, in bytes
+	 */
+	__u64 map_available_size;
+
+	/**
+	 * Single largest available region inside the mappable region, in bytes.
+	 */
+	__u64 map_largest_size;
+
+	/**
+	 * Culmulative space available for fences, in bytes
+	 */
+	__u64 fence_available_size;
+
+	/**
+	 * Single largest fenceable region, in bytes.
+	 */
+	__u64 fence_largest_size;
 };
 
 struct drm_i915_get_pipe_from_crtc_id {
Signature · 6 lines
1.9.1

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

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

Hi,

Quoted 8 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

Quoted 4 lines

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Quoted 90 lines

This is not quite what userspace wants to answer the question of whether this batch will fit as fences are also required to meet severe alignment constraints within the batch. For this purpose, a third conservative estimate of largest fence available is also provided. For when userspace needs more than one batch, we also provide the culmulative space available for fences such that it has some additional guidance to how much space it could allocate to fences. Conservatism still wins.

The patch also adds a debugfs file for convenient testing and reporting.

v2: The first object cannot end at offset 0, so we can use last==0 to detect the empty list.

v3: Expand all values to 64bit, just in case.
Report total mappable aperture size for userspace that cannot easily determine it by inspecting the PCI device.

v4: (Rodrigo) Fixed rebase conflicts.

Signed-off-by Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by Rodrigo Vivi <rodrigo.vivi at intel.com>
---
  drivers/gpu/drm/i915/i915_debugfs.c |  27 +++++++++
  drivers/gpu/drm/i915/i915_gem.c     | 116 ++++++++++++++++++++++++++++++++++--
  include/uapi/drm/i915_drm.h         |  25 ++++++++
  3 files changed, 164 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +27 -0
index 31d8768..49ec438 100644
@@ -512,6 +512,32 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
  	return 0;
  }
 
+static int i915_gem_aperture_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = m->private;
+	struct drm_i915_gem_get_aperture arg;
+	int ret;
+
+	ret = i915_gem_get_aperture_ioctl(node->minor->dev, &arg, NULL);
+	if (ret)
+		return ret;
+
+	seq_printf(m, "Total size of the GTT: %llu bytes\n",
+		   arg.aper_size);
+	seq_printf(m, "Available space in the GTT: %llu bytes\n",
+		   arg.aper_available_size);
+	seq_printf(m, "Available space in the mappable aperture: %llu bytes\n",
+		   arg.map_available_size);
+	seq_printf(m, "Single largest space in the mappable aperture: %llu bytes\n",
+		   arg.map_largest_size);
+	seq_printf(m, "Available space for fences: %llu bytes\n",
+		   arg.fence_available_size);
+	seq_printf(m, "Single largest fence available: %llu bytes\n",
+		   arg.fence_largest_size);
+
+	return 0;
+}
+
  static int i915_gem_gtt_info(struct seq_file *m, void *data)
  {
  	struct drm_info_node *node = m->private;
@@ -5030,6 +5056,7 @@ static int i915_debugfs_create(struct dentry *root,
  static const struct drm_info_list i915_debugfs_list[] = {
  	{"i915_capabilities", i915_capabilities, 0},
  	{"i915_gem_objects", i915_gem_object_info, 0},
+	{"i915_gem_aperture", i915_gem_aperture_info, 0},
  	{"i915_gem_gtt", i915_gem_gtt_info, 0},
  	{"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
  	{"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
drivers/gpu/drm/i915/i915_gem.c +3 -0
index a2a4a27..ccfc8d3 100644
@@ -32,6 +32,7 @@
  #include "i915_vgpu.h"
  #include "i915_trace.h"
  #include "intel_drv.h"
+#include <linux/list_sort.h>
  #include <linux/shmem_fs.h>
  #include <linux/slab.h>
  #include <linux/swap.h>
@@ -143,6 +144,55 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
  	return 0;
  }
 
+static inline bool
+i915_gem_object_is_inactive(struct drm_i915_gem_object *obj)

drivers/gpu/drm/i915/i915_gem.c int i915_mutex_lock_interruptible(struct drm_device *dev) · line 158

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+{
+	return i915_gem_obj_bound_any(obj) && !obj->active;
+}
+
+static int obj_rank_by_ggtt(void *priv,
+			    struct list_head *A,
+			    struct list_head *B)
+{
+	struct drm_i915_gem_object *a = list_entry(A,typeof(*a), obj_exec_link);
+	struct drm_i915_gem_object *b = list_entry(B,typeof(*b), obj_exec_link);

Nitpick - space after comma.

Quoted 21 lines
drivers/gpu/drm/i915/i915_gem.c +21 -0
+
+	return i915_gem_obj_ggtt_offset(a) - i915_gem_obj_ggtt_offset(b);
+}
+
+static u32 __fence_size(struct drm_i915_private *dev_priv, u32 start, u32 end)
+{
+	u32 size = end - start;
+	u32 fence_size;
+
+	if (INTEL_INFO(dev_priv)->gen < 4) {
+		u32 fence_max;
+		u32 fence_next;
+
+		if (IS_GEN3(dev_priv)) {
+			fence_max = I830_FENCE_MAX_SIZE_VAL << 20;
+			fence_next = 1024*1024;
+		} else {
+			fence_max = I830_FENCE_MAX_SIZE_VAL << 19;
+			fence_next = 512*1024;
+		}
+

drivers/gpu/drm/i915/i915_gem.c int i915_mutex_lock_interruptible(struct drm_device *dev) · line 189

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+		fence_max = min(fence_max, size);
+		fence_size = 0;
+		while (fence_next <= fence_max) {
+			u32 base = ALIGN(start, fence_next);
+			if (base + fence_next > end)
+				break;
+
+			fence_size = fence_next;
+			fence_next <<= 1;
+		}

I don't know a lot about fence alignment and size restrictions but since this loop is relatively complex could use a comment on what it is doing.

drivers/gpu/drm/i915/i915_gem.c int i915_mutex_lock_interruptible(struct drm_device *dev) · line 191

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +2 -0
+	} else
+		fence_size = size;

I think coding style is for all if/else branches to have braces if one has - feel free to correct me if I am wrong.

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +4 -0
+
+	return fence_size;
+}
+
  int
  i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  			    struct drm_file *file)

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

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +2 -1
@@ -150,17 +200,75 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  	struct drm_i915_private *dev_priv = dev->dev_private;
  	struct drm_i915_gem_get_aperture *args = data;
  	struct drm_i915_gem_object *obj;
-	size_t pinned;
+	struct list_head map_list;
+	const u32 map_limit = dev_priv->gtt.mappable_end;

mappable_end is u64 so gcc should complain here.

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

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +2 -0
+	size_t pinned, map_space, map_largest, fence_space, fence_largest;
+	u32 last, size;

And since the ongoing push to standardize all GTT size variables to u64 I think you'l have to change the above as well.

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

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +5 -3
+
+	INIT_LIST_HEAD(&map_list);
 
  	pinned = 0;
+	map_space = map_largest = 0;
+	fence_space = fence_largest = 0;
+
  	mutex_lock(&dev->struct_mutex);
-	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
-		if (i915_gem_obj_is_pinned(obj))
-			pinned += i915_gem_obj_ggtt_size(obj);

Unfortunately you will have to rebase this again since someone managed to change it in the meantime. Ooops it was me - sorry! :)

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

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +2 -0
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
+		struct i915_vma *vma = i915_gem_obj_to_ggtt(obj);

The issue with this is it ignores rotated and partial VMA types so will give wrong numbers. Rebasing should take care of it.

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

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +11 -0
+		if (vma == NULL || !vma->pin_count)
+			continue;
+
+		pinned += vma->node.size;
+
+		if (vma->node.start < map_limit)
+			list_add(&obj->obj_exec_link, &map_list);
+	}
+
+	last = 0;
+	list_sort(NULL, &map_list, obj_rank_by_ggtt);

I suppose the problems really start with the compare function here. Since you store objects in the list and not VMAs, compare can't know which are the correct VMAs to use.

Are there any free list_heads in the VMA you could use? vma->exec_list looks like it could be used. (Please verify :)

That would make map_list store VMAs and compare function can be change to use vma->node.start then (and work with normal/rotated/partial views).

Regards,

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

#3 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

Quoted 12 lines · Tvrtko Ursulin

Hi,

Quoted 8 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

Quoted 8 lines
Quoted 4 lines

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Yes. My use case is actually after a failure to capture debug information. I don't anticipate frequent calls to get_aperture (usually just a single call during early init).
-Chrs

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

Quoted 18 lines · Chris Wilson
Quoted 17 lines · Tvrtko Ursulin

Hi,

Quoted 12 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Quoted 7 lines
Quoted 3 lines

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Yes. My use case is actually after a failure to capture debug information. I don't anticipate frequent calls to get_aperture (usually just a single call during early init).

Should it better go to debugfs then?

Regards,

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

#5 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

Quoted 24 lines · Tvrtko Ursulin
Quoted 22 lines · Chris Wilson
Quoted 20 lines · Tvrtko Ursulin

Hi,

Quoted 8 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

Quoted 4 lines

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Quoted 5 lines
Quoted 3 lines

Yes. My use case is actually after a failure to capture debug information. I don't anticipate frequent calls to get_aperture (usually just a single call during early init).

Should it better go to debugfs then?

Hmm, I could accept that. In such a scenario, I would suggest we ignore the avail_aperture_space field all together, just report it as max (or whatever) and simply add fields for max stolen, max mappable, max ggtt (already present) and max ppgtt. (Rather than continue trying to kill multiple birds with one stone, where 99.9% of users don't want the overhead.)

Move the current patch series into debugfs.c and just add the limits to get_aperture?
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

Quoted 38 lines · Chris Wilson
Quoted 24 lines · Tvrtko Ursulin
Quoted 22 lines · Chris Wilson
Quoted 20 lines · Tvrtko Ursulin

Hi,

Quoted 8 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

Quoted 4 lines

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Quoted 5 lines
Quoted 3 lines

Yes. My use case is actually after a failure to capture debug information. I don't anticipate frequent calls to get_aperture (usually just a single call during early init).

Should it better go to debugfs then?

Hmm, I could accept that. In such a scenario, I would suggest we ignore the avail_aperture_space field all together, just report it as max (or whatever) and simply add fields for max stolen, max mappable, max ggtt (already present) and max ppgtt. (Rather than continue trying to kill multiple birds with one stone, where 99.9% of users don't want the overhead.)

Quoted 2 lines

Move the current patch series into debugfs.c and just add the limits to get_aperture?

It would make a more sensible ioctl if you think we could get away with it. Hopefully no userspace tries to do anything smart with aper_available_size today? I see one IGT user, gem_ctx_exec, which probably isn't a blocker.

In that case for stolen we would add:

stolen_size = dev_priv->gtt.stolen_size
stolen_available = stolen_size - bios_reserved

(Bios_reserved would have to be stored in i915_gtt since it is currently local to i915_gem_init_stolen.)

Plus the ones you listed, mappable_size and ppgtt_size.

And the used/largest/fence/... ones go to debugfs.

Regards,

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

#7 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

Quoted 40 lines · Tvrtko Ursulin
Quoted 38 lines · Chris Wilson
Quoted 24 lines · Tvrtko Ursulin
Quoted 22 lines · Chris Wilson
Quoted 20 lines · Tvrtko Ursulin

Hi,

Quoted 8 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

Quoted 4 lines

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Quoted 5 lines
Quoted 3 lines

Yes. My use case is actually after a failure to capture debug information. I don't anticipate frequent calls to get_aperture (usually just a single call during early init).

Should it better go to debugfs then?

Hmm, I could accept that. In such a scenario, I would suggest we ignore the avail_aperture_space field all together, just report it as max (or whatever) and simply add fields for max stolen, max mappable, max ggtt (already present) and max ppgtt. (Rather than continue trying to kill multiple birds with one stone, where 99.9% of users don't want the overhead.)

Quoted 7 lines
Quoted 2 lines

Move the current patch series into debugfs.c and just add the limits to get_aperture?

It would make a more sensible ioctl if you think we could get away with it. Hopefully no userspace tries to do anything smart with aper_available_size today? I see one IGT user, gem_ctx_exec, which probably isn't a blocker.

Now that you mention it, we lie anyway there. The idea behind gem_ctx_exec is try and guage how much remaining global gtt space we need to fill with context objects - but important reservations of global gtt aren't even subtracted from the avail aperture space.

There's also a use in sna when we run very close to the limit, we double check if the available space is enough. That's semi-sensible, certainly for the gen2-3 system that hit it most.

Ok, so we get to keep aper_available_size.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

In reply to Chris Wilson
Quoted 18 lines · Chris Wilson
Quoted 17 lines · Tvrtko Ursulin

Hi,

Quoted 12 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

Quoted 7 lines
Quoted 3 lines

Since whatever this returns is a transient number is this really that useful? There are no guarantees that by the time caller tries to act on it it will still be valid.

Yes. My use case is actually after a failure to capture debug information. I don't anticipate frequent calls to get_aperture (usually just a single call during early init).

Though that predates full-ppgtt (and even the recent aliasing-ppgtt split). Time to start thinking about doing something similar for contexts.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

Re: [PATCH 1/2] drm/i915: Extend GET_APERTURE ioctl to report available map space

In reply to [email protected]
Quoted 98 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Rodrigo Vivi <rodrigo.vivi at intel.com>

When constructing a batchbuffer, it is sometimes crucial to know the largest hole into which we can fit a fenceable buffer (for example when handling very large objects on gen2 and gen3). This depends on the fragmentation of pinned buffers inside the aperture, a question only the kernel can easily answer.

This patch extends the current DRM_I915_GEM_GET_APERTURE ioctl to include a couple of new fields in its reply to userspace - the total amount of space available in the mappable region of the aperture and also the single largest block available.

This is not quite what userspace wants to answer the question of whether this batch will fit as fences are also required to meet severe alignment constraints within the batch. For this purpose, a third conservative estimate of largest fence available is also provided. For when userspace needs more than one batch, we also provide the culmulative space available for fences such that it has some additional guidance to how much space it could allocate to fences. Conservatism still wins.

The patch also adds a debugfs file for convenient testing and reporting.

v2: The first object cannot end at offset 0, so we can use last==0 to detect the empty list.

v3: Expand all values to 64bit, just in case.
Report total mappable aperture size for userspace that cannot easily determine it by inspecting the PCI device.

v4: (Rodrigo) Fixed rebase conflicts.

Signed-off-by Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by Rodrigo Vivi <rodrigo.vivi at intel.com>
---
  drivers/gpu/drm/i915/i915_debugfs.c |  27 +++++++++
  drivers/gpu/drm/i915/i915_gem.c     | 116 ++++++++++++++++++++++++++++++++++--
  include/uapi/drm/i915_drm.h         |  25 ++++++++
  3 files changed, 164 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +27 -0
index 31d8768..49ec438 100644
@@ -512,6 +512,32 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
  	return 0;
  }
 
+static int i915_gem_aperture_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = m->private;
+	struct drm_i915_gem_get_aperture arg;
+	int ret;
+
+	ret = i915_gem_get_aperture_ioctl(node->minor->dev, &arg, NULL);
+	if (ret)
+		return ret;
+
+	seq_printf(m, "Total size of the GTT: %llu bytes\n",
+		   arg.aper_size);
+	seq_printf(m, "Available space in the GTT: %llu bytes\n",
+		   arg.aper_available_size);
+	seq_printf(m, "Available space in the mappable aperture: %llu bytes\n",
+		   arg.map_available_size);
+	seq_printf(m, "Single largest space in the mappable aperture: %llu bytes\n",
+		   arg.map_largest_size);
+	seq_printf(m, "Available space for fences: %llu bytes\n",
+		   arg.fence_available_size);
+	seq_printf(m, "Single largest fence available: %llu bytes\n",
+		   arg.fence_largest_size);
+
+	return 0;
+}
+
  static int i915_gem_gtt_info(struct seq_file *m, void *data)
  {
  	struct drm_info_node *node = m->private;
@@ -5030,6 +5056,7 @@ static int i915_debugfs_create(struct dentry *root,
  static const struct drm_info_list i915_debugfs_list[] = {
  	{"i915_capabilities", i915_capabilities, 0},
  	{"i915_gem_objects", i915_gem_object_info, 0},
+	{"i915_gem_aperture", i915_gem_aperture_info, 0},
  	{"i915_gem_gtt", i915_gem_gtt_info, 0},
  	{"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
  	{"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
drivers/gpu/drm/i915/i915_gem.c +1 -0
index a2a4a27..ccfc8d3 100644
@@ -32,6 +32,7 @@
  #include "i915_vgpu.h"
  #include "i915_trace.h"
  #include "intel_drv.h"
+#include <linux/list_sort.h>
  #include <linux/shmem_fs.h>
  #include <linux/slab.h>
  #include <linux/swap.h>

drivers/gpu/drm/i915/i915_gem.c int i915_mutex_lock_interruptible(struct drm_device *dev) · line 151

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
@@ -143,6 +144,55 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
  	return 0;
  }
 
+static inline bool
+i915_gem_object_is_inactive(struct drm_i915_gem_object *obj)
+{
+	return i915_gem_obj_bound_any(obj) && !obj->active;
+}

Oh and this function is not used.

Regards,

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

#10 lore raw

PATCH v3 2/2 drm/i915: Extend GET_APERTURE ioctl to report size of the stolen region

In reply to [email protected]

From: Ankitprasad Sharma <[email protected]>

This patch extends the GET_APERTURE ioctl to add support for getting total size and available size of the stolen region as well as single largest block available in the stolen region. Also adds debugfs support to retieve the size information of the stolen area.

v2: respinned over Rodrigo's patch which extends the GET_APERTURE too. Used drm_mm to get the size information of the stolen region (Chris)
Added debugfs support for testing (Ankit)

v3: Rebased to the latest drm-intel-nightly (Ankit)

Reviewed-by Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_debugfs.c    |  6 ++++++
 drivers/gpu/drm/i915/i915_drv.h        |  3 +++
 drivers/gpu/drm/i915/i915_gem.c        |  7 +++++++
 drivers/gpu/drm/i915/i915_gem_stolen.c | 35 ++++++++++++++++++++++++++++++++++
 include/uapi/drm/i915_drm.h            | 15 +++++++++++++++
 5 files changed, 66 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +6 -0
index 49ec438..d12ef0a 100644
@@ -534,6 +534,12 @@ static int i915_gem_aperture_info(struct seq_file *m, void *data)
 		   arg.fence_available_size);
 	seq_printf(m, "Single largest fence available: %llu bytes\n",
 		   arg.fence_largest_size);
+	seq_printf(m, "Total size of the stolen region: %llu bytes\n",
+		   arg.stolen_total_size);
+	seq_printf(m, "Available size of the stolen region: %llu bytes\n",
+		   arg.stolen_available_size);
+	seq_printf(m, "Single largest area in the stolen region: %llu bytes\n",
+		   arg.stolen_largest_size);
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_drv.h +3 -0
index ea9caf2..7cd1b2e 100644
@@ -3101,6 +3101,9 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 					       u32 stolen_offset,
 					       u32 gtt_offset,
 					       u32 size);
+void i915_gem_stolen_size_info(struct drm_mm *mm, uint64_t *stolen_total,
+			       uint64_t *stolen_free,
+			       uint64_t *stolen_largest);
 
 /* i915_gem_shrinker.c */
 unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
drivers/gpu/drm/i915/i915_gem.c +7 -0
index ccfc8d3..ec20c67 100644
@@ -203,6 +203,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	struct list_head map_list;
 	const u32 map_limit = dev_priv->gtt.mappable_end;
 	size_t pinned, map_space, map_largest, fence_space, fence_largest;
+	uint64_t stolen_total, stolen_available, stolen_largest;
 	u32 last, size;
 
 	INIT_LIST_HEAD(&map_list);
@@ -260,6 +261,9 @@ skip_first:
 			fence_largest = size;
 		fence_space += size;
 	}
+
+	i915_gem_stolen_size_info(&dev_priv->mm.stolen, &stolen_total,
+				  &stolen_available, &stolen_largest);
 	mutex_unlock(&dev->struct_mutex);
 
 	args->aper_size = dev_priv->gtt.base.total;
@@ -269,6 +273,9 @@ skip_first:
 	args->map_total_size = dev_priv->gtt.mappable_end;
 	args->fence_available_size = fence_space;
 	args->fence_largest_size = fence_largest;
+	args->stolen_total_size = stolen_total;
+	args->stolen_available_size = stolen_available;
+	args->stolen_largest_size = stolen_largest;
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_gem_stolen.c +35 -0
index 348ed5a..08d983f 100644
@@ -551,3 +551,38 @@ err_out:
 	drm_gem_object_unreference(&obj->base);
 	return NULL;
 }
+
+void i915_gem_stolen_size_info(struct drm_mm *mm, uint64_t *stolen_total,
+			       uint64_t *stolen_free,
+			       uint64_t *stolen_largest)
+{
+	struct drm_mm_node *entry;
+	struct drm_mm_node *head_node = &mm->head_node;
+	uint64_t hole_size, hole_start, hole_end, largest_hole = 0;
+	uint64_t total_used = 0, total_free = 0;
+
+	if (head_node->hole_follows) {
+		hole_start = drm_mm_hole_node_start(head_node);
+		hole_end = drm_mm_hole_node_end(head_node);
+		hole_size = hole_end - hole_start;
+		total_free += hole_size;
+		if (largest_hole < hole_size)
+			largest_hole = hole_size;
+	}
+
+	drm_mm_for_each_node(entry, mm) {
+		total_used += entry->size;
+		if (entry->hole_follows) {
+			hole_start = drm_mm_hole_node_start(entry);
+			hole_end = drm_mm_hole_node_end(entry);
+			hole_size = hole_end - hole_start;
+			total_free += hole_size;
+			if (largest_hole < hole_size)
+				largest_hole = hole_size;
+		}
+	}
+
+	*stolen_total = total_free + total_used;
+	*stolen_free = total_free;
+	*stolen_largest = largest_hole;
+}
include/uapi/drm/i915_drm.h +15 -0
index 3e7f4a3..9d59fb0 100644
@@ -947,6 +947,21 @@ struct drm_i915_gem_get_aperture {
 	 * Single largest fenceable region, in bytes.
 	 */
 	__u64 fence_largest_size;
+
+	/**
+	 * Total space in the stolen region, in bytes
+	 */
+	__u64 stolen_total_size;
+
+	/**
+	 * Available space in the stolen region, in bytes
+	 */
+	__u64 stolen_available_size;
+
+	/**
+	 * Single largest block in stolen region, in bytes
+	 */
+	__u64 stolen_largest_size;
 };
 
 struct drm_i915_get_pipe_from_crtc_id {
Signature · 6 lines
1.9.1

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

Re: [PATCH 2/2] drm/i915: Extend GET_APERTURE ioctl to report size of the stolen region

Hi,

Quoted 103 lines · On 07/08/2015 07:51 AM, [email protected] wrote:

From: Ankitprasad Sharma <[email protected]>

This patch extends the GET_APERTURE ioctl to add support for getting total size and available size of the stolen region as well as single largest block available in the stolen region. Also adds debugfs support to retieve the size information of the stolen area.

v2: respinned over Rodrigo's patch which extends the GET_APERTURE too. Used drm_mm to get the size information of the stolen region (Chris)
Added debugfs support for testing (Ankit)

v3: Rebased to the latest drm-intel-nightly (Ankit)

Reviewed-by Chris Wilson <chris at chris-wilson.co.uk>
---
  drivers/gpu/drm/i915/i915_debugfs.c    |  6 ++++++
  drivers/gpu/drm/i915/i915_drv.h        |  3 +++
  drivers/gpu/drm/i915/i915_gem.c        |  7 +++++++
  drivers/gpu/drm/i915/i915_gem_stolen.c | 35 ++++++++++++++++++++++++++++++++++
  include/uapi/drm/i915_drm.h            | 15 +++++++++++++++
  5 files changed, 66 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +6 -0
index 49ec438..d12ef0a 100644
@@ -534,6 +534,12 @@ static int i915_gem_aperture_info(struct seq_file *m, void *data)
  		   arg.fence_available_size);
  	seq_printf(m, "Single largest fence available: %llu bytes\n",
  		   arg.fence_largest_size);
+	seq_printf(m, "Total size of the stolen region: %llu bytes\n",
+		   arg.stolen_total_size);
+	seq_printf(m, "Available size of the stolen region: %llu bytes\n",
+		   arg.stolen_available_size);
+	seq_printf(m, "Single largest area in the stolen region: %llu bytes\n",
+		   arg.stolen_largest_size);
 
  	return 0;
  }
drivers/gpu/drm/i915/i915_drv.h +3 -0
index ea9caf2..7cd1b2e 100644
@@ -3101,6 +3101,9 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  					       u32 stolen_offset,
  					       u32 gtt_offset,
  					       u32 size);
+void i915_gem_stolen_size_info(struct drm_mm *mm, uint64_t *stolen_total,
+			       uint64_t *stolen_free,
+			       uint64_t *stolen_largest);
 
  /* i915_gem_shrinker.c */
  unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
drivers/gpu/drm/i915/i915_gem.c +7 -0
index ccfc8d3..ec20c67 100644
@@ -203,6 +203,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  	struct list_head map_list;
  	const u32 map_limit = dev_priv->gtt.mappable_end;
  	size_t pinned, map_space, map_largest, fence_space, fence_largest;
+	uint64_t stolen_total, stolen_available, stolen_largest;
  	u32 last, size;
 
  	INIT_LIST_HEAD(&map_list);
@@ -260,6 +261,9 @@ skip_first:
  			fence_largest = size;
  		fence_space += size;
  	}
+
+	i915_gem_stolen_size_info(&dev_priv->mm.stolen, &stolen_total,
+				  &stolen_available, &stolen_largest);
  	mutex_unlock(&dev->struct_mutex);
 
  	args->aper_size = dev_priv->gtt.base.total;
@@ -269,6 +273,9 @@ skip_first:
  	args->map_total_size = dev_priv->gtt.mappable_end;
  	args->fence_available_size = fence_space;
  	args->fence_largest_size = fence_largest;
+	args->stolen_total_size = stolen_total;
+	args->stolen_available_size = stolen_available;
+	args->stolen_largest_size = stolen_largest;
 
  	return 0;
  }
drivers/gpu/drm/i915/i915_gem_stolen.c +7 -0
index 348ed5a..08d983f 100644
@@ -551,3 +551,38 @@ err_out:
  	drm_gem_object_unreference(&obj->base);
  	return NULL;
  }
+
+void i915_gem_stolen_size_info(struct drm_mm *mm, uint64_t *stolen_total,
+			       uint64_t *stolen_free,
+			       uint64_t *stolen_largest)
+{
+	struct drm_mm_node *entry;
+	struct drm_mm_node *head_node = &mm->head_node;

drivers/gpu/drm/i915/i915_gem_stolen.c err_out: · line 570

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10 -0
+	uint64_t hole_size, hole_start, hole_end, largest_hole = 0;
+	uint64_t total_used = 0, total_free = 0;
+
+	if (head_node->hole_follows) {
+		hole_start = drm_mm_hole_node_start(head_node);
+		hole_end = drm_mm_hole_node_end(head_node);
+		hole_size = hole_end - hole_start;
+		total_free += hole_size;
+		if (largest_hole < hole_size)
+			largest_hole = hole_size;

Guaranteed it is the largest hole by this point, but not worth the effort of respining to change it.

Maybe only consider getting rid of hole_start and hole_end since they are not used but once. It would compact this block and the one below. Unless it would be longer than 80 chars in which case is not worth it.

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +5 -0
+	}
+
+	drm_mm_for_each_node(entry, mm) {
+		total_used += entry->size;
+		if (entry->hole_follows) {

drivers/gpu/drm/i915/i915_gem_stolen.c err_out: · line 585

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10 -0
+			hole_start = drm_mm_hole_node_start(entry);
+			hole_end = drm_mm_hole_node_end(entry);
+			hole_size = hole_end - hole_start;
+			total_free += hole_size;
+			if (largest_hole < hole_size)
+				largest_hole = hole_size;
+		}
+	}
+
+	*stolen_total = total_free + total_used;

Pitty for such a round about way to get total amount of stolen memory, but it looks we don't store it elsewhere.

drivers/gpu/drm/i915/i915_gem_stolen.c err_out: · line 587

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +2 -0
+	*stolen_free = total_free;
+	*stolen_largest = largest_hole;

Again I wonder the usefulness of this data?

But for the code review itself;

Regards,

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