All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Jerry (Junwei)" <Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
To: christian.koenig-5C7GfCeVMHo@public.gmane.org,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH libdrm 3/4] amdgpu: add a function to find bo by cpu mapping
Date: Tue, 7 Aug 2018 17:52:17 +0800	[thread overview]
Message-ID: <5B696BD1.6060707@amd.com> (raw)
In-Reply-To: <83000f07-20bf-dd0f-4898-3558e626c9d1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

On 08/07/2018 05:33 PM, Christian König wrote:
> Am 07.08.2018 um 10:28 schrieb Zhang, Jerry (Junwei):
>> On 08/07/2018 04:20 PM, Christian König wrote:
>>> Well NAK, that wasn't the intention of putting all BOs into the handle table.
>>>
>>> You should still use the kernel implementation.
>>
>> I thought we have discussed that in below mail thread. any gap?
>>
>> [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
>> {{{
>> >> Well we could just completely drop the kernel implementation and use
>> >> an userspace implementation.
>> >
>> > Do you mean to implement finding bo by cpu address in libdrm completely?
>>
>> Yes, exactly.
>> }}}
>
> Ok, well that is a misunderstanding. I was just speculating about that.
>
> On the other hand if searching all BOs for the right one is not to much overhead for that workaround I'm fine with it.
>
> Just drop patch #2 in this series. All unused entries should be initialized to zero and walking the extra 512 isn't that much overhead.

Yes, reserve it locally for now.
May I get your RB?

Regards,
Jerry

>
> Regards,
> Christian.
>
>>
>> Regards,
>> Jerry
>>
>>>
>>> Christian.
>>>
>>> Am 07.08.2018 um 09:26 schrieb Junwei Zhang:
>>>> Userspace needs to know if the user memory is from BO or malloc.
>>>>
>>>> Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
>>>> ---
>>>>   amdgpu/amdgpu.h    | 23 +++++++++++++++++++++++
>>>>   amdgpu/amdgpu_bo.c | 34 ++++++++++++++++++++++++++++++++++
>>>>   2 files changed, 57 insertions(+)
>>>>
>>>> diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
>>>> index be83b45..a8c353c 100644
>>>> --- a/amdgpu/amdgpu.h
>>>> +++ b/amdgpu/amdgpu.h
>>>> @@ -678,6 +678,29 @@ int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
>>>>                       amdgpu_bo_handle *buf_handle);
>>>>   /**
>>>> + * Validate if the user memory comes from BO
>>>> + *
>>>> + * \param dev - [in] Device handle. See #amdgpu_device_initialize()
>>>> + * \param cpu - [in] CPU address of user allocated memory which we
>>>> + * want to map to GPU address space (make GPU accessible)
>>>> + * (This address must be correctly aligned).
>>>> + * \param size - [in] Size of allocation (must be correctly aligned)
>>>> + * \param buf_handle - [out] Buffer handle for the userptr memory
>>>> + * if the user memory is not from BO, the buf_handle will be NULL.
>>>> + * \param offset_in_bo - [out] offset in this BO for this user memory
>>>> + *
>>>> + *
>>>> + * \return   0 on success\n
>>>> + *          <0 - Negative POSIX Error code
>>>> + *
>>>> +*/
>>>> +int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev,
>>>> +                  void *cpu,
>>>> +                  uint64_t size,
>>>> +                  amdgpu_bo_handle *buf_handle,
>>>> +                  uint64_t *offset_in_bo);
>>>> +
>>>> +/**
>>>>    * Free previosuly allocated memory
>>>>    *
>>>>    * \param   dev           - \c [in] Device handle. See #amdgpu_device_initialize()
>>>> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
>>>> index b24e698..a631050 100644
>>>> --- a/amdgpu/amdgpu_bo.c
>>>> +++ b/amdgpu/amdgpu_bo.c
>>>> @@ -529,6 +529,40 @@ int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo,
>>>>       }
>>>>   }
>>>> +int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev,
>>>> +                  void *cpu,
>>>> +                  uint64_t size,
>>>> +                  amdgpu_bo_handle *buf_handle,
>>>> +                  uint64_t *offset_in_bo)
>>>> +{
>>>> +    int i;
>>>> +    struct amdgpu_bo *bo;
>>>> +
>>>> +    if (cpu == NULL || size == 0)
>>>> +        return -EINVAL;
>>>> +
>>>> +    pthread_mutex_lock(&dev->bo_table_mutex);
>>>> +    for (i = 0; i <= dev->bo_handles.max_key; i++) {
>>>> +        bo = handle_table_lookup(&dev->bo_handles, i);
>>>> +        if (!bo || !bo->cpu_ptr || size > bo->alloc_size)
>>>> +            continue;
>>>> +        if (cpu >= bo->cpu_ptr && cpu < (bo->cpu_ptr + bo->alloc_size))
>>>> +            break;
>>>> +    }
>>>> +    pthread_mutex_unlock(&dev->bo_table_mutex);
>>>> +
>>>> +    if (i <= dev->bo_handles.max_key) {
>>>> +        atomic_inc(&bo->refcount);
>>>> +        *buf_handle = bo;
>>>> +        *offset_in_bo = cpu - bo->cpu_ptr;
>>>> +    } else {
>>>> +        *buf_handle = NULL;
>>>> +        *offset_in_bo = 0;
>>>> +    }
>>>> +
>>>> +    return 0;
>>>> +}
>>>> +
>>>>   int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
>>>>                       void *cpu,
>>>>                       uint64_t size,
>>>
>>> _______________________________________________
>>> 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
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-08-07  9:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07  7:26 [PATCH libdrm 1/4] amdgpu: add bo from user memory to handle table Junwei Zhang
     [not found] ` <1533626820-7701-1-git-send-email-Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
2018-08-07  7:26   ` [PATCH libdrm 2/4] amdgpu: add count for " Junwei Zhang
2018-08-07  7:26   ` [PATCH libdrm 3/4] amdgpu: add a function to find bo by cpu mapping Junwei Zhang
     [not found]     ` <1533626820-7701-3-git-send-email-Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
2018-08-07  7:55       ` zhoucm1
     [not found]         ` <543dd2f7-861a-c56e-f743-3c1c87602034-5C7GfCeVMHo@public.gmane.org>
2018-08-07  9:30           ` Christian König
     [not found]             ` <8fb413b3-811a-f984-a9b2-3dcd89b55bd7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-08-07 10:18               ` zhoucm1
2018-08-07  8:20       ` Christian König
     [not found]         ` <b0ec5154-45a3-4b58-cc7f-1fa5916e552a-5C7GfCeVMHo@public.gmane.org>
2018-08-07  8:28           ` Zhang, Jerry (Junwei)
     [not found]             ` <5B695839.4050604-5C7GfCeVMHo@public.gmane.org>
2018-08-07  9:33               ` Christian König
     [not found]                 ` <83000f07-20bf-dd0f-4898-3558e626c9d1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-08-07  9:52                   ` Zhang, Jerry (Junwei) [this message]
     [not found]                     ` <5B696BD1.6060707-5C7GfCeVMHo@public.gmane.org>
2018-08-07  9:59                       ` Christian König
     [not found]                         ` <f41dc914-3ae3-2bda-a987-476154f3fea1-5C7GfCeVMHo@public.gmane.org>
2018-08-07 10:23                           ` Zhang, Jerry (Junwei)
     [not found]                             ` <5B69733C.4050707-5C7GfCeVMHo@public.gmane.org>
2018-08-07 11:30                               ` Christian König
2018-08-07 11:35       ` Christian König
2018-08-07  7:27   ` [PATCH libdrm 4/4] tests/amdgpu: add test for finding bo by CPU mapping Junwei Zhang
2018-08-07  7:51   ` [PATCH libdrm 1/4] amdgpu: add bo from user memory to handle table zhoucm1
     [not found]     ` <a3b83620-72e5-76ea-5005-04f71c46f7c3-5C7GfCeVMHo@public.gmane.org>
2018-08-07  9:54       ` Zhang, Jerry (Junwei)
     [not found]         ` <5B696C56.9030403-5C7GfCeVMHo@public.gmane.org>
2018-08-07 10:01           ` Christian König

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=5B696BD1.6060707@amd.com \
    --to=jerry.zhang-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=christian.koenig-5C7GfCeVMHo@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.