*** Dedicated vmid per process v3 ***
Subsystems (3)
v3 cover *** Dedicated vmid per process v3 ***
*** BLURB HERE ***
The current kernel implementation, which grabs the idle VMID from pool when emitting the job may:
The back-to-back submission from one process could use different VMID. The submission to different queues from single process could use different VMID
It works well in most case but cannot work for the SQ thread trace capture.
The VMID for the submission that set the {SQTT}_BASE, which refers to the address of the trace buffer, is stored in shader engine.
If the profiling application have to use different VMIDs to submit IBs in its life cycle:
Some trace is not captured since it actually uses different VMID to submit jobs.
Some part of captured trace may come from different application since they are accidentally uses the owner’s VMID to submit jobs.
V2:
1. address Christian's comments:
a. drop context flags for tag process, instead, add vm ioctl. b. change order of patches.
c. sync waiting only when vm flush needs.
2. address Alex's comments;
bump module version
V3:
address Jerry and Christian's comments.
and only reserve gfxhub vmid
Chunming Zhou (6):
drm/amdgpu: add vm ioctl
drm/amdgpu: add dedicated vmid field in vm struct drm/amdgpu: reserve/unreserve vmid by vm ioctl v3 drm/amdgpu: add limitation for dedicated vm number v3 drm/amdgpu: implement grab dedicated vmid V2 drm/amdgpu: bump module verion for reserved vmid
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 148 +++++++++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 6 ++ include/uapi/drm/amdgpu_drm.h | 22 +++++ 5 files changed, 178 insertions(+), 2 deletions(-)
Signature · 1 line
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): 1493205039-3721-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
PATCH v3 1/6 drm/amdgpu: add vm ioctl
It will be used for reserving vmid.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 + include/uapi/drm/amdgpu_drm.h | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -0
@@ -1062,6 +1062,7 @@ int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_GEM_CREATE , amdgpu_gem_create_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_CTX , amdgpu_ctx_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (AMDGPU_VM , amdgpu_vm_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_BO_LIST , amdgpu_bo_list_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),/* KMS */ DRM_IOCTL_DEF_DRV (AMDGPU_GEM_MMAP , amdgpu_gem_mmap_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18 -0
@@ -2379,3 +2379,21 @@ void amdgpu_vm_manager_fini(struct amdgpu_device *adev) } } } + +int amdgpu_vm_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) +{ +union drm_amdgpu_vm *args = data; +struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv; + +switch (args->in.op) { +case AMDGPU_VM_OP_RESERVE_VMID : +case AMDGPU_VM_OP_UNRESERVE_VMID : +return -EINVAL ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
@@ -248,5 +248,6 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,void amdgpu_vm_bo_rmv (struct amdgpu_device *adev,struct amdgpu_bo_va *bo_va);void amdgpu_vm_adjust_size (struct amdgpu_device *adev,uint64_t vm_size); +int amdgpu_vm_ioctl (struct drm_device *dev,void *data,struct drm_file *filp);#endif
include/uapi/drm/amdgpu_drm.h +22 -0
@@ -51,6 +51,7 @@#define DRM_AMDGPU_GEM_OP 0x10#define DRM_AMDGPU_GEM_USERPTR 0x11#define DRM_AMDGPU_WAIT_FENCES 0x12 +#define DRM_AMDGPU_VM 0x13/* hybrid specific ioctls */ #define DRM_AMDGPU_SEM 0x5b
@@ -71,6 +72,7 @@#define DRM_IOCTL_AMDGPU_GEM_OP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op)#define DRM_IOCTL_AMDGPU_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)#define DRM_IOCTL_AMDGPU_WAIT_FENCES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_FENCES, union drm_amdgpu_wait_fences) +#define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)/* hybrid specific ioctls */ #define DRM_IOCTL_AMDGPU_GEM_DGMA DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_DGMA, struct drm_amdgpu_gem_dgma)
@@ -212,6 +214,26 @@ struct drm_amdgpu_ctx_in {union drm_amdgpu_ctx_out out; }; +/* vm ioctl */ +#define AMDGPU_VM_OP_RESERVE_VMID 1 +#define AMDGPU_VM_OP_UNRESERVE_VMID 2 + +struct drm_amdgpu_vm_in { +/** AMDGPU_VM_OP_* */ +__u32 op; +__u32 flags; +}; + +struct drm_amdgpu_vm_out { +/** For future use, no flags defined so far */ +__u64 flags; +}; + +union drm_amdgpu_vm { +struct drm_amdgpu_vm_in in; +struct drm_amdgpu_vm_out out; +}; +/* sem related */ #define AMDGPU_SEM_OP_CREATE_SEM 1#define AMDGPU_SEM_OP_WAIT_SEM 2
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 2/6 drm/amdgpu: add dedicated vmid field in vm struct
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +16 -1
@@ -2163,10 +2163,12 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,unsigned ring_instance;struct amdgpu_ring *ring;struct amd_sched_rq *rq; -int r; +int r, i; vm->va =RB_ROOT ; vm->client_id =atomic64_inc_return (&adev->vm_manager.client_counter); +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) + vm->dedicated_vmid[i] =NULL ;spin_lock_init (&vm->status_lock);INIT_LIST_HEAD (&vm->invalidated);INIT_LIST_HEAD (&vm->cleared);
@@ -2270,6 +2272,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) {struct amdgpu_bo_va_mapping *mapping, *tmp;bool prt_fini_needed = !!adev->gart.gart_funcs->set_prt; +int i;if (vm->is_kfd_vm) { struct amdgpu_vm_id_manager *id_mgr =
@@ -2313,6 +2316,18 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_vm_free_levels (&vm->root);fence_put (vm->last_dir_update); +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { +struct amdgpu_vm_id_manager *id_mgr = + &adev->vm_manager.id_mgr[i]; + +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[i]) { +list_add (&vm->dedicated_vmid[i]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[i] =NULL ; + } +mutex_unlock (&id_mgr->lock); + } }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
@@ -123,6 +123,8 @@ struct amdgpu_vm {/* client id */ u64 client_id; +/* dedicated vmid */ +struct amdgpu_vm_id *dedicated_vmid[AMDGPU_MAX_VMHUBS ];/* each VM will map on CSA */ struct amdgpu_bo_va *csa_bo_va;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 3/6 drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
In reply to a message not in the archiveadd reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhub
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +57 -13
@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready (struct amdgpu_vm *vm,unsigned vmhub) +{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID *
@@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,return r; } +static void amdgpu_vm_free_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; + +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr; +struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); +list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle; +mutex_unlock (&id_mgr->lock); + + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err; + +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} +static bool amdgpu_vm_ring_has_compute_vm_bug (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_vm_free_levels (&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/**
@@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)union drm_amdgpu_vm *args = data;struct amdgpu_device *adev = dev->dev_private;struct amdgpu_fpriv *fpriv = filp->driver_priv; +int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */ +if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 ); +if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;
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): 1493205039-3721-4-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 49 lines
add reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhubChange-Id I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039dSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24
-0@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready (struct amdgpu_vm *vm,unsigned vmhub) +{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID * @@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,return r; } +static void amdgpu_vm_free_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; + +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 582
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+struct amdgpu_vm_id_manager *id_mgr; +struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); +list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle;
We need a check here if there isn't an ID already reserved for the VM.
Additional to that I would still rename the field to reserved_vmid, that describes better what it is actually doing.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 587
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+mutex_unlock (&id_mgr->lock); + + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err;
This is racy. A command submission could happen while we wait for the id to become idle.
The easiest way to solve this is to hold the lock while waiting for the ID to become available.
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-12+ +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} +static bool amdgpu_vm_ring_has_compute_vm_bug (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_vm_free_levels (&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 2445
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0@@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)union drm_amdgpu_vm *args = data;struct amdgpu_device *adev = dev->dev_private;struct amdgpu_fpriv *fpriv = filp->driver_priv; +int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */ +if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 );
This is racy as well.
Two threads could try to reserve a VMID at the same time. You need to integrate the check if it's already allocated into amdgpu_vm_alloc_dedicated_vmid().
Regards,
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 2454
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1+if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;
_______________________________________________
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): bf812c57-d9ee-8a15-1198-acc687145fea-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
Quoted 67 lines · Christian König
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 53 lines
add reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhubChange-Id I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039dSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-0@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm,unsigned vmhub) +{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID * @@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm,struct amdgpu_ring *ring, return r; } +static void amdgpu_vm_free_dedicated_vmid(struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; + +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, · line 584
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-0+struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); +list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle;We need a check here if there isn't an ID already reserved for the VM.
Quoted 1 line
Additional to that I would still rename the field to
reserved_vmid, that describes better what it is actually doing.
the vmid is global, reserve it from global lru, so it makes sense to name 'reserved_vmid' like in patch#4. the reserved vmid is dedicated to one vm, so the field in vm is 'dedicated_vmid' like here, which is my reason to name it.
Anyway, the alternative is ok to me although I prefer mine, I hope we can deliver this solution by today, many RGP issues depend on it.
Thanks,
David Zhou
Quoted 57 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 587
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+mutex_unlock (&id_mgr->lock); + + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err;This is racy. A command submission could happen while we wait for the id to become idle.
The easiest way to solve this is to hold the lock while waiting for the ID to become available.
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} + static bool amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring*ring)
{ struct amdgpu_device *adev = ring->adev;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-12@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_vm_free_levels (&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/** @@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) union drm_amdgpu_vm *args = data;struct amdgpu_device *adev = dev->dev_private;struct amdgpu_fpriv *fpriv = filp->driver_priv; +int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 2445
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 );This is racy as well.
Quoted 17 lines
Two threads could try to reserve a VMID at the same time. You need to integrate the check if it's already allocated into
amdgpu_vm_alloc_dedicated_vmid().Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1+if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;
_______________________________________________
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): [email protected]
Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
Quoted 69 lines · On 04/27/2017 10:13 AM, zhoucm1 wrote:
Quoted 66 lines · Christian König
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 52 lines
add reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhubChange-Id I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039dSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +22
-0@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub) +{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID * @@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, structamdgpu_ring *ring, return r; } +static void amdgpu_vm_free_dedicated_vmid(struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; + +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct · line 582
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+struct amdgpu_vm_id_manager *id_mgr; +struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); +list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle;We need a check here if there isn't an ID already reserved for the VM.
Quoted 6 lines
Quoted 2 lines
Additional to that I would still rename the field to
reserved_vmid, that describes better what it is actually doing.the vmid is global, reserve it from global lru, so it makes sense to name '
reserved_vmid' like in patch#4.
the reserved vmid is dedicated to one vm, so the field in vm is 'dedicated_vmid' like here, which is my reason to name it.
Just the same thing looking at different views.
IMHO, it's reserved vmid from global group, naming "reserved_vmid".
And in Patch#4, it constrains the number, possibly naming "reserved_vmid_seq" or "reserved_vmid_ref".
Any of them looks reasonable, select the one you like. :)
Jerry
Quoted 83 lines
Anyway, the alternative is ok to me although I prefer mine, I hope we can deliver this solution by today, many RGP issues depend on it.
Thanks,
David ZhouQuoted 57 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 587
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+mutex_unlock (&id_mgr->lock); + + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err;This is racy. A command submission could happen while we wait for the id to become idle.
The easiest way to solve this is to hold the lock while waiting for the ID to become available.
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-12+ +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} +static bool amdgpu_vm_ring_has_compute_vm_bug (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) amdgpu_vm_free_levels(&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/** drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void · line 2445
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0@@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)union drm_amdgpu_vm *args = data;struct amdgpu_device *adev = dev->dev_private;struct amdgpu_fpriv *fpriv = filp->driver_priv; +int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */ +if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 );This is racy as well.
Quoted 19 lines
Two threads could try to reserve a VMID at the same time. You need to integrate the check if it's already allocated into
amdgpu_vm_alloc_dedicated_vmid().Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1+if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): [email protected]
Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
Quoted 82 lines · Jerry (Junwei)
Quoted 74 lines · On 04/27/2017 10:13 AM, zhoucm1 wrote:
Quoted 71 lines · Christian König
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 65 lines
add reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhubChange-Id I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039dSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm,unsigned
vmhub)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID * @@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm,struct
amdgpu_ring*ring,return r;}
+static void amdgpu_vm_free_dedicated_vmid(structamdgpu_device
*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+ struct amdgpu_vm *vm, + unsigned vmhub) +{ + struct amdgpu_vm_id_manager *id_mgr =&adev->vm_manager.id_mgr[vmhub];
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +22
-0+ +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr; +struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id,list);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle;We need a check here if there isn't an ID already reserved for the VM.
Quoted 6 lines
Quoted 2 lines
Additional to that I would still rename the field to
reserved_vmid, that describes better what it is actually doing.the vmid is global, reserve it from global lru, so it makes sense to name '
reserved_vmid' like in patch#4.
the reserved vmid is dedicated to one vm, so the field in vm is 'dedicated_vmid' like here, which is my reason to name it.
Quoted 4 lines
Just the same thing looking at different views.
IMHO, it's reserved vmid from global group, naming "
reserved_vmid".
And in Patch#4, it constrains the number, possibly naming "reserved_vmid_seq" or "reserved_vmid_ref".
How about reserved_vmid_num?
Regards,
David Zhou
Quoted 91 lines
Any of them looks reasonable, select the one you like. :)
Jerry
Quoted 86 lines
Anyway, the alternative is ok to me although I prefer mine, I hope we can deliver this solution by today, many RGP issues depend on it.
Thanks,
David ZhouQuoted 79 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Quoted 6 lines
+
mutex_unlock(&id_mgr->lock);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+ + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err;This is racy. A command submission could happen while we wait for the id to become idle.
The easiest way to solve this is to hold the lock while waiting for the ID to become available.
Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} + static bool amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring*ring)
{ struct amdgpu_device *adev = ring->adev;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-12@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) amdgpu_vm_free_levels(&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/** @@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev,void
*data, structdrm_file*filp)union drm_amdgpu_vm *args = data; struct amdgpu_device *adev = dev->dev_private; struct amdgpu_fpriv *fpriv = filp->driver_priv;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 );This is racy as well.
Two threads could try to reserve a VMID at the same time. You need to integrate the check if it's already allocated into
amdgpu_vm_alloc_dedicated_vmid().Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1+if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;
Quoted 8 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
In reply to a message not in the archiveAm 27.04.2017 um 04:24 schrieb Zhang, Jerry (Junwei):
Quoted 82 lines · On 04/27/2017 10:13 AM, zhoucm1 wrote:
Quoted 74 lines · Christian König
Quoted 71 lines
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 65 lines
add reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhubChange-Id I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039dSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm,unsigned
vmhub)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID * @@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm,struct
amdgpu_ring*ring,return r;}
+static void amdgpu_vm_free_dedicated_vmid(structamdgpu_device
*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+ struct amdgpu_vm *vm, + unsigned vmhub) +{ + struct amdgpu_vm_id_manager *id_mgr =&adev->vm_manager.id_mgr[vmhub];
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +22
-0+ +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr; +struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id,list);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle;We need a check here if there isn't an ID already reserved for the VM.
Quoted 6 lines
Quoted 2 lines
Additional to that I would still rename the field to
reserved_vmid, that describes better what it is actually doing.the vmid is global, reserve it from global lru, so it makes sense to name '
reserved_vmid' like in patch#4.
the reserved vmid is dedicated to one vm, so the field in vm is 'dedicated_vmid' like here, which is my reason to name it.
Quoted 6 lines
Just the same thing looking at different views.
IMHO, it's reserved vmid from global group, naming "
reserved_vmid".
And in Patch#4, it constrains the number, possibly naming "reserved_vmid_seq" or "reserved_vmid_ref".Any of them looks reasonable, select the one you like. :)
Yeah, agree. More like a gut feeling that reserved is more common wording, but I don't have a strong opinion on that either.
Christian.
Quoted 93 lines
Jerry
Quoted 90 lines
Anyway, the alternative is ok to me although I prefer mine, I hope we can deliver this solution by today, many RGP issues depend on it.
Thanks,
David ZhouQuoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Quoted 6 lines
+
mutex_unlock(&id_mgr->lock);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+ + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err;This is racy. A command submission could happen while we wait for the id to become idle.
The easiest way to solve this is to hold the lock while waiting for the ID to become available.
Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} + static bool amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring*ring)
{ struct amdgpu_device *adev = ring->adev;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-12@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) amdgpu_vm_free_levels(&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/** @@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev,void
*data, structdrm_file*filp)union drm_amdgpu_vm *args = data; struct amdgpu_device *adev = dev->dev_private; struct amdgpu_fpriv *fpriv = filp->driver_priv;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 );This is racy as well.
Quoted 19 lines
Two threads could try to reserve a VMID at the same time. You need to integrate the check if it's already allocated into
amdgpu_vm_alloc_dedicated_vmid().Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1+if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
In reply to a message not in the archiveQuoted 124 lines · Christian König
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 51 lines
add reserve/unreserve vmid funtions.
v3:
only reserve vmid from gfxhubChange-Id I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039dSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0@@ -397,6 +397,11 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,atomic_read (&adev->gpu_reset_counter); } +static bool amdgpu_vm_dedicated_vmid_ready (struct amdgpu_vm *vm,unsigned vmhub) +{ +return !!vm->dedicated_vmid[vmhub]; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID *drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +19
-0@@ -546,6 +551,47 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, structamdgpu_ring *ring, return r; } +static void amdgpu_vm_free_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{ +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; + +mutex_lock (&id_mgr->lock); +if (vm->dedicated_vmid[vmhub]) { +list_add (&vm->dedicated_vmid[vmhub]->list, + &id_mgr->ids_lru); + vm->dedicated_vmid[vmhub] =NULL ; + } +mutex_unlock (&id_mgr->lock); +} + +static int amdgpu_vm_alloc_dedicated_vmid (struct amdgpu_device *adev, +struct amdgpu_vm *vm, +unsigned vmhub) +{drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct · line 582
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+struct amdgpu_vm_id_manager *id_mgr; +struct amdgpu_vm_id *idle; +int r; + + id_mgr = &adev->vm_manager.id_mgr[vmhub]; +mutex_lock (&id_mgr->lock); +/* Select the first entry VMID */ + idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list); +list_del_init (&idle->list); + vm->dedicated_vmid[vmhub] = idle;We need a check here if there isn't an ID already reserved for the VM.
Additional to that I would still rename the field to
reserved_vmid, that describes better what it is actually doing.drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 587
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+mutex_unlock (&id_mgr->lock); + + r =amdgpu_sync_wait (&idle->active); +if (r) + goto err;This is racy. A command submission could happen while we wait for the id to become idle.
The easiest way to solve this is to hold the lock while waiting for the ID to become available.
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-12+ +return 0 ; +err: +amdgpu_vm_free_dedicated_vmid (adev, vm, vmhub); +return r; +} +static bool amdgpu_vm_ring_has_compute_vm_bug (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;@@ -2316,18 +2362,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) amdgpu_vm_free_levels(&vm->root);fence_put (vm->last_dir_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { -struct amdgpu_vm_id_manager *id_mgr = - &adev->vm_manager.id_mgr[i]; - -mutex_lock (&id_mgr->lock); -if (vm->dedicated_vmid[i]) { -list_add (&vm->dedicated_vmid[i]->list, - &id_mgr->ids_lru); - vm->dedicated_vmid[i] =NULL ; - } -mutex_unlock (&id_mgr->lock); - } +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) +amdgpu_vm_free_dedicated_vmid (adev, vm, i); }/** drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void · line 2445
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0@@ -2400,11 +2436,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)union drm_amdgpu_vm *args = data;struct amdgpu_device *adev = dev->dev_private;struct amdgpu_fpriv *fpriv = filp->driver_priv; +int r;switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : +/* current, we only have requirement to reserve vmid from gfxhub */ +if (!amdgpu_vm_dedicated_vmid_ready (&fpriv->vm,0 )) { + r =amdgpu_vm_alloc_dedicated_vmid (adev, &fpriv->vm,0 );This is racy as well.
Quoted 2 lines
Two threads could try to reserve a VMID at the same time. You need to integrate the check if it's already allocated into
amdgpu_vm_alloc_dedicated_vmid().
Apart from that, small tip.AMDGPU_GFXHUB instead of "0" looks more self-explanatory.
Jerry
Quoted 16 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 2454
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1+if (r) +return r; + } +break ;case AMDGPU_VM_OP_UNRESERVE_VMID : -return -EINVAL ; +amdgpu_vm_free_dedicated_vmid (adev, &fpriv->vm,0 );break ;default :return -EINVAL ;
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 4/6 drm/amdgpu: add limitation for dedicated vm number v3
In reply to a message not in the archivev2: move #define to amdgpu_vm.h
v3: move reserved vmid counter to id_manager,
and increase counter before allocating vmid
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 +++ 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -0
@@ -562,6 +562,7 @@ static void amdgpu_vm_free_dedicated_vmid(struct amdgpu_device *adev,list_add (&vm->dedicated_vmid[vmhub]->list, &id_mgr->ids_lru); vm->dedicated_vmid[vmhub] =NULL ; +atomic_dec (&id_mgr->reserved_vmid); }mutex_unlock (&id_mgr->lock); }
@@ -575,6 +576,12 @@ static int amdgpu_vm_alloc_dedicated_vmid(struct amdgpu_device *adev,int r; id_mgr = &adev->vm_manager.id_mgr[vmhub]; +if (atomic_inc_return (&id_mgr->reserved_vmid) > +AMDGPU_VM_MAX_RESERVED_VMID ) { +DRM_ERROR ("Over limitation of reserved vmid\n" ); +atomic_dec (&id_mgr->reserved_vmid); +return -EINVAL ; + }mutex_lock (&id_mgr->lock);/* Select the first entry VMID */ idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id, list);
@@ -2383,6 +2390,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)mutex_init (&id_mgr->lock);INIT_LIST_HEAD (&id_mgr->ids_lru); +atomic_set (&id_mgr->reserved_vmid,0 );/* skip over VMID 0, since it is the system VM */ for (j =1 ; j < id_mgr->num_ids; ++j) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -0
@@ -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_VMID 1struct amdgpu_vm_pt {struct amdgpu_bo *bo;
@@ -157,6 +159,7 @@ struct amdgpu_vm_id_manager {unsigned num_ids;struct list_head ids_lru;struct amdgpu_vm_id ids[AMDGPU_NUM_VM ]; +atomic_t reserved_vmid; };struct amdgpu_vm_manager {
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 5/6 drm/amdgpu: implement grab dedicated vmid V2
In reply to a message not in the archivev2: move sync waiting only when flush needs
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +61 -0
@@ -402,6 +402,63 @@ static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub)return !!vm->dedicated_vmid[vmhub]; } +static int amdgpu_vm_grab_dedicated_vmid (struct amdgpu_vm *vm, +struct amdgpu_ring *ring, +struct amdgpu_sync *sync, +struct fence *fence, +struct amdgpu_job *job) +{ +struct amdgpu_device *adev = ring->adev; +unsigned vmhub = ring->funcs->vmhub; +struct amdgpu_vm_id *id = vm->dedicated_vmid[vmhub]; +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; +struct fence *updates = sync->last_vm_update; +int r =0 ; +struct fence *flushed, *tmp; +bool needs_flush = false; + +mutex_lock (&id_mgr->lock); +if (amdgpu_vm_had_gpu_reset (adev, id)) + needs_flush = true; + + flushed = id->flushed_updates; +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) + needs_flush = true; +if (needs_flush) { + tmp =amdgpu_sync_get_fence (&id->active); +if (tmp) { + r =amdgpu_sync_fence (adev, sync, tmp); +fence_put (tmp); +mutex_unlock (&id_mgr->lock); +return r; + } + } + +/* Good we can use this VMID. Remember this submission as +* user of the VMID. +*/ + r =amdgpu_sync_fence (ring->adev, &id->active, fence); +if (r) + goto out; + +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) { +fence_put (id->flushed_updates); + id->flushed_updates =fence_get (updates); + } + id->pd_gpu_addr = job->vm_pd_addr; + id->current_gpu_reset_count =atomic_read (&adev->gpu_reset_counter); +atomic64_set (&id->owner, vm->client_id); + job->vm_needs_flush = needs_flush; + + job->vm_id = id - id_mgr->ids; +trace_amdgpu_vm_grab_id (vm, ring, job); +out: +mutex_unlock (&id_mgr->lock); +return r; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID *
@@ -426,6 +483,10 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,unsigned i;int r =0 ; +if (amdgpu_vm_dedicated_vmid_ready (vm, vmhub)) +return amdgpu_vm_grab_dedicated_vmid (vm, ring, sync, + fence, job); + fences =kmalloc_array (sizeof (void *), id_mgr->num_ids,GFP_KERNEL );if (!fences)return -ENOMEM ;
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): 1493205039-3721-6-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 5/6] drm/amdgpu: implement grab dedicated vmid V2
Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
Quoted 77 lines
v2: move sync waiting only when flush needs
Change-Id I64da2701c9fdcf986afb90ba1492a78d5bef1b6cSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +57
-0@@ -402,6 +402,63 @@ static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub)return !!vm->dedicated_vmid[vmhub]; } +static int amdgpu_vm_grab_dedicated_vmid (struct amdgpu_vm *vm, +struct amdgpu_ring *ring, +struct amdgpu_sync *sync, +struct fence *fence, +struct amdgpu_job *job) +{ +struct amdgpu_device *adev = ring->adev; +unsigned vmhub = ring->funcs->vmhub; +struct amdgpu_vm_id *id = vm->dedicated_vmid[vmhub]; +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; +struct fence *updates = sync->last_vm_update; +int r =0 ; +struct fence *flushed, *tmp; +bool needs_flush = false; + +mutex_lock (&id_mgr->lock); +if (amdgpu_vm_had_gpu_reset (adev, id)) + needs_flush = true; + + flushed = id->flushed_updates; +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) + needs_flush = true; +if (needs_flush) { + tmp =amdgpu_sync_get_fence (&id->active); +if (tmp) { + r =amdgpu_sync_fence (adev, sync, tmp); +fence_put (tmp); +mutex_unlock (&id_mgr->lock); +return r; + } + } + +/* Good we can use this VMID. Remember this submission as +* user of the VMID. +*/ + r =amdgpu_sync_fence (ring->adev, &id->active, fence); +if (r) + goto out; + +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) { +fence_put (id->flushed_updates); + id->flushed_updates =fence_get (updates); + } + id->pd_gpu_addr = job->vm_pd_addr; + id->current_gpu_reset_count =atomic_read (&adev->gpu_reset_counter); +atomic64_set (&id->owner, vm->client_id); + job->vm_needs_flush = needs_flush; + + job->vm_id = id - id_mgr->ids; +trace_amdgpu_vm_grab_id (vm, ring, job); +out: +mutex_unlock (&id_mgr->lock); +return r; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID *
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 488
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0@@ -426,6 +483,10 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,unsigned i;int r =0 ; +if (amdgpu_vm_dedicated_vmid_ready (vm, vmhub)) +return amdgpu_vm_grab_dedicated_vmid (vm, ring, sync, + fence, job);
That is racy as well. The reserved VMID could be unreserved while we try to grab it leading to a NULL pointer dereference in amdgpu_vm_grab_dedicated_vmid().
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 492
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ fences =kmalloc_array (sizeof (void *), id_mgr->num_ids,GFP_KERNEL );if (!fences)return -ENOMEM ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 5/6] drm/amdgpu: implement grab dedicated vmid V2
In reply to a message not in the archiveQuoted 29 lines · Chunming Zhou
v2: move sync waiting only when flush needs
Change-Id I64da2701c9fdcf986afb90ba1492a78d5bef1b6cSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13
-0@@ -402,6 +402,63 @@ static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub)return !!vm->dedicated_vmid[vmhub]; } +static int amdgpu_vm_grab_dedicated_vmid (struct amdgpu_vm *vm, +struct amdgpu_ring *ring, +struct amdgpu_sync *sync, +struct fence *fence, +struct amdgpu_job *job) +{ +struct amdgpu_device *adev = ring->adev; +unsigned vmhub = ring->funcs->vmhub; +struct amdgpu_vm_id *id = vm->dedicated_vmid[vmhub]; +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; +struct fence *updates = sync->last_vm_update; +int r =0 ; +struct fence *flushed, *tmp;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub) · line 427
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+bool needs_flush = false; + +mutex_lock (&id_mgr->lock); +if (amdgpu_vm_had_gpu_reset (adev, id)) + needs_flush = true; + + flushed = id->flushed_updates; +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) + needs_flush = true;
Just question:
Do we need to consider concurrent flush for Vega10 like grab id func?
Jerry
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +34
-0+if (needs_flush) { + tmp =amdgpu_sync_get_fence (&id->active); +if (tmp) { + r =amdgpu_sync_fence (adev, sync, tmp); +fence_put (tmp); +mutex_unlock (&id_mgr->lock); +return r; + } + } + +/* Good we can use this VMID. Remember this submission as +* user of the VMID. +*/ + r =amdgpu_sync_fence (ring->adev, &id->active, fence); +if (r) + goto out; + +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) { +fence_put (id->flushed_updates); + id->flushed_updates =fence_get (updates); + } + id->pd_gpu_addr = job->vm_pd_addr; + id->current_gpu_reset_count =atomic_read (&adev->gpu_reset_counter); +atomic64_set (&id->owner, vm->client_id); + job->vm_needs_flush = needs_flush; + + job->vm_id = id - id_mgr->ids; +trace_amdgpu_vm_grab_id (vm, ring, job); +out: +mutex_unlock (&id_mgr->lock); +return r; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID *
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 492
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0@@ -426,6 +483,10 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,unsigned i;int r =0 ; +if (amdgpu_vm_dedicated_vmid_ready (vm, vmhub)) +return amdgpu_vm_grab_dedicated_vmid (vm, ring, sync, + fence, job); + fences =kmalloc_array (sizeof (void *), id_mgr->num_ids,GFP_KERNEL );if (!fences)return -ENOMEM ;
_______________________________________________
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): [email protected]
Re: [PATCH 5/6] drm/amdgpu: implement grab dedicated vmid V2
Quoted 38 lines · Jerry (Junwei)
Quoted 37 lines · Chunming Zhou
v2: move sync waiting only when flush needs
Change-Id I64da2701c9fdcf986afb90ba1492a78d5bef1b6cSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18
-0@@ -402,6 +402,63 @@ static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub)return !!vm->dedicated_vmid[vmhub]; } +static int amdgpu_vm_grab_dedicated_vmid (struct amdgpu_vm *vm, +struct amdgpu_ring *ring, +struct amdgpu_sync *sync, +struct fence *fence, +struct amdgpu_job *job) +{ +struct amdgpu_device *adev = ring->adev; +unsigned vmhub = ring->funcs->vmhub; +struct amdgpu_vm_id *id = vm->dedicated_vmid[vmhub]; +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; +struct fence *updates = sync->last_vm_update; +int r =0 ; +struct fence *flushed, *tmp; +bool needs_flush = false; + +mutex_lock (&id_mgr->lock); +if (amdgpu_vm_had_gpu_reset (adev, id)) + needs_flush = true;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub) · line 427
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+ + flushed = id->flushed_updates; +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) + needs_flush = true;Just question:
Do we need to consider concurrent flush for Vega10 like grab id func?
Christian has pointed that old asic has hardware bug.
Regards,
David Zhou
Quoted 46 lines
Jerry
Quoted 43 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +34
-0+if (needs_flush) { + tmp =amdgpu_sync_get_fence (&id->active); +if (tmp) { + r =amdgpu_sync_fence (adev, sync, tmp); +fence_put (tmp); +mutex_unlock (&id_mgr->lock); +return r; + } + } + +/* Good we can use this VMID. Remember this submission as +* user of the VMID. +*/ + r =amdgpu_sync_fence (ring->adev, &id->active, fence); +if (r) + goto out; + +if (updates && (!flushed || updates->context != flushed->context || +fence_is_later (updates, flushed))) { +fence_put (id->flushed_updates); + id->flushed_updates =fence_get (updates); + } + id->pd_gpu_addr = job->vm_pd_addr; + id->current_gpu_reset_count =atomic_read (&adev->gpu_reset_counter); +atomic64_set (&id->owner, vm->client_id); + job->vm_needs_flush = needs_flush; + + job->vm_id = id - id_mgr->ids; +trace_amdgpu_vm_grab_id (vm, ring, job); +out: +mutex_unlock (&id_mgr->lock); +return r; +} +/**
*amdgpu_vm_grab_id- allocate the next free VMID *drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -426,6 +483,10 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm,struct amdgpu_ring *ring, unsigned i;int r =0 ;
Quoted 13 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+if (amdgpu_vm_dedicated_vmid_ready (vm, vmhub)) +return amdgpu_vm_grab_dedicated_vmid (vm, ring, sync, + fence, job); + fences =kmalloc_array (sizeof (void *), id_mgr->num_ids,GFP_KERNEL );if (!fences) return -ENOMEM;_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): [email protected]
Re: [PATCH 5/6] drm/amdgpu: implement grab dedicated vmid V2
Am 27.04.2017 um 06:42 schrieb zhoucm1:
Quoted 50 lines · Jerry (Junwei)
Quoted 39 lines · Chunming Zhou
Quoted 38 lines
v2: move sync waiting only when flush needs
Change-Id I64da2701c9fdcf986afb90ba1492a78d5bef1b6cSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +19
-0@@ -402,6 +402,63 @@ static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub)return !!vm->dedicated_vmid[vmhub]; } +static int amdgpu_vm_grab_dedicated_vmid (struct amdgpu_vm *vm, +struct amdgpu_ring *ring, +struct amdgpu_sync *sync, +struct fence *fence, +struct amdgpu_job *job) +{ +struct amdgpu_device *adev = ring->adev; +unsigned vmhub = ring->funcs->vmhub; +struct amdgpu_vm_id *id = vm->dedicated_vmid[vmhub]; +struct amdgpu_vm_id_manager *id_mgr = &adev->vm_manager.id_mgr[vmhub]; +struct fence *updates = sync->last_vm_update; +int r =0 ; +struct fence *flushed, *tmp; +bool needs_flush = false; + +mutex_lock (&id_mgr->lock); +if (amdgpu_vm_had_gpu_reset (adev, id)) + needs_flush = true; +Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm, unsigned vmhub) · line 427
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+ flushed = id->flushed_updates; + if (updates && (!flushed || updates->context !=
flushed->context||drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+ fence_is_later(updates, flushed))) + needs_flush = true;Just question:
Do we need to consider concurrent flush for Vega10 like grab id func?
Quoted 1 line
Christian has pointed that old asic has hardware bug.
Which is fixed for Vega10, on that hardware concurrent flushing works fine.
It's just that Tonga/Fiji have a real problem with that and for CIK/Polaris it's more a subtle one which is hard to trigger.
Regards,
Christian.
Quoted 64 lines
Regards,
David ZhouQuoted 47 lines
Jerry
Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18
-0+if (needs_flush) { + tmp =amdgpu_sync_get_fence (&id->active); +if (tmp) { + r =amdgpu_sync_fence (adev, sync, tmp); +fence_put (tmp); +mutex_unlock (&id_mgr->lock); +return r; + } + } + +/* Good we can use this VMID. Remember this submission as +* user of the VMID. +*/ + r =amdgpu_sync_fence (ring->adev, &id->active, fence); +if (r) + goto out; + + if (updates && (!flushed || updates->context !=
flushed->context||drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-0+ fence_is_later(updates, flushed))) { +fence_put (id->flushed_updates); + id->flushed_updates =fence_get (updates); + } + id->pd_gpu_addr = job->vm_pd_addr; + id->current_gpu_reset_count =
atomic_read(&adev->gpu_reset_counter);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+atomic64_set (&id->owner, vm->client_id); + job->vm_needs_flush = needs_flush; + + job->vm_id = id - id_mgr->ids; +trace_amdgpu_vm_grab_id (vm, ring, job); +out: +mutex_unlock (&id_mgr->lock); +return r; +} +/** * amdgpu_vm_grab_id - allocate the next free VMID * @@ -426,6 +483,10 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm,struct amdgpu_ring *ring, unsigned i;int r =0 ;Quoted 13 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+if (amdgpu_vm_dedicated_vmid_ready (vm, vmhub)) +return amdgpu_vm_grab_dedicated_vmid (vm, ring, sync, + fence, job); + fences =kmalloc_array (sizeof (void *), id_mgr->num_ids,GFP_KERNEL );if (!fences) return -ENOMEM;_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 6/6 drm/amdgpu: bump module verion for reserved vmid
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -64,9 +64,10 @@* - 3.12.0 - Add query for double offchip LDS buffers * - 3.13.0 - Add PRT support * - 3.14.0 - Fix race in amdgpu_ctx_get_fence() and note new functionality +* - 3.15.0 - Add reserved vmid support */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 14 +#define KMS_DRIVER_MINOR 15#define KMS_DRIVER_PATCHLEVEL 0int amdgpu_vram_limit =0 ;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx