[{"id":27598,"web_url":"https://patchwork.libcamera.org/comment/27598/","msgid":"<4dauzwl7kjbegpdmxh5di3ksr7t4z5neo5jfh4tvt4eoy3d5bb@ljybidssephv>","date":"2023-07-24T07:29:38","subject":"Re: [libcamera-devel] [PATCH v1 1/4] pipeline: rpi: Increase buffer\n\timport count to 32","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Naush\n\nOn Fri, Jul 21, 2023 at 10:37:56AM +0100, Naushir Patuck via libcamera-devel wrote:\n> Hardcode the maximum number of buffers imported to the V4L2 video device\n> to 32. This only has a minor disadvantage of over-allocating cache slots\n> and V4L2 buffer indexes, but does allow more headroom for using dma\n> buffers allocated from outside of libcamera.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  .../pipeline/rpi/common/rpi_stream.cpp        | 35 +++++--------------\n>  1 file changed, 9 insertions(+), 26 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> index c158843cb0ed..1d05c5acc0d9 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> @@ -94,35 +94,18 @@ int Stream::prepareBuffers(unsigned int count)\n>  {\n>  \tint ret;\n>\n> -\tif (!(flags_ & StreamFlag::ImportOnly)) {\n> -\t\tif (count) {\n> -\t\t\t/* Export some frame buffers for internal use. */\n> -\t\t\tret = dev_->exportBuffers(count, &internalBuffers_);\n> -\t\t\tif (ret < 0)\n> -\t\t\t\treturn ret;\n> -\n> -\t\t\t/* Add these exported buffers to the internal/external buffer list. */\n> -\t\t\tsetExportedBuffers(&internalBuffers_);\n> -\t\t\tresetBuffers();\n> -\t\t}\n> +\tif (!(flags_ & StreamFlag::ImportOnly) && count) {\n\nIs there a case where this functions is called with a 0 'count' ?\n\n> +\t\t/* Export some frame buffers for internal use. */\n> +\t\tret = dev_->exportBuffers(count, &internalBuffers_);\n> +\t\tif (ret < 0)\n> +\t\t\treturn ret;\n>\n> -\t\t/* We must import all internal/external exported buffers. */\n> -\t\tcount = bufferMap_.size();\n> +\t\t/* Add these exported buffers to the internal/external buffer list. */\n> +\t\tsetExportedBuffers(&internalBuffers_);\n> +\t\tresetBuffers();\n>  \t}\n>\n> -\t/*\n> -\t * If this is an external stream, we must allocate slots for buffers that\n> -\t * might be externally allocated. We have no indication of how many buffers\n> -\t * may be used, so this might overallocate slots in the buffer cache.\n> -\t * Similarly, if this stream is only importing buffers, we do the same.\n> -\t *\n> -\t * \\todo Find a better heuristic, or, even better, an exact solution to\n> -\t * this issue.\n> -\t */\n> -\tif ((flags_ & StreamFlag::External) || (flags_ & StreamFlag::ImportOnly))\n> -\t\tcount = count * 2;\n> -\n> -\treturn dev_->importBuffers(count);\n> +\treturn dev_->importBuffers(32);\n>  }\n>\n>  int Stream::queueBuffer(FrameBuffer *buffer)\n> --\n> 2.34.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2390ABDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Jul 2023 07:29:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 532D1628C0;\n\tMon, 24 Jul 2023 09:29:43 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3E83E60387\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Jul 2023 09:29:42 +0200 (CEST)","from ideasonboard.com (mob-5-91-20-233.net.vodafone.it\n\t[5.91.20.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A4C31735;\n\tMon, 24 Jul 2023 09:28:44 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690183783;\n\tbh=5w49qbpqovsHuWoUREdQ0vxykoy0epQVooyrlbq/LxQ=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=ZgPqdD53dP4J58u1Zl37XtfjsYkIq/tv7r4m5EeiX0E8dIogIc5814ghNgut+LUJ+\n\tjifSU7LGbhQzPcNYVpOe8Lcl1fEZPGOHjv7kNn3lpoli9aCkcAz3EC3eYKPSH6v2zi\n\tBV9DLpixdKxkX5eOkK44ARY0/iEaKQ/QrvUsNPnsxeBk8hN/i5MR+gv1NXe0AWJL7v\n\t9F/aOCSS5QrowkOCGVVqgX1DexddxYZFyP7ku55TehmcSWbG+gG+Am2bgKsg0aHfaP\n\tn4cFrQOwarW/HZjfg0/yOaHSqXw4iXBYg7W8fKb25SCykOwtKKZ9MoPC8Q5Lkb/vgf\n\t8IMyW9Xiehn6w==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1690183724;\n\tbh=5w49qbpqovsHuWoUREdQ0vxykoy0epQVooyrlbq/LxQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=aiOhr/3370qhVTaZieUHc4p2rQMCf8A4Ex6rEw02Y93LXvY4vvZjrhv8QEbrUxFOM\n\tSode/DaSkMQna8mT7zewFG/ZRxh43oRVDu0j0Naty5g9+u+gaQIQ96HHOpSLZuw+Hq\n\ts+wf5ruKGjCuku5LTRZpynDEhER3hcA9eA7PfMeE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"aiOhr/33\"; dkim-atps=neutral","Date":"Mon, 24 Jul 2023 09:29:38 +0200","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<4dauzwl7kjbegpdmxh5di3ksr7t4z5neo5jfh4tvt4eoy3d5bb@ljybidssephv>","References":"<20230721093759.27700-1-naush@raspberrypi.com>\n\t<20230721093759.27700-2-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230721093759.27700-2-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v1 1/4] pipeline: rpi: Increase buffer\n\timport count to 32","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27601,"web_url":"https://patchwork.libcamera.org/comment/27601/","msgid":"<CAEmqJPrh-KybGH-AR1wJ-0hOL9Js-m9jY=Sxh1CmMokAaiH3CA@mail.gmail.com>","date":"2023-07-24T07:48:02","subject":"Re: [libcamera-devel] [PATCH v1 1/4] pipeline: rpi: Increase buffer\n\timport count to 32","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Jacopo,\n\nOn Mon, 24 Jul 2023 at 08:29, Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> Hi Naush\n>\n> On Fri, Jul 21, 2023 at 10:37:56AM +0100, Naushir Patuck via libcamera-devel wrote:\n> > Hardcode the maximum number of buffers imported to the V4L2 video device\n> > to 32. This only has a minor disadvantage of over-allocating cache slots\n> > and V4L2 buffer indexes, but does allow more headroom for using dma\n> > buffers allocated from outside of libcamera.\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  .../pipeline/rpi/common/rpi_stream.cpp        | 35 +++++--------------\n> >  1 file changed, 9 insertions(+), 26 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> > index c158843cb0ed..1d05c5acc0d9 100644\n> > --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> > +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> > @@ -94,35 +94,18 @@ int Stream::prepareBuffers(unsigned int count)\n> >  {\n> >       int ret;\n> >\n> > -     if (!(flags_ & StreamFlag::ImportOnly)) {\n> > -             if (count) {\n> > -                     /* Export some frame buffers for internal use. */\n> > -                     ret = dev_->exportBuffers(count, &internalBuffers_);\n> > -                     if (ret < 0)\n> > -                             return ret;\n> > -\n> > -                     /* Add these exported buffers to the internal/external buffer list. */\n> > -                     setExportedBuffers(&internalBuffers_);\n> > -                     resetBuffers();\n> > -             }\n> > +     if (!(flags_ & StreamFlag::ImportOnly) && count) {\n>\n> Is there a case where this functions is called with a 0 'count' ?\n\nI *think* count will always be non-zero.  So the test above is\nprobably redundant!\n\nRegards,\nNaush\n\n>\n> > +             /* Export some frame buffers for internal use. */\n> > +             ret = dev_->exportBuffers(count, &internalBuffers_);\n> > +             if (ret < 0)\n> > +                     return ret;\n> >\n> > -             /* We must import all internal/external exported buffers. */\n> > -             count = bufferMap_.size();\n> > +             /* Add these exported buffers to the internal/external buffer list. */\n> > +             setExportedBuffers(&internalBuffers_);\n> > +             resetBuffers();\n> >       }\n> >\n> > -     /*\n> > -      * If this is an external stream, we must allocate slots for buffers that\n> > -      * might be externally allocated. We have no indication of how many buffers\n> > -      * may be used, so this might overallocate slots in the buffer cache.\n> > -      * Similarly, if this stream is only importing buffers, we do the same.\n> > -      *\n> > -      * \\todo Find a better heuristic, or, even better, an exact solution to\n> > -      * this issue.\n> > -      */\n> > -     if ((flags_ & StreamFlag::External) || (flags_ & StreamFlag::ImportOnly))\n> > -             count = count * 2;\n> > -\n> > -     return dev_->importBuffers(count);\n> > +     return dev_->importBuffers(32);\n> >  }\n> >\n> >  int Stream::queueBuffer(FrameBuffer *buffer)\n> > --\n> > 2.34.1\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 7EE24BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Jul 2023 07:48:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D72F2628C0;\n\tMon, 24 Jul 2023 09:48:20 +0200 (CEST)","from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com\n\t[IPv6:2607:f8b0:4864:20::1134])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E7B760387\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Jul 2023 09:48:19 +0200 (CEST)","by mail-yw1-x1134.google.com with SMTP id\n\t00721157ae682-57026f4bccaso50541427b3.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Jul 2023 00:48:19 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690184900;\n\tbh=+zzUBrCh+7YefI/sE8SC/B/8jqfgM8nYA5gIp/3f3Jc=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Qzs6YuqJms5nHh3bgeUASDMR6/ThpKm7XNMQ3NG1xGqAWtY4lcSahkk5OLiYfWuMo\n\tkCLGW5sLB4gC/jAJ6ZpfhMtUtEAugpmh7alWbUgE6CiR//ACayJ1lKuGB6PNCx1M+d\n\txQzXG2jd2+ZwajVKLAg4YQOZstWMwCM/6f/hwc9t0Oh2lMlYDBcNAyDaUOrdX2gR1X\n\tqjOa9OLjci6KdeMHEQS6bmvggheGROzMTtYQFJMWLSRGDGFyfJEFUCMmJs5PCXJ7yK\n\tUW+WXwiYGPkrGN5jZa6n+E9uP6jpmApMLXHTNXPw4kDPZpY63q2MBNM79sHe8lUJHp\n\t/17vUvLSPTGDQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1690184898; x=1690789698;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=++yB5+wrgIfegS7pIdJ+bayF0IIfRGmXm+V6n/wU26I=;\n\tb=AZQkcoQpKQTPJu+Z9IUAyjnXfiZAxfmLCKWDdEGUQ8kYzECajfeoagkOekhdopeZxj\n\tEprd9X4HAhTw5zlYU8Z7tJ9mbelXycSVSY4dmTJ4Vk9NXIMgCM1Djyw1fEQ7s05XNYMk\n\tt7LsSq2w/wVTd/ZJKvQ1UyMmwtzRvaGhtgfngF0R2z91U/Wu0g5dqYMEgfMeOU8jkrNN\n\t/h4eQ3sM38mvaVYmtaa7CkJriVAxk6RtbwqCVVLS8AxFQx1PcHZ3LMhqaUZqcKCL5SLw\n\thUzAkRe0IJO1DrEbmdb6+gmlB40cwl3iADta0E2dlyMUrDTfgfJo6GhISX3UVg0R/3l7\n\t0CVw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"AZQkcoQp\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1690184898; x=1690789698;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=++yB5+wrgIfegS7pIdJ+bayF0IIfRGmXm+V6n/wU26I=;\n\tb=GojO/HW//6/0PBjeYHCYtOEC5neH7I7F/mNu0GllC3fFEFnmEYKCkpp42ziKZN7yGa\n\tAf/JrnV+aFGGdBue9MVjGTPsxhI68/P/tNe4aenxiW9n+8Koei/NO4DFPznmP3CfFl+6\n\tFkauw6IjvWMLU3ZXUGWG1LHGpT3wq+rE8zgu+exfUrh6GYl1OzlgInYPT5L8r6UO2GFe\n\tvn3oOVMIsiJ/e4q3sipu3N4AeYlyIuwjMMJh0zqyIUYFvba1SwK2BbOs4LvXrtKUNbtX\n\tL7mnIW0pzXPXQdwLAM8W3zFlAO+Ntr6G0nhlQB3IRR3yuh9b/ZOCzr1OzaJETGYwWtTJ\n\t1xNQ==","X-Gm-Message-State":"ABy/qLbJ+2pGz9HYr8uPpssnz4HTY0a4UoAhgkCDljUCF/YIlpC1tUSa\n\tQ5atXvAASt6ABhVrHInFBylih0+cC1eny3RekmMuNB9ZiUnwOYznZ0c=","X-Google-Smtp-Source":"APBJJlH9c/WQd2IT6Dhg3ZiU9xuZDG8U9kD/bKj0YyYVGteCMhCCFu2Olq91H6ugvHeeOZfuS3MHgur7har5m0COWXo=","X-Received":"by 2002:a0d:dd48:0:b0:583:af0a:267 with SMTP id\n\tg69-20020a0ddd48000000b00583af0a0267mr5791449ywe.5.1690184898122;\n\tMon, 24 Jul 2023 00:48:18 -0700 (PDT)","MIME-Version":"1.0","References":"<20230721093759.27700-1-naush@raspberrypi.com>\n\t<20230721093759.27700-2-naush@raspberrypi.com>\n\t<4dauzwl7kjbegpdmxh5di3ksr7t4z5neo5jfh4tvt4eoy3d5bb@ljybidssephv>","In-Reply-To":"<4dauzwl7kjbegpdmxh5di3ksr7t4z5neo5jfh4tvt4eoy3d5bb@ljybidssephv>","Date":"Mon, 24 Jul 2023 08:48:02 +0100","Message-ID":"<CAEmqJPrh-KybGH-AR1wJ-0hOL9Js-m9jY=Sxh1CmMokAaiH3CA@mail.gmail.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v1 1/4] pipeline: rpi: Increase buffer\n\timport count to 32","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]