dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Ekstrand <jason@jlekstrand.net>
To: dri-devel@lists.freedesktop.org
Cc: "Jason Ekstrand" <jason.ekstrand@intel.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Jason Ekstrand" <jason@jlekstrand.net>
Subject: [PATCH 5/9] dma-buf/dma-fence: Allow wait_any_timeout without default_wait (v2)
Date: Fri, 11 Aug 2017 15:39:30 -0700	[thread overview]
Message-ID: <1502491174-10913-6-git-send-email-jason.ekstrand@intel.com> (raw)
In-Reply-To: <1502491174-10913-1-git-send-email-jason.ekstrand@intel.com>

dma_fence_wait_any_timeout only relies on two things to work correctly:

 1) The callback list to get called upon fence signal
 2) The SIGNALED flag to be set upon fence signal

The first if these is part of the core dma-fence API.  The second is
only mostly part of the core dma-fence API with the one issue that the
flag may not be set and dma_fence_is_signaled may never return true if
fence->ops->enable_signaling() has not been called.  It's easy enough to
work around that by always using dma_fence_is_signaled instead of
manually checking the bit and falling through to a zero-timeout wait if
none of the fences report that they are signaled.

v2:
 - Use dma_fence_is_signaled in test_signaled_any
 - Fall through to a zero-timeout wait

Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
---
 drivers/dma-buf/dma-fence.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 9a30279..0cac367 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -437,8 +437,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count,
 	int i;
 
 	for (i = 0; i < count; ++i) {
-		struct dma_fence *fence = fences[i];
-		if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+		if (dma_fence_is_signaled(fences[i])) {
 			if (idx)
 				*idx = i;
 			return true;
@@ -484,7 +483,13 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
 				return 1;
 			}
 
-		return 0;
+		/* There's a very annoying laxness in the dma_fence API
+		 * here, in that backends are not required to automatically
+		 * report when a fence is signaled prior to
+		 * fence->ops->enable_signaling() being called.  So here if
+		 * we fail to match signaled_count, we need to fallthough
+		 * and try a 0 timeout wait!
+		 */
 	}
 
 	cb = kcalloc(count, sizeof(struct default_wait_cb), GFP_KERNEL);
@@ -496,11 +501,6 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
 	for (i = 0; i < count; ++i) {
 		struct dma_fence *fence = fences[i];
 
-		if (fence->ops->wait != dma_fence_default_wait) {
-			ret = -EINVAL;
-			goto fence_rm_cb;
-		}
-
 		cb[i].task = current;
 		if (dma_fence_add_callback(fence, &cb[i].base,
 					   dma_fence_default_wait_cb)) {
@@ -511,7 +511,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
 		}
 	}
 
-	while (ret > 0) {
+	do {
 		if (intr)
 			set_current_state(TASK_INTERRUPTIBLE);
 		else
@@ -524,7 +524,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
 
 		if (ret > 0 && intr && signal_pending(current))
 			ret = -ERESTARTSYS;
-	}
+	} while (ret > 0);
 
 	__set_current_state(TASK_RUNNING);
 
