[{"id":20792,"web_url":"https://patchwork.libcamera.org/comment/20792/","msgid":"<163654042246.1896795.11919529052942140004@Monstersaurus>","date":"2021-11-10T10:33:42","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2021-11-10 10:08:02)\n> If a stream is marked as external, double the number of V4L2BufferCache slots\n> that are allocated. This is to account for additional buffers that may be\n> allocated directly by the application.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n>  1 file changed, 8 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> index b3265d0e8aab..67901936d6b6 100644\n> --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n>                 count = bufferMap_.size();\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> +        */\n\nPerhaps we'll need a better system here (not in this patch) to handle\nthis ... but I think overallocating is cheap - and the whole point of\nthe buffer cache is to try to re-use the same buffers where possible. So\nI /think/ overallocations is the right solution for now anyway.\n\n> +       if (isExternal())\n> +               count = count * 2;\n\nOf course it's hard to know /how/ far to overallocate ... But this will\ndo until we figure it out ;-)\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n>         return dev_->importBuffers(count);\n>  }\n>  \n> -- \n> 2.25.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 E0658BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Nov 2021 10:33:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3B08C60361;\n\tWed, 10 Nov 2021 11:33:47 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CF06360128\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Nov 2021 11:33:45 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6D41CD8B;\n\tWed, 10 Nov 2021 11:33:45 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"U68CUMNS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636540425;\n\tbh=zX12/EmQ/de0hcb4CR/CcWz7QUVmKZDMErXvQG0HlmU=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=U68CUMNSpN0vIpCMLUlvhPFTIrIOxrkg/EfZn4DKJxCJq2VhxwxqENMhQWKI1kKZZ\n\tfl99wKzOezeedzfOAYeuqTBeW0V0/glx98yLOwEAE5egh9NbKKvsSCu9A7WKFu/7K0\n\tiFvdjZ1zBkH45KqdKgZGW9zKsGEO0VbxkrqmVTe4=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211110100802.349623-3-naush@raspberrypi.com>","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 10 Nov 2021 10:33:42 +0000","Message-ID":"<163654042246.1896795.11919529052942140004@Monstersaurus>","User-Agent":"alot/0.9.1","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"Roman Stratiienko <r.stratiienko@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20793,"web_url":"https://patchwork.libcamera.org/comment/20793/","msgid":"<CAEmqJPo3JbxioWWc4Gs03vQOC1ihK5Thn+MgaTGXbuJ3-0xM+w@mail.gmail.com>","date":"2021-11-10T10:42:58","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Kieran,\n\nThanks for all the reviews!\n\nOn Wed, 10 Nov 2021 at 10:33, Kieran Bingham <\nkieran.bingham@ideasonboard.com> wrote:\n\n> Quoting Naushir Patuck (2021-11-10 10:08:02)\n> > If a stream is marked as external, double the number of V4L2BufferCache\n> slots\n> > that are allocated. This is to account for additional buffers that may be\n> > allocated directly by the application.\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n> >  1 file changed, 8 insertions(+)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > index b3265d0e8aab..67901936d6b6 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n> >                 count = bufferMap_.size();\n> >         }\n> >\n> > +       /*\n> > +        * If this is an external stream, we must allocate slots for\n> buffers that\n> > +        * might be externally allocated. We have no indication of how\n> many buffers\n> > +        * may be used, so this might overallocate slots in the buffer\n> cache.\n> > +        */\n>\n> Perhaps we'll need a better system here (not in this patch) to handle\n> this ... but I think overallocating is cheap - and the whole point of\n> the buffer cache is to try to re-use the same buffers where possible. So\n> I /think/ overallocations is the right solution for now anyway.\n>\n\nI think this over allocation is the only change needed to \"fix\" Roman's\noriginal\nissue.  But I did mean to tidy up the buffer allocations for some time now,\nso\nwhy not :-)\n\n\n>\n> > +       if (isExternal())\n> > +               count = count * 2;\n>\n> Of course it's hard to know /how/ far to overallocate ... But this will\n> do until we figure it out ;-)\n>\n\nI wonder if we can perhaps allow the cache to grow in size dynamically\ninstead of relying on a fixed number of slots?\n\nNaush\n\n\n>\n>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> > +\n> >         return dev_->importBuffers(count);\n> >  }\n> >\n> > --\n> > 2.25.1\n> >\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 4EE3EBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Nov 2021 10:43:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 933DD6035A;\n\tWed, 10 Nov 2021 11:43:16 +0100 (CET)","from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com\n\t[IPv6:2a00:1450:4864:20::12a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8874B60128\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Nov 2021 11:43:15 +0100 (CET)","by mail-lf1-x12a.google.com with SMTP id u11so5001867lfs.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Nov 2021 02:43:15 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"YTbUaSuc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=lpJv9sY8h7da+XakISOy3UrlfCsgPkmaR+tXEhDcoDU=;\n\tb=YTbUaSucpkQhH2BYZknGpi2Zi9fpc4EE1rwb1rrGY9AKcceqddyD/8YvT+gyi8gIWk\n\tK5tRAtmzl3JnWT/qJ0xIX15x2amn8L/tCEkJj4MG8ev/20I2mWpiRDM+ggFl5++Tb/9X\n\tHC9XbFxZHNirP93Jbuf9eT6vjO6ualqOARU84QO+e2mVah2FdA9VaB1SIbUPX8dr7CDB\n\t5dpJD2mlzDY9wXN3oszyycFBVYVT7NYrk/bO60WhHZBE8oPfrRbOAJ8c/B7uQxFFQe6Y\n\t9VPbYr5yB+Lzna+bnLQAFYQsyMUziqjKYGg2KN3L7etc418gwm/mVdn27pldlSgwOUsM\n\t2HcA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=lpJv9sY8h7da+XakISOy3UrlfCsgPkmaR+tXEhDcoDU=;\n\tb=ZB5Kog4dDdpahUxtfuDgpRCcxiV1n5TG+8aeXs40IQ7ut+3WIbh43qbl52ZAtcJRzm\n\tI6NyVK5SRhuJHh56ckb3ywZQ6dQOPv8TL7PsdTn0vy9CShJ7AMqM6gj6x5ipTYK7wFxB\n\tUxflPibp5qdX8tajD6dcaFXpvFSIX47M2E8sZj8j8o/jva6uOQFutLBcH3KhiXh90kUW\n\tUiE4aiqKBG5SUmZxS2/tUmy38dJDwVVh3uJGZv6z+6vDEw58y8VWF6h9AfMLIvlpKcbp\n\thKUMkeptJDanatQYFXX+bYVReia14acUiS+mzFB/JkFjpuekDceJWSYAQUzsGmmu2+gn\n\tJWAw==","X-Gm-Message-State":"AOAM531Hul0auvFJyRHEEw0bAFTtGtdG98gQnw63by/qr/72FQ3SoH9E\n\tA9xC1wB4cShvMzLOP1FSl6GQUdvEBW0jHWsRMHDSoQ==","X-Google-Smtp-Source":"ABdhPJwKUCj0Pln647ADQLuTTpJupOwbptoHvNJqCpJjMHKqbMwK29A5MXIU5AJir/CgsSRY7tW48JJR38IFUPQT29c=","X-Received":"by 2002:ac2:4570:: with SMTP id\n\tk16mr13635439lfm.611.1636540994743; \n\tWed, 10 Nov 2021 02:43:14 -0800 (PST)","MIME-Version":"1.0","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>\n\t<163654042246.1896795.11919529052942140004@Monstersaurus>","In-Reply-To":"<163654042246.1896795.11919529052942140004@Monstersaurus>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 10 Nov 2021 10:42:58 +0000","Message-ID":"<CAEmqJPo3JbxioWWc4Gs03vQOC1ihK5Thn+MgaTGXbuJ3-0xM+w@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000a705a305d06ce40b\"","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\tRoman Stratiienko <r.stratiienko@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20795,"web_url":"https://patchwork.libcamera.org/comment/20795/","msgid":"<163654152299.1911624.13255316081648091656@Monstersaurus>","date":"2021-11-10T10:52:02","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2021-11-10 10:42:58)\n> Hi Kieran,\n> \n> Thanks for all the reviews!\n> \n> On Wed, 10 Nov 2021 at 10:33, Kieran Bingham <\n> kieran.bingham@ideasonboard.com> wrote:\n> \n> > Quoting Naushir Patuck (2021-11-10 10:08:02)\n> > > If a stream is marked as external, double the number of V4L2BufferCache\n> > slots\n> > > that are allocated. This is to account for additional buffers that may be\n> > > allocated directly by the application.\n> > >\n> > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > > ---\n> > >  src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n> > >  1 file changed, 8 insertions(+)\n> > >\n> > > diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > > index b3265d0e8aab..67901936d6b6 100644\n> > > --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > > +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > > @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n> > >                 count = bufferMap_.size();\n> > >         }\n> > >\n> > > +       /*\n> > > +        * If this is an external stream, we must allocate slots for\n> > buffers that\n> > > +        * might be externally allocated. We have no indication of how\n> > many buffers\n> > > +        * may be used, so this might overallocate slots in the buffer\n> > cache.\n> > > +        */\n> >\n> > Perhaps we'll need a better system here (not in this patch) to handle\n> > this ... but I think overallocating is cheap - and the whole point of\n> > the buffer cache is to try to re-use the same buffers where possible. So\n> > I /think/ overallocations is the right solution for now anyway.\n> >\n> \n> I think this over allocation is the only change needed to \"fix\" Roman's\n> original\n> issue.  But I did mean to tidy up the buffer allocations for some time now,\n> so\n> why not :-)\n> \n> \n> >\n> > > +       if (isExternal())\n> > > +               count = count * 2;\n> >\n> > Of course it's hard to know /how/ far to overallocate ... But this will\n> > do until we figure it out ;-)\n> >\n> \n> I wonder if we can perhaps allow the cache to grow in size dynamically\n> instead of relying on a fixed number of slots?\n\nThat's the bit that I wondered about as the \"better system\" - but it\nwould require a matching number of 'buffers' on the v4l2 side - so\ndynamically growing the slots would have to interact with the V4L2\nbuffer allcoations I think...\n\nI believe we can ask for more buffers some how - but I don't know if we\ncan do so /while/ streaming...\n\n--\nKieran\n\n> Naush\n> \n> \n> >\n> >\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > > +\n> > >         return dev_->importBuffers(count);\n> > >  }\n> > >\n> > > --\n> > > 2.25.1\n> > >\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 DC753BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Nov 2021 10:52:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2A9C56034A;\n\tWed, 10 Nov 2021 11:52:08 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27AD860128\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Nov 2021 11:52:06 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B28575D;\n\tWed, 10 Nov 2021 11:52:05 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"NtvQW3OT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636541525;\n\tbh=xUN0sM4JM2F8p5oVGLb6t9aW6midE4MuAWNpG7Vz6RA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=NtvQW3OTvEq+G3MpCzhtsjRgzhZRGD0U8oLmqq/ne5AbfLM/UFpscwH1H3SQW4qQi\n\tgTqjzCKQyajCPK/hoO85YX970Cc4vRdvMyQcK06zFRaRO+TstkJLFWjZw1FJL+GFlG\n\tdwX7DCYJJJG8D8Fo9vclqsEQpoGMPSgrPmksh4ec=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<CAEmqJPo3JbxioWWc4Gs03vQOC1ihK5Thn+MgaTGXbuJ3-0xM+w@mail.gmail.com>","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>\n\t<163654042246.1896795.11919529052942140004@Monstersaurus>\n\t<CAEmqJPo3JbxioWWc4Gs03vQOC1ihK5Thn+MgaTGXbuJ3-0xM+w@mail.gmail.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 10 Nov 2021 10:52:02 +0000","Message-ID":"<163654152299.1911624.13255316081648091656@Monstersaurus>","User-Agent":"alot/0.9.1","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\tRoman Stratiienko <r.stratiienko@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20822,"web_url":"https://patchwork.libcamera.org/comment/20822/","msgid":"<a53899c6-1a5f-ba35-e7df-a4d47902b36f@ideasonboard.com>","date":"2021-11-10T18:35:07","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Naush\n\nThank you for the patch\n\nOn 11/10/21 3:38 PM, Naushir Patuck wrote:\n> If a stream is marked as external, double the number of V4L2BufferCache slots\n> that are allocated. This is to account for additional buffers that may be\n> allocated directly by the application.\n\n\nOne clarification pleease, does this mean applications can still \nallocate more buffers on the fly (i.e. the count can increase in \nfuture), even after RPi pipeline-handler has started?\n\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nPatch looks good so,\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> ---\n>   src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n>   1 file changed, 8 insertions(+)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> index b3265d0e8aab..67901936d6b6 100644\n> --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n>   \t\tcount = bufferMap_.size();\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 */\n> +\tif (isExternal())\n> +\t\tcount = count * 2;\n> +\n>   \treturn dev_->importBuffers(count);\n>   }\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 3B198BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Nov 2021 18:35:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 83DA36034E;\n\tWed, 10 Nov 2021 19:35:14 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EBC716033C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Nov 2021 19:35:12 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.5])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CE2958B6;\n\tWed, 10 Nov 2021 19:35:11 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"o2BWy6VR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636569312;\n\tbh=D7Fv/JMTXxjzjsM9jas6Y/M6GpGTuXisb41iwJifrZo=;\n\th=Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=o2BWy6VRD9cC083yIHReSMDC3AtKb9Vb4x7DaLwzdHj8ZAte+7tIx9OIOmgUpBXfT\n\tIo4b2zn2yeS5AJ4KSrlwF52D6K2cPs+9MUpVCUXlH1ToK21xRLfo/qnDU5Si9Zvcao\n\tJzfpCKja7xfim+6pU6Q7yJXL2Qz0HNahNR7AGYm4=","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>","From":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<a53899c6-1a5f-ba35-e7df-a4d47902b36f@ideasonboard.com>","Date":"Thu, 11 Nov 2021 00:05:07 +0530","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.10.2","MIME-Version":"1.0","In-Reply-To":"<20211110100802.349623-3-naush@raspberrypi.com>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"Roman Stratiienko <r.stratiienko@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20845,"web_url":"https://patchwork.libcamera.org/comment/20845/","msgid":"<CAEmqJPpowGnoOEoG0Xg-ihGG2-nvUXQ=0nC83_CHGghAwv_fZw@mail.gmail.com>","date":"2021-11-11T08:16:00","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Umang,\n\nThank you for your reviews!\n\nOn Wed, 10 Nov 2021 at 18:35, Umang Jain <umang.jain@ideasonboard.com>\nwrote:\n\n> Hi Naush\n>\n> Thank you for the patch\n>\n> On 11/10/21 3:38 PM, Naushir Patuck wrote:\n> > If a stream is marked as external, double the number of V4L2BufferCache\n> slots\n> > that are allocated. This is to account for additional buffers that may be\n> > allocated directly by the application.\n>\n>\n> One clarification pleease, does this mean applications can still\n> allocate more buffers on the fly (i.e. the count can increase in\n> future), even after RPi pipeline-handler has started?\n>\n\nMy understanding is that the Android layer does exactly this.\n\nAs pointed out by Kieran, one issue is that we may not know\nthe exact number of buffers allocated by the application.  Hence\nwe need a mechanism where the buffer cache sizing might have\nto become dynamic to account for additional buffers.  For now,\nover allocating the slots in the cache will be sufficient.\n\nRegards,\nNaush\n\n\n>\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>\n> Patch looks good so,\n>\n> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n>\n> > ---\n> >   src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n> >   1 file changed, 8 insertions(+)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > index b3265d0e8aab..67901936d6b6 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n> >               count = bufferMap_.size();\n> >       }\n> >\n> > +     /*\n> > +      * If this is an external stream, we must allocate slots for\n> buffers that\n> > +      * might be externally allocated. We have no indication of how\n> many buffers\n> > +      * may be used, so this might overallocate slots in the buffer\n> cache.\n> > +      */\n> > +     if (isExternal())\n> > +             count = count * 2;\n> > +\n> >       return dev_->importBuffers(count);\n> >   }\n> >\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 4DD3DBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 11 Nov 2021 08:16:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0B09D60362;\n\tThu, 11 Nov 2021 09:16:19 +0100 (CET)","from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com\n\t[IPv6:2a00:1450:4864:20::12d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6544F6032C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 09:16:17 +0100 (CET)","by mail-lf1-x12d.google.com with SMTP id l22so12321803lfg.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 00:16:17 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"pR3vD6Bq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=FzZfTAFJWrFnv5yESo+MOUX1ArYVvZjix9ZOltSe8kM=;\n\tb=pR3vD6Bqmxq6aJSjbNxH7CRgBB+T76kSGEHb5bzLNm+vXHXbO/DCRyqU6/zHyjdKIp\n\tdKPCkpctcD+dXdxJo4+7QpTwD6wSfRg1YjvgaGsDmXv5y40NBpYy+z4nkMAHsCpPQa8z\n\tt6rEIK2QuvoxylQCFR3IUrQW5Rz7fy0o1jsNH7673LoT5IlitoFHKYaZyKmF8k7MvLQW\n\tIthm/2oQr1sxErd7FuZwyqHA8eCngpZo2uGLYDec9vOpWYAeeo7d+y3HGlBKdZI8mbr4\n\tk1pDS95XrToWxhH3wgtn8r+o9u8DX6RRweWrqDFkgh2kmSdt9RTWhkIwhyYr2hlDYg8r\n\taFug==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=FzZfTAFJWrFnv5yESo+MOUX1ArYVvZjix9ZOltSe8kM=;\n\tb=PlAIm0SoRsrFsMYkGZhOxWCL4PHn3vAuHqXhgVj9MIOuG5ZT3HYObBYEa6f44OYADH\n\tiT70MN+bTgdKbnnPA2QaAtvwv/UdUbAcQpdBCH90LPYm+iahScQv+KtGqDkt1+ZTuZ9T\n\tl1MkC2XOILFC3a7QSNvGAOrvwTDIqSXZ4rGLcv4PQ08bmNxHiUIUvb/LEc8cwa8gEozW\n\tghbLrxRTo++JaY/CuEzjf9neAOIjCjc8bYguksDcRYzHlwRs59PdsSgFfeE/xeYvgXOy\n\tCJIecAXTLnLyPfMPaAe/rTTQKwNQsIEAmCutCorKL/NH6ntDjFsCsT/Ro/ylAKejMIgR\n\tlW+A==","X-Gm-Message-State":"AOAM5304cj6fMuQSLCyELPfgGrftHVWxSrl05iq7LsVPXSm7NQMMtcnU\n\th3wk41USyzjc3YEFQeyxorE/QPFGqt5CO5Qc8zsDWQ==","X-Google-Smtp-Source":"ABdhPJxxTv8c3MoEaVLya0pkPjiISsA1CKdkDaw0CROntgo/BUDYr5ZUOfSuWNohXoS1r3QsvADxkLq8LmmfTwdseKQ=","X-Received":"by 2002:a05:6512:3763:: with SMTP id\n\tz3mr4824320lft.315.1636618576535; \n\tThu, 11 Nov 2021 00:16:16 -0800 (PST)","MIME-Version":"1.0","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>\n\t<a53899c6-1a5f-ba35-e7df-a4d47902b36f@ideasonboard.com>","In-Reply-To":"<a53899c6-1a5f-ba35-e7df-a4d47902b36f@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Thu, 11 Nov 2021 08:16:00 +0000","Message-ID":"<CAEmqJPpowGnoOEoG0Xg-ihGG2-nvUXQ=0nC83_CHGghAwv_fZw@mail.gmail.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000e337c605d07ef477\"","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\tRoman Stratiienko <r.stratiienko@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20847,"web_url":"https://patchwork.libcamera.org/comment/20847/","msgid":"<CAGphcd=j1=hvn9QFrKpTAnj5v0XRvVKax=nfsP9d6BuQY1AEKg@mail.gmail.com>","date":"2021-11-11T08:36:03","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":106,"url":"https://patchwork.libcamera.org/api/people/106/","name":"Roman Stratiienko","email":"r.stratiienko@gmail.com"},"content":"Naush,\n\nPlease let me once again remind you that I have to set the\nconfiguration variable by downstream patch which determines the max.\nnumber of buffers for Android to allocate.\n\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -429,9 +429,9 @@ CameraConfiguration::Status\nRPiCameraConfiguration::validate()\n                        cfg.frameSize = unicamFormat.planes[0].size;\n                        rawCount++;\n                } else {\n+                       cfg.bufferCount = 3;\n                        outSize[outCount] = std::make_pair(count, cfg.size);\n                        /* Record the largest resolution for fixups later. */\n                        if (maxSize < cfg.size) {\n\nSo maybe this value could be used to calculate cache size. Sorry if I\nam talking about wrong things, I am new to the libcamera codebase.\n\nRoman.\n\nчт, 11 нояб. 2021 г. в 10:16, Naushir Patuck <naush@raspberrypi.com>:\n>\n> Hi Umang,\n>\n> Thank you for your reviews!\n>\n> On Wed, 10 Nov 2021 at 18:35, Umang Jain <umang.jain@ideasonboard.com> wrote:\n>>\n>> Hi Naush\n>>\n>> Thank you for the patch\n>>\n>> On 11/10/21 3:38 PM, Naushir Patuck wrote:\n>> > If a stream is marked as external, double the number of V4L2BufferCache slots\n>> > that are allocated. This is to account for additional buffers that may be\n>> > allocated directly by the application.\n>>\n>>\n>> One clarification pleease, does this mean applications can still\n>> allocate more buffers on the fly (i.e. the count can increase in\n>> future), even after RPi pipeline-handler has started?\n>\n>\n> My understanding is that the Android layer does exactly this.\n>\n> As pointed out by Kieran, one issue is that we may not know\n> the exact number of buffers allocated by the application.  Hence\n> we need a mechanism where the buffer cache sizing might have\n> to become dynamic to account for additional buffers.  For now,\n> over allocating the slots in the cache will be sufficient.\n>\n> Regards,\n> Naush\n>\n>>\n>>\n>> >\n>> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>>\n>> Patch looks good so,\n>>\n>> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n>>\n>> > ---\n>> >   src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n>> >   1 file changed, 8 insertions(+)\n>> >\n>> > diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n>> > index b3265d0e8aab..67901936d6b6 100644\n>> > --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n>> > +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n>> > @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n>> >               count = bufferMap_.size();\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>> > +      */\n>> > +     if (isExternal())\n>> > +             count = count * 2;\n>> > +\n>> >       return dev_->importBuffers(count);\n>> >   }\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 37BA8BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 11 Nov 2021 08:36:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 53E2E6035A;\n\tThu, 11 Nov 2021 09:36:17 +0100 (CET)","from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com\n\t[IPv6:2607:f8b0:4864:20::1035])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3E5686032C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 09:36:16 +0100 (CET)","by mail-pj1-x1035.google.com with SMTP id\n\tnh10-20020a17090b364a00b001a69adad5ebso4147526pjb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 00:36:16 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"iq/slDA9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc:content-transfer-encoding;\n\tbh=KSV2GrG80la287Yos+3zCLljT8t4+S+92/++tNDk2us=;\n\tb=iq/slDA92AANH646JV3RVVbitC38SfnMDiw+NLbHbJYQQll1etsYj/KhsdXw/vJxtv\n\toeqI0zy70cI3JvVlKMp98vUU0HYbtHXXrCGla9/6rDxVF5WaJVa5OVifcsCcsrJyn4ob\n\tnbJz7gwkaTuf1GhRlsJcJxP3Z2GolT3yL9nWG2jCY80rQ3B/9+mZck3MsUPlCD7l33MJ\n\tOFOY1diHnqBrS3Nsz34K7HfeygkAj/YI4ZtVZzY7p1JSpXWKicnXwAjia7nWqPRfKb9G\n\tLRlhx1zSGcx97adHEYjOyFiOaDGEpCkSB9tH/nzWG9v0sY+ikEH2H5SrAdG3GNGELqC4\n\tYo2w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc:content-transfer-encoding;\n\tbh=KSV2GrG80la287Yos+3zCLljT8t4+S+92/++tNDk2us=;\n\tb=ZmHpRWuq95GookhXKXTus64ZHnUXoF1WvcPzc2WiuHFH4VJ/9klMdfwy2a7Q/q5rDs\n\tmlZxkzpt837q/wPrtXBDDIwAem89R03Jdbe+2J3HP2f4OTW8WXFK0TNhvwoA1K1iN7Ce\n\tWiGcNZZvYXHItZyOEgMS/voLEqFpWy+gCgh76905B5hVIMq9XhXUrypJiZ0C+VYniul5\n\t1Uq1AWA6N9nsEiYXZ40u562gyfmhOweyrwr9RCd/XSbzv9NIE6Cbf7c7x5LVW6BlUQCj\n\tiyDd7Qol2EumB2iCTsgFThsVT5DdXOqfZGIY+YNo2Aq8rf3dik3qaLjTBQwEPaNZ2yhd\n\twd3w==","X-Gm-Message-State":"AOAM531Owv38g9suN92+elBHpXVEyamJvO3uOyAEP87q5vwBYvcDC6w7\n\tFVKqfYceGM6bYtu8yAj8K2JBzzg8JIR3Kvyr3/U=","X-Google-Smtp-Source":"ABdhPJzEedbn1ng3hEglJqX1xIeS67E4vms8f81r3zMBBLtj2ZvBW8Knjg9O81Z9LJEbBu8lt0TL0rRK0E8qUlxjZtw=","X-Received":"by 2002:a17:90b:3a89:: with SMTP id\n\tom9mr24499761pjb.29.1636619774378; \n\tThu, 11 Nov 2021 00:36:14 -0800 (PST)","MIME-Version":"1.0","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>\n\t<a53899c6-1a5f-ba35-e7df-a4d47902b36f@ideasonboard.com>\n\t<CAEmqJPpowGnoOEoG0Xg-ihGG2-nvUXQ=0nC83_CHGghAwv_fZw@mail.gmail.com>","In-Reply-To":"<CAEmqJPpowGnoOEoG0Xg-ihGG2-nvUXQ=0nC83_CHGghAwv_fZw@mail.gmail.com>","From":"Roman Stratiienko <r.stratiienko@gmail.com>","Date":"Thu, 11 Nov 2021 10:36:03 +0200","Message-ID":"<CAGphcd=j1=hvn9QFrKpTAnj5v0XRvVKax=nfsP9d6BuQY1AEKg@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20848,"web_url":"https://patchwork.libcamera.org/comment/20848/","msgid":"<CAEmqJPqeG_WboCjJ4Kb34rNrBYYCJttrL7O0A-2fukRVLS57PA@mail.gmail.com>","date":"2021-11-11T08:49:44","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Roman,\n\nOn Thu, 11 Nov 2021 at 08:36, Roman Stratiienko <r.stratiienko@gmail.com>\nwrote:\n\n> Naush,\n>\n> Please let me once again remind you that I have to set the\n> configuration variable by downstream patch which determines the max.\n> number of buffers for Android to allocate.\n>\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -429,9 +429,9 @@ CameraConfiguration::Status\n> RPiCameraConfiguration::validate()\n>                         cfg.frameSize = unicamFormat.planes[0].size;\n>                         rawCount++;\n>                 } else {\n> +                       cfg.bufferCount = 3;\n>                         outSize[outCount] = std::make_pair(count,\n> cfg.size);\n>                         /* Record the largest resolution for fixups later.\n> */\n>                         if (maxSize < cfg.size) {\n>\n> So maybe this value could be used to calculate cache size. Sorry if I\n> am talking about wrong things, I am new to the libcamera codebase.\n>\n\nI think this change effectively over allocates the buffer cache, and fixes\nthe original problem you were seeing.  The buffercount does indirectly\nget used to size the buffer cache in the existing code.\n\nI would not necessarily say this is the correct fix though, and we probably\nneed to understand the Android layer's buffer allocation mechanism better\nfor the Raspberry Pi pipeline handler.\n\nNaush\n\n\n\n>\n> Roman.\n>\n> чт, 11 нояб. 2021 г. в 10:16, Naushir Patuck <naush@raspberrypi.com>:\n> >\n> > Hi Umang,\n> >\n> > Thank you for your reviews!\n> >\n> > On Wed, 10 Nov 2021 at 18:35, Umang Jain <umang.jain@ideasonboard.com>\n> wrote:\n> >>\n> >> Hi Naush\n> >>\n> >> Thank you for the patch\n> >>\n> >> On 11/10/21 3:38 PM, Naushir Patuck wrote:\n> >> > If a stream is marked as external, double the number of\n> V4L2BufferCache slots\n> >> > that are allocated. This is to account for additional buffers that\n> may be\n> >> > allocated directly by the application.\n> >>\n> >>\n> >> One clarification pleease, does this mean applications can still\n> >> allocate more buffers on the fly (i.e. the count can increase in\n> >> future), even after RPi pipeline-handler has started?\n> >\n> >\n> > My understanding is that the Android layer does exactly this.\n> >\n> > As pointed out by Kieran, one issue is that we may not know\n> > the exact number of buffers allocated by the application.  Hence\n> > we need a mechanism where the buffer cache sizing might have\n> > to become dynamic to account for additional buffers.  For now,\n> > over allocating the slots in the cache will be sufficient.\n> >\n> > Regards,\n> > Naush\n> >\n> >>\n> >>\n> >> >\n> >> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> >>\n> >> Patch looks good so,\n> >>\n> >> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> >>\n> >> > ---\n> >> >   src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n> >> >   1 file changed, 8 insertions(+)\n> >> >\n> >> > diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> >> > index b3265d0e8aab..67901936d6b6 100644\n> >> > --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> >> > +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> >> > @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n> >> >               count = bufferMap_.size();\n> >> >       }\n> >> >\n> >> > +     /*\n> >> > +      * If this is an external stream, we must allocate slots for\n> buffers that\n> >> > +      * might be externally allocated. We have no indication of how\n> many buffers\n> >> > +      * may be used, so this might overallocate slots in the buffer\n> cache.\n> >> > +      */\n> >> > +     if (isExternal())\n> >> > +             count = count * 2;\n> >> > +\n> >> >       return dev_->importBuffers(count);\n> >> >   }\n> >> >\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 D5780BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 11 Nov 2021 08:50:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 045566034E;\n\tThu, 11 Nov 2021 09:50:03 +0100 (CET)","from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 12A426032C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 09:50:01 +0100 (CET)","by mail-lf1-x12f.google.com with SMTP id bu18so12638792lfb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 00:50:01 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"O8xurs7k\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=qohEhiG70goGUNV59JzR4EhjjgyRJk3PhbdZMGanryY=;\n\tb=O8xurs7kh5WZb4sKO+sZr0NlEQH+Jt54euo510EbwzVm+sa7hglMBqu9qMfibXOhCJ\n\too6dniNpemXo4+wmuNkqxopl9+F8QSrMIOjJEXwi49DdFYRXOoQSxYFXlcELgtuDo91H\n\t5GvBMP5cK4BE/XBvkL37t3Gyxud47dO0v7sYZCSqKjxX92ymBDw6VFsUP7qN6htNH5i0\n\t6bFVymnWR+2BSzcjcWxUqLrZ4pA2wvVEZtmOleltakM65QA2AvIj5n1O/ulcHzM+rrid\n\txkkxhXUvcdP8qxj3YrIFXdB//tFRnlJhROz0fTMAi3FdLaKFbbgqHoPmfHbKdfAKZFQ7\n\tJYYw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=qohEhiG70goGUNV59JzR4EhjjgyRJk3PhbdZMGanryY=;\n\tb=i3WBZoE3jILD1AUzFF0e9Wg3XrshkHW/IkWcm6uNGloSM7Lquvnh6MWHReFsr3LyTb\n\tKED0jA2e71BfoKchFIxHNGO4dr8snSDhypfJaANHBL0xRn/erhB8jL0mncWJEO7TPhkm\n\tkkemfyigOejopEmhvYJvazvZ3t/7KxMkBHi//g24r+SxEZV80WyGcsgZ77MHmUP6DbLw\n\tOtX37btlMNOC9NN+kKX1Dq2y/Ni7YZ02r2J4yzrXyOWCDQqlACEkRR9lX2DG7yOXVU62\n\t35oVvjC3pvIKPedF1t4qdyvD3gzNPOpc4ac7cneOuiToIglrGaPdJpp3D34MriVUYpdW\n\tWZpw==","X-Gm-Message-State":"AOAM532XUqJDBY5YjupceImU6qqu7SulN2/zjbP4w/Q9BrvQbJ0RGkrZ\n\tVt9vy9MQe3TJllXLziUm+2weco6Ac3iLlX/7T9pb+RSA0Kz4ww==","X-Google-Smtp-Source":"ABdhPJyJrkw1fLwu8LINL8IHdfAw3YvJF3PpGuXuCAAg8aUUGKklvL5R4uqy1ainSvNFKA710zVs7Qm7vjkQ1cVF3Ec=","X-Received":"by 2002:a05:6512:39c4:: with SMTP id\n\tk4mr3896721lfu.79.1636620600412; \n\tThu, 11 Nov 2021 00:50:00 -0800 (PST)","MIME-Version":"1.0","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>\n\t<a53899c6-1a5f-ba35-e7df-a4d47902b36f@ideasonboard.com>\n\t<CAEmqJPpowGnoOEoG0Xg-ihGG2-nvUXQ=0nC83_CHGghAwv_fZw@mail.gmail.com>\n\t<CAGphcd=j1=hvn9QFrKpTAnj5v0XRvVKax=nfsP9d6BuQY1AEKg@mail.gmail.com>","In-Reply-To":"<CAGphcd=j1=hvn9QFrKpTAnj5v0XRvVKax=nfsP9d6BuQY1AEKg@mail.gmail.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Thu, 11 Nov 2021 08:49:44 +0000","Message-ID":"<CAEmqJPqeG_WboCjJ4Kb34rNrBYYCJttrL7O0A-2fukRVLS57PA@mail.gmail.com>","To":"Roman Stratiienko <r.stratiienko@gmail.com>","Content-Type":"multipart/alternative; boundary=\"000000000000851ea605d07f6da9\"","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20864,"web_url":"https://patchwork.libcamera.org/comment/20864/","msgid":"<YY0tjdiJrqe0FRkS@pendragon.ideasonboard.com>","date":"2021-11-11T14:49:49","subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Nov 10, 2021 at 10:52:02AM +0000, Kieran Bingham wrote:\n> Quoting Naushir Patuck (2021-11-10 10:42:58)\n> > On Wed, 10 Nov 2021 at 10:33, Kieran Bingham wrote:\n> > > Quoting Naushir Patuck (2021-11-10 10:08:02)\n> > > > If a stream is marked as external, double the number of V4L2BufferCache slots\n> > > > that are allocated. This is to account for additional buffers that may be\n> > > > allocated directly by the application.\n> > > >\n> > > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > > > ---\n> > > >  src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 8 ++++++++\n> > > >  1 file changed, 8 insertions(+)\n> > > >\n> > > > diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > > > index b3265d0e8aab..67901936d6b6 100644\n> > > > --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > > > +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n> > > > @@ -107,6 +107,14 @@ int Stream::prepareBuffers(unsigned int count)\n> > > >                 count = bufferMap_.size();\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> > > > +        */\n> > >\n> > > Perhaps we'll need a better system here (not in this patch) to handle\n> > > this ... but I think overallocating is cheap - and the whole point of\n> > > the buffer cache is to try to re-use the same buffers where possible. So\n> > > I /think/ overallocations is the right solution for now anyway.\n\nOverallocation of V4L2 buffer slots is cheap, but we indeed can't know\nin advance how much to overallocate. Note that there's a hardcoded limit\nof 32 buffers in the kernel (VIDEO_MAX_FRAME).\n\n> > I think this over allocation is the only change needed to \"fix\" Roman's original\n> > issue.  But I did mean to tidy up the buffer allocations for some time now, so\n> > why not :-)\n> > \n> > > > +       if (isExternal())\n> > > > +               count = count * 2;\n> > >\n> > > Of course it's hard to know /how/ far to overallocate ... But this will\n> > > do until we figure it out ;-)\n> > \n> > I wonder if we can perhaps allow the cache to grow in size dynamically\n> > instead of relying on a fixed number of slots?\n> \n> That's the bit that I wondered about as the \"better system\" - but it\n> would require a matching number of 'buffers' on the v4l2 side - so\n> dynamically growing the slots would have to interact with the V4L2\n> buffer allcoations I think...\n>\n> I believe we can ask for more buffers some how - but I don't know if we\n> can do so /while/ streaming...\n\nThere's VIDIOC_CREATE_BUFS for that. The question is when to create new\nbuffer slots, as if applications were to create new buffers all the\ntime, the cache would keep growing. We probably need some type of aging\nsystem to decide when a previously cached entry would be old enough to\nbe reused.\n\n> > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > >\n> > > > +\n> > > >         return dev_->importBuffers(count);\n> > > >  }\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 3A0E8BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 11 Nov 2021 14:50:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7CF396035D;\n\tThu, 11 Nov 2021 15:50:12 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3788D600B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Nov 2021 15:50:11 +0100 (CET)","from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BFCADDEE;\n\tThu, 11 Nov 2021 15:50:10 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ZjHtF5c7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636642210;\n\tbh=SdVaqi/vBtONJRPY494p89oDUZhGd8ct0npujgKgYsY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ZjHtF5c76/eBUm1bS+tPSf5a5j4esODlyIW5gmbwTKPcq24y1WkLyBVfJcH952Bfn\n\tShSk2M8hOzKoFmhtp9xal/Bp9GESOmItaeL3VKyOB9yWEyUKMkRZVXuUc5sNEcVjk8\n\t2AtxmSA+myJV3Nt3hsDJ0cC58uC0feudAZ0Srw4o=","Date":"Thu, 11 Nov 2021 16:49:49 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YY0tjdiJrqe0FRkS@pendragon.ideasonboard.com>","References":"<20211110100802.349623-1-naush@raspberrypi.com>\n\t<20211110100802.349623-3-naush@raspberrypi.com>\n\t<163654042246.1896795.11919529052942140004@Monstersaurus>\n\t<CAEmqJPo3JbxioWWc4Gs03vQOC1ihK5Thn+MgaTGXbuJ3-0xM+w@mail.gmail.com>\n\t<163654152299.1911624.13255316081648091656@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<163654152299.1911624.13255316081648091656@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Increase\n\tthe V4L2BufferCache slot allocations","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\tRoman Stratiienko <r.stratiienko@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]