{"id":21574,"url":"https://patchwork.libcamera.org/api/1.1/patches/21574/?format=json","web_url":"https://patchwork.libcamera.org/patch/21574/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20241009200110.275544-4-hdegoede@redhat.com>","date":"2024-10-09T20:01:09","name":"[RFC,3/4] libcamera: software_isp: Move benchmark code to its own class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"7550ad23e1e29950470554c15ecd48e452188a27","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/1.1/people/102/?format=json","name":"Hans de Goede","email":"hdegoede@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21574/mbox/","series":[{"id":4678,"url":"https://patchwork.libcamera.org/api/1.1/series/4678/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4678","date":"2024-10-09T20:01:06","name":"libcamera: swstats_cpu: Add processFrame() method","version":1,"mbox":"https://patchwork.libcamera.org/series/4678/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21574/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21574/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 8E468C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Oct 2024 20:01:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1D2F265372;\n\tWed,  9 Oct 2024 22:01:26 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F19406536B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 22:01:21 +0200 (CEST)","from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-144-be5ZwOUiM2GZl0ECkGY-tw-1;\n\tWed, 09 Oct 2024 16:01:19 -0400","from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.17])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid 9B03E1955F3F for <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 20:01:18 +0000 (UTC)","from shalem.redhat.com (unknown [10.39.192.36])\n\tby mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 2342B19560A3; Wed,  9 Oct 2024 20:01:16 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"X9bSE5mD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1728504080;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=Lpj81sTO6cStZvZlGpInBrMulksGPMk/qMxFVZCGUqg=;\n\tb=X9bSE5mDfk2XG1Dfi5s9QCuCrZH95DpBoHrga4IR6kHPb2aqWWrnIEWG0yhExa1PIEojaY\n\t/1NIAbGFhNfeSUn1m/M25GGCASbDY0MBgP0XR9tOaXyxmCvSXKVv6PyJ1LIVwFda5fnqgh\n\tBY+0Dg7n0YrWHUoLvUnyem9rH2aW5GQ=","X-MC-Unique":"be5ZwOUiM2GZl0ECkGY-tw-1","From":"Hans de Goede <hdegoede@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>, Maxime Ripard <mripard@redhat.com>, \n\tHans de Goede <hdegoede@redhat.com>","Subject":"[RFC 3/4] libcamera: software_isp: Move benchmark code to its own\n\tclass","Date":"Wed,  9 Oct 2024 22:01:09 +0200","Message-ID":"<20241009200110.275544-4-hdegoede@redhat.com>","In-Reply-To":"<20241009200110.275544-1-hdegoede@redhat.com>","References":"<20241009200110.275544-1-hdegoede@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.17","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","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":"Move the code for the builtin benchmark to its own small\nBenchmark class.\n\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n src/libcamera/software_isp/benchmark.cpp   | 78 ++++++++++++++++++++++\n src/libcamera/software_isp/benchmark.h     | 36 ++++++++++\n src/libcamera/software_isp/debayer_cpu.cpp | 32 +--------\n src/libcamera/software_isp/debayer_cpu.h   |  7 +-\n src/libcamera/software_isp/meson.build     |  1 +\n 5 files changed, 119 insertions(+), 35 deletions(-)\n create mode 100644 src/libcamera/software_isp/benchmark.cpp\n create mode 100644 src/libcamera/software_isp/benchmark.h","diff":"diff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp\nnew file mode 100644\nindex 00000000..eecad51c\n--- /dev/null\n+++ b/src/libcamera/software_isp/benchmark.cpp\n@@ -0,0 +1,78 @@\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 \"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()\n+\t: measuredFrames_(0), frameProcessTime_(0)\n+{\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+void Benchmark::startFrame(void)\n+{\n+\tif (measuredFrames_ >= Benchmark::kLastFrameToMeasure)\n+\t\treturn;\n+\n+\tframeStartTime_ = {};\n+\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_);\n+}\n+\n+void Benchmark::finishFrame(void)\n+{\n+\tif (measuredFrames_ >= Benchmark::kLastFrameToMeasure)\n+\t\treturn;\n+\n+\tmeasuredFrames_++;\n+\n+\tif (measuredFrames_ <= Benchmark::kFramesToSkip)\n+\t\treturn;\n+\n+\ttimespec frameEndTime = {};\n+\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime);\n+\tframeProcessTime_ += timeDiff(frameEndTime, frameStartTime_);\n+\n+\tif (measuredFrames_ == Benchmark::kLastFrameToMeasure) {\n+\t\tconst unsigned int measuredFrames = Benchmark::kLastFrameToMeasure -\n+\t\t\t\t\t\t    Benchmark::kFramesToSkip;\n+\t\tLOG(Benchmark, Info)\n+\t\t\t<< \"Processed \" << measuredFrames\n+\t\t\t<< \" frames in \" << frameProcessTime_ / 1000 << \"us, \"\n+\t\t\t<< frameProcessTime_ / (1000 * measuredFrames)\n+\t\t\t<< \" us/frame\";\n+\t}\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/benchmark.h b/src/libcamera/software_isp/benchmark.h\nnew file mode 100644\nindex 00000000..8af25015\n--- /dev/null\n+++ b/src/libcamera/software_isp/benchmark.h\n@@ -0,0 +1,36 @@\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+\n+namespace libcamera {\n+\n+class Benchmark\n+{\n+public:\n+\tBenchmark();\n+\t~Benchmark();\n+\n+\tvoid startFrame(void);\n+\tvoid finishFrame(void);\n+\n+private:\n+\tunsigned int measuredFrames_;\n+\tint64_t frameProcessTime_;\n+\ttimespec frameStartTime_;\n+\t/* Skip 30 frames for things to stabilize then measure 30 frames */\n+\tstatic constexpr unsigned int kFramesToSkip = 30;\n+\tstatic constexpr unsigned int kLastFrameToMeasure = 60;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex cf5ecdf7..897fb83b 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -528,9 +528,6 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n \t\t\tlineBuffers_[i].resize(lineBufferLength_);\n \t}\n \n-\tmeasuredFrames_ = 0;\n-\tframeProcessTime_ = 0;\n-\n \treturn 0;\n }\n \n@@ -739,22 +736,11 @@ void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)\n \t}\n }\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-\tif (measuredFrames_ < DebayerCpu::kLastFrameToMeasure) {\n-\t\tframeStartTime = {};\n-\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n-\t}\n+\tbench_.startFrame();\n \n \tsyncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ);\n \tsyncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE);\n@@ -790,21 +776,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \tsyncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);\n \n \t/* Measure before emitting signals */\n-\tif (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&\n-\t    ++measuredFrames_ > DebayerCpu::kFramesToSkip) {\n-\t\ttimespec frameEndTime = {};\n-\t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime);\n-\t\tframeProcessTime_ += timeDiff(frameEndTime, frameStartTime);\n-\t\tif (measuredFrames_ == DebayerCpu::kLastFrameToMeasure) {\n-\t\t\tconst unsigned int measuredFrames = DebayerCpu::kLastFrameToMeasure -\n-\t\t\t\t\t\t\t    DebayerCpu::kFramesToSkip;\n-\t\t\tLOG(Debayer, Info)\n-\t\t\t\t<< \"Processed \" << measuredFrames\n-\t\t\t\t<< \" frames in \" << frameProcessTime_ / 1000 << \"us, \"\n-\t\t\t\t<< frameProcessTime_ / (1000 * measuredFrames)\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 2c47e7c6..59015479 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -19,6 +19,7 @@\n \n #include \"libcamera/internal/bayer_format.h\"\n \n+#include \"benchmark.h\"\n #include \"debayer.h\"\n #include \"swstats_cpu.h\"\n \n@@ -153,11 +154,7 @@ private:\n \tunsigned int xShift_; /* Offset of 0/1 applied to window_.x */\n \tbool enableInputMemcpy_;\n \tbool swapRedBlueGains_;\n-\tunsigned int measuredFrames_;\n-\tint64_t frameProcessTime_;\n-\t/* Skip 30 frames for things to stabilize then measure 30 frames */\n-\tstatic constexpr unsigned int kFramesToSkip = 30;\n-\tstatic constexpr unsigned int kLastFrameToMeasure = 60;\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 aac7eda7..59fa5f02 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":["RFC","3/4"]}