Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1218963rdh; Fri, 27 Oct 2023 07:58:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhcLrf0PHnZ5Okl6T+pTHFYCq+qS94doaC4/i8FSLNYMBXsDo55anB5a4sot2R33X5LYRd X-Received: by 2002:aca:2806:0:b0:3ae:3d0:d74a with SMTP id 6-20020aca2806000000b003ae03d0d74amr2753769oix.52.1698418707193; Fri, 27 Oct 2023 07:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698418707; cv=none; d=google.com; s=arc-20160816; b=GU9vrLoR9vITX1wUKhj3YSqTtG/ZAwreo8ZCl1uGp5sUBOClY9j6pyk7LpV2i0SPMd WDPdGAWmzs5w8g9qgD+l8Qb6phlaI+nKCD+KMGkR8MetzhzM9OIbPlmHe2zP3YicXha7 CZx8RZl5JZq8dCsc1ewIX0GCTCito2Mo3k5b/Na7LApLzBwKJ0xoFTPanGsWM/hUXlex N9MBgODjIeXT+d+nUjoer8MaJxrdsccit8k6kvC8MZ7cf5NZzjb9AWY4AN1rLaxRQ10A Ezptojop0L9unK/m6AtT5tTyXZD7cqCx+SPUVYw/RoGwRypbQFbE0PCPGd8nGlrx68C9 CMSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=RiEHgYu3jDS3LC0YZuaokUS9GGKXJTLW067QD16ZRJw=; fh=QA0++ifzqBBEZwbfFSrcpj/1Je7Y9xNI+6BrYB9KKOg=; b=sIC3BiPUbTslArvEFVjOAoOZHeNHGZ3srJIfrWWySuC1qdOXGg6y7wphvF4N8klRcr 2nAsvRxnaWFkxnJuhzRclBjKwFuSqdS+O8UspxPsh5zPxJ/9sAGsBHuNQHKojgvrUByc KXXsUJ+ujhsUxnEpXJ3HcglpiAOUbxYqPcCdzAD5bIZvhvC/LbPGGDcVVrmAyC7uzISa D+gUP1UpInyAxJLEh2XrR/qT63iT7yzx2gR24ZUyEgp88iQbPHj8s3HEdMyBI0ww/R+y YpkuKIv8jzmvh9q49e48Jqo8ahBeo++FtB3YSOSmblMS1v5I2ViUVWvAOil15apj2dz7 pR5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id k129-20020a253d87000000b00d43b05af683si2884604yba.651.2023.10.27.07.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:58:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CCFF880942F6; Fri, 27 Oct 2023 07:58:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346117AbjJ0O6P (ORCPT + 99 others); Fri, 27 Oct 2023 10:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345833AbjJ0O6O (ORCPT ); Fri, 27 Oct 2023 10:58:14 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 6B5E510E for ; Fri, 27 Oct 2023 07:58:12 -0700 (PDT) Received: (qmail 571154 invoked by uid 1000); 27 Oct 2023 10:58:11 -0400 Date: Fri, 27 Oct 2023 10:58:11 -0400 From: Alan Stern To: Michael Grzeschik Cc: Laurent Pinchart , Jayant Chowdhary , Thinh.Nguyen@synopsys.com, arakesh@google.com, etalvala@google.com, dan.scally@ideasonboard.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH v2] usb:gadget:uvc Do not use worker thread to pump usb requests Message-ID: <7c30f943-aaad-47dd-9ae3-02f1ca57e49b@rowland.harvard.edu> References: <20231026215635.2478767-1-jchowdhary@google.com> <20231027075117.GJ26306@pendragon.ideasonboard.com> <20231027114752.GB12144@pendragon.ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 07:58:24 -0700 (PDT) On Fri, Oct 27, 2023 at 03:39:44PM +0200, Michael Grzeschik wrote: > On Fri, Oct 27, 2023 at 02:47:52PM +0300, Laurent Pinchart wrote: > > On Fri, Oct 27, 2023 at 01:10:21PM +0200, Michael Grzeschik wrote: > > > On Fri, Oct 27, 2023 at 10:51:17AM +0300, Laurent Pinchart wrote: > > > > On Thu, Oct 26, 2023 at 09:56:35PM +0000, Jayant Chowdhary wrote: > > > >> This patch is based on top of > > > >> https://lore.kernel.org/linux-usb/20230930184821.310143-1-arakesh@google.com/T/#t: > > > >> > > > >> When we use an async work queue to perform the function of pumping > > > >> usb requests to the usb controller, it is possible that thread scheduling > > > >> affects at what cadence we're able to pump requests. This could mean usb > > > >> requests miss their uframes - resulting in video stream flickers on the host > > > >> device. > > > >> > > > >> In this patch, we move the pumping of usb requests to > > > >> 1) uvcg_video_complete() complete handler for both isoc + bulk > > > >> endpoints. We still send 0 length requests when there is no uvc buffer > > > >> available to encode. > > > > > > > > This means you will end up copying large amounts of data in interrupt > > > > context. The work queue was there to avoid exactly that, as it will > > > > introduce delays that can affect other parts of the system. I think this > > > > is a problem. > > > > > > Regarding Thin's argument about possible scheduling latency that is already > > > introducing real errors, this seemed like a good solution. > > > > > > But sure, this potential latency introduced in the interrupt context can > > > trigger other side effects. > > > > > > However I think we need some compromise since both arguments are very valid. > > > > Agreed. > > > > > Any ideas, how to solve this? > > > > I'm afraid not. > > We discussed this and came to the conclusion that we could make use of > kthread_create and sched_setattr with an attr->sched_policy = SCHED_DEADLINE > here instead of the workqueue. This way we would ensure that the worker > would be triggered with hard definitions. > > Since the SG case is not that heavy on the completion handler, we could > also make this kthread conditionaly to the memcpy case. If you don't mind a naive suggestion from someone who knows nothing about the driver... An attractive possibility is to have the work queue (or kthread) do the time-consuming copying, but leave the submission up to the completion handler. If the data isn't ready (or there's no data to send) when the handler runs, then queue a 0-length request. That will give you the best of both worlds: low latency while in interrupt context and a steady, constant flow of USB transfers at all times. The question of how to schedule the work queue or kthread is a separate matter, not directly relevant to this design decision. Alan Stern