Skip to contentSkip to conversation

drm/i915 : Reduce the shmem page allocation time by using blitter engines for clearing pages.

RFC In review [email protected] 3 participants 8 messages May 6, 2014 – May 7, 2014

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

RFC 1/1 drm/i915 : Reduce the shmem page allocation time by using blitter engines for clearing pages.

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

This patch aims to reduce the allocation time of pages from shmem by using blitter engines for clearing the pages freshly alloced. This is utilized in case of fresh pages allocated in shmem_preallocate routines in execbuffer path and page_fault path only.

Even though the CPU memset routine is optimized, but still sometimes the time consumed in clearing the pages of a large buffer comes in the order of milliseconds.
We intend to make this operation asynchronous by using blitter engine, so irrespective of the size of buffer to be cleared, the execbuffer ioctl processing time will not be affected. Use of blitter engine will make the overall execution time of 'execbuffer' ioctl lesser for large buffers.

There may be power implications here on using blitter engines, and we have to evaluate this. As a next step, we can selectively enable this HW based memset only for large buffers, where the overhead of adding commands in a blitter ring(which will otherwise be idle), cross ring synchronization, will be negligible compared to using the CPU to clear out the buffer.

---
 drivers/gpu/drm/i915/i915_drv.h            |  6 +++
 drivers/gpu/drm/i915/i915_gem.c            | 80 +++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 43 ++++++++++++++++
 include/linux/shmem_fs.h                   |  2 +
 mm/shmem.c                                 | 44 +++++++++++++++-
 5 files changed, 173 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +6 -0
index 6dc579a..c3844da 100644
@@ -1596,6 +1596,10 @@ struct drm_i915_gem_object {
 	unsigned int has_aliasing_ppgtt_mapping:1;
 	unsigned int has_global_gtt_mapping:1;
 	unsigned int has_dma_mapping:1;
+	/*
+	 * Do the pages of object need to be cleared after shmem allocation
+	 */
+	unsigned int require_clear:1;
 
 	struct sg_table *pages;
 	int pages_pin_count;
@@ -2120,6 +2124,8 @@ int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
 		      uint32_t handle, uint64_t *offset);
 void
 i915_gem_object_shmem_preallocate(struct drm_i915_gem_object *obj);
