Skip to contentSkip to conversation

Add native sync support to i915 driver

RFC In review [email protected] 6 participants 23 messages Jan 13, 2016 – Jan 21, 2016

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

cover Add native sync support to i915 driver

From: John Harrison <[email protected]>

This patch set was originally part of the struct fence and scheduler patch sets. However, it relies on de-staging the sync framework and that is now being done by another group. Hence these patches had to be split out into a separate series that can be merged after the de-stage has happened.

Note that for the time being, this patch set also includes the de-staging work because otherwise the rest of the patches will not apply. Hence it is being set as an RFC rather than PATCH as the expectation is those patches will need to be dropped and the remainder rebased.

What the patch series does is to add support for user land sync points to the i915 driver (such as Android native syncs and dma-buff syncs). That allows exernal applications/libraries/drivers to asynchronously submit and/or track GPU work. That is, a batch buffer can be submitted to the i915 driver with a sync point attached which means that the work will not actually be sent to the hardware until that sync point has been signalled. Likewise, a sync point can be requested such that when the batch buffer has completed on the hardware the sync point will be signalled by the i915 driver.

This allows long chains of interdependent work to be submitted to various drivers without the CPU having to wait between steps. E.g. a video frame can be captured, used as an OGL texture and displayed to the screen all as a single 'fire and forget' operation.

v1: New patch series put together from patches that were previously part of two different patch sets. Hence version numbers in individual patches have been change to 0.x for revisions when in previous series.

[Patches against drm-intel-nightly tree fetched 17/11/2015 with struct fence conversion and scheduler patches applied]

John Harrison (6):
staging/android/sync: Move sync framework out of staging android/sync: Improved debug dump to dmesg
drm/i915: Add sync framework support to execbuff IOCTL drm/i915: Add sync wait support to scheduler
drm/i915: Connecting execbuff fences to scheduler drm/i915: Add sync support to the scheduler statistics and status dump

Maarten Lankhorst (2):
staging/android/sync: Support sync points created from dma-fences staging/android/sync: add sync_fence_create_dma

Peter Lawthers (1):
android/sync: Fix reversed sense of signaled fence

 drivers/android/Kconfig                    |  28 ++
 drivers/android/Makefile                   |   2 +
 drivers/android/sw_sync.c                  | 260 ++++++++++
 drivers/android/sw_sync.h                  |  59 +++
 drivers/android/sync.c                     | 739 +++++++++++++++++++++++++++++
 drivers/android/sync.h                     | 388 +++++++++++++++
 drivers/android/sync_debug.c               | 280 +++++++++++
 drivers/android/trace/sync.h               |  82 ++++
 drivers/gpu/drm/i915/Kconfig               |   3 +
 drivers/gpu/drm/i915/i915_debugfs.c        |   4 +
 drivers/gpu/drm/i915/i915_drv.h            |   8 +
 drivers/gpu/drm/i915/i915_gem.c            |  90 +++-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 123 ++++-
 drivers/gpu/drm/i915/i915_scheduler.c      | 163 ++++++-
 drivers/gpu/drm/i915/i915_scheduler.h      |  11 +
 drivers/staging/android/Kconfig            |  28 --
 drivers/staging/android/Makefile           |   2 -
 drivers/staging/android/sw_sync.c          | 260 ----------
 drivers/staging/android/sw_sync.h          |  59 ---
 drivers/staging/android/sync.c             | 729 ----------------------------
 drivers/staging/android/sync.h             | 356 --------------
 drivers/staging/android/sync_debug.c       | 254 ----------
 drivers/staging/android/trace/sync.h       |  82 ----
 drivers/staging/android/uapi/sw_sync.h     |  32 --
 drivers/staging/android/uapi/sync.h        |  97 ----
 include/uapi/Kbuild                        |   1 +
 include/uapi/drm/i915_drm.h                |  16 +-
 include/uapi/sync/Kbuild                   |   3 +
 include/uapi/sync/sw_sync.h                |  32 ++
 include/uapi/sync/sync.h                   |  97 ++++
 30 files changed, 2373 insertions(+), 1915 deletions(-)
 create mode 100644 drivers/android/sw_sync.c
 create mode 100644 drivers/android/sw_sync.h
 create mode 100644 drivers/android/sync.c
 create mode 100644 drivers/android/sync.h
 create mode 100644 drivers/android/sync_debug.c
 create mode 100644 drivers/android/trace/sync.h
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sw_sync.h
 delete mode 100644 drivers/staging/android/sync.c
 delete mode 100644 drivers/staging/android/sync.h
 delete mode 100644 drivers/staging/android/sync_debug.c
 delete mode 100644 drivers/staging/android/trace/sync.h
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h
 delete mode 100644 drivers/staging/android/uapi/sync.h
 create mode 100644 include/uapi/sync/Kbuild
 create mode 100644 include/uapi/sync/sw_sync.h
 create mode 100644 include/uapi/sync/sync.h
Signature · 6 lines
1.9.1

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

RFC 1/9 staging/android/sync: Support sync points created from dma-fences

From: Maarten Lankhorst <[email protected]>

Debug output assumes all sync points are built on top of Android sync points and when we start creating them from dma-fences will NULL ptr deref unless taught about this.

v0.4: Corrected patch ownership.

v0.5: Removed redundant braces to keep style checker happy

Cc Maarten Lankhorst <[email protected]>
Cc Riley Andrews <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Gustavo Padovan <[email protected]>
---
 drivers/staging/android/sync_debug.c | 45 ++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 22 deletions(-)
drivers/staging/android/sync_debug.c +23 -22
index 91ed2c4..02a1649 100644
@@ -82,36 +82,42 @@ static const char *sync_status_str(int status)
 	return "error";
 }
 
-static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence)
+static void sync_print_pt(struct seq_file *s, struct fence *pt, bool fence)
 {
 	int status = 1;
-	struct sync_timeline *parent = sync_pt_parent(pt);
 
-	if (fence_is_signaled_locked(&pt->base))
-		status = pt->base.status;
+	if (fence_is_signaled_locked(pt))
+		status = pt->status;
 
 	seq_printf(s, "  %s%spt %s",
-		   fence ? parent->name : "",
+		   fence && pt->ops->get_timeline_name ?
+		   pt->ops->get_timeline_name(pt) : "",
 		   fence ? "_" : "",
 		   sync_status_str(status));
 
 	if (status <= 0) {
 		struct timespec64 ts64 =
-			ktime_to_timespec64(pt->base.timestamp);
+			ktime_to_timespec64(pt->timestamp);
 
 		seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
 	}
 
-	if (parent->ops->timeline_value_str &&
-	    parent->ops->pt_value_str) {
+	if ((!fence || pt->ops->timeline_value_str) &&
+	    pt->ops->fence_value_str) {
 		char value[64];
+		bool success;
 
-		parent->ops->pt_value_str(pt, value, sizeof(value));
-		seq_printf(s, ": %s", value);
-		if (fence) {
-			parent->ops->timeline_value_str(parent, value,
-						    sizeof(value));
-			seq_printf(s, " / %s", value);
+		pt->ops->fence_value_str(pt, value, sizeof(value));
+		success = strlen(value);
+
+		if (success)
+			seq_printf(s, ": %s", value);
+
+		if (success && fence) {
+			pt->ops->timeline_value_str(pt, value, sizeof(value));
+
+			if (strlen(value))
+				seq_printf(s, " / %s", value);
 		}
 	}
 
@@ -138,7 +144,7 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
 	list_for_each(pos, &obj->child_list_head) {
 		struct sync_pt *pt =
 			container_of(pos, struct sync_pt, child_list);
-		sync_print_pt(s, pt, false);
+		sync_print_pt(s, &pt->base, false);
 	}
 	spin_unlock_irqrestore(&obj->child_list_lock, flags);
 }
@@ -152,13 +158,8 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence)
 	seq_printf(s, "[%p] %s: %s\n", fence, fence->name,
 		   sync_status_str(atomic_read(&fence->status)));
 
-	for (i = 0; i < fence->num_fences; ++i) {
-		struct sync_pt *pt =
-			container_of(fence->cbs[i].sync_pt,
-				     struct sync_pt, base);
-
-		sync_print_pt(s, pt, true);
-	}
+	for (i = 0; i < fence->num_fences; ++i)
+		sync_print_pt(s, fence->cbs[i].sync_pt, true);
 
 	spin_lock_irqsave(&fence->wq.lock, flags);
 	list_for_each_entry(pos, &fence->wq.task_list, task_list) {
Signature · 6 lines
1.9.1

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

RFC 2/9 staging/android/sync: add sync_fence_create_dma

In reply to [email protected]

From: Maarten Lankhorst <[email protected]>

This allows users of dma fences to create a android fence.

v0.2: Added kerneldoc. (Tvrtko Ursulin).

v0.4: Updated comments from review feedback by Maarten.

Cc Maarten Lankhorst <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Jesse Barnes <[email protected]>
Cc Riley Andrews <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Gustavo Padovan <[email protected]>
---
 drivers/staging/android/sync.c | 13 +++++++++----
 drivers/staging/android/sync.h | 10 ++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)
drivers/staging/android/sync.c +9 -4
index f83e00c..7f0e919 100644
@@ -188,7 +188,7 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb)
 }
 
 /* TODO: implement a create which takes more that one sync_pt */
-struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt)
+struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 {
 	struct sync_fence *fence;
 
@@ -199,16 +199,21 @@ struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt)
 	fence->num_fences = 1;
 	atomic_set(&fence->status, 1);
 
-	fence->cbs[0].sync_pt = &pt->base;
+	fence->cbs[0].sync_pt = pt;
 	fence->cbs[0].fence = fence;
-	if (fence_add_callback(&pt->base, &fence->cbs[0].cb,
-			       fence_check_cb_func))
+	if (fence_add_callback(pt, &fence->cbs[0].cb, fence_check_cb_func))
 		atomic_dec(&fence->status);
 
 	sync_fence_debug_add(fence);
 
 	return fence;
 }
+EXPORT_SYMBOL(sync_fence_create_dma);
+
+struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt)
+{
+	return sync_fence_create_dma(name, &pt->base);
+}
 EXPORT_SYMBOL(sync_fence_create);
 
 struct sync_fence *sync_fence_fdget(int fd)
drivers/staging/android/sync.h +10 -0
index 61f8a3a..afa0752 100644
@@ -254,6 +254,16 @@ void sync_pt_free(struct sync_pt *pt);
  */
 struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt);
 
+/**
+ * sync_fence_create_dma() - creates a sync fence from dma-fence
+ * @name:	name of fence to create
+ * @pt:	dma-fence to add to the fence
+ *
+ * Creates a fence containg @pt.  Once this is called, the fence takes
+ * ownership of @pt.
+ */
+struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt);
+
 /*
  * API for sync_fence consumers
  */
Signature · 6 lines
1.9.1

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

Re: [RFC 2/9] staging/android/sync: add sync_fence_create_dma

Hi John,

2016-01-13 [email protected] <[email protected]>:

Quoted 20 lines

From: Maarten Lankhorst <[email protected]>

This allows users of dma fences to create a android fence.

v0.2: Added kerneldoc. (Tvrtko Ursulin).

v0.4: Updated comments from review feedback by Maarten.

Cc Maarten Lankhorst <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Jesse Barnes <[email protected]>
Cc Riley Andrews <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Gustavo Padovan <[email protected]>
Quoted 4 lines
---
 drivers/staging/android/sync.c | 13 +++++++++----
 drivers/staging/android/sync.h | 10 ++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)

Patch 1 and 2 are already upstream in staging-next. You are missing a rebase probably.

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

#4 lore raw

RFC 3/9 staging/android/sync: Move sync framework out of staging

In reply to [email protected]

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

v0.3: New patch for series.

Cc Gustavo Padovan <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Riley Andrews <[email protected]>
---
 drivers/android/Kconfig                |  28 ++
 drivers/android/Makefile               |   2 +
 drivers/android/sw_sync.c              | 260 ++++++++++++
 drivers/android/sw_sync.h              |  59 +++
 drivers/android/sync.c                 | 734 +++++++++++++++++++++++++++++++++
 drivers/android/sync.h                 | 366 ++++++++++++++++
 drivers/android/sync_debug.c           | 255 ++++++++++++
 drivers/android/trace/sync.h           |  82 ++++
 drivers/staging/android/Kconfig        |  28 --
 drivers/staging/android/Makefile       |   2 -
 drivers/staging/android/sw_sync.c      | 260 ------------
 drivers/staging/android/sw_sync.h      |  59 ---
 drivers/staging/android/sync.c         | 734 ---------------------------------
 drivers/staging/android/sync.h         | 366 ----------------
 drivers/staging/android/sync_debug.c   | 255 ------------
 drivers/staging/android/trace/sync.h   |  82 ----
 drivers/staging/android/uapi/sw_sync.h |  32 --
 drivers/staging/android/uapi/sync.h    |  97 -----
 include/uapi/Kbuild                    |   1 +
 include/uapi/sync/Kbuild               |   3 +
 include/uapi/sync/sw_sync.h            |  32 ++
 include/uapi/sync/sync.h               |  97 +++++
 22 files changed, 1919 insertions(+), 1915 deletions(-)
 create mode 100644 drivers/android/sw_sync.c
 create mode 100644 drivers/android/sw_sync.h
 create mode 100644 drivers/android/sync.c
 create mode 100644 drivers/android/sync.h
 create mode 100644 drivers/android/sync_debug.c
 create mode 100644 drivers/android/trace/sync.h
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sw_sync.h
 delete mode 100644 drivers/staging/android/sync.c
 delete mode 100644 drivers/staging/android/sync.h
 delete mode 100644 drivers/staging/android/sync_debug.c
 delete mode 100644 drivers/staging/android/trace/sync.h
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h
 delete mode 100644 drivers/staging/android/uapi/sync.h
 create mode 100644 include/uapi/sync/Kbuild
 create mode 100644 include/uapi/sync/sw_sync.h
 create mode 100644 include/uapi/sync/sync.h
drivers/android/Kconfig +28 -0
index bdfc6c6..9edcd8f 100644
@@ -32,6 +32,34 @@ config ANDROID_BINDER_IPC_32BIT
 
 	  Note that enabling this will break newer Android user-space.
 
+config SYNC
+	bool "Synchronization framework"
+	default n
+	select ANON_INODES
+	select DMA_SHARED_BUFFER
+	---help---
+	  This option enables the framework for synchronization between multiple
+	  drivers.  Sync implementations can take advantage of hardware
+	  synchronization built into devices like GPUs.
+
+config SW_SYNC
+	bool "Software synchronization objects"
+	default n
+	depends on SYNC
+	---help---
+	  A sync object driver that uses a 32bit counter to coordinate
+	  synchronization.  Useful when there is no hardware primitive backing
+	  the synchronization.
+
+config SW_SYNC_USER
+	bool "Userspace API for SW_SYNC"
+	default n
+	depends on SW_SYNC
+	---help---
+	  Provides a user space API to the sw sync object.
+	  *WARNING* improper use of this can result in deadlocking kernel
+	  drivers from userspace.
+
 endif # if ANDROID
 
 endmenu
drivers/android/Makefile +2 -0
index 3b7e4b0..a1465dd 100644
@@ -1,3 +1,5 @@
 ccflags-y += -I$(src)			# needed for trace events
 
 obj-$(CONFIG_ANDROID_BINDER_IPC)	+= binder.o
+obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
+obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
drivers/android/sw_sync.c new file +260 -0

260 lines not on this page · raw message

drivers/android/sw_sync.h new file +59 -0

59 lines not on this page · raw message

drivers/android/sync.c new file +734 -0

734 lines not on this page · raw message

drivers/android/sync.h new file +366 -0

366 lines not on this page · raw message

drivers/android/sync_debug.c new file +255 -0

255 lines not on this page · raw message

drivers/android/trace/sync.h new file +82 -0

82 lines not on this page · raw message

drivers/staging/android/Kconfig +0 -28
index 42b1512..4b18fee 100644
@@ -38,34 +38,6 @@ config ANDROID_LOW_MEMORY_KILLER
 	  scripts (/init.rc), and it defines priority values with minimum free memory size
 	  for each priority.
 
-config SYNC
-	bool "Synchronization framework"
-	default n
-	select ANON_INODES
-	select DMA_SHARED_BUFFER
-	---help---
-	  This option enables the framework for synchronization between multiple
-	  drivers.  Sync implementations can take advantage of hardware
-	  synchronization built into devices like GPUs.
-
-config SW_SYNC
-	bool "Software synchronization objects"
-	default n
-	depends on SYNC
-	---help---
-	  A sync object driver that uses a 32bit counter to coordinate
-	  synchronization.  Useful when there is no hardware primitive backing
-	  the synchronization.
-
-config SW_SYNC_USER
-	bool "Userspace API for SW_SYNC"
-	default n
-	depends on SW_SYNC
-	---help---
-	  Provides a user space API to the sw sync object.
-	  *WARNING* improper use of this can result in deadlocking kernel
-	  drivers from userspace.
-
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
drivers/staging/android/Makefile +0 -2
index c7b6c99..355ad0e 100644
@@ -6,5 +6,3 @@ obj-$(CONFIG_ASHMEM)			+= ashmem.o
 obj-$(CONFIG_ANDROID_TIMED_OUTPUT)	+= timed_output.o
 obj-$(CONFIG_ANDROID_TIMED_GPIO)	+= timed_gpio.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)	+= lowmemorykiller.o
-obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
drivers/staging/android/sw_sync.c deleted +0 -260

