From: Jason Ekstrand <jason@jlekstrand.net>
To: dri-devel@lists.freedesktop.org
Cc: Jason Ekstrand <jason.ekstrand@intel.com>,
Jason Ekstrand <jason@jlekstrand.net>
Subject: [PATCH 8/9] drm/syncobj: Add a callback mechanism for replace_fence
Date: Tue, 8 Aug 2017 15:46:08 -0700 [thread overview]
Message-ID: <1502232369-19753-9-git-send-email-jason.ekstrand@intel.com> (raw)
In-Reply-To: <1502232369-19753-1-git-send-email-jason.ekstrand@intel.com>
It is useful in certain circumstances to know when the fence is replaced
in a syncobj. Specifically, it may be useful to know when the fence
goes from NULL to something valid. This does make syncobj_replace_fence
a little more expensive because it has to take a lock but, in the common
case where there is no callback list, it spends a very short amount of
time inside the lock.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
---
drivers/gpu/drm/drm_syncobj.c | 51 ++++++++++++++++++++++++++++++++++++++++++-
include/drm/drm_syncobj.h | 33 +++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 25807f5..510dfc2 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -96,6 +96,46 @@ struct dma_fence *drm_syncobj_fence_get(struct drm_syncobj *syncobj)
}
EXPORT_SYMBOL(drm_syncobj_fence_get);
+static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,
+ struct drm_syncobj_cb *cb,
+ drm_syncobj_func_t func)
+{
+ cb->func = func;
+ list_add_tail(&cb->node, &syncobj->cb_list);
+}
+
+/**
+ * drm_syncobj_add_callback - adds a callback to syncobj::cb_list
+ * @syncobj: Sync object to which to add the callback
+ * @cb: Callback to add
+ * @func: Func to use when initializing the drm_syncobj_cb struct
+ *
+ * This adds a callback to be called next time the fence is replaced
+ */
+void drm_syncobj_add_callback(struct drm_syncobj *syncobj,
+ struct drm_syncobj_cb *cb,
+ drm_syncobj_func_t func)
+{
+ spin_lock(&syncobj->lock);
+ drm_syncobj_add_callback_locked(syncobj, cb, func);
+ spin_unlock(&syncobj->lock);
+}
+EXPORT_SYMBOL(drm_syncobj_add_callback);
+
+/**
+ * drm_syncobj_add_callback - removes a callback to syncobj::cb_list
+ * @syncobj: Sync object from which to remove the callback
+ * @cb: Callback to remove
+ */
+void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,
+ struct drm_syncobj_cb *cb)
+{
+ spin_lock(&syncobj->lock);
+ list_del_init(&cb->node);
+ spin_unlock(&syncobj->lock);
+}
+EXPORT_SYMBOL(drm_syncobj_remove_callback);
+
/**
* drm_syncobj_replace_fence - replace fence in a sync object.
* @file_private: drm file private pointer.
@@ -108,13 +148,21 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
struct dma_fence *fence)
{
struct dma_fence *old_fence = NULL;
+ struct drm_syncobj_cb *cur, *tmp;
if (fence)
dma_fence_get(fence);
spin_lock(&syncobj->lock);
+
old_fence = syncobj->fence;
syncobj->fence = fence;
+
+ list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
+ list_del_init(&cur->node);
+ cur->func(syncobj, cur);
+ }
+
spin_unlock(&syncobj->lock);
dma_fence_put(old_fence);
@@ -151,7 +199,7 @@ void drm_syncobj_free(struct kref *kref)
struct drm_syncobj *syncobj = container_of(kref,
struct drm_syncobj,
refcount);
- dma_fence_put(syncobj->fence);
+ drm_syncobj_replace_fence(syncobj, NULL);
kfree(syncobj);
}
EXPORT_SYMBOL(drm_syncobj_free);
@@ -167,6 +215,7 @@ static int drm_syncobj_create(struct drm_file *file_private,
return -ENOMEM;
kref_init(&syncobj->refcount);
+ INIT_LIST_HEAD(&syncobj->cb_list);
spin_lock_init(&syncobj->lock);
idr_preload(GFP_KERNEL);
diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index 1c81658..a81af76 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -28,6 +28,8 @@
#include "linux/dma-fence.h"
+struct drm_syncobj_cb;
+
/**
* struct drm_syncobj - sync object.
*
@@ -46,8 +48,13 @@ struct drm_syncobj {
*/
struct dma_fence *fence;
/**
+ * @list
+ * List of callbaks to call when the fence gets replaced
+ */
+ struct list_head cb_list;
+ /**
* @spinlock:
- * locks fence.
+ * locks fence and cb_list.
*/
spinlock_t lock;
/**
@@ -57,6 +64,25 @@ struct drm_syncobj {
struct file *file;
};
+typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj,
+ struct drm_syncobj_cb *cb);
+
+/**
+ * struct drm_syncobj_cb - callback for drm_syncobj_add_callback
+ * @node: used by drm_syncob_add_callback to append this struct to
+ * syncobj::cb_list
+ * @func: drm_syncobj_func_t to call
+ *
+ * This struct will be initialized by drm_syncobj_add_callback, additional
+ * data can be passed along by embedding drm_syncobj_cb in another struct.
+ * The callback will get called the next time drm_syncobj_replace_fence is
+ * called.
+ */
+struct drm_syncobj_cb {
+ struct list_head node;
+ drm_syncobj_func_t func;
+};
+
void drm_syncobj_free(struct kref *kref);
/**
@@ -85,6 +111,11 @@ drm_syncobj_put(struct drm_syncobj *obj)
struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
u32 handle);
struct dma_fence *drm_syncobj_fence_get(struct drm_syncobj *syncobj);
+void drm_syncobj_add_callback(struct drm_syncobj *syncobj,
+ struct drm_syncobj_cb *cb,
+ drm_syncobj_func_t func);
+void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,
+ struct drm_syncobj_cb *cb);
void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
struct dma_fence *fence);
int drm_syncobj_find_fence(struct drm_file *file_private,
--
2.5.0.400.gff86faf
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-08-08 22:46 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 ` Jason Ekstrand [this message]
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 ` [PATCH 5/9] dma-buf/dma-fence: Allow wait_any_timeout without default_wait (v2) Jason Ekstrand
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=1502232369-19753-9-git-send-email-jason.ekstrand@intel.com \
--to=jason@jlekstrand.net \
--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