shadow page table support V3
Subsystems (3)
cover shadow page table support V3
Since we cannot ensure VRAM is consistent after a GPU reset, page table shadowing is necessary. Shadowed page tables are, in a sense, a method to recover the consistent state of the page tables before the reset occurred.
We need to allocate GTT bo as the shadow of VRAM bo when creating page table, and make them the same. After gpu reset, we will need to use SDMA to copy GTT bo content to VRAM bo, then page table will be recoveried.
V2:
Shadow bo uses a shadow entity running on normal run queue, after gpu reset, we need to wait for all shadow jobs finished first, then recovery page table from shadow.
V3:
Addressed Christian comments for shadow bo part.
Chunming Zhou (18):
drm/amdgpu: add shadow bo support V2
drm/amdgpu: validate shadow as well when validating bo drm/amdgpu: allocate shadow for pd/pt bo V2 drm/amdgpu: add shadow flag V2
drm/amdgpu: sync bo and shadow
drm/amdgpu: implement vm recovery function from shadow drm/amdgpu: add shadow_entity for shadow page table updates drm/amdgpu: update pd shadow bo
drm/amdgpu: update pt shadow
drm/amd: add last fence in sched entity drm/amdgpu: link all vm clients
drm/amdgpu: add vm_list_lock
drm/amd: add block entity function
drm/amdgpu: add shadow fence owner
drm/amd: block entity
drm/amdgpu: recover page tables after gpu reset drm/amdgpu: add need backup function
drm/amdgpu: add backup condition for vm
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 25 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 82 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 88 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 100 ++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 + drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 281 +++++++++++++++++++------- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 38 +++- drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 5 + include/uapi/drm/amdgpu_drm.h | 2 + 10 files changed, 524 insertions(+), 105 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1470983947-32579-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
PATCH 1/18 drm/amdgpu: add shadow bo support V2
shadow bo is the shadow of a bo, which is always in GTT, which can be used to backup the original bo.
V2:
reference shadow parent, shadow bo will be freed by who allocted him.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48 ++++++++++++++++++++++++++++-- include/uapi/drm/amdgpu_drm.h | 2 ++ 3 files changed, 48 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -507,6 +507,7 @@ struct amdgpu_bo {struct amdgpu_device *adev;struct drm_gem_object gem_base;struct amdgpu_bo *parent; +struct amdgpu_bo *shadow;struct ttm_bo_kmap_obj dma_buf_vmap;struct amdgpu_mn *mn;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +45 -3
66 lines not on this page · raw message
include/uapi/drm/amdgpu_drm.h +2 -0
@@ -77,6 +77,8 @@#define AMDGPU_GEM_CREATE_CPU_GTT_USWC (1 << 2)/* Flag that the memory should be in VRAM and cleared */ #define AMDGPU_GEM_CREATE_VRAM_CLEARED (1 << 3) +/* Flag that create shadow bo(GTT) while allocating vram bo */ +#define AMDGPU_GEM_CREATE_SHADOW (1 << 4)struct drm_amdgpu_gem_create_in {/** the requested memory size */
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/18 drm/amdgpu: validate shadow as well when validating bo
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 76 ++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +46 -30
@@ -288,18 +288,56 @@ static u64 amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev)return max (bytes_moved_threshold,1024 *1024ull ); } +static int amdgpu_cs_bo_validate (struct amdgpu_cs_parser *p, +struct amdgpu_bo *bo) +{ +u64 initial_bytes_moved; +uint32_t domain; +int r; + +if (bo->pin_count) +return 0 ; + +/* Avoid moving this one if we have moved too many buffers +* for this IB already. +* +* Note that this allows moving at least one buffer of +* any size, because it doesn't take the current "bo" +* into account. We don't want to disallow buffer moves +* completely. +*/ +if (p->bytes_moved <= p->bytes_moved_threshold) + domain = bo->prefered_domains; +else + domain = bo->allowed_domains; + +retry: +amdgpu_ttm_placement_from_domain (bo, domain); + initial_bytes_moved =atomic64_read (&bo->adev->num_bytes_moved); + r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false); + p->bytes_moved +=atomic64_read (&bo->adev->num_bytes_moved) - + initial_bytes_moved; + +if (unlikely (r)) { +if (r != -ERESTARTSYS && domain != bo->allowed_domains) { + domain = bo->allowed_domains; + goto retry; + } + } + +return r; +} +int amdgpu_cs_list_validate (struct amdgpu_cs_parser *p,struct list_head *validated) {struct amdgpu_bo_list_entry *lobj; -u64 initial_bytes_moved;int r;list_for_each_entry (lobj, validated, tv.head) {struct amdgpu_bo *bo = lobj->robj;bool binding_userptr = false;struct mm_struct *usermm; -uint32_t domain; usermm =amdgpu_ttm_tt_get_usermm (bo->tbo.ttm);if (usermm && usermm != current->mm)
@@ -314,35 +352,13 @@ int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p, binding_userptr = true; } -if (bo->pin_count) -continue ; - -/* Avoid moving this one if we have moved too many buffers -* for this IB already. -* -* Note that this allows moving at least one buffer of -* any size, because it doesn't take the current "bo" -* into account. We don't want to disallow buffer moves -* completely. -*/ -if (p->bytes_moved <= p->bytes_moved_threshold) - domain = bo->prefered_domains; -else - domain = bo->allowed_domains; - - retry: -amdgpu_ttm_placement_from_domain (bo, domain); - initial_bytes_moved =atomic64_read (&bo->adev->num_bytes_moved); - r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false); - p->bytes_moved +=atomic64_read (&bo->adev->num_bytes_moved) - - initial_bytes_moved; - -if (unlikely (r)) { -if (r != -ERESTARTSYS && domain != bo->allowed_domains) { - domain = bo->allowed_domains; - goto retry; - } + r =amdgpu_cs_bo_validate (p, bo); +if (r)return r; +if (bo->shadow) { + r =amdgpu_cs_bo_validate (p, bo); +if (r) +return r; }if (binding_userptr) {
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/18 drm/amdgpu: allocate shadow for pd/pt bo V2
In reply to a message not in the archiveThe pd/pt shadow bo will be used to backup page table, when gpu reset happens, we can restore the page table by them.
V2:
Free shadow bo.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +11 -3
@@ -1341,7 +1341,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev, r =amdgpu_bo_create (adev,AMDGPU_VM_PTE_COUNT *8 ,AMDGPU_GPU_PAGE_SIZE , true,AMDGPU_GEM_DOMAIN_VRAM , -AMDGPU_GEM_CREATE_NO_CPU_ACCESS , +AMDGPU_GEM_CREATE_NO_CPU_ACCESS | +AMDGPU_GEM_CREATE_SHADOW ,NULL , resv, &pt);if (r) goto error_free;
@@ -1540,7 +1541,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) r =amdgpu_bo_create (adev, pd_size, align, true,AMDGPU_GEM_DOMAIN_VRAM , -AMDGPU_GEM_CREATE_NO_CPU_ACCESS , +AMDGPU_GEM_CREATE_NO_CPU_ACCESS | +AMDGPU_GEM_CREATE_SHADOW ,NULL ,NULL , &vm->page_directory);if (r) goto error_free_sched_entity;
@@ -1599,10 +1601,16 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)kfree (mapping); } -for (i =0 ; i <amdgpu_vm_num_pdes (adev); i++) +for (i =0 ; i <amdgpu_vm_num_pdes (adev); i++) { +if (vm->page_tables[i].entry.robj && + vm->page_tables[i].entry.robj->shadow) +amdgpu_bo_unref (&vm->page_tables[i].entry.robj->shadow);amdgpu_bo_unref (&vm->page_tables[i].entry.robj); + }drm_free_large (vm->page_tables); +if (vm->page_directory->shadow) +amdgpu_bo_unref (&vm->page_directory->shadow);amdgpu_bo_unref (&vm->page_directory);fence_put (vm->page_directory_fence); }
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/18 drm/amdgpu: add shadow flag V2
In reply to a message not in the archiveIndicate if need to sync between bo and shadow, where sync to where. V2:
Rename to backup_shadow
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8 -0
@@ -482,6 +482,12 @@ struct amdgpu_bo_va {#define AMDGPU_GEM_DOMAIN_MAX 0x3 +enum amdgpu_bo_shadow { +AMDGPU_BO_SHADOW_TO_NONE =0 , +AMDGPU_BO_SHADOW_TO_PARENT , +AMDGPU_BO_SHADOW_TO_SHADOW , +}; +struct amdgpu_bo {/* Protected by gem.mutex */ struct list_head list;
@@ -508,6 +514,8 @@ struct amdgpu_bo {struct drm_gem_object gem_base;struct amdgpu_bo *parent;struct amdgpu_bo *shadow; +/* indicate if need to sync between bo and shadow */ +enum amdgpu_bo_shadow backup_shadow;struct ttm_bo_kmap_obj dma_buf_vmap;struct amdgpu_mn *mn;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/18 drm/amdgpu: sync bo and shadow
In reply to a message not in the archiveUse shadow flag to judge which direction to sync.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 52 ++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 +++ 2 files changed, 57 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +52 -0
@@ -443,6 +443,58 @@ int amdgpu_bo_create(struct amdgpu_device *adev,return r; } +int amdgpu_bo_sync_between_bo_and_shadow (struct amdgpu_device *adev, +struct amdgpu_ring *ring, +struct amdgpu_bo *bo, +struct reservation_object *resv, +struct fence **fence) + +{ +struct amdgpu_bo *shadow = bo->shadow; +uint64_t bo_addr, shadow_addr; +int r; + +if (!shadow) +return -EINVAL ; + +if (bo->backup_shadow &AMDGPU_BO_SHADOW_TO_NONE ) { +DRM_INFO ("No need to sync bo and shadow\n" ); +return 0 ; + } + r =amdgpu_bo_pin (bo, bo->prefered_domains, &bo_addr); +if (r) { +DRM_ERROR ("Failed to pin bo object\n" ); + goto err1; + } + r =amdgpu_bo_pin (bo->shadow, bo->shadow->prefered_domains, &shadow_addr); +if (r) { +DRM_ERROR ("Failed to pin bo shadow object\n" ); + goto err2; + } + + r =reservation_object_reserve_shared (bo->tbo.resv); +if (r) + goto err3; + +if (bo->backup_shadow &AMDGPU_BO_SHADOW_TO_PARENT ) + r =amdgpu_copy_buffer (ring, shadow_addr, bo_addr, +amdgpu_bo_size (bo), resv, fence); +else + r =amdgpu_copy_buffer (ring, bo_addr, shadow_addr, +amdgpu_bo_size (bo), resv, fence); +if (!r) { +amdgpu_bo_fence (bo, *fence, true); + bo->backup_shadow =AMDGPU_BO_SHADOW_TO_NONE ; + } +err3: +amdgpu_bo_unpin (bo->shadow); +err2: +amdgpu_bo_unpin (bo); +err1: + +return r; +} +int amdgpu_bo_kmap (struct amdgpu_bo *bo,void **ptr) {bool is_iomem;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +5 -0
@@ -155,6 +155,11 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo);void amdgpu_bo_fence (struct amdgpu_bo *bo,struct fence *fence,bool shared);u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo); +int amdgpu_bo_sync_between_bo_and_shadow (struct amdgpu_device *adev, +struct amdgpu_ring *ring, +struct amdgpu_bo *bo, +struct reservation_object *resv, +struct fence **fence);/* * sub allocation
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/18 drm/amdgpu: implement vm recovery function from shadow
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -922,6 +922,8 @@ struct amdgpu_vm {/* client id */ u64 client_id; + +struct fence *shadow_sync_fence; };struct amdgpu_vm_id {
@@ -1012,6 +1014,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, uint64_t addr);void amdgpu_vm_bo_rmv (struct amdgpu_device *adev,struct amdgpu_bo_va *bo_va); +int amdgpu_vm_recover_page_table_from_shadow (struct amdgpu_device *adev, +struct amdgpu_vm *vm);/* * context related structures
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +48 -0
66 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/18 drm/amdgpu: add shadow_entity for shadow page table updates
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -1
@@ -922,7 +922,8 @@ struct amdgpu_vm {/* client id */ u64 client_id; - +/* Scheduler entity for shadow page table updates */ +struct amd_sched_entity shadow_entity;struct fence *shadow_sync_fence; };
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -1
@@ -1577,11 +1577,17 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) ring_instance =atomic_inc_return (&adev->vm_manager.vm_pte_next_ring); ring_instance %= adev->vm_manager.vm_pte_num_rings; ring = adev->vm_manager.vm_pte_rings[ring_instance]; + rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL ]; + r =amd_sched_entity_init (&ring->sched, &vm->shadow_entity, + rq, amdgpu_sched_jobs); +if (r) + goto err; + rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_KERNEL ]; r =amd_sched_entity_init (&ring->sched, &vm->entity, rq, amdgpu_sched_jobs);if (r) - goto err; + goto err1; vm->page_directory_fence =NULL ;
@@ -1613,6 +1619,8 @@ error_free_page_directory: error_free_sched_entity:amd_sched_entity_fini (&ring->sched, &vm->entity); +err1: +amd_sched_entity_fini (&ring->sched, &vm->shadow_entity); err:drm_free_large (vm->page_tables);
@@ -1633,6 +1641,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)struct amdgpu_bo_va_mapping *mapping, *tmp;int i; +amd_sched_entity_fini (vm->shadow_entity.sched, &vm->shadow_entity);amd_sched_entity_fini (vm->entity.sched, &vm->entity);if (!RB_EMPTY_ROOT (&vm->va)) {
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 8/18 drm/amdgpu: update pd shadow bo
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 +++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -884,6 +884,7 @@ struct amdgpu_ring {struct amdgpu_vm_pt {struct amdgpu_bo_list_entry entry;uint64_t addr; +uint64_t shadow_addr; };struct amdgpu_vm {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +49 -24
111 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1470983947-32579-9-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 08/18] drm/amdgpu: update pd shadow bo
Quoted 53 lines · Chunming Zhou
Change-Id I8d0c625c9f1c9a16b8e2e915831590be5a9a5242Signed-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 +++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 24 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -884,6 +884,7 @@ struct amdgpu_ring {struct amdgpu_vm_pt {struct amdgpu_bo_list_entry entry;uint64_t addr; +uint64_t shadow_addr; };struct amdgpu_vm {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-15@@ -597,23 +597,13 @@ uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr)return result; } -/** -* amdgpu_vm_update_pdes - make sure that page directory is valid -* -* @adev: amdgpu_device pointer -* @vm: requested vm -* @start: start of GPU address range -* @end: end of GPU address range -* -* Allocates new page tables if necessary -* and updates the page directory. -* Returns 0 for success, error for failure. -*/ -int amdgpu_vm_update_page_directory (struct amdgpu_device *adev, -struct amdgpu_vm *vm) +int amdgpu_vm_update_page_directory_or_shadow (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +bool shadow) {struct amdgpu_ring *ring; -struct amdgpu_bo *pd = vm->page_directory; +struct amdgpu_bo *pd = shadow ? vm->page_directory->shadow : + vm->page_directory;uint64_t pd_addr =amdgpu_bo_gpu_offset (pd);uint32_t incr =AMDGPU_VM_PTE_COUNT *8 ;uint64_t last_pde = ~0 , last_pt = ~0 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, · line 650
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-1@@ -647,10 +637,17 @@ int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,if (bo ==NULL )continue ; - pt =amdgpu_bo_gpu_offset (bo);
Hmm, no need to remove this line as it is common to both branches.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, · line 641
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-3-if (vm->page_tables[pt_idx].addr == pt) -continue ; - vm->page_tables[pt_idx].addr = pt; +if (!shadow) { + pt =amdgpu_bo_gpu_offset (bo);
ditto
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, · line 646
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+if (vm->page_tables[pt_idx].addr == pt) +continue ; + vm->page_tables[pt_idx].addr = pt; + }else { + pt =amdgpu_bo_gpu_offset (bo);
ditto
Quoted 66 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +36
-5+if (vm->page_tables[pt_idx].shadow_addr == pt) +continue ; + vm->page_tables[pt_idx].shadow_addr = pt; + } pde = pd_addr + pt_idx *8 ; if (((last_pde + 8 * count) != pde) ||@@ -678,17 +675,21 @@ int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,if (vm_update_params.ib->length_dw !=0 ) {amdgpu_ring_pad_ib (ring, vm_update_params.ib); -amdgpu_sync_resv (adev, &job->sync, pd->tbo.resv, -AMDGPU_FENCE_OWNER_VM ); +if (!shadow) +amdgpu_sync_resv (adev, &job->sync, pd->tbo.resv, +AMDGPU_FENCE_OWNER_VM );WARN_ON (vm_update_params.ib->length_dw > ndw); - r =amdgpu_job_submit (job, ring, &vm->entity, + r =amdgpu_job_submit (job, ring, + shadow ? &vm->shadow_entity : &vm->entity,AMDGPU_FENCE_OWNER_VM , &fence);if (r) goto error_free;amdgpu_bo_fence (pd, fence, true); -fence_put (vm->page_directory_fence); - vm->page_directory_fence =fence_get (fence); +if (!shadow) { +fence_put (vm->page_directory_fence); + vm->page_directory_fence =fence_get (fence); + }fence_put (fence); }else {@@ -702,6 +703,29 @@ error_free:return r; } +/** +* amdgpu_vm_update_pdes - make sure that page directory is valid +* +* @adev: amdgpu_device pointer +* @vm: requested vm +* @start: start of GPU address range +* @end: end of GPU address range +* +* Allocates new page tables if necessary +* and updates the page directory. +* Returns 0 for success, error for failure. +*/ +int amdgpu_vm_update_page_directory (struct amdgpu_device *adev, +struct amdgpu_vm *vm) +{ +int r; + + r =amdgpu_vm_update_page_directory_or_shadow (adev, vm, true); +if (r) +return r; +return amdgpu_vm_update_page_directory_or_shadow (adev, vm, false); +} +int amdgpu_vm_recover_page_table_from_shadow (struct amdgpu_device *adev,struct amdgpu_vm *vm) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_map(struct amdgpu_device *adev, · line 1440
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -1410,6 +1434,7 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev, entry->tv.shared = true; entry->user_pages =NULL ; vm->page_tables[pt_idx].addr =0 ; + vm->page_tables[pt_idx].shadow_addr =0 ; }return 0 ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 9/18 drm/amdgpu: update pt shadow
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 108 +++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 39 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +69 -39
@@ -871,7 +871,8 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev, *vm_update_params, struct amdgpu_vm *vm, uint64_t start, uint64_t end, - uint64_t dst, uint32_t flags) + uint64_t dst, uint32_t flags, + bool shadow) {const uint64_t mask =AMDGPU_VM_PTE_COUNT -1 ;
@@ -885,7 +886,8 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,/* initialize the variables */ addr = start; pt_idx = addr >> amdgpu_vm_block_size; - pt = vm->page_tables[pt_idx].entry.robj; + pt = shadow ? vm->page_tables[pt_idx].entry.robj->shadow : + vm->page_tables[pt_idx].entry.robj;if ((addr & ~mask) == (end & ~mask)) nptes = end - addr;
@@ -904,7 +906,8 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev,/* walk over the address space and update the page tables */ while (addr < end) { pt_idx = addr >> amdgpu_vm_block_size; - pt = vm->page_tables[pt_idx].entry.robj; + pt = shadow ? vm->page_tables[pt_idx].entry.robj->shadow : + vm->page_tables[pt_idx].entry.robj;if ((addr & ~mask) == (end & ~mask)) nptes = end - addr;
@@ -939,31 +942,15 @@ static void amdgpu_vm_update_ptes(struct amdgpu_device *adev, cur_pe_end, cur_dst, flags); } -/** -* amdgpu_vm_bo_update_mapping - update a mapping in the vm page table -* -* @adev: amdgpu_device pointer -* @exclusive: fence we need to sync to -* @src: address where to copy page table entries from -* @pages_addr: DMA addresses to use for mapping -* @vm: requested vm -* @start: start of mapped range -* @last: last mapped entry -* @flags: flags for the entries -* @addr: addr to set the area to -* @fence: optional resulting fence -* -* Fill in the page table entries between @start and @last. -* Returns 0 for success, -EINVAL for failure. -*/ -static int amdgpu_vm_bo_update_mapping (struct amdgpu_device *adev, -struct fence *exclusive, -uint64_t src, -dma_addr_t *pages_addr, -struct amdgpu_vm *vm, -uint64_t start,uint64_t last, -uint32_t flags,uint64_t addr, -struct fence **fence) +static int amdgpu_vm_bo_update_mapping_or_shadow (struct amdgpu_device *adev, +struct fence *exclusive, +uint64_t src, +dma_addr_t *pages_addr, +struct amdgpu_vm *vm, +uint64_t start,uint64_t last, +uint32_t flags,uint64_t addr, +struct fence **fence, +bool shadow) {struct amdgpu_ring *ring;void *owner =AMDGPU_FENCE_OWNER_VM ;
@@ -1018,29 +1005,30 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, vm_update_params.ib = &job->ibs[0 ]; - r =amdgpu_sync_fence (adev, &job->sync, exclusive); -if (r) - goto error_free; - - r =amdgpu_sync_resv (adev, &job->sync, vm->page_directory->tbo.resv, - owner); -if (r) - goto error_free; +if (!shadow) { + r =amdgpu_sync_fence (adev, &job->sync, exclusive); +if (r) + goto error_free; + r =amdgpu_sync_resv (adev, &job->sync, vm->page_directory->tbo.resv, + owner); +if (r) + goto error_free; + } r =reservation_object_reserve_shared (vm->page_directory->tbo.resv);if (r) goto error_free;amdgpu_vm_update_ptes (adev, &vm_update_params, vm, start, - last +1 , addr, flags); + last +1 , addr, flags, shadow);amdgpu_ring_pad_ib (ring, vm_update_params.ib);WARN_ON (vm_update_params.ib->length_dw > ndw); - r =amdgpu_job_submit (job, ring, &vm->entity, + r =amdgpu_job_submit (job, ring, + shadow ? &vm->shadow_entity : &vm->entity,AMDGPU_FENCE_OWNER_VM , &f);if (r) goto error_free; -amdgpu_bo_fence (vm->page_directory, f, true);if (fence) {fence_put (*fence);
@@ -1055,6 +1043,48 @@ error_free: }/** +* amdgpu_vm_bo_update_mapping - update a mapping in the vm page table +* +* @adev: amdgpu_device pointer +* @exclusive: fence we need to sync to +* @src: address where to copy page table entries from +* @pages_addr: DMA addresses to use for mapping +* @vm: requested vm +* @start: start of mapped range +* @last: last mapped entry +* @flags: flags for the entries +* @addr: addr to set the area to +* @fence: optional resulting fence +* +* Fill in the page table entries between @start and @last. +* Returns 0 for success, -EINVAL for failure. +*/ +static int amdgpu_vm_bo_update_mapping (struct amdgpu_device *adev, +struct fence *exclusive, +uint64_t src, +dma_addr_t *pages_addr, +struct amdgpu_vm *vm, +uint64_t start,uint64_t last, +uint32_t flags,uint64_t addr, +struct fence **fence) +{ +int r; + + r =amdgpu_vm_bo_update_mapping_or_shadow (adev, exclusive, src, + pages_addr, vm, + start, last, + flags, addr, +NULL , true); +if (r) +return r; +return amdgpu_vm_bo_update_mapping_or_shadow (adev, exclusive, src, + pages_addr, vm, + start, last, + flags, addr, + fence, false); +} + +/** * amdgpu_vm_bo_split_mapping - split a mapping into smaller chunks * * @adev: amdgpu_device pointer
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 10/18 drm/amd: add last fence in sched entity
In reply to a message not in the archive--- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 9 +++++++-- drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +7 -2
@@ -134,6 +134,7 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,INIT_LIST_HEAD (&entity->list); entity->rq = rq; entity->sched = sched; + entity->last_fence =NULL ;spin_lock_init (&entity->queue_lock); r =kfifo_alloc (&entity->job_queue, jobs *sizeof (void *),GFP_KERNEL );
@@ -219,6 +220,7 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,amd_sched_rq_remove_entity (rq, entity);kfifo_free (&entity->job_queue); +fence_put (entity->last_fence); }static void amd_sched_entity_wakeup (struct fence *f,struct fence_cb *cb)
@@ -304,6 +306,7 @@ static bool amd_sched_entity_in(struct amd_sched_job *sched_job) {struct amd_gpu_scheduler *sched = sched_job->sched;struct amd_sched_entity *entity = sched_job->s_entity; +struct amd_sched_fence *s_fence = sched_job->s_fence;bool added, first = false;spin_lock (&entity->queue_lock);
@@ -312,9 +315,11 @@ static bool amd_sched_entity_in(struct amd_sched_job *sched_job)if (added &&kfifo_len (&entity->job_queue) ==sizeof (sched_job)) first = true; - +if (added) { +fence_put (entity->last_fence); + entity->last_fence =fence_get (&s_fence->finished); + }spin_unlock (&entity->queue_lock); -/* first job wakes up scheduler */ if (first) {/* Add the entity to the run queue */
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h +1 -0
@@ -49,6 +49,7 @@ struct amd_sched_entity {atomic_t fence_seq;uint64_t fence_context; +struct fence *last_fence;struct fence *dependency;struct fence_cb cb;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 11/18 drm/amdgpu: link all vm clients
In reply to a message not in the archiveAdd vm client to list tail when creating it, move to head while submit to scheduler.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 +++ 4 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -903,6 +903,9 @@ struct amdgpu_vm {/* BO mappings freed, but not yet updated in the PT */ struct list_head freed; +/* vm itself list */ +struct list_head list; +/* contains the page directory */ struct amdgpu_bo *page_directory;unsigned max_pde_used;
@@ -2177,6 +2180,9 @@ struct amdgpu_device {struct kfd_dev *kfd;struct amdgpu_virtualization virtualization; + +/* link all vm clients */ +struct list_head vm_list; };bool amdgpu_device_is_px (struct drm_device *dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -0
@@ -860,7 +860,10 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,static int amdgpu_cs_submit (struct amdgpu_cs_parser *p,union drm_amdgpu_cs *cs) { +struct amdgpu_fpriv *fpriv = p->filp->driver_priv; +struct amdgpu_vm *vm = &fpriv->vm;struct amdgpu_ring *ring = p->job->ring; +struct amdgpu_device *adev = ring->adev;struct amd_sched_entity *entity = &p->ctx->rings[ring->idx].entity;struct amdgpu_job *job;int r;
@@ -883,6 +886,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,trace_amdgpu_cs_ioctl (job);amd_sched_entity_push_job (&job->base); +list_move (&vm->list, &adev->vm_list);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
@@ -1561,6 +1561,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,spin_lock_init (&adev->gc_cac_idx_lock);spin_lock_init (&adev->audio_endpt_idx_lock); +INIT_LIST_HEAD (&adev->vm_list); + adev->rmmio_base =pci_resource_start (adev->pdev,5 ); adev->rmmio_size =pci_resource_len (adev->pdev,5 ); adev->rmmio =ioremap (adev->rmmio_base, adev->rmmio_size);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -0
@@ -1616,6 +1616,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)INIT_LIST_HEAD (&vm->invalidated);INIT_LIST_HEAD (&vm->cleared);INIT_LIST_HEAD (&vm->freed); +INIT_LIST_HEAD (&vm->list); pd_size =amdgpu_vm_directory_size (adev); pd_entries =amdgpu_vm_num_pdes (adev);
@@ -1664,6 +1665,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) goto error_free_page_directory; vm->last_eviction_counter =atomic64_read (&adev->num_evictions); vm->shadow_sync_fence =NULL ; +list_add_tail (&vm->list, &adev->vm_list);return 0 ;
@@ -1696,6 +1698,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)struct amdgpu_bo_va_mapping *mapping, *tmp;int i; +list_del (&vm->list);amd_sched_entity_fini (vm->shadow_entity.sched, &vm->shadow_entity);amd_sched_entity_fini (vm->entity.sched, &vm->entity);
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 12/18 drm/amdgpu: add vm_list_lock
In reply to a message not in the archiveTo lock adev->vm_list.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++++ 4 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -2183,6 +2183,7 @@ struct amdgpu_device {/* link all vm clients */ struct list_head vm_list; +spinlock_t vm_list_lock; };bool amdgpu_device_is_px (struct drm_device *dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -0
@@ -886,7 +886,9 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,trace_amdgpu_cs_ioctl (job);amd_sched_entity_push_job (&job->base); +spin_lock (&adev->vm_list_lock);list_move (&vm->list, &adev->vm_list); +spin_unlock (&adev->vm_list_lock);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -1562,6 +1562,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,spin_lock_init (&adev->audio_endpt_idx_lock);INIT_LIST_HEAD (&adev->vm_list); +spin_lock_init (&adev->vm_list_lock); adev->rmmio_base =pci_resource_start (adev->pdev,5 ); adev->rmmio_size =pci_resource_len (adev->pdev,5 );
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -1665,7 +1665,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) goto error_free_page_directory; vm->last_eviction_counter =atomic64_read (&adev->num_evictions); vm->shadow_sync_fence =NULL ; +spin_lock (&adev->vm_list_lock);list_add_tail (&vm->list, &adev->vm_list); +spin_unlock (&adev->vm_list_lock);return 0 ;
@@ -1698,7 +1700,9 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)struct amdgpu_bo_va_mapping *mapping, *tmp;int i; +spin_lock (&adev->vm_list_lock);list_del (&vm->list); +spin_unlock (&adev->vm_list_lock);amd_sched_entity_fini (vm->shadow_entity.sched, &vm->shadow_entity);amd_sched_entity_fini (vm->entity.sched, &vm->entity);
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 13/18 drm/amd: add block entity function
In reply to a message not in the archive--- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 3 +++ 2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +24 -0
@@ -110,6 +110,26 @@ amd_sched_rq_select_entity(struct amd_sched_rq *rq) }/** +* block all entity of this run queue +* +* @rq The run queue to check. +* +*/ +int amd_sched_rq_block_entity (struct amd_sched_rq *rq,bool block) +{ +struct amd_sched_entity *entity; + +spin_lock (&rq->lock); + +list_for_each_entry (entity, &rq->entities, list) + entity->block = block; + +spin_unlock (&rq->lock); + +return 0 ; +} + +/** * Init a context entity used by scheduler when submit to HW ring. * * @sched The pointer to the scheduler
@@ -135,6 +155,7 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->last_fence =NULL ; + entity->block = false;spin_lock_init (&entity->queue_lock); r =kfifo_alloc (&entity->job_queue, jobs *sizeof (void *),GFP_KERNEL );
@@ -187,6 +208,9 @@ static bool amd_sched_entity_is_idle(struct amd_sched_entity *entity)*/ static bool amd_sched_entity_is_ready (struct amd_sched_entity *entity) { +if (entity->block) +return false; +if (kfifo_is_empty (&entity->job_queue))return false;
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h +3 -0
@@ -53,6 +53,8 @@ struct amd_sched_entity {struct fence *dependency;struct fence_cb cb; + +bool block; };/**
@@ -156,4 +158,5 @@ int amd_sched_job_init(struct amd_sched_job *job, void *owner);void amd_sched_hw_job_reset (struct amd_gpu_scheduler *sched);void amd_sched_job_recovery (struct amd_gpu_scheduler *sched); +int amd_sched_rq_block_entity (struct amd_sched_rq *rq,bool block);#endif
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 14/18 drm/amdgpu: add shadow fence owner
In reply to a message not in the archiveNormal cs doesn't need to care shadow jobs.
Conflicts:
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 22 ++++++++++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -379,6 +379,8 @@ struct amdgpu_fence_driver {/* some special values for the owner field */ #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)#define AMDGPU_FENCE_OWNER_VM ((void*)1ul) +/* don't need to care vm shadow fence, except eviction */ +#define AMDGPU_FENCE_OWNER_VM_SHADOW ((void*)2ul)#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)#define AMDGPU_FENCE_FLAG_INT (1 << 1)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +3 -0
@@ -213,6 +213,9 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,if (owner !=AMDGPU_FENCE_OWNER_UNDEFINED && fence_owner == owner)continue ; + +if (fence_owner ==AMDGPU_FENCE_OWNER_VM_SHADOW ) +continue ; } r =amdgpu_sync_fence (adev, sync, f);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +16 -6
@@ -679,9 +679,14 @@ int amdgpu_vm_update_page_directory_or_shadow(struct amdgpu_device *adev,amdgpu_sync_resv (adev, &job->sync, pd->tbo.resv,AMDGPU_FENCE_OWNER_VM );WARN_ON (vm_update_params.ib->length_dw > ndw); - r =amdgpu_job_submit (job, ring, - shadow ? &vm->shadow_entity : &vm->entity, -AMDGPU_FENCE_OWNER_VM , &fence); +if (shadow) + r =amdgpu_job_submit (job, ring, + &vm->shadow_entity, +AMDGPU_FENCE_OWNER_VM_SHADOW , &fence); +else + r =amdgpu_job_submit (job, ring, &vm->entity, +AMDGPU_FENCE_OWNER_VM , &fence); +if (r) goto error_free;
@@ -1024,9 +1029,14 @@ static int amdgpu_vm_bo_update_mapping_or_shadow(struct amdgpu_device *adev,amdgpu_ring_pad_ib (ring, vm_update_params.ib);WARN_ON (vm_update_params.ib->length_dw > ndw); - r =amdgpu_job_submit (job, ring, - shadow ? &vm->shadow_entity : &vm->entity, -AMDGPU_FENCE_OWNER_VM , &f); +if (shadow) + r =amdgpu_job_submit (job, ring, + &vm->shadow_entity, +AMDGPU_FENCE_OWNER_VM_SHADOW , &f); +else + r =amdgpu_job_submit (job, ring, &vm->entity, +AMDGPU_FENCE_OWNER_VM , &f); +if (r) goto error_free;amdgpu_bo_fence (vm->page_directory, f, true);
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 15/18 drm/amd: block entity
In reply to a message not in the archive--- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 7 ++++++- drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +6 -1
@@ -109,6 +109,11 @@ amd_sched_rq_select_entity(struct amd_sched_rq *rq)return NULL ; } +void amd_sched_block_entity (struct amd_sched_entity *entity,bool block) +{ + entity->block = block; +} +/** * block all entity of this run queue *
@@ -122,7 +127,7 @@ int amd_sched_rq_block_entity(struct amd_sched_rq *rq, bool block)spin_lock (&rq->lock);list_for_each_entry (entity, &rq->entities, list) - entity->block = block; +amd_sched_block_entity (entity, block);spin_unlock (&rq->lock);
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h +1 -0
@@ -159,4 +159,5 @@ int amd_sched_job_init(struct amd_sched_job *job,void amd_sched_hw_job_reset (struct amd_gpu_scheduler *sched);void amd_sched_job_recovery (struct amd_gpu_scheduler *sched);int amd_sched_rq_block_entity (struct amd_sched_rq *rq,bool block); +void amd_sched_block_entity (struct amd_sched_entity *entity,bool block);#endif
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1470983947-32579-16-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 15/18] drm/amd: block entity
Quoted 12 lines · Chunming Zhou
Change-Id Iba210e0d007a249a90f955f5ac9c3803cc40def2Signed-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 7 ++++++- drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +0
-0
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c amd_sched_rq_select_entity(struct amd_sched_rq *rq) · line 115
Quoted 7 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4
-0@@ -109,6 +109,11 @@ amd_sched_rq_select_entity(struct amd_sched_rq *rq)return NULL ; } +void amd_sched_block_entity (struct amd_sched_entity *entity,bool block) +{ + entity->block = block; +}
Why is this function necessary, did I miss something?
Quoted 19 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +2
-1+/** * block all entity of this run queue * @@ -122,7 +127,7 @@ int amd_sched_rq_block_entity(struct amd_sched_rq *rq, bool block)spin_lock (&rq->lock);list_for_each_entry (entity, &rq->entities, list) - entity->block = block; +amd_sched_block_entity (entity, block);spin_unlock (&rq->lock);drivers/gpu/drm/amd/scheduler/gpu_scheduler.h +0
-0
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h int amd_sched_job_init(struct amd_sched_job *job, · line 163
Quoted 5 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h +1
-0@@ -159,4 +159,5 @@ int amd_sched_job_init(struct amd_sched_job *job,void amd_sched_hw_job_reset (struct amd_gpu_scheduler *sched);void amd_sched_job_recovery (struct amd_gpu_scheduler *sched);int amd_sched_rq_block_entity (struct amd_sched_rq *rq,bool block); +void amd_sched_block_entity (struct amd_sched_entity *entity,bool block);#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): f8dfeb55-132f-1ddf-2e2f-02776aa5d3e0-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org
Re: [PATCH 15/18] drm/amd: block entity
Quoted 17 lines · Edward O'Callaghan
Quoted 15 lines · Chunming Zhou
Change-Id Iba210e0d007a249a90f955f5ac9c3803cc40def2Signed-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 7 ++++++- drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +0
-0@@ -109,6 +109,11 @@ amd_sched_rq_select_entity(struct amd_sched_rq *rq)return NULL ; }
Quoted 5 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c amd_sched_rq_select_entity(struct amd_sched_rq *rq) · line 115
Quoted 4 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4
-0+void amd_sched_block_entity (struct amd_sched_entity *entity,bool block) +{ + entity->block = block; +}Why is this function necessary, did I miss something?
Yes, As Christian mentioned, we will switch to twice updating pt.
Regards,
David Zhou
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +2
-1+/** * block all entity of this run queue * @@ -122,7 +127,7 @@ int amd_sched_rq_block_entity(struct amd_sched_rq *rq, bool block)spin_lock (&rq->lock);list_for_each_entry (entity, &rq->entities, list) - entity->block = block; +amd_sched_block_entity (entity, block);spin_unlock (&rq->lock);
Quoted 11 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h int amd_sched_job_init(struct amd_sched_job *job, · line 163
Quoted 11 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h +1
-0@@ -159,4 +159,5 @@ int amd_sched_job_init(struct amd_sched_job *job,void amd_sched_hw_job_reset (struct amd_gpu_scheduler *sched);void amd_sched_job_recovery (struct amd_gpu_scheduler *sched);int amd_sched_rq_block_entity (struct amd_sched_rq *rq,bool block); +void amd_sched_block_entity (struct amd_sched_entity *entity,bool block);#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 16/18 drm/amdgpu: recover page tables after gpu reset
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 77 +++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +76 -1
@@ -2162,18 +2162,93 @@ retry:amdgpu_atombios_scratch_regs_restore (adev); }if (!r) { +struct amdgpu_ring *buffer_ring = adev->mman.buffer_funcs_ring; +amdgpu_irq_gpu_reset_resume_helper (adev); r =amdgpu_ib_ring_tests (adev);if (r) {dev_err (adev->dev,"ib ring test failed (%d).\n" , r); r =amdgpu_suspend (adev); + need_full_reset = true; goto retry; } - +/** +* recovery vm page tables, since we cannot depend on VRAM is no problem +* after gpu full reset. +*/ +if (need_full_reset && !(adev->flags &AMD_IS_APU )) { +struct amdgpu_vm *vm, *tmp; +struct amdgpu_ring *ring; +struct fence *fence =NULL ; +int i; + +DRM_INFO ("recover page table from shadow\n" ); +for (i =0 ; i < adev->vm_manager.vm_pte_num_rings; i++) { + ring = adev->vm_manager.vm_pte_rings[i]; +amd_sched_rq_block_entity ( + &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL ], true); +amd_sched_rq_block_entity ( + &ring->sched.sched_rq[AMD_SCHED_PRIORITY_KERNEL ], true); + } +spin_lock (&adev->vm_list_lock); +list_for_each_entry_safe (vm, tmp, &adev->vm_list, list) { +spin_unlock (&adev->vm_list_lock); +amd_sched_block_entity (&vm->shadow_entity, false); +spin_lock (&adev->vm_list_lock); + } +spin_unlock (&adev->vm_list_lock); +for (i =0 ; i < adev->vm_manager.vm_pte_num_rings; i++) { + ring = adev->vm_manager.vm_pte_rings[i]; +kthread_unpark (ring->sched.thread); + } +spin_lock (&adev->vm_list_lock); +list_for_each_entry_safe (vm, tmp, &adev->vm_list, list) { +spin_unlock (&adev->vm_list_lock); +/* wait for all shadow jobs finished */ +if (vm->shadow_entity.last_fence) +fence_wait (vm->shadow_entity.last_fence, false); +spin_lock (&adev->vm_list_lock); + } +spin_unlock (&adev->vm_list_lock); +for (i =0 ; i < adev->vm_manager.vm_pte_num_rings; i++) { + ring = adev->vm_manager.vm_pte_rings[i]; +kthread_park (ring->sched.thread); +amd_sched_rq_block_entity ( + &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL ], true); +amd_sched_rq_block_entity ( + &ring->sched.sched_rq[AMD_SCHED_PRIORITY_KERNEL ], true); + } +amd_sched_block_entity (&adev->mman.entity, false); +kthread_unpark (buffer_ring->sched.thread); +spin_lock (&adev->vm_list_lock); +list_for_each_entry_safe (vm, tmp, &adev->vm_list, list) { +spin_unlock (&adev->vm_list_lock); +amdgpu_vm_recover_page_table_from_shadow (adev, vm); +if (vm->shadow_sync_fence) { +fence_put (fence); + fence =fence_get (vm->shadow_sync_fence); + } +spin_lock (&adev->vm_list_lock); + } +spin_unlock (&adev->vm_list_lock); +if (fence) +fence_wait (fence, false); +fence_put (fence); +for (i =0 ; i < adev->vm_manager.vm_pte_num_rings; i++) { + ring = adev->vm_manager.vm_pte_rings[i]; +kthread_park (ring->sched.thread); +amd_sched_rq_block_entity ( + &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL ], false); +amd_sched_rq_block_entity ( + &ring->sched.sched_rq[AMD_SCHED_PRIORITY_KERNEL ], false); + } + }for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i];if (!ring)continue ; + +DRM_INFO ("ring:%d recover jobs\n" , ring->idx);amd_sched_job_recovery (&ring->sched);kthread_unpark (ring->sched.thread); }
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 17/18 drm/amdgpu: add need backup function
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++++++++ 2 files changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -2458,6 +2458,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)/* Common functions */ int amdgpu_gpu_reset (struct amdgpu_device *adev); +bool amdgpu_need_backup (struct amdgpu_device *adev);void amdgpu_pci_config_reset (struct amdgpu_device *adev);bool amdgpu_card_posted (struct amdgpu_device *adev);void amdgpu_update_display_priority (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
@@ -2085,6 +2085,14 @@ static int amdgpu_post_soft_reset(struct amdgpu_device *adev)return 0 ; } +bool amdgpu_need_backup (struct amdgpu_device *adev) +{ +if (adev->flags &AMD_IS_APU ) +return false; + +return amdgpu_lockup_timeout >0 ? true : false; +} +/** * amdgpu_gpu_reset - reset the asic *
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 18/18 drm/amdgpu: add backup condition for vm
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18 -12
@@ -725,9 +725,11 @@ int amdgpu_vm_update_page_directory(struct amdgpu_device *adev, {int r; - r =amdgpu_vm_update_page_directory_or_shadow (adev, vm, true); -if (r) -return r; +if (amdgpu_need_backup (adev)) { + r =amdgpu_vm_update_page_directory_or_shadow (adev, vm, true); +if (r) +return r; + }return amdgpu_vm_update_page_directory_or_shadow (adev, vm, false); }
@@ -1080,13 +1082,15 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, {int r; - r =amdgpu_vm_bo_update_mapping_or_shadow (adev, exclusive, src, - pages_addr, vm, - start, last, - flags, addr, -NULL , true); -if (r) -return r; +if (amdgpu_need_backup (adev)) { + r =amdgpu_vm_bo_update_mapping_or_shadow (adev, exclusive, src, + pages_addr, vm, + start, last, + flags, addr, +NULL , true); +if (r) +return r; + } return amdgpu_vm_bo_update_mapping_or_shadow(adev, exclusive, src, pages_addr, vm, start, last,
@@ -1452,7 +1456,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,AMDGPU_GPU_PAGE_SIZE , true,AMDGPU_GEM_DOMAIN_VRAM ,AMDGPU_GEM_CREATE_NO_CPU_ACCESS | -AMDGPU_GEM_CREATE_SHADOW , + (amdgpu_need_backup (adev) ? +AMDGPU_GEM_CREATE_SHADOW :0 ), NULL, resv, &pt);if (r) goto error_free;
@@ -1660,7 +1665,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm) r =amdgpu_bo_create (adev, pd_size, align, true,AMDGPU_GEM_DOMAIN_VRAM ,AMDGPU_GEM_CREATE_NO_CPU_ACCESS | -AMDGPU_GEM_CREATE_SHADOW , + (amdgpu_need_backup (adev) ? +AMDGPU_GEM_CREATE_SHADOW :0 ),NULL ,NULL , &vm->page_directory);if (r) goto error_free_sched_entity;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Patch #1-#4 are Reviewed-by: Christian König <[email protected]>, please commit those so that we can consider them as done.
Patch #5:
Review
Quoted 6 lines
(quoted diff) +5
-0+int amdgpu_bo_sync_between_bo_and_shadow(struct amdgpu_device *adev, + struct amdgpu_ring *ring, + struct amdgpu_bo *bo, + struct reservation_object *resv, + struct fence **fence)
Maybe rename this to amdgpu_bo_backup_shadow(), when talking about sync at least I always think about synchronization using fences.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (bo->backup_shadow & AMDGPU_BO_SHADOW_TO_NONE) {
That condition will never be true, cause AMDGPU_BO_SHADOW_TO_NONE is defined as 0. You probably wanted to use "==" here, don't you?
Review
Quoted 10 lines
(quoted diff) +10
-0+ r = amdgpu_bo_pin(bo, bo->prefered_domains, &bo_addr); + if (r) { + DRM_ERROR("Failed to pin bo object\n"); + goto err1; + } + r = amdgpu_bo_pin(bo->shadow, bo->shadow->prefered_domains, &shadow_addr); + if (r) { + DRM_ERROR("Failed to pin bo shadow object\n"); + goto err2; + }
Again don't use amdgpu_bo_pin() here.
Patch #6:
Review
Quoted 3 lines
(quoted diff) +3
-0+ r = amdgpu_bo_reserve(vm->page_directory, false); + if (r) + return r;
You need to double check if the BOs aren't swapped out. See amdgpu_gem_va_update_vm() on how to do this.
Review
Quoted 2 lines
(quoted diff) +2
-0+ fence_put(vm->shadow_sync_fence); + vm->shadow_sync_fence = fence_get(fence);
I wouldn't remember the backup operation at all, just return the fence to the caller instead.
Review
Quoted 2 lines
(quoted diff) +2
-0+ r = amdgpu_bo_sync_between_bo_and_shadow(adev, ring, bo, + NULL, &fence);
As discussed we don't want to use the scheduler for the recovery operation, so we need a flag to send the commands directly to the ring here.
Patch #7 and following. Thinking about this more the whole idea of using a separate entity is a NAK.
The basic problem is that you can't know which updates are completed, crashed or in flight when the the GPU recovery hits us. So the shadow needs to be updated before the real page table and none of this can be done out of order.
I suggest you just switch back to doing the updates twice for now.
Regards,
Christian.
Am 12.08.2016 um 08:38 schrieb Chunming Zhou:
Quoted 37 lines
Since we cannot ensure VRAM is consistent after a GPU reset, page table shadowing is necessary. Shadowed page tables are, in a sense, a method to recover the consistent state of the page tables before the reset occurred.
We need to allocate GTT bo as the shadow of VRAM bo when creating page table, and make them the same. After gpu reset, we will need to use SDMA to copy GTT bo content to VRAM bo, then page table will be recoveried.
V2:
Shadow bo uses a shadow entity running on normal run queue, after gpu reset, we need to wait for all shadow jobs finished first, then recovery page table from shadow.V3:
Addressed Christian comments for shadow bo part.Chunming Zhou (18):
drm/amdgpu: add shadow bo support V2
drm/amdgpu: validate shadow as well when validating bo drm/amdgpu: allocate shadow for pd/pt bo V2 drm/amdgpu: add shadow flag V2
drm/amdgpu: sync bo and shadow
drm/amdgpu: implement vm recovery function from shadow drm/amdgpu: addshadow_entityfor shadow page table updates drm/amdgpu: update pd shadow bo
drm/amdgpu: update pt shadow
drm/amd: add last fence in sched entity drm/amdgpu: link all vm clients
drm/amdgpu: addvm_list_lock
drm/amd: add block entity function
drm/amdgpu: add shadow fence owner
drm/amd: block entity
drm/amdgpu: recover page tables after gpu reset drm/amdgpu: add need backup function
drm/amdgpu: add backup condition for vm
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 25 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 82 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 88 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 100 ++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 + drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 281 +++++++++++++++++++------- drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 38 +++- drivers/gpu/drm/amd/scheduler/gpu_scheduler.h | 5 + include/uapi/drm/amdgpu_drm.h | 2 + 10 files changed, 524 insertions(+), 105 deletions(-)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx