Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: use only one reservation object for each VM v2

Reduces the locking and fencing overhead.

v2: add comment why we need the duplicates list in the GEM op.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>

authored by

Christian König and committed by
Alex Deucher
bf60efd3 a5b75058

+9 -30
+4 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
··· 455 455 struct ttm_validate_buffer tv, *entry; 456 456 struct amdgpu_bo_list_entry *vm_bos; 457 457 struct ww_acquire_ctx ticket; 458 - struct list_head list; 458 + struct list_head list, duplicates; 459 459 unsigned domain; 460 460 int r; 461 461 462 462 INIT_LIST_HEAD(&list); 463 + INIT_LIST_HEAD(&duplicates); 463 464 464 465 tv.bo = &bo_va->bo->tbo; 465 466 tv.shared = true; ··· 470 469 if (!vm_bos) 471 470 return; 472 471 473 - r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL); 472 + /* Provide duplicates to avoid -EALREADY */ 473 + r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates); 474 474 if (r) 475 475 goto error_free; 476 476
+5 -28
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
··· 686 686 } 687 687 688 688 /** 689 - * amdgpu_vm_fence_pts - fence page tables after an update 690 - * 691 - * @vm: requested vm 692 - * @start: start of GPU address range 693 - * @end: end of GPU address range 694 - * @fence: fence to use 695 - * 696 - * Fence the page tables in the range @start - @end (cayman+). 697 - * 698 - * Global and local mutex must be locked! 699 - */ 700 - static void amdgpu_vm_fence_pts(struct amdgpu_vm *vm, 701 - uint64_t start, uint64_t end, 702 - struct fence *fence) 703 - { 704 - unsigned i; 705 - 706 - start >>= amdgpu_vm_block_size; 707 - end >>= amdgpu_vm_block_size; 708 - 709 - for (i = start; i <= end; ++i) 710 - amdgpu_bo_fence(vm->page_tables[i].bo, fence, true); 711 - } 712 - 713 - /** 714 689 * amdgpu_vm_bo_update_mapping - update a mapping in the vm page table 715 690 * 716 691 * @adev: amdgpu_device pointer ··· 788 813 if (r) 789 814 goto error_free; 790 815 791 - amdgpu_vm_fence_pts(vm, mapping->it.start, 792 - mapping->it.last + 1, f); 816 + amdgpu_bo_fence(vm->page_directory, f, true); 793 817 if (fence) { 794 818 fence_put(*fence); 795 819 *fence = fence_get(f); ··· 1063 1089 1064 1090 /* walk over the address space and allocate the page tables */ 1065 1091 for (pt_idx = saddr; pt_idx <= eaddr; ++pt_idx) { 1092 + struct reservation_object *resv = vm->page_directory->tbo.resv; 1066 1093 struct amdgpu_bo *pt; 1067 1094 1068 1095 if (vm->page_tables[pt_idx].bo) ··· 1072 1097 /* drop mutex to allocate and clear page table */ 1073 1098 mutex_unlock(&vm->mutex); 1074 1099 1100 + ww_mutex_lock(&resv->lock, NULL); 1075 1101 r = amdgpu_bo_create(adev, AMDGPU_VM_PTE_COUNT * 8, 1076 1102 AMDGPU_GPU_PAGE_SIZE, true, 1077 1103 AMDGPU_GEM_DOMAIN_VRAM, 1078 1104 AMDGPU_GEM_CREATE_NO_CPU_ACCESS, 1079 - NULL, NULL, &pt); 1105 + NULL, resv, &pt); 1106 + ww_mutex_unlock(&resv->lock); 1080 1107 if (r) 1081 1108 goto error_free; 1082 1109