Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp133326rwi; Wed, 12 Oct 2022 17:20:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HfSAPwEY8yV9mjp3RJlHTsJi/WTbJ3dT+e9oyrvqJj1AY1G3NybeH5lCwGJ8PZ43RKada X-Received: by 2002:a17:906:3852:b0:78d:b3d2:97a9 with SMTP id w18-20020a170906385200b0078db3d297a9mr14403348ejc.565.1665620403574; Wed, 12 Oct 2022 17:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665620403; cv=none; d=google.com; s=arc-20160816; b=WM1TWrQw8F/ZkJk7gzwsoFeLNsX0mnJ+pZriPXGwBUKLIENeaGHH7Zt6NMz2rxb1OM PP6H0+7O08766on+j8HAfPgKgeyot0yYSNSPPDI8dupwYYx0OJpHlXdRZ61MGZD+WHH1 ooin8uEOJqZmKco2rzYdwJICNTqY0h0xf3yUzztI4w29jgF2wGnOsx1SL1KjSste29rb 4EoYqtrehTYuDr96JEBMRpAkLiiGWpirInal64bsOpIIIIwelZFQzQ9BpNmgxqIStp5e Zvbx5r7CSZiaYYQDjrM0gEXCAD4BVwXTELD4iSrMBhSbCQbFmSLLbBWLFQO8gG4mIlA1 XIYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1K7Z+fsRNqZnE062rJ6nGuTpHytGRGlYh/TdR0XRg3k=; b=hvJxxv5hufUbZVU+I0CeQB5C70pZN61mdl8+mSoNjmgpxsyB8+H2IxxH3cC1RXuBsR OscpFDP2YyK93ohEJIHqd7188OBOOlv2MS0MPwuA2ZQenaAhF0brFg/UrMOO6fSrDbX4 yWmt1271u6nayGxFIWWRkKjHhSJbDmgj8v8ubjP6oBNfYLnisjYgMwaWB41AAjDg396q y5bkFy+nEAk6WqgkelBpXyzRDM2A5GvYpKNyhW1L9zoiryNwjgeGDrEhkJ3DO/g0jV8U u/hT6Ku47aW80RLzvFHv4g7mSIgkIqJVLW9wmCElCf+1jE3ffq24GI1auUzhUC1N1sZi Dv3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nWQ9CNEz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ee21-20020a056402291500b004587cd5a5bdsi14535185edb.81.2022.10.12.17.19.37; Wed, 12 Oct 2022 17:20:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nWQ9CNEz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229600AbiJMARY (ORCPT + 99 others); Wed, 12 Oct 2022 20:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbiJMAQu (ORCPT ); Wed, 12 Oct 2022 20:16:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6431815E0F1; Wed, 12 Oct 2022 17:16:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 45CE0616BD; Thu, 13 Oct 2022 00:16:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C864EC4347C; Thu, 13 Oct 2022 00:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620186; bh=cMPXsVuPdcph4KjBelvtN/XnqSk3H6dZgGkqU0pF/dA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWQ9CNEz5cZ79FLgYfdtahm1iBbbx00V1LC+6r9LchsUA1NnT5jDs4mp6Om+RW2OH nnTLbHhKMlNvwoPaq71QD47GdjEG+vXYEbPYTGQ5R6JZN8BtTGsqVv2ippVUPH1PZL 6xzbVDrA0cgFrCC9p5DBhF9VHK1UX5/hldXVoog61+hZn8Ug1ACP/cegbSQgyKi9np 86pVhp4Zxwt0HrxkOp6xGVr+yszQukUgk4X8mvB9vGGn6JIrwxRE+B/zesu0MkLpyD w2CWqLqI2YgYFgPeB1zzCqc7YQICrbELwvcQJMuPT7UJKYwJVbDavtgAu4jbEFVwMJ g8DIOE6D3LLhw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Grzeschik , Greg Kroah-Hartman , Sasha Levin , laurent.pinchart@ideasonboard.com, balbi@kernel.org, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 14/67] usb: gadget: uvc: increase worker prio to WQ_HIGHPRI Date: Wed, 12 Oct 2022 20:14:55 -0400 Message-Id: <20221013001554.1892206-14-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Grzeschik [ Upstream commit 9b91a65230784a9ef644b8bdbb82a79ba4ae9456 ] 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 Link: https://lore.kernel.org/r/20220907215818.2670097-1-m.grzeschik@pengutronix.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_uvc.c | 4 ++++ drivers/usb/gadget/function/uvc.h | 1 + drivers/usb/gadget/function/uvc_v4l2.c | 2 +- drivers/usb/gadget/function/uvc_video.c | 9 +++++++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index 71669e0e4d00..241b0de7b4aa 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -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 diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h index 58e383afdd44..1a31e6c6a5ff 100644 --- a/drivers/usb/gadget/function/uvc.h +++ b/drivers/usb/gadget/function/uvc.h @@ -88,6 +88,7 @@ struct uvc_video { struct usb_ep *ep; struct work_struct pump; + struct workqueue_struct *async_wq; /* Frame parameters */ u8 bpp; diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c index fd8f73bb726d..fddc392b8ab9 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -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; } diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index c00ce0e91f5d..bb037fcc90e6 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -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; -- 2.35.1