Skip to content

Commit

Permalink
usb: gadget: uvc: increase worker prio to WQ_HIGHPRI
Browse files Browse the repository at this point in the history
[ Upstream commit 9b91a65 ]

This patch is changing the simple workqueue in the gadget driver to be
allocated as async_wq with a higher priority. The pump worker, that is
filling the usb requests, will have a higher priority and will not be
scheduled away so often while the video stream is handled. This will
lead to fewer streaming underruns.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20220907215818.2670097-1-m.grzeschik@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
mgrzeschik authored and gregkh committed Oct 21, 2022
1 parent e4dd77a commit 5609dcc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions drivers/usb/gadget/function/f_uvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,14 @@ static void uvc_function_unbind(struct usb_configuration *c,
{
struct usb_composite_dev *cdev = c->cdev;
struct uvc_device *uvc = to_uvc(f);
struct uvc_video *video = &uvc->video;
long wait_ret = 1;

uvcg_info(f, "%s()\n", __func__);

if (video->async_wq)
destroy_workqueue(video->async_wq);

/*
* If we know we're connected via v4l2, then there should be a cleanup
* of the device from userspace either via UVC_EVENT_DISCONNECT or
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/function/uvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct uvc_video {
struct usb_ep *ep;

struct work_struct pump;
struct workqueue_struct *async_wq;

/* Frame parameters */
u8 bpp;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/gadget/function/uvc_v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
return ret;

if (uvc->state == UVC_STATE_STREAMING)
schedule_work(&video->pump);
queue_work(video->async_wq, &video->pump);

return ret;
}
Expand Down
9 changes: 7 additions & 2 deletions drivers/usb/gadget/function/uvc_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
spin_unlock_irqrestore(&video->req_lock, flags);

if (uvc->state == UVC_STATE_STREAMING)
schedule_work(&video->pump);
queue_work(video->async_wq, &video->pump);
}

static int
Expand Down Expand Up @@ -485,7 +485,7 @@ int uvcg_video_enable(struct uvc_video *video, int enable)

video->req_int_count = 0;

schedule_work(&video->pump);
queue_work(video->async_wq, &video->pump);

return ret;
}
Expand All @@ -499,6 +499,11 @@ int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc)
spin_lock_init(&video->req_lock);
INIT_WORK(&video->pump, uvcg_video_pump);

/* Allocate a work queue for asynchronous video pump handler. */
video->async_wq = alloc_workqueue("uvcgadget", WQ_UNBOUND | WQ_HIGHPRI, 0);
if (!video->async_wq)
return -EINVAL;

video->uvc = uvc;
video->fcc = V4L2_PIX_FMT_YUYV;
video->bpp = 16;
Expand Down

0 comments on commit 5609dcc

Please sign in to comment.