Re: [Intel-gfx] [PATCH] dma-fence: Refactor signaling for manual invocation

2019-05-08 Thread Tvrtko Ursulin


On 08/05/2019 12:25, Chris Wilson wrote:

Move the duplicated code within dma-fence.c into the header for wider
reuse.


For this one I am not sure whether to go with static inlines or 
EXPORT_SYMBOL the helpers.


Also you'll need to mention that in the same patch you are optimized the 
whole-list-unlink. Presumably, when this goes to dri-devel one day.


But overall it makes sense to me to allow controlled fine control of the 
fence signaling from dma-fence core.


Regards,

Tvrtko


Signed-off-by: Chris Wilson 
---
  drivers/dma-buf/Makefile|  10 +-
  drivers/dma-buf/dma-fence-trace.c   |  28 +++
  drivers/dma-buf/dma-fence.c |  32 +--
  drivers/gpu/drm/i915/gt/intel_breadcrumbs.c |  30 ---
  include/linux/dma-fence-types.h | 248 +++
  include/linux/dma-fence.h   | 251 +++-
  6 files changed, 321 insertions(+), 278 deletions(-)
  create mode 100644 drivers/dma-buf/dma-fence-trace.c
  create mode 100644 include/linux/dma-fence-types.h

diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 1f006e083eb9..56e579878f26 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1,5 +1,11 @@
-obj-y := dma-buf.o dma-fence.o dma-fence-array.o dma-fence-chain.o \
-reservation.o seqno-fence.o
+obj-y := \
+   dma-buf.o \
+   dma-fence.o \
+   dma-fence-array.o \
+   dma-fence-chain.o \
+   dma-fence-trace.o \
+   reservation.o \
+   seqno-fence.o
  obj-$(CONFIG_SYNC_FILE)   += sync_file.o
  obj-$(CONFIG_SW_SYNC) += sw_sync.o sync_debug.o
  obj-$(CONFIG_UDMABUF) += udmabuf.o
diff --git a/drivers/dma-buf/dma-fence-trace.c 
b/drivers/dma-buf/dma-fence-trace.c
new file mode 100644
index ..eb6f282be4c0
--- /dev/null
+++ b/drivers/dma-buf/dma-fence-trace.c
@@ -0,0 +1,28 @@
+/*
+ * Fence mechanism for dma-buf and to allow for asynchronous dma access
+ *
+ * Copyright (C) 2012 Canonical Ltd
+ * Copyright (C) 2012 Texas Instruments
+ *
+ * Authors:
+ * Rob Clark 
+ * Maarten Lankhorst 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+
+#define CREATE_TRACE_POINTS
+#include 
+
+EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit);
+EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal);
+EXPORT_TRACEPOINT_SYMBOL(dma_fence_signaled);
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 9bf06042619a..8196a179fdc2 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -24,13 +24,6 @@
  #include 
  #include 
  
-#define CREATE_TRACE_POINTS

-#include 
-
-EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit);
-EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal);
-EXPORT_TRACEPOINT_SYMBOL(dma_fence_signaled);
-
  static DEFINE_SPINLOCK(dma_fence_stub_lock);
  static struct dma_fence dma_fence_stub;
  
@@ -136,7 +129,6 @@ EXPORT_SYMBOL(dma_fence_context_alloc);

   */
  int dma_fence_signal_locked(struct dma_fence *fence)
  {
-   struct dma_fence_cb *cur, *tmp;
int ret = 0;
  
  	lockdep_assert_held(fence->lock);

@@ -144,7 +136,7 @@ int dma_fence_signal_locked(struct dma_fence *fence)
if (WARN_ON(!fence))
return -EINVAL;
  
-	if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {

+   if (!__dma_fence_signal(fence)) {
ret = -EINVAL;
  
  		/*

@@ -152,15 +144,10 @@ int dma_fence_signal_locked(struct dma_fence *fence)
 * still run through all callbacks
 */
} else {
-   fence->timestamp = ktime_get();
-   set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
-   trace_dma_fence_signaled(fence);
+   __dma_fence_signal__timestamp(fence, ktime_get());
}
  
-	list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {

-   list_del_init(&cur->node);
-   cur->func(fence, cur);
-   }
+   __dma_fence_signal__notify(fence);
return ret;
  }
  EXPORT_SYMBOL(dma_fence_signal_locked);
@@ -185,21 +172,14 @@ int dma_fence_signal(struct dma_fence *fence)
if (!fence)
return -EINVAL;
  
-	if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))

+   if (!__dma_fence_signal(fence))
return -EINVAL;
  
-	fence->timestamp = ktime_get();

