From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Cc: Jayant Chowdhary <jchowdhary@google.com>,
"mgr@pengutronix.de" <mgr@pengutronix.de>,
Greg KH <gregkh@linuxfoundation.org>,
"corbet@lwn.net" <corbet@lwn.net>,
"dan.scally@ideasonboard.com" <dan.scally@ideasonboard.com>,
"kieran.bingham@ideasonboard.com"
<kieran.bingham@ideasonboard.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"etalvala@google.com" <etalvala@google.com>,
"arakesh@google.com" <arakesh@google.com>
Subject: Re: uvc gadget: Making upper bound of number of usb requests allocated configurable through configfs
Date: Fri, 27 Oct 2023 11:14:00 +0300 [thread overview]
Message-ID: <20231027081400.GM26306@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20231020233044.dh63nu3tkbmrtfl4@synopsys.com>
On Fri, Oct 20, 2023 at 11:30:52PM +0000, Thinh Nguyen wrote:
> Sorry for the delay response.
>
> On Sun, Oct 15, 2023, Jayant Chowdhary wrote:
> > On 10/12/23 11:50, Thinh Nguyen wrote:
> > > The frequency of the request submission should not depend on the
> > > video_pump() work thread since it can vary. The frequency of request
> > > submission should match with the request completion. We know that
> > > request completion rate should be fixed (1 uframe/request + when you
> > > don't set no_interrupt). Base on this you can do your calculation on how
> > > often you should set no_interrupt and how many requests you must submit.
> > > You don't have to wait for the video_pump() to submit 0-length requests.
> > >
> > > The only variable here is the completion handler delay or system
> > > latency, which should not be much and should be within your calculation.
> >
> >
> > Thanks for the suggestion. It indeed makes sense that we do not completely depend on
> > video_pump() for sending 0 length requests. I was concerned about
> > synchronization needed when we send requests to the dwc3 controller from
> > different threads. I see that the dwc3 controller code does internally serialize
> > queueing requests, can we expect this from other controllers as well ?
>
> While it's not explicitly documented, when the gadget driver uses
> usb_ep_queue(), the order in which the gadget recieves the request
> should be maintained and serialized. Because the order the transfer go
> out for the same endpoint can be critical, breaking this will cause
> issue.
That's right, but if usp_ep_queue() is called from multiple contexts,
there's no guarantee it can provide when it comes to the ordering. The
caller has to handle it.
> > This brings me to another question for Michael - I see
> > that we introduced a worker thread for pumping usb requests to the usb endpoint
> > in https://urldefense.com/v3/__https://lore.kernel.org/all/20200427151614.10868-1-m.grzeschik@pengutronix.de/__;!!A4F2R9G_pg!aAnzCopbTbZtUxBK6a6r6_QzV-b2Z2J5o5esPaartZ2jogKijmhqj6OyiKDg-BPhxq8pJHR3HS1Hf8z6YnqfWTon$
> > (I see multiple email addresses, so apologies if I used the incorrect one).
> >
> > Did we introduce the worker thread to solve some specific deadlock scenarios ?
> > Or was it a general mitigation against racy usb request submission from v4l2 buffer
> > queuing, stream enable and the video complete handler firing ?
> >
> > I was chatting with Avi about this, what if we submit requests to the endpoint
> > only at two points in the streaming lifecycle -
> > 1) The whole 64 (or however many usb requests are allocated) when
> > uvcg_video_enable() is called - with 0 length usb_requests.
> > 2) In the video complete handler - if a video buffer is available, we encode it
> > and submit it to the endpoint. If not, we send a 0 length request.
> >
> > This way we're really maintaining back pressure and sending requests as soon
> > as we can to the dwc3 controller. Encoding is mostly memcpys from what I see
> > so hopefully not too heavy on the interrupt handler. I will work on prototyping
> > this meanwhile.
>
> That sounds good to me. I believe Michael already provided some test
> patches and you've already done some preliminary tests for that right?
--
Regards,
Laurent Pinchart
prev parent reply other threads:[~2023-10-27 8:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <edad1597-48da-49d2-a089-da2487cac889@google.com>
[not found] ` <2023100834-statistic-richly-49ef@gregkh>
2023-10-09 22:34 ` uvc gadget: Making upper bound of number of usb requests allocated configurable through configfs Jayant Chowdhary
2023-10-12 18:50 ` Thinh Nguyen
2023-10-16 4:33 ` Jayant Chowdhary
2023-10-18 13:28 ` Michael Grzeschik
2023-10-19 23:15 ` Michael Grzeschik
2023-10-20 5:52 ` Jayant Chowdhary
2023-10-20 12:49 ` Michael Grzeschik
2023-10-27 8:12 ` Laurent Pinchart
2023-10-20 23:30 ` Thinh Nguyen
2023-10-23 18:13 ` Jayant Chowdhary
2023-10-24 12:33 ` Michael Grzeschik
2023-10-25 23:09 ` Jayant Chowdhary
2023-10-26 6:55 ` Michael Grzeschik
2023-10-27 8:14 ` Laurent Pinchart [this message]
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=20231027081400.GM26306@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=arakesh@google.com \
--cc=corbet@lwn.net \
--cc=dan.scally@ideasonboard.com \
--cc=etalvala@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jchowdhary@google.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mgr@pengutronix.de \
/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).