{"id":25108,"url":"https://patchwork.libcamera.org/api/patches/25108/?format=json","web_url":"https://patchwork.libcamera.org/patch/25108/","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":"<20251120232019.3590-8-bryan.odonoghue@linaro.org>","date":"2025-11-20T23:20:04","name":"[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/25108/mbox/","series":[{"id":5599,"url":"https://patchwork.libcamera.org/api/series/5599/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5599","date":"2025-11-20T23:19:57","name":"GPUISP precursor series","version":1,"mbox":"https://patchwork.libcamera.org/series/5599/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25108/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25108/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 24221C3330\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 20 Nov 2025 23:20:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CC04960AB0;\n\tFri, 21 Nov 2025 00:20:40 +0100 (CET)","from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EFC560A8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Nov 2025 00:20:38 +0100 (CET)","by mail-wm1-x330.google.com with SMTP id\n\t5b1f17b1804b1-477632b0621so9995585e9.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 Nov 2025 15:20:38 -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-477bf3af0ecsm11618415e9.9.2025.11.20.15.20.36\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 20 Nov 2025 15:20:36 -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=\"NBFfqUa/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1763680837; x=1764285637;\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=NBFfqUa/hkNakrcxFrUcTTukOVT7ErW/HG6/Q2wusKRAJhf2T68b1L3X00m31hsILa\n\t/R2+vHY1Ap1lwLu+hhe8+E5zm2wLK4ZcCEixwbAvipX9J+473ZTvbxQP/qfEERi6mwZu\n\tAckq2aJPwNOI7ZG6iAehAmYBpruwFdldyr9ABHWaaV/CU9z1EWV7/4iOUsdlTPSWKdbm\n\te58HDQeDYLaPItVfQ+HlzbOcKh5pXbe/AIjzD3g+Tnz9Kbay3PJDwMVuYIK+lRJ51518\n\t6NbaUTKayJqFeWmdvpBN0rnZ0IGzwlibu5gLbu0ZhGBMCwWQj+Km/P4d3WrIqRlMsjH7\n\t9evQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1763680837; x=1764285637;\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=CvEVnWJux2OTUCR8KMvgsOaLwAfnl9CZEHx42PHy9F4Curh1LyALdv/WPibTx+awbE\n\tZ7vjJ3SErRDE3t3SH84EgEMGUArSfBS2Ewtnx3ALu8aJXOMgoOhby4Fo2/1FlcjB/WH9\n\tA8IUUxj2cfg6TukQ+oPSs4TLxeFPXhFmQ+f1n0p25AyPTKLYCt6okfFTBTk6cFKqNQGn\n\tDKP50HX9D+SxrfUjRCcdGQ9elbR1LhLV+Es79aru9L9GxQdmhgfzpmXeEHnFvoW1qOiY\n\tNJQSX6G2CS1uc0jsNp8r2gQpOQgLRUsKSrmr3tRkPpvf7ofRTiOMmbLWF4G+unx90fFj\n\tAk5w==","X-Gm-Message-State":"AOJu0Yw5y5fmXWjoP0ivJVzOJQ4fKfyNRQjbx/Uce5HgWJLaHI5qK1mn\n\tfti5YUpo02YooaLfD+IPlQ0jgncbhTkHCCYB7qFsh7YfOslU5FHZIbYKsWSLx8IUz+BUCk6zQS+\n\txMps+mOQ=","X-Gm-Gg":"ASbGncs/9+0oj/38jGNibUP9A1maaarWlC027CqCAAcCX/U9nsKK5s0DrEoTnUxNICp\n\t0a68xQrUbKILuPx/oMuUudYLQIsSGjvQ4Inmoa/KTj+4mCnjWxITo6u5hX9wnkq6DIVC41lWvEV\n\t3j7dvXxWocJGBkQH/L3476gLAz5mLUwkUckAbjpDopFLYADUfF0F4y1et72GQMW/QEFzhTGJk4l\n\t5ebGwIL07GTZoD5eOSByfb9IFradHFmMlTXmqtQO5tizjdmVcKOaZH1kYQk8foCv22TD9Cs3BgZ\n\t/OcWK4Mhk1xvNh4z2vckBYoCUZOYJWSo79Mmynkglxz7c8PKH6azoYvM2rM5mML3DbVGSTWxU0w\n\tDxC/8BEdlrE6UrOd+FJqcV0dK1b4HwPGl8uTCyYAJku3MFWid3Ojd2prz0FgwQ/Gyk3bhYrllSD\n\tz+LUveHJdEL0C2X4XCvjdMgXCUUOUszjCVXbPyvmF/qd+fBXqwS1fYBo7HKgmi2qW/p2w=","X-Google-Smtp-Source":"AGHT+IEi63MqipVcjTBhKxKTUJrxDud+upCl2qZtVYkaKvHcmXdRDZhrCsljFLXPub4QwFNlhDOdUg==","X-Received":"by 2002:a05:600c:a07:b0:477:a219:cdb7 with SMTP id\n\t5b1f17b1804b1-477c10523aamr1053605e9.0.1763680837367; \n\tThu, 20 Nov 2025 15:20:37 -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 07/22] libcamera: software_isp: Move benchmark code to its\n\town class","Date":"Thu, 20 Nov 2025 23:20:04 +0000","Message-ID":"<20251120232019.3590-8-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.51.2","In-Reply-To":"<20251120232019.3590-1-bryan.odonoghue@linaro.org>","References":"<20251120232019.3590-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":["07/22"]}