All of lore.kernel.org
 help / color / mirror / Atom feed
From: Keiichi Watanabe <keiichiw@chromium.org>
To: Tomasz Figa <tfiga@chromium.org>
Cc: "Gerd Hoffmann" <kraxel@redhat.com>,
	"Dmitry Sepp" <dmitry.sepp@opensynergy.com>,
	virtio-dev@lists.oasis-open.org,
	"Linux Media Mailing List" <linux-media@vger.kernel.org>,
	"Alexandre Courbot" <acourbot@chromium.org>,
	"Alex Lau" <alexlau@chromium.org>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Dylan Reid" <dgreid@chromium.org>,
	"Enrico Granata" <egranata@google.com>,
	"Frediano Ziglio" <fziglio@redhat.com>,
	"Hans Verkuil" <hverkuil@xs4all.nl>,
	"Stéphane Marchesin" <marcheu@chromium.org>,
	"Pawel Osciak" <posciak@chromium.org>,
	spice-devel@lists.freedesktop.org,
	"David Stevens" <stevensd@chromium.org>,
	uril@redhat.com
Subject: Re: [virtio-dev] Re: [PATCH v2 1/1] virtio-video: Add virtio video device specification
Date: Tue, 14 Jan 2020 16:18:50 +0900	[thread overview]
Message-ID: <CAD90VcbG6kR1Nw6DTr2RjwFrDja2B=Ohje_2MMeKBwpXGZ_MyA@mail.gmail.com> (raw)
In-Reply-To: <CAAFQd5DcYWymWyzdiyfy18HkUBsEhALYG+DLwjXGCpRGDaJqyQ@mail.gmail.com>

Hi,

On Thu, Jan 9, 2020 at 11:21 PM Tomasz Figa <tfiga@chromium.org> wrote:
>
> On Wed, Jan 8, 2020 at 10:52 PM Keiichi Watanabe <keiichiw@chromium.org> wrote:
> >
> > Hi Gerd,
> >
> > On Thu, Dec 19, 2019 at 10:12 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
> > >
> > >   Hi,
> > >
> > > > > However that still doesn't let the driver know which buffers will be
> > > > > dequeued when. A simple example of this scenario is when the guest is
> > > > > done displaying a frame and requeues the buffer back to the decoder.
> > > > > Then the decoder will not choose it for decoding next frames into as
> > > > > long as the frame in that buffer is still used as a reference frame,
> > > > > even if one sends the drain request.
> > > > It might be that I'm getting your point wrong, but do you mean some hardware
> > > > can mark a buffer as ready to be displayed yet still using the underlying
> > > > memory to decode other frames?
> > >
> > > Yes, this is how I understand Tomasz Figa.
> > >
> > > > This means, if you occasionally/intentionally
> > > > write to the buffer you mess up the whole decoding pipeline.
> > >
> > > And to avoid this the buffer handling aspect must be clarified in the
> > > specification.  Is the device allowed to continue using the buffer after
> > > finishing decoding and completing the queue request?  If so, how do we
> > > hand over buffer ownership back to the driver so it can free the pages?
> > > drain request?  How do we handle re-using buffers?  Can the driver
> > > simply re-queue them and expect the device figures by itself whenever it
> > > can use the buffer or whenever it is still needed as reference frame?
> >
> > The device shouldn't be able to access buffers after it completes a
> > queue request.
> > The device can touch buffer contents from when a queue request is sent
> > until the device responds it.
> > In contrast, the driver must not modify buffer contents in that period.
> >
> > Regarding re-using, the driver can simply re-queue buffers returned by
> > the device. If the device needs a buffer as reference frame, it must
> > not return the buffer.
>
> I think that might not be what we expect. We want the decoder to
> return a decoded frame as soon as possible, but that decoded frame may
> be also needed for decoding next frames. In V4L2 stateful decoder, the
> API is defined that the client must not modify the decoded
> framebuffer, otherwise decoding next frames may not be correct.

