linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: uvcvideo: use dynamic allocation for uvc_copy_op
@ 2021-09-02  8:49 Kyeongdon Kim
  2021-09-02 15:18 ` kernel test robot
  2021-09-02 17:30 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Kyeongdon Kim @ 2021-09-02  8:49 UTC (permalink / raw)
  To: laurent.pinchart; +Cc: mchehab, linux-media, linux-kernel, Kyeongdon Kim

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) : 64732 / 66000
[UVC] Check time duration(us) : 67452 / 66000
[UVC] Check time duration(us) : 67413 / 66000
[UVC] Check time duration(us) : 66713 / 66000
[UVC] Check time duration(us) : 67967 / 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 <kyeongdon.kim@lge.com>
---
 drivers/media/usb/uvc/uvc_video.c | 52 ++++++++++++++++++++++++++++++++++++---
 drivers/media/usb/uvc/uvcvideo.h  |  3 ++-
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index e164646..32bc98e 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1614,6 +1614,33 @@ 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)
+{
+	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;
+
+	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 +1714,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 +1771,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 +1819,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 +1879,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 +2191,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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: uvcvideo: use dynamic allocation for uvc_copy_op
  2021-09-02  8:49 [PATCH] media: uvcvideo: use dynamic allocation for uvc_copy_op Kyeongdon Kim
@ 2021-09-02 15:18 ` kernel test robot
  2021-09-02 17:30 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-09-02 15:18 UTC (permalink / raw)
  To: Kyeongdon Kim, laurent.pinchart
  Cc: llvm, kbuild-all, mchehab, linux-media, linux-kernel, Kyeongdon Kim

