Skip to contentSkip to conversation

Save megabytes of wasted sg entries

RFC In review Tvrtko Ursulin 6 participants 19 messages Oct 13, 2016

Subsystems (3)
lore
Share & tools
lore

Tvrtko Ursulin

author maintainer
#0 lore raw

cover Save megabytes of wasted sg entries

From: Tvrtko Ursulin <[email protected]>

We can decrease the i915 slab usage by 1-6 MiB* easily by doing more sg list coalescing and having the tables at the correct size at the same time.

This series extracts the sg table building code into helper so that all places in i915 can benefit.

Another problem is that it is hard to know in advance how many entries we will need (due coalescing).

Rather than try to pre-scan the pages before creating the table, it looks easier to keep our pessimistic table sizing at creation, and trim the waste afterwards.

*** There is a bug here somewhere so please don't run it. ***
*** I am sending it as RFC only since my debug capabilities ***
*** are severely limited at the moment. ***

*) I measured the memory savings by looking at the unused number
of sg entries at some points:

* Logging into KDE there is 1-2 MiB of unused sg entries.
* Running the T-Rex benchamrk aroun 3 Mib.
* Similarly for Manhattan 5-6 MiB.

Tvrtko Ursulin (7):
drm/i915: Extract sg creation into a helper drm/i915: Use i915_sg_create for userptr drm/i915: Use i915_sg_create for partial views drm/i915: Use i915_sg_create for rotated pages view drm/i915: Use i915_sg_create for dmabuf lib/scatterlist: Add sg_trim_table drm/i915: Trim sg table after creating it

 drivers/gpu/drm/i915/i915_drv.h         |  34 +++++
 drivers/gpu/drm/i915/i915_gem.c         | 218 +++++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_gem_dmabuf.c  |  45 +++----
 drivers/gpu/drm/i915/i915_gem_gtt.c     |  76 ++++-------
 drivers/gpu/drm/i915/i915_gem_userptr.c |  51 ++------
 include/linux/scatterlist.h             |   2 +
 lib/scatterlist.c                       |  53 ++++++++
 7 files changed, 314 insertions(+), 165 deletions(-)
Signature · 6 lines
2.7.4

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

RFC 1/7 drm/i915: Extract sg creation into a helper

From: Tvrtko Ursulin <[email protected]>

In order to reuse the same logic in several places in the driver, extract the logic which adds pages to the sg list and does the potential coalescing, into separate functions.

Code wanting to build the sg table needs to do the following:

1. Call i915_sg_create to create the state object for a given maximum number of pages.
2. Iterate using i915_sg_for_each_page
3. Call i915_sg_add_page to add all the pages in order
4. On success call i915_sg_complete, or on failure i915_sg_abort

In this patch only i915_gem_object_get_pages_gtt gets converted to use the new functions.

---
 drivers/gpu/drm/i915/i915_gem.c | 153 ++++++++++++++++++++++++++++------------
 1 file changed, 109 insertions(+), 44 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +109 -44
index fdd496e6c081..93b047735e6b 100644
@@ -2216,18 +2216,104 @@ static unsigned long swiotlb_max_size(void)
 #endif
 }
 
+struct i915_sg_create_state {
+	struct sg_table *st;
+	struct scatterlist *sg;
+	unsigned int idx;
+	unsigned int page_count;
+	unsigned long max_segment;
+	unsigned long last_pfn;
+};
+
+static struct i915_sg_create_state *
+i915_sg_create(unsigned int page_count)
+{
+	struct i915_sg_create_state *state;
+	struct sg_table *st;
+
+	state = kmalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	st = kmalloc(sizeof(*st), GFP_KERNEL);
+	if (!st) {
+		kfree(state);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	if (sg_alloc_table(st, page_count, GFP_KERNEL)) {
+		kfree(st);
+		kfree(state);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	st->nents = 0;
+	state->st = st;
+	state->sg = st->sgl;
+	state->page_count = page_count;
+	state->idx = 0;
+	state->max_segment = swiotlb_max_size();
+	if (!state->max_segment)
+		state->max_segment = page_count * PAGE_SIZE;
+	state->last_pfn = 0;
+
+	return state;
+}
+
+static void
+i915_sg_add_page(struct i915_sg_create_state *state, struct page *page)
+{
+	unsigned long pfn = page_to_pfn(page);
+	struct scatterlist *sg = state->sg;
+
+	if (!state->idx ||
+	    sg->length >= state->max_segment ||
+	    pfn != state->last_pfn + 1) {
+		if (state->idx)
+			sg = sg_next(sg);
+		state->st->nents++;
+		sg_set_page(sg, page, PAGE_SIZE, 0);
+	} else {
+		sg->length += PAGE_SIZE;
+	}
+
+	state->last_pfn = pfn;
+	state->sg = sg;
+	state->idx++;
+}
+
+static struct sg_table *
+i915_sg_complete(struct i915_sg_create_state *state)
+{
+	struct sg_table *st = state->st;
+
+	if (state->sg) /* fewer sg entries written than max allocated */
+		sg_mark_end(state->sg);
+
+	kfree(state);
+
+	return st;
+}
+
+static void
+i915_sg_abort(struct i915_sg_create_state *state)
+{
+	sg_free_table(state->st);
+	kfree(state->st);
+	kfree(state);
+}
+
+#define i915_sg_for_each_page(state) \
+	for( ; (state)->idx < (state)->page_count; )
+
 static int
 i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
 {
 	struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
-	int page_count, i;
 	struct address_space *mapping;
-	struct sg_table *st;
-	struct scatterlist *sg;
+	struct i915_sg_create_state *state;
 	struct sgt_iter sgt_iter;
 	struct page *page;
-	unsigned long last_pfn = 0;	/* suppress gcc warning */
-	unsigned long max_segment;
 	int ret;
 	gfp_t gfp;
 
@@ -2238,19 +2324,9 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
 	BUG_ON(obj->base.read_domains & I915_GEM_GPU_DOMAINS);
 	BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS);
 
-	max_segment = swiotlb_max_size();
-	if (!max_segment)
-		max_segment = obj->base.size;
-
-	st = kmalloc(sizeof(*st), GFP_KERNEL);
-	if (st == NULL)
-		return -ENOMEM;
-
-	page_count = obj->base.size / PAGE_SIZE;
-	if (sg_alloc_table(st, page_count, GFP_KERNEL)) {
-		kfree(st);
-		return -ENOMEM;
-	}
+	state = i915_sg_create(obj->base.size / PAGE_SIZE);
+	if (IS_ERR(state))
+		return PTR_ERR(state);
 
 	/* Get the list of pages out of our struct file.  They'll be pinned
 	 * at this point until we release them.
@@ -2260,47 +2336,37 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
 	mapping = obj->base.filp->f_mapping;
 	gfp = mapping_gfp_constraint(mapping, ~(__GFP_IO | __GFP_RECLAIM));
 	gfp |= __GFP_NORETRY | __GFP_NOWARN;
-	sg = st->sgl;
-	st->nents = 0;
-	for (i = 0; i < page_count; i++) {
-		page = shmem_read_mapping_page_gfp(mapping, i, gfp);
+	i915_sg_for_each_page(state) {
+		page = shmem_read_mapping_page_gfp(mapping, state->idx, gfp);
 		if (IS_ERR(page)) {
 			i915_gem_shrink(dev_priv,
-					page_count,
+					state->page_count,
 					I915_SHRINK_BOUND |
 					I915_SHRINK_UNBOUND |
 					I915_SHRINK_PURGEABLE);
-			page = shmem_read_mapping_page_gfp(mapping, i, gfp);
+			page = shmem_read_mapping_page_gfp(mapping, state->idx,
+							   gfp);
 		}
 		if (IS_ERR(page)) {
 			/* We've tried hard to allocate the memory by reaping
 			 * our own buffer, now let the real VM do its job and
 			 * go down in flames if truly OOM.
 			 */
-			page = shmem_read_mapping_page(mapping, i);
+			page = shmem_read_mapping_page(mapping, state->idx);
 			if (IS_ERR(page)) {
 				ret = PTR_ERR(page);
 				goto err_pages;
 			}
 		}
-		if (!i ||
-		    sg->length >= max_segment ||
-		    page_to_pfn(page) != last_pfn + 1) {
-			if (i)
-				sg = sg_next(sg);
-			st->nents++;
-			sg_set_page(sg, page, PAGE_SIZE, 0);
-		} else {
-			sg->length += PAGE_SIZE;
-		}
-		last_pfn = page_to_pfn(page);
+
+		i915_sg_add_page(state, page);
 
 		/* Check that the i965g/gm workaround works. */
-		WARN_ON((gfp & __GFP_DMA32) && (last_pfn >= 0x00100000UL));
+		WARN_ON((gfp & __GFP_DMA32) &&
+			(state->last_pfn >= 0x00100000UL));
 	}