Thanks Tomasz! I didn't know the V4L2's convention.
So, the host should be able to read a frame buffer after it is
returned by responding RESOURCE_QUEUE command.


> We may
> need something similar, with an explicit operation that makes the
> buffers not accessible to the host anymore. I think the queue flush
> operation could work as such.

After offline discussion with Tomasz, I suspect the queue flush
operation (= VIRTIO_VIDEO_CMD_QUEUE_CLEAR) shouldn't work so, as it
just forces pending QUEUE requests to be backed for video seek.
So, a buffer can be readable from the device once it's queued until
STREAM_DESTROY or RESOURCE_DESTROY is called.

In my understanding, the life cycle of video buffers is defined as
this state machine.
https://drive.google.com/file/d/1c6oY5S_9bhpJlrOt4UfoQex0CanpG-kZ/view?usp=sharing

```
# The definition of the state machine in DOT language
digraph G {
  graph [ rankdir = LR, layout = dot ];

  init [shape=point]
  created [label="created", shape=circle]
  dequeued [label="dequeued", shape=circle]
  queued [label="queued", shape=circle]

  init -> created [label="RESOURCE_CREATE"]

  created -> queued [label="RESOURCE_QUEUE \n is sent"]
  dequeued -> queued [label="RESOURCE_QUEUE \n is sent"]
  queued -> dequeued [label="RESOURCE_QUEUE \n is returned"]

  created -> init [label="DESTROY"]
  dequeued -> init [label="DESTROY"]
}
```

In each state of this figure, the accessibility of each buffer should
be like the following:

# Input buffers
 state   |   Guest    |    Host
-----------------------------------
created  | Read/Write | -
queued   | -          | Read
dequeued | Read/Write | -

# Output buffers
 state   |   Guest    |    Host
----------------------------------
created  | Read       | -
queued   | -          | Read/Write
dequeued | Read       | Read

Does it make sense?
If ok, I'll have this state machine and tables in the next version of
spec to describe device/driver requirements by adding a subsection
about buffer life cycle.


By the way, regarding destruction of buffers, I suspect it doesn't
make much sense to have RESOURCE_DESTROY command. Though it was
suggested as a per-buffer command, it doesn't match the existing V4L2
API, as REQBUFS(0) destroys all buffers at once. I guess per-buffer
destruction would require hardware or firmware supports.
Even if we want to destroy buffers at once, we can destroy the stream
and recreate one. So, I wonder if we can remove RESOURCE_DESTROY
command from the first version of spec at least.
What do you think?

Best regards,
Keiichi


>
> > I'll describe this rule in the next version of the patch.
> >
> > Best regards,
> > Keiichi
> >
> > >
> > > cheers,
> > >   Gerd
> > >

WARNING: multiple messages have this Message-ID (diff)
From: Keiichi Watanabe <keiichiw@chromium.org>
To: Tomasz Figa <tfiga@chromium.org>
Cc: "Gerd Hoffmann" <kraxel@redhat.com>,
	"Dmitry Sepp" <dmitry.sepp@opensynergy.com>,
	virtio-dev@lists.oasis-open.org,
	"Linux Media Mailing List" <linux-media@vger.kernel.org>,
	"Alexandre Courbot" <acourbot@chromium.org>,
	"Alex Lau" <alexlau@chromium.org>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Dylan Reid" <dgreid@chromium.org>,
	"Enrico Granata" <egranata@google.com>,
	"Frediano Ziglio" <fziglio@redhat.com>,
	"Hans Verkuil" <hverkuil@xs4all.nl>,
	"Stéphane Marchesin" <marcheu@chromium.org>,
	"Pawel Osciak" <posciak@chromium.org>,
	spice-devel@lists.freedesktop.org,
	"David Stevens" <stevensd@chromium.org>,
	uril@redhat.com
Subject: Re: [virtio-dev] Re: [PATCH v2 1/1] virtio-video: Add virtio video device specification
Date: Tue, 14 Jan 2020 16:18:50 +0900	[thread overview]
Message-ID: <CAD90VcbG6kR1Nw6DTr2RjwFrDja2B=Ohje_2MMeKBwpXGZ_MyA@mail.gmail.com> (raw)
In-Reply-To: <CAAFQd5DcYWymWyzdiyfy18HkUBsEhALYG+DLwjXGCpRGDaJqyQ@mail.gmail.com>

