{"id":25403,"url":"https://patchwork.libcamera.org/api/patches/25403/?format=json","web_url":"https://patchwork.libcamera.org/patch/25403/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20251210003139.43606-8-bryan.odonoghue@linaro.org>","date":"2025-12-10T00:31:24","name":"[v4,07/20] libcamera: software_isp: Move benchmark code to its own class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e649df0ecaf565f7fcee3de762f7979ab1801975","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/?format=json","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25403/mbox/","series":[{"id":5644,"url":"https://patchwork.libcamera.org/api/series/5644/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5644","date":"2025-12-10T00:31:17","name":"GPUISP precursor series","version":4,"mbox":"https://patchwork.libcamera.org/series/5644/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25403/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25403/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 94DD8BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Dec 2025 00:32:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5927A6143D;\n\tWed, 10 Dec 2025 01:32:17 +0100 (CET)","from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com\n\t[IPv6:2607:f8b0:4864:20::102d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 416E26142A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Dec 2025 01:32:16 +0100 (CET)","by mail-pj1-x102d.google.com with SMTP id\n\t98e67ed59e1d1-343806688c5so5084700a91.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 09 Dec 2025 16:32:16 -0800 (PST)","from inspiron14p-linux (p96936b06.osaknt01.ap.so-net.ne.jp.\n\t[150.147.107.6]) by smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-34a70427ea6sm566580a91.3.2025.12.09.16.32.12\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 09 Dec 2025 16:32:13 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"dxfwUT5K\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1765326735; x=1765931535;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=yyoWJ0Rzqed6amy1jTZnt8wvjKyWv6LvwRUBP/6g4Vc=;\n\tb=dxfwUT5KvYlG/X6LGId5XPhHakZztExv9yPfOGKM50lxYtZTLsPaiOqITWX46ESk1f\n\tlDpu/NquLvWWZF1ZXBItqU1xok/10CEmkqMoJ/E4K9vOKXfZfQWNncPizBbkeNLHMjj+\n\t3dPUVhCf9/FAQ+GhsytPCoUgvw4ivmBODF1VRZqaVeyFCqiqcqYLMeFNAvQeJW706Dn6\n\tnNsyxju5eZsmJ1tW7DCLN52rYwN9e67zNIa9oETthHQVVdW/HGaAQFOaTehNGSzGwi7a\n\tgYVZ+a60ckKaSmIsqa4lbJLFlsmYvakgjQ1G+ZEiGUuCIMg7C3BVyFhgRovyt08uCFGx\n\tdSKA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1765326735; x=1765931535;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=yyoWJ0Rzqed6amy1jTZnt8wvjKyWv6LvwRUBP/6g4Vc=;\n\tb=qpevKxPUxxlDrY0RUqg5k5RE/EydPmehPC91jOZeIIrHBpkpj6DQKsljjF1FXbWOIw\n\tDaxRKtZkAJX1tnqcUKm8KIIfbvQvLe/RDPRBC6zSabEAuct8CI81Om8KezEnZUhDDamy\n\t40MxMXFTs8yDGnaiuRX1UnQQpeDrZr8DYdzHxpSbJ27HuROZcfeZVBEHsaVZQxmc+VGn\n\tMRNXh0xkomPKMGMXb/WuKgtDd4h3mJbC+t494CKaff1OKnTAtmsIsh0sAh/qoNQZkmwA\n\t+WoL4L4K0MQexgmrehdditCW/wRfuVwKmFUPYVFH/Tisufa0ToRnE51+iwSZMOySB7I1\n\txYDw==","X-Gm-Message-State":"AOJu0YxX09wZnTOcSaKMg08vTvNLfdVFZstfQzUSikgV8zw12RuJ+o/T\n\t+wYF9xqXC0nfI2Wi/F8/8qk+WFDIlEEAKtlhGfGsaUTmrNJT4W053qtrHreQB9EzfNXt/JqjgrO\n\t6ssGW","X-Gm-Gg":"AY/fxX72o6dVQxNdpYiHHy2EoRTVeuksDCgwQ7ybhHAhoRudVN3nIYvHdg7kkcpMcXv\n\twv4A2tj8652lZC4WFLz7l+r160t9B4Gl2warY1kPQN1kdVWd48sOxweslE0Y3NZTHWwE7jbIpuy\n\tITR4y6YeJFABtVmrY23AzCMrhpY1wr00UGhyGDzMwShRJ/YyBiv/9QiBZ8t6dZ9KiW2UEDI2Peo\n\td2P7/zYVr/xw8q33IMHyOTwLzH4DmgF+V77yNTQ2Y74WdIcq7wq1Efm8ob/t9Gktnm4gMd0Rlog\n\tJj92UjTeEvA+mxfunYC8zt2BEDr7OdgwkIdf9OFrcVrmxw+TyQHHUyF9rVHaTJDHM4F+JTFW0Qc\n\tZajDjPP/vHRtCSMTb4zY0T8HBucPyUFXVnBAxwPwD0sb37QlGgQfje9l3mYsBa5+6UT0EKXpt15\n\tqY5QoXp1s4xE2cBX7Uth6Uxcdr1HKK8L1tYFiK4nIkuFpeQjGUXYoXMKktnKO7V+Hb","X-Google-Smtp-Source":"AGHT+IF+AI42JB2cf4l/k1dHq4hmvztuZKHFOEdpUey0UO1JIkYsx7aE9VfSSCJkz2qnTRWbGKsbkQ==","X-Received":"by 2002:a17:90b:584f:b0:340:f40c:169c with SMTP id\n\t98e67ed59e1d1-34a72887e16mr429095a91.32.1765326734497; \n\tTue, 09 Dec 2025 16:32:14 -0800 (PST)","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","To":"libcamera-devel@lists.libcamera.org","Cc":"pavel@ucw.cz, Hans de Goede <hdegoede@redhat.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tMilan Zamazal <mzamazal@redhat.com>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>","Subject":"[PATCH v4 07/20] libcamera: software_isp: Move benchmark code to its\n\town class","Date":"Wed, 10 Dec 2025 00:31:24 +0000","Message-ID":"<20251210003139.43606-8-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20251210003139.43606-1-bryan.odonoghue@linaro.org>","References":"<20251210003139.43606-1-bryan.odonoghue@linaro.org>","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":"From: Hans de Goede <hdegoede@redhat.com>\n\nMove the code for the builtin benchmark to its own small\nBenchmark class.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n[bod: Fixed up some drift in this patch since initial propostion]\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n .../internal/software_isp/benchmark.h         | 39 ++++++++\n .../internal/software_isp/meson.build         |  1 +\n src/libcamera/software_isp/benchmark.cpp      | 92 +++++++++++++++++++\n src/libcamera/software_isp/debayer_cpu.cpp    | 45 +--------\n src/libcamera/software_isp/debayer_cpu.h      |  6 +-\n src/libcamera/software_isp/meson.build        |  1 +\n 6 files changed, 138 insertions(+), 46 deletions(-)\n create mode 100644 include/libcamera/internal/software_isp/benchmark.h\n create mode 100644 src/libcamera/software_isp/benchmark.cpp","diff":"diff --git a/include/libcamera/internal/software_isp/benchmark.h b/include/libcamera/internal/software_isp/benchmark.h\nnew file mode 100644\nindex 000000000..0680d6cd9\n--- /dev/null\n+++ b/include/libcamera/internal/software_isp/benchmark.h\n@@ -0,0 +1,39 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Red Hat Inc.\n+ *\n+ * Authors:\n+ * Hans de Goede <hdegoede@redhat.com>\n+ *\n+ * Simple builtin benchmark to measure software ISP processing times\n+ */\n+\n+#pragma once\n+\n+#include <stdint.h>\n+#include <time.h>\n+#include <libcamera/base/log.h>\n+#include \"libcamera/internal/global_configuration.h\"\n+\n+namespace libcamera {\n+\n+class Benchmark\n+{\n+public:\n+\tBenchmark(const GlobalConfiguration &configuration);\n+\t~Benchmark();\n+\n+\tvoid startFrame(void);\n+\tvoid finishFrame(void);\n+\n+private:\n+\ttimespec frameStartTime_;\n+\tbool measure;\n+\t/* Skip 30 frames for things to stabilize then measure 30 frames */\n+\tunsigned int encounteredFrames_ = 0;\n+\tint64_t frameProcessTime_ = 0;\n+\tunsigned int skipBeforeMeasure_ = 30;\n+\tunsigned int framesToMeasure_ = 30;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build\nindex ea3f3f1c1..df7c3b97d 100644\n--- a/include/libcamera/internal/software_isp/meson.build\n+++ b/include/libcamera/internal/software_isp/meson.build\n@@ -1,6 +1,7 @@\n # SPDX-License-Identifier: CC0-1.0\n \n libcamera_internal_headers += files([\n+    'benchmark.h',\n     'debayer_params.h',\n     'software_isp.h',\n     'swisp_stats.h',\ndiff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp\nnew file mode 100644\nindex 000000000..1a00ae569\n--- /dev/null\n+++ b/src/libcamera/software_isp/benchmark.cpp\n@@ -0,0 +1,92 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Red Hat Inc.\n+ *\n+ * Authors:\n+ * Hans de Goede <hdegoede@redhat.com>\n+ *\n+ * Simple builtin benchmark to measure software ISP processing times\n+ */\n+\n+#include \"libcamera/internal/software_isp/benchmark.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Benchmark)\n+\n+/**\n+ * \\class Benchmark\n+ * \\brief Simple builtin benchmark\n+ *\n+ * Simple builtin benchmark to measure software ISP processing times.\n+ */\n+\n+/**\n+ * \\brief Constructs a Benchmark object\n+ */\n+Benchmark::Benchmark(const GlobalConfiguration &configuration)\n+{\n+\tskipBeforeMeasure_ = configuration.option<unsigned int>(\n+\t\t\t\t\t\t{ \"software_isp\", \"measure\", \"skip\" })\n+\t\t\t\t\t\t\t.value_or(skipBeforeMeasure_);\n+\tframesToMeasure_ = configuration.option<unsigned int>(\n+\t\t\t\t\t\t{ \"software_isp\", \"measure\", \"number\" })\n+\t\t\t\t\t\t\t.value_or(framesToMeasure_);\n+}\n+\n+Benchmark::~Benchmark()\n+{\n+}\n+\n+static inline int64_t timeDiff(timespec &after, timespec &before)\n+{\n+\treturn (after.tv_sec - before.tv_sec) * 1000000000LL +\n+\t       (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n+}\n+\n+/**\n+ * \\brief Start measuring process time for a single frame\n+ *\n+ * Call this function before processing frame data to start measuring\n+ * the process time for a frame.\n+ */\n+void Benchmark::startFrame(void)\n+{\n+\tmeasure = framesToMeasure_ > 0 &&\n+\t\t  encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ &&\n+\t\t  ++encounteredFrames_ > skipBeforeMeasure_;\n+\n+\tif (measure) {\n+\t\tframeStartTime_ = {};\n+\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_);\n+\t}\n+}\n+\n+/**\n+ * \\brief Finish measuring process time for a single frame\n+ *\n+ * Call this function after processing frame data to finish measuring\n+ * the process time for a frame.\n+ *\n+ * This function will log frame processing time information after\n+ * Benchmark::kLastFrameToMeasure frames have been processed.\n+ */\n+void Benchmark::finishFrame(void)\n+{\n+\tif (measure) {\n+\t\ttimespec frameEndTime = {};\n+\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime);\n+\t\tframeProcessTime_ += timeDiff(frameEndTime, frameStartTime_);\n+\t\tif (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) {\n+\t\t\tLOG(Benchmark, Info)\n+\t\t\t\t<< \"Processed \" << framesToMeasure_\n+\t\t\t\t<< \" frames in \" << frameProcessTime_ / 1000 << \"us, \"\n+\t\t\t\t<< frameProcessTime_ / (1000 * framesToMeasure_)\n+\t\t\t\t<< \" us/frame\";\n+\t\t}\n+\t}\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 67a303c65..b92c6a904 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -42,7 +42,7 @@ namespace libcamera {\n  * \\param[in] configuration The global configuration\n  */\n DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration)\n-\t: stats_(std::move(stats))\n+\t: stats_(std::move(stats)), bench_(configuration)\n {\n \t/*\n \t * Reading from uncached buffers may be very slow.\n@@ -58,13 +58,6 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfigurat\n \tenableInputMemcpy_ =\n \t\tconfiguration.option<bool>({ \"software_isp\", \"copy_input_buffer\" }).value_or(true);\n \n-\tskipBeforeMeasure_ = configuration.option<unsigned int>(\n-\t\t\t\t\t\t  { \"software_isp\", \"measure\", \"skip\" })\n-\t\t\t\t     .value_or(skipBeforeMeasure_);\n-\tframesToMeasure_ = configuration.option<unsigned int>(\n-\t\t\t\t\t\t{ \"software_isp\", \"measure\", \"number\" })\n-\t\t\t\t   .value_or(framesToMeasure_);\n-\n \t/* Initialize color lookup tables */\n \tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n \t\tred_[i] = green_[i] = blue_[i] = i;\n@@ -571,9 +564,6 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n \t\t\tlineBuffers_[i].resize(lineBufferLength_);\n \t}\n \n-\tencounteredFrames_ = 0;\n-\tframeProcessTime_ = 0;\n-\n \treturn 0;\n }\n \n@@ -765,27 +755,9 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst)\n \t}\n }\n \n-namespace {\n-\n-inline int64_t timeDiff(timespec &after, timespec &before)\n-{\n-\treturn (after.tv_sec - before.tv_sec) * 1000000000LL +\n-\t       (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n-}\n-\n-} /* namespace */\n-\n void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n {\n-\ttimespec frameStartTime;\n-\n-\tbool measure = framesToMeasure_ > 0 &&\n-\t\t       encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ &&\n-\t\t       ++encounteredFrames_ > skipBeforeMeasure_;\n-\tif (measure) {\n-\t\tframeStartTime = {};\n-\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n-\t}\n+\tbench_.startFrame();\n \n \tstd::vector<DmaSyncer> dmaSyncers;\n \tfor (const FrameBuffer::Plane &plane : input->planes())\n@@ -840,18 +812,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \tdmaSyncers.clear();\n \n \t/* Measure before emitting signals */\n-\tif (measure) {\n-\t\ttimespec frameEndTime = {};\n-\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime);\n-\t\tframeProcessTime_ += timeDiff(frameEndTime, frameStartTime);\n-\t\tif (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) {\n-\t\t\tLOG(Debayer, Info)\n-\t\t\t\t<< \"Processed \" << framesToMeasure_\n-\t\t\t\t<< \" frames in \" << frameProcessTime_ / 1000 << \"us, \"\n-\t\t\t\t<< frameProcessTime_ / (1000 * framesToMeasure_)\n-\t\t\t\t<< \" us/frame\";\n-\t\t}\n-\t}\n+\tbench_.finishFrame();\n \n \t/*\n \t * Buffer ids are currently not used, so pass zeros as its parameter.\ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 1cd411f26..aff32491e 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -17,6 +17,7 @@\n \n #include <libcamera/base/object.h>\n \n+#include \"libcamera/internal/software_isp/benchmark.h\"\n #include \"libcamera/internal/bayer_format.h\"\n #include \"libcamera/internal/global_configuration.h\"\n #include \"libcamera/internal/software_isp/swstats_cpu.h\"\n@@ -161,10 +162,7 @@ private:\n \tunsigned int xShift_; /* Offset of 0/1 applied to window_.x */\n \tbool enableInputMemcpy_;\n \tbool swapRedBlueGains_;\n-\tunsigned int encounteredFrames_;\n-\tint64_t frameProcessTime_;\n-\tunsigned int skipBeforeMeasure_ = 30;\n-\tunsigned int framesToMeasure_ = 30;\n+\tBenchmark bench_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build\nindex aac7eda7b..59fa5f02a 100644\n--- a/src/libcamera/software_isp/meson.build\n+++ b/src/libcamera/software_isp/meson.build\n@@ -8,6 +8,7 @@ if not softisp_enabled\n endif\n \n libcamera_internal_sources += files([\n+    'benchmark.cpp',\n     'debayer.cpp',\n     'debayer_cpu.cpp',\n     'software_isp.cpp',\n","prefixes":["v4","07/20"]}