-   set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
-   trace_dma_fence_signaled(fence);
+   __dma_fence_signal__timestamp(fence, ktime_get());
  
  	if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) {

[Intel-gfx] [PATCH] dma-fence: Refactor signaling for manual invocation

2019-05-08 Thread Chris Wilson
Move the duplicated code within dma-fence.c into the header for wider
reuse.

Signed-off-by: Chris Wilson 
---
 drivers/dma-buf/Makefile|  10 +-
 drivers/dma-buf/dma-fence-trace.c   |  28 +++
 drivers/dma-buf/dma-fence.c |  32 +--
 drivers/gpu/drm/i915/gt/intel_breadcrumbs.c |  30 ---
 include/linux/dma-fence-types.h | 248 +++
 include/linux/dma-fence.h   | 251 +++-
 6 files changed, 321 insertions(+), 278 deletions(-)
 create mode 100644 drivers/dma-buf/dma-fence-trace.c
 create mode 100644 include/linux/dma-fence-types.h

diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 1f006e083eb9..56e579878f26 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1,5 +1,11 @@
-obj-y := dma-buf.o dma-fence.o dma-fence-array.o dma-fence-chain.o \
-reservation.o seqno-fence.o
+obj-y := \
+   dma-buf.o \
+   dma-fence.o \
+   dma-fence-array.o \
+   dma-fence-chain.o \
+   dma-fence-trace.o \
+   reservation.o \
+   seqno-fence.o
 obj-$(CONFIG_SYNC_FILE)+= sync_file.o
 obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
 obj-$(CONFIG_UDMABUF)  += udmabuf.o
diff --git a/drivers/dma-buf/dma-fence-trace.c 
b/drivers/dma-buf/dma-fence-trace.c
new file mode 100644
index ..eb6f282be4c0
--- /dev/null
+++ b/drivers/dma-buf/dma-fence-trace.c
@@ -0,0 +1,28 @@
+/*
+ * Fence mechanism for dma-buf and to allow for asynchronous dma access
+ *
+ * Copyright (C) 2012 Canonical Ltd
+ * Copyright (C) 2012 Texas Instruments
+ *
+ * Authors:
+ * Rob Clark 
+ * Maarten Lankhorst 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+
+#define CREATE_TRACE_POINTS
+#include 
+
+EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit);
+EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal);
+EXPORT_TRACEPOINT_SYMBOL(dma_fence_signaled);
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 9bf06042619a..8196a179fdc2 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -24,13 +24,6 @@
 #include 
 #include 
 
-#define CREATE_TRACE_POINTS
-#include 
-
-EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit);
-EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal);
-EXPORT_TRACEPOINT_SYMBOL(dma_fence_signaled);
-
 static DEFINE_SPINLOCK(dma_fence_stub_lock);
 static struct dma_fence dma_fence_stub;
 
@@ -136,7 +129,6 @@ EXPORT_SYMBOL(dma_fence_context_alloc);
  */
 int dma_fence_signal_locked(struct dma_fence *fence)
 {
-   struct dma_fence_cb *cur, *tmp;
int ret = 0;
 
lockdep_assert_held(fence->lock);
@@ -144,7 +136,7 @@ int dma_fence_signal_locked(struct dma_fence *fence)
if (WARN_ON(!fence))
return -EINVAL;
 
-   if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+   if (!__dma_fence_signal(fence)) {
ret = -EINVAL;
 
/*
@@ -152,15 +144,10 @@ int dma_fence_signal_locked(struct dma_fence *fence)
 * still run through all callbacks
 */
} else {
-   fence->timestamp = ktime_get();
-   set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
-   trace_dma_fence_signaled(fence);
+   __dma_fence_signal__timestamp(fence, ktime_get());
}
 
-   list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
-   list_del_init(&cur->node);
-   cur->func(fence, cur);
-   }
+   __dma_fence_signal__notify(fence);
return ret;
 }
 EXPORT_SYMBOL(dma_fence_signal_locked);
@@ -185,21 +172,14 @@ int dma_fence_signal(struct dma_fence *fence)
if (!fence)
return -EINVAL;
 
-   if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+   if (!__dma_fence_signal(fence))
return -EINVAL;
 
-   fence->timestamp = ktime_get();
-   set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
-   trace_dma_fence_signaled(fence);
+   __dma_fence_signal__timestamp(fence, ktime_get());
 
if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) {
-   struct dma_fence_cb *cur, *tmp;
-
spin_lock_irqsave(fence->lock, flags);
-   list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
-   list_del_init(&cur->node);
-   cur->func(fence, cur);
-   }
+   __dma_fence_signal__notify(fence);
spin_unlock_irqrestore(fence->lock, flag