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 04/13] drm/amdgpu: init/fini vm lru
Date: Wed, 9 May 2018 14:45:34 +0800	[thread overview]
Message-ID: <20180509064543.15937-5-david1.zhou@amd.com> (raw)
In-Reply-To: <20180509064543.15937-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>

Change-Id: Icba45a329e2e2094581ad6c4b8b9028a2e5c5faa
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 37 +++++++++++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     | 14 +++++++++++
 5 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2d7500921c0b..f186c8f29774 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1532,6 +1532,8 @@ struct amdgpu_device {
 	dma_addr_t			dummy_page_addr;
 	struct amdgpu_vm_manager	vm_manager;
 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
+	struct amdgpu_vm_lru		kernel_vm_lru;
+	struct list_head		vm_lru_list;
 
 	/* memory management */
 	struct amdgpu_mman		mman;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 887f7c9e84e0..feafcfa2633d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2266,6 +2266,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	spin_lock_init(&adev->audio_endpt_idx_lock);
 	spin_lock_init(&adev->mm_stats.lock);
 
+	INIT_LIST_HEAD(&adev->vm_lru_list);
 	INIT_LIST_HEAD(&adev->shadow_list);
 	mutex_init(&adev->shadow_list_lock);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 0bbb1dfdceff..207f88f38b23 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1417,6 +1417,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 		return r;
 	}
 	adev->mman.initialized = true;
+	amdgpu_vm_lru_init(&adev->kernel_vm_lru, adev, NULL);
 
 	/* We opt to avoid OOM on system pages allocations */
 	adev->mman.bdev.no_retry = true;
@@ -1537,6 +1538,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 		return;
 
 	amdgpu_ttm_debugfs_fini(adev);
+	amdgpu_vm_lru_fini(&adev->kernel_vm_lru, adev);
 	amdgpu_ttm_fw_reserve_vram_fini(adev);
 	if (adev->mman.aper_base_kaddr)
 		iounmap(adev->mman.aper_base_kaddr);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index cc6093233ae7..72ff2d9c8686 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -124,6 +124,39 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
 	spin_unlock(&vm->status_lock);
 }
 
+int amdgpu_vm_lru_init(struct amdgpu_vm_lru *vm_lru, struct amdgpu_device *adev,
+		       struct reservation_object *resv)
+{
+	struct ttm_bo_global *glob = adev->mman.bdev.glob;
+	int i, j;
+
+	INIT_LIST_HEAD(&vm_lru->vm_lru_list);
+	for (i = 0; i < TTM_NUM_MEM_TYPES; i++) {
+		for (j = 0; j < TTM_MAX_BO_PRIORITY; j++) {
+			INIT_LIST_HEAD(&vm_lru->fixed_lru[i][j]);
+			INIT_LIST_HEAD(&vm_lru->dynamic_lru[i][j]);
+		}
+	}
+	spin_lock(&glob->lru_lock);
+	list_add_tail(&vm_lru->vm_lru_list, &adev->vm_lru_list);
+	spin_unlock(&glob->lru_lock);
+
+	vm_lru->resv = resv;
+
+	return 0;
+}
+
+int amdgpu_vm_lru_fini(struct amdgpu_vm_lru *vm_lru, struct amdgpu_device *adev)
+{
+	struct ttm_bo_global *glob = adev->mman.bdev.glob;
+
+	spin_lock(&glob->lru_lock);
+	list_del(&vm_lru->vm_lru_list);
+	spin_unlock(&glob->lru_lock);
+
+	return 0;
+}
+
 struct ttm_buffer_object *amdgpu_vm_get_evictable_bo(struct ttm_bo_device *bdev,
 						     uint32_t mem_type,
 						     const struct ttm_place *place,
@@ -2413,6 +2446,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	uint64_t flags;
 	int r, i;
 
+	amdgpu_vm_lru_init(&vm->vm_lru, adev, NULL);
 	vm->va = RB_ROOT_CACHED;
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
 		vm->reserved_vmid[i] = NULL;
@@ -2468,7 +2502,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	r = amdgpu_bo_create(adev, &bp, &root);
 	if (r)
 		goto error_free_sched_entity;
-
+	vm->vm_lru.resv = root->tbo.resv;
 	r = amdgpu_bo_reserve(root, true);
 	if (r)
 		goto error_free_root;
@@ -2672,6 +2706,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 				      adev->vm_manager.root_level);
 		amdgpu_bo_unreserve(root);
 	}
+	amdgpu_vm_lru_fini(&vm->vm_lru, adev);
 	amdgpu_bo_unref(&root);
 	dma_fence_put(vm->last_update);
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 0c965683faba..66ee902614a2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -29,6 +29,7 @@
 #include <linux/rbtree.h>
 #include <drm/gpu_scheduler.h>
 #include <drm/drm_file.h>
+#include <drm/ttm/ttm_bo_driver.h>
 
 #include "amdgpu_sync.h"
 #include "amdgpu_ring.h"
@@ -135,6 +136,13 @@ enum amdgpu_vm_level {
 	AMDGPU_VM_PTB
 };
 
+struct amdgpu_vm_lru {
+	struct list_head vm_lru_list;
+	struct list_head fixed_lru[TTM_NUM_MEM_TYPES][TTM_MAX_BO_PRIORITY];
+	struct list_head dynamic_lru[TTM_NUM_MEM_TYPES][TTM_MAX_BO_PRIORITY];
+	struct reservation_object *resv;
+};
+
 /* base structure for tracking BO usage in a VM */
 struct amdgpu_vm_bo_base {
 	/* constant after initialization */
@@ -167,6 +175,7 @@ struct amdgpu_vm {
 	/* tree of virtual addresses mapped */
 	struct rb_root_cached	va;
 
+	struct amdgpu_vm_lru	vm_lru;
 	/* protecting invalidated */
 	spinlock_t		status_lock;
 
@@ -256,6 +265,11 @@ struct amdgpu_vm_manager {
 	spinlock_t				pasid_lock;
 };
 
+int amdgpu_vm_lru_init(struct amdgpu_vm_lru *vm_lru, struct amdgpu_device *adev,
+		       struct reservation_object *resv);
+int amdgpu_vm_lru_fini(struct amdgpu_vm_lru *vm_lru,
+		       struct amdgpu_device *adev);
+
 struct ttm_buffer_object *amdgpu_vm_get_evictable_bo(struct ttm_bo_device *bdev,
 						     uint32_t mem_type,
 						     const struct ttm_place *place,
-- 
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   ` Chunming Zhou [this message]
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   ` [PATCH 13/13] drm/amdgpu: free vm lru when vm fini Chunming Zhou
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-5-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.