All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chunming Zhou <david1.zhou-5C7GfCeVMHo@public.gmane.org>
To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Jerry.Zhang-5C7GfCeVMHo@public.gmane.org,
	ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	Kai.Guo-5C7GfCeVMHo@public.gmane.org,
	Chunming Zhou <david1.zhou-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 13/13] drm/amdgpu: free vm lru when vm fini
Date: Wed, 9 May 2018 14:45:43 +0800	[thread overview]
Message-ID: <20180509064543.15937-14-david1.zhou@amd.com> (raw)
In-Reply-To: <20180509064543.15937-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>

That means bo isn't per vm bo when vm fini, back to normal bo instead.

Change-Id: Ida56abd0351422dd0b4a4393545c9cdb0e1a6818
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 50 +++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index a425d498f3fc..89c2cbbce436 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -150,10 +150,34 @@ int amdgpu_vm_lru_init(struct amdgpu_vm_lru *vm_lru, struct amdgpu_device *adev,
 int amdgpu_vm_lru_fini(struct amdgpu_vm_lru *vm_lru, struct amdgpu_device *adev)
 {
 	struct ttm_bo_global *glob = adev->mman.bdev.glob;
+	struct ttm_buffer_object *bo = NULL;
+	struct amdgpu_bo *abo = NULL;
+	struct rb_node *node;
+	int i, j;
+	bool locked;
 
+	locked = reservation_object_trylock(vm_lru->resv);
 	spin_lock(&glob->lru_lock);
 	list_del(&vm_lru->vm_lru_list);
+	for (i = 0; i < TTM_MAX_BO_PRIORITY; i++) {
+		for (j = 0; j < TTM_NUM_MEM_TYPES; j++) {
+			list_for_each_entry(bo, &vm_lru->dynamic_lru[j][i], lru) {
+				struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
+
+				abo->vm_lru = NULL;
+				abo->index = 0;
+			}
+			for (node = rb_first(&vm_lru->fixed_lru[j][i]);
+			     node; node = rb_next(node)) {
+				abo = rb_entry(node, struct amdgpu_bo, node);
+				abo->vm_lru = NULL;
+				abo->index = 0;
+			}
+		}
+	}
 	spin_unlock(&glob->lru_lock);
+	if (locked)
+		reservation_object_unlock(vm_lru->resv);
 
 	return 0;
 }
@@ -253,12 +277,16 @@ static void amdgpu_vm_bo_add_to_rb(struct amdgpu_bo *bo,
 void amdgpu_vm_add_to_lru(struct ttm_buffer_object *bo)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
-	struct amdgpu_vm_lru *vm_lru = abo->vm_lru;
+	struct amdgpu_bo *abo;
+	struct amdgpu_vm_lru *vm_lru = NULL;
 	struct ttm_mem_type_manager *man;
 
+	if (bo->destroy != ttm_transfered_destroy) {
+		abo = ttm_to_amdgpu_bo(bo);
+		vm_lru = abo->vm_lru;
+	}
 	if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
-		if (bo->destroy == ttm_transfered_destroy) {
+		if (bo->destroy == ttm_transfered_destroy || !vm_lru) {
 			BUG_ON(!list_empty(&bo->lru));
 
 			man = &bdev->man[bo->mem.mem_type];
@@ -300,11 +328,15 @@ static struct amdgpu_bo *amdgpu_vm_bo_rb_find(struct rb_root *root, u64 index)
 
 void amdgpu_vm_del_from_lru(struct ttm_buffer_object *bo)
 {
-	struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
-	struct amdgpu_vm_lru *vm_lru = abo->vm_lru;
+	struct amdgpu_bo *abo;
+	struct amdgpu_vm_lru *vm_lru;
 
 	if (bo->destroy == ttm_transfered_destroy)
 		return;
+	abo = ttm_to_amdgpu_bo(bo);
+	vm_lru = abo->vm_lru;
+	if (!vm_lru)
+		return;
 	if (amdgpu_vm_bo_rb_find(&vm_lru->fixed_lru[bo->mem.mem_type][bo->priority],
 				 abo->index)) {
 		rb_erase(&abo->node,
@@ -315,12 +347,16 @@ void amdgpu_vm_del_from_lru(struct ttm_buffer_object *bo)
 
 void amdgpu_vm_move_to_lru_tail(struct ttm_buffer_object *bo)
 {
-	struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
-	struct amdgpu_vm_lru *vm_lru = abo->vm_lru;
+	struct amdgpu_bo *abo;
+	struct amdgpu_vm_lru *vm_lru;
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
 
 	if (bo->destroy == ttm_transfered_destroy)
 		return;
+	abo = ttm_to_amdgpu_bo(bo);
+	vm_lru = abo->vm_lru;
+	if (!vm_lru)
+		return;
 	if (bo->resv == vm_lru->resv)
                list_move_tail(&vm_lru->vm_lru_list, &adev->vm_lru_list);
 }
-- 
2.14.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-05-09  6:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09  6:45 [PATCH 00/13] *** per vm lru *** Chunming Zhou
2018-05-09  6:45 ` [PATCH 03/13] drm/amdgpu: add lru backend for amdgpu driver Chunming Zhou
2018-05-09  6:45 ` [PATCH 05/13] drm/amdgpu: pass vm lru to buffer object Chunming Zhou
2018-05-09  6:45 ` [PATCH 06/13] drm/amdgpu: add amdgpu lru implementation Chunming Zhou
2018-05-09  6:45 ` [PATCH 07/13] drm/ttm: export ttm_bo_ref_bug Chunming Zhou
     [not found] ` <20180509064543.15937-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-05-09  6:45   ` [PATCH 01/13] ttm: abstruct evictable bo Chunming Zhou
2018-05-09  8:34     ` Lucas Stach
2018-05-09  9:50       ` Daniel Vetter
2018-05-09 10:06         ` zhoucm1
2018-05-09 16:04           ` Alex Deucher
2018-05-09  6:45   ` [PATCH 02/13] ttm: allow driver has own lru policy Chunming Zhou
2018-05-09  6:45   ` [PATCH 04/13] drm/amdgpu: init/fini vm lru Chunming Zhou
2018-05-09  6:45   ` [PATCH 08/13] drm/amdgpu: use RB tree instead of link list Chunming Zhou
2018-05-09  6:45   ` [PATCH 09/13] drm/amdgpu: add bo index counter Chunming Zhou
2018-05-09  6:45   ` [PATCH 10/13] drm/amdgpu: bulk move per vm bo Chunming Zhou
2018-05-09  6:45   ` [PATCH 12/13] drm/amdgpu: transferred bo doesn't use vm lru Chunming Zhou
2018-05-09  6:45   ` Chunming Zhou [this message]
2018-05-09  6:45 ` [PATCH 11/13] ttm: export ttm_transfered_destroy Chunming Zhou
2018-05-10  5:07 ` [PATCH 00/13] *** per vm lru *** Zhang, Jerry (Junwei)
     [not found]   ` <5AF3D38F.1040704-5C7GfCeVMHo@public.gmane.org>
2018-05-10  8:45     ` zhoucm1
2018-05-14  5:44       ` Zhang, Jerry (Junwei)
     [not found]       ` <8c18f05c-54bc-47c8-8d63-8610420238cc-5C7GfCeVMHo@public.gmane.org>
2018-05-14  5:54         ` Zhang, Jerry (Junwei)

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=20180509064543.15937-14-david1.zhou@amd.com \
    --to=david1.zhou-5c7gfcevmho@public.gmane.org \
    --cc=Jerry.Zhang-5C7GfCeVMHo@public.gmane.org \
    --cc=Kai.Guo-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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 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.