Patch Detail
Show a patch.
GET /api/patches/26674/?format=api
{ "id": 26674, "url": "https://patchwork.libcamera.org/api/patches/26674/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26674/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260507125458.12140-4-david.plowman@raspberrypi.com>", "date": "2026-05-07T12:20:36", "name": "[v4,3/3] pipeline: rpi: Make control lists in requests properly atomic", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "fa92733d066ab4eb4a44b6cab806722da0cc59e7", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26674/mbox/", "series": [ { "id": 5917, "url": "https://patchwork.libcamera.org/api/series/5917/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5917", "date": "2026-05-07T12:20:33", "name": "Atomic control lists on Raspberry Pi", "version": 4, "mbox": "https://patchwork.libcamera.org/series/5917/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26674/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26674/checks/", "tags": {}, "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 1CD34C32F8\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 7 May 2026 12:55:10 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D26656301E;\n\tThu, 7 May 2026 14:55:08 +0200 (CEST)", "from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EEC8662010\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 7 May 2026 14:55:03 +0200 (CEST)", "by mail-wm1-x32e.google.com with SMTP id\n\t5b1f17b1804b1-48a7fe4f40bso9326305e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 07 May 2026 05:55:03 -0700 (PDT)", "from davidp-pi5.pitowers.org\n\t([2a00:1098:3142:1f:88ea:c658:5b20:5e46])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-450524833e1sm20396324f8f.2.2026.05.07.05.55.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 07 May 2026 05:55:02 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"QAQeXgLB\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1778158503; x=1778763303;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=7qXhgolOuJk656ES/U26gIkNoakVkmPr3O4bl7zAoi4=;\n\tb=QAQeXgLBt1B4CGCOVEmQsoj67ezSqHZfhMC1kLQkLMDhbCUjDFLcyUo96QkdDBKFov\n\tTrXJ0spUDaG+zupzMpmFrR6Zyn5e5ikUKe7qFHo913C3jOEB8yQTIvenMuZaik7+vcg4\n\ti2JHbf8gIx2iGZA4vEfA1LqtbNirPCd0GDaGTdfzVPsJLdH5jDmxK1tpfP80SxHfyHKZ\n\tzZMan8Qo+Fz2ShPGJxqWvmbhIAisA2X5Cwu526+4YiV8lSb6fgyUpXcC3EWrXxtQsfdf\n\tnWfkXRvvFO/lv/9QazjJuH6Cs8jnS1YjnN7ejumF1q3gNHXkws39wzpSDH40XS+ZBDmx\n\tbNDg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1778158503; x=1778763303;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=7qXhgolOuJk656ES/U26gIkNoakVkmPr3O4bl7zAoi4=;\n\tb=SHWtDXEcO9cfJyncXCk83B+ah0KKquU9S6M3uDyS9Vql8RiJVy+oC2JIVJycTDFEic\n\tHeVuLeC902AlQL69f+lkFveXBwsQAODzCvIUpdWOlNb8jMkjjZfAZN/KqSc3TIZcE/Fp\n\tVA0osta1yAwTD008knE2KInDm1zx56ClLP1ksTGmU1sAkHNMSrH2cD1aXDK+RrbbZp4w\n\tPnj5xEcIpi1Bo6pnr1gbNoSsSvwTmb2DrGmYQXHrsEBEGRIDigmL0QNr5PHsN14l/kVH\n\trnRWiA+aA+mKHOvwM5PsbcSxSS7licLmwb57Hj6I66qHKFsI300VtO8g3kEePvzVsUru\n\tbXwQ==", "X-Gm-Message-State": "AOJu0Yygt9ygEGTYWlHPDyhBmGf4hnth1I0rJSBdEy2CEPp4QuJfKfoJ\n\tqQB4EMSgmlaeriTIDt56bNxXzMtrHcStLuP2VR5YZ1NqnHMhwdsDKt9am+/KfhCnrixkTxa/V1R\n\tQjbls", "X-Gm-Gg": "AeBDiesHv2gOMEzYb+nTI34Fb0Auk2a0F64hVvNR2S7d+GWNrqymUYCptQCrql75nkc\n\tEz3w9YgpcJfkez0Jgl64VOVfI2CAyy+TRHBR/q7tkFEnTupFxp41ZBG6tXZt5ck6yvJ69ApHZXf\n\tF3Wm2Q+VT70pGillyoDxS/ZCjlpho4Q2gNbjOzANICczq0B2V5x6lkxmY6y192QhO5HmvRcMcyF\n\tJi5+X8EqpeZtPAEHt/KEzYVHvz3Y9/9PsByKEmS/nWoSLIKEC8oRNZFgJ9b/3Xcslp9o7KHf5f/\n\tqmZPciyFU1wkU6ZV7lS1fXOK7mDNS+FLgMtrfdwdS35zrQdVPBtuw1bnmKIUX7K0XX4rcHtC7vr\n\tlHXTgGrsFTDaF1jQHr1FKVJfPM4DOivPDp7CBSnwFS0q1/L88vDRSOKMUTH8kd5Guu1v5Fxx/EG\n\t353SGvYylgx93yyOuARQXe+QrARHmjUWevjrNk6p/I7/YfznnpSFc6WFQRnYCHHYIYxj4eRCcGS\n\tT1GRorKqatgUWNhtz+B39SxxAH0HOiEkt/1zwrPXtBB+RapJENZxENGu2TGRq0=", "X-Received": "by 2002:a05:600c:a305:b0:48a:5970:2005 with SMTP id\n\t5b1f17b1804b1-48e51e08362mr87094505e9.2.1778158503007; \n\tThu, 07 May 2026 05:55:03 -0700 (PDT)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "David Plowman <david.plowman@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>", "Subject": "[PATCH v4 3/3] pipeline: rpi: Make control lists in requests\n\tproperly atomic", "Date": "Thu, 7 May 2026 13:20:36 +0100", "Message-ID": "<20260507125458.12140-4-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.47.3", "In-Reply-To": "<20260507125458.12140-1-david.plowman@raspberrypi.com>", "References": "<20260507125458.12140-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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>" }, "content": "When a request is about to be processed, this commit separates\n\"delayed controls\" (camera-related ones that take \"a few frames\" to\napply) from \"immediate controls\" (ISP-related controls) that will\nhappen instantly. It does so in a copy of the request's control list,\nso as to avoid disturbing the request's original version.\n\nThe immediate controls are held back until the delayed controls that\nthey were submitted with, have happened. This means all the controls\nsubmitted in a request happen atomically.\n\nWe therefore already have the sequence number of the request whose\ncontrols have just been applied, so we additionally attach this to the\ncurrent request as \"ControlId\" metadata.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/common/ipa_base.cpp | 24 ++++++---\n .../pipeline/rpi/common/pipeline_base.cpp | 49 +++++++++++++++++++\n .../pipeline/rpi/common/pipeline_base.h | 9 ++++\n src/libcamera/pipeline/rpi/pisp/pisp.cpp | 9 ++--\n src/libcamera/pipeline/rpi/vc4/vc4.cpp | 9 ++--\n 5 files changed, 86 insertions(+), 14 deletions(-)", "diff": "diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp\nindex faa77719..dacafa57 100644\n--- a/src/ipa/rpi/common/ipa_base.cpp\n+++ b/src/ipa/rpi/common/ipa_base.cpp\n@@ -431,6 +431,15 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms)\n \trpiMetadata.clear();\n \tfillDeviceStatus(params.sensorControls, ipaContext);\n \n+\t/*\n+\t * When there are controls, it's important that we don't skip running the\n+\t * IPAs, as that can mess with synchronisation. Crucially though, we need\n+\t * to know whether there were controls when this comes back as the\n+\t * _delayed_ metadata, hence why we flag this in the metadata itself.\n+\t */\n+\tif (!params.requestControls.empty())\n+\t\trpiMetadata.set(\"ipa.request_controls\", true);\n+\n \tif (params.buffers.embedded) {\n \t\t/*\n \t\t * Pipeline handler has supplied us with an embedded data buffer,\n@@ -451,7 +460,7 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms)\n \t */\n \tAgcStatus agcStatus;\n \tbool hdrChange = false;\n-\tRPiController::Metadata &delayedMetadata = rpiMetadata_[params.delayContext];\n+\tRPiController::Metadata &delayedMetadata = rpiMetadata_[params.delayContext % rpiMetadata_.size()];\n \tif (!delayedMetadata.get<AgcStatus>(\"agc.status\", agcStatus)) {\n \t\trpiMetadata.set(\"agc.delayed_status\", agcStatus);\n \t\thdrChange = agcStatus.hdr.mode != hdrStatus_.mode;\n@@ -464,9 +473,13 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms)\n \t */\n \thelper_->prepare(embeddedBuffer, rpiMetadata);\n \n+\tbool delayedRequestControls = false;\n+\tdelayedMetadata.get<bool>(\"ipa.request_controls\", delayedRequestControls);\n+\n \t/* Allow a 10% margin on the comparison below. */\n \tDuration delta = (frameTimestamp - lastRunTimestamp_) * 1.0ns;\n-\tif (lastRunTimestamp_ && frameCount_ > invalidCount_ &&\n+\tif (!delayedRequestControls && params.requestControls.empty() &&\n+\t lastRunTimestamp_ && frameCount_ > invalidCount_ &&\n \t delta < controllerMinFrameDuration_ * 0.9 && !hdrChange) {\n \t\t/*\n \t\t * Ensure we merge the previous frame's metadata with the current\n@@ -535,7 +548,7 @@ void IpaBase::processStats(const ProcessParams ¶ms)\n \t\tControlList ctrls(sensorCtrls_);\n \t\tapplyAGC(&agcStatus, ctrls);\n \t\trpiMetadata.set(\"agc.status\", agcStatus);\n-\t\tsetDelayedControls.emit(ctrls, ipaContext);\n+\t\tsetDelayedControls.emit(ctrls, params.ipaContext);\n \t\tsetCameraTimeoutValue();\n \t}\n \n@@ -951,8 +964,6 @@ void IpaBase::applyControls(const ControlList &controls)\n \n \t\t\t/* The control provides units of microseconds. */\n \t\t\tagc->setFixedExposureTime(0, ctrl.second.get<int32_t>() * 1.0us);\n-\n-\t\t\tlibcameraMetadata_.set(controls::ExposureTime, ctrl.second.get<int32_t>());\n \t\t\tbreak;\n \t\t}\n \n@@ -976,9 +987,6 @@ void IpaBase::applyControls(const ControlList &controls)\n \t\t\t\tbreak;\n \n \t\t\tagc->setFixedGain(0, ctrl.second.get<float>());\n-\n-\t\t\tlibcameraMetadata_.set(controls::AnalogueGain,\n-\t\t\t\t\t ctrl.second.get<float>());\n \t\t\tbreak;\n \t\t}\n \ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex f6ef8a3b..0c82f549 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -1528,4 +1528,53 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request\n \t}\n }\n \n+static bool isControlDelayed(unsigned int id)\n+{\n+\treturn id == controls::ExposureTime ||\n+\t id == controls::AnalogueGain ||\n+\t id == controls::FrameDurationLimits ||\n+\t id == controls::AeEnable ||\n+\t id == controls::ExposureTimeMode ||\n+\t id == controls::AnalogueGainMode;\n+}\n+\n+void CameraData::handleControlLists(uint32_t delayContext, ControlList &requestControls)\n+{\n+\t/*\n+\t * The delayContext is the sequence number after it's gone through the various\n+\t * pipeline delays, so that's what gets reported as the \"ControlListSequence\"\n+\t * in the metadata, being the sequence number of the request whose ControlList\n+\t * has just been applied.\n+\t */\n+\tRequest *request = requestQueue_.front();\n+\trequest->_d()->metadata().set(controls::rpi::ControlListSequence, delayContext);\n+\n+\t/*\n+\t * Controls that take effect immediately (typically ISP controls) have to be\n+\t * delayed so as to synchronise with those controls that do get delayed. So we\n+\t * must remove them from the current request, and push them onto a queue so\n+\t * that they can be used later.\n+\t *\n+\t * Note that we are passed a copy of the request's controls, so that we can\n+\t * avoid disturbing what was in the original request.\n+\t */\n+\tControlList controls = std::move(requestControls);\n+\trequestControls.clear();\n+\timmediateControls_.push({ request->sequence(), {} });\n+\tfor (const auto &ctrl : controls) {\n+\t\tif (isControlDelayed(ctrl.first))\n+\t\t\trequestControls.set(ctrl.first, ctrl.second);\n+\t\telse\n+\t\t\timmediateControls_.back().controls.set(ctrl.first, ctrl.second);\n+\t}\n+\n+\t/* \"Immediate\" controls that have become due are now merged back into this request. */\n+\twhile (!immediateControls_.empty() &&\n+\t immediateControls_.front().controlListId <= delayContext) {\n+\t\trequestControls.merge(immediateControls_.front().controls,\n+\t\t\t\t ControlList::MergePolicy::OverwriteExisting);\n+\t\timmediateControls_.pop();\n+\t}\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\nindex 7bfac33e..134262b6 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n@@ -180,10 +180,19 @@ public:\n \n \tClockRecovery wallClockRecovery_;\n \n+\tstruct ImmediateControlsEntry {\n+\t\tuint64_t controlListId;\n+\t\tControlList controls;\n+\t};\n+\tstd::queue<ImmediateControlsEntry> immediateControls_;\n+\n protected:\n \tvoid fillRequestMetadata(const ControlList &bufferControls,\n \t\t\t\t Request *request);\n \n+\tvoid handleControlLists(uint32_t delayContext,\n+\t\t\t\tControlList &requestControls);\n+\n \tvirtual void tryRunPipeline() = 0;\n \n private:\ndiff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp\nindex cc7e32c3..690d2511 100644\n--- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n+++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n@@ -2322,9 +2322,6 @@ void PiSPCameraData::tryRunPipeline()\n \n \tfillRequestMetadata(job.sensorControls, request);\n \n-\t/* Set our state to say the pipeline is active. */\n-\tstate_ = State::Busy;\n-\n \tunsigned int bayerId = cfe_[Cfe::Output0].getBufferId(job.buffers[&cfe_[Cfe::Output0]]);\n \tunsigned int statsId = cfe_[Cfe::Stats].getBufferId(job.buffers[&cfe_[Cfe::Stats]]);\n \tASSERT(bayerId && statsId);\n@@ -2343,6 +2340,12 @@ void PiSPCameraData::tryRunPipeline()\n \tparams.sensorControls = std::move(job.sensorControls);\n \tparams.requestControls = request->controls();\n \n+\t/* This sorts out synchronisation with ControlLists in earlier requests. */\n+\thandleControlLists(job.delayContext, params.requestControls);\n+\n+\t/* Set our state to say the pipeline is active. */\n+\tstate_ = State::Busy;\n+\n \tif (sensorMetadata_) {\n \t\tunsigned int embeddedId =\n \t\t\tcfe_[Cfe::Embedded].getBufferId(job.buffers[&cfe_[Cfe::Embedded]]);\ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex f99cfdbc..28e7ad46 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -939,9 +939,6 @@ void Vc4CameraData::tryRunPipeline()\n \n \tfillRequestMetadata(bayerFrame.controls, request);\n \n-\t/* Set our state to say the pipeline is active. */\n-\tstate_ = State::Busy;\n-\n \tunsigned int bayer = unicam_[Unicam::Image].getBufferId(bayerFrame.buffer);\n \n \tLOG(RPI, Debug) << \"Signalling prepareIsp:\"\n@@ -955,6 +952,12 @@ void Vc4CameraData::tryRunPipeline()\n \tparams.delayContext = bayerFrame.delayContext;\n \tparams.buffers.embedded = 0;\n \n+\t/* This sorts out synchronisation with ControlLists in earlier requests. */\n+\thandleControlLists(bayerFrame.delayContext, params.requestControls);\n+\n+\t/* Set our state to say the pipeline is active. */\n+\tstate_ = State::Busy;\n+\n \tif (embeddedBuffer) {\n \t\tunsigned int embeddedId = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer);\n \n", "prefixes": [ "v4", "3/3" ] }