-- 
2.5.0.400.gff86faf

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2017-08-11 22:39 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 22:46 [PATCH 0/9] drm/syncobj: Add full-featured wait support Jason Ekstrand
2017-08-08 22:46 ` [PATCH 1/9] drm/syncobj: Rename fence_get to find_fence Jason Ekstrand
2017-08-08 22:46 ` [PATCH 2/9] drm/syncobj: Lock around drm_syncobj::fence Jason Ekstrand
2017-08-09 21:21   ` Chris Wilson
2017-08-10  0:31     ` Jason Ekstrand
2017-08-10 10:55       ` Chris Wilson
2017-08-10 19:10       ` Chris Wilson
2017-08-08 22:46 ` [PATCH 3/9] drm/syncobj: Remove file_private from replace_fence Jason Ekstrand
2017-08-08 22:46 ` [PATCH 4/9] i915: Add support for drm syncobjs Jason Ekstrand
2017-08-08 22:46 ` [PATCH 5/9] drm/syncobj: add sync obj wait interface. (v8) Jason Ekstrand
2017-08-08 22:46 ` [PATCH 6/9] dma-buf/dma-fence: Allow wait_any_timeout without default_wait Jason Ekstrand
2017-08-08 22:46 ` [PATCH 7/9] drm/syncobj: Add a reset ioctl Jason Ekstrand
2017-08-08 22:46 ` [PATCH 8/9] drm/syncobj: Add a callback mechanism for replace_fence Jason Ekstrand
2017-08-08 22:46 ` [PATCH 9/9] drm/syncobj: Allow wait for submit and signal behavior Jason Ekstrand
2017-08-09 17:00   ` [PATCH] drm/syncobj: Allow wait for submit and signal behavior (v2) Jason Ekstrand
2017-08-09 17:57     ` Chris Wilson
2017-08-09 18:25       ` Christian König
2017-08-09 21:09         ` Jason Ekstrand
2017-08-09 22:41       ` Chris Wilson
2017-08-09 23:53         ` Jason Ekstrand
2017-08-10 11:00           ` Chris Wilson
2017-08-10 14:42             ` Jason Ekstrand
2017-08-10 12:26           ` Christian König
2017-08-10 14:32             ` Jason Ekstrand
2017-08-10 14:41               ` Christian König
2017-08-09 21:31     ` Chris Wilson
2017-08-09 21:54       ` Jason Ekstrand
2017-08-10 12:26       ` Christian König
2017-08-10  1:35     ` [PATCH v3 9/9] drm/syncobj: Allow wait for submit and signal behavior (v3) Jason Ekstrand
2017-08-11 22:39 ` [PATCH 0/9] drm/syncobj: Add full-featured wait support (v2) Jason Ekstrand
2017-08-11 22:39   ` [PATCH 1/9] drm/syncobj: Rename fence_get to find_fence Jason Ekstrand
2017-08-11 22:39   ` [PATCH 2/9] drm/syncobj: Add a race-free drm_syncobj_fence_get helper Jason Ekstrand
2017-08-14  2:03     ` kbuild test robot
2017-08-11 22:39   ` [PATCH 3/9] i915: Add support for drm syncobjs Jason Ekstrand
2017-08-14  2:58     ` Jason Ekstrand
2017-08-11 22:39   ` [PATCH 4/9] drm/syncobj: add sync obj wait interface. (v8) Jason Ekstrand
2017-08-11 22:39   ` Jason Ekstrand [this message]
2017-08-11 22:39   ` [PATCH 6/9] drm/syncobj: Add a reset ioctl Jason Ekstrand
2017-08-11 22:39   ` [PATCH 7/9] dma-buf/dma-fence: Signal all callbacks from dma_fence_release() Jason Ekstrand
2018-01-31 12:32     ` Gustavo Padovan
2018-01-31 15:53       ` Chris Wilson
2017-08-11 22:39   ` [PATCH 8/9] dma-buf/dma-fence: Add a mechanism for proxy fences Jason Ekstrand
2017-08-11 22:39   ` [PATCH 9/9] drm/syncobj: Allow wait for submit and signal behavior (v4) Jason Ekstrand
2017-08-13 13:19   ` [PATCH 0/9] drm/syncobj: Add full-featured wait support (v2) Christian König
2017-08-13 15:26     ` Jason Ekstrand
2017-08-13 15:52       ` Christian König
2017-08-13 23:14         ` Jason Ekstrand
2017-08-14  5:49           ` Jason Ekstrand
2017-08-14  7:36           ` Christian König
2017-08-14 15:08             ` Jason Ekstrand
2017-08-16 15:52               ` Jason Ekstrand
2017-08-16 16:53                 ` Christian König
2017-08-16 20:10                   ` Jason Ekstrand
2017-08-21 21:42                     ` Jason Ekstrand
2017-08-22  8:30                       ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502491174-10913-6-git-send-email-jason.ekstrand@intel.com \
    --to=jason@jlekstrand.net \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jason.ekstrand@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox