All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomasz Stanislawski <t.stanislaws@samsung.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	airlied@redhat.com, m.szyprowski@samsung.com,
	kyungmin.park@samsung.com, sumit.semwal@ti.com,
	daeinki@gmail.com, daniel.vetter@ffwll.ch, robdclark@gmail.com,
	pawel@osciak.com, linaro-mm-sig@lists.linaro.org,
	remi@remlab.net, subashrp@gmail.com, mchehab@redhat.com,
	zhangfei.gao@gmail.com, s.nawrocki@samsung.com,
	k.debski@samsung.com
Subject: Re: [PATCHv9 18/25] v4l: add buffer exporting via dmabuf
Date: Mon, 08 Oct 2012 12:41:28 +0200	[thread overview]
Message-ID: <5072ADD8.90709@samsung.com> (raw)
In-Reply-To: <201210081154.57646.hverkuil@xs4all.nl>

Hi Hans,

On 10/08/2012 11:54 AM, Hans Verkuil wrote:
> On Mon October 8 2012 11:40:37 Tomasz Stanislawski wrote:
>> Hi Hans,
>>
>> On 10/07/2012 04:17 PM, Hans Verkuil wrote:
>>> On Sun October 7 2012 15:38:30 Laurent Pinchart wrote:
>>>> Hi Hans,
>>>>
>>>> On Friday 05 October 2012 10:55:40 Hans Verkuil wrote:
>>>>> On Tue October 2 2012 16:27:29 Tomasz Stanislawski wrote:
>>>>>> This patch adds extension to V4L2 api. It allow to export a mmap buffer as
>>>>>> file descriptor. New ioctl VIDIOC_EXPBUF is added. It takes a buffer
>>>>>> offset used by mmap and return a file descriptor on success.
>>>>>>
>>>>>> Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
>>>>>> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
[snip]
>>>>>> +struct v4l2_exportbuffer {
>>>>>> +	__s32		fd;
>>>>>> +	__u32		flags;
>>>>>> +	__u32		type; /* enum v4l2_buf_type */
>>>>>> +	__u32		index;
>>>>>> +	__u32		plane;
>>>>>
>>>>> As suggested in my comments in the previous patch, I think it is a more
>>>>> natural order to have the type/index/plane fields first in this struct.
>>>>>
>>>>> Actually, I think that flags should also come before fd:
>>>>>
>>>>> struct v4l2_exportbuffer {
>>>>> 	__u32		type; /* enum v4l2_buf_type */
>>>>> 	__u32		index;
>>>>> 	__u32		plane;
>>>>> 	__u32		flags;
>>>>> 	__s32		fd;
>>>>> 	__u32		reserved[11];
>>>>> };
>>>>
>>>> It would indeed feel more natural, but putting them right before the reserved 
>>>> fields allows creating an anonymous union around type, index and plane and 
>>>> extending it with reserved fields if needed. That's (at least to my 
>>>> understanding) the rationale behind the current structure layout.
>>>
>>> The anonymous union argument makes no sense to me, to be honest.
>>
>> I agree that the anonymous unions are not good solutions because they are not
>> supported in many C dialects. However I have nothing against using named unions.
> 
> Named or unnamed, I don't see how a union will help. What do you want to do
> with a union?
> 

Currently, there exist three sane layouts of the structure, that use
only one reserved field:

A)
struct v4l2_exportbuffer {
	__s32		fd;
	__u32		flags;
	__u32		type; /* enum v4l2_buf_type */
	__u32		index;
	__u32		plane;
	__u32		reserved[11];
}

B)
struct v4l2_exportbuffer {
	__u32		type; /* enum v4l2_buf_type */
	__u32		index;
	__u32		plane;
	__u32		flags;
	__s32		fd;
	__u32		reserved[11];
}

C)
struct v4l2_exportbuffer {
	__u32		type; /* enum v4l2_buf_type */
	__u32		index;
	__u32		plane;
	__u32		reserved[11];
	__u32		flags;
	__s32		fd;
}

Only the layout B follows 'input/output/reserved' rule.

The layouts A and C allows to extend (type/index/plane) tuple without mixing
it with (flags,fd).

For layouts A and C it is possible to use unions to provide new
means of describing a buffer to be exported.

struct v4l2_exportbuffer {
	__s32		fd;
	__u32		flags;
	union {
		struct by_tip { /* type, index, plane */
			__u32		type; /* enum v4l2_buf_type */
			__u32		index;
			__u32		plane;
		} by_tip;
		struct by_userptr {
			u64	userptr;
			u64	length;
		} by_userptr;
		__u32	reserved[6];
	} b;
	__u32	union_type; /* BY_TIP or BY_USERPTR */
	__u32	reserved[4];
};

No such an extension can be applied for layout B.

The similar scheme can be used for layout C. Moreover it support
extensions and variants for (flags/fd) tuple. It might be
useful if one day we would like to export a buffer as something
different from DMABUF file descriptors.

Anyway, we have to choose between the elegance of the layout
and the extensibility.

I think that layout A is a good trade-off.
We could swap fd and flags to get little closer to "the rule".

