{"id":23846,"url":"https://patchwork.libcamera.org/api/1.1/patches/23846/?format=json","web_url":"https://patchwork.libcamera.org/patch/23846/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20250718082402.1207460-1-naush@raspberrypi.com>","date":"2025-07-18T08:23:33","name":"ipa: rpi: Fix static initialisation order bug in the Controller","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"36b8fdb98b7ac3305844bf048e6c4aeaa4ff35da","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23846/mbox/","series":[{"id":5296,"url":"https://patchwork.libcamera.org/api/1.1/series/5296/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5296","date":"2025-07-18T08:23:33","name":"ipa: rpi: Fix static initialisation order bug in the Controller","version":1,"mbox":"https://patchwork.libcamera.org/series/5296/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23846/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23846/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 8B282C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Jul 2025 08:24:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC17668F93;\n\tFri, 18 Jul 2025 10:24:07 +0200 (CEST)","from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com\n\t[IPv6:2a00:1450:4864:20::42b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DB4CD6150A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Jul 2025 10:24:05 +0200 (CEST)","by mail-wr1-x42b.google.com with SMTP id\n\tffacd0b85a97d-3b60565d5f4so229749f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Jul 2025 01:24:05 -0700 (PDT)","from NAUSH-P-DELL.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-3b61ca4d48bsm1137448f8f.62.2025.07.18.01.24.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 18 Jul 2025 01:24:04 -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=\"d1UJDkfP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1752827045; x=1753431845;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=TcZM2e1QHnCjMTz0w3Gh3RrldDUxkz0OHyKOYWefgWc=;\n\tb=d1UJDkfProhDOKSKBBv1cCnDt0wRdkavMaK6P+Ft+Wm61VGLdLCCgigIcf3i/kqNm0\n\t1tt4sG2cl50xVcUouC/K6ilgbYN3CksKuhXnNDoZJq5XGwv01KodSUZbDScQN6eFMx6Z\n\tdGd1GfwwPoDp6ihV4LPV1A9g50dBvX5+T3G7n2DjGP1rmkwIIc2e28yAVClhyxF0jSCG\n\tHjAkVUjeEZnbqtQWQCxKXkFhvJP24h2xL7EHX/BdMJTteC9dA8/EZjJ4F4BJf0rvldsr\n\tNfoxPYSJutuBoELGyplbldiqVXEA/umLnW6l7xVGisIB6Na4PDzaAkVRmVNC3fDwYB/F\n\tuhqw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1752827045; x=1753431845;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=TcZM2e1QHnCjMTz0w3Gh3RrldDUxkz0OHyKOYWefgWc=;\n\tb=A70mrRlmrKpcHq/msAmHqY+JqDiWnQBNOjtG/K7KIyFXc/+fYq3EYtPQARLt1VMllN\n\tMLlgGJYx+9Cgo9YLxg5OhCD9zPcPj8Q8Ml91LhW4pagqMOvmoRLMcyBXWia8XRh/BDnO\n\tDpiyvpHIthwlbRaJHXxL1wNuYLn/YnH6HTxoE/NfE0Nsk2tUKrEfGJWKo3gY0sm/jNm/\n\t8POCMcDPmBqqEm3HFvZYTAi0YFPqeR9RFIkM9CBdV6rLavFOVhpYtXTS3jugEJHk1bo0\n\tBO6P6jN45I/3bwF7CM3tpvkJTFChqxBXixBAxnSLL43NRgAEDPIW9h3LSe5xK16Kdzlf\n\t2bVg==","X-Gm-Message-State":"AOJu0Yxcmbt5m6l4qdUshqa8rNlfhns7iYgJdB2tuY+06ccMBBqF6OP6\n\tX3RdzN1o7oaGj7zFw3pa8FyzmNrZQR9BFWIxxIYXg65IuUxWidscomMGaRNRm2lXBkYwjGMdBwZ\n\tOIOMeC1Q=","X-Gm-Gg":"ASbGnctx8LN1QySiEjLc0Lex1GnSI42XUmJe11K+w0Rp7A02y2SzZIfAkBio5Vqe799\n\tekxJ6zY0sZXmztniNnVJFPPAXQMJ8ruo7+1+R/0CnGhdxvCNFrloub2u4Qzxl2CKVaRUEtxiTuk\n\tM3oqqeeQ3vhUBArVbDxFZOz8y7TkeLr+uEOVqQO2pwjdo9BjJBZux/Hz6f1FQJaSC6buMeacHl8\n\tpV5SMZHtxigHrUyZ5qt9hvwmXIYsxOkCKKn+8hbKl2vDcEtgKblmi32FVVoEIOeBsc6wRC9pLFM\n\tljw1E+oFOCZPeAZueqWClObYwLJ7AIwkRWgyk+C0zjTqV11veZGAM2ByLHuvA7dUt6E9mhTbEHT\n\tYzwBsWeCS5lBkMcypp5PUK+OUz9baBTgVPjubjiSDug==","X-Google-Smtp-Source":"AGHT+IEZaCK6c7+wwVV9X0vQfF12BDlm8mj8GlIZCrJiYVqffhHFYv4RwUGWadKE0RV1grbRlPS8Cw==","X-Received":"by 2002:a05:6000:420b:b0:3a4:e740:cd6e with SMTP id\n\tffacd0b85a97d-3b60dd54d8fmr3555696f8f.8.1752827044961; \n\tFri, 18 Jul 2025 01:24:04 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Naushir Patuck <naush@raspberrypi.com>","Subject":"[PATCH] ipa: rpi: Fix static initialisation order bug in the\n\tController","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","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":"There is a possible static initialisation issue with accessing the\nHardwareConfigMap static object through Controller::getHardwareConfig().\nFix this by providing a static function &hardwareConfigMap() to access\nthe object.\n\nThough not proven, this is possibly the cause of a very infrequent\nlockup in https://github.com/raspberrypi/rpicam-apps/issues/799.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/controller/controller.cpp | 119 ++++++++++++++------------\n 1 file changed, 64 insertions(+), 55 deletions(-)","diff":"diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp\nindex 651fff632400..72c0592c9585 100644\n--- a/src/ipa/rpi/controller/controller.cpp\n+++ b/src/ipa/rpi/controller/controller.cpp\n@@ -21,61 +21,70 @@ using namespace std::literals::chrono_literals;\n \n LOG_DEFINE_CATEGORY(RPiController)\n \n-static const std::map<std::string, Controller::HardwareConfig> HardwareConfigMap = {\n-\t{\n-\t\t\"bcm2835\",\n+namespace {\n+\n+const std::map<std::string, Controller::HardwareConfig> &hardwareConfigMap() {\n+\n+\tstatic const std::map<std::string, Controller::HardwareConfig> map = {\n \t\t{\n-\t\t\t/*\n-\t\t\t * There are only ever 15 AGC regions computed by the firmware\n-\t\t\t * due to zoning, but the HW defines AGC_REGIONS == 16!\n-\t\t\t */\n-\t\t\t.agcRegions = { 15 , 1 },\n-\t\t\t.agcZoneWeights = { 15 , 1 },\n-\t\t\t.awbRegions = { 16, 12 },\n-\t\t\t.cacRegions = { 0, 0 },\n-\t\t\t.focusRegions = { 4, 3 },\n-\t\t\t.numHistogramBins = 128,\n-\t\t\t.numGammaPoints = 33,\n-\t\t\t.pipelineWidth = 13,\n-\t\t\t.statsInline = false,\n-\t\t\t.minPixelProcessingTime = 0s,\n-\t\t\t.dataBufferStrided = true,\n-\t\t}\n-\t},\n-\t{\n-\t\t\"pisp\",\n+\t\t\t\"bcm2835\",\n+\t\t\t{\n+\t\t\t\t/*\n+\t\t\t\t* There are only ever 15 AGC regions computed by the firmware\n+\t\t\t\t* due to zoning, but the HW defines AGC_REGIONS == 16!\n+\t\t\t\t*/\n+\t\t\t\t.agcRegions = { 15 , 1 },\n+\t\t\t\t.agcZoneWeights = { 15 , 1 },\n+\t\t\t\t.awbRegions = { 16, 12 },\n+\t\t\t\t.cacRegions = { 0, 0 },\n+\t\t\t\t.focusRegions = { 4, 3 },\n+\t\t\t\t.numHistogramBins = 128,\n+\t\t\t\t.numGammaPoints = 33,\n+\t\t\t\t.pipelineWidth = 13,\n+\t\t\t\t.statsInline = false,\n+\t\t\t\t.minPixelProcessingTime = 0s,\n+\t\t\t\t.dataBufferStrided = true,\n+\t\t\t}\n+\t\t},\n \t\t{\n-\t\t\t.agcRegions = { 0, 0 },\n-\t\t\t.agcZoneWeights = { 15, 15 },\n-\t\t\t.awbRegions = { 32, 32 },\n-\t\t\t.cacRegions = { 8, 8 },\n-\t\t\t.focusRegions = { 8, 8 },\n-\t\t\t.numHistogramBins = 1024,\n-\t\t\t.numGammaPoints = 64,\n-\t\t\t.pipelineWidth = 16,\n-\t\t\t.statsInline = true,\n-\n-\t\t\t/*\n-\t\t\t * The constraint below is on the rate of pixels going\n-\t\t\t * from CSI2 peripheral to ISP-FE (400Mpix/s, plus tiny\n-\t\t\t * overheads per scanline, for which 380Mpix/s is a\n-\t\t\t * conservative bound).\n-\t\t\t *\n-\t\t\t * There is a 64kbit data FIFO before the bottleneck,\n-\t\t\t * which means that in all reasonable cases the\n-\t\t\t * constraint applies at a timescale >= 1 scanline, so\n-\t\t\t * adding horizontal blanking can prevent loss.\n-\t\t\t *\n-\t\t\t * If the backlog were to grow beyond 64kbit during a\n-\t\t\t * single scanline, there could still be loss. This\n-\t\t\t * could happen using 4 lanes at 1.5Gbps at 10bpp with\n-\t\t\t * frames wider than ~16,000 pixels.\n-\t\t\t */\n-\t\t\t.minPixelProcessingTime = 1.0us / 380,\n-\t\t\t.dataBufferStrided = false,\n-\t\t}\n-\t},\n-};\n+\t\t\t\"pisp\",\n+\t\t\t{\n+\t\t\t\t.agcRegions = { 0, 0 },\n+\t\t\t\t.agcZoneWeights = { 15, 15 },\n+\t\t\t\t.awbRegions = { 32, 32 },\n+\t\t\t\t.cacRegions = { 8, 8 },\n+\t\t\t\t.focusRegions = { 8, 8 },\n+\t\t\t\t.numHistogramBins = 1024,\n+\t\t\t\t.numGammaPoints = 64,\n+\t\t\t\t.pipelineWidth = 16,\n+\t\t\t\t.statsInline = true,\n+\n+\t\t\t\t/*\n+\t\t\t\t* The constraint below is on the rate of pixels going\n+\t\t\t\t* from CSI2 peripheral to ISP-FE (400Mpix/s, plus tiny\n+\t\t\t\t* overheads per scanline, for which 380Mpix/s is a\n+\t\t\t\t* conservative bound).\n+\t\t\t\t*\n+\t\t\t\t* There is a 64kbit data FIFO before the bottleneck,\n+\t\t\t\t* which means that in all reasonable cases the\n+\t\t\t\t* constraint applies at a timescale >= 1 scanline, so\n+\t\t\t\t* adding horizontal blanking can prevent loss.\n+\t\t\t\t*\n+\t\t\t\t* If the backlog were to grow beyond 64kbit during a\n+\t\t\t\t* single scanline, there could still be loss. This\n+\t\t\t\t* could happen using 4 lanes at 1.5Gbps at 10bpp with\n+\t\t\t\t* frames wider than ~16,000 pixels.\n+\t\t\t\t*/\n+\t\t\t\t.minPixelProcessingTime = 1.0us / 380,\n+\t\t\t\t.dataBufferStrided = false,\n+\t\t\t}\n+\t\t},\n+\t};\n+\n+\treturn map;\n+}\n+\n+} /* namespace */\n \n Controller::Controller()\n \t: switchModeCalled_(false)\n@@ -211,12 +220,12 @@ const std::string &Controller::getTarget() const\n \n const Controller::HardwareConfig &Controller::getHardwareConfig() const\n {\n-\tauto cfg = HardwareConfigMap.find(getTarget());\n+\tauto cfg = hardwareConfigMap().find(getTarget());\n \n \t/*\n \t * This really should not happen, the IPA ought to validate the target\n \t * on initialisation.\n \t */\n-\tASSERT(cfg != HardwareConfigMap.end());\n+\tASSERT(cfg != hardwareConfigMap().end());\n \treturn cfg->second;\n }\n","prefixes":[]}