All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gustavo Padovan <gustavo@padovan.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: marcheu@google.com, Daniel Stone <daniels@collabora.com>,
	seanpaul@google.com, Daniel Vetter <daniel.vetter@ffwll.ch>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	m.chehab@samsung.com,
	Gustavo Padovan <gustavo.padovan@collabora.co.uk>,
	John Harrison <John.C.Harrison@Intel.com>,
	laurent.pinchart@ideasonboard.com
Subject: Re: [PATCH] dma-buf/sync_file: only enable fence signalling during wait
Date: Tue, 12 Jul 2016 10:43:59 -0300	[thread overview]
Message-ID: <20160712134359.GD2565@joana> (raw)
In-Reply-To: <58ef685f-0308-6828-6e21-ab5fd1302b84@linux.intel.com>

2016-07-12 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:

> Op 11-07-16 om 22:27 schreef Gustavo Padovan:
> > 2016-07-10 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
> >
> >> Op 08-07-16 om 17:44 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>> Signalling doesn't need to be enabled at sync_file creation, it is only
> >>> required if userspace waiting the fence to signal through poll().
> >>>
> >>> Thus we delay fence_add_callback() until poll is called. It only adds the
> >>> callback the first time poll() is called. This avoid re-adding the same
> >>> callback multiple times.
> >>>
> >>> v2: rebase and update to work with new fence support for sync_file
> >>>
> >>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>> ---
> >>> This patch applies on top of my latest sync_file changes to support
> >>> fence_array: https://lkml.org/lkml/2016/7/4/534
> >>>
> >>>  drivers/dma-buf/sync_file.c | 23 ++++++++++++++---------
> >>>  include/linux/sync_file.h   |  2 ++
> >>>  2 files changed, 16 insertions(+), 9 deletions(-)
> >>>
> >>> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> >>> index 61a687c..1db4a64 100644
> >>> --- a/drivers/dma-buf/sync_file.c
> >>> +++ b/drivers/dma-buf/sync_file.c
> >>> @@ -86,8 +86,6 @@ struct sync_file *sync_file_create(struct fence *fence)
> >>>  		 fence->ops->get_timeline_name(fence), fence->context,
> >>>  		 fence->seqno);
> >>>  
> >>> -	fence_add_callback(fence, &sync_file->cb, fence_check_cb_func);
> >>> -
> >>>  	return sync_file;
> >>>  }
> >>>  EXPORT_SYMBOL(sync_file_create);
> >>> @@ -269,9 +267,6 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
> >>>  		goto err;
> >>>  	}
> >>>  
> >>> -	fence_add_callback(sync_file->fence, &sync_file->cb,
> >>> -			   fence_check_cb_func);
> >>> -
> >>>  	strlcpy(sync_file->name, name, sizeof(sync_file->name));
> >>>  	return sync_file;
> >>>  
> >>> @@ -286,7 +281,6 @@ static void sync_file_free(struct kref *kref)
> >>>  	struct sync_file *sync_file = container_of(kref, struct sync_file,
> >>>  						     kref);
> >>>  
> >>> -	fence_remove_callback(sync_file->fence, &sync_file->cb);
> >>>  	fence_put(sync_file->fence);
> >>>  	kfree(sync_file);
> >>>  }
> >>> @@ -306,13 +300,24 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait)
> >>>  
> >>>  	poll_wait(file, &sync_file->wq, wait);
> >>>  
> >>> +	if (!sync_file->enabled) {
> >>> +		fence_add_callback(sync_file->fence, &sync_file->cb,
> >>> +				   fence_check_cb_func);
> >>> +		sync_file->enabled = true;
> >>> +	}
> >> Won't this blow up completely with 2 threads polling at the same time?
> > Indeed, using atomic operations on enabled should fix this.
> No, it still would blow up without locking around fence_remove/add_callback too..
> 
> Personally I would just add the callback once, then remove it in destructor.
> 
> Something like:
> 
> poll:
> if (!atomic_xchg(&sync_file->enabled, 1)) {
> if (fence_add_callback(...) < 0)
> wake up sync_file->wq, fence is signaled
> }
> 
> sync_file_free:
> if (atomic_read(&sync_file->enabled))
> fence_remove_callback(...);
> 
> fence_put()
> 
> It's not like fence can disable hw signaling when all callbacks are removed anyway,
> it's harmless to keep it on the list.

Move the callback removal to sync_file_free() seems a good idea to me.
I'll rework this patch taking in account your suggestions and resend it.

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

WARNING: multiple messages have this Message-ID (diff)
From: Gustavo Padovan <gustavo@padovan.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Daniel Stone <daniels@collabora.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Rob Clark <robdclark@gmail.com>,
	Greg Hackmann <ghackmann@google.com>,
	John Harrison <John.C.Harrison@Intel.com>,
	laurent.pinchart@ideasonboard.com, seanpaul@google.com,
	marcheu@google.com, m.chehab@samsung.com,
	Sumit Semwal <sumit.semwal@linaro.org>,
	Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Subject: Re: [PATCH] dma-buf/sync_file: only enable fence signalling during wait
