[libcamera-devel,02/13] libcamera: ipu3: Import instead of allocate statistic buffers

Message ID 20200627030043.2088585-3-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: ipu3: Refactoring of ImgU
Related show

Commit Message

Niklas Söderlund June 27, 2020, 3 a.m. UTC
Statistics buffers are not yet used by the IPU3 pipeline, they are never
queued to the video device or in any other way consumed. The kernel
driver will however not allow video streaming to start if buffers are
not either allocated or imported on the video device. Instead of
allocating the buffers wasting memory that is never used import buffers.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Jacopo Mondi June 27, 2020, 9:51 a.m. UTC | #1
Hi Niklas,

On Sat, Jun 27, 2020 at 05:00:32AM +0200, Niklas Söderlund wrote:
> Statistics buffers are not yet used by the IPU3 pipeline, they are never
> queued to the video device or in any other way consumed. The kernel
> driver will however not allow video streaming to start if buffers are
> not either allocated or imported on the video device. Instead of
> allocating the buffers wasting memory that is never used import buffers.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/libcamera/pipeline/ipu3/ipu3.cpp | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index fba45935741e0e4e..405550b1302fb370 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -1135,11 +1135,13 @@ int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount)
>  	}
>
>  	/*
> -	 * Use for the stat's internal pool the same number of buffers as for
> -	 * the input pool.
> +	 * The kernel fails to start if buffers are not either imported or
> +	 * allocated for the statisitcs video device. As statistics buffers are
> +	 * not yet used by the pipeline import buffers to save memory.
> +	 *

Is this based on practical experience ? The IPU3 driver documentation
is a bit confusing on which output is required to have buffes queued
in order for operations to start...


>  	 * \todo To be revised when we'll actually use the stat node.
>  	 */
> -	ret = stat_.dev->allocateBuffers(bufferCount, &stat_.buffers);
> +	ret = stat_.dev->importBuffers(bufferCount);
>  	if (ret < 0) {
>  		LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers";
>  		goto error;
> --
> 2.27.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Niklas Söderlund June 27, 2020, 10:27 a.m. UTC | #2
Hi Jacopo,

Thanks for your feedback.

On 2020-06-27 11:51:32 +0200, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Sat, Jun 27, 2020 at 05:00:32AM +0200, Niklas Söderlund wrote:
> > Statistics buffers are not yet used by the IPU3 pipeline, they are never
> > queued to the video device or in any other way consumed. The kernel
> > driver will however not allow video streaming to start if buffers are
> > not either allocated or imported on the video device. Instead of
> > allocating the buffers wasting memory that is never used import buffers.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > ---
> >  src/libcamera/pipeline/ipu3/ipu3.cpp | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > index fba45935741e0e4e..405550b1302fb370 100644
> > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > @@ -1135,11 +1135,13 @@ int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount)
> >  	}
> >
> >  	/*
> > -	 * Use for the stat's internal pool the same number of buffers as for
> > -	 * the input pool.
> > +	 * The kernel fails to start if buffers are not either imported or
> > +	 * allocated for the statisitcs video device. As statistics buffers are
> > +	 * not yet used by the pipeline import buffers to save memory.
> > +	 *
> 
> Is this based on practical experience ? The IPU3 driver documentation
> is a bit confusing on which output is required to have buffes queued
> in order for operations to start...

Yes the documentation is not very helpful so this is all based on 
experimentation and reading the code. See the cover letter for how I 
verified it.

> 
> 
> >  	 * \todo To be revised when we'll actually use the stat node.
> >  	 */
> > -	ret = stat_.dev->allocateBuffers(bufferCount, &stat_.buffers);
> > +	ret = stat_.dev->importBuffers(bufferCount);
> >  	if (ret < 0) {
> >  		LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers";
> >  		goto error;
> > --
> > 2.27.0
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index fba45935741e0e4e..405550b1302fb370 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -1135,11 +1135,13 @@  int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount)
 	}
 
 	/*
-	 * Use for the stat's internal pool the same number of buffers as for
-	 * the input pool.
+	 * The kernel fails to start if buffers are not either imported or
+	 * allocated for the statisitcs video device. As statistics buffers are
+	 * not yet used by the pipeline import buffers to save memory.
+	 *
 	 * \todo To be revised when we'll actually use the stat node.
 	 */
-	ret = stat_.dev->allocateBuffers(bufferCount, &stat_.buffers);
+	ret = stat_.dev->importBuffers(bufferCount);
 	if (ret < 0) {
 		LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers";
 		goto error;