From patchwork Thu Dec 11 23:22:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25501 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 52487C3257 for ; Thu, 11 Dec 2025 23:23:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F1CE61643; Fri, 12 Dec 2025 00:23:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pFVETq9Z"; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C04506162E for ; Fri, 12 Dec 2025 00:23:37 +0100 (CET) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7ade456b6abso498248b3a.3 for ; Thu, 11 Dec 2025 15:23:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765495416; x=1766100216; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yyoWJ0Rzqed6amy1jTZnt8wvjKyWv6LvwRUBP/6g4Vc=; b=pFVETq9ZUY1ZCsVxxPv//3v8ywHNkah/2vvxPc9SmJsBfW46jnvKNEZu/0n6I/qspQ k977NrhG7rXs7tdHgCmQ4vM0el8f1HDBYIZr3kYFd1FAl9gipvO2LKMF9QnS3y73RbGl F+RBM5Y1qvSu9+ruBu+j7oegO9Zj8+YQVfaw/OR8EokqfQ9aPccDUgpjuOSLXaOh+IKt nb35R6nFszFAGlp4lHpFS5ASdwtuHzcSkaLlo566nHsrlF95kkqY8aEuTucj0C2+op23 eAAYA+lO/Q9phtPOlpVMVAI1jHRKl95hz6REg+WUfSGHwYtj6p3BYgs+/Gu0Clklnq0t LdRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765495416; x=1766100216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yyoWJ0Rzqed6amy1jTZnt8wvjKyWv6LvwRUBP/6g4Vc=; b=RsaYpgz6L+i8mR31HELuU4w5o8zuGBgzC9FaFgDLGU6b/dqfciYQ4r7ZDAauVWWvoE BUNzFFi1W1iekqsLgkaOXlSXIzwX71U2xEHTj9RWsIzaC1O73mTia9YOf8S5ZZTpoUHn 1e4sfSWYIj4LaikzOghqcvDfpcKJoeWacwgJQdsA5holFw5Wq1KOjEJrjDj6QrrgbJMm lM1RbsYLFSeRdYIostdsrYZ+kfxbkQrCUQK5U9pP3KzJlFO3EyTfU+oi3r6iSGNmsWKu LeqpCwRBr3HWkhPFb7ga0aJKI1tg5sJ1Tz9I4+U2LouP3olqCexiew+nmcSqW20nnsbe owtw== X-Gm-Message-State: AOJu0YwJZwpFVwH+d/AGCViX8mKyeSer4/7PySkRqASYjlxeQuVksWx+ gFopuji2GCK0rWuW5Z2nNQnImj4TSmymaYO6WkqF8vRj1achi4sUwhMgtN0/u0NA61wRflkn9J5 yu22n X-Gm-Gg: AY/fxX5MECzUT04Ekk0u1LDPYdKpv92UDoGa/ApzKTzxHzZ+z7/o7CDUModVhX690fg sGp6TmeyGMoJIQ2yO8UIj+5QIoiHZ5Plg9HOlnsaw7lUqTeIR9I3lKsu57qpeTsGJ3WImZZRNu7 OetpXQMaq6GVpNbH3MrKMkiTm7BljRnAi08lYdOOLFoQnaoU/6Ehwvz2eg2SbKpRDSVP+o2FKN0 cBuIbgYo5qx5HeT0Z7FxWKj0NSAy5MKKV84D6As0Td++4xhWGmD7F9cUWwK5VEjlmWn5p18lCw+ mqJd7ONVw9KP2z6HoOv2Y4TQvj4ksahdCEO/UmT6EkCfHHquujevSrbsMSBbaduImP1rzp4DrYj SSGGMLCkpw8kPWBokR76EZzznbXMarzXUDgEjDMPSW6/8rnO5kJnzNHGiY04ilFwHNT3CcvOCcF HJ+EyK4JxHEDa6cq0qYwjQj7Q1gfJZctRMDbb1MHZ3ArY7qiJzpTZZmwigAdHmjw== X-Google-Smtp-Source: AGHT+IGbE1aZD3b8OZ3QcYgnlyk0aKGnmJvYcOviuY7pnbknc8oKcXDIT1qMeiVLq3A42cpApSppvw== X-Received: by 2002:a05:6a00:1d9d:b0:7e8:4471:8d0 with SMTP id d2e1a72fcca58-7f669a93165mr161366b3a.49.1765495416130; Thu, 11 Dec 2025 15:23:36 -0800 (PST) Received: from inspiron14p-linux (M106185144161.v4.enabler.ne.jp. [106.185.144.161]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7f4c4ab52aasm3399933b3a.38.2025.12.11.15.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 15:23:35 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Hans de Goede , Kieran Bingham , Milan Zamazal , Bryan O'Donoghue Subject: [PATCH v5 07/20] libcamera: software_isp: Move benchmark code to its own class Date: Thu, 11 Dec 2025 23:22:32 +0000 Message-ID: <20251211232246.31330-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251211232246.31330-1-bryan.odonoghue@linaro.org> References: <20251211232246.31330-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Hans de Goede Move the code for the builtin benchmark to its own small Benchmark class. Reviewed-by: Kieran Bingham Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede [bod: Fixed up some drift in this patch since initial propostion] Signed-off-by: Bryan O'Donoghue --- .../internal/software_isp/benchmark.h | 39 ++++++++ .../internal/software_isp/meson.build | 1 + src/libcamera/software_isp/benchmark.cpp | 92 +++++++++++++++++++ src/libcamera/software_isp/debayer_cpu.cpp | 45 +-------- src/libcamera/software_isp/debayer_cpu.h | 6 +- src/libcamera/software_isp/meson.build | 1 + 6 files changed, 138 insertions(+), 46 deletions(-) create mode 100644 include/libcamera/internal/software_isp/benchmark.h create mode 100644 src/libcamera/software_isp/benchmark.cpp diff --git a/include/libcamera/internal/software_isp/benchmark.h b/include/libcamera/internal/software_isp/benchmark.h new file mode 100644 index 000000000..0680d6cd9 --- /dev/null +++ b/include/libcamera/internal/software_isp/benchmark.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * Simple builtin benchmark to measure software ISP processing times + */ + +#pragma once + +#include +#include +#include +#include "libcamera/internal/global_configuration.h" + +namespace libcamera { + +class Benchmark +{ +public: + Benchmark(const GlobalConfiguration &configuration); + ~Benchmark(); + + void startFrame(void); + void finishFrame(void); + +private: + timespec frameStartTime_; + bool measure; + /* Skip 30 frames for things to stabilize then measure 30 frames */ + unsigned int encounteredFrames_ = 0; + int64_t frameProcessTime_ = 0; + unsigned int skipBeforeMeasure_ = 30; + unsigned int framesToMeasure_ = 30; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index ea3f3f1c1..df7c3b97d 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_internal_headers += files([ + 'benchmark.h', 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', diff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp new file mode 100644 index 000000000..1a00ae569 --- /dev/null +++ b/src/libcamera/software_isp/benchmark.cpp @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * + * Authors: + * Hans de Goede + * + * Simple builtin benchmark to measure software ISP processing times + */ + +#include "libcamera/internal/software_isp/benchmark.h" + +#include + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Benchmark) + +/** + * \class Benchmark + * \brief Simple builtin benchmark + * + * Simple builtin benchmark to measure software ISP processing times. + */ + +/** + * \brief Constructs a Benchmark object + */ +Benchmark::Benchmark(const GlobalConfiguration &configuration) +{ + skipBeforeMeasure_ = configuration.option( + { "software_isp", "measure", "skip" }) + .value_or(skipBeforeMeasure_); + framesToMeasure_ = configuration.option( + { "software_isp", "measure", "number" }) + .value_or(framesToMeasure_); +} + +Benchmark::~Benchmark() +{ +} + +static inline int64_t timeDiff(timespec &after, timespec &before) +{ + return (after.tv_sec - before.tv_sec) * 1000000000LL + + (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; +} + +/** + * \brief Start measuring process time for a single frame + * + * Call this function before processing frame data to start measuring + * the process time for a frame. + */ +void Benchmark::startFrame(void) +{ + measure = framesToMeasure_ > 0 && + encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ && + ++encounteredFrames_ > skipBeforeMeasure_; + + if (measure) { + frameStartTime_ = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); + } +} + +/** + * \brief Finish measuring process time for a single frame + * + * Call this function after processing frame data to finish measuring + * the process time for a frame. + * + * This function will log frame processing time information after + * Benchmark::kLastFrameToMeasure frames have been processed. + */ +void Benchmark::finishFrame(void) +{ + if (measure) { + timespec frameEndTime = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); + frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); + if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { + LOG(Benchmark, Info) + << "Processed " << framesToMeasure_ + << " frames in " << frameProcessTime_ / 1000 << "us, " + << frameProcessTime_ / (1000 * framesToMeasure_) + << " us/frame"; + } + } +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 67a303c65..b92c6a904 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -42,7 +42,7 @@ namespace libcamera { * \param[in] configuration The global configuration */ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfiguration &configuration) - : stats_(std::move(stats)) + : stats_(std::move(stats)), bench_(configuration) { /* * Reading from uncached buffers may be very slow. @@ -58,13 +58,6 @@ DebayerCpu::DebayerCpu(std::unique_ptr stats, const GlobalConfigurat enableInputMemcpy_ = configuration.option({ "software_isp", "copy_input_buffer" }).value_or(true); - skipBeforeMeasure_ = configuration.option( - { "software_isp", "measure", "skip" }) - .value_or(skipBeforeMeasure_); - framesToMeasure_ = configuration.option( - { "software_isp", "measure", "number" }) - .value_or(framesToMeasure_); - /* Initialize color lookup tables */ for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { red_[i] = green_[i] = blue_[i] = i; @@ -571,9 +564,6 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg, lineBuffers_[i].resize(lineBufferLength_); } - encounteredFrames_ = 0; - frameProcessTime_ = 0; - return 0; } @@ -765,27 +755,9 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst) } } -namespace { - -inline int64_t timeDiff(timespec &after, timespec &before) -{ - return (after.tv_sec - before.tv_sec) * 1000000000LL + - (int64_t)after.tv_nsec - (int64_t)before.tv_nsec; -} - -} /* namespace */ - void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params) { - timespec frameStartTime; - - bool measure = framesToMeasure_ > 0 && - encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ && - ++encounteredFrames_ > skipBeforeMeasure_; - if (measure) { - frameStartTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime); - } + bench_.startFrame(); std::vector dmaSyncers; for (const FrameBuffer::Plane &plane : input->planes()) @@ -840,18 +812,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output dmaSyncers.clear(); /* Measure before emitting signals */ - if (measure) { - timespec frameEndTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); - frameProcessTime_ += timeDiff(frameEndTime, frameStartTime); - if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { - LOG(Debayer, Info) - << "Processed " << framesToMeasure_ - << " frames in " << frameProcessTime_ / 1000 << "us, " - << frameProcessTime_ / (1000 * framesToMeasure_) - << " us/frame"; - } - } + bench_.finishFrame(); /* * Buffer ids are currently not used, so pass zeros as its parameter. diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h index 1cd411f26..aff32491e 100644 --- a/src/libcamera/software_isp/debayer_cpu.h +++ b/src/libcamera/software_isp/debayer_cpu.h @@ -17,6 +17,7 @@ #include +#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/global_configuration.h" #include "libcamera/internal/software_isp/swstats_cpu.h" @@ -161,10 +162,7 @@ private: unsigned int xShift_; /* Offset of 0/1 applied to window_.x */ bool enableInputMemcpy_; bool swapRedBlueGains_; - unsigned int encounteredFrames_; - int64_t frameProcessTime_; - unsigned int skipBeforeMeasure_ = 30; - unsigned int framesToMeasure_ = 30; + Benchmark bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index aac7eda7b..59fa5f02a 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -8,6 +8,7 @@ if not softisp_enabled endif libcamera_internal_sources += files([ + 'benchmark.cpp', 'debayer.cpp', 'debayer_cpu.cpp', 'software_isp.cpp',