From: Michael Grzeschik <m.grzeschik@pengutronix.de>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Daniel Scally <dan.scally@ideasonboard.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Avichal Rakesh <arakesh@google.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Grzeschik <m.grzeschik@pengutronix.de>
Subject: [PATCH v3 02/10] usb: gadget: uvc: only enqueue zero length requests in potential underrun
Date: Sat, 27 Jul 2024 00:02:37 +0200 [thread overview]
Message-ID: <20240403-uvc_request_length_by_interval-v3-2-4da7033dd488@pengutronix.de> (raw)
In-Reply-To: <20240403-uvc_request_length_by_interval-v3-0-4da7033dd488@pengutronix.de>
The complete handler will at least be called after 16 requests have
completed, but will still handle all finisher requests. Since we have
to maintain a costant filling in the isoc queue we ensure this by
adding zero length requests.
By counting the amount enqueued requests we can ensure that the queue is
never underrun and only need to get active if the queue is running
critical. This patch is setting 32 as the critical level, which
is twice the request amount that is needed to create interrupts.
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
v1 -> v3: new patch
---
drivers/usb/gadget/function/uvc.h | 5 ++++-
drivers/usb/gadget/function/uvc_video.c | 7 +++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h
index cb35687b11e7e..646f1c01c5101 100644
--- a/drivers/usb/gadget/function/uvc.h
+++ b/drivers/usb/gadget/function/uvc.h
@@ -91,6 +91,9 @@ struct uvc_video {
struct work_struct pump;
struct workqueue_struct *async_wq;
+ int enqueued;
+ int dequeued;
+
/* Frame parameters */
u8 bpp;
u32 fcc;
@@ -106,7 +109,7 @@ struct uvc_video {
unsigned int req_size;
struct list_head ureqs; /* all uvc_requests allocated by uvc_video */
- /* USB requests that the video pump thread can encode into */
+ /* USB requests that the video qbuf thread can encode into */
struct list_head req_free;
/*
diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
index 03bff39cd4902..d47ddd674f457 100644
--- a/drivers/usb/gadget/function/uvc_video.c
+++ b/drivers/usb/gadget/function/uvc_video.c
@@ -269,6 +269,8 @@ static int uvcg_video_ep_queue(struct uvc_video *video, struct usb_request *req)
}
}
+ video->enqueued++;
+
return ret;
}
@@ -380,6 +382,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
int ret = 0;
spin_lock_irqsave(&video->req_lock, flags);
+ video->dequeued++;
if (!video->is_enabled) {
/*
* When is_enabled is false, uvcg_video_disable() ensures
@@ -467,6 +470,10 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
* happen.
*/
queue_work(video->async_wq, &video->pump);
+ } else if ((video->enqueued - video->dequeued) > 32) {
+ spin_unlock_irqrestore(&video->req_lock, flags);
+
+ return;
}
/*
* Queue to the endpoint. The actual queueing to ep will
--
2.39.2
next prev parent reply other threads:[~2024-07-26 22:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 22:02 [PATCH v3 00/10] usb: gadget: uvc: effectively fill the udc isoc pipeline with available video buffers Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 01/10] usb: gadget: uvc: always set interrupt on zero length requests Michael Grzeschik
2024-07-26 22:02 ` Michael Grzeschik [this message]
2024-07-26 22:02 ` [PATCH v3 03/10] usb: gadget: uvc: remove pump worker and enqueue all buffers per frame in qbuf Michael Grzeschik
2024-08-13 9:10 ` Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 04/10] usb: gadget: uvc: rework to enqueue in pump worker from encoded queue Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 05/10] usb: gadget: uvc: remove uvc_video_ep_queue_initial_requests Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 06/10] usb: gadget: uvc: set req_size once when the vb2 queue is calculated Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 07/10] usb: gadget: uvc: add g_parm and s_parm for frame interval Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 08/10] usb: gadget: uvc: set req_size and n_requests based on the " Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 09/10] usb: gadget: uvc: set req_length based on payload by nreqs instead of req_size Michael Grzeschik
2024-07-26 22:02 ` [PATCH v3 10/10] usb: gadget: uvc: add min g_ctrl vidioc and set min buffs to 4 Michael Grzeschik
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=20240403-uvc_request_length_by_interval-v3-2-4da7033dd488@pengutronix.de \
--to=m.grzeschik@pengutronix.de \
--cc=arakesh@google.com \
--cc=dan.scally@ideasonboard.com \
--cc=gregkh@linuxfoundation.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.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
all inboxes | Powered by JetHome®