Patch Detail
Show a patch.
GET /api/patches/22190/?format=api
{ "id": 22190, "url": "https://patchwork.libcamera.org/api/patches/22190/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22190/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20241205192519.49104-5-hdegoede@redhat.com>", "date": "2024-12-05T19:25:18", "name": "[resend,4/5] libcamera: software_isp: Move benchmark code to its own class", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "c5a0f995b18e08d412628858ecb008f6a654d64b", "submitter": { "id": 102, "url": "https://patchwork.libcamera.org/api/people/102/?format=api", "name": "Hans de Goede", "email": "hdegoede@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22190/mbox/", "series": [ { "id": 4853, "url": "https://patchwork.libcamera.org/api/series/4853/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4853", "date": "2024-12-05T19:25:14", "name": "libcamera: Add swstats_cpu::processFrame()", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4853/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22190/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22190/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 D5286BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 5 Dec 2024 19:25:41 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9DB036611B;\n\tThu, 5 Dec 2024 20:25:41 +0100 (CET)", "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 060D766120\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 5 Dec 2024 20:25:38 +0100 (CET)", "from mx-prod-mc-03.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-670-RZjf9BC0PwSrmdOzLrw9Aw-1;\n\tThu, 05 Dec 2024 14:25:35 -0500", "from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.15])\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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 901901955DC1; Thu, 5 Dec 2024 19:25:34 +0000 (UTC)", "from localhost.localdomain (unknown [10.39.192.39])\n\tby mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 3348819560A0; Thu, 5 Dec 2024 19:25:32 +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=\"ilxW+hIb\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1733426738;\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=Fkm6Z9TGbYwjOKjHcK9WgAGaxJp23PrH28S3rFC8FWU=;\n\tb=ilxW+hIbG65Mjp3evVA1CFodXCsago2zZ7RTFVGNraypx2L9QWSsWl5qGs4fGbSUG4rPSX\n\teW64mhT2Hlv6xkVn4l6P3WZyGYuKUqU6KmtjI4TniHusU0h16ATYNw6iQbbTqVDCSBthac\n\tDI3KvbXIAYaDLzxxzwTZd/uWW9boYOs=", "X-MC-Unique": "RZjf9BC0PwSrmdOzLrw9Aw-1", "X-Mimecast-MFC-AGG-ID": "RZjf9BC0PwSrmdOzLrw9Aw", "From": "Hans de Goede <hdegoede@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Milan Zamazal <mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH resend 4/5] libcamera: software_isp: Move benchmark code to\n\tits own class", "Date": "Thu, 5 Dec 2024 20:25:18 +0100", "Message-ID": "<20241205192519.49104-5-hdegoede@redhat.com>", "In-Reply-To": "<20241205192519.49104-1-hdegoede@redhat.com>", "References": "<20241205192519.49104-1-hdegoede@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.0 on 10.30.177.15", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "m90wB7XJTeNdHSRdnJb9z1fK7XVaVm2f04NLLjNH36o_1733426734", "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\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---\nChanges since the RFC:\n- Add doxygen documentation to for all the public methods\n---\n .../internal/software_isp/benchmark.h | 36 +++++++\n .../internal/software_isp/meson.build | 1 +\n src/libcamera/software_isp/benchmark.cpp | 93 +++++++++++++++++++\n src/libcamera/software_isp/debayer_cpu.cpp | 36 +------\n src/libcamera/software_isp/debayer_cpu.h | 7 +-\n src/libcamera/software_isp/meson.build | 1 +\n 6 files changed, 135 insertions(+), 39 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 00000000..8af25015\n--- /dev/null\n+++ b/include/libcamera/internal/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/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build\nindex ea3f3f1c..df7c3b97 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 00000000..b3da3c41\n--- /dev/null\n+++ b/src/libcamera/software_isp/benchmark.cpp\n@@ -0,0 +1,93 @@\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()\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+/**\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+\tif (measuredFrames_ >= Benchmark::kLastFrameToMeasure)\n+\t\treturn;\n+\n+\tframeStartTime_ = {};\n+\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_);\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 (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/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 31ab96ab..e0cfcab1 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -529,9 +529,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@@ -721,24 +718,9 @@ void DebayerCpu::process4(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-\tif (measuredFrames_ < DebayerCpu::kLastFrameToMeasure) {\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@@ -777,21 +759,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \tdmaSyncers.clear();\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 feb0452e..c0d1b03d 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/software_isp/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": [ "resend", "4/5" ] }