[{"id":22381,"web_url":"https://patchwork.libcamera.org/comment/22381/","msgid":"<Yjp23Y9R1SNSH/sM@pendragon.ideasonboard.com>","date":"2022-03-23T01:24:45","subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: ipu3: af: Remove redundant\n\tmemcpy","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Mar 15, 2022 at 05:53:45PM +0000, Kieran Bingham via libcamera-devel wrote:\n> The af statistics can be accessed directly from the mapped buffer.\n> Remove the redundant memcpy, and simplify the call to\n> afEstimateVariance().\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/af.cpp | 12 ++++--------\n>  src/ipa/ipu3/algorithms/af.h   |  2 +-\n>  2 files changed, 5 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n> index 469762a29937..e10cff968895 100644\n> --- a/src/ipa/ipu3/algorithms/af.cpp\n> +++ b/src/ipa/ipu3/algorithms/af.cpp\n> @@ -336,7 +336,7 @@ void Af::afIgnoreFrameReset()\n>   *\n>   * \\return The variance of the values in the data set \\a y_item selected by \\a isY1\n>   */\n> -double Af::afEstimateVariance(y_table_item_t *y_item, uint32_t len,\n> +double Af::afEstimateVariance(const y_table_item_t *y_item, uint32_t len,\n>  \t\t\t      bool isY1)\n\nNot a candidate for this patch, but pointer + len immediately makes me\nthink the Span class should be used instead.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  {\n>  \tuint32_t z = 0;\n> @@ -406,25 +406,21 @@ bool Af::afIsOutOfFocus(IPAContext context)\n>   */\n>  void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n>  {\n> -\ty_table_item_t y_item[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE / sizeof(y_table_item_t)];\n> +\tconst y_table_item_t *y_item = reinterpret_cast<const y_table_item_t *>(&stats->af_raw_buffer.y_table);\n>  \tuint32_t afRawBufferLen;\n>  \n>  \t/* Evaluate the AF buffer length */\n>  \tafRawBufferLen = context.configuration.af.afGrid.width *\n>  \t\t\t context.configuration.af.afGrid.height;\n>  \n> -\tmemcpy(y_item, stats->af_raw_buffer.y_table,\n> -\t       afRawBufferLen * sizeof(y_table_item_t));\n> +\tASSERT(afRawBufferLen / sizeof(y_table_item_t) < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE);\n>  \n>  \t/*\n>  \t * Calculate the mean and the variance of AF statistics for a given grid.\n>  \t * For coarse: y1 are used.\n>  \t * For fine: y2 results are used.\n>  \t */\n> -\tif (coarseCompleted_)\n> -\t\tcurrentVariance_ = afEstimateVariance(y_item, afRawBufferLen, false);\n> -\telse\n> -\t\tcurrentVariance_ = afEstimateVariance(y_item, afRawBufferLen, true);\n> +\tcurrentVariance_ = afEstimateVariance(y_item, afRawBufferLen, !coarseCompleted_);\n>  \n>  \tif (!context.frameContext.af.stable) {\n>  \t\tafCoarseScan(context);\n> diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h\n> index 906f2843dd49..3b5758e868ea 100644\n> --- a/src/ipa/ipu3/algorithms/af.h\n> +++ b/src/ipa/ipu3/algorithms/af.h\n> @@ -41,7 +41,7 @@ private:\n>  \tvoid afReset(IPAContext &context);\n>  \tbool afNeedIgnoreFrame();\n>  \tvoid afIgnoreFrameReset();\n> -\tdouble afEstimateVariance(y_table_item_t *y_item, uint32_t len,\n> +\tdouble afEstimateVariance(const y_table_item_t *y_item, uint32_t len,\n>  \t\t\t\t  bool isY1);\n>  \tbool afIsOutOfFocus(IPAContext context);\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 6ADCDC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Mar 2022 01:25:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7FDFE604DB;\n\tWed, 23 Mar 2022 02:25:05 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C2608604C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Mar 2022 02:25:03 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 38BF79DE;\n\tWed, 23 Mar 2022 02:25:03 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647998705;\n\tbh=Tc04dPe6WQJPezf56XvfdurUH07Mt+YtADIArWwW+Gw=;\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=lOJxPYmbiv0roSna5t8cPxU1kxRltZpVR6Qc3PBquStaghssFaYt6dA8WWAQsJYgI\n\tM7bHq5zN1tM2arXdl5yCAZmoajE1446pysYmNN//vENoeuoGZQRTYt7Mn3+P+7JREM\n\tyFcSomwX5j50M1WeH7Wf5UR8ZW2DMf8vyhBTN0JFoC4IEz4qY9L0yGEwXcN0eHr2Xx\n\t3GnHe3Vlx3zg7Iz9N4c/YGVg0WaXb/nw76Sc/Gh3VeMJ7jvqMIo77Lxs6dLYAJRQej\n\t1pPcOYk54Le++8BEDhibTrO3b8aB2sDCyTTKTVkO6SQsr0LNSwLlR+GaEM00aVkDjk\n\tCL7SeM6GzdzOA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1647998703;\n\tbh=Tc04dPe6WQJPezf56XvfdurUH07Mt+YtADIArWwW+Gw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qF4ev3afg+876NKMD5CVq6GVRbEnXKy6IxtCYgV7VJJ+lR9dcrbEIo2Oe+gdqB40T\n\tkLkUtkn44msFIDBou94oSEsx0f7fsId5Pgmo3dYYCJstFI/Cn5a01kURXEjREbWC87\n\tDhwOuwOqR6mfhcfbD35FNli8giU0MTLMaPehIeW0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"qF4ev3af\"; dkim-atps=neutral","Date":"Wed, 23 Mar 2022 03:24:45 +0200","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<Yjp23Y9R1SNSH/sM@pendragon.ideasonboard.com>","References":"<20220315175345.479951-1-kieran.bingham@ideasonboard.com>\n\t<20220315175345.479951-4-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220315175345.479951-4-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: ipu3: af: Remove redundant\n\tmemcpy","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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":22403,"web_url":"https://patchwork.libcamera.org/comment/22403/","msgid":"<164803357756.2130830.7322540828803028118@Monstersaurus>","date":"2022-03-23T11:06:17","subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: ipu3: af: Remove redundant\n\tmemcpy","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2022-03-23 01:24:45)\n> Hi Kieran,\n> \n> Thank you for the patch.\n> \n> On Tue, Mar 15, 2022 at 05:53:45PM +0000, Kieran Bingham via libcamera-devel wrote:\n> > The af statistics can be accessed directly from the mapped buffer.\n> > Remove the redundant memcpy, and simplify the call to\n> > afEstimateVariance().\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >  src/ipa/ipu3/algorithms/af.cpp | 12 ++++--------\n> >  src/ipa/ipu3/algorithms/af.h   |  2 +-\n> >  2 files changed, 5 insertions(+), 9 deletions(-)\n> > \n> > diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n> > index 469762a29937..e10cff968895 100644\n> > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > @@ -336,7 +336,7 @@ void Af::afIgnoreFrameReset()\n> >   *\n> >   * \\return The variance of the values in the data set \\a y_item selected by \\a isY1\n> >   */\n> > -double Af::afEstimateVariance(y_table_item_t *y_item, uint32_t len,\n> > +double Af::afEstimateVariance(const y_table_item_t *y_item, uint32_t len,\n> >                             bool isY1)\n> \n> Not a candidate for this patch, but pointer + len immediately makes me\n> think the Span class should be used instead.\n\nI agree, I think the Span would help improve the iterators in here too.\nWill do on top.\n\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> >  {\n> >       uint32_t z = 0;\n> > @@ -406,25 +406,21 @@ bool Af::afIsOutOfFocus(IPAContext context)\n> >   */\n> >  void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n> >  {\n> > -     y_table_item_t y_item[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE / sizeof(y_table_item_t)];\n> > +     const y_table_item_t *y_item = reinterpret_cast<const y_table_item_t *>(&stats->af_raw_buffer.y_table);\n> >       uint32_t afRawBufferLen;\n> >  \n> >       /* Evaluate the AF buffer length */\n> >       afRawBufferLen = context.configuration.af.afGrid.width *\n> >                        context.configuration.af.afGrid.height;\n> >  \n> > -     memcpy(y_item, stats->af_raw_buffer.y_table,\n> > -            afRawBufferLen * sizeof(y_table_item_t));\n> > +     ASSERT(afRawBufferLen / sizeof(y_table_item_t) < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE);\n\nLooking at \ninclude/linux/intel-ipu3.h:     __u8 y_table[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE] __attribute__((aligned(32)));\n\nIPU3_UAPI_AF_Y_TABLE_MAX_SIZE is the maximum number of entries of y_table_item_t\n\nSo I think this ASSERT is wrong, and should be:\n\n\tASSERT(afRawBufferLen < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE);\n\n> >  \n> >       /*\n> >        * Calculate the mean and the variance of AF statistics for a given grid.\n> >        * For coarse: y1 are used.\n> >        * For fine: y2 results are used.\n> >        */\n> > -     if (coarseCompleted_)\n> > -             currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, false);\n> > -     else\n> > -             currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, true);\n> > +     currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, !coarseCompleted_);\n> >  \n> >       if (!context.frameContext.af.stable) {\n> >               afCoarseScan(context);\n> > diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h\n> > index 906f2843dd49..3b5758e868ea 100644\n> > --- a/src/ipa/ipu3/algorithms/af.h\n> > +++ b/src/ipa/ipu3/algorithms/af.h\n> > @@ -41,7 +41,7 @@ private:\n> >       void afReset(IPAContext &context);\n> >       bool afNeedIgnoreFrame();\n> >       void afIgnoreFrameReset();\n> > -     double afEstimateVariance(y_table_item_t *y_item, uint32_t len,\n> > +     double afEstimateVariance(const y_table_item_t *y_item, uint32_t len,\n> >                                 bool isY1);\n> >       bool afIsOutOfFocus(IPAContext context);\n> >  \n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","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 8B68EC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Mar 2022 11:06:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B5E15604C4;\n\tWed, 23 Mar 2022 12:06:22 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 95687604C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Mar 2022 12:06:20 +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 2FEBB9DE;\n\tWed, 23 Mar 2022 12:06:20 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648033582;\n\tbh=Iu1z1pjKGSS4CA0puQ1RCIAYh3CaeH101GinKWJ0ab4=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=VnwxAiYYirFwqZm1YdUbf+cGMts3NIFTG7mge7f4s40y3HS6nDI1ppJo5Hmpq8GKg\n\t0ZeJP6fVvRty8kS8ucV4tXtWFjPUXA8aXm4aupbNhVfUcFY81xAqtmglGdCBULLXMO\n\tEtlfUHD4Z2hznqcp9rF0drBJ+Lbr6Gxv9hHU3qyp9a7djs6UmEx15Fg10qaQcxaMZq\n\tvb9Zi6LE3Z+AKKtgN3gPOsWYh/fRcBtBPaO3R9kUNz2sg/HCY2N07O/XzdbXfuospt\n\tThFrMiLYkHWS3FEWpMNvxZhOLKJB9XIX6PHNgMxYnEk7wHZDyWni6EDfRjjrtjgmm8\n\t8VYwH4XJiuEqA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648033580;\n\tbh=Iu1z1pjKGSS4CA0puQ1RCIAYh3CaeH101GinKWJ0ab4=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=XyxMrLIg23T9Y1fHzc0/1dUxUoPydwNmx3/oTjY4l8L09/FJ8touCc6UuosocXLTT\n\tncmyZ+CS25Qo8kvs8rVrBg2z1BhR2MwfLnTz6kf8QunorPw7aF0KuokyMKd+dyhyJp\n\tFSkhsvcgnBnQbvs//I1XA49L08R1IjuD3ZDGhX2g="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"XyxMrLIg\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<Yjp23Y9R1SNSH/sM@pendragon.ideasonboard.com>","References":"<20220315175345.479951-1-kieran.bingham@ideasonboard.com>\n\t<20220315175345.479951-4-kieran.bingham@ideasonboard.com>\n\t<Yjp23Y9R1SNSH/sM@pendragon.ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Date":"Wed, 23 Mar 2022 11:06:17 +0000","Message-ID":"<164803357756.2130830.7322540828803028118@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH 3/3] ipa: ipu3: af: Remove redundant\n\tmemcpy","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","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>"}}]