From patchwork Fri Jul 18 08:23:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 23846 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 8B282C3237 for ; Fri, 18 Jul 2025 08:24:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC17668F93; Fri, 18 Jul 2025 10:24:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="d1UJDkfP"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DB4CD6150A for ; Fri, 18 Jul 2025 10:24:05 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3b60565d5f4so229749f8f.0 for ; Fri, 18 Jul 2025 01:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1752827045; x=1753431845; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TcZM2e1QHnCjMTz0w3Gh3RrldDUxkz0OHyKOYWefgWc=; b=d1UJDkfProhDOKSKBBv1cCnDt0wRdkavMaK6P+Ft+Wm61VGLdLCCgigIcf3i/kqNm0 1tt4sG2cl50xVcUouC/K6ilgbYN3CksKuhXnNDoZJq5XGwv01KodSUZbDScQN6eFMx6Z dGd1GfwwPoDp6ihV4LPV1A9g50dBvX5+T3G7n2DjGP1rmkwIIc2e28yAVClhyxF0jSCG HjAkVUjeEZnbqtQWQCxKXkFhvJP24h2xL7EHX/BdMJTteC9dA8/EZjJ4F4BJf0rvldsr NfoxPYSJutuBoELGyplbldiqVXEA/umLnW6l7xVGisIB6Na4PDzaAkVRmVNC3fDwYB/F uhqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752827045; x=1753431845; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TcZM2e1QHnCjMTz0w3Gh3RrldDUxkz0OHyKOYWefgWc=; b=A70mrRlmrKpcHq/msAmHqY+JqDiWnQBNOjtG/K7KIyFXc/+fYq3EYtPQARLt1VMllN MLlgGJYx+9Cgo9YLxg5OhCD9zPcPj8Q8Ml91LhW4pagqMOvmoRLMcyBXWia8XRh/BDnO DpiyvpHIthwlbRaJHXxL1wNuYLn/YnH6HTxoE/NfE0Nsk2tUKrEfGJWKo3gY0sm/jNm/ 8POCMcDPmBqqEm3HFvZYTAi0YFPqeR9RFIkM9CBdV6rLavFOVhpYtXTS3jugEJHk1bo0 BO6P6jN45I/3bwF7CM3tpvkJTFChqxBXixBAxnSLL43NRgAEDPIW9h3LSe5xK16Kdzlf 2bVg== X-Gm-Message-State: AOJu0Yxcmbt5m6l4qdUshqa8rNlfhns7iYgJdB2tuY+06ccMBBqF6OP6 X3RdzN1o7oaGj7zFw3pa8FyzmNrZQR9BFWIxxIYXg65IuUxWidscomMGaRNRm2lXBkYwjGMdBwZ OIOMeC1Q= X-Gm-Gg: ASbGnctx8LN1QySiEjLc0Lex1GnSI42XUmJe11K+w0Rp7A02y2SzZIfAkBio5Vqe799 ekxJ6zY0sZXmztniNnVJFPPAXQMJ8ruo7+1+R/0CnGhdxvCNFrloub2u4Qzxl2CKVaRUEtxiTuk M3oqqeeQ3vhUBArVbDxFZOz8y7TkeLr+uEOVqQO2pwjdo9BjJBZux/Hz6f1FQJaSC6buMeacHl8 pV5SMZHtxigHrUyZ5qt9hvwmXIYsxOkCKKn+8hbKl2vDcEtgKblmi32FVVoEIOeBsc6wRC9pLFM ljw1E+oFOCZPeAZueqWClObYwLJ7AIwkRWgyk+C0zjTqV11veZGAM2ByLHuvA7dUt6E9mhTbEHT YzwBsWeCS5lBkMcypp5PUK+OUz9baBTgVPjubjiSDug== X-Google-Smtp-Source: AGHT+IEZaCK6c7+wwVV9X0vQfF12BDlm8mj8GlIZCrJiYVqffhHFYv4RwUGWadKE0RV1grbRlPS8Cw== X-Received: by 2002:a05:6000:420b:b0:3a4:e740:cd6e with SMTP id ffacd0b85a97d-3b60dd54d8fmr3555696f8f.8.1752827044961; Fri, 18 Jul 2025 01:24:04 -0700 (PDT) Received: from NAUSH-P-DELL.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b61ca4d48bsm1137448f8f.62.2025.07.18.01.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jul 2025 01:24:04 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [PATCH] ipa: rpi: Fix static initialisation order bug in the Controller Date: Fri, 18 Jul 2025 09:23:33 +0100 Message-ID: <20250718082402.1207460-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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" There is a possible static initialisation issue with accessing the HardwareConfigMap static object through Controller::getHardwareConfig(). Fix this by providing a static function &hardwareConfigMap() to access the object. Though not proven, this is possibly the cause of a very infrequent lockup in https://github.com/raspberrypi/rpicam-apps/issues/799. Signed-off-by: Naushir Patuck --- src/ipa/rpi/controller/controller.cpp | 119 ++++++++++++++------------ 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index 651fff632400..72c0592c9585 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -21,61 +21,70 @@ using namespace std::literals::chrono_literals; LOG_DEFINE_CATEGORY(RPiController) -static const std::map HardwareConfigMap = { - { - "bcm2835", +namespace { + +const std::map &hardwareConfigMap() { + + static const std::map map = { { - /* - * There are only ever 15 AGC regions computed by the firmware - * due to zoning, but the HW defines AGC_REGIONS == 16! - */ - .agcRegions = { 15 , 1 }, - .agcZoneWeights = { 15 , 1 }, - .awbRegions = { 16, 12 }, - .cacRegions = { 0, 0 }, - .focusRegions = { 4, 3 }, - .numHistogramBins = 128, - .numGammaPoints = 33, - .pipelineWidth = 13, - .statsInline = false, - .minPixelProcessingTime = 0s, - .dataBufferStrided = true, - } - }, - { - "pisp", + "bcm2835", + { + /* + * There are only ever 15 AGC regions computed by the firmware + * due to zoning, but the HW defines AGC_REGIONS == 16! + */ + .agcRegions = { 15 , 1 }, + .agcZoneWeights = { 15 , 1 }, + .awbRegions = { 16, 12 }, + .cacRegions = { 0, 0 }, + .focusRegions = { 4, 3 }, + .numHistogramBins = 128, + .numGammaPoints = 33, + .pipelineWidth = 13, + .statsInline = false, + .minPixelProcessingTime = 0s, + .dataBufferStrided = true, + } + }, { - .agcRegions = { 0, 0 }, - .agcZoneWeights = { 15, 15 }, - .awbRegions = { 32, 32 }, - .cacRegions = { 8, 8 }, - .focusRegions = { 8, 8 }, - .numHistogramBins = 1024, - .numGammaPoints = 64, - .pipelineWidth = 16, - .statsInline = true, - - /* - * The constraint below is on the rate of pixels going - * from CSI2 peripheral to ISP-FE (400Mpix/s, plus tiny - * overheads per scanline, for which 380Mpix/s is a - * conservative bound). - * - * There is a 64kbit data FIFO before the bottleneck, - * which means that in all reasonable cases the - * constraint applies at a timescale >= 1 scanline, so - * adding horizontal blanking can prevent loss. - * - * If the backlog were to grow beyond 64kbit during a - * single scanline, there could still be loss. This - * could happen using 4 lanes at 1.5Gbps at 10bpp with - * frames wider than ~16,000 pixels. - */ - .minPixelProcessingTime = 1.0us / 380, - .dataBufferStrided = false, - } - }, -}; + "pisp", + { + .agcRegions = { 0, 0 }, + .agcZoneWeights = { 15, 15 }, + .awbRegions = { 32, 32 }, + .cacRegions = { 8, 8 }, + .focusRegions = { 8, 8 }, + .numHistogramBins = 1024, + .numGammaPoints = 64, + .pipelineWidth = 16, + .statsInline = true, + + /* + * The constraint below is on the rate of pixels going + * from CSI2 peripheral to ISP-FE (400Mpix/s, plus tiny + * overheads per scanline, for which 380Mpix/s is a + * conservative bound). + * + * There is a 64kbit data FIFO before the bottleneck, + * which means that in all reasonable cases the + * constraint applies at a timescale >= 1 scanline, so + * adding horizontal blanking can prevent loss. + * + * If the backlog were to grow beyond 64kbit during a + * single scanline, there could still be loss. This + * could happen using 4 lanes at 1.5Gbps at 10bpp with + * frames wider than ~16,000 pixels. + */ + .minPixelProcessingTime = 1.0us / 380, + .dataBufferStrided = false, + } + }, + }; + + return map; +} + +} /* namespace */ Controller::Controller() : switchModeCalled_(false) @@ -211,12 +220,12 @@ const std::string &Controller::getTarget() const const Controller::HardwareConfig &Controller::getHardwareConfig() const { - auto cfg = HardwareConfigMap.find(getTarget()); + auto cfg = hardwareConfigMap().find(getTarget()); /* * This really should not happen, the IPA ought to validate the target * on initialisation. */ - ASSERT(cfg != HardwareConfigMap.end()); + ASSERT(cfg != hardwareConfigMap().end()); return cfg->second; }