>>
>>> It's standard practice within V4L2 to have the IN fields first, then the OUT fields, followed
>>> by reserved fields for future expansion.
>>
>> IMO, the "input/output/reserved rule" is only a recommendation.
>> The are places in V4L2 where this rule is violated with structure
>> v4l2_buffer being the most notable example.
>>
>> Notice that if at least one of the reserved fields becomes an input
>> file then "the rule" will be violated anyway.
> 
> Sure, but there is no legacy yet, so why not keep to the recommendation?
> 
>>> Should we ever need a, say, sub-plane
>>> index (whatever that might be), then we can use one of the reserved fields.
>>
>> Maybe not subplane :).
>> But maybe some data_offset for exporting only a part of the buffer will
>> be needed some day.
>> Moreover, the integration of DMABUF with the DMA synchronization framework
>> may involve passing additional parameters from the userspace.
>>
>> Notice that flags and fd fields are not logically connected with
>> (type/index/plane) tuple.
>> Therefore both field sets should be separated by some reserved fields to
>> ensure that any of them can be extended if needed.
>>
>> This was the rationale for the structure layout in v9.
> 
> It's a bad idea to add multiple 'reserved' arrays, that makes userspace harder
> since it has to zero all of them instead of just one. Actually, the same applies
> to kernel space, which has to zero them as well.

Userspace usually cleans the whole structure using memset call.
Notice that memset is a build-in functions therefore fields
are not zeroed if they are initialized just below memset.

The number of reserved fields has no impact on initialization code.
There has also negligible impact on performance (if any at all).

Regards,
Tomasz Stanislawski

> 
> I still don't know why you want to use a non-standard field order.
> 
> Regards,
> 
> 	Hans
> 

  reply	other threads:[~2012-10-08 10:41 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-02 14:27 [PATCHv9 00/25] Integration of videobuf2 with DMABUF Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 01/25] v4l: Add DMABUF as a memory type Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 02/25] Documentation: media: description of DMABUF importing in V4L2 Tomasz Stanislawski
2012-10-05  8:05   ` Hans Verkuil
2012-10-02 14:27 ` [PATCHv9 03/25] v4l: vb2: add support for shared buffer (dma_buf) Tomasz Stanislawski
2012-10-05  8:17   ` Hans Verkuil
2012-10-02 14:27 ` [PATCHv9 04/25] v4l: vb: remove warnings about MEMORY_DMABUF Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 05/25] v4l: vb2-dma-contig: shorten vb2_dma_contig prefix to vb2_dc Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 06/25] v4l: vb2-dma-contig: remove reference of alloc_ctx from a buffer Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 07/25] v4l: vb2-dma-contig: reorder functions Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 08/25] v4l: vb2-dma-contig: add support for scatterlist in userptr mode Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 09/25] v4l: vb2: add prepare/finish callbacks to allocators Tomasz Stanislawski
2012-10-05  8:22   ` Hans Verkuil
2012-10-02 14:27 ` [PATCHv9 10/25] v4l: vb2-dma-contig: add prepare/finish to dma-contig allocator Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 11/25] v4l: vb2-dma-contig: add support for dma_buf importing Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 12/25] v4l: vb2-vmalloc: add support for dmabuf importing Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 13/25] v4l: vivi: " Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 14/25] v4l: s5p-tv: mixer: " Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 15/25] v4l: s5p-fimc: " Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 16/25] v4l: vb2-dma-contig: let mmap method to use dma_mmap_coherent call Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 17/25] Documentation: media: description of DMABUF exporting in V4L2 Tomasz Stanislawski
2012-10-05  8:44   ` Hans Verkuil
2012-10-02 14:27 ` [PATCHv9 18/25] v4l: add buffer exporting via dmabuf Tomasz Stanislawski
2012-10-05  8:55   ` Hans Verkuil
2012-10-07 13:38     ` Laurent Pinchart
2012-10-07 14:17       ` Hans Verkuil
2012-10-08  9:40         ` Tomasz Stanislawski
2012-10-08  9:54           ` Hans Verkuil
2012-10-08 10:41             ` Tomasz Stanislawski [this message]
2012-10-08 11:15               ` Hans Verkuil
2012-10-02 14:27 ` [PATCHv9 19/25] v4l: vb2: " Tomasz Stanislawski
2012-10-06 12:22   ` Hans Verkuil
2012-10-10 14:05     ` Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 20/25] v4l: vb2-dma-contig: add support for DMABUF exporting Tomasz Stanislawski
2012-10-07 13:38   ` Laurent Pinchart
2012-10-02 14:27 ` [PATCHv9 21/25] v4l: vb2-dma-contig: add reference counting for a device from allocator context Tomasz Stanislawski
2012-10-07 13:38   ` Laurent Pinchart
2012-10-02 14:27 ` [PATCHv9 22/25] v4l: vb2-dma-contig: fail if user ptr buffer is not correctly aligned Tomasz Stanislawski
2012-10-07 13:38   ` Laurent Pinchart
2012-10-02 14:27 ` [PATCHv9 23/25] v4l: s5p-fimc: support for dmabuf exporting Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 24/25] v4l: s5p-tv: mixer: " Tomasz Stanislawski
2012-10-02 14:27 ` [PATCHv9 25/25] v4l: s5p-mfc: " Tomasz Stanislawski
2012-10-05  9:24 ` [PATCHv9 00/25] Integration of videobuf2 with DMABUF Hans Verkuil
2012-10-07 10:03 ` Hans Verkuil
2012-10-10 10:54 ` Mauro Carvalho Chehab
2012-10-10 11:11   ` [Linaro-mm-sig] " Kyungmin Park
2012-10-10 11:11     ` Kyungmin Park
2012-10-10 13:34   ` Laurent Pinchart

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=5072ADD8.90709@samsung.com \
    --to=t.stanislaws@samsung.com \
    --cc=airlied@redhat.com \
    --cc=daeinki@gmail.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hverkuil@xs4all.nl \
    --cc=k.debski@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@redhat.com \
    --cc=pawel@osciak.com \
    --cc=remi@remlab.net \
    --cc=robdclark@gmail.com \
    --cc=s.nawrocki@samsung.com \
    --cc=subashrp@gmail.com \
    --cc=sumit.semwal@ti.com \
    --cc=zhangfei.gao@gmail.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.