Re: [PATCH libdrm] etnaviv: fix BO cache to properly work with different flags

2017-12-15 Thread Christian Gmeiner
2017-12-15 11:30 GMT+01:00 Lucas Stach :
> Currently if the oldest BO in a bucket has different flags than what we
> look for we'll miss the cache.Fix this by iterating over the cached BOs
> until we find the oldest one with matching flags. This improves the hit
> ratio for some of the buckets.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  etnaviv/etnaviv_bo_cache.c | 26 +++---
>  1 file changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/etnaviv/etnaviv_bo_cache.c b/etnaviv/etnaviv_bo_cache.c
> index 8924651f0cd8..6208230dc81a 100644
> --- a/etnaviv/etnaviv_bo_cache.c
> +++ b/etnaviv/etnaviv_bo_cache.c
> @@ -124,20 +124,32 @@ static int is_idle(struct etna_bo *bo)
>
>  static struct etna_bo *find_in_bucket(struct etna_bo_bucket *bucket, 
> uint32_t flags)
>  {
> -   struct etna_bo *bo = NULL;
> +   struct etna_bo *bo = NULL, *tmp;
>
> pthread_mutex_lock(_lock);
> -   while (!LIST_IS_EMPTY(>list)) {
> -   bo = LIST_ENTRY(struct etna_bo, bucket->list.next, list);
>
> -   if (bo->flags == flags && is_idle(bo)) {
> -   list_del(>list);
> -   break;
> +   if (LIST_IS_EMPTY(>list))
> +   goto out_unlock;
> +
> +   LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, >list, list) {
> +   /* skip BOs with different flags */
> +   if (bo->flags != flags)
> +   continue;
> +
> +   /* check if the first BO with matching flags is idle */
> +   if (is_idle(bo)) {
> +   list_delinit(>list);
> +   goto out_unlock;
> }
>
> -   bo = NULL;
> +   /* If the oldest BO is still busy, don't try younger ones */
> break;
> }
> +
> +   /* There was no matching buffer found */
> +   bo = NULL;
> +
> +out_unlock:
> pthread_mutex_unlock(_lock);
>
> return bo;
> --
> 2.11.0
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH libdrm] etnaviv: fix BO cache to properly work with different flags

2017-12-15 Thread Philipp Zabel
On Fri, 2017-12-15 at 11:30 +0100, Lucas Stach wrote:
> Currently if the oldest BO in a bucket has different flags than what we
> look for we'll miss the cache.Fix this by iterating over the cached BOs
> until we find the oldest one with matching flags. This improves the hit
> ratio for some of the buckets.
> 
> Signed-off-by: Lucas Stach 

Reviewed-by: Philipp Zabel 

regards
Philipp

> ---
>  etnaviv/etnaviv_bo_cache.c | 26 +++---
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/etnaviv/etnaviv_bo_cache.c b/etnaviv/etnaviv_bo_cache.c
> index 8924651f0cd8..6208230dc81a 100644
> --- a/etnaviv/etnaviv_bo_cache.c
> +++ b/etnaviv/etnaviv_bo_cache.c
> @@ -124,20 +124,32 @@ static int is_idle(struct etna_bo *bo)
>  
>  static struct etna_bo *find_in_bucket(struct etna_bo_bucket *bucket, 
> uint32_t flags)
>  {
> - struct etna_bo *bo = NULL;
> + struct etna_bo *bo = NULL, *tmp;
>  
>   pthread_mutex_lock(_lock);
> - while (!LIST_IS_EMPTY(>list)) {
> - bo = LIST_ENTRY(struct etna_bo, bucket->list.next, list);
>  
> - if (bo->flags == flags && is_idle(bo)) {
> - list_del(>list);
> - break;
> + if (LIST_IS_EMPTY(>list))
> + goto out_unlock;
> +
> + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, >list, list) {
> + /* skip BOs with different flags */
> + if (bo->flags != flags)
> + continue;
> +
> + /* check if the first BO with matching flags is idle */
> + if (is_idle(bo)) {
> + list_delinit(>list);
> + goto out_unlock;
>   }
>  
> - bo = NULL;
> + /* If the oldest BO is still busy, don't try younger ones */
>   break;
>   }
> +
> + /* There was no matching buffer found */
> + bo = NULL;
> +
> +out_unlock:
>   pthread_mutex_unlock(_lock);
>  
>   return bo;
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH libdrm] etnaviv: fix BO cache to properly work with different flags

2017-12-15 Thread Lucas Stach
Currently if the oldest BO in a bucket has different flags than what we
look for we'll miss the cache.Fix this by iterating over the cached BOs
until we find the oldest one with matching flags. This improves the hit
ratio for some of the buckets.

Signed-off-by: Lucas Stach 
---
 etnaviv/etnaviv_bo_cache.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/etnaviv/etnaviv_bo_cache.c b/etnaviv/etnaviv_bo_cache.c
index 8924651f0cd8..6208230dc81a 100644
--- a/etnaviv/etnaviv_bo_cache.c
+++ b/etnaviv/etnaviv_bo_cache.c
@@ -124,20 +124,32 @@ static int is_idle(struct etna_bo *bo)
 
 static struct etna_bo *find_in_bucket(struct etna_bo_bucket *bucket, uint32_t 
flags)
 {
-   struct etna_bo *bo = NULL;
+   struct etna_bo *bo = NULL, *tmp;
 
pthread_mutex_lock(_lock);
-   while (!LIST_IS_EMPTY(>list)) {
-   bo = LIST_ENTRY(struct etna_bo, bucket->list.next, list);
 
-   if (bo->flags == flags && is_idle(bo)) {
-   list_del(>list);
-   break;
+   if (LIST_IS_EMPTY(>list))
+   goto out_unlock;
+
+   LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, >list, list) {
+   /* skip BOs with different flags */
+   if (bo->flags != flags)
+   continue;
+
+   /* check if the first BO with matching flags is idle */
+   if (is_idle(bo)) {
+   list_delinit(>list);
+   goto out_unlock;
}
 
-   bo = NULL;
+   /* If the oldest BO is still busy, don't try younger ones */
break;
}
+
+   /* There was no matching buffer found */
+   bo = NULL;
+
+out_unlock:
pthread_mutex_unlock(_lock);
 
return bo;
-- 
2.11.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel