{"id":11253,"url":"https://patchwork.libcamera.org/api/covers/11253/?format=json","web_url":"https://patchwork.libcamera.org/cover/11253/","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":"<20210212113312.239076-1-naush@raspberrypi.com>","date":"2021-02-12T11:33:07","name":"[libcamera-devel,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/11253/mbox/","series":[{"id":1683,"url":"https://patchwork.libcamera.org/api/series/1683/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1683","date":"2021-02-12T11:33:07","name":"DelayedControls updates and fixes","version":1,"mbox":"https://patchwork.libcamera.org/series/1683/mbox/"}],"comments":"https://patchwork.libcamera.org/api/covers/11253/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 2DFACBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 12 Feb 2021 11:37:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 667DC63776;\n\tFri, 12 Feb 2021 12:37:33 +0100 (CET)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D560B6376F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Feb 2021 12:37:31 +0100 (CET)","by mail-wm1-x32c.google.com with SMTP id y134so653508wmd.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Feb 2021 03:37:31 -0800 (PST)","from naush-laptop.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tv5sm10005020wro.71.2021.02.12.03.37.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 12 Feb 2021 03:37:30 -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=\"lq+06Qyg\"; 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=0qhb53j9t0gM4sA8vnT7g+jOOUA5U3dRZj1Rfci4bIU=;\n\tb=lq+06Qyg1aOKCHuICq494ZpzkX7oW7r0ti2WWiOtZwBZwy1uOAUcEHoQHcHVdb2fHE\n\tQkycBeviYUXLdxqygP2EgoMvT7NA9HBJWBwj/G9eso0zLWOUj07+jT5yOKhoi1EvByh5\n\tqatXDD9AI2eVpZ5R03qqCuU992P2baVowZPcURjzuyknLYnx94b6znC/mgnRtFI9JplT\n\tqaZls/bwSFYaWzwEGXfMWsEzv34IhqH87HGMVtjSoQL4UwFGBSCLlXex4WkRNuFN1KFH\n\t9v8RFexvjBkWhwYbtNBYMohEMaEzzuvU/DugWpmPmJdvJtHC1hm1Kl+d6aFUvfOnu62n\n\tm1zg==","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=0qhb53j9t0gM4sA8vnT7g+jOOUA5U3dRZj1Rfci4bIU=;\n\tb=RbYL3VCWkx7wd+C9E+GQk9TsEBq+v7bsBs6i1fzHPE5DvBSfCcSENK78kwUT4EnW7Q\n\tlygDnL+vbqoTJzTEhBW6cj47OauMoxew6Uygu3HlLUhlk9WjurFdO09pPAVe53vEpe/4\n\t+xa9vY6ndg7bvLFazkULL8IsY5/xqKGSR3rVjKClKjmFtXz6N45yO+G8psbX5eQk2CzP\n\tkD/Kc/S2UkcxxjcrCdlTw47SvKGG2smAT+7NQJjrg4rNTtwEqZgDQkTQjXDMYFz93nK0\n\tTS2QyQtn2BFMT7jYQ3SKVYxZG0m/cgYqScSWP/6Goru4/odzavRhmjejNU5NSR/kCwrg\n\tzUPw==","X-Gm-Message-State":"AOAM531QL+DBVzWUQ9HkuQ48poOwgPdD/HAHAQ+jNH2g93+E0Q/JyobJ\n\t3WCu38GuW4mt7pq5rw8aBesVVgcsTHUOgQuU","X-Google-Smtp-Source":"ABdhPJxI27fHa5EICCUrQ+9MD105RojGYQhj+vh+jMiCZJfqjjy6HSzC9RP2NqN0jW2WcMB53LYqOA==","X-Received":"by 2002:a1c:29c4:: with SMTP id p187mr2130004wmp.8.1613129851065;\n\tFri, 12 Feb 2021 03:37:31 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 12 Feb 2021 11:33:07 +0000","Message-Id":"<20210212113312.239076-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 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 all,\n\nThis patchset mainly addresses some minor issues we have encountered with DelayedControls\nwhen running on the Raspberry Pi platform.  Apologies for the slightly long cover letter,\nbut I wanted to explain the problems we are seeing in a bit of detail :-)\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.  It is, however, mostly inconsequential at runtime.\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\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\nHope that is all reasonably well explained :-)  Any questions, please do shout.\n\nRegards,\nNaush\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            | 72 ++++++++++------\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       | 82 +++++++++++++++++++\n 7 files changed, 162 insertions(+), 54 deletions(-)\n create mode 100644 utils/raspberrypi/delayedctrls_parse.py"}