usb: gadget: uvc: increase worker prio to WQ_HIGHPRI
authorMichael Grzeschik <m.grzeschik@pengutronix.de>
Wed, 7 Sep 2022 21:58:18 +0000 (23:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Sep 2022 07:30:18 +0000 (09:30 +0200)
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>
drivers/usb/gadget/function/f_uvc.c
drivers/usb/gadget/function/uvc.h
drivers/usb/gadget/function/uvc_v4l2.c
drivers/usb/gadget/function/uvc_video.c

index f4f6cf7..09961f4 100644 (file)
@@ -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
index 58e383a..1a31e6c 100644 (file)
@@ -88,6 +88,7 @@ struct uvc_video {
        struct usb_ep *ep;
 
        struct work_struct pump;
+       struct workqueue_struct *async_wq;
 
        /* Frame parameters */
        u8 bpp;
index 511f106..d6dbf9b 100644 (file)
@@ -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;
 }
index c00ce0e..bb037fc 100644 (file)
@@ -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
@@ -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;
 }
@@ -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;