[libcamera-devel,v3,5/7] libcamera: V4L2BufferCache: Check for hot hit first

Message ID 20200304232246.325384-6-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • libcamera: V4L2BufferCache: Improve cache
Related show

Commit Message

Niklas Söderlund March 4, 2020, 11:22 p.m. UTC
Check for a hot cache hit before updating which buffer is best to evict
in case no hot hit is found.

Suggested-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/v4l2_videodevice.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart March 4, 2020, 11:29 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Thu, Mar 05, 2020 at 12:22:44AM +0100, Niklas Söderlund wrote:
> Check for a hot cache hit before updating which buffer is best to evict
> in case no hot hit is found.

You can add "This doesn't change the behaviour, by follows a more
logical flow.".

> 
> Suggested-by: Jacopo Mondi <jacopo@jmondi.org>
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/v4l2_videodevice.cpp | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 268de60bc7965f58..c495de85f26efe14 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -212,15 +212,15 @@ int V4L2BufferCache::get(const FrameBuffer &buffer)
>  		if (!entry.free)
>  			continue;
>  
> -		if (use < 0)
> -			use = index;
> -
>  		/* Try to find a cache hit by comparing the planes. */
>  		if (entry == buffer) {
>  			hit = true;
>  			use = index;
>  			break;
>  		}
> +
> +		if (use < 0)
> +			use = index;
>  	}
>  
>  	if (!hit)

Patch

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 268de60bc7965f58..c495de85f26efe14 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -212,15 +212,15 @@  int V4L2BufferCache::get(const FrameBuffer &buffer)
 		if (!entry.free)
 			continue;
 
-		if (use < 0)
-			use = index;
-
 		/* Try to find a cache hit by comparing the planes. */
 		if (entry == buffer) {
 			hit = true;
 			use = index;
 			break;
 		}
+
+		if (use < 0)
+			use = index;
 	}
 
 	if (!hit)