From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org, Chris Wilson <chris@chris-wilson.co.uk>
Subject: [PATCH 1/2] dma-buf/dma-fence: Trim dma_fence_add_callback()
Date: Wed, 15 Jul 2020 11:49:04 +0100 [thread overview]
Message-ID: <20200715104905.11006-1-chris@chris-wilson.co.uk> (raw)
Rearrange the code to pull the operations beore the fence->lock critical
section, and remove a small amount of redundancy:
Function old new delta
dma_fence_add_callback 156 145 -11
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/dma-buf/dma-fence.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 656e9ac2d028..8d5bdfce638e 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -348,29 +348,25 @@ EXPORT_SYMBOL(dma_fence_enable_sw_signaling);
int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
dma_fence_func_t func)
{
- unsigned long flags;
- int ret = 0;
+ int ret = -ENOENT;
if (WARN_ON(!fence || !func))
return -EINVAL;
- if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
- INIT_LIST_HEAD(&cb->node);
- return -ENOENT;
- }
+ cb->func = func;
+ INIT_LIST_HEAD(&cb->node);
- spin_lock_irqsave(fence->lock, flags);
+ if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+ unsigned long flags;
- if (__dma_fence_enable_signaling(fence)) {
- cb->func = func;
- list_add_tail(&cb->node, &fence->cb_list);
- } else {
- INIT_LIST_HEAD(&cb->node);
- ret = -ENOENT;
+ spin_lock_irqsave(fence->lock, flags);
+ if (__dma_fence_enable_signaling(fence)) {
+ list_add_tail(&cb->node, &fence->cb_list);
+ ret = 0;
+ }
+ spin_unlock_irqrestore(fence->lock, flags);
}
- spin_unlock_irqrestore(fence->lock, flags);
-
return ret;
}
EXPORT_SYMBOL(dma_fence_add_callback);
--
2.20.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2020-07-15 10:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-15 10:49 Chris Wilson [this message]
2020-07-15 10:49 ` [PATCH 2/2] dma-buf/dma-fence: Add quick tests before dma_fence_remove_callback Chris Wilson
2020-07-15 12:10 ` [Intel-gfx] " Daniel Vetter
2020-07-15 12:21 ` Chris Wilson
2020-07-15 12:40 ` Chris Wilson
2020-07-15 14:03 ` Daniel Vetter
2020-07-15 14:37 ` Chris Wilson
2020-07-15 14:46 ` Daniel Vetter
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=20200715104905.11006-1-chris@chris-wilson.co.uk \
--to=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/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;
as well as URLs for NNTP newsgroup(s).