From patchwork Mon Feb 5 23:40:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 197118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1214439dyb; Mon, 5 Feb 2024 15:41:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbUsOa0W1dXvWWPUxR+Xu7LZVeB4w/XCQN2Krp8Iis3blhYa/aw5Xsuz9YdAp7+SDTJAGH X-Received: by 2002:ac8:6d2:0:b0:42c:247f:60ab with SMTP id j18-20020ac806d2000000b0042c247f60abmr745619qth.2.1707176474724; Mon, 05 Feb 2024 15:41:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707176474; cv=pass; d=google.com; s=arc-20160816; b=sptAzqnys0vSobbKoLm57WaOipBVhECV5ljgbyaoN/SJX7wn6O3FXO2kMUiHkL9+SU VR3om0JvavKPuNfG1KUHbwhf5VQK+Q1AszNdKfDrDIZO+1Axp4puoCyNXNtVk43+vU+Q MQlEaZQiUZw0bpx919p98LCOD83zU0bSdfeD1qYniZD7joNhTmn/XQH+aJQOYCUKJgGR DgIHW/PEo3e6Gqr/n3AAq54N2qPLouuQd6GvHHVYccQ0+4BSL2BRwXHa5oVBC6p2emVw EwDBbgIAsfbQkv11ZqCDrp4ZOsHqUhOnVq84+tGBV94LOIunRXMqN8P2Pdukcfi+wdCB J1XQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date; bh=0SlMLqPrDEKDfO3ZVzovp6ekmK3aOXNG5PFNz3+2aNI=; fh=yQbzTVEoB2WfuGjlfsk4i78Nr0n0uXjuzwirTPz/uwg=; b=XsjdhAXNCs9+M2/MLmXVgrmoTFVDrAfyS52QDBvdKcDGAvHtCx08I3JZpZYU1koUgF vtX3f8dNmZAdUoxC+funi4wQcUnOzxnG5Ko29uvbFgwxcDOxwuAOgchdNvGQWbIHlEN4 QFRnQUK0wNWadbGsgLylL1gbwz1v1AeKCSj3RGDbCNmi7SvgYGU0AOYC/JNXWHpIO5F+ A0IfgoJ20XRZSyKI4308LBkrI6PwKGVI76P2sKnvOw0QH7v0kej28zUwFx+xikG+NKvt Fsy+vxVyuuOG3pi2ONRSZss7m+1xY7LHeajUjuDjGOIyywKkZvokZG5bRJ4FaS69nz0U +nRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-54100-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54100-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUw36E0GWukPih9bfzba+McSjQJUNn6i4ibeHa+490xGbiEyQBP5ScMWubItabywPQhKuJK+bi86SWVp0zMTAQ9WRN7jA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g14-20020ac87f4e000000b0042c2e1586a4si1095361qtk.767.2024.02.05.15.41.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 15:41:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54100-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-54100-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54100-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 71E6E1C23185 for ; Mon, 5 Feb 2024 23:41:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89AF74A990; Mon, 5 Feb 2024 23:40:37 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90CE34C3DE for ; Mon, 5 Feb 2024 23:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707176435; cv=none; b=dCOBA/PBFOkEhnC3n/ABnrXgom5Pi/D7y0XJkJMcrYX/q8CvB03R+/kTBRD1E0j7K/BJxF+PT5VbnnK1KjCcbjn9mtElgTijiexng0LleUclmESy5Sbg2H2LqgsbGfrx0NxC03Xodssp6CS7mtI03zMsVGC1qqNund5aveAHrew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707176435; c=relaxed/simple; bh=xPE7313tGa36WXt8zAWU+JWd3UaGL/fTkOi3lRYG8Qs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=YUu0Ubu1UNDQ0o3Auc6b/U0Drf+BBzRx4/O2/MQLlG3LB9HY2zI26+AxVffV47Ck+DCj08ixXaFerqXeJY1ieF2kAPuQGMTBiFuE9Y2WKLSLhwW/XjDYWNIwBKtaLSxdi3crRRGPS0erHjYu2fl2mDy/njoxya8Rr6f4Q/pw2ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rX8Zh-00082y-3L; Tue, 06 Feb 2024 00:40:29 +0100 Received: from [2a0a:edc0:2:b01:1d::c5] (helo=pty.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rX8Zg-004ifQ-7E; Tue, 06 Feb 2024 00:40:28 +0100 Received: from mgr by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rX8Zg-00CtLW-0R; Tue, 06 Feb 2024 00:40:28 +0100 Date: Tue, 6 Feb 2024 00:40:28 +0100 From: Michael Grzeschik To: Thinh Nguyen Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: duplicate requests on host side while streaming via uvcvideo gadget Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-URL: http://www.pengutronix.de/ X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mgr@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790104279345043388 X-GMAIL-MSGID: 1790104279345043388 Hi Thinh I found some strange situation while streaming via uvc-gadget to some usb host. It happens when some requests are missed due to higher load on the gadget machine. In some cases some requests will reach the host twice. In my special case, I added the following changes [1] for the host and gadget side. When applying the patches you will find all requests marked as errors on the host and gadget side reported. However, the odd thing is that the error counter on the host side will rise higher than the number of requests we have actually marked as errornous on the gadget side. You check the number of errors found on the host by looking in the statistics and compare it with the numer of requests that are actually marked with UVC_STREAM_ERR. [1] applied hunks: [ 1769.213387] error on uvc package! [ 1769.213396] PTS: 16 [ 1769.213400] SCR: 64 [ 1769.213402] SCR: 229 [ 1769.461386] error on uvc package! [ 1769.461394] PTS: 96 [ 1769.461398] SCR: 80 [ 1769.461401] SCR: 33 [ 1769.461405] error on uvc package! <- duplicate [ 1769.461408] PTS: 96 [ 1769.461410] SCR: 80 [ 1769.461413] SCR: 33 [ 1769.657405] error on uvc package! [ 1769.657442] PTS: 224 [ 1769.657449] SCR: 64 [ 1769.657453] SCR: 81 [ 1769.657460] error on uvc package! <- duplicate [ 1769.657465] PTS: 224 [ 1769.657470] SCR: 64 [ 1769.657476] SCR: 81 [ 1779.525368] error on uvc package! [ 1779.525374] PTS: 128 [ 1779.525378] SCR: 224 [ 1779.525380] SCR: 157 [ 1784.637359] error on uvc package! [ 1784.637367] PTS: 0 [ 1784.637371] SCR: 208 [ 1784.637374] SCR: 89 [ 1784.825357] error on uvc package! [ 1784.825394] PTS: 224 [ 1784.825401] SCR: 192 [ 1784.825406] SCR: 63 [ 1784.841362] error on uvc package! [ 1784.841394] PTS: 144 [ 1784.841403] SCR: 48 [ 1784.841410] SCR: 186 [ 1784.841418] error on uvc package! <- duplicate [ 1784.841424] PTS: 144 [ 1784.841430] SCR: 48 [ 1784.841436] SCR: 186 host$ grep errors /sys/kernel/debug/usb/uvcvideo/*/stats /sys/kernel/debug/usb/uvcvideo/4-81-1/stats:errors: 10 -- Gadget: [  126.826517] dropping frame! 1 [  126.829658] PTS: 16 [  126.831761] SCR: 64 [  126.833858] SCR: 229 [  127.090069] dropping frame! 2 [  127.093059] PTS: 96 [  127.095164] SCR: 80 [  127.097261] SCR: 33 [  127.288045] dropping frame! 3 [  127.291041] PTS: 224 [  127.293233] SCR: 64 [  127.295330] SCR: 81 [  137.153499] dropping frame! 4 [  137.156494] PTS: 128 [  137.158687] SCR: 224 [  137.160871] SCR: 157 [  142.265135] dropping frame! 5 [  142.268131] PTS: 0 [  142.270148] SCR: 208 [  142.272332] SCR: 89 [  142.453636] dropping frame! 6 [  142.456634] PTS: 224 [  142.458825] SCR: 192 [  142.461009] SCR: 63 [  142.469131] dropping frame! 7 [  142.472118] PTS: 144 [  142.474310] SCR: 48 [  142.476407] SCR: 186 Now I am totally unsure what could cause such error, but would expect the issue to be somewhere in the gadget driver and the mapped trb memory content. For the uvc_video layer, I compared and tested the enqueued request list for duplicates but could not find any. I also reverted all recent patches that changed request handling in the past year. I still find these request duplicates on the host side show up. Any Ideas? Regards, Michael diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h index 6bdcf3bdd62a9..63515fc949880 100644 --- a/drivers/usb/gadget/function/uvc.h +++ b/drivers/usb/gadget/function/uvc.h @@ -91,6 +91,8 @@ struct uvc_video { struct work_struct pump; struct workqueue_struct *async_wq; + int errorcount; + /* Frame parameters */ u8 bpp; u32 fcc; diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index eb1f7cee4a0af..f45dd53fde7ef 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -35,6 +35,12 @@ uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf, data[1] = UVC_STREAM_EOH | video->fid; + if (video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) { + video->errorcount++; + printk("dropping frame! %d\n", video->errorcount); + data[1] |= UVC_STREAM_ERR; + } + if (video->queue.buf_used == 0 && ts.tv_sec) { /* dwClockFrequency is 48 MHz */ u32 pts = ((u64)ts.tv_sec * USEC_PER_SEC + ts.tv_nsec / NSEC_PER_USEC) * 48; @@ -47,6 +47,8 @@ uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf, data[1] |= UVC_STREAM_PTS; put_unaligned_le32(pts, &data[pos]); + if (data[1] & UVC_STREAM_ERR) + trace_printk("PTS: %u\n", data[pos]); pos += 4; } @@ -60,6 +62,10 @@ uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf, data[1] |= UVC_STREAM_SCR; put_unaligned_le32(stc, &data[pos]); put_unaligned_le16(sof, &data[pos+4]); + if (data[1] & UVC_STREAM_ERR) { + trace_printk("SCR: %u\n", data[pos]); + trace_printk("SCR: %hu\n", data[pos+4]); + } pos += 6; } @@ -731,6 +734,7 @@ int uvcg_video_enable(struct uvc_video *video) struct usb_gadget *gadget = cdev->gadget; int ret; + video->errorcount = 0; if (video->ep == NULL) { uvcg_info(&video->uvc->func, "Video enable failed, device is uninitialized.\n"); diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 28dde08ec6c5d..40eafe43d1888 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -916,8 +916,24 @@ static void uvc_video_stats_decode(struct uvc_streaming *stream, if (len <= header_size) stream->stats.frame.nb_empty++; - if (data[1] & UVC_STREAM_ERR) + if (data[1] & UVC_STREAM_ERR) { stream->stats.frame.nb_errors++; + printk("error on uvc package!\n"); + if (data[1] & UVC_STREAM_PTS) { + printk("PTS: %u\n", data[2]); + if (data[1] & UVC_STREAM_SCR) { + printk("SCR: %u\n", data[6]); + printk("SCR: %hu\n", data[10]); + } + } else { + if (data[1] & UVC_STREAM_SCR) { + printk("SCR: %u\n", data[2]); + printk("SCR: %hu\n", data[6]); + } + } + + + } } -- Host: