From patchwork Thu Nov 26 11:03:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29096 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 DB514BDE17 for ; Thu, 26 Nov 2026 11:05:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9CD366AA25; Thu, 26 Nov 2026 12:05:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="TIae61i3"; dkim-atps=neutral Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82D986AA1F for ; Thu, 26 Nov 2026 12:05:12 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691108; cv=none; d=zohomail.com; s=zohoarc; b=c3FtINiJ8SGWUjFy50cZZSQgpSLPCkCZ/BVyKb4nvNL63Dy0bUmAyuR7E5Jb+xmJcJKJmsmJTNnonmOdnwzORReLVhCaXQoXWVFJZ/jLENE3rhclE4RFqgINKnuSbSawrASjndpyZcr99ICjGckPyufmhMO8r5Cx8i+syQyMc6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691108; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=eyFOA5I10Pxw+44De1FeIgG4Rnp1f0zeW4R3OLODitM=; b=gfSDwjdK7lysqyFWjUlPm2blESvw/Yijs3gCLm+OjKyVs0o/69KGPjGo0t1/Nyy7Rnx3zIFIna71aAkanqf11I6UqLyD9/w9f76JMvGWtDHro3S5zgq+VskQmGjwDxN5QsbNKEWbYFernLAg2mE4Ss6QDDSmD2fR1O0Haza/hhs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=TIae61i3wG1qxH6Wf+HGzmYF4PeNlFEtAfmltcRXuy0cPdbapifd0zaTLiO7VZHeu0Y1ZqgcYSkaN/aGPcKZ7ZxgrGOjMcmyATaeErcDE9OvzsQFiFQt4kkkms4J8+yxkJjWj2JzYLhy4AUFqTYntNX0NoUmYmPgiwnyJZBgv0s=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=eyFOA5I10Pxw+44De1FeIgG4Rnp1f0zeW4R3OLODitM=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691107240644.3250544502131; Thu, 26 Nov 2026 03:05:07 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 5/6] software_isp: benchmark: Make benchmark into an abstract class Date: Fri, 27 Nov 2026 00:03:43 +1300 Message-ID: <20261126110422.362455-6-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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" Makes the Benchmark class abstract, splitting off the CPU-specific timing code to a separate file to allow for different benchmarking methods to be added in the future. Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- .../internal/software_isp/benchmark.h | 18 ++- .../internal/software_isp/benchmark_cpu.h | 37 ++++++ .../internal/software_isp/meson.build | 2 +- .../internal/software_isp/swstats_cpu.h | 5 +- src/libcamera/software_isp/benchmark.cpp | 108 ++++++++++++++---- src/libcamera/software_isp/benchmark_cpu.cpp | 74 ++++++++++++ src/libcamera/software_isp/debayer.h | 4 +- src/libcamera/software_isp/debayer_cpu.cpp | 1 + src/libcamera/software_isp/debayer_egl.cpp | 2 + src/libcamera/software_isp/debayer_egl.h | 1 - src/libcamera/software_isp/meson.build | 1 + src/libcamera/software_isp/swstats_cpu.cpp | 1 + 12 files changed, 220 insertions(+), 34 deletions(-) create mode 100644 include/libcamera/internal/software_isp/benchmark_cpu.h create mode 100644 src/libcamera/software_isp/benchmark_cpu.cpp diff --git a/include/libcamera/internal/software_isp/benchmark.h b/include/libcamera/internal/software_isp/benchmark.h index cc7f9d71..be2f6ca5 100644 --- a/include/libcamera/internal/software_isp/benchmark.h +++ b/include/libcamera/internal/software_isp/benchmark.h @@ -1,18 +1,18 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. * * Authors: * Hans de Goede + * Remy Alipoursafari * * Simple builtin benchmark to measure software ISP processing times */ #pragma once -#include #include -#include namespace libcamera { @@ -22,18 +22,26 @@ class Benchmark { public: Benchmark(const CameraManager &cm, const std::string &name); - ~Benchmark(); + virtual ~Benchmark(); void startFrame(void); void finishFrame(void); + void queryFrame(void); + +protected: + /* Cumulative time in nanoseconds */ + int64_t frameProcessTime_ = 0; + + virtual bool timeFrameStart(void) = 0; + virtual bool timeFrameEnd(void) = 0; + virtual bool timeFrameQuery(void) = 0; private: std::string name_; - timespec frameStartTime_; + /* Whether to process the current frame */ 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; }; diff --git a/include/libcamera/internal/software_isp/benchmark_cpu.h b/include/libcamera/internal/software_isp/benchmark_cpu.h new file mode 100644 index 00000000..b61737d4 --- /dev/null +++ b/include/libcamera/internal/software_isp/benchmark_cpu.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. + * + * Authors: + * Hans de Goede + * Remy Alipoursafari + * + * Simple builtin benchmark to measure software ISP CPU processing times + */ + +#pragma once + +#include +#include + +#include "libcamera/internal/software_isp/benchmark.h" + +namespace libcamera { + +class BenchmarkCpu : public Benchmark +{ +public: + BenchmarkCpu(const CameraManager &cm, const std::string &name); + ~BenchmarkCpu(); + +protected: + bool timeFrameStart(void) override; + bool timeFrameEnd(void) override; + bool timeFrameQuery(void) override; + +private: + timespec frameStartTime_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build index df7c3b97..89161600 100644 --- a/include/libcamera/internal/software_isp/meson.build +++ b/include/libcamera/internal/software_isp/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_internal_headers += files([ - 'benchmark.h', + 'benchmark_cpu.h', 'debayer_params.h', 'software_isp.h', 'swisp_stats.h', diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h index 55187092..e7871e41 100644 --- a/include/libcamera/internal/software_isp/swstats_cpu.h +++ b/include/libcamera/internal/software_isp/swstats_cpu.h @@ -22,8 +22,7 @@ #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/swisp_stats.h" - -#include "benchmark.h" +#include "benchmark_cpu.h" namespace libcamera { @@ -123,7 +122,7 @@ private: std::vector stats_; SharedMemObject sharedStats_; - Benchmark bench_; + BenchmarkCpu bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/benchmark.cpp b/src/libcamera/software_isp/benchmark.cpp index 96f0ae00..8f2fa84c 100644 --- a/src/libcamera/software_isp/benchmark.cpp +++ b/src/libcamera/software_isp/benchmark.cpp @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. * * Authors: * Hans de Goede + * Remy Alipoursafari * * Simple builtin benchmark to measure software ISP processing times */ @@ -35,38 +37,74 @@ Benchmark::Benchmark(const CameraManager &cm, const std::string &name) const GlobalConfiguration &configuration = cm._d()->configuration(); skipBeforeMeasure_ = configuration.option( - { "software_isp", "measure", "skip" }) - .value_or(skipBeforeMeasure_); + { "software_isp", "measure", "skip" }) + .value_or(skipBeforeMeasure_); framesToMeasure_ = configuration.option( { "software_isp", "measure", "number" }) - .value_or(framesToMeasure_); + .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; -} +/** + * \var Benchmark::frameProcessTime_ + * \brief Cumulative time in nanoseconds + */ + +/** + * \fn Benchmark::timeFrameStart() + * \brief Start measuring process time for a single frame + * \return True on success, false on failure. On failure, the rest of the + * pipeline is skipped + * \sa timeFrameEnd() + * \sa timeFrameQuery() + */ + +/** + * \fn Benchmark::timeFrameEnd() + * \brief Finish measuring process time for a single frame + * \return True on success, false on failure. On failure, the rest of the + * pipeline is skipped + * \sa timeFrameStart() + * \sa timeFrameQuery() + */ + +/** + * \fn Benchmark::timeFrameQuery() + * \brief Query the processing time between the timer's start & end + * + * Queries for the time between the timer's start & end, and putting the result + * in Benchmark::frameProcessTime_. + * + * \return True on success, false on failure. On failure, the rest of the + * pipeline is skipped + * \sa timeFrameStart() + * \sa timeFrameEnd() + */ /** * \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. + * + * \sa finishFrame() + * \sa queryFrame() */ -void Benchmark::startFrame(void) +void Benchmark::startFrame() { measure_ = framesToMeasure_ > 0 && encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ && ++encounteredFrames_ > skipBeforeMeasure_; if (measure_) { - frameStartTime_ = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); + if (!timeFrameStart()) { + LOG(Benchmark, Error) << name_ << " failed starting time benchmark"; + encounteredFrames_--; + measure_ = false; + } } } @@ -76,21 +114,47 @@ void Benchmark::startFrame(void) * Call this function after processing frame data to finish measuring * the process time for a frame. * + * \sa startFrame() + * \sa queryFrame() + */ +void Benchmark::finishFrame() +{ + if (measure_) { + if (!timeFrameEnd()) { + LOG(Benchmark, Error) << name_ << " failed ending time benchmark"; + encounteredFrames_--; + measure_ = false; + } + } +} + +/** + * \brief Query & potentially print the processing time for a single frame + * + * Call this function once Benchmark::startFrame() & Benchmark::finishFrame() + * have been called. + * * This function will log frame processing time information after - * Benchmark::kLastFrameToMeasure frames have been processed. + * (Benchmark::skipBeforeMeasure_ + Benchmark::framesToMeasure_) successful + * frames have been processed. + * + * \sa startFrame() + * \sa finishFrame() */ -void Benchmark::finishFrame(void) +void Benchmark::queryFrame() { if (measure_) { - timespec frameEndTime = {}; - clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); - frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); - if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { - LOG(Benchmark, Info) - << name_ << " processed " << framesToMeasure_ - << " frames in " << frameProcessTime_ / 1000 << "us, " - << frameProcessTime_ / (1000 * framesToMeasure_) - << " us/frame"; + if (timeFrameQuery()) { + if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) { + LOG(Benchmark, Info) + << name_ << " processed " << framesToMeasure_ + << " frames in " << frameProcessTime_ / 1000 << "us, " + << frameProcessTime_ / (1000 * framesToMeasure_) + << " us/frame"; + } + } else { + LOG(Benchmark, Error) << name_ << " failed querying time benchmark"; + encounteredFrames_--; } } } diff --git a/src/libcamera/software_isp/benchmark_cpu.cpp b/src/libcamera/software_isp/benchmark_cpu.cpp new file mode 100644 index 00000000..3b9eb629 --- /dev/null +++ b/src/libcamera/software_isp/benchmark_cpu.cpp @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2026, Collabora Inc. + * + * Authors: + * Hans de Goede + * Remy Alipoursafari + * + * Simple builtin benchmark to measure software ISP CPU processing times + */ + +#include "libcamera/internal/software_isp/benchmark_cpu.h" + +namespace libcamera { + +/** + * \class BenchmarkCpu + * \brief Simple builtin benchmark for mesuring CPU time + * + * Simple builtin benchmark to measure software ISP CPU processing times. + */ + +/** + * \brief Constructs a BenchmarkCpu object + */ +BenchmarkCpu::BenchmarkCpu(const CameraManager &cm, const std::string &name) + : Benchmark(cm, name) +{ +} + +BenchmarkCpu::~BenchmarkCpu() +{ +} + +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 + */ +bool BenchmarkCpu::timeFrameStart() +{ + frameStartTime_ = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime_); + + return true; +} + +/** + * \brief Finish measuring process time for a single frame + */ +bool BenchmarkCpu::timeFrameEnd() +{ + timespec frameEndTime = {}; + clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime); + frameProcessTime_ += timeDiff(frameEndTime, frameStartTime_); + + return true; +} + +/** + * \brief Query the processing time between the timer's start & end + */ +bool BenchmarkCpu::timeFrameQuery() +{ + // Querying the processing time is done in BenchmarkCpu::timeFrameEnd() + return true; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h index e30a0527..c9423263 100644 --- a/src/libcamera/software_isp/debayer.h +++ b/src/libcamera/software_isp/debayer.h @@ -22,7 +22,7 @@ #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/dma_buf_allocator.h" -#include "libcamera/internal/software_isp/benchmark.h" +#include "libcamera/internal/software_isp/benchmark_cpu.h" #include "libcamera/internal/software_isp/debayer_params.h" namespace libcamera { @@ -80,7 +80,7 @@ public: PixelFormat inputPixelFormat_; PixelFormat outputPixelFormat_; bool swapRedBlueGains_; - Benchmark bench_; + BenchmarkCpu bench_; private: virtual Size patternSize(PixelFormat inputFormat) = 0; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index 91867baa..23e519c3 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -1094,6 +1094,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output /* Measure before emitting signals */ bench_.finishFrame(); + bench_.queryFrame(); /* * Buffer ids are currently not used, so pass zeros as its parameter. diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index d94a06d1..ca99bdc2 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -672,6 +672,7 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output egl_.syncOutput(); bench_.finishFrame(); + bench_.queryFrame(); outputBufferReady.emit(output); inputBufferReady.emit(input); @@ -680,6 +681,7 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output error: bench_.finishFrame(); + bench_.queryFrame(); metadata.status = FrameMetadata::FrameError; return; } diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index cbbc6a45..4185d32b 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -21,7 +21,6 @@ #include "libcamera/internal/egl.h" #include "libcamera/internal/mapped_framebuffer.h" -#include "libcamera/internal/software_isp/benchmark.h" #include "libcamera/internal/software_isp/swstats_cpu.h" #include diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build index 15f9e403..f6ee6700 100644 --- a/src/libcamera/software_isp/meson.build +++ b/src/libcamera/software_isp/meson.build @@ -21,6 +21,7 @@ summary({'SoftISP GPU acceleration' : mesa_works}, libcamera_internal_sources += files([ 'benchmark.cpp', + 'benchmark_cpu.cpp', 'debayer.cpp', 'debayer_cpu.cpp', 'software_isp.cpp', diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 74633815..0f08b19e 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -632,6 +632,7 @@ void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, MappedFrameBuff (this->*processFrame_)(input); finishFrame(frame, bufferId); bench_.finishFrame(); + bench_.queryFrame(); } } /* namespace libcamera */