260 lines not on this page · raw message

drivers/staging/android/sw_sync.h deleted +0 -59

59 lines not on this page · raw message

drivers/staging/android/sync.c deleted +0 -734

734 lines not on this page · raw message

drivers/staging/android/sync.h deleted +0 -366

113 lines not on this page · raw message

drivers/staging/android/sync_debug.c deleted +0 -255

255 lines not on this page · raw message

drivers/staging/android/trace/sync.h deleted +0 -82

82 lines not on this page · raw message

drivers/staging/android/uapi/sw_sync.h deleted +0 -32
deleted file mode 100644
index 9b5d486..0000000

Lines of this file are not shown. View the raw message.

drivers/staging/android/uapi/sync.h deleted +0 -97

97 lines not on this page · raw message

include/uapi/Kbuild +1 -0
index 245aa6e..7c415d0 100644

Lines of this file are not shown. View the raw message.

include/uapi/sync/Kbuild new file +3 -0
new file mode 100644
index 0000000..2716ffe

Lines of this file are not shown. View the raw message.

include/uapi/sync/sw_sync.h new file +32 -0
new file mode 100644
index 0000000..9b5d486

Lines of this file are not shown. View the raw message.

include/uapi/sync/sync.h new file +97 -0

97 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
1.9.1

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

Part of the diff is not shown here. View the raw message.

#5 lore raw

Re: [RFC 3/9] staging/android/sync: Move sync framework out of staging

Hi John,

2016-01-13 [email protected] <[email protected]>:

Quoted 5 lines

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

I also have been working on de-staging the sync framework, but I've taken the approach of cleaning up the sync framework first. e.g., I got rid of sync_pt and use struct fence directly, also sync_timeline is now fence_timeline and its ops are gone in favor of fence_ops. My current work is here:

https://git.kernel.org/cgit/linux/kernel/git/padovan/linux.git/log/?h=sync

My current plan is clean up patches, add commits messages and document the changes I've made and then it should be ready for a RFC.

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

#6 lore raw

Re: [RFC 3/9] staging/android/sync: Move sync framework out of staging

Quoted 15 lines · Gustavo Padovan

Hi John,

2016-01-13 [email protected] <[email protected]>:

Quoted 5 lines

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

I also have been working on de-staging the sync framework, but I've taken the approach of cleaning up the sync framework first. e.g., I got rid of sync_pt and use struct fence directly, also sync_timeline is now fence_timeline and its ops are gone in favor of fence_ops. My current work is here:

Quoted 6 lines

https://git.kernel.org/cgit/linux/kernel/git/padovan/linux.git/log/?h=sync

My current plan is clean up patches, add commits messages and document the changes I've made and then it should be ready for a RFC.

Gustavo

Hello,

Sounds good. I did note in my cover letter that these patches were only being posted to let people review the i915 side of the changes on a complete and working tree. Once we found out you were working on the de-stage the decision was to let you get on with it and not duplicate the effort here :). Note that patches four and five of this series are enhancements to the sync code rather than just de-staging it. Would they still be applicable to your new and improved version?

Do you have an expected time scale for when your patches will land?

Also, do you have any sort of overview document explaining what externally visible changes you are making and what the implications are for other drivers that are using the API?

Re the SW_SYNC_USER bits, we were just using that for a user land test program. The idea was to create an timeline external to the i915 driver and pass sync points in to i915 to be waited on and check that the i915 work itself only happens after the test signals the timeline appropriately. If this interface is going away, is there a plan to replace it with any other mechanism for doing similar? Or do we have to create some kind of dummy kernel module in order to get a testing timeline?

Thanks,
John.

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

#7 lore raw

Re: [RFC 3/9] staging/android/sync: Move sync framework out of staging

Hi John,

2016-01-14 John Harrison <[email protected]>:

Quoted 24 lines · Gustavo Padovan
Quoted 15 lines

Hi John,

2016-01-13 [email protected] <[email protected]>:

Quoted 5 lines

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

I also have been working on de-staging the sync framework, but I've taken the approach of cleaning up the sync framework first. e.g., I got rid of sync_pt and use struct fence directly, also sync_timeline is now fence_timeline and its ops are gone in favor of fence_ops. My current work is here:

Quoted 6 lines

https://git.kernel.org/cgit/linux/kernel/git/padovan/linux.git/log/?h=sync

My current plan is clean up patches, add commits messages and document the changes I've made and then it should be ready for a RFC.

Gustavo

Hello,

Quoted 7 lines

Sounds good. I did note in my cover letter that these patches were only being posted to let people review the i915 side of the changes on a complete and working tree. Once we found out you were working on the de-stage the decision was to let you get on with it and not duplicate the effort here :). Note that patches four and five of this series are enhancements to the sync code rather than just de-staging it. Would they still be applicable to your new and improved version?

Yes, with a small rework we can surely apply them on top of my changes.

Quoted 1 line

Do you have an expected time scale for when your patches will land?

I hope to send a RFC sometime next week, after that it will depend on how many comments and iterations I get from upstream.

Quoted 3 lines

Also, do you have any sort of overview document explaining what externally visible changes you are making and what the implications are for other drivers that are using the API?

Not yet. But I'll write one. In short: SW_SYNC didn't change from API point of view. And I replaced sync_timeline with fence_timeline and sync_pt with fence changing the respective functions name, e.g., sync_timeline_create is now fence_timeline_create.

Quoted 8 lines

Re the SW_SYNC_USER bits, we were just using that for a user land test program. The idea was to create an timeline external to the i915 driver and pass sync points in to i915 to be waited on and check that the i915 work itself only happens after the test signals the timeline appropriately. If this interface is going away, is there a plan to replace it with any other mechanism for doing similar? Or do we have to create some kind of dummy kernel module in order to get a testing timeline?

I've moved it to debugfs. You just need to point your test program to <debugfs>/sync/sw_sync and everything will continue to work.

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

#8 lore raw

Re: [RFC 3/9] staging/android/sync: Move sync framework out of staging

Quoted 35 lines · Gustavo Padovan

Hi John,

2016-01-14 John Harrison <[email protected]>:

Quoted 24 lines · Gustavo Padovan
Quoted 15 lines

Hi John,

2016-01-13 [email protected] <[email protected]>:

Quoted 5 lines

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

I also have been working on de-staging the sync framework, but I've taken the approach of cleaning up the sync framework first. e.g., I got rid of sync_pt and use struct fence directly, also sync_timeline is now fence_timeline and its ops are gone in favor of fence_ops. My current work is here:

Quoted 6 lines

https://git.kernel.org/cgit/linux/kernel/git/padovan/linux.git/log/?h=sync

My current plan is clean up patches, add commits messages and document the changes I've made and then it should be ready for a RFC.

Gustavo

Hello,

Quoted 7 lines

Sounds good. I did note in my cover letter that these patches were only being posted to let people review the i915 side of the changes on a complete and working tree. Once we found out you were working on the de-stage the decision was to let you get on with it and not duplicate the effort here :). Note that patches four and five of this series are enhancements to the sync code rather than just de-staging it. Would they still be applicable to your new and improved version?

Quoted 5 lines

Yes, with a small rework we can surely apply them on top of my changes.

Quoted 1 line

Do you have an expected time scale for when your patches will land?

I hope to send a RFC sometime next week, after that it will depend on how many comments and iterations I get from upstream.

Make sure to CC myself and hopefully I should be able to do some testing/reviewing for you.

Quoted 15 lines
Quoted 3 lines

Also, do you have any sort of overview document explaining what externally visible changes you are making and what the implications are for other drivers that are using the API?

Not yet. But I'll write one. In short: SW_SYNC didn't change from API point of view. And I replaced sync_timeline with fence_timeline and sync_pt with fence changing the respective functions name, e.g., sync_timeline_create is now fence_timeline_create.

Quoted 7 lines

Re the SW_SYNC_USER bits, we were just using that for a user land test program. The idea was to create an timeline external to the i915 driver and pass sync points in to i915 to be waited on and check that the i915 work itself only happens after the test signals the timeline appropriately. If this interface is going away, is there a plan to replace it with any other mechanism for doing similar? Or do we have to create some kind of dummy kernel module in order to get a testing timeline?

Quoted 2 lines

I've moved it to debugfs. You just need to point your test program to <debugfs>/sync/sw_sync and everything will continue to work.

Okay, that sounds easy enough :).

Daniel Vetter, do you see any issues with using this in an IGT test?

Quoted 2 lines

Gustavo

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

#9 lore raw

Re: [RFC 3/9] staging/android/sync: Move sync framework out of staging

In reply to [email protected]

2016-01-13 [email protected] <[email protected]>:

Quoted 81 lines

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

v0.3: New patch for series.

