Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3413672rwa; Tue, 23 Aug 2022 04:29:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR4K96JcE9HbDKq0OPTjQBdmSuwD7QadiaBAhx6JLNOGfaaFgxusNp9G0xFaUDzwHnCVD6Qr X-Received: by 2002:a05:6402:2744:b0:446:ab07:eb52 with SMTP id z4-20020a056402274400b00446ab07eb52mr3169592edd.83.1661254119457; Tue, 23 Aug 2022 04:28:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254119; cv=none; d=google.com; s=arc-20160816; b=pI/cBD7lvRlcyRH5CdAORZeBf4aH7MJxQukXqCPz49+I2DOSBbx6vC3Lejfq9xjJCu 4tVP3ZeE3qtA6vFXphBezh5/Sndx8ldeVCXKaLmstnVKEH0pTIU2uU67Lg9MKunc+761 UDCMQ+/D2501Yd8Jo5eKEJiJ8udAvmA8PjrNFWoYW5Ev7wdYKg2E1Dz5EyU29eVd4dZq Pmle+bPBUVNNFWJ6JZoWkdoOESR+Preku2mPpoi3g0glOnp7/xenY+fDh2Tl6kx510nd JRrwvuPOX8No6jTZjaWMRdW3aS4Ojf4ZllbsBTfqMJpBtCGGtcgBj0L3pew1/PpLDUlp 4NIw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DyTQ3eub3FzAZrduz+f1vL4Rbf1g6Bh/RfolLa867Ko=; b=wHKAZuEfFxlb8GipWJVxggCr7SkRDf00AbS7LQk4uYEYl/WWPMyH01Z3CNruARE+m4 8DJro3BIalgfp+hBXvHbMLhDp0QNeZkO7aR+MuZwv5oH2Dy1oKS35hgk0YSAy2D7sZAO xs1RAf7+t+SodIpwxJZiHtf0Q5IL22IFyG+jqsP5oS4Bk24X21AVDw56Qy8n/6SQ1Soe xT9ME3OZ2BtIHUQXi4+8Mp5HoTT7E3qKSjDfkn4uF744DL8wA2JzDZ9w/NaQgH9H7Jqa jlGGRl2WbN+60/rxUfKj5ecF3651mlfCWe1+GZJrkqNXHNZZArLEniCpoSCWnyDRUahA k7Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pfGj1Zou; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020aa7c0c8000000b0043d281cfe2bsi1860546edp.481.2022.08.23.04.28.13; Tue, 23 Aug 2022 04:28:39 -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=@linuxfoundation.org header.s=korg header.b=pfGj1Zou; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354031AbiHWKTm (ORCPT + 99 others); Tue, 23 Aug 2022 06:19:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352709AbiHWKIf (ORCPT ); Tue, 23 Aug 2022 06:08:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E31746E2CB; Tue, 23 Aug 2022 01:54:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8D74EB81C39; Tue, 23 Aug 2022 08:54:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF3DFC433C1; Tue, 23 Aug 2022 08:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244884; bh=d9zByOqMLOF3FIcefgl0t3MfVCirt6tjn609U+L5Uy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pfGj1Zou0viuiteCmBH6RdR7ZwfOJ6g7rV+Sh5iF3k7Ip1olhV17tngcr4rwcichF cnxVFp71j71tsyjsvnC6FZXHnvliKTRiefMxRb446tt89lJ8Eq1XMFDIB0akRMDoqJ mO/6uNOYc996gQ/yfWt45qK/3xW1h57gagZQQ4+o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Vacura , Michael Grzeschik , Sasha Levin Subject: [PATCH 5.15 167/244] usb: gadget: uvc: calculate the number of request depending on framesize Date: Tue, 23 Aug 2022 10:25:26 +0200 Message-Id: <20220823080104.803122251@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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,T_SCC_BODY_TEXT_LINE 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 87d76b5f1d8eeb49efa16e2018e188864cbb9401 ] The current limitation of possible number of requests being handled is dependent on the gadget speed. It makes more sense to depend on the typical frame size when calculating the number of requests. This patch is changing this and is using the previous limits as boundaries for reasonable minimum and maximum number of requests. For a 1080p jpeg encoded video stream with a maximum imagesize of e.g. 800kB with a maxburst of 8 and an multiplier of 1 the resulting number of requests is calculated to 49. 800768 1 nreqs = ------ * -------------- ~= 49 2 (1024 * 8 * 1) Tested-by: Dan Vacura Signed-off-by: Michael Grzeschik Link: https://lore.kernel.org/r/20220529223848.105914-2-m.grzeschik@pengutronix.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/uvc_queue.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c index 99dc9adf56ef..a64b842665b9 100644 --- a/drivers/usb/gadget/function/uvc_queue.c +++ b/drivers/usb/gadget/function/uvc_queue.c @@ -44,7 +44,8 @@ static int uvc_queue_setup(struct vb2_queue *vq, { struct uvc_video_queue *queue = vb2_get_drv_priv(vq); struct uvc_video *video = container_of(queue, struct uvc_video, queue); - struct usb_composite_dev *cdev = video->uvc->func.config->cdev; + unsigned int req_size; + unsigned int nreq; if (*nbuffers > UVC_MAX_VIDEO_BUFFERS) *nbuffers = UVC_MAX_VIDEO_BUFFERS; @@ -53,10 +54,16 @@ static int uvc_queue_setup(struct vb2_queue *vq, sizes[0] = video->imagesize; - if (cdev->gadget->speed < USB_SPEED_SUPER) - video->uvc_num_requests = 4; - else - video->uvc_num_requests = 64; + req_size = video->ep->maxpacket + * max_t(unsigned int, video->ep->maxburst, 1) + * (video->ep->mult); + + /* We divide by two, to increase the chance to run + * into fewer requests for smaller framesizes. + */ + nreq = DIV_ROUND_UP(DIV_ROUND_UP(sizes[0], 2), req_size); + nreq = clamp(nreq, 4U, 64U); + video->uvc_num_requests = nreq; return 0; } -- 2.35.1