All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Airlie <airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 2/4] sync_file: add replace and export some functionality
Date: Tue, 14 Mar 2017 10:50:52 +1000	[thread overview]
Message-ID: <20170314005054.7487-4-airlied@gmail.com> (raw)
In-Reply-To: <20170314005054.7487-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Dave Airlie <airlied@redhat.com>

Using sync_file to back vulkan semaphores means need to replace
the fence underlying the sync file. This replace function removes
the callback, swaps the fence, and returns the old one. This
also exports the alloc and fdget functionality for the semaphore
wrapper code.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/dma-buf/sync_file.c | 46 +++++++++++++++++++++++++++++++++++++++++----
 include/linux/sync_file.h   |  5 ++++-
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index 105f48c..df7bb37 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -28,7 +28,14 @@
 
 static const struct file_operations sync_file_fops;
 
-static struct sync_file *sync_file_alloc(void)
+/**
+ * sync_file_alloc() - allocate an unfenced sync file
+ *
+ * Creates a sync_file.
+ * The sync_file can be released with fput(sync_file->file).
+ * Returns the sync_file or NULL in case of error.
+ */
+struct sync_file *sync_file_alloc(void)
 {
 	struct sync_file *sync_file;
 
@@ -54,6 +61,7 @@ static struct sync_file *sync_file_alloc(void)
 	kfree(sync_file);
 	return NULL;
 }
+EXPORT_SYMBOL(sync_file_alloc);
 
 static void fence_check_cb_func(struct dma_fence *f, struct dma_fence_cb *cb)
 {
@@ -92,7 +100,7 @@ struct sync_file *sync_file_create(struct dma_fence *fence)
 }
 EXPORT_SYMBOL(sync_file_create);
 
-static struct sync_file *sync_file_fdget(int fd)
+struct sync_file *sync_file_fdget(int fd)
 {
 	struct file *file = fget(fd);
 
@@ -108,6 +116,7 @@ static struct sync_file *sync_file_fdget(int fd)
 	fput(file);
 	return NULL;
 }
+EXPORT_SYMBOL(sync_file_fdget);
 
 /**
  * sync_file_get_fence - get the fence related to the sync_file fd
@@ -125,13 +134,40 @@ struct dma_fence *sync_file_get_fence(int fd)
 	if (!sync_file)
 		return NULL;
 
+	mutex_lock(&sync_file->lock);
 	fence = dma_fence_get(sync_file->fence);
+	mutex_unlock(&sync_file->lock);
 	fput(sync_file->file);
 
 	return fence;
 }
 EXPORT_SYMBOL(sync_file_get_fence);
 
+/**
+ * sync_file_replace_fence - replace the fence related to the sync_file
+ * @sync_file:	 sync file to replace fence in
+ * @fence: fence to replace with (or NULL for no fence).
+ * Returns previous fence.
+ */
+struct dma_fence *sync_file_replace_fence(struct sync_file *sync_file,
+					  struct dma_fence *fence)
+{
+	struct dma_fence *ret_fence = NULL;
+	mutex_lock(&sync_file->lock);
+	if (sync_file->fence) {
+		if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
+			dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
+		ret_fence = sync_file->fence;
+	}
+	if (fence)
+		sync_file->fence = dma_fence_get(fence);
+	else
+		sync_file->fence = NULL;
+	mutex_unlock(&sync_file->lock);
+	return ret_fence;
+}
+EXPORT_SYMBOL(sync_file_replace_fence);
+
 static int sync_file_set_fence(struct sync_file *sync_file,
 			       struct dma_fence **fences, int num_fences)
 {
@@ -292,8 +328,10 @@ static void sync_file_free(struct kref *kref)
 	struct sync_file *sync_file = container_of(kref, struct sync_file,
 						     kref);
 
-	if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
-		dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
+	if (sync_file->fence) {
+		if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
+			dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
+	}
 	dma_fence_put(sync_file->fence);
 	kfree(sync_file);
 }
diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h
index 5aef17f..9511a54 100644
--- a/include/linux/sync_file.h
+++ b/include/linux/sync_file.h
@@ -50,7 +50,10 @@ struct sync_file {
 
 #define POLL_ENABLED DMA_FENCE_FLAG_USER_BITS
 
+struct sync_file *sync_file_alloc(void);
 struct sync_file *sync_file_create(struct dma_fence *fence);
 struct dma_fence *sync_file_get_fence(int fd);
-
+struct sync_file *sync_file_fdget(int fd);
+struct dma_fence *sync_file_replace_fence(struct sync_file *sync_file,
+					  struct dma_fence *fence);
 #endif /* _LINUX_SYNC_H */
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-03-14  0:50 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14  0:50 [rfc] amdgpu/sync_file shared semaphores Dave Airlie
2017-03-14  0:50 ` [PATCH 1/4] sync_file: add a mutex to protect fence and callback members Dave Airlie
     [not found]   ` <20170314005054.7487-3-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-14  8:45     ` Daniel Vetter
2017-03-14  9:13       ` Christian König
     [not found]         ` <2cba21f6-731b-d112-f882-bef66a9b96c9-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-03-14  9:29           ` Chris Wilson
     [not found]             ` <20170314092909.GE2118-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-03-14  9:30               ` Christian König
2017-03-15  0:47                 ` Dave Airlie
     [not found]                   ` <CAPM=9twwjgBirFDenUmnorDdOZNiWHuzdBxawCiU7p9uS1o0_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15  2:20                     ` Dave Airlie
     [not found] ` <20170314005054.7487-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-14  0:50   ` [PATCH libdrm] libdrm/amdgpu: add interface for kernel semaphores Dave Airlie
2017-03-14  2:00     ` zhoucm1
2017-03-14  2:52       ` Dave Airlie
     [not found]         ` <CAPM=9tzegdtiyEmbW+PqmVeQ+bXrNtrdKXuE3kB0dPMKnMir+Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-14  3:30           ` zhoucm1
     [not found]             ` <58C763E0.1-5C7GfCeVMHo@public.gmane.org>
2017-03-14  4:16               ` Dave Airlie
2017-03-14  8:56                 ` Daniel Vetter
2017-03-14  8:54             ` Daniel Vetter
2017-03-14  9:20               ` Christian König
2017-03-14 10:04                 ` zhoucm1
     [not found]                   ` <58C7C032.7060706-5C7GfCeVMHo@public.gmane.org>
2017-03-14 17:45                     ` Harry Wentland
     [not found]                       ` <8dea3303-480d-c29a-22ec-42adf3dab4ce-5C7GfCeVMHo@public.gmane.org>
2017-03-14 17:54                         ` Daniel Vetter
2017-03-14 18:10                         ` Christian König
2017-03-15  0:01                           ` Marek Olšák
     [not found]                             ` <CAAxE2A7xRWhkp-OC59iy2i91uj5mtVTHR0uHfDf745L-ixxHcw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15  8:48                               ` Daniel Vetter
2017-03-15  9:35                                 ` Christian König
     [not found]     ` <20170314005054.7487-2-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-15 10:30       ` Emil Velikov
2017-03-14  0:50   ` Dave Airlie [this message]
     [not found]     ` <20170314005054.7487-4-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-14  8:48       ` [PATCH 2/4] sync_file: add replace and export some functionality Daniel Vetter
     [not found]         ` <20170314084851.covfl7sjwn3yadh5-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-15  4:19           ` Dave Airlie
2017-03-15  8:55             ` Daniel Vetter
2017-03-16  5:18               ` Dave Airlie
2017-03-14  9:00     ` Chris Wilson
2017-03-14  0:50   ` [PATCH 3/4] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-03-14  0:50   ` [PATCH 4/4] amdgpu: use sync file for shared semaphores Dave Airlie
     [not found]     ` <20170314005054.7487-6-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-15  9:01       ` Daniel Vetter
     [not found]         ` <20170315090129.fneo5gafrz2jec32-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-15  9:43           ` Christian König
2017-03-15  9:57             ` Daniel Vetter
2017-03-14  8:53 ` [rfc] amdgpu/sync_file " Daniel Vetter
     [not found]   ` <20170314085313.qmnnofqa6e6ozmwk-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-15  1:09     ` Dave Airlie
     [not found]       ` <CAPM=9txSFTkz0y5hamBA7U7fu+X8x_wHG+X3xtWvm2PY4aCwsw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15  8:47         ` 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=20170314005054.7487-4-airlied@gmail.com \
    --to=airlied-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.