Cc Gustavo Padovan <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Riley Andrews <[email protected]>
---
 drivers/android/Kconfig                |  28 ++
 drivers/android/Makefile               |   2 +
 drivers/android/sw_sync.c              | 260 ++++++++++++
 drivers/android/sw_sync.h              |  59 +++
 drivers/android/sync.c                 | 734 +++++++++++++++++++++++++++++++++
 drivers/android/sync.h                 | 366 ++++++++++++++++
 drivers/android/sync_debug.c           | 255 ++++++++++++
 drivers/android/trace/sync.h           |  82 ++++
 drivers/staging/android/Kconfig        |  28 --
 drivers/staging/android/Makefile       |   2 -
 drivers/staging/android/sw_sync.c      | 260 ------------
 drivers/staging/android/sw_sync.h      |  59 ---
 drivers/staging/android/sync.c         | 734 ---------------------------------
 drivers/staging/android/sync.h         | 366 ----------------
 drivers/staging/android/sync_debug.c   | 255 ------------
 drivers/staging/android/trace/sync.h   |  82 ----
 drivers/staging/android/uapi/sw_sync.h |  32 --
 drivers/staging/android/uapi/sync.h    |  97 -----
 include/uapi/Kbuild                    |   1 +
 include/uapi/sync/Kbuild               |   3 +
 include/uapi/sync/sw_sync.h            |  32 ++
 include/uapi/sync/sync.h               |  97 +++++
 22 files changed, 1919 insertions(+), 1915 deletions(-)
 create mode 100644 drivers/android/sw_sync.c
 create mode 100644 drivers/android/sw_sync.h
 create mode 100644 drivers/android/sync.c
 create mode 100644 drivers/android/sync.h
 create mode 100644 drivers/android/sync_debug.c
 create mode 100644 drivers/android/trace/sync.h
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sw_sync.h
 delete mode 100644 drivers/staging/android/sync.c
 delete mode 100644 drivers/staging/android/sync.h
 delete mode 100644 drivers/staging/android/sync_debug.c
 delete mode 100644 drivers/staging/android/trace/sync.h
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h
 delete mode 100644 drivers/staging/android/uapi/sync.h
 create mode 100644 include/uapi/sync/Kbuild
 create mode 100644 include/uapi/sync/sw_sync.h
 create mode 100644 include/uapi/sync/sync.h
drivers/android/Kconfig +17 -0
index bdfc6c6..9edcd8f 100644
@@ -32,6 +32,34 @@ config ANDROID_BINDER_IPC_32BIT
 
 	  Note that enabling this will break newer Android user-space.
 
+config SYNC
+	bool "Synchronization framework"
+	default n
+	select ANON_INODES
+	select DMA_SHARED_BUFFER
+	---help---
+	  This option enables the framework for synchronization between multiple
+	  drivers.  Sync implementations can take advantage of hardware
+	  synchronization built into devices like GPUs.
+
+config SW_SYNC
+	bool "Software synchronization objects"
+	default n
+	depends on SYNC
+	---help---
+	  A sync object driver that uses a 32bit counter to coordinate
+	  synchronization.  Useful when there is no hardware primitive backing

drivers/android/Kconfig config ANDROID_BINDER_IPC_32BIT · line 61

Quoted 10 lines
drivers/android/Kconfig +10 -0
+	  the synchronization.
+
+config SW_SYNC_USER
+	bool "Userspace API for SW_SYNC"
+	default n
+	depends on SW_SYNC
+	---help---
+	  Provides a user space API to the sw sync object.
+	  *WARNING* improper use of this can result in deadlocking kernel
+	  drivers from userspace.

Also, SW_SYNC_USER is a way too dangerous to be upstreamed a /dev file because as the warning says it can deadlock the kernel. What I did in my patches was to move the sw_sync_user features to a debugfs file.

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

#10 lore raw

Re: [RFC 3/9] staging/android/sync: Move sync framework out of staging

In reply to [email protected]
Quoted 47 lines · On Wed, Jan 13, 2016 at 05:57:29PM +0000, [email protected] wrote:

From: John Harrison <[email protected]>

The sync framework is now used by the i915 driver. Therefore it can be moved out of staging and into the regular tree. Also, the public interfaces can actually be made public and exported.

v0.3: New patch for series.

Cc Gustavo Padovan <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Riley Andrews <[email protected]>
---
 drivers/android/Kconfig                |  28 ++
 drivers/android/Makefile               |   2 +
 drivers/android/sw_sync.c              | 260 ++++++++++++
 drivers/android/sw_sync.h              |  59 +++
 drivers/android/sync.c                 | 734 +++++++++++++++++++++++++++++++++
 drivers/android/sync.h                 | 366 ++++++++++++++++
 drivers/android/sync_debug.c           | 255 ++++++++++++
 drivers/android/trace/sync.h           |  82 ++++
 drivers/staging/android/Kconfig        |  28 --
 drivers/staging/android/Makefile       |   2 -
 drivers/staging/android/sw_sync.c      | 260 ------------
 drivers/staging/android/sw_sync.h      |  59 ---
 drivers/staging/android/sync.c         | 734 ---------------------------------
 drivers/staging/android/sync.h         | 366 ----------------
 drivers/staging/android/sync_debug.c   | 255 ------------
 drivers/staging/android/trace/sync.h   |  82 ----
 drivers/staging/android/uapi/sw_sync.h |  32 --
 drivers/staging/android/uapi/sync.h    |  97 -----
 include/uapi/Kbuild                    |   1 +
 include/uapi/sync/Kbuild               |   3 +
 include/uapi/sync/sw_sync.h            |  32 ++
 include/uapi/sync/sync.h               |  97 +++++
 22 files changed, 1919 insertions(+), 1915 deletions(-)
 create mode 100644 drivers/android/sw_sync.c
 create mode 100644 drivers/android/sw_sync.h
 create mode 100644 drivers/android/sync.c
 create mode 100644 drivers/android/sync.h
 create mode 100644 drivers/android/sync_debug.c
 create mode 100644 drivers/android/trace/sync.h
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sw_sync.h
 delete mode 100644 drivers/staging/android/sync.c
Quoted 8 lines
 delete mode 100644 drivers/staging/android/sync.h
 delete mode 100644 drivers/staging/android/sync_debug.c
 delete mode 100644 drivers/staging/android/trace/sync.h
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h
 delete mode 100644 drivers/staging/android/uapi/sync.h
 create mode 100644 include/uapi/sync/Kbuild
 create mode 100644 include/uapi/sync/sw_sync.h
 create mode 100644 include/uapi/sync/sync.h

Always create patches with the -M option, that shows files being moved instead of deleting and adding them, as a patch like this is impossible to read and ensure that nothing got changed in the move.

thanks,

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

#11 lore raw

RFC 4/9 android/sync: Improved debug dump to dmesg

In reply to [email protected]

From: John Harrison <[email protected]>

The sync code has a facility for dumping current state information via debugfs. It also has a way to re-use the same code for dumping to the kernel log on an internal error. However, the redirection was rather clunky and split the output across multiple prints at arbitrary boundaries. This made it difficult to read and could result in output from different sources being randomly interspersed.

This patch improves the redirection code to split the output on line feed boundaries instead. It also adds support for highlighting the offending fence object that caused the state dump in the first place.

v0.4: New patch in series.

v0.5: Twiddled white space and line wrapping to keep style checker happy.

Cc Gustavo Padovan <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Riley Andrews <[email protected]>
---
 drivers/android/sync.c       |  9 ++++++--
 drivers/android/sync.h       |  5 +++--
 drivers/android/sync_debug.c | 51 +++++++++++++++++++++++++++++++++-----------
 3 files changed, 48 insertions(+), 17 deletions(-)
