From patchwork Wed Mar 4 07:50:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 26252 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 28680C32EF for ; Wed, 4 Mar 2026 07:51:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD656623A8; Wed, 4 Mar 2026 08:51:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="LryNL55/"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="kNFev4bo"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71E9A6239C for ; Wed, 4 Mar 2026 08:51:02 +0100 (CET) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6245SiB8152731 for ; Wed, 4 Mar 2026 07:51:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=2pTT2vd9CrP iuo7G72w3VpawJDhZAO0mN9LyY+btYmM=; b=LryNL55/S7qHtwXA63kzh/HyvPP RVCxLNEPfb8MAU7e0yE7g1TLb7B+FECzIwHIDxp3rUFREGToEFWUVpBp/yEyQcmi aVWSQskdD5EKQeXb1+S52D9vbPaF2pGPbr0I/s7c7KpvRTpJRLYEF5wA4S+d5TDV jigGw7bBC12dF+vmm5u95WMU5eMOIvHwHECS2fLAC8YSWpgtGktUzM0JhQ6jscPQ OAweCUitnlmgRwtiRPIrSGoz7W/MqZiLiMtVJ13ym5QuDe2plE3TqQxdVlHtlBor lKe+1SHx/7byhMuOjbFZdEAQ/bE1PdSa57C4KrigwSFLsFk0toRccQMmawg== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cp3tvjnpf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Mar 2026 07:50:59 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8c70b6a5821so3532893485a.0 for ; Tue, 03 Mar 2026 23:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1772610658; x=1773215458; 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=2pTT2vd9CrPiuo7G72w3VpawJDhZAO0mN9LyY+btYmM=; b=kNFev4boXZFvkOCB+hBVMwg/bx220UHss050Lfj4kky8pZg/E2Gpkxtv8cqK4nZu6f qg9NM75zPqpcGaUZKLnjN0hpF1g2CwWTiRsg8D0NbxKfBzN5hsp4iN42CZ00IU61Iry2 TMhqYUswcqn+jTgtjKYHa954PDhdcZTzlHnRtPYwqLyvXwjC7+5J+ZcYNHHyAZ0m6Pcr kmn5fNynu9fdS4jCHvw0wOrhiYCOg8dRnM2FKtfqbXHu4F9c9q3ILqopOubVrsQzqTe+ 2O4GK0OmrgE1qfKOz1cjCDqbm0v0h8LmEm+NHfStU3UsLjE/hlvOiz2WfzkvUTDvK8xy Jz4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772610658; x=1773215458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2pTT2vd9CrPiuo7G72w3VpawJDhZAO0mN9LyY+btYmM=; b=rcr1FJuX8rE4BXG83HqV5OttLwXAXqS4033pIvZmKLaE5f3u5vBJXGqJaSpM8IRgkH DnJxC6BtW8JY1nDmapRuvshLOBfYOncj68pDIblh0t9r6jx6xUNUEQ+61TKc0GQDQ6Ag CHsLRsbME+dWjKqYCpMiTwnAGQitQXyOmkiSomYOrm4NFpH7JhkNg5Mp0b3ul9VvLYo1 qyHV7ugAY5BA1gB47CFWlFQ+F5vjRxYNKaiTLZ7dz4TL4UxMQ748BAecuq80reFG39/5 LqJxUDYYieEbIxvmvBpTyHMNowQJ/fHYhmQ7NJVRVaoR/igFsLDq67wTNMM7roIO8MEw gUBA== X-Gm-Message-State: AOJu0YycYX1D1WZpadjxnyZVCktJ7Rjfc8QN2fvPFYAcv5A0f5w7ki/k kF7mlIRRop6BEDfZFthAl2TvCJHHss8ubwEeZAHvSPnuzBnAucTh23ObeWcUIWKHwwxibvLYKHu YEzRzwXagwLRAyV2c9K3ZvdZnc0f0SLW6sEO7Z22bfskWt9xSBbSMVBIl8O+2yPipaxmm/mWkbh 6oQjF4jFSC X-Gm-Gg: ATEYQzzK8jvHC8yMnowrpHChafcllD/bjQZSiTiLvqC4+bKXxzLCwAmgJRLDa5x6eQZ qE/IAS5yj48VX5d42+iHENf8RNBcKX89cPX7PljTed91Xk3bvkwrLI9JwpUSo30ZhMnkToPOoa3 dCy443z1NxBtpGdfO+7JWu9GdUyo9hTpyeYOiKu83WcsZzBvs/Re74o/Flkk6xNmfmJ2hBigx1m lJ6pgMRDvdHZcn27jLPUqjN21zl8B0I6J6THxsunzvO7eksFjC8TgoM8h6hBQIhX0KjN5enBcfF NlVNaGHRdsKyD1roUPhZUCW4Vfb0aZSKO80ykHOdJRUErJejqVkCikrsD80fVB4RaBC4A8b60vg j3ELIjnREL2bYcQnlLv8+wcenCAXXdjwBgtICTwlkdQhqzVkc3rwD7fQmpANAGSFTj5apxKw3PS GaIc4hki26LpMo8drsEcZcinSzUkPiLDUSLQBq X-Received: by 2002:a05:620a:25cf:b0:8b2:ec1e:fe24 with SMTP id af79cd13be357-8cd5af7852dmr133029085a.42.1772610658371; Tue, 03 Mar 2026 23:50:58 -0800 (PST) X-Received: by 2002:a05:620a:25cf:b0:8b2:ec1e:fe24 with SMTP id af79cd13be357-8cd5af7852dmr133028185a.42.1772610657870; Tue, 03 Mar 2026 23:50:57 -0800 (PST) Received: from shalem (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935ac73a5dsm693263366b.25.2026.03.03.23.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 23:50:57 -0800 (PST) From: Hans de Goede To: libcamera-devel@lists.libcamera.org, Milan Zamazal Cc: Hans de Goede Subject: [PATCH v5 3/5] software_isp: debayer_cpu: Add multi-threading support Date: Wed, 4 Mar 2026 08:50:50 +0100 Message-ID: <20260304075052.11599-4-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260304075052.11599-1-johannes.goede@oss.qualcomm.com> References: <20260304075052.11599-1-johannes.goede@oss.qualcomm.com> MIME-Version: 1.0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzA0MDA2MiBTYWx0ZWRfX04yOHmJTkvo+ 0fnprhJIhRyBGL9DNZAcLsV1kA4PA2fhQlv9tYhDb5xrM6rstxfQHSVqSXI5j6kRbEXaQHQQ9U6 jyUVRCG4dEeVTHzYQirYs+72abiJfE1X9yGMURCo+Deuf4xIAxq56lomsw2ufSuAjBUUtXMMt35 HYscxBJ9BIDo2a4Z5zKopBJBQ//nWujgzqRNYkMbzGK5cVxd8jE37gRWtqMvhuq4pH432LpPZLM YVOOmHmRPxesw55Efzfnb38clqvx4FHwtLMHPWENRp/0mPZMoP7Yr2bd7SA/CZqY3huqUs/pFkO SMXQj7ZwAcAEj149KMSO/jwLHPeisq9Ov7HO9YPdKjTxTh6sC3gsqH2foHZx8eCnAkZ4iIBiaTe AbUlWNDhJdafLypHz8eirxvnIVpL29OOhAqym8HiQ4s/IgXiyLs2eOqcjS+IbhC3qbSZVLjWeQl SJAogZ7d5BkW+T3LjHA== X-Authority-Analysis: v=2.4 cv=VYv6/Vp9 c=1 sm=1 tr=0 ts=69a7e463 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=xqWC_Br6kY4A:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=4i1XYD-pSnUufzSozdQA:9 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-GUID: qVGW4iuvJhaBZHaEVmSlfEUl9BBZrR9a X-Proofpoint-ORIG-GUID: qVGW4iuvJhaBZHaEVmSlfEUl9BBZrR9a X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1121, Hydra:6.1.51, FMLib:17.12.100.49 definitions=2026-03-04_02,2026-03-03_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 bulkscore=0 adultscore=0 spamscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603040062 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" Add CPU soft ISP multi-threading support. Benchmark results for the Arduino Uno-Q with a weak CPU which is good for performance testing, all numbers with an IMX219 running at 3280x2464 -> 3272x2464: 1 thread : 147ms / frame, ~6.5 fps 2 threads: 80ms / frame, ~12.5 fps 3 threads: 65ms / frame, ~15 fps Adding a 4th thread does not improve performance. Signed-off-by: Hans de Goede Reviewed-by: Milan Zamazal --- Changes in v5: - Extend software_isp.threads docs in runtime_configuration.rst Changes in v4: - Document software_isp.threads option in runtime_configuration.rst - Add an use constants for min/max/default number of threads Changes in v3: - Adjust for DebayerCpuThread now inheriting from Thread - Use for (auto &thread : threads_) Changes in v2: - Adjust to use the new DebayerCpuThread class introduced in the v2 patch-series - Re-use threads instead of starting new threads every frame --- Documentation/runtime_configuration.rst | 8 ++++ src/libcamera/software_isp/debayer_cpu.cpp | 45 ++++++++++++++++++++-- src/libcamera/software_isp/debayer_cpu.h | 10 +++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst index e99ef2fb9..651929a4d 100644 --- a/Documentation/runtime_configuration.rst +++ b/Documentation/runtime_configuration.rst @@ -51,6 +51,7 @@ file structure: measure: skip: # non-negative integer, frames to skip initially number: # non-negative integer, frames to measure + threads: # integer >= 1, number of render threads to use, default 2 Configuration file example -------------------------- @@ -84,6 +85,7 @@ Configuration file example measure: skip: 50 number: 30 + threads: 2 List of variables and configuration options ------------------------------------------- @@ -167,6 +169,12 @@ software_isp.measure.skip, software_isp.measure.number Example `number` value: ``30`` +software_isp.threads + Number of render threads the software ISP uses when using the CPU. + This must be between 1 and 8 and the default is 2. + + Example value: ``2`` + Further details --------------- diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index d57d640df..f7c3e1751 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -76,6 +76,7 @@ DebayerCpuThread::DebayerCpuThread(DebayerCpu *debayer, unsigned int threadIndex debayer_(debayer), threadIndex_(threadIndex), enableInputMemcpy_(enableInputMemcpy) { + moveToThread(this); } /** @@ -107,8 +108,10 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfigurat bool enableInputMemcpy = configuration.option({ "software_isp", "copy_input_buffer" }).value_or(true); - /* Just one thread object for now, which will be called inline rather than async */ - threads_.resize(1); + unsigned int threadCount = + configuration.option({ "software_isp", "threads" }).value_or(kDefaultThreads); + threadCount = std::clamp(threadCount, kMinThreads, kMaxThreads); + threads_.resize(threadCount); for (unsigned int i = 0; i < threads_.size(); i++) threads_[i] = std::make_unique(this, i, enableInputMemcpy); @@ -746,6 +749,11 @@ void DebayerCpuThread::process(uint32_t frame, const uint8_t *src, uint8_t *dst) process2(frame, src, dst); else process4(frame, src, dst); + + debayer_->workPendingMutex_.lock(); + debayer_->workPending_ &= ~(1 << threadIndex_); + debayer_->workPendingMutex_.unlock(); + debayer_->workPendingCv_.notify_one(); } void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst) @@ -985,7 +993,21 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output stats_->startFrame(frame); - threads_[0]->process(frame, in.planes()[0].data(), out.planes()[0].data()); + workPendingMutex_.lock(); + workPending_ = (1 << threads_.size()) - 1; + workPendingMutex_.unlock(); + + for (auto &thread : threads_) + thread->invokeMethod(&DebayerCpuThread::process, + ConnectionTypeQueued, frame, + in.planes()[0].data(), out.planes()[0].data()); + + { + MutexLocker locker(workPendingMutex_); + workPendingCv_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(workPendingMutex_) { + return workPending_ == 0; + }); + } metadata.planes()[0].bytesused = out.planes()[0].size(); @@ -1004,6 +1026,23 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output inputBufferReady.emit(input); } +int DebayerCpu::start() +{ + for (auto &thread : threads_) + thread->start(); + + return 0; +} + +void DebayerCpu::stop() +{ + for (auto &thread : threads_) + thread->exit(); + + for (auto &thread : threads_) + thread->wait(); +} + SizeRange DebayerCpu::sizes(PixelFormat inputFormat, const Size &inputSize) { Size patternSize = this->patternSize(inputFormat); diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 780576090..11280c0a1 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -16,6 +16,7 @@ #include #include +#include #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/global_configuration.h" @@ -41,6 +42,8 @@ public: std::tuple strideAndFrameSize(const PixelFormat &outputFormat, const Size &size); void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms); + int start(); + void stop(); SizeRange sizes(PixelFormat inputFormat, const Size &inputSize); const SharedFD &getStatsFD() { return stats_->getStatsFD(); } @@ -144,6 +147,13 @@ private: std::unique_ptr stats_; unsigned int xShift_; /* Offset of 0/1 applied to window_.x */ + static constexpr unsigned int kMinThreads = 1; + static constexpr unsigned int kMaxThreads = 8; + static constexpr unsigned int kDefaultThreads = 2; + + unsigned int workPending_ LIBCAMERA_TSA_GUARDED_BY(workPendingMutex_); + Mutex workPendingMutex_; + ConditionVariable workPendingCv_; std::vector>threads_; };