Date: Tue, 12 Jul 2016 10:43:59 -0300	[thread overview]
Message-ID: <20160712134359.GD2565@joana> (raw)
In-Reply-To: <58ef685f-0308-6828-6e21-ab5fd1302b84@linux.intel.com>

2016-07-12 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:

> Op 11-07-16 om 22:27 schreef Gustavo Padovan:
> > 2016-07-10 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
> >
> >> Op 08-07-16 om 17:44 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>> Signalling doesn't need to be enabled at sync_file creation, it is only
> >>> required if userspace waiting the fence to signal through poll().
> >>>
> >>> Thus we delay fence_add_callback() until poll is called. It only adds the
> >>> callback the first time poll() is called. This avoid re-adding the same
> >>> callback multiple times.
> >>>
> >>> v2: rebase and update to work with new fence support for sync_file
> >>>
> >>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>> ---
> >>> This patch applies on top of my latest sync_file changes to support
> >>> fence_array: https://lkml.org/lkml/2016/7/4/534
> >>>
> >>>  drivers/dma-buf/sync_file.c | 23 ++++++++++++++---------
> >>>  include/linux/sync_file.h   |  2 ++
> >>>  2 files changed, 16 insertions(+), 9 deletions(-)
> >>>
> >>> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> >>> index 61a687c..1db4a64 100644
> >>> --- a/drivers/dma-buf/sync_file.c
> >>> +++ b/drivers/dma-buf/sync_file.c
> >>> @@ -86,8 +86,6 @@ struct sync_file *sync_file_create(struct fence *fence)
> >>>  		 fence->ops->get_timeline_name(fence), fence->context,
> >>>  		 fence->seqno);
> >>>  
> >>> -	fence_add_callback(fence, &sync_file->cb, fence_check_cb_func);
> >>> -
> >>>  	return sync_file;
> >>>  }
> >>>  EXPORT_SYMBOL(sync_file_create);
> >>> @@ -269,9 +267,6 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
> >>>  		goto err;
> >>>  	}
> >>>  
> >>> -	fence_add_callback(sync_file->fence, &sync_file->cb,
> >>> -			   fence_check_cb_func);
> >>> -
> >>>  	strlcpy(sync_file->name, name, sizeof(sync_file->name));
> >>>  	return sync_file;
> >>>  
> >>> @@ -286,7 +281,6 @@ static void sync_file_free(struct kref *kref)
> >>>  	struct sync_file *sync_file = container_of(kref, struct sync_file,
> >>>  						     kref);
> >>>  
> >>> -	fence_remove_callback(sync_file->fence, &sync_file->cb);
> >>>  	fence_put(sync_file->fence);
> >>>  	kfree(sync_file);
> >>>  }
> >>> @@ -306,13 +300,24 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait)
> >>>  
> >>>  	poll_wait(file, &sync_file->wq, wait);
> >>>  
> >>> +	if (!sync_file->enabled) {
> >>> +		fence_add_callback(sync_file->fence, &sync_file->cb,
> >>> +				   fence_check_cb_func);
> >>> +		sync_file->enabled = true;
> >>> +	}
> >> Won't this blow up completely with 2 threads polling at the same time?
> > Indeed, using atomic operations on enabled should fix this.
> No, it still would blow up without locking around fence_remove/add_callback too..
> 
> Personally I would just add the callback once, then remove it in destructor.
> 
> Something like:
> 
> poll:
> if (!atomic_xchg(&sync_file->enabled, 1)) {
> if (fence_add_callback(...) < 0)
> wake up sync_file->wq, fence is signaled
> }
> 
> sync_file_free:
> if (atomic_read(&sync_file->enabled))
> fence_remove_callback(...);
> 
> fence_put()
> 
> It's not like fence can disable hw signaling when all callbacks are removed anyway,
> it's harmless to keep it on the list.

Move the callback removal to sync_file_free() seems a good idea to me.
I'll rework this patch taking in account your suggestions and resend it.

	Gustavo

  reply	other threads:[~2016-07-12 13:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08 15:44 [PATCH] dma-buf/sync_file: only enable fence signalling during wait Gustavo Padovan
2016-07-08 15:44 ` Gustavo Padovan
2016-07-10  9:15 ` Maarten Lankhorst
2016-07-10  9:15   ` Maarten Lankhorst
2016-07-11 20:27   ` Gustavo Padovan
2016-07-12  8:46     ` Maarten Lankhorst
2016-07-12  8:46       ` Maarten Lankhorst
2016-07-12 13:43       ` Gustavo Padovan [this message]
2016-07-12 13:43         ` Gustavo Padovan
2016-07-12 14:08       ` Daniel Vetter
2016-07-12 14:08         ` 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=20160712134359.GD2565@joana \
    --to=gustavo@padovan.org \
    --cc=John.C.Harrison@Intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo.padovan@collabora.co.uk \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marcheu@google.com \
    --cc=seanpaul@google.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 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.