Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp144725pxb; Thu, 2 Sep 2021 21:57:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0wyt9rdOXDcEWQy6/IbYQ22d3cTJoNsSO+T49iIfFSmOiIKghgUc9h7TQubTpJ0OUBdZt X-Received: by 2002:a92:d9c2:: with SMTP id n2mr1227457ilq.214.1630645022183; Thu, 02 Sep 2021 21:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630645022; cv=none; d=google.com; s=arc-20160816; b=xo0BMsTx+EqSAx9GSy4T4B0hSTh1ZAjITjC4nM8oYzKal8ehv5oAEclFvQFyy+tW4A uJoC1Qe1nEB0XM34F2DwWZ1ZGsDIppwB4OLHxFLsMX25e9r5i+IZlwVPszy9/oF31g3b 71bD6IJ6uugFaH5Bv9cMQwfZhhvOHoTyXrluwOhAjE9wE5DyfhFH5Edg9dEto9doF2lG j+wF5XPrGUKdBOr4dv7UBuuJB8ZIq3Pm+FbVck0l/ErnMNeFV6Er0bBuZjxmndq5xbr7 GbSiiBFbjwL/Su8k6yIHoO7lW/nseqYhgYMW7NsaZ6Pi7jULX4DV85bpk68+tmc397Bu lZrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=d/LYbW/QE4R7lHMZoD2nlACpGZYWSl+4MFe9vHxQQXM=; b=XzJNCU/jpMy8B02xSXaqKH/6FCscVqgOCkKivxarnMu/d6eer9srV15DkMuggNK1sc mKnEPl2CdDZ8ObKCbMAPA9GTOwMy+2ENpbu4k3Lu8iBAbrP3bu9PYEemONKXPnO2b1i5 3AN/dET8Xnjq3IJoce238bnQzOLKQ12L4hI7CdevoKBlmqQ76HSpPfh97hNWsVIX1FPv w/Ff24Q/DkIQq+EAQcHfZqR5mt11qxZkYr26Lp4IVeTWgsS/XhF9XeNyPZdV7Ay3+uHs 2hwKVt0p/M0CGAXmBi78/2zCxA8WMP7RAO2G6HQS1WNrEPSHYHvxcz0VtGP6UsoMFAS/ 3kEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si3721661iot.57.2021.09.02.21.56.38; Thu, 02 Sep 2021 21:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231705AbhICE4B (ORCPT + 99 others); Fri, 3 Sep 2021 00:56:01 -0400 Received: from lgeamrelo13.lge.com ([156.147.23.53]:44724 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229561AbhICE4A (ORCPT ); Fri, 3 Sep 2021 00:56:00 -0400 Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.53 with ESMTP; 3 Sep 2021 13:54:58 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: kyeongdon.kim@lge.com Received: from unknown (HELO localhost.localdomain) (10.159.40.99) by 156.147.1.121 with ESMTP; 3 Sep 2021 13:54:58 +0900 X-Original-SENDERIP: 10.159.40.99 X-Original-MAILFROM: kyeongdon.kim@lge.com From: Kyeongdon Kim To: laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kyeongdon Kim Subject: [PATCH v2] media: uvcvideo: use dynamic allocation for uvc_copy_op Date: Fri, 3 Sep 2021 13:54:56 +0900 Message-Id: <20210903045456.83301-1-kyeongdon.kim@lge.com> X-Mailer: git-send-email 2.10.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are some issues to handle frame throughput with camera devices Using devices: - Logitech Webcam - Intel(R) RealSense(TM) Depth Camera To improve efficiency, and maximise throughput, use dynamic allocation for uvc_copy_op. Change from struct uvc_copy_op copy_operations[UVC_MAX_PACKETS]; to struct uvc_copy_op *copy_operations; Now, only tested bulk video options. On test device & own debug log to check frame duration(us), refer to test result the below: Use copy_operations[UVC_MAX_PACKETS] [UVC] Check time duration(us) : 54732 / 66000 [UVC] Check time duration(us) : 57452 / 66000 [UVC] Check time duration(us) : 57413 / 66000 [UVC] Check time duration(us) : 56713 / 66000 [UVC] Check time duration(us) : 57967 / 66000 Use *copy_operations [UVC] Check time duration(us) : 30804 / 66000 [UVC] Check time duration(us) : 38642 / 66000 [UVC] Check time duration(us) : 26011 / 66000 [UVC] Check time duration(us) : 30116 / 66000 [UVC] Check time duration(us) : 29265 / 66000 Signed-off-by: Kyeongdon Kim --- drivers/media/usb/uvc/uvc_video.c | 55 ++++++++++++++++++++++++++++++++++++--- drivers/media/usb/uvc/uvcvideo.h | 3 ++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index e164646..3a7c131 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1614,6 +1614,36 @@ static void uvc_video_complete(struct urb *urb) queue_work(stream->async_wq, &uvc_urb->work); } +static void uvc_free_urb_cop(struct uvc_streaming *stream) +{ + struct uvc_urb *uvc_urb; + + for_each_uvc_urb(uvc_urb, stream) { + if (uvc_urb->copy_operations) { + kfree(uvc_urb->copy_operations); + uvc_urb->copy_operations = NULL; + } + } +} + +static int uvc_alloc_urb_cop(struct uvc_streaming *stream, gfp_t gfp_flags) +{ + int max_packet = stream->urb_max_packets; + struct uvc_urb *uvc_urb; + + for_each_uvc_urb(uvc_urb, stream) { + uvc_urb->copy_operations + = kcalloc(max_packet, sizeof(struct uvc_copy_op), gfp_flags); + if (uvc_urb->copy_operations == NULL) + goto error; + } + return 0; +error: + uvc_free_urb_cop(stream); + + return -ENOMEM; +} + /* * Free transfer buffers. */ @@ -1687,8 +1717,8 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, * payloads across multiple URBs. */ npackets = DIV_ROUND_UP(size, psize); - if (npackets > UVC_MAX_PACKETS) - npackets = UVC_MAX_PACKETS; + if (npackets > stream->urb_max_packets) + npackets = stream->urb_max_packets; /* Retry allocations until one succeed. */ for (; npackets > 1; npackets /= 2) { @@ -1744,8 +1774,10 @@ static void uvc_video_stop_transfer(struct uvc_streaming *stream, uvc_urb->urb = NULL; } - if (free_buffers) + if (free_buffers) { uvc_free_urb_buffers(stream); + uvc_free_urb_cop(stream); + } } /* @@ -1790,10 +1822,18 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream, psize = uvc_endpoint_max_bpi(stream->dev->udev, ep); size = stream->ctrl.dwMaxVideoFrameSize; + stream->urb_max_packets = UVC_MAX_PACKETS; + npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); if (npackets == 0) return -ENOMEM; + if (uvc_alloc_urb_cop(stream, gfp_flags) != 0) { + uvc_dbg(stream->dev, VIDEO, + "Failed to init URBs copy operations.\n"); + return -ENOMEM; + } + size = npackets * psize; for_each_uvc_urb(uvc_urb, stream) { @@ -1842,11 +1882,18 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream, psize = usb_endpoint_maxp(&ep->desc); size = stream->ctrl.dwMaxPayloadTransferSize; stream->bulk.max_payload_size = size; + stream->urb_max_packets = DIV_ROUND_UP(size, psize); npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); if (npackets == 0) return -ENOMEM; + if (uvc_alloc_urb_cop(stream, gfp_flags) != 0) { + uvc_dbg(stream->dev, VIDEO, + "Failed to init URBs copy operations.\n"); + return -ENOMEM; + } + size = npackets * psize; if (usb_endpoint_dir_in(&ep->desc)) @@ -2147,6 +2194,8 @@ int uvc_video_init(struct uvc_streaming *stream) } } + stream->urb_max_packets = UVC_MAX_PACKETS; + /* Prepare asynchronous work items. */ for_each_uvc_urb(uvc_urb, stream) INIT_WORK(&uvc_urb->work, uvc_video_copy_data_work); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index cce5e38..00cf6c9 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -561,7 +561,7 @@ struct uvc_urb { struct sg_table *sgt; unsigned int async_operations; - struct uvc_copy_op copy_operations[UVC_MAX_PACKETS]; + struct uvc_copy_op *copy_operations; struct work_struct work; }; @@ -616,6 +616,7 @@ struct uvc_streaming { struct uvc_urb uvc_urb[UVC_URBS]; unsigned int urb_size; + unsigned int urb_max_packets; u32 sequence; u8 last_fid; -- 2.10.2