@@ -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 <hdegoede@redhat.com>
+ * Remy Alipoursafari <remy.alipoursafari@collabora.com>
*
* Simple builtin benchmark to measure software ISP processing times
*/
#pragma once
-#include <stdint.h>
#include <string>
-#include <time.h>
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;
};
new file mode 100644
@@ -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 <hdegoede@redhat.com>
+ * Remy Alipoursafari <remy.alipoursafari@collabora.com>
+ *
+ * Simple builtin benchmark to measure software ISP CPU processing times
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <time.h>
+
+#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 */
@@ -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',
@@ -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<SwIspStats> stats_;
SharedMemObject<SwIspStats> sharedStats_;
- Benchmark bench_;
+ BenchmarkCpu bench_;
};
} /* namespace libcamera */
@@ -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 <hdegoede@redhat.com>
+ * Remy Alipoursafari <remy.alipoursafari@collabora.com>
*
* 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<unsigned int>(
- { "software_isp", "measure", "skip" })
- .value_or(skipBeforeMeasure_);
+ { "software_isp", "measure", "skip" })
+ .value_or(skipBeforeMeasure_);
framesToMeasure_ = configuration.option<unsigned int>(
{ "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_--;
}
}
}
new file mode 100644
@@ -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 <hdegoede@redhat.com>
+ * Remy Alipoursafari <remy.alipoursafari@collabora.com>
+ *
+ * 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 */
@@ -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;
@@ -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.
@@ -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;
}
@@ -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 <EGL/egl.h>
@@ -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',
@@ -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 */