Hi,

On Thu, Jan 9, 2020 at 11:21 PM Tomasz Figa <tfiga@chromium.org> wrote:
>
> On Wed, Jan 8, 2020 at 10:52 PM Keiichi Watanabe <keiichiw@chromium.org> wrote:
> >
> > Hi Gerd,
> >
> > On Thu, Dec 19, 2019 at 10:12 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
> > >
> > >   Hi,
> > >
> > > > > However that still doesn't let the driver know which buffers will be
> > > > > dequeued when. A simple example of this scenario is when the guest is
> > > > > done displaying a frame and requeues the buffer back to the decoder.
> > > > > Then the decoder will not choose it for decoding next frames into as
> > > > > long as the frame in that buffer is still used as a reference frame,
> > > > > even if one sends the drain request.
> > > > It might be that I'm getting your point wrong, but do you mean some hardware
> > > > can mark a buffer as ready to be displayed yet still using the underlying
> > > > memory to decode other frames?
> > >
> > > Yes, this is how I understand Tomasz Figa.
> > >
> > > > This means, if you occasionally/intentionally
> > > > write to the buffer you mess up the whole decoding pipeline.
> > >
> > > And to avoid this the buffer handling aspect must be clarified in the
> > > specification.  Is the device allowed to continue using the buffer after
> > > finishing decoding and completing the queue request?  If so, how do we
> > > hand over buffer ownership back to the driver so it can free the pages?
> > > drain request?  How do we handle re-using buffers?  Can the driver
> > > simply re-queue them and expect the device figures by itself whenever it
> > > can use the buffer or whenever it is still needed as reference frame?
> >
> > The device shouldn't be able to access buffers after it completes a
> > queue request.
> > The device can touch buffer contents from when a queue request is sent
> > until the device responds it.
> > In contrast, the driver must not modify buffer contents in that period.
> >
> > Regarding re-using, the driver can simply re-queue buffers returned by
> > the device. If the device needs a buffer as reference frame, it must
> > not return the buffer.
>
> I think that might not be what we expect. We want the decoder to
> return a decoded frame as soon as possible, but that decoded frame may
> be also needed for decoding next frames. In V4L2 stateful decoder, the
> API is defined that the client must not modify the decoded
> framebuffer, otherwise decoding next frames may not be correct.

Thanks Tomasz! I didn't know the V4L2's convention.
So, the host should be able to read a frame buffer after it is
returned by responding RESOURCE_QUEUE command.


> We may
> need something similar, with an explicit operation that makes the
> buffers not accessible to the host anymore. I think the queue flush
> operation could work as such.

After offline discussion with Tomasz, I suspect the queue flush
operation (= VIRTIO_VIDEO_CMD_QUEUE_CLEAR) shouldn't work so, as it
just forces pending QUEUE requests to be backed for video seek.
So, a buffer can be readable from the device once it's queued until
STREAM_DESTROY or RESOURCE_DESTROY is called.

In my understanding, the life cycle of video buffers is defined as
this state machine.
https://drive.google.com/file/d/1c6oY5S_9bhpJlrOt4UfoQex0CanpG-kZ/view?usp=sharing

```
# The definition of the state machine in DOT language
digraph G {
  graph [ rankdir = LR, layout = dot ];

  init [shape=point]
  created [label="created", shape=circle]
  dequeued [label="dequeued", shape=circle]
  queued [label="queued", shape=circle]

  init -> created [label="RESOURCE_CREATE"]

  created -> queued [label="RESOURCE_QUEUE \n is sent"]
  dequeued -> queued [label="RESOURCE_QUEUE \n is sent"]
  queued -> dequeued [label="RESOURCE_QUEUE \n is returned"]

  created -> init [label="DESTROY"]
  dequeued -> init [label="DESTROY"]
}
```

