linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@canonical.com>
To: sumit.semwal@linaro.org, rob.clark@linaro.org,
	linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org
Subject: Re: [Linaro-mm-sig] [PATCH 3/4] dma-seqno-fence: Hardware dma-buf implementation of fencing (v2)
Date: Sat, 11 Aug 2012 18:05:21 +0200	[thread overview]
Message-ID: <502682C1.4060609@canonical.com> (raw)
In-Reply-To: <20120810195749.GH5738@phenom.ffwll.local>

Op 10-08-12 21:57, Daniel Vetter schreef:
> On Fri, Aug 10, 2012 at 04:57:58PM +0200, Maarten Lankhorst wrote:
>> This type of fence can be used with hardware synchronization for simple
>> hardware that can block execution until the condition
>> (dma_buf[offset] - value) >= 0 has been met.
>>
>> A software fallback still has to be provided in case the fence is used
>> with a device that doesn't support this mechanism. It is useful to expose
>> this for graphics cards that have an op to support this.
>>
>> Some cards like i915 can export those, but don't have an option to wait,
>> so they need the software fallback.
>>
>> I extended the original patch by Rob Clark.
>>
>> v1: Original
>> v2: Renamed from bikeshed to seqno, moved into dma-fence.c since
>>     not much was left of the file. Lots of documentation added.
>>
>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
> Patch looks good, two bikesheds inline. Either way
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>
>> ---
>>  drivers/base/dma-fence.c  |   21 +++++++++++++++
>>  include/linux/dma-fence.h |   61 +++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 82 insertions(+)
>>
>> diff --git a/drivers/base/dma-fence.c b/drivers/base/dma-fence.c
>> index 93448e4..4092a58 100644
>> --- a/drivers/base/dma-fence.c
>> +++ b/drivers/base/dma-fence.c
>> @@ -266,3 +266,24 @@ struct dma_fence *dma_fence_create(void *priv)
>>  	return fence;
>>  }
>>  EXPORT_SYMBOL_GPL(dma_fence_create);
>> +
>> +static int seqno_enable_signaling(struct dma_fence *fence)
>> +{
>> +	struct dma_seqno_fence *seqno_fence = to_seqno_fence(fence);
>> +	return seqno_fence->enable_signaling(seqno_fence);
>> +}
>> +
>> +static void seqno_release(struct dma_fence *fence)
>> +{
>> +	struct dma_seqno_fence *f = to_seqno_fence(fence);
>> +
>> +	if (f->release)
>> +		f->release(f);
>> +	dma_buf_put(f->sync_buf);
>> +}
>> +
>> +const struct dma_fence_ops dma_seqno_fence_ops = {
>> +	.enable_signaling = seqno_enable_signaling,
>> +	.release = seqno_release
>> +};
>> +EXPORT_SYMBOL_GPL(dma_seqno_fence_ops);
>> diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
>> index e0ceddd..3ef0da0 100644
>> --- a/include/linux/dma-fence.h
>> +++ b/include/linux/dma-fence.h
>> @@ -91,6 +91,19 @@ struct dma_fence_ops {
>>  	void (*release)(struct dma_fence *fence);
>>  };
>>  
>> +struct dma_seqno_fence {
>> +	struct dma_fence base;
>> +
>> +	struct dma_buf *sync_buf;
>> +	uint32_t seqno_ofs;
>> +	uint32_t seqno;
>> +
>> +	int (*enable_signaling)(struct dma_seqno_fence *fence);
>> +	void (*release)(struct dma_seqno_fence *fence);
> I think using dma_fence_ops here is the better color. We lose type-safety
> at compile-time, but still keep type-safety at runtime (thanks to
> to_dma_seqno_fence). In addition people seem to like to constify function
> pointers, we'd save a pointer and if we extend the sw dma_fence interface.
Ok, will change.

>> +};
>> +
>> +extern const struct dma_fence_ops dma_seqno_fence_ops;
>> +
>>  struct dma_fence *dma_fence_create(void *priv);
>>  
>>  /**
>> @@ -121,4 +134,52 @@ int dma_fence_wait(struct dma_fence *fence, bool intr, unsigned long timeout);
>>  int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
>>  			   dma_fence_func_t func, void *priv);
>>  
>> +/**
>> + * to_seqno_fence - cast a dma_fence to a dma_seqno_fence
>> + * @fence: dma_fence to cast to a dma_seqno_fence
>> + *
>> + * Returns NULL if the dma_fence is not a dma_seqno_fence,
>> + * or the dma_seqno_fence otherwise.
>> + */
>> +static inline struct dma_seqno_fence *
>> +to_seqno_fence(struct dma_fence *fence)
>> +{
>> +	if (fence->ops != &dma_seqno_fence_ops)
>> +		return NULL;
>> +	return container_of(fence, struct dma_seqno_fence, base);
>> +}
> I think adding an is_dma_seqno_fence would be nice ...
#define is_dma_seqno_fence !!to_dma_seqno_fence

