diff options
author | Chunming Zhou <David1.Zhou@amd.com> | 2017-04-21 03:51:04 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-05-24 17:40:09 -0400 |
commit | c350577073de8fe21e6cdd798c4e4746d670bb47 (patch) | |
tree | 968c894c30c1e0ee539eb347c1117f104b681144 | |
parent | 1e9ef26fb385394c3b0267c8293f4178729d8719 (diff) |
drm/amdgpu: add limitation for dedicated vm number v4
Limit reserved vmids to 1 to avoid taking too many
out of commission and starving the system.
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
Signed-off-by: Chunming Zhou <David1.Zhou@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 |
2 files changed, 12 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 86ef0cdfd04d..2ea91392290c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -551,6 +551,7 @@ static void amdgpu_vm_free_reserved_vmid(struct amdgpu_device *adev, | |||
551 | list_add(&vm->reserved_vmid[vmhub]->list, | 551 | list_add(&vm->reserved_vmid[vmhub]->list, |
552 | &id_mgr->ids_lru); | 552 | &id_mgr->ids_lru); |
553 | vm->reserved_vmid[vmhub] = NULL; | 553 | vm->reserved_vmid[vmhub] = NULL; |
554 | atomic_dec(&id_mgr->reserved_vmid_num); | ||
554 | } | 555 | } |
555 | mutex_unlock(&id_mgr->lock); | 556 | mutex_unlock(&id_mgr->lock); |
556 | } | 557 | } |
@@ -567,6 +568,13 @@ static int amdgpu_vm_alloc_reserved_vmid(struct amdgpu_device *adev, | |||
567 | mutex_lock(&id_mgr->lock); | 568 | mutex_lock(&id_mgr->lock); |
568 | if (vm->reserved_vmid[vmhub]) | 569 | if (vm->reserved_vmid[vmhub]) |
569 | goto unlock; | 570 | goto unlock; |
571 | if (atomic_inc_return(&id_mgr->reserved_vmid_num) > | ||
572 | AMDGPU_VM_MAX_RESERVED_VMID) { | ||
573 | DRM_ERROR("Over limitation of reserved vmid\n"); | ||
574 | atomic_dec(&id_mgr->reserved_vmid_num); | ||
575 | r = -EINVAL; | ||
576 | goto unlock; | ||
577 | } | ||
570 | /* Select the first entry VMID */ | 578 | /* Select the first entry VMID */ |
571 | idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); | 579 | idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); |
572 | list_del_init(&idle->list); | 580 | list_del_init(&idle->list); |
@@ -2321,6 +2329,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev) | |||
2321 | 2329 | ||
2322 | mutex_init(&id_mgr->lock); | 2330 | mutex_init(&id_mgr->lock); |
2323 | INIT_LIST_HEAD(&id_mgr->ids_lru); | 2331 | INIT_LIST_HEAD(&id_mgr->ids_lru); |
2332 | atomic_set(&id_mgr->reserved_vmid_num, 0); | ||
2324 | 2333 | ||
2325 | /* skip over VMID 0, since it is the system VM */ | 2334 | /* skip over VMID 0, since it is the system VM */ |
2326 | for (j = 1; j < id_mgr->num_ids; ++j) { | 2335 | 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 24ccf677f5a5..fb25bb747730 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | |||
@@ -84,6 +84,8 @@ struct amdgpu_bo_list_entry; | |||
84 | 84 | ||
85 | /* hardcode that limit for now */ | 85 | /* hardcode that limit for now */ |
86 | #define AMDGPU_VA_RESERVED_SIZE (8 << 20) | 86 | #define AMDGPU_VA_RESERVED_SIZE (8 << 20) |
87 | /* max vmids dedicated for process */ | ||
88 | #define AMDGPU_VM_MAX_RESERVED_VMID 1 | ||
87 | 89 | ||
88 | struct amdgpu_vm_pt { | 90 | struct amdgpu_vm_pt { |
89 | struct amdgpu_bo *bo; | 91 | struct amdgpu_bo *bo; |
@@ -154,6 +156,7 @@ struct amdgpu_vm_id_manager { | |||
154 | unsigned num_ids; | 156 | unsigned num_ids; |
155 | struct list_head ids_lru; | 157 | struct list_head ids_lru; |
156 | struct amdgpu_vm_id ids[AMDGPU_NUM_VM]; | 158 | struct amdgpu_vm_id ids[AMDGPU_NUM_VM]; |
159 | atomic_t reserved_vmid_num; | ||
157 | }; | 160 | }; |
158 | 161 | ||
159 | struct amdgpu_vm_manager { | 162 | struct amdgpu_vm_manager { |