-	if (sg) /* loop terminated early; short sg table */
-		sg_mark_end(sg);
-	obj->pages = st;
+
+	obj->pages = i915_sg_complete(state);
 
 	ret = i915_gem_gtt_prepare_object(obj);
 	if (ret)
@@ -2316,11 +2382,10 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
 	return 0;
 
 err_pages:
-	sg_mark_end(sg);
-	for_each_sgt_page(page, sgt_iter, st)
+	sg_mark_end(state->sg);
+	for_each_sgt_page(page, sgt_iter, state->st)
 		put_page(page);
-	sg_free_table(st);
-	kfree(st);
+	i915_sg_abort(state);
 
 	/* shmemfs first checks if there is enough memory to allocate the page
 	 * and reports ENOSPC should there be insufficient, along with the usual
Signature · 6 lines
2.7.4

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

RFC 2/7 drm/i915: Use i915_sg_create for userptr

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Now that we have a helper which builds the sg lists, use it from the userptr code as well.

To do this we first export the API and add kerneldoc for it.

---
 drivers/gpu/drm/i915/i915_drv.h         | 33 +++++++++++++++++
 drivers/gpu/drm/i915/i915_gem.c         | 65 +++++++++++++++++++++++----------
 drivers/gpu/drm/i915/i915_gem_userptr.c | 51 +++++---------------------
 3 files changed, 87 insertions(+), 62 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +33 -0
index bf397b643cc0..e226794ffc1b 100644
@@ -3999,4 +3999,37 @@ int remap_io_mapping(struct vm_area_struct *vma,
 	__T;								\
 })
 
+/**
+ * struct i915_sg_create_state - state object for the sg creation helpers
+ * @st: sg_table being created
+ * @sg: Current scatterlist entry iterated over
+ * @idx: Current page index iterated over
+ * @page_count: Number of pages requested for the sg table to hold at creation
+ * @max_segment: Maximum size in bytes of a single sg entry
+ * @last_pfn: Page frame number of the previously added page
+ */
+struct i915_sg_create_state {
+	struct sg_table *st;
+	struct scatterlist *sg;
+	unsigned int idx;
+	unsigned int page_count;
+	unsigned long max_segment;
+	unsigned long last_pfn;
+};
+
+struct i915_sg_create_state *i915_sg_create(unsigned int page_count);
+void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page);
+struct sg_table *i915_sg_complete(struct i915_sg_create_state *state);
+void i915_sg_abort(struct i915_sg_create_state *state);
+
+/**
+ * i915_sg_for_each_page - sg creation iterator
+ * @state: state object created by i915_sg_create
+ *
+ * Iterates page_count times over the created state allowing the caller to
+ * call i915_sg_add_page for all the pages it wants to build the list from.
+ */
+#define i915_sg_for_each_page(state) \
+	for( ; (state)->idx < (state)->page_count; )
+
 #endif
drivers/gpu/drm/i915/i915_gem.c +45 -20

95 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_userptr.c +9 -42

63 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#6 lore raw

RFC 3/7 drm/i915: Use i915_sg_create for partial views

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Simplify the partial view creation loop by using the newly introduced helpers.

It also allows the list to be coalesced when possbile.

New i915_sg_add_dma helper was added to allow adding just the DMA address entries to the list.

---
 drivers/gpu/drm/i915/i915_drv.h     |  1 +
 drivers/gpu/drm/i915/i915_gem.c     | 38 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 34 ++++++++-------------------------
 3 files changed, 47 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index e226794ffc1b..641a1dbc87b8 100644
@@ -4019,6 +4019,7 @@ struct i915_sg_create_state {
 
 struct i915_sg_create_state *i915_sg_create(unsigned int page_count);
 void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page);
