[PATCH 01/11] drm/ttm: Make LRU removal optional.
Zhou, David(ChunMing)
David1.Zhou at amd.com
Fri May 17 14:05:06 UTC 2019
> -----Original Message-----
> From: Christian König <ckoenig.leichtzumerken at gmail.com>
> Sent: Tuesday, May 14, 2019 8:31 PM
> To: Olsak, Marek <Marek.Olsak at amd.com>; Zhou, David(ChunMing)
> <David1.Zhou at amd.com>; Liang, Prike <Prike.Liang at amd.com>; dri-
> devel at lists.freedesktop.org; amd-gfx at lists.freedesktop.org
> Subject: [PATCH 01/11] drm/ttm: Make LRU removal optional.
>
> [CAUTION: External Email]
>
> We are already doing this for DMA-buf imports and also for amdgpu VM BOs
> for quite a while now.
>
> If this doesn't run into any problems we are probably going to stop removing
> BOs from the LRU altogether.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> ---
[snip]
> diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> index 0075eb9a0b52..957ec375a4ba 100644
> --- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
> @@ -69,7 +69,8 @@ void ttm_eu_backoff_reservation(struct
> ww_acquire_ctx *ticket,
> list_for_each_entry(entry, list, head) {
> struct ttm_buffer_object *bo = entry->bo;
>
> - ttm_bo_add_to_lru(bo);
> + if (list_empty(&bo->lru))
> + ttm_bo_add_to_lru(bo);
> reservation_object_unlock(bo->resv);
> }
> spin_unlock(&glob->lru_lock);
> @@ -93,7 +94,7 @@ EXPORT_SYMBOL(ttm_eu_backoff_reservation);
>
> int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
> struct list_head *list, bool intr,
> - struct list_head *dups)
> + struct list_head *dups, bool del_lru)
> {
> struct ttm_bo_global *glob;
> struct ttm_validate_buffer *entry; @@ -172,11 +173,11 @@ int
> ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
> list_add(&entry->head, list);
> }
>
> - if (ticket)
> - ww_acquire_done(ticket);
> - spin_lock(&glob->lru_lock);
> - ttm_eu_del_from_lru_locked(list);
> - spin_unlock(&glob->lru_lock);
> + if (del_lru) {
> + spin_lock(&glob->lru_lock);
> + ttm_eu_del_from_lru_locked(list);
> + spin_unlock(&glob->lru_lock);
> + }
Can you make bo to lru tail here when del_lru is false?
Busy iteration in evict_first will try other process Bos first, which could save loop time.
> return 0;
> }
> EXPORT_SYMBOL(ttm_eu_reserve_buffers);
> @@ -203,7 +204,10 @@ void ttm_eu_fence_buffer_objects(struct
> ww_acquire_ctx *ticket,
> reservation_object_add_shared_fence(bo->resv, fence);
> else
> reservation_object_add_excl_fence(bo->resv, fence);
> - ttm_bo_add_to_lru(bo);
> + if (list_empty(&bo->lru))
> + ttm_bo_add_to_lru(bo);
> + else
> + ttm_bo_move_to_lru_tail(bo, NULL);
If this line is done in above, then we don't need this here.
-David
> reservation_object_unlock(bo->resv);
> }
> spin_unlock(&glob->lru_lock);
> diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> index 161b80fee492..5cffaa24259f 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> @@ -63,7 +63,7 @@ static int virtio_gpu_object_list_validate(struct
> ww_acquire_ctx *ticket,
> struct virtio_gpu_object *qobj;
> int ret;
>
> - ret = ttm_eu_reserve_buffers(ticket, head, true, NULL);
> + ret = ttm_eu_reserve_buffers(ticket, head, true, NULL, true);
> if (ret != 0)
> return ret;
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> index a7c30e567f09..d28cbedba0b5 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
> @@ -465,7 +465,8 @@ vmw_resource_check_buffer(struct ww_acquire_ctx
> *ticket,
> val_buf->bo = &res->backup->base;
> val_buf->num_shared = 0;
> list_add_tail(&val_buf->head, &val_list);
> - ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL);
> + ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL,
> + true);
> if (unlikely(ret != 0))
> goto out_no_reserve;
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> index 3b396fea40d7..ac435b51f4eb 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h
> @@ -165,7 +165,7 @@ vmw_validation_bo_reserve(struct
> vmw_validation_context *ctx,
> bool intr)
> {
> return ttm_eu_reserve_buffers(&ctx->ticket, &ctx->bo_list, intr,
> - NULL);
> + NULL, true);
> }
>
> /**
> diff --git a/include/drm/ttm/ttm_bo_driver.h
> b/include/drm/ttm/ttm_bo_driver.h index c008346c2401..fc0d995ac90d
> 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -769,7 +769,10 @@ static inline void ttm_bo_unreserve(struct
> ttm_buffer_object *bo) {
> if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
> spin_lock(&bo->bdev->glob->lru_lock);
> - ttm_bo_add_to_lru(bo);
> + if (list_empty(&bo->lru))
> + ttm_bo_add_to_lru(bo);
> + else
> + ttm_bo_move_to_lru_tail(bo, NULL);
> spin_unlock(&bo->bdev->glob->lru_lock);
> }
> reservation_object_unlock(bo->resv);
> diff --git a/include/drm/ttm/ttm_execbuf_util.h
> b/include/drm/ttm/ttm_execbuf_util.h
> index 621615fa7728..7e46cc678e7e 100644
> --- a/include/drm/ttm/ttm_execbuf_util.h
> +++ b/include/drm/ttm/ttm_execbuf_util.h
> @@ -70,6 +70,7 @@ extern void ttm_eu_backoff_reservation(struct
> ww_acquire_ctx *ticket,
> * @list: thread private list of ttm_validate_buffer structs.
> * @intr: should the wait be interruptible
> * @dups: [out] optional list of duplicates.
> + * @del_lru: true if BOs should be removed from the LRU.
> *
> * Tries to reserve bos pointed to by the list entries for validation.
> * If the function returns 0, all buffers are marked as "unfenced", @@ -98,7
> +99,7 @@ extern void ttm_eu_backoff_reservation(struct ww_acquire_ctx
> *ticket,
>
> extern int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
> struct list_head *list, bool intr,
> - struct list_head *dups);
> + struct list_head *dups, bool del_lru);
>
> /**
> * function ttm_eu_fence_buffer_objects.
> --
> 2.17.1
More information about the amd-gfx
mailing list