{"id":11299,"url":"https://patchwork.libcamera.org/api/covers/11299/?format=json","web_url":"https://patchwork.libcamera.org/cover/11299/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210216085342.1012717-1-naush@raspberrypi.com>","date":"2021-02-16T08:53:37","name":"[libcamera-devel,v2,0/5] DelayedControls updates and fixes","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"mbox":"https://patchwork.libcamera.org/cover/11299/mbox/","series":[{"id":1694,"url":"https://patchwork.libcamera.org/api/series/1694/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1694","date":"2021-02-16T08:53:37","name":"DelayedControls updates and fixes","version":2,"mbox":"https://patchwork.libcamera.org/series/1694/mbox/"}],"comments":"https://patchwork.libcamera.org/api/covers/11299/comments/","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 98ECBBD1EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Feb 2021 08:53:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0056B637D2;\n\tTue, 16 Feb 2021 09:53:48 +0100 (CET)","from mail-wm1-x334.google.com (mail-wm1-x334.google.com\n\t[IPv6:2a00:1450:4864:20::334])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C65E963762\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Feb 2021 09:53:47 +0100 (CET)","by mail-wm1-x334.google.com with SMTP id a207so485187wmd.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Feb 2021 00:53:47 -0800 (PST)","from naush-laptop.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\te1sm9300369wrd.44.2021.02.16.00.53.46\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 16 Feb 2021 00:53:46 -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=\"Hz7Ce4pk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=VJevRbV+jG1ruVaXqBbKRQQ38klOCSMUCESU8E7hLQg=;\n\tb=Hz7Ce4pki33W0+LTbBb4Z2SwN3egTXorqhnGxSd1eZs4DyYFR5Vm6cjv88d5EJz5c6\n\t/YnkWs53/a1dsswEt8rB2z8xceA3gr6qpA+IxktIvwC6xyeXysRrg6PZ2pGo52jWF9HG\n\tqPgztv9YZWuPUDHGzwI9duFZ4wUjtrm8vUlv+GFuYTgvWum60nJJZgjc+85u+ZtU49Fw\n\tULf3eMz4f86RIpfQKFtfnX8fOyorgCXNjcGqO5a+w2Ttytff936vW3yIv6TfsIffZI0C\n\t4fv8YG+crUEZXVq0/VNBz5ZIhxMwacy/Yz2XlIIrOV3Bw0JbCbOrinznIxyZ5pjpCdp+\n\tmJ+w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=VJevRbV+jG1ruVaXqBbKRQQ38klOCSMUCESU8E7hLQg=;\n\tb=tWFfNHIw/rSRKF7BVBNAAPQSirABc0OoKVzDSN6p25TFDLYKyWt5Fi7yRMFwHNvfni\n\tl9Ahm34Lor0+kNx2keK+h76zpZsquM72x8keUIFNKcfC74TC4v0xTcIuUHsebjM5O+sA\n\tAf/GmXrEIT69uVIqrMCExo/ppLWYdxJG4Z365VQ/bk6O8YonfU8RQ02AnrpZ9aYVRhEH\n\tgk4BezjWvChrV0nqKzG3rHg09NpX3XTd8pZSNIgOlb5zlYMJeAiXNOPMm5VZUu2LojQg\n\t58kjG2+0klzuRN2QIqcIQ9I6c6aihkButCsTUeuoPcw3HC5j3Wdk0m8f2snHQsDfym60\n\t7YjQ==","X-Gm-Message-State":"AOAM531HA2A+RNNnt2oaTjakqqfiA3FTjrbcjXnb6p0FxCsMv2Wg7f9J\n\t49+oQyR3TCI0C2k0Kz0rSrcYXPzb/EvFZ+S+","X-Google-Smtp-Source":"ABdhPJztvZJYgtKpRXQxCY0E05ZPi3JdXMw/DrIdccrleo+knAyHZ/px0EMiujlnL5zmmCb+ZVlIPQ==","X-Received":"by 2002:a05:600c:190f:: with SMTP id\n\tj15mr2352245wmq.174.1613465626897; \n\tTue, 16 Feb 2021 00:53:46 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 16 Feb 2021 08:53:37 +0000","Message-Id":"<20210216085342.1012717-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 0/5] DelayedControls updates and fixes","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Hi,\n\nHere is a revised version of the DelayedControls patch. The only difference between v2 and v1 is in patch 4/5 where the fix was incomplete.  To reiterate, here is a summary of the patches:\n\nPatch 1/5\nThis adds the notion of priority write to fixup the known issue of settings VBLANK and\nEXPOSURE in a single batch.  It is simply a port of the fix applied to StaggeredCtrl\nthat had been reviewed and subsequently deprecated, so hopefully nothing too controversial.\n\nPatch 2/5\nThis is simply a python script that I am using to debug the small problems (more details\nbelow) that we have encountered.  It parses the DelayedControls logs and nicely tabulates\nthe results to show what controls and values have been set/queued/get on each frame.\nThis has helped me tremendously in identifying problems and fixing them.  However, this\nmay not be useful to others, so I am happy to not have this merged if folks do not think\nit is the right place to put it.\n\nPatch 3/5\nFixes a spurious write to the device on startup.  The following is an extract from using\nthe script to parse the logs:\n\nFrame     Action         Gain        Exposure          Vblank\n0         Write         0 [0]          52 [0]         531 [0] <<<<<\n0         Get           0 [0]          52 [0]         531 [0]\n0         Queue       --- [-]         --- [-]         --- [-]\n1         Write         0 [0]         --- [-]         --- [-]\n1         Get           0 [0]          52 [0]         531 [0]\n1         Queue       --- [-]         --- [-]         --- [-]\n2         Write       --- [-]         --- [-]         --- [-]\n2         Get           0 [1]          52 [1]         531 [1]\n2         Queue       192 [4]        1664 [4]         531 [4]\n\nYou can see above, on frame 0 we are writing controls to the sensor, but this is unneeded.\nThis spurious write should really not happen as there is no controls queued by the\npipeline_handler at this point.  This problem is mostly inconsequential.\n\nPatch 4/5\nThis fixes an issue where controls queued by the pipeline handler are delayed by and\nadditional frame when writing.  You can see better in the parsed log:\n\nFrame     Action         Gain        Exposure          Vblank\n2         Write       --- [-]         --- [-]         --- [-]\n2         Get           0 [1]          52 [1]         531 [1]\n2         Queue       192 [4]        1664 [4]         531 [4] <<<<<\n3         Write       --- [-]         --- [-]         --- [-] <<<<<\n3         Get           0 [2]          52 [2]         531 [2]\n3         Queue       192 [5]        1664 [5]         531 [5]\n4         Write       --- [-]        1664 [4]         531 [4] <<<<<\n4         Get           0 [3]          52 [3]         531 [3]\n4         Queue       192 [6]        1664 [6]         531 [6]\n\nOn frame 2, we queue controls from the pipeline handler.  Exposure and Vblank must be\nwritten one frame before gain, so you would expect them to be written on frame 3 as\nnothing else is in the queue.  However, they only get written on frame 4, one frame\nlater than expected.\n\nThis is because of how DelayedControls handles \"no-op\" queue items, i.e. frames where\nwe do not provide the helper with controls to use.  It was adding one more no-op than\nneeded, and causing an extra frame delay when setting the control on the device.\n\nAs a consequence of this change, we must also ensure that controls that have been sent\nto the device must have the update flag cleared or there is a change it may be re-used\nwhen going around the ring buffer. \n\nPatch 5/5\nWe had an off-by-one error when reading back values from the queues.  See the parsed\nlogs below:\n\nFrame     Action         Gain        Exposure          Vblank\n7         Write       192 [6]        1664 [7]         531 [7] <<<<<\n7         Get         192 [6]        1664 [6]         531 [6]\n7         Queue       210 [9]        3174 [9]        1946 [9]\n8         Write       192 [7]        3526 [8]        2298 [8]\n8         Get         192 [7]        1664 [7]         531 [7] <<<<<\n8         Queue       210 [10]       3174 [10]       1946 [10]\n9         Write       213 [8]        3174 [9]        1946 [9]\n9         Get         213 [8]        3526 [8]        2298 [8] <<<<<\n9         Queue       213 [12]       3526 [12]       2298 [12]\n\nOn frame 7, we write exposure and vblank with values 1664 and 531 respectively.  These\nvalues take 2 frames to consume, so should be retuned to the pipeline handler by the\nDelayedControls::get() on frame 9.  However, it returns on frame 8 instead.\n\nThis only causes slight (but visible) oscillations in brightness in the AGC loop as\nthe values used by the sensor are not in lock-step to what is reported by DelayedControls::get().\n\nNaushir Patuck (5):\n  libcamera: delayed_controls: Add notion of priority write\n  utils: raspberrypi: Add a DelayedControls log parser\n  libcamera: delayed_controls: Remove unneeded write when starting up\n  libcamera: delayed_controls: Remove spurious no-op queued controls\n  libcamera: delayed_controls: Fix off-by-one error in get()\n\n include/libcamera/internal/delayed_controls.h | 13 ++-\n src/libcamera/delayed_controls.cpp            | 79 ++++++++++-----\n src/libcamera/pipeline/ipu3/ipu3.cpp          |  8 +-\n .../pipeline/raspberrypi/raspberrypi.cpp      | 13 ++-\n src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  8 +-\n test/delayed_contols.cpp                      | 20 ++--\n utils/raspberrypi/delayedctrls_parse.py       | 98 +++++++++++++++++++\n 7 files changed, 183 insertions(+), 56 deletions(-)\n create mode 100644 utils/raspberrypi/delayedctrls_parse.py"}