Show a patch.

GET /api/patches/10431/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 10431,
    "url": "https://patchwork.libcamera.org/api/patches/10431/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10431/",
    "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": "<20201116164918.2055-3-david.plowman@raspberrypi.com>",
    "date": "2020-11-16T16:49:10",
    "name": "[libcamera-devel,02/10] libcamera: ipa: raspberrypi: agc: Remove unnecessary locking",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "86955bb0fcafea09caaa8d3235214131d408e678",
    "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/10431/mbox/",
    "series": [
        {
            "id": 1464,
            "url": "https://patchwork.libcamera.org/api/series/1464/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1464",
            "date": "2020-11-16T16:49:08",
            "name": "Raspberry Pi AGC",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1464/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10431/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10431/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 4F079BE082\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Nov 2020 16:49:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 10D80632D4;\n\tMon, 16 Nov 2020 17:49:29 +0100 (CET)",
            "from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF2C3632C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 17:49:26 +0100 (CET)",
            "by mail-wr1-x433.google.com with SMTP id p8so19427387wrx.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 08:49:26 -0800 (PST)",
            "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tq16sm23716973wrn.13.2020.11.16.08.49.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 16 Nov 2020 08:49:24 -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=\"is8Te22X\"; 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:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=fnx644/4e1aclgbmGPuB8wpXNNlNgk4rgNHPuNiIVwo=;\n\tb=is8Te22X41nTPWaQpy0bAQKCkBbatmToD+4Z+ORZ6yLkpcJ0sAOnL+idNU7cuSjIWE\n\tmy1vYGYdBZ8helWF088826vEZXtFuUieTlpowcPnXEd3ZcyK6MeuciO5LidIch93JE1y\n\t6khLEnsSQHDS1liB58YTD4O4PY/f/HbW5qR+/FmCzZ73AYkTLOu4CW7SVzqRaCJXIjNm\n\tMR8sgclWe3bvkwoK1d83KLHMBqo3NlEvjBmiZBW7Rk2G0PMSQwBCUtmJJBYUyUn8z11o\n\tDY1Y9JN8f1HDF4WJIqLorSKC5y3tZ3WRJDYotxogQtCpAZt0tX1Jx8vX1WynRba3WRQi\n\t2jjA==",
        "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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=fnx644/4e1aclgbmGPuB8wpXNNlNgk4rgNHPuNiIVwo=;\n\tb=niecWTKt2izCRtNtxvemMxIbHvrei0gzkFWSyVERK8j5fkSjzUS1jHN3/132cNNJkg\n\tlhn4nEI/9sBUPxRUPKx8D01PHuyESEChbBkntrFOZnuO1L1j8n2hFcsXc4NxsUCxfSs+\n\tRVg/+2cz92B7cP9HvzXMUqYt3F0X04FIComKMaQP4yA98BOILPFthAop4Cmt02uuF0nZ\n\tgJn2/l8PFeucAJXeHpR1bOJ6eSR6u7/2n2XOBmj/CJm8KZRUuON+jhOUJPnreyr68vah\n\tqnb1JsFpZLIp4Jfj5/fAQO9dIwfXxM91U+/VPA3vtTQdzbjU2nfsMCpgoiZ5BhG1zMXz\n\tZRGQ==",
        "X-Gm-Message-State": "AOAM533iWy5dij6CbqOmpC/Ve5f1OYjrqt5mwGbQUotaGCOL/7QrViBk\n\tzmX0zgjiFvlF/+vVMEWM/NTXue03liCZNA==",
        "X-Google-Smtp-Source": "ABdhPJwAGHDfxAlPViJZus04GoHVbCy2opSke3vwWf4/PUWVOeJb2pSeSLwBXpRcoludENWDxd9EsQ==",
        "X-Received": "by 2002:adf:f906:: with SMTP id\n\tb6mr20211716wrr.244.1605545366052; \n\tMon, 16 Nov 2020 08:49:26 -0800 (PST)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 16 Nov 2020 16:49:10 +0000",
        "Message-Id": "<20201116164918.2055-3-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20201116164918.2055-1-david.plowman@raspberrypi.com>",
        "References": "<20201116164918.2055-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH 02/10] libcamera: ipa: raspberrypi: agc:\n\tRemove unnecessary locking",
        "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": "On the libcamera/VC4 platform the AGC Prepare/Process methods, and any\nchanges to the AGC settings, run synchronously - so a number of\nmutexes and copies are unnecessary and can be removed.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 99 ++++++++--------------\n src/ipa/raspberrypi/controller/rpi/agc.hpp |  5 +-\n 2 files changed, 37 insertions(+), 67 deletions(-)",
    "diff": "diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex 8079345b..c4379b99 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -160,7 +160,6 @@ Agc::Agc(Controller *controller)\n \tstatus_.total_exposure_value = 0.0;\n \tstatus_.target_exposure_value = 0.0;\n \tstatus_.locked = false;\n-\toutput_status_ = status_;\n }\n \n char const *Agc::Name() const\n@@ -185,43 +184,36 @@ void Agc::Read(boost::property_tree::ptree const &params)\n \n void Agc::SetEv(double ev)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \tev_ = ev;\n }\n \n void Agc::SetFlickerPeriod(double flicker_period)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \tflicker_period_ = flicker_period;\n }\n \n void Agc::SetFixedShutter(double fixed_shutter)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \tfixed_shutter_ = fixed_shutter;\n }\n \n void Agc::SetFixedAnalogueGain(double fixed_analogue_gain)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \tfixed_analogue_gain_ = fixed_analogue_gain;\n }\n \n void Agc::SetMeteringMode(std::string const &metering_mode_name)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \tmetering_mode_name_ = metering_mode_name;\n }\n \n void Agc::SetExposureMode(std::string const &exposure_mode_name)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \texposure_mode_name_ = exposure_mode_name;\n }\n \n void Agc::SetConstraintMode(std::string const &constraint_mode_name)\n {\n-\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n \tconstraint_mode_name_ = constraint_mode_name;\n }\n \n@@ -240,14 +232,9 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n \n void Agc::Prepare(Metadata *image_metadata)\n {\n-\tAgcStatus status;\n-\t{\n-\t\tstd::unique_lock<std::mutex> lock(output_mutex_);\n-\t\tstatus = output_status_;\n-\t}\n \tint lock_count = lock_count_;\n \tlock_count_ = 0;\n-\tstatus.digital_gain = 1.0;\n+\tstatus_.digital_gain = 1.0;\n \tif (status_.total_exposure_value) {\n \t\t// Process has run, so we have meaningful values.\n \t\tDeviceStatus device_status;\n@@ -255,48 +242,46 @@ void Agc::Prepare(Metadata *image_metadata)\n \t\t\tdouble actual_exposure = device_status.shutter_speed *\n \t\t\t\t\t\t device_status.analogue_gain;\n \t\t\tif (actual_exposure) {\n-\t\t\t\tstatus.digital_gain =\n+\t\t\t\tstatus_.digital_gain =\n \t\t\t\t\tstatus_.total_exposure_value /\n \t\t\t\t\tactual_exposure;\n \t\t\t\tLOG(RPiAgc, Debug) << \"Want total exposure \" << status_.total_exposure_value;\n \t\t\t\t// Never ask for a gain < 1.0, and also impose\n \t\t\t\t// some upper limit. Make it customisable?\n-\t\t\t\tstatus.digital_gain = std::max(\n+\t\t\t\tstatus_.digital_gain = std::max(\n \t\t\t\t\t1.0,\n-\t\t\t\t\tstd::min(status.digital_gain, 4.0));\n+\t\t\t\t\tstd::min(status_.digital_gain, 4.0));\n \t\t\t\tLOG(RPiAgc, Debug) << \"Actual exposure \" << actual_exposure;\n-\t\t\t\tLOG(RPiAgc, Debug) << \"Use digital_gain \" << status.digital_gain;\n-\t\t\t\tLOG(RPiAgc, Debug) << \"Effective exposure \" << actual_exposure * status.digital_gain;\n+\t\t\t\tLOG(RPiAgc, Debug) << \"Use digital_gain \" << status_.digital_gain;\n+\t\t\t\tLOG(RPiAgc, Debug) << \"Effective exposure \" << actual_exposure * status_.digital_gain;\n \t\t\t\t// Decide whether AEC/AGC has converged.\n \t\t\t\t// Insist AGC is steady for MAX_LOCK_COUNT\n \t\t\t\t// frames before we say we are \"locked\".\n \t\t\t\t// (The hard-coded constants may need to\n \t\t\t\t// become customisable.)\n-\t\t\t\tif (status.target_exposure_value) {\n+\t\t\t\tif (status_.target_exposure_value) {\n #define MAX_LOCK_COUNT 3\n-\t\t\t\t\tdouble err = 0.10 * status.target_exposure_value + 200;\n+\t\t\t\t\tdouble err = 0.10 * status_.target_exposure_value + 200;\n \t\t\t\t\tif (actual_exposure <\n-\t\t\t\t\t    status.target_exposure_value + err\n-\t\t\t\t\t    && actual_exposure >\n-\t\t\t\t\t    status.target_exposure_value - err)\n+\t\t\t\t\t\t    status_.target_exposure_value + err &&\n+\t\t\t\t\t    actual_exposure >\n+\t\t\t\t\t\t    status_.target_exposure_value - err)\n \t\t\t\t\t\tlock_count_ =\n \t\t\t\t\t\t\tstd::min(lock_count + 1,\n-\t\t\t\t\t\t\t       MAX_LOCK_COUNT);\n+\t\t\t\t\t\t\t\t MAX_LOCK_COUNT);\n \t\t\t\t\telse if (actual_exposure <\n-\t\t\t\t\t\t status.target_exposure_value\n-\t\t\t\t\t\t + 1.5 * err &&\n+\t\t\t\t\t\t\t status_.target_exposure_value + 1.5 * err &&\n \t\t\t\t\t\t actual_exposure >\n-\t\t\t\t\t\t status.target_exposure_value\n-\t\t\t\t\t\t - 1.5 * err)\n+\t\t\t\t\t\t\t status_.target_exposure_value - 1.5 * err)\n \t\t\t\t\t\tlock_count_ = lock_count;\n \t\t\t\t\tLOG(RPiAgc, Debug) << \"Lock count: \" << lock_count_;\n \t\t\t\t}\n \t\t\t}\n \t\t} else\n \t\t\tLOG(RPiAgc, Debug) << Name() << \": no device metadata\";\n-\t\tstatus.locked = lock_count_ >= MAX_LOCK_COUNT;\n-\t\t//printf(\"%s\\n\", status.locked ? \"+++++++++\" : \"-\");\n-\t\timage_metadata->Set(\"agc.status\", status);\n+\t\tstatus_.locked = lock_count_ >= MAX_LOCK_COUNT;\n+\t\t//printf(\"%s\\n\", status_.locked ? \"+++++++++\" : \"-\");\n+\t\timage_metadata->Set(\"agc.status\", status_);\n \t}\n }\n \n@@ -335,55 +320,47 @@ static void copy_string(std::string const &s, char *d, size_t size)\n void Agc::housekeepConfig()\n {\n \t// First fetch all the up-to-date settings, so no one else has to do it.\n-\tstd::string new_exposure_mode_name, new_constraint_mode_name,\n-\t\tnew_metering_mode_name;\n-\t{\n-\t\tstd::unique_lock<std::mutex> lock(settings_mutex_);\n-\t\tnew_metering_mode_name = metering_mode_name_;\n-\t\tnew_exposure_mode_name = exposure_mode_name_;\n-\t\tnew_constraint_mode_name = constraint_mode_name_;\n-\t\tstatus_.ev = ev_;\n-\t\tstatus_.fixed_shutter = fixed_shutter_;\n-\t\tstatus_.fixed_analogue_gain = fixed_analogue_gain_;\n-\t\tstatus_.flicker_period = flicker_period_;\n-\t}\n+\tstatus_.ev = ev_;\n+\tstatus_.fixed_shutter = fixed_shutter_;\n+\tstatus_.fixed_analogue_gain = fixed_analogue_gain_;\n+\tstatus_.flicker_period = flicker_period_;\n \tLOG(RPiAgc, Debug) << \"ev \" << status_.ev << \" fixed_shutter \"\n \t\t\t   << status_.fixed_shutter << \" fixed_analogue_gain \"\n \t\t\t   << status_.fixed_analogue_gain;\n \t// Make sure the \"mode\" pointers point to the up-to-date things, if\n \t// they've changed.\n-\tif (strcmp(new_metering_mode_name.c_str(), status_.metering_mode)) {\n-\t\tauto it = config_.metering_modes.find(new_metering_mode_name);\n+\tif (strcmp(metering_mode_name_.c_str(), status_.metering_mode)) {\n+\t\tauto it = config_.metering_modes.find(metering_mode_name_);\n \t\tif (it == config_.metering_modes.end())\n \t\t\tthrow std::runtime_error(\"Agc: no metering mode \" +\n-\t\t\t\t\t\t new_metering_mode_name);\n+\t\t\t\t\t\t metering_mode_name_);\n \t\tmetering_mode_ = &it->second;\n-\t\tcopy_string(new_metering_mode_name, status_.metering_mode,\n+\t\tcopy_string(metering_mode_name_, status_.metering_mode,\n \t\t\t    sizeof(status_.metering_mode));\n \t}\n-\tif (strcmp(new_exposure_mode_name.c_str(), status_.exposure_mode)) {\n-\t\tauto it = config_.exposure_modes.find(new_exposure_mode_name);\n+\tif (strcmp(exposure_mode_name_.c_str(), status_.exposure_mode)) {\n+\t\tauto it = config_.exposure_modes.find(exposure_mode_name_);\n \t\tif (it == config_.exposure_modes.end())\n \t\t\tthrow std::runtime_error(\"Agc: no exposure profile \" +\n-\t\t\t\t\t\t new_exposure_mode_name);\n+\t\t\t\t\t\t exposure_mode_name_);\n \t\texposure_mode_ = &it->second;\n-\t\tcopy_string(new_exposure_mode_name, status_.exposure_mode,\n+\t\tcopy_string(exposure_mode_name_, status_.exposure_mode,\n \t\t\t    sizeof(status_.exposure_mode));\n \t}\n-\tif (strcmp(new_constraint_mode_name.c_str(), status_.constraint_mode)) {\n+\tif (strcmp(constraint_mode_name_.c_str(), status_.constraint_mode)) {\n \t\tauto it =\n-\t\t\tconfig_.constraint_modes.find(new_constraint_mode_name);\n+\t\t\tconfig_.constraint_modes.find(constraint_mode_name_);\n \t\tif (it == config_.constraint_modes.end())\n \t\t\tthrow std::runtime_error(\"Agc: no constraint list \" +\n-\t\t\t\t\t\t new_constraint_mode_name);\n+\t\t\t\t\t\t constraint_mode_name_);\n \t\tconstraint_mode_ = &it->second;\n-\t\tcopy_string(new_constraint_mode_name, status_.constraint_mode,\n+\t\tcopy_string(constraint_mode_name_, status_.constraint_mode,\n \t\t\t    sizeof(status_.constraint_mode));\n \t}\n \tLOG(RPiAgc, Debug) << \"exposure_mode \"\n-\t\t\t   << new_exposure_mode_name << \" constraint_mode \"\n-\t\t\t   << new_constraint_mode_name << \" metering_mode \"\n-\t\t\t   << new_metering_mode_name;\n+\t\t\t   << exposure_mode_name_ << \" constraint_mode \"\n+\t\t\t   << constraint_mode_name_ << \" metering_mode \"\n+\t\t\t   << metering_mode_name_;\n }\n \n void Agc::fetchCurrentExposure(Metadata *image_metadata)\n@@ -638,10 +615,6 @@ void Agc::writeAndFinish(Metadata *image_metadata, bool desaturate)\n \tstatus_.target_exposure_value = desaturate ? 0 : target_.total_exposure_no_dg;\n \tstatus_.shutter_time = filtered_.shutter;\n \tstatus_.analogue_gain = filtered_.analogue_gain;\n-\t{\n-\t\tstd::unique_lock<std::mutex> lock(output_mutex_);\n-\t\toutput_status_ = status_;\n-\t}\n \t// Write to metadata as well, in case anyone wants to update the camera\n \t// immediately.\n \timage_metadata->Set(\"agc.status\", status_);\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp\nindex ba7ae092..5a02df4e 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.hpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp\n@@ -106,12 +106,9 @@ private:\n \tExposureValues current_;  // values for the current frame\n \tExposureValues target_;   // calculate the values we want here\n \tExposureValues filtered_; // these values are filtered towards target\n-\tAgcStatus status_;        // to \"latch\" settings so they can't change\n-\tAgcStatus output_status_; // the status we will write out\n-\tstd::mutex output_mutex_;\n+\tAgcStatus status_;\n \tint lock_count_;\n \t// Below here the \"settings\" that applications can change.\n-\tstd::mutex settings_mutex_;\n \tstd::string metering_mode_name_;\n \tstd::string exposure_mode_name_;\n \tstd::string constraint_mode_name_;\n",
    "prefixes": [
        "libcamera-devel",
        "02/10"
    ]
}