All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Jerry (Junwei)" <Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
To: zhoucm1 <david1.zhou-5C7GfCeVMHo@public.gmane.org>,
	"Christian König"
	<deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3
Date: Thu, 27 Apr 2017 10:24:08 +0800	[thread overview]
Message-ID: <59015648.5010403@amd.com> (raw)
In-Reply-To: <590153B1.3070305-5C7GfCeVMHo@public.gmane.org>

On 04/27/2017 10:13 AM, zhoucm1 wrote:
>
>
> On 2017年04月26日 20:26, Christian König wrote:
>> Am 26.04.2017 um 13:10 schrieb Chunming Zhou:
>>> add reserve/unreserve vmid funtions.
>>> v3:
>>> only reserve vmid from gfxhub
>>>
>>> Change-Id: I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039d
>>> Signed-off-by: Chunming Zhou <David1.Zhou@amd.com>
>>> ---
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70
>>> +++++++++++++++++++++++++++-------
>>>   1 file changed, 57 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> index ec87d64..a783e8e 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> @@ -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;
>>
>> 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.
> 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

>
> 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
>>
>>> +    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.
>>
>>> +
>>> +    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);
>>
>> 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.
>>
>>> +            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
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-04-27  2:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-26 11:10 [PATCH 0/6 v3] *** Dedicated vmid per process v3 *** Chunming Zhou
     [not found] ` <1493205039-3721-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2017-04-26 11:10   ` [PATCH 1/6] drm/amdgpu: add vm ioctl Chunming Zhou
2017-04-26 11:10   ` [PATCH 2/6] drm/amdgpu: add dedicated vmid field in vm struct Chunming Zhou
2017-04-26 11:10   ` [PATCH 3/6] drm/amdgpu: reserve/unreserve vmid by vm ioctl v3 Chunming Zhou
     [not found]     ` <1493205039-3721-4-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2017-04-26 12:26       ` Christian König
     [not found]         ` <bf812c57-d9ee-8a15-1198-acc687145fea-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-04-27  2:13           ` zhoucm1
     [not found]             ` <590153B1.3070305-5C7GfCeVMHo@public.gmane.org>
2017-04-27  2:24               ` Zhang, Jerry (Junwei) [this message]
     [not found]                 ` <59015648.5010403-5C7GfCeVMHo@public.gmane.org>
2017-04-27  4:29                   ` zhoucm1
2017-04-27  9:13                   ` Christian König
2017-04-27  2:18           ` Zhang, Jerry (Junwei)
2017-04-26 11:10   ` [PATCH 4/6] drm/amdgpu: add limitation for dedicated vm number v3 Chunming Zhou
2017-04-26 11:10   ` [PATCH 5/6] drm/amdgpu: implement grab dedicated vmid V2 Chunming Zhou
     [not found]     ` <1493205039-3721-6-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2017-04-26 12:57       ` Christian König
2017-04-27  2:52       ` Zhang, Jerry (Junwei)
     [not found]         ` <59015CD8.3000303-5C7GfCeVMHo@public.gmane.org>
2017-04-27  4:42           ` zhoucm1
     [not found]             ` <590176A2.70304-5C7GfCeVMHo@public.gmane.org>
2017-04-27  9:14               ` Christian König
2017-04-26 11:10   ` [PATCH 6/6] drm/amdgpu: bump module verion for reserved vmid Chunming Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59015648.5010403@amd.com \
    --to=jerry.zhang-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=david1.zhou-5C7GfCeVMHo@public.gmane.org \
    --cc=deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.