From patchwork Thu Feb 4 09:34:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 11131 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EEB19BD162 for ; Thu, 4 Feb 2021 09:35:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3CD0861402; Thu, 4 Feb 2021 10:35:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="e6cAFuvy"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84ED760107 for ; Thu, 4 Feb 2021 10:35:02 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id f16so2475453wmq.5 for ; Thu, 04 Feb 2021 01:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I7i7fBZpiVuIH5sFk+yyLknlBa9tcpZHROKD240TfvU=; b=e6cAFuvyHAK0LRHwNPMYqkiK3o6Shr8/6/j/1Go/bMTy0upWIcC3WsCSGEH63BBRhk yidwGnaSpqRS5+fBLwVxxLQtW/vFJmKZlq+w2rGVmLR0RxfanrOrgbNblEIDFZ1V/xgx e7GU0d+Ohp5PH0ESzADZ6hrwnLPaxDekMjabfK2IddzmJIuujHBePkzWFLyPB/VydX51 pPOf0R+lvMcc3nEdjc6kD/QsxsYanRiu04Ty2WJhbNVLUaFGwlgb3WrS4dDSjZQkUvUS QS3RQDjWFoD8novVtCKgkf13M/Vs+Zm/b3QsFAuMFSZbnetZcC3g3nvOk5HwZEYQnEry hG3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I7i7fBZpiVuIH5sFk+yyLknlBa9tcpZHROKD240TfvU=; b=t4aSm8g9kYo/NcgXb6F9HgwEtCXRFIOgrynBoa//YMFUkKhT9/Pej7Atth6fiu5/jR l/kIe+NiTGqr4TvwqccLlBgRhkEfivBIotyCDmP5H/nvKA29dsxoyBk/RKdR5gTUuID7 Ik9JgHqS4uvgDCkWZJ8Zqs5sCf+7XfAu501h8DOCLX5igle3gDbzdfW/bGtPubSGeEM7 oLVB6s9cErBR3yINiyGwp5qsOlbqhOQ4elWqzZ4FtTbnz+qNJotUZ7L5Nuo3pLPsnkcn EWRU6v9cPInYzae10X0EbxtQKOItLOiB/Wzp3RhMyqhXGyMGaV2nhc2abj18HOSdC+8y PiGA== X-Gm-Message-State: AOAM5315Brzq0I14riaGaKd7clh/z9P8s5KpqFLLwGSs9DvbrRbccV4q +CEVrejLD0i62rTMxt9F2Smo340tNADlxWrT X-Google-Smtp-Source: ABdhPJzM2fvNWcUF2McMbZO8DufnLBkRT1tAp3qNJpA+ApqaZ9354WuQjZ8dLfAcjCejUZWJumw9qw== X-Received: by 2002:a1c:2501:: with SMTP id l1mr6541055wml.41.1612431301911; Thu, 04 Feb 2021 01:35:01 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id g16sm5280580wmi.30.2021.02.04.01.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 01:35:01 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Feb 2021 09:34:51 +0000 Message-Id: <20210204093457.6879-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210204093457.6879-1-david.plowman@raspberrypi.com> References: <20210204093457.6879-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/7] ipa: raspberrypi: AWB: Remove unnecessary locking for AWB settings X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" AWB settings get updated synchronously with the main thread, so the settings_mutex_ and associated locking can be removed. Signed-off-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 18 +++++------------- src/ipa/raspberrypi/controller/rpi/awb.hpp | 4 +--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index 62337b13..dabab726 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -185,13 +185,11 @@ unsigned int Awb::GetConvergenceFrames() const void Awb::SetMode(std::string const &mode_name) { - std::unique_lock lock(settings_mutex_); mode_name_ = mode_name; } void Awb::SetManualGains(double manual_r, double manual_b) { - std::unique_lock lock(settings_mutex_); // If any of these are 0.0, we swich back to auto. manual_r_ = manual_r; manual_b_ = manual_b; @@ -229,14 +227,13 @@ void Awb::fetchAsyncResults() sync_results_ = async_results_; } -void Awb::restartAsync(StatisticsPtr &stats, std::string const &mode_name, - double lux) +void Awb::restartAsync(StatisticsPtr &stats, double lux) { LOG(RPiAwb, Debug) << "Starting AWB calculation"; // this makes a new reference which belongs to the asynchronous thread statistics_ = stats; // store the mode as it could technically change - auto m = config_.modes.find(mode_name); + auto m = config_.modes.find(mode_name_); mode_ = m != config_.modes.end() ? &m->second : (mode_ == nullptr ? config_.default_mode : mode_); @@ -244,8 +241,8 @@ void Awb::restartAsync(StatisticsPtr &stats, std::string const &mode_name, frame_phase_ = 0; async_start_ = true; async_started_ = true; - size_t len = mode_name.copy(async_results_.mode, - sizeof(async_results_.mode) - 1); + size_t len = mode_name_.copy(async_results_.mode, + sizeof(async_results_.mode) - 1); async_results_.mode[len] = '\0'; async_signal_.notify_one(); } @@ -294,11 +291,6 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata) if (frame_phase_ >= (int)config_.frame_period || frame_count2_ < (int)config_.startup_frames) { // Update any settings and any image metadata that we need. - std::string mode_name; - { - std::unique_lock lock(settings_mutex_); - mode_name = mode_name_; - } struct LuxStatus lux_status = {}; lux_status.lux = 400; // in case no metadata if (image_metadata->Get("lux.status", lux_status) != 0) @@ -307,7 +299,7 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata) std::unique_lock lock(mutex_); if (async_started_ == false) - restartAsync(stats, mode_name, lux_status.lux); + restartAsync(stats, lux_status.lux); } } diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp index 83b81498..1b39ab4b 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp @@ -134,11 +134,9 @@ private: AwbStatus sync_results_; AwbStatus prev_sync_results_; std::string mode_name_; - std::mutex settings_mutex_; // The following are for the asynchronous thread to use, though the main // thread can set/reset them if the async thread is known to be idle: - void restartAsync(StatisticsPtr &stats, std::string const &mode_name, - double lux); + void restartAsync(StatisticsPtr &stats, double lux); // copy out the results from the async thread so that it can be restarted void fetchAsyncResults(); StatisticsPtr statistics_;