In each state of this figure, the accessibility of each buffer should
be like the following:

# Input buffers
 state   |   Guest    |    Host
-----------------------------------
created  | Read/Write | -
queued   | -          | Read
dequeued | Read/Write | -

# Output buffers
 state   |   Guest    |    Host
----------------------------------
created  | Read       | -
queued   | -          | Read/Write
dequeued | Read       | Read

Does it make sense?
If ok, I'll have this state machine and tables in the next version of
spec to describe device/driver requirements by adding a subsection
about buffer life cycle.


By the way, regarding destruction of buffers, I suspect it doesn't
make much sense to have RESOURCE_DESTROY command. Though it was
suggested as a per-buffer command, it doesn't match the existing V4L2
API, as REQBUFS(0) destroys all buffers at once. I guess per-buffer
destruction would require hardware or firmware supports.
Even if we want to destroy buffers at once, we can destroy the stream
and recreate one. So, I wonder if we can remove RESOURCE_DESTROY
command from the first version of spec at least.
What do you think?

Best regards,
Keiichi


>
> > I'll describe this rule in the next version of the patch.
> >
> > Best regards,
> > Keiichi
> >
> > >
> > > cheers,
> > >   Gerd
> > >

---------------------------------------------------------------------
To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org


  reply	other threads:[~2020-01-14  7:19 UTC|newest]