drivers/android/sync.c +7 -2
index 7f0e919..db4a54b 100644
@@ -86,6 +86,11 @@ static void sync_timeline_put(struct sync_timeline *obj)
 
 void sync_timeline_destroy(struct sync_timeline *obj)
 {
+	if (!list_empty(&obj->active_list_head)) {
+		pr_info("destroying timeline with outstanding fences!\n");
+		sync_dump_timeline(obj);
+	}
+
 	obj->destroyed = true;
 	/*
 	 * Ensure timeline is marked as destroyed before
@@ -397,7 +402,7 @@ int sync_fence_wait(struct sync_fence *fence, long timeout)
 		if (timeout) {
 			pr_info("fence timeout on [%p] after %dms\n", fence,
 				jiffies_to_msecs(timeout));
-			sync_dump();
+			sync_dump(fence);
 		}
 		return -ETIME;
 	}
@@ -405,7 +410,7 @@ int sync_fence_wait(struct sync_fence *fence, long timeout)
 	ret = atomic_read(&fence->status);
 	if (ret) {
 		pr_info("fence error %ld on [%p]\n", ret, fence);
-		sync_dump();
+		sync_dump(fence);
 	}
 	return ret;
 }
drivers/android/sync.h +3 -2
index 4ccff01..d57fa0a 100644
@@ -351,14 +351,15 @@ void sync_timeline_debug_add(struct sync_timeline *obj);
 void sync_timeline_debug_remove(struct sync_timeline *obj);
 void sync_fence_debug_add(struct sync_fence *fence);
 void sync_fence_debug_remove(struct sync_fence *fence);
-void sync_dump(void);
+void sync_dump(struct sync_fence *fence);
+void sync_dump_timeline(struct sync_timeline *timeline);
 
 #else
 # define sync_timeline_debug_add(obj)
 # define sync_timeline_debug_remove(obj)
 # define sync_fence_debug_add(fence)
 # define sync_fence_debug_remove(fence)
-# define sync_dump()
+# define sync_dump(fence)
 #endif
 int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode,
 				 int wake_flags, void *key);
drivers/android/sync_debug.c +38 -13

66 lines not on this page · raw message

Signature · 6 lines
1.9.1

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

RFC 5/9 android/sync: Fix reversed sense of signaled fence

In reply to [email protected]

From: Peter Lawthers <[email protected]>

In the 3.14 kernel, a signaled fence was indicated by the status field == 1. In 4.x, a status == 0 indicates signaled, status < 0 indicates error, and status > 0 indicates active.

This patch wraps the check for a signaled fence in a function so that callers no longer needs to know the underlying implementation.

v0.3: New patch for series.

Tracked-On: https://jira01.devtools.intel.com/browse/ACD-308

Cc Gustavo Padovan <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Riley Andrews <[email protected]>
---
 drivers/android/sync.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/android/sync.h +21 -0
index d57fa0a..75532d8 100644
@@ -345,6 +345,27 @@ int sync_fence_cancel_async(struct sync_fence *fence,
  */
 int sync_fence_wait(struct sync_fence *fence, long timeout);
 
+/**
+ * sync_fence_is_signaled() - Return an indication if the fence is signaled
+ * @fence:	fence to check
+ *
+ * returns 1 if fence is signaled
+ * returns 0 if fence is not signaled
+ * returns < 0 if fence is in error state
+ */
+static inline int
+sync_fence_is_signaled(struct sync_fence *fence)
+{
+	int status;
+
+	status = atomic_read(&fence->status);
+	if (status == 0)
+		return 1;
+	if (status > 0)
+		return 0;
+	return status;
+}
+
 #ifdef CONFIG_DEBUG_FS
 
 void sync_timeline_debug_add(struct sync_timeline *obj);
Signature · 6 lines
1.9.1

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

RFC 6/9 drm/i915: Add sync framework support to execbuff IOCTL

In reply to [email protected]

From: John Harrison <[email protected]>

Various projects desire a mechanism for managing dependencies between work items asynchronously. This can also include work items across complete different and independent systems. For example, an application wants to retrieve a frame from a video in device, using it for rendering on a GPU then send it to the video out device for display all without having to stall waiting for completion along the way. The sync framework allows this. It encapsulates synchronisation events in file descriptors. The application can request a sync point for the completion of each piece of work. Drivers should also take sync points in with each new work request and not schedule the work to start until the sync has been signalled.

This patch adds sync framework support to the exec buffer IOCTL. A sync point can be passed in to stall execution of the batch buffer until signalled. And a sync point can be returned after each batch buffer submission which will be signalled upon that batch buffer's completion.

At present, the input sync point is simply waited on synchronously inside the exec buffer IOCTL call. Once the GPU scheduler arrives, this will be handled asynchronously inside the scheduler and the IOCTL can return without having to wait.

Note also that the scheduler will re-order the execution of batch buffers, e.g. because a batch buffer is stalled on a sync point and cannot be submitted yet but other, independent, batch buffers are being presented to the driver. This means that the timeline within the sync points returned cannot be global to the engine. Instead they must be kept per context per engine (the scheduler may not re-order batches within a context). Hence the timeline cannot be based on the existing seqno values but must be a new implementation.

This patch is a port of work by several people that has been pulled across from Android. It has been updated several times across several patches. Rather than attempt to port each individual patch, this version is the finished product as a single patch. The various contributors/authors along the way (in addition to myself) were:
Satyanantha RamaGopal M <[email protected]> Tvrtko Ursulin <[email protected]>
Michel Thierry <[email protected]>
Arun Siluvery <[email protected]>

v0.2: New patch in series.

v0.3: Updated to use the new 'sync_fence_is_signaled' API rather than having to know about the internal meaning of the 'fence::status' field (which recently got inverted!) [work by Peter Lawthers].

Updated after review comments by Daniel Vetter. Removed '#ifdef CONFIG_SYNC' and add 'select SYNC' to the Kconfig instead. Moved the fd installation of fences to the end of the execbuff call to in order to remove the need to use 'sys_close' to clean up on failure.

Updated after review comments by Tvrtko Ursulin. Remvoed the 'fence_external' flag as redundant. Covnerted DRM_ERRORs to DRM_DEBUGs. Changed one second wait to a wait forever when waiting on incoming fences.

v0.4: Re-instated missing return of fd to user land that somehow got lost in the anti-sys_close() re-factor.

v0.5: Correct typo in commit message. Twiddled white space and wrapped some long lines to keep style checker happy.

Corrected return codes, removed redundant test and added a descriptive comment to i915_early_fence_wait() - review feedback from Tvrtko.

Also, patch appears somewhat different in a few places due to being rebased after the scheduler patches rather than before.

For: VIZ-5190

---
 drivers/gpu/drm/i915/Kconfig               |   3 +
 drivers/gpu/drm/i915/i915_drv.h            |   7 ++
 drivers/gpu/drm/i915/i915_gem.c            |  90 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 100 +++++++++++++++++++++++++++--
 include/uapi/drm/i915_drm.h                |  16 ++++-
 5 files changed, 206 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/Kconfig +3 -0
index 1d96fe1..cb5d5b2 100644
@@ -22,6 +22,9 @@ config DRM_I915
 	select ACPI_VIDEO if ACPI
 	select ACPI_BUTTON if ACPI
 	select MMU_NOTIFIER
+	# ANDROID is required for SYNC
+	select ANDROID
+	select SYNC
 	help
 	  Choose this option if you have a system that has "Intel Graphics
 	  Media Accelerator" or "HD Graphics" integrated graphics,
drivers/gpu/drm/i915/i915_drv.h +7 -0
index 20c8a06..7c9a6ec 100644
@@ -2323,6 +2323,13 @@ void i915_gem_request_notify(struct intel_engine_cs *ring, bool fence_locked);
 int i915_create_fence_timeline(struct drm_device *dev,
 			       struct intel_context *ctx,
 			       struct intel_engine_cs *ring);
+struct sync_fence;
+int i915_create_sync_fence(struct drm_i915_gem_request *req,
+			   struct sync_fence **sync_fence, int *fence_fd);
+void i915_install_sync_fence_fd(struct drm_i915_gem_request *req,
+				struct sync_fence *sync_fence, int fence_fd);
+bool i915_safe_to_ignore_fence(struct intel_engine_cs *ring,
+			       struct sync_fence *fence);
 
 static inline bool i915_gem_request_completed(struct drm_i915_gem_request *req)
 {
drivers/gpu/drm/i915/i915_gem.c +89 -1

108 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_execbuffer.c +94 -6

154 lines not on this page · raw message

include/uapi/drm/i915_drm.h +13 -3
index 86a255c..5f35f89 100644
@@ -250,7 +250,7 @@ typedef struct _drm_i915_sarea {
 #define DRM_IOCTL_I915_HWS_ADDR		DRM_IOW(DRM_COMMAND_BASE + DRM_I915_HWS_ADDR, struct drm_i915_gem_init)
 #define DRM_IOCTL_I915_GEM_INIT		DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_INIT, struct drm_i915_gem_init)
 #define DRM_IOCTL_I915_GEM_EXECBUFFER	DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER, struct drm_i915_gem_execbuffer)
-#define DRM_IOCTL_I915_GEM_EXECBUFFER2	DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER2, struct drm_i915_gem_execbuffer2)
+#define DRM_IOCTL_I915_GEM_EXECBUFFER2	DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_EXECBUFFER2, struct drm_i915_gem_execbuffer2)
 #define DRM_IOCTL_I915_GEM_PIN		DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_PIN, struct drm_i915_gem_pin)
 #define DRM_IOCTL_I915_GEM_UNPIN	DRM_IOW(DRM_COMMAND_BASE + DRM_I915_GEM_UNPIN, struct drm_i915_gem_unpin)
 #define DRM_IOCTL_I915_GEM_BUSY		DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_BUSY, struct drm_i915_gem_busy)
@@ -695,7 +695,7 @@ struct drm_i915_gem_exec_object2 {
 	__u64 flags;
 
 	__u64 rsvd1;
-	__u64 rsvd2;
+	__u64 rsvd2;	/* Used for fence fd */
 };
 
 struct drm_i915_gem_execbuffer2 {
@@ -776,7 +776,17 @@ struct drm_i915_gem_execbuffer2 {
  */
 #define I915_EXEC_RESOURCE_STREAMER     (1<<15)
 
-#define __I915_EXEC_UNKNOWN_FLAGS -(I915_EXEC_RESOURCE_STREAMER<<1)
+/** Caller supplies a sync fence fd in the rsvd2 field.
+ * Wait for it to be signalled before starting the work
+ */
+#define I915_EXEC_WAIT_FENCE		(1<<16)
+
+/** Caller wants a sync fence fd for this execbuffer.
+ *  It will be returned in rsvd2
+ */
+#define I915_EXEC_CREATE_FENCE		(1<<17)
+
+#define __I915_EXEC_UNKNOWN_FLAGS -(I915_EXEC_CREATE_FENCE<<1)
 
 #define I915_EXEC_CONTEXT_ID_MASK	(0xffffffff)
 #define i915_execbuffer2_set_context_id(eb2, context) \
Signature · 6 lines
1.9.1

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

Re: [RFC 6/9] drm/i915: Add sync framework support to execbuff IOCTL

Quoted 8 lines · On Wed, Jan 13, 2016 at 05:57:32PM +0000, [email protected] wrote:

static int
i915_gem_do_execbuffer(struct drm_device *dev, void *data,

drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
 		       struct drm_file *file,
@@ -1428,6 +1465,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	u32 dispatch_flags;
 	int ret, i;
 	bool need_relocs;
+	int fd_fence_complete = -1;

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

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -0
+	int fd_fence_wait = lower_32_bits(args->rsvd2);
+	struct sync_fence *sync_fence;
+
+	/*
+	 * Make sure an broken fence handle is not returned no matter
+	 * how early an error might be hit. Note that rsvd2 has been
+	 * saved away above because it is also an input parameter!
+	 */
+	if (args->flags & I915_EXEC_CREATE_FENCE)
+		args->rsvd2 = (__u64) -1;

But you are not restoring the user input parameter upon an error path.

Very simple example is the user trying to do a wait on a fence but is woken up by a signal and then tries to restart the syscall, the standard

	do {
		ret = ioctl(fd, request, arg);
	} while (ret == -1 && (errno == EINTR || errno == EAGAIN));

loop errors out with EINVAL on the second pass.

Quoted 48 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +28 -1
 	if (!i915_gem_check_execbuffer(args))
 		return -EINVAL;
@@ -1511,6 +1559,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 		dispatch_flags |= I915_DISPATCH_RS;
 	}
 
+	/*
+	 * Without a GPU scheduler, any fence waits must be done up front.
+	 */
+	if (args->flags & I915_EXEC_WAIT_FENCE) {
+		ret = i915_early_fence_wait(ring, fd_fence_wait);
+		if (ret < 0)
+			return ret;
+
+		args->flags &= ~I915_EXEC_WAIT_FENCE;
+	}
+
 	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)
 		goto pre_mutex_err;
@@ -1695,13 +1754,41 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	i915_gem_context_reference(ctx);
 	params->ctx = ctx;
 
+	if (args->flags & I915_EXEC_CREATE_FENCE) {
+		/*
+		 * Caller has requested a sync fence.
+		 * User interrupts will be enabled to make sure that
+		 * the timeline is signalled on completion.
+		 */
+		ret = i915_create_sync_fence(params->request, &sync_fence,
+					     &fd_fence_complete);
+		if (ret) {
+			DRM_ERROR("Fence creation failed for ring %d, ctx %p\n",
+				  ring->id, ctx);
+			goto err_batch_unpin;
+		}
+	}
+
 	ret = dev_priv->gt.execbuf_submit(params, args, &eb->vmas);
 	if (ret)
-		goto err_batch_unpin;
+		goto err_fence;
 
 	/* the request owns the ref now */
 	i915_gem_context_unreference(ctx);
 
+	if (fd_fence_complete != -1) {

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

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -0
+		/*
+		 * Install the fence into the pre-allocated file
+		 * descriptor to the fence object so that user land
+		 * can wait on it...
+		 */
+		i915_install_sync_fence_fd(params->request,
+					   sync_fence, fd_fence_complete);
+
+		/* Return the fence through the rsvd2 field */
+		args->rsvd2 = (__u64) fd_fence_complete;

Use the upper s32 for the output, so again you are not overwriting user state without good reason.
-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
#15 lore raw

Re: [RFC 6/9] drm/i915: Add sync framework support to execbuff IOCTL

Quoted 75 lines · Chris Wilson
Quoted 8 lines · On Wed, Jan 13, 2016 at 05:57:32PM +0000, [email protected] wrote:

static int
i915_gem_do_execbuffer(struct drm_device *dev, void *data,
struct drm_file *file,

drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
@@ -1428,6 +1465,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
  	u32 dispatch_flags;
  	int ret, i;
  	bool need_relocs;
+	int fd_fence_complete = -1;

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

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +10 -0
+	int fd_fence_wait = lower_32_bits(args->rsvd2);
+	struct sync_fence *sync_fence;
+
+	/*
+	 * Make sure an broken fence handle is not returned no matter
+	 * how early an error might be hit. Note that rsvd2 has been
+	 * saved away above because it is also an input parameter!
+	 */
+	if (args->flags & I915_EXEC_CREATE_FENCE)
+		args->rsvd2 = (__u64) -1;

But you are not restoring the user input parameter upon an error path.

Very simple example is the user trying to do a wait on a fence but is woken up by a signal and then tries to restart the syscall, the standard

	do {
		ret = ioctl(fd, request, arg);
	} while (ret == -1 && (errno == EINTR || errno == EAGAIN));

loop errors out with EINVAL on the second pass.

Quoted 47 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +27 -1
  	if (!i915_gem_check_execbuffer(args))
  		return -EINVAL;
@@ -1511,6 +1559,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
  		dispatch_flags |= I915_DISPATCH_RS;
  	}
 
+	/*
+	 * Without a GPU scheduler, any fence waits must be done up front.
+	 */
+	if (args->flags & I915_EXEC_WAIT_FENCE) {
+		ret = i915_early_fence_wait(ring, fd_fence_wait);
+		if (ret < 0)
+			return ret;
+
+		args->flags &= ~I915_EXEC_WAIT_FENCE;
+	}
+
  	ret = i915_mutex_lock_interruptible(dev);
  	if (ret)
  		goto pre_mutex_err;
@@ -1695,13 +1754,41 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
  	i915_gem_context_reference(ctx);
  	params->ctx = ctx;
 
+	if (args->flags & I915_EXEC_CREATE_FENCE) {
+		/*
+		 * Caller has requested a sync fence.
+		 * User interrupts will be enabled to make sure that
+		 * the timeline is signalled on completion.
+		 */
+		ret = i915_create_sync_fence(params->request, &sync_fence,
+					     &fd_fence_complete);
+		if (ret) {
+			DRM_ERROR("Fence creation failed for ring %d, ctx %p\n",
+				  ring->id, ctx);
+			goto err_batch_unpin;
+		}
+	}
+
  	ret = dev_priv->gt.execbuf_submit(params, args, &eb->vmas);
  	if (ret)
-		goto err_batch_unpin;
+		goto err_fence;
 
  	/* the request owns the ref now */
  	i915_gem_context_unreference(ctx);
 
Quoted 15 lines

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

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +11 -0
+	if (fd_fence_complete != -1) {
+		/*
+		 * Install the fence into the pre-allocated file
+		 * descriptor to the fence object so that user land
+		 * can wait on it...
+		 */
+		i915_install_sync_fence_fd(params->request,
+					   sync_fence, fd_fence_complete);
+
+		/* Return the fence through the rsvd2 field */
+		args->rsvd2 = (__u64) fd_fence_complete;

Use the upper s32 for the output, so again you are not overwriting user state without good reason.
-Chris

Makes sense. Will do.

Thanks,
John.

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

#16 lore raw

Re: [RFC 6/9] drm/i915: Add sync framework support to execbuff IOCTL

Quoted 5 lines · John Harrison
Quoted 3 lines · Chris Wilson

Use the upper s32 for the output, so again you are not overwriting user state without good reason.

Makes sense. Will do.

It would also be useful (for nefarious reasons) to only copy back the rsvd2 field, i.e. keep it as DRM_IOW(EXECBUFFER2) and do the small fixed-sized copy_to_user of rsvd2 as required. That means we can avoid the copy mostly, and treat args as a private copy of the user parameters, i.e. space we can scribble over with impunity. -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
#17 lore raw

Re: [RFC 6/9] drm/i915: Add sync framework support to execbuff IOCTL

Op 14-01-16 om 13:07 schreef Chris Wilson:

Quoted 11 lines · John Harrison
Quoted 5 lines · Chris Wilson
Quoted 3 lines

Use the upper s32 for the output, so again you are not overwriting user state without good reason.

Makes sense. Will do.

It would also be useful (for nefarious reasons) to only copy back the rsvd2 field, i.e. keep it as DRM_IOW(EXECBUFFER2) and do the small fixed-sized copy_to_user of rsvd2 as required. That means we can avoid the copy mostly, and treat args as a private copy of the user parameters, i.e. space we can scribble over with impunity.

Won't that be an abuse of abi? If we write memory we should mark the struct as writable, and make sure we don't touch the user execbuffer2 at all until the call succeeds.

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

#18 lore raw

Re: [RFC 6/9] drm/i915: Add sync framework support to execbuff IOCTL

Quoted 6 lines · Maarten Lankhorst

Op 14-01-16 om 13:07 schreef Chris Wilson:

Quoted 5 lines · John Harrison
Quoted 4 lines · Chris Wilson
Quoted 3 lines

Use the upper s32 for the output, so again you are not overwriting user state without good reason.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Makes sense. Will do.

It would also be useful (for nefarious reasons) to only copy back the rsvd2 field, i.e. keep it as DRM_IOW(EXECBUFFER2) and do the small fixed-sized copy_to_user of rsvd2 as required. That means we can avoid the copy mostly, and treat args as a private copy of the user parameters, i.e. space we can scribble over with impunity.

Won't that be an abuse of abi? If we write memory we should mark the struct as writable, and make sure we don't touch the user execbuffer2 at all until the call succeeds.

We only write into the structure when the user requests an output parameter, so they have to opt in (because the current ABI has no outputs through the ioctl atm). Whether or not userspace marks the ioctl argument as RW/RO is irrelevant to the kernel who uses its own table to control the ABI. If the memory really is read-only, then copy_to_user() will -EFAULT (and as the user requested an output we should check early and fail, whether to fail after we dispatch the request is an interesting conundrum).
-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
#19 lore raw

RFC 7/9 drm/i915: Add sync wait support to scheduler

In reply to [email protected]

From: John Harrison <[email protected]>

There is a sync framework to allow work for multiple independent systems to be synchronised with each other but without stalling the CPU whether in the application or the driver. This patch adds support for this framework to the GPU scheduler.

Batch buffers can now have sync framework fence objects associated with them. The scheduler will look at this fence when deciding what to submit next to the hardware. If the fence is outstanding then that batch buffer will be passed over in preference of one that is ready to run. If no other batches are ready then the scheduler will queue an asynchronous callback to be woken up when the fence has been signalled. The callback will wake the scheduler and submit the now ready batch buffer.

v0.2: Updated to use the new sync_fence_is_signaled() API rather than having to know about the internals of a fence object.

Also removed the spin lock from the fence wait callback function. This was used to clear the 'waiting' flag. However, it causes a problem with the TDR code. Specifically, when cancelling work packets due to a TDR there is a code path where the fence can be signalled while the spinlock is already held. It is not really necessary to clear the flag anyway as it's purpose is solely to prevent multiple waits being issued. Once the fence has been signalled, no further waits will be attempted so it doesn't matter whether the fence is marked as having an outstanding wait or not.

v0.3: Re-wrapped long lines and comments to keep style checker happy.

For: VIZ-1587

---
 drivers/gpu/drm/i915/i915_drv.h       |   1 +
 drivers/gpu/drm/i915/i915_scheduler.c | 146 ++++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/i915_scheduler.h |   6 ++
 3 files changed, 148 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 7c9a6ec..0316dcd 100644
@@ -1714,6 +1714,7 @@ struct i915_execbuffer_params {
 	uint64_t                        batch_obj_vm_offset;
 	struct intel_engine_cs          *ring;
 	struct drm_i915_gem_object      *batch_obj;
+	struct sync_fence               *fence_wait;
 	struct drm_clip_rect            *cliprects;
 	uint32_t                        instp_mask;
 	int                             instp_mode;
drivers/gpu/drm/i915/i915_scheduler.c +141 -5

218 lines not on this page · raw message

drivers/gpu/drm/i915/i915_scheduler.h +6 -0
index 3d1484d..408958f 100644
@@ -55,6 +55,11 @@ struct i915_scheduler_obj_entry {
 	bool                                read_only;
 };
 
+enum i915_scheduler_queue_entry_flags {
+	/* Fence is being waited on */
+	i915_qef_fence_waiting              = (1 << 0),
+};
+
 struct i915_scheduler_queue_entry {
 	struct i915_execbuffer_params       params;
 	/* -1023 = lowest priority, 0 = default, 1023 = highest */
@@ -67,6 +72,7 @@ struct i915_scheduler_queue_entry {
 	enum i915_scheduler_queue_status    status;
 	unsigned long                       stamp;
 	struct list_head                    link;
+	uint32_t                            flags;
 };
 const char *i915_qe_state_str(struct i915_scheduler_queue_entry *node);
 
Signature · 6 lines
1.9.1

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

RFC 8/9 drm/i915: Connecting execbuff fences to scheduler

In reply to [email protected]

From: John Harrison <[email protected]>

The scheduler now supports sync framework fences being associated with batch buffers. The execbuff IOCTL allows such fences to be passed in from user land. This patch wires the two together so that the IOCTL no longer needs to stall on the fence immediately. Instead the stall is now swallowed by the scheduler's scheduling algorithm.

v0.1: Updated a comment that would become incorrect after this patch.

For: VIZ-1587

---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 25 +++++++++++++++++++++----
 drivers/gpu/drm/i915/i915_scheduler.c      |  3 +++
 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +21 -4
index 372922a..8232a02 100644
@@ -1412,9 +1412,9 @@ eb_get_batch(struct eb_vmas *eb)
 }
 
 /*
- * Do a synchronous wait on any incoming fence object (until the scheduler
- * arrives and implements asynchronous waits). NB: This must be called before
- * acquiring the driver mutex lock!
+ * Do a synchronous wait on any incoming fence object (e.g. in the case where
+ * the scheduler is disabled). NB: This must be called before acquiring the
+ * driver mutex lock!
  */
 static int i915_early_fence_wait(struct intel_engine_cs *ring, int fence_fd)
 {
@@ -1562,7 +1562,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	/*
 	 * Without a GPU scheduler, any fence waits must be done up front.
 	 */
-	if (args->flags & I915_EXEC_WAIT_FENCE) {
+	if ((args->flags & I915_EXEC_WAIT_FENCE) &&
+	    (i915.scheduler_override & i915_so_direct_submit))
+	{
 		ret = i915_early_fence_wait(ring, fd_fence_wait);
 		if (ret < 0)
 			return ret;
@@ -1754,6 +1756,18 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	i915_gem_context_reference(ctx);
 	params->ctx = ctx;
 
+	if (args->flags & I915_EXEC_WAIT_FENCE) {
+		if (fd_fence_wait < 0) {
+			DRM_ERROR("Wait fence for ring %d has invalid id %d\n",
+				  (int) ring->id, fd_fence_wait);
+		} else {
+			params->fence_wait = sync_fence_fdget(fd_fence_wait);
+			if (params->fence_wait == NULL)
+				DRM_ERROR("Invalid wait fence %d\n",
+					  fd_fence_wait);
+		}
+	}
+
 	if (args->flags & I915_EXEC_CREATE_FENCE) {
 		/*
 		 * Caller has requested a sync fence.
@@ -1834,6 +1848,9 @@ err:
 			i915_gem_context_unreference(params->ctx);
 	}
 
+	if (params->fence_wait)
+		sync_fence_put(params->fence_wait);
+
 	/*
 	 * If the request was created but not successfully submitted then it
 	 * must be freed again. If it was submitted then it is being tracked
drivers/gpu/drm/i915/i915_scheduler.c +3 -0
index 4b3943a..5228df7 100644
@@ -1280,6 +1280,9 @@ static int i915_scheduler_pop_from_queue_locked(struct intel_engine_cs *ring,
 		else
 			signalled = true;
 
+		if (!signalled)
+			signalled = i915_safe_to_ignore_fence(ring, node->params.fence_wait);
+
 		has_local  = false;
 		has_remote = false;
 		for (i = 0; i < node->num_deps; i++) {
Signature · 6 lines
1.9.1

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

RFC 9/9 drm/i915: Add sync support to the scheduler statistics and status dump

In reply to [email protected]

From: John Harrison <[email protected]>

There are useful statistics and debug information about fences that can be returned via the scheduler's existing reporting mechanisms (sysfs and debug output). These changes were previously part of the patches that originally added those mechanisms. However, as the sync framework has now been rebased to after the scheduler patches, they must now be done as a separate patch on top.

For: VIZ-1587

---
 drivers/gpu/drm/i915/i915_debugfs.c        |  4 ++++
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  8 +++++++-
 drivers/gpu/drm/i915/i915_scheduler.c      | 20 ++++++++++++++++----
 drivers/gpu/drm/i915/i915_scheduler.h      |  5 +++++
 4 files changed, 32 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +4 -0
index a99f9c5..c1e1bcd 100644
@@ -3712,6 +3712,10 @@ static int i915_scheduler_info(struct seq_file *m, void *unused)
 	PRINT_VAR("  ExecEarly retry",      "u", stats[r].exec_early);
 	PRINT_VAR("  ExecFinal requeue",    "u", stats[r].exec_again);
 	PRINT_VAR("  ExecFinal killed",     "u", stats[r].exec_dead);
+	PRINT_VAR("  Fence wait",           "u", stats[r].fence_wait);
+	PRINT_VAR("  Fence wait again",     "u", stats[r].fence_again);
+	PRINT_VAR("  Fence wait ignore",    "u", stats[r].fence_ignore);
+	PRINT_VAR("  Fence supplied",       "u", stats[r].fence_got);
 	PRINT_VAR("  Hung flying",          "u", stats[r].kill_flying);
 	PRINT_VAR("  Hung queued",          "u", stats[r].kill_queued);
 	seq_putc(m, '\n');
drivers/gpu/drm/i915/i915_gem_execbuffer.c +7 -1
index 8232a02..252532b 100644
@@ -1418,6 +1418,8 @@ eb_get_batch(struct eb_vmas *eb)
  */
 static int i915_early_fence_wait(struct intel_engine_cs *ring, int fence_fd)
 {
+	struct drm_i915_private *dev_priv = ring->dev->dev_private;
+	struct i915_scheduler *scheduler = dev_priv->scheduler;
 	struct sync_fence *fence;
 	int ret = 0;
 
@@ -1439,8 +1441,12 @@ static int i915_early_fence_wait(struct intel_engine_cs *ring, int fence_fd)
 	 * because the the mutex lock has not yet been acquired and
 	 * the wait is interruptible.
 	 */
-	if (!i915_safe_to_ignore_fence(ring, fence))
+	if (i915_safe_to_ignore_fence(ring, fence))
+		scheduler->stats[ring->id].fence_ignore++;
+	else {
+		scheduler->stats[ring->id].fence_wait++;
 		ret = sync_fence_wait(fence, -1);
+	}
 
 	sync_fence_put(fence);
 	return ret;
drivers/gpu/drm/i915/i915_scheduler.c +16 -4
index 5228df7..5e3e85a 100644
@@ -274,6 +274,9 @@ int i915_scheduler_queue_execbuffer(struct i915_scheduler_queue_entry *qe)
 
 	WARN_ON(!scheduler);
 
+	if (qe->params.fence_wait)
+		scheduler->stats[ring->id].fence_got++;
+
 	if (i915.scheduler_override & i915_so_direct_submit) {
 		int ret;
 
@@ -912,7 +915,7 @@ static int i915_scheduler_dump_locked(struct intel_engine_cs *ring,
 					deps++;
 
 			DRM_DEBUG_DRIVER("<%s>   %c:%02d> uniq = %d, seqno"
-					 " = %d/%s, deps = %d / %d, %s [pri = "
+					 " = %d/%s, deps = %d / %d, fence = %p/%d, %s [pri = "
 					 "%4d]\n", ring->name,
 					 i915_scheduler_queue_status_chr(node->status),
 					 count,
@@ -920,6 +923,8 @@ static int i915_scheduler_dump_locked(struct intel_engine_cs *ring,
 					 node->params.request->seqno,
 					 node->params.ring->name,
 					 deps, node->num_deps,
+					 node->params.fence_wait,
+					 node->params.fence_wait ? sync_fence_is_signaled(node->params.fence_wait) : 0,
 					 i915_qe_state_str(node),
 					 node->priority);
 
@@ -1205,15 +1210,20 @@ static void i915_scheduler_wait_fence_signaled(struct sync_fence *fence,
 static bool i915_scheduler_async_fence_wait(struct drm_device *dev,
 				     struct i915_scheduler_queue_entry *node)
 {
+	struct drm_i915_private         *dev_priv = node->params.ring->dev->dev_private;
+	struct i915_scheduler           *scheduler = dev_priv->scheduler;
 	struct i915_sync_fence_waiter	*fence_waiter;
 	struct sync_fence		*fence = node->params.fence_wait;
 	int				signaled;
 	bool				success = true;
 
-	if ((node->flags & i915_qef_fence_waiting) == 0)
+	if ((node->flags & i915_qef_fence_waiting) == 0) {
 		node->flags |= i915_qef_fence_waiting;
-	else
+		scheduler->stats[node->params.ring->id].fence_wait++;
+	} else {
+		scheduler->stats[node->params.ring->id].fence_again++;
 		return true;
+	}
 
 	if (fence == NULL)
 		return false;
@@ -1280,8 +1290,10 @@ static int i915_scheduler_pop_from_queue_locked(struct intel_engine_cs *ring,
 		else
 			signalled = true;
 
-		if (!signalled)
+		if (!signalled) {
 			signalled = i915_safe_to_ignore_fence(ring, node->params.fence_wait);
+			scheduler->stats[node->params.ring->id].fence_ignore++;
+		}
 
 		has_local  = false;
 		has_remote = false;
drivers/gpu/drm/i915/i915_scheduler.h +5 -0
index 408958f..7622963 100644
@@ -100,6 +100,11 @@ struct i915_scheduler_stats {
 	uint32_t            exec_dead;
 	uint32_t            kill_flying;
 	uint32_t            kill_queued;
+
+	uint32_t            fence_wait;
+	uint32_t            fence_again;
+	uint32_t            fence_ignore;
+	uint32_t            fence_got;
 };
 
 struct i915_scheduler {
Signature · 6 lines
1.9.1

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

RFC 1/1 igt/gem_exec_fence: New test for sync/fence interface

In reply to [email protected]

From: John Harrison <[email protected]>

Note, this is a work in progress. It is being posted now as there is work going on to change the debugging interface used by this test. So it would be useful to get some comments on whether the proposed changes will cause a problem for this test or whether the test itself should be done differently.

Cc Gustavo Padovan <[email protected]>
---
 lib/intel_batchbuffer.c |   36 ++
 lib/intel_batchbuffer.h |    1 +
 tests/Makefile.sources  |    1 +
 tests/gem_exec_fence.c  | 1470 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1508 insertions(+)
 create mode 100644 tests/gem_exec_fence.c
lib/intel_batchbuffer.c +36 -0
index 692521f..55c7f9f 100644
@@ -186,6 +186,27 @@ intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring)
 	intel_batchbuffer_reset(batch);
 }
 
+static void
+intel_batchbuffer_flush_on_ring_fence(struct intel_batchbuffer *batch, int ring,
+				      int fence_in, int *fence_out)
+{
+	unsigned int used = flush_on_ring_common(batch, ring);
+	drm_intel_context *ctx;
+
+	if (used == 0)
+		return;
+
+	do_or_die(drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer));
+
+	batch->ptr = NULL;
+
+	ctx = batch->ctx;
+	do_or_die(drm_intel_gem_bo_context_fence_exec(batch->bo, ctx, used,
+						      ring, fence_in, fence_out));
+
+	intel_batchbuffer_reset(batch);
+}
+
 void
 intel_batchbuffer_set_context(struct intel_batchbuffer *batch,
 				     drm_intel_context *context)
@@ -239,6 +260,21 @@ intel_batchbuffer_flush(struct intel_batchbuffer *batch)
 	intel_batchbuffer_flush_on_ring(batch, ring);
 }
 
+/**
+ * intel_batchbuffer_flush_fence:
+ * @batch: batchbuffer object
+ *
+ * Submits the batch for execution on the blitter engine, selecting the right
+ * ring depending upon the hardware platform.
+ */
+void
+intel_batchbuffer_flush_fence(struct intel_batchbuffer *batch, int fence_in, int *fence_out)
+{
+	int ring = 0;
+	if (HAS_BLT_RING(batch->devid))
+		ring = I915_EXEC_BLT;
+	intel_batchbuffer_flush_on_ring_fence(batch, ring, fence_in, fence_out);
+}
 
 /**
  * intel_batchbuffer_emit_reloc:
lib/intel_batchbuffer.h +1 -0
index 869747d..5dece2a 100644
@@ -35,6 +35,7 @@ void intel_batchbuffer_free(struct intel_batchbuffer *batch);
 
 
 void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
+void intel_batchbuffer_flush_fence(struct intel_batchbuffer *batch, int fence_in, int *fence_out);
 void intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring);
 void intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch,
 					  drm_intel_context *context);
tests/Makefile.sources +1 -0
index 8fb2de8..1000324 100644
@@ -26,6 +26,7 @@ TESTS_progs_M = \
 	gem_exec_alignment \
 	gem_exec_bad_domains \
 	gem_exec_faulting_reloc \
+	gem_exec_fence \
 	gem_exec_nop \
 	gem_exec_params \
 	gem_exec_parse \
tests/gem_exec_fence.c new file +1470 -0

1,470 lines not on this page · raw message

Signature · 6 lines
1.9.1

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