+int i915_add_clear_obj_cmd(struct drm_i915_gem_object *obj);
+int i915_gem_memset_obj_hw(struct drm_i915_gem_object *obj);
 
 /**
  * Returns true if seq1 is later than seq2.
drivers/gpu/drm/i915/i915_gem.c +79 -1

109 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_execbuffer.c +43 -0

55 lines not on this page · raw message

include/linux/shmem_fs.h +2 -0
index 4d1771c..ac976c8 100644
@@ -55,6 +55,8 @@ extern bool shmem_mapping(struct address_space *mapping);
 extern void shmem_unlock_mapping(struct address_space *mapping);
 extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
 					pgoff_t index, gfp_t gfp_mask);
+extern struct page *shmem_read_mapping_page_gfp_noclear(struct address_space *mapping,
+					pgoff_t index, gfp_t gfp_mask);
 extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
 extern int shmem_unuse(swp_entry_t entry, struct page *page);
 
mm/shmem.c +43 -1

59 lines not on this page · raw message

Signature · 1 line
1.8.5.1
#1 lore raw
Quoted 20 lines · On Tue, May 06, 2014 at 04:40:58PM +0530, [email protected] wrote:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

This patch aims to reduce the allocation time of pages from shmem by using blitter engines for clearing the pages freshly alloced. This is utilized in case of fresh pages allocated in shmem_preallocate routines in execbuffer path and page_fault path only.

Even though the CPU memset routine is optimized, but still sometimes the time consumed in clearing the pages of a large buffer comes in the order of milliseconds.
We intend to make this operation asynchronous by using blitter engine, so irrespective of the size of buffer to be cleared, the execbuffer ioctl processing time will not be affected. Use of blitter engine will make the overall execution time of 'execbuffer' ioctl lesser for large buffers.

Quoted 6 lines

There may be power implications here on using blitter engines, and we have to evaluate this. As a next step, we can selectively enable this HW based memset only for large buffers, where the overhead of adding commands in a blitter ring(which will otherwise be idle), cross ring synchronization, will be negligible compared to using the CPU to clear out the buffer.

You leave a lot of holes by which you leak the uncleared pages to userspace.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
Quoted 28 lines · Chris Wilson
Quoted 20 lines · On Tue, May 06, 2014 at 04:40:58PM +0530, [email protected] wrote:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

This patch aims to reduce the allocation time of pages from shmem by using blitter engines for clearing the pages freshly alloced. This is utilized in case of fresh pages allocated in shmem_preallocate routines in execbuffer path and page_fault path only.

Even though the CPU memset routine is optimized, but still sometimes the time consumed in clearing the pages of a large buffer comes in the order of milliseconds.
We intend to make this operation asynchronous by using blitter engine, so irrespective of the size of buffer to be cleared, the execbuffer ioctl processing time will not be affected. Use of blitter engine will make the overall execution time of 'execbuffer' ioctl lesser for large buffers.

Quoted 6 lines

There may be power implications here on using blitter engines, and we have to evaluate this. As a next step, we can selectively enable this HW based memset only for large buffers, where the overhead of adding commands in a blitter ring(which will otherwise be idle), cross ring synchronization, will be negligible compared to using the CPU to clear out the buffer.

Quoted 4 lines

You leave a lot of holes by which you leak the uncleared pages to userspace.
-Chris

Hi Chris,

Are you ok with the overall design as such, and the shmem_read_mapping_page_gfp_noclear interface?
Is the leak of uncleared pages happening due to implementation issues? If so, we'll try to mitigate them.

Regards,
Sourab

#3 lore raw
Quoted 33 lines · Sourab
Quoted 28 lines · Chris Wilson
Quoted 20 lines · On Tue, May 06, 2014 at 04:40:58PM +0530, [email protected] wrote:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

This patch aims to reduce the allocation time of pages from shmem by using blitter engines for clearing the pages freshly alloced. This is utilized in case of fresh pages allocated in shmem_preallocate routines in execbuffer path and page_fault path only.

Even though the CPU memset routine is optimized, but still sometimes the time consumed in clearing the pages of a large buffer comes in the order of milliseconds.
We intend to make this operation asynchronous by using blitter engine, so irrespective of the size of buffer to be cleared, the execbuffer ioctl processing time will not be affected. Use of blitter engine will make the overall execution time of 'execbuffer' ioctl lesser for large buffers.

Quoted 6 lines

There may be power implications here on using blitter engines, and we have to evaluate this. As a next step, we can selectively enable this HW based memset only for large buffers, where the overhead of adding commands in a blitter ring(which will otherwise be idle), cross ring synchronization, will be negligible compared to using the CPU to clear out the buffer.

Quoted 4 lines

You leave a lot of holes by which you leak the uncleared pages to userspace.
-Chris

Quoted 6 lines

Hi Chris,

Are you ok with the overall design as such, and the shmem_read_mapping_page_gfp_noclear interface?
Is the leak of uncleared pages happening due to implementation issues? If so, we'll try to mitigate them.

Actually, along similar lines there is an even more fundamental issue. You should only clear the objects if the pages have not been prepopulated.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw
Quoted 41 lines · Chris Wilson
Quoted 33 lines · Sourab
Quoted 28 lines · Chris Wilson
Quoted 20 lines · On Tue, May 06, 2014 at 04:40:58PM +0530, [email protected] wrote:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

This patch aims to reduce the allocation time of pages from shmem by using blitter engines for clearing the pages freshly alloced. This is utilized in case of fresh pages allocated in shmem_preallocate routines in execbuffer path and page_fault path only.

Even though the CPU memset routine is optimized, but still sometimes the time consumed in clearing the pages of a large buffer comes in the order of milliseconds.
We intend to make this operation asynchronous by using blitter engine, so irrespective of the size of buffer to be cleared, the execbuffer ioctl processing time will not be affected. Use of blitter engine will make the overall execution time of 'execbuffer' ioctl lesser for large buffers.

Quoted 6 lines

There may be power implications here on using blitter engines, and we have to evaluate this. As a next step, we can selectively enable this HW based memset only for large buffers, where the overhead of adding commands in a blitter ring(which will otherwise be idle), cross ring synchronization, will be negligible compared to using the CPU to clear out the buffer.

Quoted 4 lines

You leave a lot of holes by which you leak the uncleared pages to userspace.
-Chris

Quoted 6 lines

Hi Chris,

Are you ok with the overall design as such, and the shmem_read_mapping_page_gfp_noclear interface?
Is the leak of uncleared pages happening due to implementation issues? If so, we'll try to mitigate them.

Quoted 5 lines

Actually, along similar lines there is an even more fundamental issue. You should only clear the objects if the pages have not been prepopulated.
-Chris

Hi Chris,
This patch is in continuation of the shmem preallocate patch sent by Akash earlier.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044597.html)
We employ this method only in case of the preallocate routine, which will be called in the first page fault of the object resulting in fresh allocation of pages.
This is controlled by means of a flag 'require_clear' which is set in preallocate routine(which will be come into picture only in case of fresh allocation). If pages are already populated for the object, this won't come into picture.
Also, we'll try to fix the leak of uncleared pages due to any implementation issues.

Regards,
Sourab

#5 lore raw
In reply to [email protected]
Quoted 5 lines · [email protected] writes:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

One of userspace's assumptions is that when you allocate a new BO, you can map it and start writing data into it without needing to wait on the GPU. I expect this patch to mostly hurt performance on apps (and I note that the patch doesn't come with any actual performance data) that get more stalls as a result.

More importantly, though, it breaks existing userspace that relies on buffers being idle on allocation, for the unsychronized maps used in intel_bufferobj_subdata() and intel_bufferobj_map_range(GL_INVALIDATE_BUFFER_BIT | GL_UNSYNCHRONIZED_BIT)

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

#6 lore raw
Quoted 8 lines · Eric Anholt
Quoted 5 lines · [email protected] writes:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

Quoted 6 lines

One of userspace's assumptions is that when you allocate a new BO, you can map it and start writing data into it without needing to wait on the GPU. I expect this patch to mostly hurt performance on apps (and I note that the patch doesn't come with any actual performance data) that get more stalls as a result.

Hi Eric,
Yes, it may hurt the performance on apps, in case of small buffers and if blitter engine is busy as there is a synchronous wait for rendering in the gem_fault handler. If that is the case, we can drop this from the gem_fault routine and employ it only in the do_execbuffer routine. Its useful there because there is no synchronous wait required in sw, due to cross ring synchronization.
We'll gather the numbers to quantify the performance benefit we have while using blitter engines in this way for different buffer sizes.

Quoted 5 lines

More importantly, though, it breaks existing userspace that relies on buffers being idle on allocation, for the unsychronized maps used in intel_bufferobj_subdata() and intel_bufferobj_map_range(GL_INVALIDATE_BUFFER_BIT | GL_UNSYNCHRONIZED_BIT)

Sorry, I miss your point here. It may not break this assumption due to the fact that we employ this method only in case of the preallocate routine, which will be called in the first page fault of the object (gem_fault handler) resulting in fresh allocation of pages.

So, in case of unsynchronized maps, there may be a wait involved in the first page fault. Also, that wait time may be lesser than the time required for CPU memset (resulting in no performance hit). There won't be any subsequent waits afterwards for that buffer object.

Though, we'll have performance hit in the case when blitter engine is already busy and may not be available to immediately start the memset of freshly allocated mmaped buffers.

Am I missing something here? Does the userspace requirement for unsynchronized mapped objects involve complete idleness of object on gpu even when object page faults for the first time?

Regards,
Sourab

#7 lore raw
Quoted 42 lines · Sourab
Quoted 8 lines · Eric Anholt
Quoted 5 lines · [email protected] writes:

From: Sourab Gupta <[email protected]>

This patch is in continuation of and is dependent on earlier patch series to 'reduce the time for which device mutex is kept locked'.
(http://lists.freedesktop.org/archives/intel-gfx/2014-May/044596.html)

Quoted 6 lines

One of userspace's assumptions is that when you allocate a new BO, you can map it and start writing data into it without needing to wait on the GPU. I expect this patch to mostly hurt performance on apps (and I note that the patch doesn't come with any actual performance data) that get more stalls as a result.

Hi Eric,
Yes, it may hurt the performance on apps, in case of small buffers and if blitter engine is busy as there is a synchronous wait for rendering in the gem_fault handler. If that is the case, we can drop this from the gem_fault routine and employ it only in the do_execbuffer routine. Its useful there because there is no synchronous wait required in sw, due to cross ring synchronization.
We'll gather the numbers to quantify the performance benefit we have while using blitter engines in this way for different buffer sizes.

Quoted 5 lines

More importantly, though, it breaks existing userspace that relies on buffers being idle on allocation, for the unsychronized maps used in intel_bufferobj_subdata() and intel_bufferobj_map_range(GL_INVALIDATE_BUFFER_BIT | GL_UNSYNCHRONIZED_BIT)

Sorry, I miss your point here. It may not break this assumption due to the fact that we employ this method only in case of the preallocate routine, which will be called in the first page fault of the object (gem_fault handler) resulting in fresh allocation of pages.

So, in case of unsynchronized maps, there may be a wait involved in the first page fault. Also, that wait time may be lesser than the time required for CPU memset (resulting in no performance hit). There won't be any subsequent waits afterwards for that buffer object.

Quoted 7 lines

Though, we'll have performance hit in the case when blitter engine is already busy and may not be available to immediately start the memset of freshly allocated mmaped buffers.

Am I missing something here? Does the userspace requirement for unsynchronized mapped objects involve complete idleness of object on gpu even when object page faults for the first time?

Oh, I mised how this works. So at pagefault time, you're firing off the blit, then immediately stalling on it? This sounds even less like a possible performance win than I was initially thinking.

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