AMD-GFX Archive on 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 3/7] sync_file: split out fence_file base class from sync_file.
Date: Thu, 13 Apr 2017 11:41:40 +1000	[thread overview]
Message-ID: <20170413014144.637-4-airlied@gmail.com> (raw)
In-Reply-To: <20170413014144.637-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Dave Airlie <airlied@redhat.com>

This just splits out a common base object to be shared
between sync_file and sem_files.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/dma-buf/sync_file.c  | 49 +++++++++++++++++++++++++++-----------------
 drivers/gpu/drm/drm_atomic.c |  4 ++--
 include/linux/sync_file.h    | 17 ++++++++++-----
 3 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index 9b7ad7e..2342d8b 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -28,17 +28,28 @@
 
 static const struct file_operations sync_file_fops;
 
+static int fence_file_init(struct fence_file *fence_file,
+			   const struct file_operations *fops)
+{
+	fence_file->file = anon_inode_getfile("fence_file", fops,
+					     fence_file, 0);
+	if (IS_ERR(fence_file->file))
+		return PTR_ERR(fence_file->file);
+	return 0;
+}
+
 static struct sync_file *sync_file_alloc(void)
 {
 	struct sync_file *sync_file;
+	int ret;
 
 	sync_file = kzalloc(sizeof(*sync_file), GFP_KERNEL);
 	if (!sync_file)
 		return NULL;
 
-	sync_file->file = anon_inode_getfile("sync_file", &sync_file_fops,
-					     sync_file, 0);
-	if (IS_ERR(sync_file->file))
+	ret = fence_file_init(&sync_file->base,
+			      &sync_file_fops);
+	if (ret)
 		goto err;
 
 	init_waitqueue_head(&sync_file->wq);
@@ -67,7 +78,7 @@ static void fence_check_cb_func(struct dma_fence *f, struct dma_fence_cb *cb)
  *
  * Creates a sync_file containg @fence. This function acquires and additional
  * reference of @fence for the newly-created &sync_file, if it succeeds. The
- * sync_file can be released with fput(sync_file->file). Returns the
+ * sync_file can be released with fput(sync_file->base.file). Returns the
  * sync_file or NULL in case of error.
  */
 struct sync_file *sync_file_create(struct dma_fence *fence)
@@ -78,7 +89,7 @@ struct sync_file *sync_file_create(struct dma_fence *fence)
 	if (!sync_file)
 		return NULL;
 
-	RCU_INIT_POINTER(sync_file->fence, dma_fence_get(fence));
+	RCU_INIT_POINTER(sync_file->base.fence, dma_fence_get(fence));
 
 	snprintf(sync_file->name, sizeof(sync_file->name), "%s-%s%llu-%d",
 		 fence->ops->get_driver_name(fence),
@@ -122,8 +133,8 @@ struct dma_fence *sync_file_get_fence(int fd)
 	if (!sync_file)
 		return NULL;
 
-	fence = dma_fence_get(rcu_dereference_protected(sync_file->fence, 1));
-	fput(sync_file->file);
+	fence = dma_fence_get(rcu_dereference_protected(sync_file->base.fence, 1));
+	fput(sync_file->base.file);
 
 	return fence;
 }
@@ -141,7 +152,7 @@ static int sync_file_set_fence(struct sync_file *sync_file,
 	 * we own the reference of the dma_fence_array creation.
 	 */
 	if (num_fences == 1) {
-		RCU_INIT_POINTER(sync_file->fence, fences[0]);
+		RCU_INIT_POINTER(sync_file->base.fence, fences[0]);
 		kfree(fences);
 	} else {
 		array = dma_fence_array_create(num_fences, fences,
@@ -150,7 +161,7 @@ static int sync_file_set_fence(struct sync_file *sync_file,
 		if (!array)
 			return -ENOMEM;
 
-		RCU_INIT_POINTER(sync_file->fence, &array->base);
+		RCU_INIT_POINTER(sync_file->base.fence, &array->base);
 	}
 
 	return 0;
@@ -159,7 +170,7 @@ static int sync_file_set_fence(struct sync_file *sync_file,
 static struct dma_fence **get_fences(struct sync_file *sync_file,
 				     int *num_fences)
 {
-	struct dma_fence *fence = rcu_dereference_protected(sync_file->fence, 1);
+	struct dma_fence *fence = rcu_dereference_protected(sync_file->base.fence, 1);
 	if (dma_fence_is_array(fence)) {
 		struct dma_fence_array *array = to_dma_fence_array(fence);
 
@@ -168,7 +179,7 @@ static struct dma_fence **get_fences(struct sync_file *sync_file,
 	}
 
 	*num_fences = 1;
-	return &sync_file->fence;
+	return &sync_file->base.fence;
 }
 
 static void add_fence(struct dma_fence **fences,
@@ -271,7 +282,7 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
 	return sync_file;
 
 err:
-	fput(sync_file->file);
+	fput(sync_file->base.file);
 	return NULL;
 
 }
@@ -281,7 +292,7 @@ static int sync_file_release(struct inode *inode, struct file *file)
 	struct sync_file *sync_file = file->private_data;
 	struct dma_fence *fence;
 
-	fence = rcu_dereference_protected(sync_file->fence, 1);
+	fence = rcu_dereference_protected(sync_file->base.fence, 1);
 	if (test_bit(POLL_ENABLED, &fence->flags))
 		dma_fence_remove_callback(fence, &sync_file->cb);
 	dma_fence_put(fence);
@@ -295,7 +306,7 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait)
 	struct sync_file *sync_file = file->private_data;
 	struct dma_fence *fence;
 
-	fence = rcu_dereference_protected(sync_file->fence, 1);
+	fence = rcu_dereference_protected(sync_file->base.fence, 1);
 
 	poll_wait(file, &sync_file->wq, wait);
 
@@ -348,15 +359,15 @@ static long sync_file_ioctl_merge(struct sync_file *sync_file,
 		goto err_put_fence3;
 	}
 
-	fd_install(fd, fence3->file);
-	fput(fence2->file);
+	fd_install(fd, fence3->base.file);
+	fput(fence2->base.file);
 	return 0;
 
 err_put_fence3:
-	fput(fence3->file);
+	fput(fence3->base.file);
 
 err_put_fence2:
-	fput(fence2->file);
+	fput(fence2->base.file);
 
 err_put_fd:
 	put_unused_fd(fd);
@@ -420,7 +431,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
 
 no_fences:
 	strlcpy(info.name, sync_file->name, sizeof(info.name));
-	info.status = dma_fence_is_signaled(rcu_dereference_protected(sync_file->fence, 1));
+	info.status = dma_fence_is_signaled(rcu_dereference_protected(sync_file->base.fence, 1));
 	info.num_fences = num_fences;
 
 	if (copy_to_user((void __user *)arg, &info, sizeof(info)))
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index a567310..16053a0 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -2012,7 +2012,7 @@ static void complete_crtc_signaling(struct drm_device *dev,
 	if (install_fds) {
 		for (i = 0; i < num_fences; i++)
 			fd_install(fence_state[i].fd,
-				   fence_state[i].sync_file->file);
+				   fence_state[i].sync_file->base.file);
 
 		kfree(fence_state);
 		return;
@@ -2036,7 +2036,7 @@ static void complete_crtc_signaling(struct drm_device *dev,
 
 	for (i = 0; i < num_fences; i++) {
 		if (fence_state[i].sync_file)
-			fput(fence_state[i].sync_file->file);
+			fput(fence_state[i].sync_file->base.file);
 		if (fence_state[i].fd >= 0)
 			put_unused_fd(fence_state[i].fd);
 
diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h
index adbc0b9..b0ae1cf 100644
--- a/include/linux/sync_file.h
+++ b/include/linux/sync_file.h
@@ -21,24 +21,31 @@
 #include <linux/dma-fence-array.h>
 
 /**
- * struct sync_file - sync file to export to the userspace
+ * struct fence_file - basic file to fence mapping
  * @file:		file representing this fence
+ * @fence:		fence with the fences in the fence_file
+ */
+struct fence_file {
+	struct file		*file;
+	struct dma_fence	__rcu *fence;
+};
+
+/**
+ * struct sync_file - sync file to export to the userspace
+ * @base:               base fence file
  * @name:		name of sync_file.  Useful for debugging
  * @sync_file_list:	membership in global file list
  * @wq:			wait queue for fence signaling
- * @fence:		fence with the fences in the sync_file
  * @cb:			fence callback information
  */
 struct sync_file {
-	struct file		*file;
+	struct fence_file       base;
 	char			name[32];
 #ifdef CONFIG_DEBUG_FS
 	struct list_head	sync_file_list;
 #endif
 
 	wait_queue_head_t	wq;
-
-	struct dma_fence	__rcu *fence;
 	struct dma_fence_cb cb;
 };
 
-- 
2.9.3

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

  parent reply	other threads:[~2017-04-13  1:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13  1:41 [rfc repost] drm sync objects - a new beginning (make ickle happier?) Dave Airlie
     [not found] ` <20170413014144.637-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-13  1:41   ` [PATCH 1/7] sync_file: get rid of internal reference count Dave Airlie
     [not found]     ` <20170413014144.637-2-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-17 13:13       ` Gustavo Padovan
2017-04-17 15:14         ` Sumit Semwal
     [not found]           ` <CAO_48GHYX7oDv3MtD5XhoQOSyYZOF_byP+niV0YC7f1ZhHvL1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-18 14:38             ` Gustavo Padovan
2017-04-13  1:41   ` Dave Airlie [this message]
2017-04-19 12:02     ` [PATCH 3/7] sync_file: split out fence_file base class from sync_file Christian König
2017-04-13  1:41   ` [PATCH 4/7] sync_file: add support for sem_file Dave Airlie
     [not found]     ` <20170413014144.637-5-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-13  2:52       ` Chris Wilson
2017-04-19 12:07   ` [rfc repost] drm sync objects - a new beginning (make ickle happier?) Christian König
2017-04-19 17:14     ` James Jones
     [not found]     ` <0734833f-e6f2-b5f3-9687-f21f82fd8599-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-04-19 18:42       ` Dave Airlie
2017-04-19 19:14         ` Dave Airlie
2017-04-20  8:36           ` Christian König
2017-04-13  1:41 ` [PATCH 2/7] sync_file: mark the fence pointer as rcu Dave Airlie
2017-04-13  1:41 ` [PATCH 5/7] drm: introduce sync objects as wrappers for sem files Dave Airlie
2017-04-13  1:41 ` [PATCH 6/7] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-04-13  1:41 ` [PATCH 7/7] amdgpu: use sync file for shared semaphores (v3) Dave Airlie

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=20170413014144.637-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox