From patchwork Fri Jul 18 10:43:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 23850 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 4BC73C3237 for ; Fri, 18 Jul 2025 10:44:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8421568F99; Fri, 18 Jul 2025 12:44:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="oTwJn1rW"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D43D26150F for ; Fri, 18 Jul 2025 12:44:07 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3a577ab8c34so233146f8f.3 for ; Fri, 18 Jul 2025 03:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1752835447; x=1753440247; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5uUZjSAS3sSznM4zC21zCFrGDZXcqkoHXc5Yx1SKlO4=; b=oTwJn1rWT55ITF1fuf2EcjNox2Tk6I7Kh08YfeAmCmsy5Q9GYUtybBy+nfejbL0/Bo EPHSxHN+s2KG1Igpi6noyzvQec775ufvecXcO838bMje/jqZ/oCBpUs95PxlZI0FkO+U Tt138PgwQDeCIpNW3R6sEPZPjzGJ8HxsGkBkaCuYEG0gFVg196oGiD+9H1lPit7BLy9R 0DlnOkrH4BUzS8tS91EoTmoeb5leD/jENGdCKaKtHPtI/mHMbn1+xcb2YR+KX+7QCuEp ae7FXMeFvyghooGirRtB16aMjaIc0N1G2htoaffUo/vra7stTGLnXMkD+FhNsSCyAc/8 mfKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752835447; x=1753440247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5uUZjSAS3sSznM4zC21zCFrGDZXcqkoHXc5Yx1SKlO4=; b=v5mOqQ7CnAH+cd6btkgxKKT6/4woKbkelIQFURx/ybLorAyPRCF0+T2FfRoIseKrvz L4lTe863GGmNnitR9+PIADYwPvIspbhkJMzNxtkrCIgxQl9SIGIRZCfyYTNRhlqJk6pA 8e05dhRru3MgtvqaQB0TRO18DaIdzyHUkOkPYDFYlfuXvpI30TO0LAce3NupQH6vCMi/ j0nnobLNBIHXQemYLfNlaWwr8HrfDSYwJpYmMHYdxqrlPPMOfxEAtXGDHEyyn22watny kFfhuVdbPRFc7dPZIcn3z0fp1wNiJ/CnUbQU9JHPneO3m7u4iQMR+4vRoiWxyMRUNWgD 8vJw== X-Gm-Message-State: AOJu0YyOp7y7QsO6KXFRBPkhEqx4RhfHQSy+jhrRGYcd83NdzyrTSJyd +g4K2jgXboHC8p/3LgOQG+Hy0s9sr19IUpeOL3yvllNjWrlDJjMfvq378PUV3oWvevZ9xWUwPhb ahXXm0r0= X-Gm-Gg: ASbGncuGV93PjFQsh6aRADrPKbLVhWw+zhTzkj2NIzGeFg0W3t39oov7FqNNshvXjXF BpUaI+0v/aSg4tnvCE7XY63+90pQkZyRSPkwJ1qt71a6dkWDbR6aY865/IYnT9bMwwgBH7Y5/NV hsVkVxcXOiqCUvX18QSoNi49c87Fa1HQUnAeB0b5zH+o8XAlJBX8kzo2KeixvFa9PYPwcRTvihq wMiteQeth+Bnwpq6dTM6aCOxUBEH2Da32Nvp2c+c4uUjMkyFrjGrZOQG4gowAhtg7Lyc3wI1rd9 qJkvkQrg7vFEpU23dn8FmxxdI90CECYaJyebKevfPdhba2VJLQGUqOWB8t2JpMDR2KQEWV2FcWW 4LJneZ3qcd+Ghe1Xnj7ppb8lwVTBap0jerb1KXVLabU3GrkKJUFqA X-Google-Smtp-Source: AGHT+IG3+IYzgigiBoncwHqSm5KatSXj8GWSAmEKsnXkS6vXlstcT5aZZFxLJhNvhFeAp+4+0OGVgw== X-Received: by 2002:a05:6000:40c7:b0:3b6:18c4:e5af with SMTP id ffacd0b85a97d-3b618c4e70bmr1294939f8f.10.1752835446912; Fri, 18 Jul 2025 03:44:06 -0700 (PDT) Received: from NAUSH-P-DELL.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b61ca254f4sm1490907f8f.2.2025.07.18.03.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jul 2025 03:44:06 -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 11:43:46 +0100 Message-ID: <20250718104404.1284865-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250718082402.1207460-1-naush@raspberrypi.com> References: <20250718082402.1207460-1-naush@raspberrypi.com> 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 Reviewed-by: Kieran Bingham --- 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..df45dcd345b7 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; }