{"id":25221,"url":"https://patchwork.libcamera.org/api/patches/25221/?format=json","web_url":"https://patchwork.libcamera.org/patch/25221/","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":"<20251127022256.178929-8-bryan.odonoghue@linaro.org>","date":"2025-11-27T02:22:39","name":"[v2,07/22] 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/25221/mbox/","series":[{"id":5616,"url":"https://patchwork.libcamera.org/api/series/5616/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5616","date":"2025-11-27T02:22:32","name":"GPUISP precursor series","version":2,"mbox":"https://patchwork.libcamera.org/series/5616/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25221/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25221/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 1B27BC3260\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Nov 2025 02:23:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B009060AA9;\n\tThu, 27 Nov 2025 03:23:22 +0100 (CET)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 58CC460A9D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Nov 2025 03:23:19 +0100 (CET)","by mail-wm1-x32c.google.com with SMTP id\n\t5b1f17b1804b1-477a2ab455fso2940405e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Nov 2025 18:23:19 -0800 (PST)","from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4790b0e21e8sm71549495e9.15.2025.11.26.18.23.15\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 26 Nov 2025 18:23:17 -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=\"oBnt5cj+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1764210199; x=1764814999;\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=ghAief1BczG8dBZtklHiLxUtm0S3sgE9QT1CVt2nttY=;\n\tb=oBnt5cj+H5I232IFRbAC8HqDUdBRVXAF4iHeeSKe4iQkUzFHU+ZlL1DZbJ6j7+ppUs\n\tz5GnJj+IdlmszfhKqzoStW1FbY0d0ViGjsFWG9YEUylR9u6OiNbqyZV2CbFNxIFAhYCt\n\twBbnMRGQr1zi4gNYRvcrrXBUE09dCpHkZzLFApyHg4u9JmOL9Eq5g+y7DBKY3uivqvQM\n\t7o9tLFDkqM46IfG2unGmttNtHJMIn6yvChczAUQzYLngEwF9QomFWqwrP51BZ1Ci5+pT\n\taH9fkLbd43zwBH54zMadyXylIVBm5klbCjU/QoPhpNx8M2I6lsVcvGGpsjBDVf47Fc2O\n\tQQ4Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1764210199; x=1764814999;\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=ghAief1BczG8dBZtklHiLxUtm0S3sgE9QT1CVt2nttY=;\n\tb=KhWHPlqlYZjIP0CzowqATZXGrESuuE+u7vNHw6Ms0YJ+teyBKo6jh+zKr07SMQL5pW\n\te+XkgWZG29y0BL2roiZl93yhKK2j9rn0KQCvp5sB+PRpWaKO1QzR2f7xVfNUSbHp6Rs3\n\t4GntlNIbHa1RfTWyuSHYkxJaCzAObvxRYjDeHmFwi7E72hRgyW6NpfoBxwl8AMDwnGya\n\tvyiWqUg+wfq+UD49TKcEftIB3k8BVs50H9Xht1dj94rkLShKhNxmuJI1CVLXFGTQD4+2\n\tnBPaQKhUNAVoBGHwSlL7aRrbVNCEVE7NB7pxG3IPgLai5jJtG0gj7n5yCwqvLRGhP5Om\n\tqyhQ==","X-Gm-Message-State":"AOJu0YyNcOSVFtRpRiEzJp3Z9mVWKHlS41vKLTHW1fZO+KePBPPMxcNk\n\t85uuMMEUK1C8EggYW6uWwaJmr/7u1m6iTJ7LuQAJ4vbW8xNaaj4LJOV8Vyn5M1oQJ7yfV7icjH9\n\tbGChhv3g=","X-Gm-Gg":"ASbGnculTzYBBmyyUBugQaObGm6eESKaq/r3PdmJxeuR6L8BT9cJGopbkxxenoBpO91\n\tqGl0niTr5KzFyMlAw7iIgHfplcM0958d4ic46xNi6Jbza+AA4Kf//Wl144WrsIkn4L2Et07ur5V\n\tqx7SNjRffOxybrg4afYHYmVkjyR2q1Bl/sqPURkHCR//npZP8qDJD4Tb3qO/d9vU4nYFsfB512h\n\toEn2Prpy4s2849H1A37R5T7pnx31/0JnNEV8uk55TmKzlfR7342NxrFx6WQi7ZQyadRm+pp2sm5\n\tVfhF0LezmjVDorzXMwpeM3++Bg+AlicQe8Y52/Xe3LB0U5D1u5WvGYUvhLcd/jEfZQXimA0c8/m\n\tSJR4q632u3I/Zj7zgleuCUqbZjYHUFdHfkxYdXycR5dz43D6c/e596dE6BCrZDxooq/gYw80fT+\n\tvSNp3iOTXUZYyJKz2D13NcsONdeOygDRvZwtF32kSCsci73YdtLlccXrbmGMQLReoIkAE=","X-Google-Smtp-Source":"AGHT+IGpqWkgYJ279IAcLHPS8Dd6KRGh5emfjUUCY0Q3U2V2wzisj4t2/8V0Pxk4U7EJiN9jiqepcg==","X-Received":"by 2002:a05:600c:474a:b0:477:b0b9:3137 with SMTP id\n\t5b1f17b1804b1-477c10c8886mr221386165e9.1.1764210198591; \n\tWed, 26 Nov 2025 18:23:18 -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 v2 07/22] libcamera: software_isp: Move benchmark code to its\n\town class","Date":"Thu, 27 Nov 2025 02:22:39 +0000","Message-ID":"<20251127022256.178929-8-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.51.2","In-Reply-To":"<20251127022256.178929-1-bryan.odonoghue@linaro.org>","References":"<20251127022256.178929-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":["v2","07/22"]}