[{"id":29723,"web_url":"https://patchwork.libcamera.org/comment/29723/","msgid":"<9007f71e-23b5-4e0a-839e-9fdc21bb272d@ideasonboard.com>","date":"2024-06-01T22:13:49","subject":"Re: [PATCH v2 3/6] test: fence: Fix race condition","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Laurent - thanks for the patch\n\nOn 29/05/2024 16:43, Laurent Pinchart wrote:\n> The fence test is racy, as it relies on the main loop being executed\n> between completion of request signalledRequestId_ and\n> signalledRequestId_ + 1. This usually happens, but is not guaranteed.\n>\n> To fix the race condition, change the request identification logic by\n> replacing usage of the cookie value, which is zero-based and wraps\n> around at nbuffers_ - 1, with a completed request counter that is\n> one-based and doesn't wrap. The completedRequestId_, expiredRequestId_\n> and signalledRequestId_ variables now track the identifier of the last\n> request that has completed, the request whose fence will time out, and\n> the request whose fence will be signalled.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nTook me a while to wrap my head around it, but I think it's fine:\n\n\nDaniel Scally <dan.scally@ideasonboard.com>\n\n> ---\n> Changes since v1:\n>\n> - Add and update comments\n> - Fix typo in commit message\n> ---\n>   test/fence.cpp | 57 +++++++++++++++++++++++++++++++-------------------\n>   1 file changed, 36 insertions(+), 21 deletions(-)\n>\n> diff --git a/test/fence.cpp b/test/fence.cpp\n> index c282886287aa..a8fba7284d82 100644\n> --- a/test/fence.cpp\n> +++ b/test/fence.cpp\n> @@ -57,8 +57,11 @@ private:\n>   \tbool expectedCompletionResult_ = true;\n>   \tbool setFence_ = true;\n>   \n> -\tunsigned int completedRequest_;\n> -\n> +\t/*\n> +\t * Request IDs track the number of requests that have completed. They\n> +\t * are one-based, and don't wrap.\n> +\t */\n> +\tunsigned int completedRequestId_;\n>   \tunsigned int signalledRequestId_;\n>   \tunsigned int expiredRequestId_;\n>   \tunsigned int nbuffers_;\n> @@ -126,8 +129,19 @@ int FenceTest::init()\n>   \t\treturn TestFail;\n>   \t}\n>   \n> -\tsignalledRequestId_ = nbuffers_ - 2;\n> -\texpiredRequestId_ = nbuffers_ - 1;\n> +\tcompletedRequestId_ = 0;\n> +\n> +\t/*\n> +\t * All but two requests are queued without a fence. Request\n> +\t * expiredRequestId_ will be queued with a fence that we won't signal\n> +\t * (which is then expected to expire), and request signalledRequestId_\n> +\t * will be queued with a fence that gets signalled. Select nbuffers_\n> +\t * and nbuffers_ * 2 for those two requests, to space them by a few\n> +\t * frames while still not requiring a long time for the test to\n> +\t * complete.\n> +\t */\n> +\texpiredRequestId_ = nbuffers_;\n> +\tsignalledRequestId_ = nbuffers_ * 2;\n>   \n>   \treturn TestPass;\n>   }\n> @@ -189,16 +203,16 @@ void FenceTest::requestRequeue(Request *request)\n>   \tconst Request::BufferMap &buffers = request->buffers();\n>   \tconst Stream *stream = buffers.begin()->first;\n>   \tFrameBuffer *buffer = buffers.begin()->second;\n> -\tuint64_t cookie = request->cookie();\n>   \n>   \trequest->reuse();\n>   \n> -\tif (cookie == signalledRequestId_ && setFence_) {\n> +\tif (completedRequestId_ == signalledRequestId_ - nbuffers_ && setFence_) {\n>   \t\t/*\n> -\t\t * The second time this request is queued add a fence to it.\n> -\t\t *\n> -\t\t * The main loop signals it by using a timer to write to the\n> -\t\t * efd2_ file descriptor before the fence expires.\n> +\t\t * This is the request that will be used to test fence\n> +\t\t * signalling when it completes next time. Add a fence to it,\n> +\t\t * using efd2_. The main loop will signal the fence by using a\n> +\t\t * timer to write to the efd2_ file descriptor before the fence\n> +\t\t * expires.\n>   \t\t */\n>   \t\tstd::unique_ptr<Fence> fence =\n>   \t\t\tstd::make_unique<Fence>(std::move(eventFd2_));\n> @@ -213,16 +227,15 @@ void FenceTest::requestRequeue(Request *request)\n>   \n>   void FenceTest::requestComplete(Request *request)\n>   {\n> -\tuint64_t cookie = request->cookie();\n> -\tcompletedRequest_ = cookie;\n> +\tcompletedRequestId_++;\n>   \n>   \t/*\n> -\t * The last request is expected to fail as its fence has not been\n> -\t * signaled.\n> +\t * Request expiredRequestId_ is expected to fail as its fence has not\n> +\t * been signalled.\n>   \t *\n>   \t * Validate the fence status but do not re-queue it.\n>   \t */\n> -\tif (cookie == expiredRequestId_) {\n> +\tif (completedRequestId_ == expiredRequestId_) {\n>   \t\tif (validateExpiredRequest(request) != TestPass)\n>   \t\t\texpectedCompletionResult_ = false;\n>   \n> @@ -230,7 +243,7 @@ void FenceTest::requestComplete(Request *request)\n>   \t\treturn;\n>   \t}\n>   \n> -\t/* Validate all requests but the last. */\n> +\t/* Validate all other requests. */\n>   \tif (validateRequest(request) != TestPass) {\n>   \t\texpectedCompletionResult_ = false;\n>   \n> @@ -271,7 +284,7 @@ int FenceTest::run()\n>   \t\t}\n>   \n>   \t\tint ret;\n> -\t\tif (i == expiredRequestId_) {\n> +\t\tif (i == expiredRequestId_ - 1) {\n>   \t\t\t/* This request will have a fence, and it will expire. */\n>   \t\t\tstd::unique_ptr<Fence> fence =\n>   \t\t\t\tstd::make_unique<Fence>(std::move(eventFd_));\n> @@ -318,11 +331,13 @@ int FenceTest::run()\n>   \tTimer timer;\n>   \ttimer.start(1000ms);\n>   \twhile (timer.isRunning() && expectedCompletionResult_) {\n> -\t\tif (completedRequest_ == signalledRequestId_ && setFence_)\n> +\t\tif (completedRequestId_ == signalledRequestId_ - 1 && setFence_)\n>   \t\t\t/*\n> -\t\t\t * signalledRequestId_ has just completed and it has\n> -\t\t\t * been re-queued with a fence. Start the timer to\n> -\t\t\t * signal the fence in 10 msec.\n> +\t\t\t * The request just before signalledRequestId_ has just\n> +\t\t\t * completed. Request signalledRequestId_ has been\n> +\t\t\t * queued with a fence, and libcamera is likely already\n> +\t\t\t * waiting on the fence, or will soon. Start the timer\n> +\t\t\t * to signal the fence in 10 msec.\n>   \t\t\t */\n>   \t\t\tfenceTimer.start(10ms);\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 F3A75BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Jun 2024 22:13:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 25FB8634BA;\n\tSun,  2 Jun 2024 00:13:55 +0200 (CEST)","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 B361861A46\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  2 Jun 2024 00:13:52 +0200 (CEST)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B00BB4CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  2 Jun 2024 00:13:46 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"nRZKSkTZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1717280026;\n\tbh=QPEuOfAmqT01HQXTzmLh0PClFJ6ScbcWZF4DHNJYEgY=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=nRZKSkTZ9wg2iK5xZaxfsER93hzhyID7cs79xcokfGmdXMH9d5AOjcdZN7L9q2sNY\n\tVZC1Wjx6ysSyjfwJ82j6WpPzHSfTehpwm2pERTxgFyd24RNgDw7wlXKdSfgoGN7utk\n\t0ZV52dJqGWbsnJEknNpFsH1lGteKSe/oljV8jP18=","Message-ID":"<9007f71e-23b5-4e0a-839e-9fdc21bb272d@ideasonboard.com>","Date":"Sat, 1 Jun 2024 23:13:49 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 3/6] test: fence: Fix race condition","To":"libcamera-devel@lists.libcamera.org","References":"<20240529154341.10426-1-laurent.pinchart@ideasonboard.com>\n\t<20240529154341.10426-4-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","Autocrypt":"addr=dan.scally@ideasonboard.com; keydata=\n\txsFNBGLydlEBEADa5O2s0AbUguprfvXOQun/0a8y2Vk6BqkQALgeD6KnXSWwaoCULp18etYW\n\tB31bfgrdphXQ5kUQibB0ADK8DERB4wrzrUb5CMxLBFE7mQty+v5NsP0OFNK9XTaAOcmD+Ove\n\teIjYvqurAaro91jrRVrS1gBRxIFqyPgNvwwL+alMZhn3/2jU2uvBmuRrgnc/e9cHKiuT3Dtq\n\tMHGPKL2m+plk+7tjMoQFfexoQ1JKugHAjxAhJfrkXh6uS6rc01bYCyo7ybzg53m1HLFJdNGX\n\tsUKR+dQpBs3SY4s66tc1sREJqdYyTsSZf80HjIeJjU/hRunRo4NjRIJwhvnK1GyjOvvuCKVU\n\tRWpY8dNjNu5OeAfdrlvFJOxIE9M8JuYCQTMULqd1NuzbpFMjc9524U3Cngs589T7qUMPb1H1\n\tNTA81LmtJ6Y+IV5/kiTUANflpzBwhu18Ok7kGyCq2a2jsOcVmk8gZNs04gyjuj8JziYwwLbf\n\tvzABwpFVcS8aR+nHIZV1HtOzyw8CsL8OySc3K9y+Y0NRpziMRvutrppzgyMb9V+N31mK9Mxl\n\t1YkgaTl4ciNWpdfUe0yxH03OCuHi3922qhPLF4XX5LN+NaVw5Xz2o3eeWklXdouxwV7QlN33\n\tu4+u2FWzKxDqO6WLQGjxPE0mVB4Gh5Pa1Vb0ct9Ctg0qElvtGQARAQABzShEYW4gU2NhbGx5\n\tIDxkYW4uc2NhbGx5QGlkZWFzb25ib2FyZC5jb20+wsGNBBMB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KM\n\tyMcoUWrTK0Uz6UzUGKoJVbxmSW/EJLEGoI5p3NWxWtScEVv8mO49gqQdrRIOheZycDmHnItt\n\t9Qjv00uFhEwv2YfiyGk6iGF2W40s2pH2t6oeuGgmiZ7g6d0MEK8Ql/4zPItvr1c1rpwpXUC1\n\tu1kQWgtnNjFHX3KiYdqjcZeRBiry1X0zY+4Y24wUU0KsEewJwjhmCKAsju1RpdlPg2kC","In-Reply-To":"<20240529154341.10426-4-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":29738,"web_url":"https://patchwork.libcamera.org/comment/29738/","msgid":"<171740451023.1000377.3565447349880422935@ping.linuxembedded.co.uk>","date":"2024-06-03T08:48:30","subject":"Re: [PATCH v2 3/6] test: fence: Fix race condition","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2024-05-29 16:43:38)\n> The fence test is racy, as it relies on the main loop being executed\n> between completion of request signalledRequestId_ and\n> signalledRequestId_ + 1. This usually happens, but is not guaranteed.\n> \n> To fix the race condition, change the request identification logic by\n> replacing usage of the cookie value, which is zero-based and wraps\n> around at nbuffers_ - 1, with a completed request counter that is\n> one-based and doesn't wrap. The completedRequestId_, expiredRequestId_\n> and signalledRequestId_ variables now track the identifier of the last\n> request that has completed, the request whose fence will time out, and\n> the request whose fence will be signalled.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Changes since v1:\n> \n> - Add and update comments\n> - Fix typo in commit message\n> ---\n>  test/fence.cpp | 57 +++++++++++++++++++++++++++++++-------------------\n>  1 file changed, 36 insertions(+), 21 deletions(-)\n> \n> diff --git a/test/fence.cpp b/test/fence.cpp\n> index c282886287aa..a8fba7284d82 100644\n> --- a/test/fence.cpp\n> +++ b/test/fence.cpp\n> @@ -57,8 +57,11 @@ private:\n>         bool expectedCompletionResult_ = true;\n>         bool setFence_ = true;\n>  \n> -       unsigned int completedRequest_;\n> -\n> +       /*\n> +        * Request IDs track the number of requests that have completed. They\n> +        * are one-based, and don't wrap.\n> +        */\n> +       unsigned int completedRequestId_;\n>         unsigned int signalledRequestId_;\n>         unsigned int expiredRequestId_;\n>         unsigned int nbuffers_;\n> @@ -126,8 +129,19 @@ int FenceTest::init()\n>                 return TestFail;\n>         }\n>  \n> -       signalledRequestId_ = nbuffers_ - 2;\n> -       expiredRequestId_ = nbuffers_ - 1;\n> +       completedRequestId_ = 0;\n> +\n> +       /*\n> +        * All but two requests are queued without a fence. Request\n> +        * expiredRequestId_ will be queued with a fence that we won't signal\n> +        * (which is then expected to expire), and request signalledRequestId_\n> +        * will be queued with a fence that gets signalled. Select nbuffers_\n> +        * and nbuffers_ * 2 for those two requests, to space them by a few\n> +        * frames while still not requiring a long time for the test to\n> +        * complete.\n> +        */\n> +       expiredRequestId_ = nbuffers_;\n> +       signalledRequestId_ = nbuffers_ * 2;\n\nThank you - that's /far/ clearer as to what's going on now and why\nthere's a * 2.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  \n>         return TestPass;\n>  }\n> @@ -189,16 +203,16 @@ void FenceTest::requestRequeue(Request *request)\n>         const Request::BufferMap &buffers = request->buffers();\n>         const Stream *stream = buffers.begin()->first;\n>         FrameBuffer *buffer = buffers.begin()->second;\n> -       uint64_t cookie = request->cookie();\n>  \n>         request->reuse();\n>  \n> -       if (cookie == signalledRequestId_ && setFence_) {\n> +       if (completedRequestId_ == signalledRequestId_ - nbuffers_ && setFence_) {\n>                 /*\n> -                * The second time this request is queued add a fence to it.\n> -                *\n> -                * The main loop signals it by using a timer to write to the\n> -                * efd2_ file descriptor before the fence expires.\n> +                * This is the request that will be used to test fence\n> +                * signalling when it completes next time. Add a fence to it,\n> +                * using efd2_. The main loop will signal the fence by using a\n> +                * timer to write to the efd2_ file descriptor before the fence\n> +                * expires.\n>                  */\n>                 std::unique_ptr<Fence> fence =\n>                         std::make_unique<Fence>(std::move(eventFd2_));\n> @@ -213,16 +227,15 @@ void FenceTest::requestRequeue(Request *request)\n>  \n>  void FenceTest::requestComplete(Request *request)\n>  {\n> -       uint64_t cookie = request->cookie();\n> -       completedRequest_ = cookie;\n> +       completedRequestId_++;\n>  \n>         /*\n> -        * The last request is expected to fail as its fence has not been\n> -        * signaled.\n> +        * Request expiredRequestId_ is expected to fail as its fence has not\n> +        * been signalled.\n>          *\n>          * Validate the fence status but do not re-queue it.\n>          */\n> -       if (cookie == expiredRequestId_) {\n> +       if (completedRequestId_ == expiredRequestId_) {\n>                 if (validateExpiredRequest(request) != TestPass)\n>                         expectedCompletionResult_ = false;\n>  \n> @@ -230,7 +243,7 @@ void FenceTest::requestComplete(Request *request)\n>                 return;\n>         }\n>  \n> -       /* Validate all requests but the last. */\n> +       /* Validate all other requests. */\n>         if (validateRequest(request) != TestPass) {\n>                 expectedCompletionResult_ = false;\n>  \n> @@ -271,7 +284,7 @@ int FenceTest::run()\n>                 }\n>  \n>                 int ret;\n> -               if (i == expiredRequestId_) {\n> +               if (i == expiredRequestId_ - 1) {\n>                         /* This request will have a fence, and it will expire. */\n>                         std::unique_ptr<Fence> fence =\n>                                 std::make_unique<Fence>(std::move(eventFd_));\n> @@ -318,11 +331,13 @@ int FenceTest::run()\n>         Timer timer;\n>         timer.start(1000ms);\n>         while (timer.isRunning() && expectedCompletionResult_) {\n> -               if (completedRequest_ == signalledRequestId_ && setFence_)\n> +               if (completedRequestId_ == signalledRequestId_ - 1 && setFence_)\n>                         /*\n> -                        * signalledRequestId_ has just completed and it has\n> -                        * been re-queued with a fence. Start the timer to\n> -                        * signal the fence in 10 msec.\n> +                        * The request just before signalledRequestId_ has just\n> +                        * completed. Request signalledRequestId_ has been\n> +                        * queued with a fence, and libcamera is likely already\n> +                        * waiting on the fence, or will soon. Start the timer\n> +                        * to signal the fence in 10 msec.\n>                          */\n>                         fenceTimer.start(10ms);\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\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 E8CC6BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  3 Jun 2024 08:48:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA951634CA;\n\tMon,  3 Jun 2024 10:48:33 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1867D61A3B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Jun 2024 10:48:33 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1D601B53;\n\tMon,  3 Jun 2024 10:48:26 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"cxm8Yb6c\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1717404506;\n\tbh=ynX096Zrk/FO5HsrNcUp2eNly7n2fftrD6l90wIKt/0=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=cxm8Yb6croSut2LtSRCD5O4tLnMkBiGBaYjsjGwZECN96P6MpLOrPGHFmlnM0WEBB\n\to716+vzY38Ty4ZBb4GDUhsXsb3wVVHuKeAymx6CtgopJ44UWlnXLfoyAWQbVEwtXpR\n\tmnQV0oRhmvkomVHHhIZK7QaX5G+rjhHvNTpv6aXQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240529154341.10426-4-laurent.pinchart@ideasonboard.com>","References":"<20240529154341.10426-1-laurent.pinchart@ideasonboard.com>\n\t<20240529154341.10426-4-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v2 3/6] test: fence: Fix race condition","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 03 Jun 2024 09:48:30 +0100","Message-ID":"<171740451023.1000377.3565447349880422935@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]