<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
True. There indeed are two vmhubs on Navi. So my two comments are not useful here.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Yong</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Sent:</b> Monday, December 23, 2019 2:34 PM<br>
<b>To:</b> Zhao, Yong <Yong.Zhao@amd.com>; Sierra Guiza, Alejandro (Alex) <Alex.Sierra@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH 3/5] drm/amdgpu: GPU TLB flush API moved to amdgpu_amdkfd</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
On 2019-12-20 7:01 p.m., Yong Zhao wrote:<br>
><br>
> On 2019-12-20 6:50 p.m., Yong Zhao wrote:<br>
>> Inline.<br>
>><br>
>> On 2019-12-20 4:35 p.m., Felix Kuehling wrote:<br>
>>> On 2019-12-20 1:24, Alex Sierra wrote:<br>
>>>> [Why]<br>
>>>> TLB flush method has been deprecated using kfd2kgd interface.<br>
>>>> This implementation is now on the amdgpu_amdkfd API.<br>
>>>><br>
>>>> [How]<br>
>>>> TLB flush functions now implemented in amdgpu_amdkfd.<br>
>>>><br>
>>>> Change-Id: Ic51cccdfe6e71288d78da772b6e1b6ced72f8ef7<br>
>>>> Signed-off-by: Alex Sierra <alex.sierra@amd.com><br>
>>><br>
>>> Looks good to me. See my comment about the TODO inline.<br>
>>><br>
>>><br>
>>>> ---<br>
>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 32 <br>
>>>> ++++++++++++++++++++++<br>
>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 ++<br>
>>>> drivers/gpu/drm/amd/amdkfd/kfd_process.c | 8 ++++--<br>
>>>> 3 files changed, 39 insertions(+), 3 deletions(-)<br>
>>>><br>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c <br>
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
>>>> index d3da9dde4ee1..b7f6e70c5762 100644<br>
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
>>>> @@ -634,6 +634,38 @@ bool amdgpu_amdkfd_is_kfd_vmid(struct <br>
>>>> amdgpu_device *adev, u32 vmid)<br>
>>>> return false;<br>
>>>> }<br>
>>>> +int amdgpu_amdkfd_flush_gpu_tlb_vmid(struct kgd_dev *kgd, <br>
>>>> uint16_t vmid)<br>
>>>> +{<br>
>>>> + struct amdgpu_device *adev = (struct amdgpu_device *)kgd;<br>
>>>> + /* TODO: condition missing for FAMILY above NV */<br>
>>><br>
>>> I'm not sure what's missing here. NV and above don't need any <br>
>>> special treatment. Since SDMA is connected to GFXHUB on NV, only the <br>
>>> GFXHUB needs to be flushed.<br>
>>><br>
>>> Regards,<br>
>>> Felix<br>
>>><br>
>>><br>
>>>> + if (adev->family == AMDGPU_FAMILY_AI) {<br>
>>>> + int i;<br>
>>>> +<br>
>>>> + for (i = 0; i < adev->num_vmhubs; i++)<br>
>>>> + amdgpu_gmc_flush_gpu_tlb(adev, vmid, i, 0);<br>
>>>> + } else {<br>
>>>> + amdgpu_gmc_flush_gpu_tlb(adev, vmid, AMDGPU_GFXHUB_0, 0);<br>
>>>> + }<br>
>><br>
>> This if else can be unified by<br>
>><br>
>> for (i = 0; i < adev->num_vmhubs; i++)<br>
>><br>
>> amdgpu_gmc_flush_gpu_tlb(adev, vmid, i, 0);<br>
>><br>
>>>> +<br>
>>>> + return 0;<br>
>>>> +}<br>
>>>> +<br>
>>>> +int amdgpu_amdkfd_flush_gpu_tlb_pasid(struct kgd_dev *kgd, <br>
>>>> uint16_t pasid)<br>
>>>> +{<br>
>>>> + struct amdgpu_device *adev = (struct amdgpu_device *)kgd;<br>
>>>> + uint32_t flush_type = 0;<br>
>>>> + bool all_hub = false;<br>
>>>> +<br>
>>>> + if (adev->gmc.xgmi.num_physical_nodes &&<br>
>>>> + adev->asic_type == CHIP_VEGA20)<br>
>>>> + flush_type = 2;<br>
>>>> +<br>
>>>> + if (adev->family == AMDGPU_FAMILY_AI)<br>
>>>> + all_hub = true;<br>
>>>> +<br>
>>>> + return amdgpu_gmc_flush_gpu_tlb_pasid(adev, pasid, flush_type, <br>
>>>> all_hub);<br>
> The all_hub parameter can be inferred from num_vmhubs in <br>
> flush_gpu_tlb_pasid(), so it can be optimized out here.<br>
<br>
Hi Yong,<br>
<br>
This is incorrect. NV has two VM hubs: GFXHUB and MMHUB. But KFD doesn't <br>
care about MMHUB on Navi because SDMA is connected to the GFXHUB. <br>
Therefore the all_hub parameter should not be based on the num_vmhubs. <br>
We need a special case for NV.<br>
<br>
Or rather the special case could be AI, where SDMA is not connected to <br>
GFXHUB. So only on AI we need to flush all hubs for KFD VMs.<br>
<br>
Regards,<br>
Felix<br>
<br>
>>>> +}<br>
>>>> +<br>
>>>> bool amdgpu_amdkfd_have_atomics_support(struct kgd_dev *kgd)<br>
>>>> {<br>
>>>> struct amdgpu_device *adev = (struct amdgpu_device *)kgd;<br>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h <br>
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h<br>
>>>> index 069d5d230810..47b0f2957d1f 100644<br>
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h<br>
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h<br>
>>>> @@ -136,6 +136,8 @@ int amdgpu_amdkfd_submit_ib(struct kgd_dev <br>
>>>> *kgd, enum kgd_engine_type engine,<br>
>>>> uint32_t *ib_cmd, uint32_t ib_len);<br>
>>>> void amdgpu_amdkfd_set_compute_idle(struct kgd_dev *kgd, bool idle);<br>
>>>> bool amdgpu_amdkfd_have_atomics_support(struct kgd_dev *kgd);<br>
>>>> +int amdgpu_amdkfd_flush_gpu_tlb_vmid(struct kgd_dev *kgd, uint16_t <br>
>>>> vmid);<br>
>>>> +int amdgpu_amdkfd_flush_gpu_tlb_pasid(struct kgd_dev *kgd, <br>
>>>> uint16_t pasid);<br>
>>>> bool amdgpu_amdkfd_is_kfd_vmid(struct amdgpu_device *adev, u32 <br>
>>>> vmid);<br>
>>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c <br>
>>>> b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
>>>> index 536a153ac9a4..25b90f70aecd 100644<br>
>>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
>>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
>>>> @@ -32,6 +32,7 @@<br>
>>>> #include <linux/mman.h><br>
>>>> #include <linux/file.h><br>
>>>> #include "amdgpu_amdkfd.h"<br>
>>>> +#include "amdgpu.h"<br>
>>>> struct mm_struct;<br>
>>>> @@ -1152,16 +1153,17 @@ int kfd_reserved_mem_mmap(struct kfd_dev <br>
>>>> *dev, struct kfd_process *process,<br>
>>>> void kfd_flush_tlb(struct kfd_process_device *pdd)<br>
>>>> {<br>
>>>> struct kfd_dev *dev = pdd->dev;<br>
>>>> - const struct kfd2kgd_calls *f2g = dev->kfd2kgd;<br>
>>>> if (dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS) {<br>
>>>> /* Nothing to flush until a VMID is assigned, which<br>
>>>> * only happens when the first queue is created.<br>
>>>> */<br>
>>>> if (pdd->qpd.vmid)<br>
>>>> - f2g->invalidate_tlbs_vmid(dev->kgd, pdd->qpd.vmid);<br>
>>>> + amdgpu_amdkfd_flush_gpu_tlb_vmid(dev->kgd,<br>
>>>> + pdd->qpd.vmid);<br>
>>>> } else {<br>
>>>> - f2g->invalidate_tlbs(dev->kgd, pdd->process->pasid);<br>
>>>> + amdgpu_amdkfd_flush_gpu_tlb_pasid(dev->kgd,<br>
>>>> + pdd->process->pasid);<br>
>>>> }<br>
>>>> }<br>
>>> _______________________________________________<br>
>>> amd-gfx mailing list<br>
>>> amd-gfx@lists.freedesktop.org<br>
>>> <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cyong.zhao%40amd.com%7C3a33649d2a804998d00408d785a7776f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637124827007059728&sdata=fNTunmAJObxfgbJBlNWWXucyH9ezedLv%2BrqnMTz3Ai4%3D&reserved=0">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cyong.zhao%40amd.com%7C3a33649d2a804998d00408d785a7776f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637124827007059728&sdata=fNTunmAJObxfgbJBlNWWXucyH9ezedLv%2BrqnMTz3Ai4%3D&reserved=0</a>
<br>
>>><br>
>> _______________________________________________<br>
>> amd-gfx mailing list<br>
>> amd-gfx@lists.freedesktop.org<br>
>> <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cyong.zhao%40amd.com%7C3a33649d2a804998d00408d785a7776f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637124827007059728&sdata=fNTunmAJObxfgbJBlNWWXucyH9ezedLv%2BrqnMTz3Ai4%3D&reserved=0">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cyong.zhao%40amd.com%7C3a33649d2a804998d00408d785a7776f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637124827007059728&sdata=fNTunmAJObxfgbJBlNWWXucyH9ezedLv%2BrqnMTz3Ai4%3D&reserved=0</a>
<br>
>><br>
</div>
</span></font></div>
</div>
</body>
</html>