diff mbox

[3/3] drm/amdgpu: add amdgpu_ttm_bo_eviction_valuable callback

Message ID 1477320052-2105-3-git-send-email-deathsimple@vodafone.de (mailing list archive)
State New, archived
Headers show

Commit Message

Christian König Oct. 24, 2016, 2:40 p.m. UTC
From: Christian König <christian.koenig@amd.com>

This way we can correctly check split VRAM buffers as well.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

Comments

Alex Deucher Oct. 24, 2016, 3 p.m. UTC | #1
On Mon, Oct 24, 2016 at 10:40 AM, Christian König
<deathsimple@vodafone.de> wrote:
> From: Christian König <christian.koenig@amd.com>
>
> This way we can correctly check split VRAM buffers as well.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>

Just a small typo noted on patch 2.  With that fixed, for the series:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index c512540..5951666 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1100,13 +1100,37 @@ static struct list_head *amdgpu_ttm_swap_lru_tail(struct ttm_buffer_object *tbo)
>         return res;
>  }
>
> +static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
> +                                           const struct ttm_place *place)
> +{
> +       if (bo->mem.mem_type == TTM_PL_VRAM &&
> +           bo->mem.start == AMDGPU_BO_INVALID_OFFSET) {
> +               unsigned long num_pages = bo->mem.num_pages;
> +               struct drm_mm_node *node = bo->mem.mm_node;
> +
> +               /* Check each drm MM node individually */
> +               while (num_pages) {
> +                       if (place->fpfn < (node->start + node->size) &&
> +                           !(place->lpfn && place->lpfn <= node->start))
> +                               return true;
> +
> +                       num_pages -= node->size;
> +                       ++node;
> +               }
> +
> +               return false;
> +       }
> +
> +       return ttm_bo_eviction_valuable(bo, place);
> +}
> +
>  static struct ttm_bo_driver amdgpu_bo_driver = {
>         .ttm_tt_create = &amdgpu_ttm_tt_create,
>         .ttm_tt_populate = &amdgpu_ttm_tt_populate,
>         .ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
>         .invalidate_caches = &amdgpu_invalidate_caches,
>         .init_mem_type = &amdgpu_init_mem_type,
> -       .eviction_valuable = ttm_bo_eviction_valuable,
> +       .eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
>         .evict_flags = &amdgpu_evict_flags,
>         .move = &amdgpu_bo_move,
>         .verify_access = &amdgpu_verify_access,
> --
> 2.5.0
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
diff mbox

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index c512540..5951666 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1100,13 +1100,37 @@  static struct list_head *amdgpu_ttm_swap_lru_tail(struct ttm_buffer_object *tbo)
 	return res;
 }
 
+static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+					    const struct ttm_place *place)
+{
+	if (bo->mem.mem_type == TTM_PL_VRAM &&
+	    bo->mem.start == AMDGPU_BO_INVALID_OFFSET) {
+		unsigned long num_pages = bo->mem.num_pages;
+		struct drm_mm_node *node = bo->mem.mm_node;
+
+		/* Check each drm MM node individually */
+		while (num_pages) {
+			if (place->fpfn < (node->start + node->size) &&
+			    !(place->lpfn && place->lpfn <= node->start))
+				return true;
+
+			num_pages -= node->size;
+			++node;
+		}
+
+		return false;
+	}
+
+	return ttm_bo_eviction_valuable(bo, place);
+}
+
 static struct ttm_bo_driver amdgpu_bo_driver = {
 	.ttm_tt_create = &amdgpu_ttm_tt_create,
 	.ttm_tt_populate = &amdgpu_ttm_tt_populate,
 	.ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
 	.invalidate_caches = &amdgpu_invalidate_caches,
 	.init_mem_type = &amdgpu_init_mem_type,
-	.eviction_valuable = ttm_bo_eviction_valuable,
+	.eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
 	.evict_flags = &amdgpu_evict_flags,
 	.move = &amdgpu_bo_move,
 	.verify_access = &amdgpu_verify_access,