From patchwork Wed Oct 15 01:22:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 24652 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 60F5ABF415 for ; Wed, 15 Oct 2025 01:23:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B76E260629; Wed, 15 Oct 2025 03:23:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="M1VKP047"; dkim-atps=neutral Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 519DA6060D for ; Wed, 15 Oct 2025 03:23:02 +0200 (CEST) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-639e1e8c8c8so11576871a12.1 for ; Tue, 14 Oct 2025 18:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1760491381; x=1761096181; 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=/6kxvdjX0tzQocqho+X4IStbtmMCRaS8dOxX+24Nfqs=; b=M1VKP0470f+vSrNR2NwHZraXKEd9y8+NNPawXAld27aIfFj8q8MmZbpFVtKtsFextd Ruuwz1CWx0DuKV8CSxi0IjJOv3n2VsOMtCmeiurKogjm8Rj66UQPKCAvglJJCWgn0Ih5 BDgopB11v3u8GiVsnqWzUNg4Phs/BHF9n6AGe1Rp8iN3dTnQrUU4bT859PsnqI+34rST RadUBPQOZ1CQ+eKxKziqmlFovx1HmZQSUX66HcVYSSmHWZGIEeT/dFoIsBRyWZpcsjpw EMqv6gSM/mHDzinbj2o1EHEC15/QbxDBUEy70mbsrMO1/m1p4hvQoQZUUJ5AU6SyWCDW +olQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760491381; x=1761096181; 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=/6kxvdjX0tzQocqho+X4IStbtmMCRaS8dOxX+24Nfqs=; b=HuIkiiNf2iIyoZEB9HGdlt34zwHc1z4g/xZR0oXa0MAJvJnK6W3qHZXSoGCu3Wi2aI JFO5qndriYsPaxJnq8QsvQLSmdUbG9t6P7xeOnDMCfeZkA8PC7MCEN7nNkVDBu0Rqdma ANPLMtiCzCcczlIpdi/5yFepl7vrEVNlapGRf5n4H7T9DNLpfxdY+M5DtH48PgoMo6Kt Sb8UhIZGoPEYw5m6C8xhqvUAJRAisB6bD++USeV7rBomS6Or7pJ1BE18G/zhnaI4FLJG Smx2A5Y8aA6Yi4XzITHx2OJBmiEULj9hjazRR8/Ht19f72zxXMD1uz04i9S3JYXErhhB GAzw== X-Gm-Message-State: AOJu0YxlDuACY83nuKZ2oVsJZJjAiApHtk8B/nUNgEO8VicPBMj0nZfS lBZRmYqWszsM8Wu1urkjTTN3XwSWJfI5P5E7b3sZnHbSXnBUtB0uYH5kowsCtABpQRf/jyfCSkR Vp7Ic X-Gm-Gg: ASbGncugovpiTVyA9lvByiVI9jz6LOUeCD2axUvdfKisCHoqDnRcbBcH4tgwiBfmkdG fbVxiAU3TaGHHGwcYLZST79MNzSAduEyS/loZogNBiF/CTOkyfnVUx/S4NbPcdVH2B9tfOAVgGD vuu3Q7EI6DZshFzt3tarBbi61ZSTSfLkHJDvhgQOHiXEv0rjUR+E2NYa5eoqwqU6kC97aFDmmuO ccC511H7L2C/AGtgB6xfXjdkpjxpDC23dnKnyAja8IzrbBf3FWHY2UTGjX99JpDF3L29FDH5rBT fZKUQIi6lLDaeG8FKFqrFkVyx0wCUmBArhPtPKL/fU1+rYKir6ILRHnhDRb6a1TqPodhRYXO3KX FPwhEHHRptYCE5uwDsipVGjSLWcXvYTsWUzAsZLo+gtEZbpQdYQ+RQfDdotFO1pOu1xIJERIZ3H x/Xr+WkxlzduNSutgQD/M0jtEopB9uCweJ8pbI7QffSBiwCh0w40c= X-Google-Smtp-Source: AGHT+IELNu+IiopqU3iaNpdKTzn30axZoWZEswTys8EWxKhMAUQT2Qu4Tork4aafL+h+jABUCwmldA== X-Received: by 2002:a17:907:d86:b0:b40:8954:a8a9 with SMTP id a640c23a62f3a-b50ac0cc32amr2727847366b.34.1760491381586; Tue, 14 Oct 2025 18:23:01 -0700 (PDT) Received: from inspiron14p-linux.nxsw.local (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b5ccd7b202dsm98348466b.82.2025.10.14.18.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Oct 2025 18:23:01 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie, Kieran Bingham Subject: [PATCH v3 07/39] libcamera: software_isp: Move benchmark code to its own class Date: Wed, 15 Oct 2025 02:22:19 +0100 Message-ID: <20251015012251.17508-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251015012251.17508-1-bryan.odonoghue@linaro.org> References: <20251015012251.17508-1-bryan.odonoghue@linaro.org> 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" From: Hans de Goede Move the code for the builtin benchmark to its own small Benchmark class. Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede [bod: Fixed up some drift in this patch since initial propostion] Signed-off-by: Bryan O'Donoghue --- .../internal/software_isp/benchmark.h | 39 ++++++++ .../internal/software_isp/meson.build | 1 + src/libcamera/software_isp/benchmark.cpp | 92 +++++++++++++++++++ src/libcamera/software_isp/debayer_cpu.cpp | 45 +-------- src/libcamera/software_isp/debayer_cpu.h | 6 +- src/libcamera/software_isp/meson.build | 1 + 6 files changed, 138 insertions(+), 46 deletions(-) create mode 100644 include/libcamera/internal/software_isp/benchmark.h create mode 100644 src/libcamera/software_isp/benchmark.cpp diff --git a/include/libcamera/internal/software_isp/benchmark.h b/include/libcamera/internal/software_isp/benchmark.h new file mode 100644 index 00000000..0680d6cd --- /dev/null +++ b/include/libcamera/internal/software_isp/benchmark.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * Simple builtin benchmark to measure software ISP processing times + */ + +#pragma once + +#include +#include +#include +#include "libcamera/internal/global_configuration.h" + +namespace libcamera { + +class Benchmark +{ +public: + Benchmark(const GlobalConfiguration &configuration); + ~Benchmark(); + + void startFrame(void); + void finishFrame(void); + +private: + timespec frameStartTime_; + bool measure; + /* Skip 30 frames for things to stabilize then measure 30 frames */ + unsigned int encounteredFrames_ = 0; + int64_t frameProcessTime_ = 0; + unsigned int skipBeforeMeasure_ = 30; + unsigned int framesToMeasure_ = 30; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index ea3f3f1c..df7c3b97 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_internal_headers += files([ + 'benchmark.h', 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', diff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp new file mode 100644 index 00000000..1a00ae56 --- /dev/null +++ b/src/libcamera/software_isp/benchmark.cpp @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * Simple builtin benchmark to measure software ISP processing times + */ + +#include "libcamera/internal/software_isp/benchmark.h" + +#include + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Benchmark) + +/** + * \class Benchmark + * \brief Simple builtin benchmark + * + * Simple builtin benchmark to measure software ISP processing times. + */ + +/** + * \brief Constructs a Benchmark object + */ +Benchmark::Benchmark(const GlobalConfiguration &configuration) +{ + skipBeforeMeasure_ = configuration.option( + { "software_isp", "measure", "skip" }) + .value_or(skipBeforeMeasure_); + framesToMeasure_ = configuration.option( + { "software_isp", "measure", "number" }) + .value_or(framesToMeasure_); +} + +Benchmark::~Benchmark() +{ +} + +static inline int64_t timeDiff(timespec &after, timespec &before) +{ + return (after.tv_sec - before.tv_sec) * 1000000000LL + + (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; +} + +/** + * \brief Start measuring process time for a single frame + * + * Call this function before processing frame data to start measuring + * the process time for a frame. + */ +void Benchmark::startFrame(void) +{ + measure = framesToMeasure_ > 0 && + encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ && + ++encounteredFrames_ > skipBeforeMeasure_; + + if (measure) { + frameStartTime_ = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); + } +} + +/** + * \brief Finish measuring process time for a single frame + * + * Call this function after processing frame data to finish measuring + * the process time for a frame. + * + * This function will log frame processing time information after + * Benchmark::kLastFrameToMeasure frames have been processed. + */ +void Benchmark::finishFrame(void) +{ + if (measure) { + timespec frameEndTime = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); + frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); + if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { + LOG(Benchmark, Info) + << "Processed " << framesToMeasure_ + << " frames in " << frameProcessTime_ / 1000 << "us, " + << frameProcessTime_ / (1000 * framesToMeasure_) + << " us/frame"; + } + } +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index c2fb11ba..df77deb6 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -42,7 +42,7 @@ namespace libcamera { * \param[in] configuration The global configuration */ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfiguration &configuration) - : stats_(std::move(stats)) + : stats_(std::move(stats)), bench_(configuration) { /* * Reading from uncached buffers may be very slow. @@ -58,13 +58,6 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfigurat enableInputMemcpy_ = configuration.option({ "software_isp", "copy_input_buffer" }).value_or(true); - skipBeforeMeasure_ = configuration.option( - { "software_isp", "measure", "skip" }) - .value_or(skipBeforeMeasure_); - framesToMeasure_ = configuration.option( - { "software_isp", "measure", "number" }) - .value_or(framesToMeasure_); - /* Initialize color lookup tables */ for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { red_[i] = green_[i] = blue_[i] = i; @@ -571,9 +564,6 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, lineBuffers_[i].resize(lineBufferLength_); } - encounteredFrames_ = 0; - frameProcessTime_ = 0; - return 0; } @@ -765,27 +755,9 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst) } } -namespace { - -inline int64_t timeDiff(timespec &after, timespec &before) -{ - return (after.tv_sec - before.tv_sec) * 1000000000LL + - (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; -} - -} /* namespace */ - void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) { - timespec frameStartTime; - - bool measure = framesToMeasure_ > 0 && - encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ && - ++encounteredFrames_ > skipBeforeMeasure_; - if (measure) { - frameStartTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); - } + bench_.startFrame(); std::vector dmaSyncers; for (const FrameBuffer::Plane &plane : input->planes()) @@ -839,18 +811,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output dmaSyncers.clear(); /* Measure before emitting signals */ - if (measure) { - timespec frameEndTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); - frameProcessTime_ += timeDiff(frameEndTime, frameStartTime); - if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { - LOG(Debayer, Info) - << "Processed " << framesToMeasure_ - << " frames in " << frameProcessTime_ / 1000 << "us, " - << frameProcessTime_ / (1000 * framesToMeasure_) - << " us/frame"; - } - } + bench_.finishFrame(); /* * Buffer ids are currently not used, so pass zeros as its parameter. diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 1cd411f2..aff32491 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -17,6 +17,7 @@ #include +#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/global_configuration.h" #include "libcamera/internal/software_isp/swstats_cpu.h" @@ -161,10 +162,7 @@ private: unsigned int xShift_; /* Offset of 0/1 applied to window_.x */ bool enableInputMemcpy_; bool swapRedBlueGains_; - unsigned int encounteredFrames_; - int64_t frameProcessTime_; - unsigned int skipBeforeMeasure_ = 30; - unsigned int framesToMeasure_ = 30; + Benchmark bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index aac7eda7..59fa5f02 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -8,6 +8,7 @@ if not softisp_enabled endif libcamera_internal_sources += files([ + 'benchmark.cpp', 'debayer.cpp', 'debayer_cpu.cpp', 'software_isp.cpp',