dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Lang.Yu@amd.com, thomas_os@shipmail.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH 4/4] drm/amdgpu: switch gtt_mgr to counting used pages
Date: Tue,  1 Jun 2021 14:25:28 +0200	[thread overview]
Message-ID: <20210601122528.1643-4-christian.koenig@amd.com> (raw)
In-Reply-To: <20210601122528.1643-1-christian.koenig@amd.com>

From: Lang Yu <Lang.Yu@amd.com>

Change mgr->available into mgr->used (invert the value).

Makes more sense to do it this way since we don't need the spinlock any
more to double check the handling.

v3 (chk): separated from the TEMPOARAY FLAG change.

Signed-off-by: Lang Yu <Lang.Yu@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 26 ++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h     |  2 +-
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 5e6b76441449..4d7e34a8d3fd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -121,14 +121,10 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man,
 	struct amdgpu_gtt_node *node;
 	int r;
 
-	if (!(place->flags & TTM_PL_FLAG_TEMPORARY)) {
-		spin_lock(&mgr->lock);
-		if (atomic64_read(&mgr->available) < mem->num_pages) {
-			spin_unlock(&mgr->lock);
-			return -ENOSPC;
-		}
-		atomic64_sub(mem->num_pages, &mgr->available);
-		spin_unlock(&mgr->lock);
+	if (!(place->flags & TTM_PL_FLAG_TEMPORARY) &&
+	    atomic64_add_return(mem->num_pages, &mgr->used) >  man->size) {
+		atomic64_sub(mem->num_pages, &mgr->used);
+		return -ENOSPC;
 	}
 
 	if (!place->lpfn) {
@@ -164,7 +160,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man,
 
 err_out:
 	if (!(place->flags & TTM_PL_FLAG_TEMPORARY))
-		atomic64_add(mem->num_pages, &mgr->available);
+		atomic64_sub(mem->num_pages, &mgr->used);
 
 	return r;
 }
@@ -191,7 +187,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
 	}
 
 	if (!(mem->placement & TTM_PL_FLAG_TEMPORARY))
-		atomic64_add(mem->num_pages, &mgr->available);
+		atomic64_sub(mem->num_pages, &mgr->used);
 }
 
 /**
@@ -204,9 +200,8 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_resource_manager *man)
 {
 	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
-	s64 result = man->size - atomic64_read(&mgr->available);
 
-	return (result > 0 ? result : 0) * PAGE_SIZE;
+	return atomic64_read(&mgr->used) * PAGE_SIZE;
 }
 
 /**
@@ -252,9 +247,8 @@ static void amdgpu_gtt_mgr_debug(struct ttm_resource_manager *man,
 	drm_mm_print(&mgr->mm, printer);
 	spin_unlock(&mgr->lock);
 
-	drm_printf(printer, "man size:%llu pages, gtt available:%lld pages, usage:%lluMB\n",
-		   man->size, (u64)atomic64_read(&mgr->available),
-		   amdgpu_gtt_mgr_usage(man) >> 20);
+	drm_printf(printer, "man size:%llu pages,  gtt used:%llu pages\n",
+		   man->size, atomic64_read(&mgr->used));
 }
 
 static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = {
@@ -286,7 +280,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 	size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
 	drm_mm_init(&mgr->mm, start, size);
 	spin_lock_init(&mgr->lock);
-	atomic64_set(&mgr->available, gtt_size >> PAGE_SHIFT);
+	atomic64_set(&mgr->used, 0);
 
 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager);
 	ttm_resource_manager_set_used(man, true);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index b2c97b19cbe1..64a78da33805 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -51,7 +51,7 @@ struct amdgpu_gtt_mgr {
 	struct ttm_resource_manager manager;
 	struct drm_mm mm;
 	spinlock_t lock;
-	atomic64_t available;
+	atomic64_t used;
 };
 
 struct amdgpu_mman {
-- 
2.25.1


  parent reply	other threads:[~2021-06-01 12:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01 12:25 [PATCH 1/4] drm/ttm: add TTM_PL_FLAG_TEMPORARY flag v3 Christian König
2021-06-01 12:25 ` [PATCH 2/4] drm/amdgpu: user temporary GTT as bounce buffer Christian König
2021-06-01 12:25 ` [PATCH 3/4] drm/amdgpu: always allow evicting to SYSTEM domain Christian König
2021-06-02  1:30   ` Yu, Lang
2021-06-01 12:25 ` Christian König [this message]
2021-06-07 12:36 ` [PATCH 1/4] drm/ttm: add TTM_PL_FLAG_TEMPORARY flag v3 Christian König
2021-06-07 12:38   ` Thomas Hellström (Intel)
2021-06-07 12:41     ` Christian König
2021-06-07 12:58       ` Yu, Lang
2021-06-07 13:01         ` Christian König
2021-06-07 14:42           ` Das, Nirmoy
2021-06-07 15:27             ` Das, Nirmoy

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=20210601122528.1643-4-christian.koenig@amd.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=Lang.Yu@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=thomas_os@shipmail.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).