[-- Attachment #1: Type: text/plain, Size: 4022 bytes --]

Hi Kyeongdon,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.14 next-20210902]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kyeongdon-Kim/media-uvcvideo-use-dynamic-allocation-for-uvc_copy_op/20210902-172043
base:   git://linuxtv.org/media_tree.git master
config: i386-randconfig-a014-20210831 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project c9948e9254fbb6ea00f66c7b4542311d21e060be)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/2a36e010c8f73cd5c36072caf7e63431a07f4aad
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kyeongdon-Kim/media-uvcvideo-use-dynamic-allocation-for-uvc_copy_op/20210902-172043
        git checkout 2a36e010c8f73cd5c36072caf7e63431a07f4aad
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/media/usb/uvc/uvc_video.c:1619:19: error: use of undeclared identifier 'uvc_urb'
           for_each_uvc_urb(uvc_urb, stream) {
                            ^
>> drivers/media/usb/uvc/uvc_video.c:1619:19: error: use of undeclared identifier 'uvc_urb'
>> drivers/media/usb/uvc/uvc_video.c:1619:19: error: use of undeclared identifier 'uvc_urb'
   drivers/media/usb/uvc/uvc_video.c:1620:7: error: use of undeclared identifier 'uvc_urb'
                   if (uvc_urb->copy_operations) {
                       ^
   drivers/media/usb/uvc/uvc_video.c:1621:10: error: use of undeclared identifier 'uvc_urb'
                           kfree(uvc_urb->copy_operations);
                                 ^
>> drivers/media/usb/uvc/uvc_video.c:1622:4: error: must use 'struct' tag to refer to type 'uvc_urb'
                           uvc_urb->copy_operations = NULL;
                           ^
                           struct 
>> drivers/media/usb/uvc/uvc_video.c:1622:11: error: expected identifier or '('
                           uvc_urb->copy_operations = NULL;
                                  ^
   drivers/media/usb/uvc/uvc_video.c:1631:19: error: use of undeclared identifier 'uvc_urb'
           for_each_uvc_urb(uvc_urb, stream) {
                            ^
   drivers/media/usb/uvc/uvc_video.c:1631:19: error: use of undeclared identifier 'uvc_urb'
   drivers/media/usb/uvc/uvc_video.c:1631:19: error: use of undeclared identifier 'uvc_urb'
   drivers/media/usb/uvc/uvc_video.c:1632:3: error: must use 'struct' tag to refer to type 'uvc_urb'
                   uvc_urb->copy_operations
                   ^
                   struct 
   drivers/media/usb/uvc/uvc_video.c:1632:10: error: expected identifier or '('
                   uvc_urb->copy_operations
                          ^
   drivers/media/usb/uvc/uvc_video.c:1634:7: error: use of undeclared identifier 'uvc_urb'
                   if (uvc_urb->copy_operations == NULL)
                       ^
   13 errors generated.


vim +/uvc_urb +1619 drivers/media/usb/uvc/uvc_video.c

  1616	
  1617	static void uvc_free_urb_cop(struct uvc_streaming *stream)
  1618	{
> 1619		for_each_uvc_urb(uvc_urb, stream) {
  1620			if (uvc_urb->copy_operations) {
  1621				kfree(uvc_urb->copy_operations);
> 1622				uvc_urb->copy_operations = NULL;
  1623			}
  1624		}
  1625	}
  1626	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 35291 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: uvcvideo: use dynamic allocation for uvc_copy_op
  2021-09-02  8:49 [PATCH] media: uvcvideo: use dynamic allocation for uvc_copy_op Kyeongdon Kim
  2021-09-02 15:18 ` kernel test robot
@ 2021-09-02 17:30 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-09-02 17:30 UTC (permalink / raw)
  To: Kyeongdon Kim, laurent.pinchart
  Cc: kbuild-all, mchehab, linux-media, linux-kernel, Kyeongdon Kim

[-- Attachment #1: Type: text/plain, Size: 3411 bytes --]

Hi Kyeongdon,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v5.14 next-20210902]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kyeongdon-Kim/media-uvcvideo-use-dynamic-allocation-for-uvc_copy_op/20210902-172043
base:   git://linuxtv.org/media_tree.git master
config: openrisc-buildonly-randconfig-r003-20210902 (attached as .config)
compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/2a36e010c8f73cd5c36072caf7e63431a07f4aad
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kyeongdon-Kim/media-uvcvideo-use-dynamic-allocation-for-uvc_copy_op/20210902-172043
        git checkout 2a36e010c8f73cd5c36072caf7e63431a07f4aad
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash drivers/media/usb/uvc/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from drivers/media/usb/uvc/uvc_video.c:25:
   drivers/media/usb/uvc/uvc_video.c: In function 'uvc_free_urb_cop':
>> drivers/media/usb/uvc/uvc_video.c:1619:26: error: 'uvc_urb' undeclared (first use in this function)
    1619 |         for_each_uvc_urb(uvc_urb, stream) {
         |                          ^~~~~~~
   drivers/media/usb/uvc/uvcvideo.h:654:15: note: in definition of macro 'for_each_uvc_urb'
     654 |         for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \
         |               ^~~~~~~
   drivers/media/usb/uvc/uvc_video.c:1619:26: note: each undeclared identifier is reported only once for each function it appears in
    1619 |         for_each_uvc_urb(uvc_urb, stream) {
         |                          ^~~~~~~
   drivers/media/usb/uvc/uvcvideo.h:654:15: note: in definition of macro 'for_each_uvc_urb'
     654 |         for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \
         |               ^~~~~~~
   drivers/media/usb/uvc/uvc_video.c: In function 'uvc_alloc_urb_cop':
   drivers/media/usb/uvc/uvc_video.c:1631:26: error: 'uvc_urb' undeclared (first use in this function)
    1631 |         for_each_uvc_urb(uvc_urb, stream) {
         |                          ^~~~~~~
   drivers/media/usb/uvc/uvcvideo.h:654:15: note: in definition of macro 'for_each_uvc_urb'
     654 |         for ((uvc_urb) = &(uvc_streaming)->uvc_urb[0]; \
         |               ^~~~~~~


vim +/uvc_urb +1619 drivers/media/usb/uvc/uvc_video.c

  1616	
  1617	static void uvc_free_urb_cop(struct uvc_streaming *stream)
  1618	{
> 1619		for_each_uvc_urb(uvc_urb, stream) {
  1620			if (uvc_urb->copy_operations) {
  1621				kfree(uvc_urb->copy_operations);
  1622				uvc_urb->copy_operations = NULL;
  1623			}
  1624		}
  1625	}
  1626	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 40656 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-02 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  8:49 [PATCH] media: uvcvideo: use dynamic allocation for uvc_copy_op Kyeongdon Kim
2021-09-02 15:18 ` kernel test robot
2021-09-02 17:30 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).