The first thing you would do after finding out it's a seqno fence
is calling to_dma_seqno_fence, otherwise why would you care?
As such the check was pointless and deleted.

My bikeshed, go build your own!

>> +
>> +/**
>> + * dma_seqno_fence_init - initialize a seqno fence
>> + * @fence: dma_seqno_fence to initialize
>> + * @sync_buf: buffer containing the memory location to signal on
>> + * @seqno_ofs: the offset within @sync_buf
>> + * @seqno: the sequence # to signal on
>> + * @priv: value of priv member
>> + * @enable_signaling: callback which is called when some other device is
>> + *    waiting for sw notification of fence
>> + * @release: callback called during destruction before object is freed.
>> + *
>> + * This function initializes a struct dma_seqno_fence with passed parameters,
>> + * and takes a reference on sync_buf which is released on fence destruction.
>> + */
>> +static inline void
>> +dma_seqno_fence_init(struct dma_seqno_fence *fence,
>> +			struct dma_buf *sync_buf,
>> +			uint32_t seqno_ofs, uint32_t seqno, void *priv,
>> +			int (*enable_signaling)(struct dma_seqno_fence *),
>> +			void (*release)(struct dma_seqno_fence *))
>> +{
>> +	BUG_ON(!fence || !sync_buf || !enable_signaling);
>> +
>> +	__dma_fence_init(&fence->base, &dma_seqno_fence_ops, priv);
>> +
>> +	get_dma_buf(sync_buf);
>> +	fence->sync_buf = sync_buf;
>> +	fence->seqno_ofs = seqno_ofs;
>> +	fence->seqno = seqno;
>> +	fence->enable_signaling = enable_signaling;
>> +	fence->release = release;
>> +}
>> +
>>  #endif /* __DMA_FENCE_H__ */
>>
>>
>> _______________________________________________
>> Linaro-mm-sig mailing list
>> Linaro-mm-sig@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/linaro-mm-sig


  reply	other threads:[~2012-08-11 16:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 14:57 [PATCH 1/4] dma-buf: remove fallback for !CONFIG_DMA_SHARED_BUFFER Maarten Lankhorst
2012-08-10 14:57 ` [PATCH 2/4] dma-fence: dma-buf synchronization (v8 ) Maarten Lankhorst
2012-08-10 20:29   ` [Linaro-mm-sig] " Daniel Vetter
2012-08-11 15:14     ` Rob Clark
2012-08-11 16:00       ` Maarten Lankhorst
2012-08-11 19:39         ` Daniel Vetter
2012-08-13 12:43           ` Maarten Lankhorst
2012-08-11 19:22       ` Daniel Vetter
2012-08-11 20:50         ` Rob Clark
2012-08-12  9:34   ` Daniel Vetter
2012-08-29 17:49   ` Francesco Lavra
2012-08-10 14:57 ` [PATCH 3/4] dma-seqno-fence: Hardware dma-buf implementation of fencing (v2) Maarten Lankhorst
2012-08-10 19:57   ` [Linaro-mm-sig] " Daniel Vetter
2012-08-11 16:05     ` Maarten Lankhorst [this message]
2012-08-10 14:58 ` [PATCH 4/4] dma-buf-mgr: multiple dma-buf synchronization (v3) Maarten Lankhorst
2012-08-15 23:12   ` [Linaro-mm-sig] " Daniel Vetter
2012-08-22 11:50     ` [RFC patch 4/4] " Maarten Lankhorst
2012-08-22 12:52       ` Thomas Hellstrom
2012-08-22 13:32         ` Maarten Lankhorst
2012-08-22 14:12           ` Thomas Hellstrom
2012-08-22 15:13         ` Daniel Vetter
2012-08-10 19:32 ` [Linaro-mm-sig] [PATCH 1/4] dma-buf: remove fallback for !CONFIG_DMA_SHARED_BUFFER Daniel Vetter
2012-08-11 15:17   ` Rob Clark

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=502682C1.4060609@canonical.com \
    --to=maarten.lankhorst@canonical.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=rob.clark@linaro.org \
    --cc=sumit.semwal@linaro.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).