[PATCH 4/6] drm/amdgpu: add limitation for dedicated vm number v4

2017-04-27 Thread Chunming Zhou
v2: move #define to amdgpu_vm.h
v3: move reserved vmid counter to id_manager,
and increase counter before allocating vmid
v4: rename to reserved_vmid_num

Change-Id: Ie5958cf6dbdc1c8278e61d9158483472d6f5c6e3
Signed-off-by: Chunming Zhou 
Reviewed-by: Junwei Zhang 
Reviewed-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e37421e..e6fdfa4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -557,6 +557,7 @@ static void amdgpu_vm_free_reserved_vmid(struct 
amdgpu_device *adev,
list_add(>reserved_vmid[vmhub]->list,
_mgr->ids_lru);
vm->reserved_vmid[vmhub] = NULL;
+   atomic_dec(_mgr->reserved_vmid_num);
}
mutex_unlock(_mgr->lock);
 }
@@ -573,6 +574,13 @@ static int amdgpu_vm_alloc_reserved_vmid(struct 
amdgpu_device *adev,
mutex_lock(_mgr->lock);
if (vm->reserved_vmid[vmhub])
goto unlock;
+   if (atomic_inc_return(_mgr->reserved_vmid_num) >
+   AMDGPU_VM_MAX_RESERVED_VMID) {
+   DRM_ERROR("Over limitation of reserved vmid\n");
+   atomic_dec(_mgr->reserved_vmid_num);
+   r = -EINVAL;
+   goto unlock;
+   }
/* Select the first entry VMID */
idle = list_first_entry(_mgr->ids_lru, struct amdgpu_vm_id, list);
list_del_init(>list);
@@ -2376,6 +2384,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
 
mutex_init(_mgr->lock);
INIT_LIST_HEAD(_mgr->ids_lru);
+   atomic_set(_mgr->reserved_vmid_num, 0);
 
/* skip over VMID 0, since it is the system VM */
for (j = 1; j < id_mgr->num_ids; ++j) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 8eedca1..9828fcd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -84,6 +84,8 @@
 
 /* hardcode that limit for now */
 #define AMDGPU_VA_RESERVED_SIZE(8 << 20)
+/* max vmids dedicated for process */
+#define AMDGPU_VM_MAX_RESERVED_VMID1
 
 struct amdgpu_vm_pt {
struct amdgpu_bo*bo;
@@ -157,6 +159,7 @@ struct amdgpu_vm_id_manager {
unsignednum_ids;
struct list_headids_lru;
struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
+   atomic_treserved_vmid_num;
 };
 
 struct amdgpu_vm_manager {
-- 
1.9.1

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


[PATCH 4/6] drm/amdgpu: add limitation for dedicated vm number v4

2017-04-26 Thread Chunming Zhou
v2: move #define to amdgpu_vm.h
v3: move reserved vmid counter to id_manager,
and increase counter before allocating vmid
v4: rename to reserved_vmid_num

Change-Id: Ie5958cf6dbdc1c8278e61d9158483472d6f5c6e3
Signed-off-by: Chunming Zhou 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e37421e..e6fdfa4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -557,6 +557,7 @@ static void amdgpu_vm_free_reserved_vmid(struct 
amdgpu_device *adev,
list_add(>reserved_vmid[vmhub]->list,
_mgr->ids_lru);
vm->reserved_vmid[vmhub] = NULL;
+   atomic_dec(_mgr->reserved_vmid_num);
}
mutex_unlock(_mgr->lock);
 }
@@ -573,6 +574,13 @@ static int amdgpu_vm_alloc_reserved_vmid(struct 
amdgpu_device *adev,
mutex_lock(_mgr->lock);
if (vm->reserved_vmid[vmhub])
goto unlock;
+   if (atomic_inc_return(_mgr->reserved_vmid_num) >
+   AMDGPU_VM_MAX_RESERVED_VMID) {
+   DRM_ERROR("Over limitation of reserved vmid\n");
+   atomic_dec(_mgr->reserved_vmid_num);
+   r = -EINVAL;
+   goto unlock;
+   }
/* Select the first entry VMID */
idle = list_first_entry(_mgr->ids_lru, struct amdgpu_vm_id, list);
list_del_init(>list);
@@ -2376,6 +2384,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
 
mutex_init(_mgr->lock);
INIT_LIST_HEAD(_mgr->ids_lru);
+   atomic_set(_mgr->reserved_vmid_num, 0);
 
/* skip over VMID 0, since it is the system VM */
for (j = 1; j < id_mgr->num_ids; ++j) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 8eedca1..9828fcd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -84,6 +84,8 @@
 
 /* hardcode that limit for now */
 #define AMDGPU_VA_RESERVED_SIZE(8 << 20)
+/* max vmids dedicated for process */
+#define AMDGPU_VM_MAX_RESERVED_VMID1
 
 struct amdgpu_vm_pt {
struct amdgpu_bo*bo;
@@ -157,6 +159,7 @@ struct amdgpu_vm_id_manager {
unsignednum_ids;
struct list_headids_lru;
struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
+   atomic_treserved_vmid_num;
 };
 
 struct amdgpu_vm_manager {
-- 
1.9.1

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