[v2,13/13] libcamera: software_isp: Make measurement configurable
diff mbox series

Message ID 20240423103034.364150-14-mzamazal@redhat.com
State Superseded
Headers show
Series
  • Add global configuration file
Related show

Commit Message

Milan Zamazal April 23, 2024, 10:30 a.m. UTC
Software ISP performs performance measurement on certain part of initial
frames.  Let's make this range configurable.

For this purpose, this patch introduces new configuration options
pipelines.simple.measure.skip and pipelines.simple.measure.number.
Setting the latter one to 0 disables the measurement.

Instead of the last frame, the class member and its configuration
specify the number of frames to measure.  This is easier to use for
users and doesn't require to adjust two configuration parameters when
the number of the initially skipped frames is changed.

The patch also changes the names of the class members to make them more
accurate.

Completes software ISP TODO #7.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 Documentation/runtime_configuration.rst    |  6 ++++++
 src/libcamera/software_isp/TODO            | 25 ----------------------
 src/libcamera/software_isp/debayer_cpu.cpp | 25 ++++++++++++++--------
 src/libcamera/software_isp/debayer_cpu.h   |  7 +++---
 4 files changed, 25 insertions(+), 38 deletions(-)

Patch
diff mbox series

diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
index ed6370bb..582e388f 100644
--- a/Documentation/runtime_configuration.rst
+++ b/Documentation/runtime_configuration.rst
@@ -49,6 +49,9 @@  file structure:
         tuning_file: # full path
       simple:
         copy_input_buffer: # true/false
+        measure:
+          skip: # non-negative integer, frames to skip initially
+          number: # non-negative integer, frames to measure
         supported_devices:
         - driver: # driver name, e.g. `mxc-isi`
           software_isp: # true/false
@@ -76,6 +79,9 @@  Configuration file example
          config_file: /usr/local/share/libcamera/pipeline/rpi/vc4/minimal_mem.yaml
        simple:
          copy_input_buffer: false
+         measure:
+           skip: 50
+           number: 30
          supported_devices:
          - driver: mxc-isi
            software_isp: true
diff --git a/src/libcamera/software_isp/TODO b/src/libcamera/software_isp/TODO
index 15396322..ca305a63 100644
--- a/src/libcamera/software_isp/TODO
+++ b/src/libcamera/software_isp/TODO
@@ -103,31 +103,6 @@  per-frame buffers like we do for hardware ISPs.
 
 ---
 
-7. Performance measurement configuration
-
-> void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams params)
-> /* Measure before emitting signals */
-> if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&
->     ++measuredFrames_ > DebayerCpu::kFramesToSkip) {
-> 	timespec frameEndTime = {};
-> 	clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime);
-> 	frameProcessTime_ += timeDiff(frameEndTime, frameStartTime);
-> 	if (measuredFrames_ == DebayerCpu::kLastFrameToMeasure) {
-> 		const unsigned int measuredFrames = DebayerCpu::kLastFrameToMeasure -
-> 						    DebayerCpu::kFramesToSkip;
-> 		LOG(Debayer, Info)
-> 			<< "Processed " << measuredFrames
-> 			<< " frames in " << frameProcessTime_ / 1000 << "us, "
-> 			<< frameProcessTime_ / (1000 * measuredFrames)
-> 			<< " us/frame";
-> 	}
-> }
-
-I wonder if there would be a way to control at runtime when/how to
-perform those measurements. Maybe that's a bit overkill.
-
----
-
 8. DebayerCpu cleanups
 
 > >> class DebayerCpu : public Debayer, public Object
diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
index fa538927..59694ad6 100644
--- a/src/libcamera/software_isp/debayer_cpu.cpp
+++ b/src/libcamera/software_isp/debayer_cpu.cpp
@@ -50,6 +50,13 @@  DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)
 				     "pipelines.simple.copy_input_buffer")
 				     .value_or(true);
 
+	skipBeforeMeasure_ = GlobalConfiguration::option<unsigned int>(
+				     "pipelines.simple.measure.skip")
+				     .value_or(skipBeforeMeasure_);
+	framesToMeasure_ = GlobalConfiguration::option<unsigned int>(
+				   "pipelines.simple.measure.number")
+				   .value_or(framesToMeasure_);
+
 	/* Initialize gamma to 1.0 curve */
 	for (unsigned int i = 0; i < kGammaLookupSize; i++)
 		gamma_[i] = i / (kGammaLookupSize / kRGBLookupSize);
@@ -496,7 +503,7 @@  int DebayerCpu::configure(const StreamConfiguration &inputCfg,
 			return -ENOMEM;
 	}
 
-	measuredFrames_ = 0;
+	encounteredFrames_ = 0;
 	frameProcessTime_ = 0;
 
 	return 0;
@@ -696,7 +703,10 @@  void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams
 {
 	timespec frameStartTime;
 
-	if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure) {
+	bool measure = framesToMeasure_ > 0 &&
+		       encounteredFrames_ < skipBeforeMeasure_ + framesToMeasure_ &&
+		       ++encounteredFrames_ > skipBeforeMeasure_;
+	if (measure) {
 		frameStartTime = {};
 		clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);
 	}
@@ -757,18 +767,15 @@  void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams
 	metadata.planes()[0].bytesused = out.planes()[0].size();
 
 	/* Measure before emitting signals */
-	if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&
-	    ++measuredFrames_ > DebayerCpu::kFramesToSkip) {
+	if (measure) {
 		timespec frameEndTime = {};
 		clock_gettime(CLOCK_MONOTONIC_RAW, &frameEndTime);
 		frameProcessTime_ += timeDiff(frameEndTime, frameStartTime);
-		if (measuredFrames_ == DebayerCpu::kLastFrameToMeasure) {
-			const unsigned int measuredFrames = DebayerCpu::kLastFrameToMeasure -
-							    DebayerCpu::kFramesToSkip;
+		if (encounteredFrames_ == skipBeforeMeasure_ + framesToMeasure_) {
 			LOG(Debayer, Info)
-				<< "Processed " << measuredFrames
+				<< "Processed " << framesToMeasure_
 				<< " frames in " << frameProcessTime_ / 1000 << "us, "
-				<< frameProcessTime_ / (1000 * measuredFrames)
+				<< frameProcessTime_ / (1000 * framesToMeasure_)
 				<< " us/frame";
 		}
 	}
diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h
index 689c1075..1306ef6f 100644
--- a/src/libcamera/software_isp/debayer_cpu.h
+++ b/src/libcamera/software_isp/debayer_cpu.h
@@ -148,11 +148,10 @@  private:
 	bool swapRedBlueGains_;
 	float gammaCorrection_;
 	unsigned int blackLevel_;
-	unsigned int measuredFrames_;
+	unsigned int encounteredFrames_;
 	int64_t frameProcessTime_;
-	/* Skip 30 frames for things to stabilize then measure 30 frames */
-	static constexpr unsigned int kFramesToSkip = 30;
-	static constexpr unsigned int kLastFrameToMeasure = 60;
+	unsigned int skipBeforeMeasure_ = 30;
+	unsigned int framesToMeasure_ = 30;
 };
 
 } /* namespace libcamera */