Show a patch.

GET /api/1.1/patches/23219/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23219,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/23219/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23219/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20250422215920.4297-7-bryan.odonoghue@linaro.org>",
    "date": "2025-04-22T21:58:59",
    "name": "[06/27] libcamera: software_isp: Move benchmark code to its own class",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": false,
    "hash": "202c2ffe1fbb02cba0a915ac6143c352b9876df6",
    "submitter": {
        "id": 175,
        "url": "https://patchwork.libcamera.org/api/1.1/people/175/?format=api",
        "name": "Bryan O'Donoghue",
        "email": "bryan.odonoghue@linaro.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23219/mbox/",
    "series": [
        {
            "id": 5142,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5142/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5142",
            "date": "2025-04-22T21:58:53",
            "name": "RFC: Add in a eGL based GPUISP in libcamera",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5142/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23219/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23219/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 39C43C32A2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Apr 2025 21:59:35 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E23C068B2A;\n\tTue, 22 Apr 2025 23:59:33 +0200 (CEST)",
            "from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com\n\t[IPv6:2a00:1450:4864:20::42c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FB7268AD9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Apr 2025 23:59:29 +0200 (CEST)",
            "by mail-wr1-x42c.google.com with SMTP id\n\tffacd0b85a97d-39efc1365e4so2059265f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Apr 2025 14:59:29 -0700 (PDT)",
            "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-44092d2eccesm2726615e9.20.2025.04.22.14.59.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 22 Apr 2025 14:59:27 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"H1KuB6ez\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1745359168; x=1745963968;\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=NL86VTXgXgeQtJwMlBiBDgKApRvuNu2cPMHijbRU9yo=;\n\tb=H1KuB6ez99mh9tg/2hpuplddll0/zET3UfRPoveuTvHrIFPvjh2BDfhg6zOKE7HFWy\n\tL3D70/D/RCx4M1hm2jZV2JMkjyjzb0fwF/aWYPLpyfwTMqhiLxt1oSaKFwvQOoUvPin4\n\tYvXr8YXwl/JQAaEMSZmdHhzTL6JXAN/PhMg7+8g6du+UZl9nURrKSxbQEXPiBQTbqupO\n\t6O1yiJ0jKyLdltj1w9tyfNbr/Z605qdOw1wcW9dJV253d2mLogSLBe92ydvRTfyRlTuV\n\t5T36wnVyN3jcpFp5SsAW1FfUmXzHq+tMZFDsPBH+w3uAjH5Qql5rzPPUtM66A9KLJwH1\n\twT6g==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1745359168; x=1745963968;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=NL86VTXgXgeQtJwMlBiBDgKApRvuNu2cPMHijbRU9yo=;\n\tb=Q9/C5Qd/RxzAb2Qpk5bItla0dzp376SVZ9yA+kUssCzMujKkMTHv512C6oQOzOHW2a\n\tyUm9mS7k6ePh66cDkkGNIQ/O+2aRcJwFNeLXjnt1Bq5iUuAn3kaG6m/nIJhp/9/oy8U9\n\tgSnn4u7yWUNRmRR8CfKTf2gSHSWWjZrD6+s3dWsez2hGb4g9lytZJjrQBTYYAjKMsnNJ\n\tKIclXJ4ZSu3dPudP704msyCJYotEEdhvILxWpDhoDdEuHhvEsSma5doFDFuPTK1DZvRA\n\tC/fY1knRw9DkPcAFg+qCpC6Xpspdd+fkjLxxrmlqQPrTBAaGQ9j3YBx6I8M6YR3ElO7C\n\t8StA==",
        "X-Gm-Message-State": "AOJu0YwyBY0UgRtud8XQ65U1cdYT5qFyBXshlmlFpGqXjQVn5XvnaGyW\n\tvY/1tMJGiM2K+r68Qs25Qb22266ZrCQXgwbHOjrgo89S2lAzPCKEggy2rwPSfZT7YpluLNTGV3H\n\tpGWY=",
        "X-Gm-Gg": "ASbGncsXx55o7urIK2oKRNeYX+shDfWZCw+EHl5IJyQsV6lVku8mOmogXf0GK/BhVQj\n\tKsp1CDVq5zO2nfv3M0WctpceLZ2/rkg0TQTPwFiyKjf+FQQkBtZ0QYcF0R8q4yrQt+8zyx7S22T\n\twjBKJY+llVoYwBts/WjFYGtd0Z55T5YxV7sNXPWTnz0KaGiQzWUHaFqweP0tU/R9aXOuhKuBlxd\n\thATCRW23URJiPtPQtnzwL/5wBj8SVcZP+1mQGLKMfDcJDW3f5zeJCq9tcoFuYVwGxG4nQ/1Mrgo\n\tp0UwlT5d7uRfURMSuxI3xUmA1voU/UmCA+TcOdy0MEOxH/vq71oUkufWw4h/ili//pZQgBatjXX\n\t7CENxqOtABA/RuOl0ryHj",
        "X-Google-Smtp-Source": "AGHT+IGiTgRjWIY/8L+Vth5Qai6xIQmdiAnk+4gf2Ep1fYEyxz6LqXb2MCYZWOX/09VAAa0CTASwJA==",
        "X-Received": "by 2002:a05:6000:22c7:b0:391:3988:1c97 with SMTP id\n\tffacd0b85a97d-39efba4af82mr14396217f8f.17.1745359168357; \n\tTue, 22 Apr 2025 14:59:28 -0700 (PDT)",
        "From": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org,\n\tbod.linux@nxsw.ie, Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH 06/27] libcamera: software_isp: Move benchmark code to its\n\town class",
        "Date": "Tue, 22 Apr 2025 22:58:59 +0100",
        "Message-ID": "<20250422215920.4297-7-bryan.odonoghue@linaro.org>",
        "X-Mailer": "git-send-email 2.49.0",
        "In-Reply-To": "<20250422215920.4297-1-bryan.odonoghue@linaro.org>",
        "References": "<20250422215920.4297-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---\nChanges since the RFC:\n- Add doxygen documentation to for all the public methods\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\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 508ddddc..a7e606d2 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 66f6038c..8d30bf4a 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -554,9 +554,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@@ -746,24 +743,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@@ -817,21 +799,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 926195e9..d6820d5e 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 \n #include \"debayer.h\"\n@@ -160,11 +161,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": [
        "06/27"
    ]
}