+void i915_sg_add_dma(struct i915_sg_create_state *state, dma_addr_t addr);
 struct sg_table *i915_sg_complete(struct i915_sg_create_state *state);
 void i915_sg_abort(struct i915_sg_create_state *state);
 
drivers/gpu/drm/i915/i915_gem.c +38 -0
index 1c1aa3bbde8a..05dc2af1a89e 100644
@@ -2268,6 +2268,8 @@ struct i915_sg_create_state *i915_sg_create(unsigned int page_count)
  * page which needs to be added to the sg list.
  * Function manages the internal state which can be read (only!) by the caller
  * where appropriate.
+ *
+ * MUST NOT be mixed with i915_sg_add_dma!
  */
 void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page)
 {
@@ -2291,6 +2293,42 @@ void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page)
 }
 
 /**
+ * i915_sg_add_dma - adds a dma address to the sg list being built
+ * @state: state created with i915_sg_create
+ * @addr: dma address to add
+ *
+ * Intended to be called under the i915_sg_for_each_page iterator once for each
+ * page which needs to be added to the sg list.
+ * Function manages the internal state which can be read (only!) by the caller
+ * where appropriate.
+ *
+ * MUST NOT be mixed with i915_sg_add_page!
+ */
+void i915_sg_add_dma(struct i915_sg_create_state *state, dma_addr_t addr)
+{
+	struct scatterlist *sg = state->sg;
+
+	if (!state->idx ||
+	    sg->length >= state->max_segment ||
+	    addr != state->last_pfn + PAGE_SIZE) {
+		if (state->idx)
+			sg = sg_next(sg);
+		state->st->nents++;
+		sg_set_page(sg, NULL, PAGE_SIZE, 0);
+		sg_dma_address(sg) = addr;
+		sg_dma_len(sg) = PAGE_SIZE;
+	} else {
+		sg->length += PAGE_SIZE;
+		if (IS_ENABLED(CONFIG_NEED_SG_DMA_LENGTH))
+			sg_dma_len(sg) += PAGE_SIZE;
+	}
+
+	state->last_pfn = addr;
+	state->sg = sg;
+	state->idx++;
+}
+
+/**
  * i915_sg_complete - completes the sg list building
  * @state: state created with i915_sg_create
  *
drivers/gpu/drm/i915/i915_gem_gtt.c +8 -26
index 2d846aa39ca5..f0c70e7c8daa 100644
@@ -3559,41 +3559,23 @@ static struct sg_table *
 intel_partial_pages(const struct i915_ggtt_view *view,
 		    struct drm_i915_gem_object *obj)
 {
-	struct sg_table *st;
-	struct scatterlist *sg;
+	struct i915_sg_create_state *state;
 	struct sg_page_iter obj_sg_iter;
-	int ret = -ENOMEM;
 
-	st = kmalloc(sizeof(*st), GFP_KERNEL);
-	if (!st)
-		goto err_st_alloc;
-
-	ret = sg_alloc_table(st, view->params.partial.size, GFP_KERNEL);
-	if (ret)
-		goto err_sg_alloc;
+	state = i915_sg_create(view->params.partial.size);
+	if (IS_ERR(state))
+		return ERR_CAST(state);
 
-	sg = st->sgl;
-	st->nents = 0;
 	for_each_sg_page(obj->pages->sgl, &obj_sg_iter, obj->pages->nents,
-		view->params.partial.offset)
+			 view->params.partial.offset)
 	{
-		if (st->nents >= view->params.partial.size)
+		if (state->idx >= view->params.partial.size)
 			break;
 
-		sg_set_page(sg, NULL, PAGE_SIZE, 0);
-		sg_dma_address(sg) = sg_page_iter_dma_address(&obj_sg_iter);
-		sg_dma_len(sg) = PAGE_SIZE;
-
-		sg = sg_next(sg);
-		st->nents++;
+		i915_sg_add_dma(state, sg_page_iter_dma_address(&obj_sg_iter));
 	}
 
-	return st;
-
-err_sg_alloc:
-	kfree(st);
-err_st_alloc:
-	return ERR_PTR(ret);
+	return i915_sg_complete(state);
 }
 
 static int
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#7 lore raw

RFC 4/7 drm/i915: Use i915_sg_create for rotated pages view

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

As for the partial view, just simplifies the loop and enables entry coalescing.

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 42 +++++++++++++------------------------
 1 file changed, 14 insertions(+), 28 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +14 -28
index f0c70e7c8daa..655c31182c68 100644
@@ -3464,11 +3464,10 @@ i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
 	return vma;
 }
 
-static struct scatterlist *
+static void
 rotate_pages(const dma_addr_t *in, unsigned int offset,
-	     unsigned int width, unsigned int height,
-	     unsigned int stride,
-	     struct sg_table *st, struct scatterlist *sg)
+	     unsigned int width, unsigned int height, unsigned int stride,
+	     struct i915_sg_create_state *state)
 {
 	unsigned int column, row;
 	unsigned int src_idx;
@@ -3476,34 +3475,27 @@ rotate_pages(const dma_addr_t *in, unsigned int offset,
 	for (column = 0; column < width; column++) {
 		src_idx = stride * (height - 1) + column;
 		for (row = 0; row < height; row++) {
-			st->nents++;
 			/* We don't need the pages, but need to initialize
 			 * the entries so the sg list can be happily traversed.
 			 * The only thing we need are DMA addresses.
 			 */
-			sg_set_page(sg, NULL, PAGE_SIZE, 0);
-			sg_dma_address(sg) = in[offset + src_idx];
-			sg_dma_len(sg) = PAGE_SIZE;
-			sg = sg_next(sg);
+			i915_sg_add_dma(state, in[offset + src_idx]);
 			src_idx -= stride;
 		}
 	}
-
-	return sg;
 }
 
 static struct sg_table *
 intel_rotate_fb_obj_pages(const struct intel_rotation_info *rot_info,
 			  struct drm_i915_gem_object *obj)
 {
+	struct i915_sg_create_state *state;
 	const size_t n_pages = obj->base.size / PAGE_SIZE;
 	unsigned int size = intel_rotation_info_size(rot_info);
 	struct sgt_iter sgt_iter;
 	dma_addr_t dma_addr;
 	unsigned long i;
 	dma_addr_t *page_addr_list;
-	struct sg_table *st;
-	struct scatterlist *sg;
 	int ret = -ENOMEM;
 
 	/* Allocate a temporary list of source pages for random access. */
@@ -3513,14 +3505,12 @@ intel_rotate_fb_obj_pages(const struct intel_rotation_info *rot_info,
 	if (!page_addr_list)
 		return ERR_PTR(ret);
 
-	/* Allocate target SG list. */
-	st = kmalloc(sizeof(*st), GFP_KERNEL);
-	if (!st)
+	/* Begin creation of the target SG list. */
+	state = i915_sg_create(size);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
 		goto err_st_alloc;
-
-	ret = sg_alloc_table(st, size, GFP_KERNEL);
-	if (ret)
-		goto err_sg_alloc;
+	}
 
 	/* Populate source page list from the object. */
 	i = 0;
@@ -3528,13 +3518,11 @@ intel_rotate_fb_obj_pages(const struct intel_rotation_info *rot_info,
 		page_addr_list[i++] = dma_addr;
 
 	GEM_BUG_ON(i != n_pages);
-	st->nents = 0;
-	sg = st->sgl;
 
 	for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) {
-		sg = rotate_pages(page_addr_list, rot_info->plane[i].offset,
-				  rot_info->plane[i].width, rot_info->plane[i].height,
-				  rot_info->plane[i].stride, st, sg);
+		rotate_pages(page_addr_list, rot_info->plane[i].offset,
+			     rot_info->plane[i].width, rot_info->plane[i].height,
+			     rot_info->plane[i].stride, state);
 	}
 
 	DRM_DEBUG_KMS("Created rotated page mapping for object size %zu (%ux%u tiles, %u pages)\n",
@@ -3542,10 +3530,8 @@ intel_rotate_fb_obj_pages(const struct intel_rotation_info *rot_info,
 
 	drm_free_large(page_addr_list);
 
-	return st;
+	return i915_sg_complete(state);
 
-err_sg_alloc:
-	kfree(st);
 err_st_alloc:
 	drm_free_large(page_addr_list);
 
Signature · 6 lines
2.7.4

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

RFC 5/7 drm/i915: Use i915_sg_create for dmabuf

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

As for the earlier ones, it simplifies the loop and enables entry colaescing.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 45 +++++++++++++++-------------------
 1 file changed, 20 insertions(+), 25 deletions(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +20 -25
index 97c9d68b45df..5df1dfdeec66 100644
@@ -40,11 +40,13 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
 					     enum dma_data_direction dir)
 {
 	struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf);
-	struct sg_table *st;
-	struct scatterlist *src, *dst;
-	int ret, i;
+	struct drm_device *dev = obj->base.dev;
+	struct i915_sg_create_state *state;
+	struct sgt_iter sgt_iter;
+	struct page *page;
+	int ret;
 
-	ret = i915_mutex_lock_interruptible(obj->base.dev);
+	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)
 		goto err;
 
@@ -55,40 +57,33 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
 	i915_gem_object_pin_pages(obj);
 
 	/* Copy sg so that we make an independent mapping */
-	st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
-	if (st == NULL) {
-		ret = -ENOMEM;
+	state = i915_sg_create(obj->pages->nents);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
 		goto err_unpin;
 	}
 
-	ret = sg_alloc_table(st, obj->pages->nents, GFP_KERNEL);
-	if (ret)
-		goto err_free;
-
-	src = obj->pages->sgl;
-	dst = st->sgl;
-	for (i = 0; i < obj->pages->nents; i++) {
-		sg_set_page(dst, sg_page(src), src->length, 0);
-		dst = sg_next(dst);
-		src = sg_next(src);
-	}
+	for_each_sgt_page(page, sgt_iter, obj->pages)
+		i915_sg_add_page(state, page);
 
-	if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) {
+	i915_sg_complete(state);
+
+	if (!dma_map_sg(attachment->dev,
+			state->st->sgl, state->st->nents, dir)) {
 		ret =-ENOMEM;
 		goto err_free_sg;
 	}
 
-	mutex_unlock(&obj->base.dev->struct_mutex);
-	return st;
+	mutex_unlock(&dev->struct_mutex);
+
+	return state->st;
 
 err_free_sg:
-	sg_free_table(st);
-err_free:
-	kfree(st);
+	i915_sg_abort(state);
 err_unpin:
 	i915_gem_object_unpin_pages(obj);
 err_unlock:
-	mutex_unlock(&obj->base.dev->struct_mutex);
+	mutex_unlock(&dev->struct_mutex);
 err:
 	return ERR_PTR(ret);
 }
Signature · 6 lines
2.7.4

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

RFC 6/7 lib/scatterlist: Add sg_trim_table

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

*** BROKEN *** RFC only *** BROKEN ***

In cases where it is hard to know to minimum numbers of ents table will need to hold at sg_alloc_time, and we end up with a table with unused sg entries at its end, this function will trim (free) the unused sg entry blocks and adjust the table->orig_nents down.

---
 include/linux/scatterlist.h |  2 ++
 lib/scatterlist.c           | 53 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
include/linux/scatterlist.h +2 -0
index cb3c8fe6acd7..b344ecc8eddf 100644
@@ -266,6 +266,8 @@ int sg_alloc_table_from_pages(struct sg_table *sgt,
 	unsigned long offset, unsigned long size,
 	gfp_t gfp_mask);
 
+void sg_trim_table(struct sg_table *);
+
 size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, void *buf,
 		      size_t buflen, off_t skip, bool to_buffer);
 
lib/scatterlist.c +53 -0

59 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#14 lore raw

RFC 7/7 drm/i915: Trim sg table after creating it

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Since most of our callers do not know in advance how many entries in the sg table they will need, it is beneficial to trim the table after it has been created.

Use the newly added sg_trim_table to do that when i915_sg_complete is called.

Before we were wasting between 1-2 MiB of space on unused sg entries just when logging into an idle desktop (KDE), around 3 MiB while running the T-Rex benchmark or around 5-6 MiB with Manhattan.

---
 drivers/gpu/drm/i915/i915_gem.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_gem.c +2 -0
