From: Huang Rui <ray.huang@amd.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: "airlied@linux.ie" <airlied@linux.ie>,
"sroland@vmware.com" <sroland@vmware.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-graphics-maintainer@vmware.com"
<linux-graphics-maintainer@vmware.com>,
"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
"daniel@ffwll.ch" <daniel@ffwll.ch>
Subject: Re: [PATCH 01/11] drm/ttm: add ttm_bo_pin()/ttm_bo_unpin() v2
Date: Wed, 23 Sep 2020 12:36:47 +0800 [thread overview]
Message-ID: <20200923043647.GA3536145@hr-amd> (raw)
In-Reply-To: <20200922133208.1273-1-christian.koenig@amd.com>
On Tue, Sep 22, 2020 at 09:31:58PM +0800, Christian König wrote:
> As an alternative to the placement flag add a
> pin count to the ttm buffer object.
>
> v2: add dma_resv_assert_help() calls
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
Series look good for me as well.
Reviewed-by: Huang Rui <ray.huang@amd.com>
Only one comment:
We can modify the TOPDOWN offset as 21 since the NO_EVICT is removed.
#define TTM_PL_FLAG_UNCACHED (1 << 17)
#define TTM_PL_FLAG_WC (1 << 18)
#define TTM_PL_FLAG_CONTIGUOUS (1 << 19)
-#define TTM_PL_FLAG_NO_EVICT (1 << 21)
#define TTM_PL_FLAG_TOPDOWN (1 << 22)
Thanks,
Ray
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 9 ++++++---
> drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
> include/drm/ttm/ttm_bo_api.h | 26 ++++++++++++++++++++++++++
> 3 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 70b3bee27850..b82b49d43942 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -115,7 +115,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
> struct ttm_bo_device *bdev = bo->bdev;
> struct ttm_resource_manager *man;
>
> - if (!list_empty(&bo->lru))
> + if (!list_empty(&bo->lru) || bo->pin_count)
> return;
>
> if (mem->placement & TTM_PL_FLAG_NO_EVICT)
> @@ -165,7 +165,8 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
> ttm_bo_del_from_lru(bo);
> ttm_bo_add_mem_to_lru(bo, &bo->mem);
>
> - if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
> + if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT) &&
> + !bo->pin_count) {
> switch (bo->mem.mem_type) {
> case TTM_PL_TT:
> ttm_bo_bulk_move_set_pos(&bulk->tt[bo->priority], bo);
> @@ -544,8 +545,9 @@ static void ttm_bo_release(struct kref *kref)
> * shrinkers, now that they are queued for
> * destruction.
> */
> - if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
> + if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT || bo->pin_count) {
> bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
> + bo->pin_count = 0;
> ttm_bo_del_from_lru(bo);
> ttm_bo_add_mem_to_lru(bo, &bo->mem);
> }
> @@ -1172,6 +1174,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> bo->moving = NULL;
> bo->mem.placement = TTM_PL_FLAG_CACHED;
> bo->acc_size = acc_size;
> + bo->pin_count = 0;
> bo->sg = sg;
> if (resv) {
> bo->base.resv = resv;
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fb2a25f8408f..1968df9743fc 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -352,7 +352,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> return -ENOMEM;
>
> fbo->base = *bo;
> - fbo->base.mem.placement |= TTM_PL_FLAG_NO_EVICT;
>
> ttm_bo_get(bo);
> fbo->bo = bo;
> @@ -372,6 +371,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> kref_init(&fbo->base.kref);
> fbo->base.destroy = &ttm_transfered_destroy;
> fbo->base.acc_size = 0;
> + fbo->base.pin_count = 1;
> if (bo->type != ttm_bo_type_sg)
> fbo->base.base.resv = &fbo->base.base._resv;
>
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 0f7cd21d6d74..33aca60870e2 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -157,6 +157,7 @@ struct ttm_buffer_object {
>
> struct dma_fence *moving;
> unsigned priority;
> + unsigned pin_count;
>
> /**
> * Special members that are protected by the reserve lock
> @@ -606,6 +607,31 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
> return bo->base.dev != NULL;
> }
>
> +/**
> + * ttm_bo_pin - Pin the buffer object.
> + * @bo: The buffer object to pin
> + *
> + * Make sure the buffer is not evicted any more during memory pressure.
> + */
> +static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
> +{
> + dma_resv_assert_held(bo->base.resv);
> + ++bo->pin_count;
> +}
> +
> +/**
> + * ttm_bo_unpin - Unpin the buffer object.
> + * @bo: The buffer object to unpin
> + *
> + * Allows the buffer object to be evicted again during memory pressure.
> + */
> +static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
> +{
> + dma_resv_assert_held(bo->base.resv);
> + WARN_ON_ONCE(!bo->pin_count);
> + --bo->pin_count;
> +}
> +
> int ttm_mem_evict_first(struct ttm_bo_device *bdev,
> struct ttm_resource_manager *man,
> const struct ttm_place *place,
> --
> 2.17.1
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Huang Rui <ray.huang@amd.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: "airlied@linux.ie" <airlied@linux.ie>,
"sroland@vmware.com" <sroland@vmware.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-graphics-maintainer@vmware.com"
<linux-graphics-maintainer@vmware.com>,
"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 01/11] drm/ttm: add ttm_bo_pin()/ttm_bo_unpin() v2
Date: Wed, 23 Sep 2020 12:36:47 +0800 [thread overview]
Message-ID: <20200923043647.GA3536145@hr-amd> (raw)
In-Reply-To: <20200922133208.1273-1-christian.koenig@amd.com>
On Tue, Sep 22, 2020 at 09:31:58PM +0800, Christian König wrote:
> As an alternative to the placement flag add a
> pin count to the ttm buffer object.
>
> v2: add dma_resv_assert_help() calls
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
Series look good for me as well.
Reviewed-by: Huang Rui <ray.huang@amd.com>
Only one comment:
We can modify the TOPDOWN offset as 21 since the NO_EVICT is removed.
#define TTM_PL_FLAG_UNCACHED (1 << 17)
#define TTM_PL_FLAG_WC (1 << 18)
#define TTM_PL_FLAG_CONTIGUOUS (1 << 19)
-#define TTM_PL_FLAG_NO_EVICT (1 << 21)
#define TTM_PL_FLAG_TOPDOWN (1 << 22)
Thanks,
Ray
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 9 ++++++---
> drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
> include/drm/ttm/ttm_bo_api.h | 26 ++++++++++++++++++++++++++
> 3 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 70b3bee27850..b82b49d43942 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -115,7 +115,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
> struct ttm_bo_device *bdev = bo->bdev;
> struct ttm_resource_manager *man;
>
> - if (!list_empty(&bo->lru))
> + if (!list_empty(&bo->lru) || bo->pin_count)
> return;
>
> if (mem->placement & TTM_PL_FLAG_NO_EVICT)
> @@ -165,7 +165,8 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
> ttm_bo_del_from_lru(bo);
> ttm_bo_add_mem_to_lru(bo, &bo->mem);
>
> - if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
> + if (bulk && !(bo->mem.placement & TTM_PL_FLAG_NO_EVICT) &&
> + !bo->pin_count) {
> switch (bo->mem.mem_type) {
> case TTM_PL_TT:
> ttm_bo_bulk_move_set_pos(&bulk->tt[bo->priority], bo);
> @@ -544,8 +545,9 @@ static void ttm_bo_release(struct kref *kref)
> * shrinkers, now that they are queued for
> * destruction.
> */
> - if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT) {
> + if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT || bo->pin_count) {
> bo->mem.placement &= ~TTM_PL_FLAG_NO_EVICT;
> + bo->pin_count = 0;
> ttm_bo_del_from_lru(bo);
> ttm_bo_add_mem_to_lru(bo, &bo->mem);
> }
> @@ -1172,6 +1174,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> bo->moving = NULL;
> bo->mem.placement = TTM_PL_FLAG_CACHED;
> bo->acc_size = acc_size;
> + bo->pin_count = 0;
> bo->sg = sg;
> if (resv) {
> bo->base.resv = resv;
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fb2a25f8408f..1968df9743fc 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -352,7 +352,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> return -ENOMEM;
>
> fbo->base = *bo;
> - fbo->base.mem.placement |= TTM_PL_FLAG_NO_EVICT;
>
> ttm_bo_get(bo);
> fbo->bo = bo;
> @@ -372,6 +371,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> kref_init(&fbo->base.kref);
> fbo->base.destroy = &ttm_transfered_destroy;
> fbo->base.acc_size = 0;
> + fbo->base.pin_count = 1;
> if (bo->type != ttm_bo_type_sg)
> fbo->base.base.resv = &fbo->base.base._resv;
>
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 0f7cd21d6d74..33aca60870e2 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -157,6 +157,7 @@ struct ttm_buffer_object {
>
> struct dma_fence *moving;
> unsigned priority;
> + unsigned pin_count;
>
> /**
> * Special members that are protected by the reserve lock
> @@ -606,6 +607,31 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
> return bo->base.dev != NULL;
> }
>
> +/**
> + * ttm_bo_pin - Pin the buffer object.
> + * @bo: The buffer object to pin
> + *
> + * Make sure the buffer is not evicted any more during memory pressure.
> + */
> +static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
> +{
> + dma_resv_assert_held(bo->base.resv);
> + ++bo->pin_count;
> +}
> +
> +/**
> + * ttm_bo_unpin - Unpin the buffer object.
> + * @bo: The buffer object to unpin
> + *
> + * Allows the buffer object to be evicted again during memory pressure.
> + */
> +static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
> +{
> + dma_resv_assert_held(bo->base.resv);
> + WARN_ON_ONCE(!bo->pin_count);
> + --bo->pin_count;
> +}
> +
> int ttm_mem_evict_first(struct ttm_bo_device *bdev,
> struct ttm_resource_manager *man,
> const struct ttm_place *place,
> --
> 2.17.1
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-09-23 4:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 13:31 [PATCH 01/11] drm/ttm: add ttm_bo_pin()/ttm_bo_unpin() v2 Christian König
2020-09-22 13:31 ` Christian König
2020-09-22 13:31 ` [PATCH 02/11] drm/vmwgfx: remove unused placement combination Christian König
2020-09-22 13:31 ` Christian König
2020-09-22 13:32 ` [PATCH 03/11] drm/vmwgfx: stop using ttm_bo_create Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 04/11] drm/vmwgfx: switch over to the new pin interface v2 Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 05/11] drm/nouveau: switch over to the new pin interface Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 06/11] drm/vram-helper: " Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 07/11] drm/qxl: " Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 08/11] drm/radeon: " Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 09/11] drm/amdgpu: " Christian König
2020-09-22 13:32 ` Christian König
2020-09-24 9:39 ` Nirmoy
2020-09-24 9:43 ` Nirmoy
2020-09-24 9:43 ` Nirmoy
2020-09-22 13:32 ` [PATCH 10/11] drm/ttm: remove ttm_bo_create Christian König
2020-09-22 13:32 ` Christian König
2020-09-22 13:32 ` [PATCH 11/11] drm/ttm: remove TTM_PL_FLAG_NO_EVICT Christian König
2020-09-22 13:32 ` Christian König
2020-09-23 3:01 ` [PATCH 01/11] drm/ttm: add ttm_bo_pin()/ttm_bo_unpin() v2 Dave Airlie
2020-09-23 3:01 ` Dave Airlie
2020-09-24 9:00 ` Daniel Vetter
2020-09-24 9:00 ` Daniel Vetter
2020-09-23 4:36 ` Huang Rui [this message]
2020-09-23 4:36 ` Huang Rui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200923043647.GA3536145@hr-amd \
--to=ray.huang@amd.com \
--cc=airlied@linux.ie \
--cc=amd-gfx@lists.freedesktop.org \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-graphics-maintainer@vmware.com \
--cc=sroland@vmware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.