Thread overview: 147+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 13:02 [PATCH v2 0/1] VirtIO video device specification Keiichi Watanabe
2019-12-18 13:02 ` [virtio-dev] " Keiichi Watanabe
2019-12-18 13:02 ` [PATCH v2 1/1] virtio-video: Add virtio " Keiichi Watanabe
2019-12-18 13:02   ` [virtio-dev] " Keiichi Watanabe
2019-12-18 13:40   ` Gerd Hoffmann
2019-12-18 13:40     ` [virtio-dev] " Gerd Hoffmann
2019-12-18 14:08     ` Tomasz Figa
2019-12-18 14:08       ` Tomasz Figa
2019-12-19  7:46       ` Gerd Hoffmann
2019-12-19  7:46         ` Gerd Hoffmann
2019-12-19  9:48         ` Dmitry Sepp
2019-12-19  9:48           ` Dmitry Sepp
2019-12-19  9:59           ` Tomasz Figa
2019-12-19  9:59             ` Tomasz Figa
2019-12-19 10:54             ` Dmitry Sepp
2019-12-19 10:54               ` Dmitry Sepp
2019-12-19 12:05               ` Tomasz Figa
2019-12-19 12:05                 ` Tomasz Figa
2019-12-19 13:12               ` Gerd Hoffmann
2019-12-19 13:12                 ` Gerd Hoffmann
2020-01-08 13:52                 ` Keiichi Watanabe
2020-01-08 13:52                   ` Keiichi Watanabe
2020-01-09 13:40                   ` Gerd Hoffmann
2020-01-09 13:40                     ` Gerd Hoffmann
2020-01-09 14:20                   ` Tomasz Figa
2020-01-09 14:20                     ` Tomasz Figa
2020-01-14  7:18                     ` Keiichi Watanabe [this message]
2020-01-14  7:18                       ` Keiichi Watanabe
2020-01-14 10:35                       ` Dmitry Sepp
2020-01-14 10:35                         ` Dmitry Sepp
2020-01-15  7:49                         ` Keiichi Watanabe
2020-01-15  7:49                           ` Keiichi Watanabe
2020-01-15 11:12                         ` Tomasz Figa
2020-01-15 11:12                           ` Tomasz Figa
2019-12-19 13:01           ` Gerd Hoffmann
2019-12-19 13:01             ` Gerd Hoffmann
2020-01-08 13:50             ` Keiichi Watanabe
2020-01-08 13:50               ` Keiichi Watanabe
2019-12-19  9:26     ` Dmitry Sepp
2019-12-19  9:26       ` [virtio-dev] " Dmitry Sepp
2019-12-19  9:59       ` Tomasz Figa
2019-12-19  9:59         ` [virtio-dev] " Tomasz Figa
2019-12-19 12:54       ` Gerd Hoffmann
2019-12-19 12:54         ` [virtio-dev] " Gerd Hoffmann
2019-12-18 17:29   ` Frediano Ziglio
2019-12-20 14:05     ` Keiichi Watanabe
2019-12-20 14:05       ` [virtio-dev] " Keiichi Watanabe
2019-12-20 15:33       ` Dmitry Sepp
2019-12-20 15:33         ` [virtio-dev] " Dmitry Sepp
2019-12-19 13:28   ` Dmitry Sepp
2019-12-19 13:28     ` [virtio-dev] " Dmitry Sepp
2019-12-20 15:26     ` Keiichi Watanabe
2019-12-20 15:26       ` [virtio-dev] " Keiichi Watanabe
2019-12-20 15:46       ` Dmitry Sepp
2019-12-21  6:46         ` Tomasz Figa
2019-12-21  6:46           ` [virtio-dev] " Tomasz Figa
2019-12-30 12:16     ` Dmitry Sepp
2019-12-30 12:16       ` Dmitry Sepp
2020-01-06  6:31       ` Tomasz Figa
2020-01-06  6:31         ` Tomasz Figa
2020-01-06  8:33         ` Gerd Hoffmann
2020-01-06  8:33           ` Gerd Hoffmann
2020-01-06  9:29           ` Dmitry Sepp
2020-01-06  9:29             ` Dmitry Sepp
2020-01-03 15:47   ` Dmitry Sepp
2020-01-03 15:47     ` [virtio-dev] " Dmitry Sepp
2020-01-06  8:47     ` Gerd Hoffmann
2020-01-06  8:47       ` [virtio-dev] " Gerd Hoffmann
2020-01-06 10:21     ` Keiichi Watanabe
2020-01-06 10:21       ` [virtio-dev] " Keiichi Watanabe
2020-01-06 14:59   ` Dmitry Sepp
2020-01-06 14:59     ` [virtio-dev] " Dmitry Sepp
2020-01-07 13:24     ` Keiichi Watanabe
2020-01-07 13:24       ` [virtio-dev] " Keiichi Watanabe
2020-01-07 16:50       ` Dmitry Sepp
2020-01-07 16:50         ` [virtio-dev] " Dmitry Sepp
2020-01-08  6:59         ` Keiichi Watanabe
2020-01-08  6:59           ` [virtio-dev] " Keiichi Watanabe
2020-01-08 10:00           ` Dmitry Sepp
2020-01-08 10:00             ` [virtio-dev] " Dmitry Sepp
2020-01-08 12:14             ` Keiichi Watanabe
2020-01-08 12:14               ` [virtio-dev] " Keiichi Watanabe
2020-01-08 12:46               ` Tomasz Figa
2020-01-08 12:46                 ` [virtio-dev] " Tomasz Figa
2020-01-08 13:05                 ` Keiichi Watanabe
2020-01-08 13:05                   ` [virtio-dev] " Keiichi Watanabe
2020-01-08 13:11                 ` Dmitry Sepp
2020-01-08 13:11                   ` [virtio-dev] " Dmitry Sepp
2020-01-08 13:23                   ` Keiichi Watanabe
2020-01-08 13:23                     ` Keiichi Watanabe
2020-01-08 12:23   ` Keiichi Watanabe
2020-01-08 12:23     ` [virtio-dev] " Keiichi Watanabe
2019-12-20 15:58 ` [PATCH v2 0/1] VirtIO " Dmitry Sepp
2019-12-20 15:58   ` [virtio-dev] " Dmitry Sepp
2019-12-21  4:36   ` Keiichi Watanabe
2019-12-21  4:36     ` [virtio-dev] " Keiichi Watanabe
2019-12-21  6:18     ` Tomasz Figa
2019-12-21  6:18       ` [virtio-dev] " Tomasz Figa
2019-12-21  6:19       ` Tomasz Figa
2019-12-21  6:19         ` [virtio-dev] " Tomasz Figa
2020-01-03 13:05         ` Dmitry Sepp
2020-01-03 13:05           ` [virtio-dev] " Dmitry Sepp
2020-01-06 10:30           ` Keiichi Watanabe
2020-01-06 10:30             ` [virtio-dev] " Keiichi Watanabe
2020-01-06 11:28             ` Dmitry Sepp
2020-01-06 11:28               ` [virtio-dev] " Dmitry Sepp
2020-01-07 10:25               ` Keiichi Watanabe
2020-01-07 10:25                 ` [virtio-dev] " Keiichi Watanabe
2020-01-09 14:56                 ` Dmitry Sepp
2020-01-09 14:56                   ` [virtio-dev] " Dmitry Sepp
2020-01-10 10:16                   ` Dmitry Sepp
2020-01-10 10:16                     ` Dmitry Sepp
2020-01-10 13:53                     ` Keiichi Watanabe
2020-01-10 13:53                       ` Keiichi Watanabe
2020-01-10 15:11                       ` Dmitry Sepp
2020-01-10 15:11                         ` Dmitry Sepp
2020-01-11 16:06                         ` Tomasz Figa
2020-01-11 16:06                           ` Tomasz Figa
2020-01-13  9:50                           ` Dmitry Sepp
2020-01-13  9:50                             ` Dmitry Sepp
2020-01-15 11:23                             ` Keiichi Watanabe
2020-01-15 11:23                               ` Keiichi Watanabe
2020-01-13  9:56                         ` Gerd Hoffmann
2020-01-13  9:56                           ` Gerd Hoffmann
2020-01-13 10:41                           ` Dmitry Sepp
2020-01-13 11:05                             ` Gerd Hoffmann
2020-01-13 11:05                               ` Gerd Hoffmann
2020-01-13 11:59                               ` Tomasz Figa
2020-01-13 11:59                                 ` Tomasz Figa
2020-01-13 13:26                                 ` Gerd Hoffmann
2020-01-13 13:26                                   ` Gerd Hoffmann
2020-01-15 11:00                                   ` Tomasz Figa
2020-01-15 11:00                                     ` Tomasz Figa
2020-01-15 11:23                                     ` Keiichi Watanabe
2020-01-15 11:23                                       ` Keiichi Watanabe
2020-01-15 11:26                                     ` Gerd Hoffmann
2020-01-15 11:26                                       ` Gerd Hoffmann
2020-01-20  7:20                                       ` Keiichi Watanabe
2020-01-20  7:20                                         ` Keiichi Watanabe
2020-01-20 10:47                                         ` Gerd Hoffmann
2020-01-20 10:47                                           ` Gerd Hoffmann
2020-01-21  2:47                                           ` Keiichi Watanabe
2020-01-21  2:47                                             ` Keiichi Watanabe
2020-01-21  6:44                                             ` Gerd Hoffmann
2020-01-21  6:44                                               ` Gerd Hoffmann
2020-01-21  8:56                                               ` Keiichi Watanabe
2020-01-21  8:56                                                 ` Keiichi Watanabe

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='CAD90VcbG6kR1Nw6DTr2RjwFrDja2B=Ohje_2MMeKBwpXGZ_MyA@mail.gmail.com' \
    --to=keiichiw@chromium.org \
    --cc=acourbot@chromium.org \
    --cc=alexlau@chromium.org \
    --cc=daniel@ffwll.ch \
    --cc=dgreid@chromium.org \
    --cc=dmitry.sepp@opensynergy.com \
    --cc=egranata@google.com \
    --cc=fziglio@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kraxel@redhat.com \
    --cc=linux-media@vger.kernel.org \
    --cc=marcheu@chromium.org \
    --cc=posciak@chromium.org \
    --cc=spice-devel@lists.freedesktop.org \
    --cc=stevensd@chromium.org \
    --cc=tfiga@chromium.org \
    --cc=uril@redhat.com \
    --cc=virtio-dev@lists.oasis-open.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.