index 05dc2af1a89e..1b722c5ebb26 100644
@@ -2347,6 +2347,8 @@ struct sg_table *i915_sg_complete(struct i915_sg_create_state *state)
 
 	kfree(state);
 
+	sg_trim_table(st);
+
 	return st;
 }
 
Signature · 6 lines
2.7.4

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

Re: [RFC 5/7] drm/i915: Use i915_sg_create for dmabuf

In reply to Tvrtko Ursulin

drivers/gpu/drm/i915/i915_gem_dmabuf.c static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme · line 67

Quoted 9 lines · Tvrtko Ursulin
drivers/gpu/drm/i915/i915_gem_dmabuf.c +2 -7
-	src = obj->pages->sgl;
-	dst = st->sgl;
-	for (i = 0; i < obj->pages->nents; i++) {
-		sg_set_page(dst, sg_page(src), src->length, 0);
-		dst = sg_next(dst);
-		src = sg_next(src);
-	}
+	for_each_sgt_page(page, sgt_iter, obj->pages)
+		i915_sg_add_page(state, page);

This (and partial_pages) can just copy the existing compact obj->pages. The previous code should already be as compact as its input. And that is not a simpler loop!
-Chris

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

Re: [RFC 1/7] drm/i915: Extract sg creation into a helper

In reply to Tvrtko Ursulin
Quoted 8 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

In order to reuse the same logic in several places in the driver, extract the logic which adds pages to the sg list and does the potential coalescing, into separate functions.

Code wanting to build the sg table needs to do the following:

Quoted 8 lines

1. Call i915_sg_create to create the state object for a given maximum number of pages.
2. Iterate using i915_sg_for_each_page
3. Call i915_sg_add_page to add all the pages in order
4. On success call i915_sg_complete, or on failure i915_sg_abort

In this patch only i915_gem_object_get_pages_gtt gets converted to use the new functions.

Yup, much happier. Though can we just allocate the state on the stack, it is the same as what we are previously using anyway. 40 bytes.

I've also thought about doing the sg_trim, just never actually tried...

Just not convinced that recreating the compact sg is better than copying the already compact sg (for dmabuf, partial).
-Chris

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

Re: [RFC 6/7] lib/scatterlist: Add sg_trim_table

In reply to Tvrtko Ursulin
Quoted 9 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

*** BROKEN *** RFC only *** BROKEN ***

In cases where it is hard to know to minimum numbers of ents table will need to hold at sg_alloc_time, and we end up with a table with unused sg entries at its end, this function will trim (free) the unused sg entry blocks and adjust the table->orig_nents down.

An alternative I had in mind, was to allocate the new chunks iteratively, i.e. as we run out of room in i915_sg_add_page. -Chris

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

Re: [RFC 5/7] drm/i915: Use i915_sg_create for dmabuf

In reply to Chris Wilson
Quoted 13 lines · Chris Wilson

drivers/gpu/drm/i915/i915_gem_dmabuf.c static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme · line 67

Quoted 9 lines · Tvrtko Ursulin
drivers/gpu/drm/i915/i915_gem_dmabuf.c +2 -7
-	src = obj->pages->sgl;
-	dst = st->sgl;
-	for (i = 0; i < obj->pages->nents; i++) {
-		sg_set_page(dst, sg_page(src), src->length, 0);
-		dst = sg_next(dst);
-		src = sg_next(src);
-	}
+	for_each_sgt_page(page, sgt_iter, obj->pages)
+		i915_sg_add_page(state, page);

This (and partial_pages) can just copy the existing compact obj->pages. The previous code should already be as compact as its input. And that is not a simpler loop!

Ah yes, you are right. A bit too mindless "search and replace" on my part.

Regards,

Tvrtko

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

#13 lore raw

Re: [RFC 6/7] lib/scatterlist: Add sg_trim_table

In reply to Chris Wilson
Quoted 5 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

*** BROKEN *** RFC only *** BROKEN ***

Quoted 7 lines
Quoted 5 lines

In cases where it is hard to know to minimum numbers of ents table will need to hold at sg_alloc_time, and we end up with a table with unused sg entries at its end, this function will trim (free) the unused sg entry blocks and adjust the table->orig_nents down.

An alternative I had in mind, was to allocate the new chunks iteratively, i.e. as we run out of room in i915_sg_add_page.

Thought about it but did not like having to handle another source of failures. Hm, don't know. Will think about it.

Regards,

Tvrtko

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

#3 lore raw

Re: [RFC 1/7] drm/i915: Extract sg creation into a helper

In reply to Chris Wilson
Quoted 15 lines · Chris Wilson
Quoted 14 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

In order to reuse the same logic in several places in the driver, extract the logic which adds pages to the sg list and does the potential coalescing, into separate functions.

Code wanting to build the sg table needs to do the following:

1. Call i915_sg_create to create the state object for a given maximum number of pages.
2. Iterate using i915_sg_for_each_page
3. Call i915_sg_add_page to add all the pages in order
4. On success call i915_sg_complete, or on failure i915_sg_abort

Quoted 4 lines
Quoted 2 lines

In this patch only i915_gem_object_get_pages_gtt gets converted to use the new functions.

Yup, much happier. Though can we just allocate the state on the stack, it is the same as what we are previously using anyway. 40 bytes.

Thought about this also and had a slight preference not to use stack, since we got to have kmalloc and error handling in i915_sg_create anyway.

Quoted 4 lines

I've also thought about doing the sg_trim, just never actually tried...

Just not convinced that recreating the compact sg is better than copying the already compact sg (for dmabuf, partial).

Agreed already on dmabuf. Partials yes, I suppose that could be implemented more efficiently. You think it is worth special casing it rather than reuse the common API? It would have to handle a start in the middle of the sg entry so it wouldn't be a straightforward copy.

Regards,

Tvrtko

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

#4 lore raw

Re: [RFC 1/7] drm/i915: Extract sg creation into a helper

Quoted 28 lines · Tvrtko Ursulin
Quoted 15 lines · Chris Wilson
Quoted 14 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

In order to reuse the same logic in several places in the driver, extract the logic which adds pages to the sg list and does the potential coalescing, into separate functions.

Code wanting to build the sg table needs to do the following:

1. Call i915_sg_create to create the state object for a given maximum number of pages.
2. Iterate using i915_sg_for_each_page
3. Call i915_sg_add_page to add all the pages in order
4. On success call i915_sg_complete, or on failure i915_sg_abort

Quoted 4 lines
Quoted 2 lines

In this patch only i915_gem_object_get_pages_gtt gets converted to use the new functions.

Yup, much happier. Though can we just allocate the state on the stack, it is the same as what we are previously using anyway. 40 bytes.

Thought about this also and had a slight preference not to use stack, since we got to have kmalloc and error handling in i915_sg_create anyway.

Quoted 2 lines

I've also thought about doing the sg_trim, just never actually tried...

Quoted 8 lines
Quoted 2 lines

Just not convinced that recreating the compact sg is better than copying the already compact sg (for dmabuf, partial).

Agreed already on dmabuf. Partials yes, I suppose that could be implemented more efficiently. You think it is worth special casing it rather than reuse the common API? It would have to handle a start in the middle of the sg entry so it wouldn't be a straightforward copy.

If you happen to running perf and gem_mmap_gtt, you might want to improve it. (You have to be using lots of large textures with mesa to worry about it, and then you are more likely bandwidth limited and not notice the load stalls as much.) It doesn't look too bad:

https://cgit.freedesktop.org/~ickle/linux-2.6/commit/?h=eb-fence&id=6eb7f33c14b9c408856af86c3b35c7ff878afca9

partial pages is a bit special as we have to copy across the dma mapping as well.
-Chris

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

✗ Fi.CI.BAT: failure for Save megabytes of wasted sg entries

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: Save megabytes of wasted sg entries
URL : https://patchwork.freedesktop.org/series/13706/
State : failure

== Summary ==

Series 13706v1 Save megabytes of wasted sg entries
https://patchwork.freedesktop.org/api/1.0/series/13706/revisions/1/mbox/

Test gem_cs_tlb:

        Subgroup basic-default:
                pass       -> INCOMPLETE (fi-bsw-n3050)
                pass       -> INCOMPLETE (fi-byt-n2820)
                pass       -> INCOMPLETE (fi-hsw-4770r)
                pass       -> INCOMPLETE (fi-skl-6260u)
                pass       -> INCOMPLETE (fi-ivb-3770)
                pass       -> INCOMPLETE (fi-kbl-7200u)
                pass       -> INCOMPLETE (fi-skl-6700hq)
                pass       -> INCOMPLETE (fi-bdw-5557u)
                pass       -> INCOMPLETE (fi-ilk-650)
                pass       -> INCOMPLETE (fi-hsw-4770)
                pass       -> INCOMPLETE (fi-byt-j1900)
                pass       -> INCOMPLETE (fi-snb-2520m)
                pass       -> INCOMPLETE (fi-bxt-t5700)
                pass       -> INCOMPLETE (fi-ivb-3520m)
fi-bdw-5557u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-bsw-n3050     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-bxt-t5700     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-byt-j1900     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-byt-n2820     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-hsw-4770      total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-hsw-4770r     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-ilk-650       total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-ivb-3520m     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-ivb-3770      total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-kbl-7200u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6260u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6700hq    total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2520m     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0  

Results at /archive/results/CI_IGT_test/Patchwork_2698/

75d9d28f7f5d0147ba35e956268c3a3c079dc754 drm-intel-nightly: 2016y-10m-13d-09h-14m-05s UTC integration manifest ae958d3 drm/i915: Trim sg table after creating it
c393824 lib/scatterlist: Add sg_trim_table
35fb691 drm/i915: Use i915_sg_create for dmabuf
215eb9b drm/i915: Use i915_sg_create for rotated pages view
845b775 drm/i915: Use i915_sg_create for partial views
393cad6 drm/i915: Use i915_sg_create for userptr
0e4b44a drm/i915: Extract sg creation into a helper

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

#16 lore raw

Re: ✗ Fi.CI.BAT: failure for Save megabytes of wasted sg entries

Quoted 12 lines

== Series Details ==

Series: Save megabytes of wasted sg entries
URL : https://patchwork.freedesktop.org/series/13706/
State : failure

== Summary ==

Series 13706v1 Save megabytes of wasted sg entries
https://patchwork.freedesktop.org/api/1.0/series/13706/revisions/1/mbox/

Test gem_cs_tlb:

Quoted 15 lines
        Subgroup basic-default:
                pass       -> INCOMPLETE (fi-bsw-n3050)
                pass       -> INCOMPLETE (fi-byt-n2820)
                pass       -> INCOMPLETE (fi-hsw-4770r)
                pass       -> INCOMPLETE (fi-skl-6260u)
                pass       -> INCOMPLETE (fi-ivb-3770)
                pass       -> INCOMPLETE (fi-kbl-7200u)
                pass       -> INCOMPLETE (fi-skl-6700hq)
                pass       -> INCOMPLETE (fi-bdw-5557u)
                pass       -> INCOMPLETE (fi-ilk-650)
                pass       -> INCOMPLETE (fi-hsw-4770)
                pass       -> INCOMPLETE (fi-byt-j1900)
                pass       -> INCOMPLETE (fi-snb-2520m)
                pass       -> INCOMPLETE (fi-bxt-t5700)
                pass       -> INCOMPLETE (fi-ivb-3520m)

running: igt/gem_cs_tlb/basic-default

[014/246] pass: 14 -
Build timed out (after 18 minutes). Marking the build as aborted.

[   96.771613] gem_cs_tlb: starting subtest basic-default
[   96.773567] general protection fault: 0000 [#1] PREEMPT SMP
[   96.773599] Modules linked in: snd_hda_intel i915 cdc_ncm usbnet mii x86_pkg_temp_thermal intel_powerclamp coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel lpc_ich snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_codec snd_hwdep snd_hda_core snd_pcm mei_me mei sdhci_pci sdhci mmc_core e1000e ptp pps_core [last unloaded: i915]
[   96.773775] CPU: 1 PID: 8922 Comm: gem_cs_tlb Tainted: G     U          4.8.0-CI-Patchwork_2698+ #1
[   96.773806] Hardware name: LENOVO 2356GCG/2356GCG, BIOS G7ET31WW (1.13 ) 07/02/2012
[   96.773833] task: ffff8801311ace40 task.stack: ffff880137654000
[   96.773854] RIP: 0010:[<ffffffff811cd432>]  [<ffffffff811cd432>] kfree+0x72/0x2e0

...

Quoted 18 lines
fi-bdw-5557u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-bsw-n3050     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-bxt-t5700     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-byt-j1900     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-byt-n2820     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-hsw-4770      total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-hsw-4770r     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-ilk-650       total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-ivb-3520m     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-ivb-3770      total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-kbl-7200u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-skl-6260u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-skl-6700hq    total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-snb-2520m     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0

Results at /archive/results/CI_IGT_test/Patchwork_2698/

Quoted 10 lines

75d9d28f7f5d0147ba35e956268c3a3c079dc754 drm-intel-nightly: 2016y-10m- 13d-09h-14m-05s UTC integration manifest
ae958d3 drm/i915: Trim sg table after creating it
c393824 lib/scatterlist: Add sg_trim_table
35fb691 drm/i915: Use i915_sg_create for dmabuf 215eb9b drm/i915: Use i915_sg_create for rotated pages view
845b775 drm/i915: Use i915_sg_create for partial views
393cad6 drm/i915: Use i915_sg_create for userptr 0e4b44a drm/i915: Extract sg creation into a helper

Jani Saarinen
Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo

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

#17 lore raw

Re: ✗ Fi.CI.BAT: failure for Save megabytes of wasted sg entries

Quoted 32 lines · Jani
Quoted 12 lines

== Series Details ==

Series: Save megabytes of wasted sg entries
URL : https://patchwork.freedesktop.org/series/13706/
State : failure

== Summary ==

Series 13706v1 Save megabytes of wasted sg entries
https://patchwork.freedesktop.org/api/1.0/series/13706/revisions/1/mbox/

Test gem_cs_tlb:

Quoted 15 lines
        Subgroup basic-default:
                pass       -> INCOMPLETE (fi-bsw-n3050)
                pass       -> INCOMPLETE (fi-byt-n2820)
                pass       -> INCOMPLETE (fi-hsw-4770r)
                pass       -> INCOMPLETE (fi-skl-6260u)
                pass       -> INCOMPLETE (fi-ivb-3770)
                pass       -> INCOMPLETE (fi-kbl-7200u)
                pass       -> INCOMPLETE (fi-skl-6700hq)
                pass       -> INCOMPLETE (fi-bdw-5557u)
                pass       -> INCOMPLETE (fi-ilk-650)
                pass       -> INCOMPLETE (fi-hsw-4770)
                pass       -> INCOMPLETE (fi-byt-j1900)
                pass       -> INCOMPLETE (fi-snb-2520m)
                pass       -> INCOMPLETE (fi-bxt-t5700)
                pass       -> INCOMPLETE (fi-ivb-3520m)

running: igt/gem_cs_tlb/basic-default

[014/246] pass: 14 -
Build timed out (after 18 minutes). Marking the build as aborted.

Quoted 8 lines
[   96.771613] gem_cs_tlb: starting subtest basic-default
[   96.773567] general protection fault: 0000 [#1] PREEMPT SMP
[   96.773599] Modules linked in: snd_hda_intel i915 cdc_ncm usbnet mii x86_pkg_temp_thermal intel_powerclamp coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel lpc_ich snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_codec snd_hwdep snd_hda_core snd_pcm mei_me mei sdhci_pci sdhci mmc_core e1000e ptp pps_core [last unloaded: i915]
[   96.773775] CPU: 1 PID: 8922 Comm: gem_cs_tlb Tainted: G     U          4.8.0-CI-Patchwork_2698+ #1
[   96.773806] Hardware name: LENOVO 2356GCG/2356GCG, BIOS G7ET31WW (1.13 ) 07/02/2012
[   96.773833] task: ffff8801311ace40 task.stack: ffff880137654000
[   96.773854] RIP: 0010:[<ffffffff811cd432>]  [<ffffffff811cd432>] kfree+0x72/0x2e0

...

Please paste the full backtrace, it might throw a hint on what's going on. -Daniel

Quoted 39 lines
Quoted 19 lines

fi-bdw-5557u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-bsw-n3050     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-bxt-t5700     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-byt-j1900     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-byt-n2820     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-hsw-4770      total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-hsw-4770r     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-ilk-650       total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-ivb-3520m     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-ivb-3770      total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-kbl-7200u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-skl-6260u     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-skl-6700hq    total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0
fi-snb-2520m     total:15   pass:14   dwarn:0   dfail:0   fail:0   skip:0

Results at /archive/results/CI_IGT_test/Patchwork_2698/

Quoted 10 lines

75d9d28f7f5d0147ba35e956268c3a3c079dc754 drm-intel-nightly: 2016y-10m- 13d-09h-14m-05s UTC integration manifest
ae958d3 drm/i915: Trim sg table after creating it
c393824 lib/scatterlist: Add sg_trim_table
35fb691 drm/i915: Use i915_sg_create for dmabuf 215eb9b drm/i915: Use i915_sg_create for rotated pages view
845b775 drm/i915: Use i915_sg_create for partial views
393cad6 drm/i915: Use i915_sg_create for userptr 0e4b44a drm/i915: Extract sg creation into a helper

Jani Saarinen
Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo

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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw

Re: ✗ Fi.CI.BAT: failure for Save megabytes of wasted sg entries

Quoted 41 lines · Daniel Vetter
Quoted 32 lines · Jani
Quoted 12 lines

== Series Details ==

Series: Save megabytes of wasted sg entries
URL : https://patchwork.freedesktop.org/series/13706/
State : failure

== Summary ==

Series 13706v1 Save megabytes of wasted sg entries
https://patchwork.freedesktop.org/api/1.0/series/13706/revisions/1/mbox/

Test gem_cs_tlb:

Quoted 15 lines
         Subgroup basic-default:
                 pass       -> INCOMPLETE (fi-bsw-n3050)
                 pass       -> INCOMPLETE (fi-byt-n2820)
                 pass       -> INCOMPLETE (fi-hsw-4770r)
                 pass       -> INCOMPLETE (fi-skl-6260u)
                 pass       -> INCOMPLETE (fi-ivb-3770)
                 pass       -> INCOMPLETE (fi-kbl-7200u)
                 pass       -> INCOMPLETE (fi-skl-6700hq)
                 pass       -> INCOMPLETE (fi-bdw-5557u)
                 pass       -> INCOMPLETE (fi-ilk-650)
                 pass       -> INCOMPLETE (fi-hsw-4770)
                 pass       -> INCOMPLETE (fi-byt-j1900)
                 pass       -> INCOMPLETE (fi-snb-2520m)
                 pass       -> INCOMPLETE (fi-bxt-t5700)
                 pass       -> INCOMPLETE (fi-ivb-3520m)

running: igt/gem_cs_tlb/basic-default

[014/246] pass: 14 -
Build timed out (after 18 minutes). Marking the build as aborted.

Quoted 8 lines
[   96.771613] gem_cs_tlb: starting subtest basic-default
[   96.773567] general protection fault: 0000 [#1] PREEMPT SMP
[   96.773599] Modules linked in: snd_hda_intel i915 cdc_ncm usbnet mii x86_pkg_temp_thermal intel_powerclamp coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel lpc_ich snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_codec snd_hwdep snd_hda_core snd_pcm mei_me mei sdhci_pci sdhci mmc_core e1000e ptp pps_core [last unloaded: i915]
[   96.773775] CPU: 1 PID: 8922 Comm: gem_cs_tlb Tainted: G     U          4.8.0-CI-Patchwork_2698+ #1
[   96.773806] Hardware name: LENOVO 2356GCG/2356GCG, BIOS G7ET31WW (1.13 ) 07/02/2012
[   96.773833] task: ffff8801311ace40 task.stack: ffff880137654000
[   96.773854] RIP: 0010:[<ffffffff811cd432>]  [<ffffffff811cd432>] kfree+0x72/0x2e0

...

Quoted 1 line

Please paste the full backtrace, it might throw a hint on what's going on.

It was just a RFC, I even labelled it as broken. Just wanted to send it out for feedback on the general approach since I was unsure when I will get back to debugging it.

It is most certainly a bug in my sg_table_trim implementation. :)

[   67.205081] general protection fault: 0000 [#1] PREEMPT SMP
[   67.205115] Modules linked in: snd_hda_intel i915 intel_powerclamp coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_hda_codec snd_hwdep snd_hda_core snd_pcm mei_me mei lpc_ich e1000e ptp pps_core [last unloaded: i915]
[   67.205284] CPU: 2 PID: 7725 Comm: gem_cs_tlb Tainted: G     U          4.8.0-CI-Patchwork_2698+ #1
[   67.205315] Hardware name: Hewlett-Packard HP Compaq 8100 Elite SFF PC/304Ah, BIOS 786H1 v01.05 06/09/2010
[   67.205347] task: ffff88020a68a600 task.stack: ffff880207708000
[   67.205370] RIP: 0010:[<ffffffff811cd432>]  [<ffffffff811cd432>] kfree+0x72/0x2e0
[   67.205404] RSP: 0018:ffff88020770bc30  EFLAGS: 00010203
[   67.205425] RAX: ffffea0000000000 RBX: 6b6b6b6b6b6b6b68 RCX: 0000000000000002
[   67.205450] RDX: 0000000080000002 RSI: ffffffff81c595f0 RDI: ffff88020a68ae28
[   67.205476] RBP: ffff88020770bc58 R08: ffffea0008239c20 R09: 0000000000000001
[   67.205501] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000087654321
[   67.205527] R13: ffffffff814392a6 R14: 01ad998dadadad80 R15: 0000000000000000
[   67.205553] FS:  00007ff7454d4740(0000) GS:ffff88021bc80000(0000) knlGS:0000000000000000
[   67.205581] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   67.205602] CR2: 00000000019273f8 CR3: 00000002102a2000 CR4: 00000000000006e0
[   67.205627] Stack:
[   67.205638]  ffff88020cc062c8 0000000087654321 000000000000012f 0000000000000036
[   67.205678]  0000000000000000 ffff88020770bc90 ffffffff814392a6 ffff88020cc062c8
[   67.205717]  ffff880208d8a420 0000000000021292 0000000000000000 ffff880209a35dc0
[   67.205757] Call Trace:
[   67.205772]  [<ffffffff814392a6>] sg_trim_table+0x96/0xe0
[   67.205808]  [<ffffffffa03569c8>] i915_sg_complete+0x38/0x40 [i915]
[   67.205844]  [<ffffffffa0356ae5>] i915_gem_object_get_pages_gtt+0xe5/0x340 [i915]
[   67.205884]  [<ffffffffa0356d7c>] i915_gem_object_get_pages+0x3c/0xb0 [i915]
[   67.205922]  [<ffffffffa035844b>] i915_gem_object_set_to_gtt_domain+0x3b/0x290 [i915]
[   67.205963]  [<ffffffffa03592d8>] i915_gem_set_domain_ioctl+0x108/0x130 [i915]
[   67.205991]  [<ffffffff815488a6>] drm_ioctl+0x1f6/0x480
[   67.206024]  [<ffffffffa03591d0>] ? i915_gem_obj_prepare_shmem_write+0x170/0x170 [i915]
[   67.206054]  [<ffffffff810eaa6d>] ? debug_lockdep_rcu_enabled+0x1d/0x20
[   67.206080]  [<ffffffff811fe76e>] do_vfs_ioctl+0x8e/0x690
[   67.206102]  [<ffffffff810d4372>] ? trace_hardirqs_on_caller+0x122/0x1b0
[   67.206126]  [<ffffffff811fedac>] SyS_ioctl+0x3c/0x70
[   67.206150]  [<ffffffff8180faa9>] entry_SYSCALL_64_fastpath+0x1c/0xac
[   67.206173] Code: 00 00 00 80 ff 77 00 00 49 01 de 48 0f 42 05 f6 db c3 00 49 01 c6 48 b8 00 00 00 00 00 ea ff ff 49 c1 ee 0c 49 c1 e6 06 49 01 c6 <49> 8b 46 20 48 8d 50 ff a8 01 4c 0f 45 f2 49 8b 56 20 48 8d 42
[   67.206487] RIP  [<ffffffff811cd432>] kfree+0x72/0x2e0
[   67.206512]  RSP <ffff88020770bc30>
[   67.206551] ---[ end trace 8401cce8db339cc8 ]---

Regards,

Tvrtko

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