drm/amdgpu: XGMI pstate switch initial support
Subsystems (2)
PATCH 1/1 drm/amdgpu: XGMI pstate switch initial support
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
@@ -2018,6 +2018,10 @@ static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work) r =amdgpu_device_enable_mgpu_fan_boost ();if (r)DRM_ERROR ("enable mgpu fan boost failed (%d).\n" , r); + +/*set to low pstate by default */ +amdgpu_xgmi_set_pstate (adev,0 ); + }static void amdgpu_device_delay_enable_gfx_off (struct work_struct *work)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -0
@@ -72,6 +72,8 @@ struct amdgpu_bo_va {/* If the mappings are cleared or filled */ bool cleared; + +bool is_xgmi; };struct amdgpu_bo {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +21 -0
@@ -34,6 +34,7 @@#include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /** * DOC: GPUVM
@@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,INIT_LIST_HEAD (&bo_va->valids);INIT_LIST_HEAD (&bo_va->invalids); +if (bo &&amdgpu_xgmi_same_hive (adev,amdgpu_ttm_adev (bo->tbo.bdev))) { + bo_va->is_xgmi = true; +mutex_lock (&adev->vm_manager.lock_pstate); +/* Power up XGMI if it can be potentially used */ +if (++adev->vm_manager.xgmi_map_counter ==1 ) +amdgpu_xgmi_set_pstate (adev,1 ); +mutex_unlock (&adev->vm_manager.lock_pstate); + } +return bo_va; }
@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, }dma_fence_put (bo_va->last_pt_update); + +if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); +if (--adev->vm_manager.xgmi_map_counter ==0 ) +amdgpu_xgmi_set_pstate (adev,0 ); +mutex_unlock (&adev->vm_manager.lock_pstate); + } +kfree (bo_va); }
@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)idr_init (&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter =0 ; +mutex_init (&adev->vm_manager.lock_pstate); }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4 -0
@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr;spinlock_t pasid_lock; + +/* counter of mapped memory through xgmi */ +uint32_t xgmi_map_counter; +struct mutex lock_pstate; };#define amdgpu_vm_copy_pte (adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +15 -1
@@ -200,12 +200,26 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int loif (lock)mutex_lock (&tmp->hive_lock); - + tmp->pstate =-1 ;mutex_unlock (&xgmi_mutex);return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ +int ret =0 ; +struct amdgpu_hive_info *hive =amdgpu_get_xgmi_hive (adev,0 ); + +if (!hive) +return 0 ; + +if (hive->pstate == pstate) +return 0 ; +/* Todo : sent the message to SMU for pstate change */ +return ret; +} +int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev) {int ret = -EINVAL ;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +10 -0
@@ -33,11 +33,21 @@ struct amdgpu_hive_info {struct kobject *kobj;struct device_attribute dev_attr;struct amdgpu_device *adev; + int pstate; /*0 -- low , 1 -- high , -1 unknown*/ };struct amdgpu_hive_info *amdgpu_get_xgmi_hive (struct amdgpu_device *adev,int lock);int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev);int amdgpu_xgmi_add_device (struct amdgpu_device *adev);void amdgpu_xgmi_remove_device (struct amdgpu_device *adev); +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate); + +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, +struct amdgpu_device *bo_adev) +{ +return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +}#endif
Signature · 6 lines
2.7.4 _______________________________________________ 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): 1553282911-11125-1-git-send-email-shaoyun.liu-5C7GfCeVMHo@public.gmane.org
Am 22.03.19 um 20:28 schrieb Liu, Shaoyun:
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 36
Quoted 8 lines
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0+int pstate;/*0 -- low , 1 -- high , -1 unknown*/
Maybe Alex or somebody else who is working on the power management stuff knows a better enum for this.
But at least from the VM side the patch is Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
I don't see any check for the memory type. As far as I can tell you'll power up XGMI even for system memory mappings. See inline.
Quoted 56 lines · Shaoyun
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -2018,6 +2018,10 @@ static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work) r =amdgpu_device_enable_mgpu_fan_boost ();if (r)DRM_ERROR ("enable mgpu fan boost failed (%d).\n" , r); + +/*set to low pstate by default */ +amdgpu_xgmi_set_pstate (adev,0 ); + }static void amdgpu_device_delay_enable_gfx_off (struct work_struct *work)drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -72,6 +72,8 @@ struct amdgpu_bo_va {/* If the mappings are cleared or filled */ bool cleared; + +bool is_xgmi; };struct amdgpu_bo {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -34,6 +34,7 @@#include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /** * DOC: GPUVM
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, · line 2077
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,INIT_LIST_HEAD (&bo_va->valids);INIT_LIST_HEAD (&bo_va->invalids); +if (bo &&amdgpu_xgmi_same_hive (adev,amdgpu_ttm_adev (bo->tbo.bdev))) { + bo_va->is_xgmi = true;
You're setting this to true even for system memory BOs that don't involve XGMI mappings. That means you'll power up XGMI unnecessarily in many cases because KFD processes always have system memory mappings that are mapped to all GPUs (e.g. the signal page).
Regards,
Felix
Quoted 98 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18
-0+mutex_lock (&adev->vm_manager.lock_pstate); +/* Power up XGMI if it can be potentially used */ +if (++adev->vm_manager.xgmi_map_counter ==1 ) +amdgpu_xgmi_set_pstate (adev,1 ); +mutex_unlock (&adev->vm_manager.lock_pstate); + } +return bo_va; }@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, }dma_fence_put (bo_va->last_pt_update); + +if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); +if (--adev->vm_manager.xgmi_map_counter ==0 ) +amdgpu_xgmi_set_pstate (adev,0 ); +mutex_unlock (&adev->vm_manager.lock_pstate); + } +kfree (bo_va); }@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)idr_init (&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter =0 ; +mutex_init (&adev->vm_manager.lock_pstate); }/** drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr;spinlock_t pasid_lock; + +/* counter of mapped memory through xgmi */ +uint32_t xgmi_map_counter; +struct mutex lock_pstate; };#define amdgpu_vm_copy_pte (adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +15
-1@@ -200,12 +200,26 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int loif (lock)mutex_lock (&tmp->hive_lock); - + tmp->pstate =-1 ;mutex_unlock (&xgmi_mutex);return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ +int ret =0 ; +struct amdgpu_hive_info *hive =amdgpu_get_xgmi_hive (adev,0 ); + +if (!hive) +return 0 ; + +if (hive->pstate == pstate) +return 0 ; +/* Todo : sent the message to SMU for pstate change */ +return ret; +} +int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev) {int ret = -EINVAL ;drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2
-0@@ -33,11 +33,21 @@ struct amdgpu_hive_info {struct kobject *kobj;struct device_attribute dev_attr;struct amdgpu_device *adev; +int pstate;/*0 -- low , 1 -- high , -1 unknown*/ };struct amdgpu_hive_info *amdgpu_get_xgmi_hive (struct amdgpu_device *adev,int lock);int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev);int amdgpu_xgmi_add_device (struct amdgpu_device *adev);void amdgpu_xgmi_remove_device (struct amdgpu_device *adev); +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate);
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 53
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +8
-0+ +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, +struct amdgpu_device *bo_adev) +{ +return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +}#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): 0baa3321-72d1-f7bf-b09b-39a380971dca-5C7GfCeVMHo@public.gmane.org
I think in a real usage ( tensorflow ex), it's rarely only the system memory (no vram) will be mapped for peer access.
Anyway, how about add preferred_domain check for xgmi ? I think even user use ioctl to change the preferred_domain, bo_add should still be called before the real mapping.
Regards
Shaoyun.liu
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Kuehling, Felix <[email protected]>
Sent: March 25, 2019 6:28:32 PM
To: Liu, Shaoyun; [email protected]
Subject: Re: [PATCH] drm/amdgpu: XGMI pstate switch initial support
I don't see any check for the memory type. As far as I can tell you'll power up XGMI even for system memory mappings. See inline.
Quoted 56 lines · Shaoyun
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -2018,6 +2018,10 @@ static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work) r =amdgpu_device_enable_mgpu_fan_boost ();if (r)DRM_ERROR ("enable mgpu fan boost failed (%d).\n" , r); + +/*set to low pstate by default */ +amdgpu_xgmi_set_pstate (adev,0 ); + }static void amdgpu_device_delay_enable_gfx_off (struct work_struct *work)drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -72,6 +72,8 @@ struct amdgpu_bo_va {/* If the mappings are cleared or filled */ bool cleared; + +bool is_xgmi; };struct amdgpu_bo {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -34,6 +34,7 @@#include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /** * DOC: GPUVM
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, · line 2077
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,INIT_LIST_HEAD (&bo_va->valids);INIT_LIST_HEAD (&bo_va->invalids); +if (bo &&amdgpu_xgmi_same_hive (adev,amdgpu_ttm_adev (bo->tbo.bdev))) { + bo_va->is_xgmi = true;
You're setting this to true even for system memory BOs that don't involve XGMI mappings. That means you'll power up XGMI unnecessarily in many cases because KFD processes always have system memory mappings that are mapped to all GPUs (e.g. the signal page).
Regards,
Felix
Quoted 98 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18
-0+mutex_lock (&adev->vm_manager.lock_pstate); +/* Power up XGMI if it can be potentially used */ +if (++adev->vm_manager.xgmi_map_counter ==1 ) +amdgpu_xgmi_set_pstate (adev,1 ); +mutex_unlock (&adev->vm_manager.lock_pstate); + } +return bo_va; }@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, }dma_fence_put (bo_va->last_pt_update); + +if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); +if (--adev->vm_manager.xgmi_map_counter ==0 ) +amdgpu_xgmi_set_pstate (adev,0 ); +mutex_unlock (&adev->vm_manager.lock_pstate); + } +kfree (bo_va); }@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)idr_init (&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter =0 ; +mutex_init (&adev->vm_manager.lock_pstate); }/** drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr;spinlock_t pasid_lock; + +/* counter of mapped memory through xgmi */ +uint32_t xgmi_map_counter; +struct mutex lock_pstate; };#define amdgpu_vm_copy_pte (adev, ib, pe, src, count) ((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +15
-1@@ -200,12 +200,26 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int loif (lock)mutex_lock (&tmp->hive_lock); - + tmp->pstate =-1 ;mutex_unlock (&xgmi_mutex);return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ +int ret =0 ; +struct amdgpu_hive_info *hive =amdgpu_get_xgmi_hive (adev,0 ); + +if (!hive) +return 0 ; + +if (hive->pstate == pstate) +return 0 ; +/* Todo : sent the message to SMU for pstate change */ +return ret; +} +int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev) {int ret = -EINVAL ;drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2
-0@@ -33,11 +33,21 @@ struct amdgpu_hive_info {struct kobject *kobj;struct device_attribute dev_attr;struct amdgpu_device *adev; +int pstate;/*0 -- low , 1 -- high , -1 unknown*/ };struct amdgpu_hive_info *amdgpu_get_xgmi_hive (struct amdgpu_device *adev,int lock);int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev);int amdgpu_xgmi_add_device (struct amdgpu_device *adev);void amdgpu_xgmi_remove_device (struct amdgpu_device *adev); +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate);
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 53
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +8
-0+ +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, +struct amdgpu_device *bo_adev) +{ +return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +}#endif
_______________________________________________
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): DM6PR12MB3241D607634C7D7A58742D3BF45F0-lmeGfMZKVrEShx2hYn8pVQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Quoted 2 lines · Shaoyun
I think in a real usage ( tensorflow ex), it's rarely only the system memory (no vram) will be mapped for peer access.
With that argument you could simplify your change and just power up XGMI as soon as a KFD process starts. Because that's effectively what happens with your change as it is now, if you don't check the memory type. Every KFD process maps the signal page (in system memory) to all GPUs. So you will always increment the xgmi_map_count even before the first VRAM BO is allocated, let alone mapped to multiple GPUs.
Quoted 3 lines
Anyway, how about add
preferred_domaincheck for xgmi ? I think even user use ioctl to change the preferred_domain,bo_addshould still be called before the real mapping.
amdgpu_gem_op_ioctl with AMDGPU_GEM_OP_SET_PLACEMENT doesn't call bo_add. You'd have to add something in amdgpu_gem_op_ioctl to re-evaluate all bo_vas of the BO when its placement changes, update the bo_va->is_xgmi flag, and if necessary the xgmi_map_counter.
Regards,
Felix
Quoted 207 lines
Regards
Shaoyun.liu
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Kuehling, Felix <[email protected]>
*Sent:* March 25, 2019 6:28:32 PM
*To:* Liu, Shaoyun; [email protected] *Subject:* Re: [PATCH] drm/amdgpu: XGMI pstate switch initial support I don't see any check for the memory type. As far as I can tell you'll power up XGMI even for system memory mappings. See inline.Quoted 13 lines · Shaoyun
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 4 ++++drivers/gpu/drm/amd/amdgpu/amdgpu_object.h| 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++Review
Quoted 3 lines
6 files changed, 56 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void
Quoted 4 lines
index ec9562d..c4c61e9 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -2018,6 +2018,10 @@ static void
amdgpu_device_ip_late_init_func_handler(struct work_struct *work)Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0r = amdgpu_device_enable_mgpu_fan_boost(); if (r) DRM_ERROR("enable mgpu fan boost failed (%d).\n", r); + + /*set to low pstate by default */ + amdgpu_xgmi_set_pstate(adev, 0); + }static void amdgpu_device_delay_enable_gfx_off(struct
work_struct*work)
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.hReview
Quoted 13 lines
index 220a6a7..c430e82 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -72,6 +72,8 @@ struct amdgpu_bo_va { /* If the mappings are cleared or filled */ bool cleared; + + bool is_xgmi; }; struct amdgpu_bo {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.cdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
Quoted 12 lines
index 729da1c..a7247d5 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -34,6 +34,7 @@ #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /*** DOC: GPUVM @@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0INIT_LIST_HEAD(&bo_va->valids); INIT_LIST_HEAD(&bo_va->invalids); + if (bo && amdgpu_xgmi_same_hive(adev,
amdgpu_ttm_adev(bo->tbo.bdev))) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, · line 2077
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ bo_va->is_xgmi = true;You're setting this to true even for system memory BOs that don't involve XGMI mappings. That means you'll power up XGMI unnecessarily in many cases because KFD processes always have system memory mappings that are mapped to all GPUs (e.g. the signal page).
Regards,
Felixdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15
-0+mutex_lock (&adev->vm_manager.lock_pstate); + /* Power up XGMI if it can be potentially used */ + if (++adev->vm_manager.xgmi_map_counter == 1) + amdgpu_xgmi_set_pstate(adev, 1); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + return bo_va; }@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, } dma_fence_put(bo_va->last_pt_update); + + if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); + if (--adev->vm_manager.xgmi_map_counter == 0) + amdgpu_xgmi_set_pstate(adev, 0); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + kfree(bo_va); }@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct
amdgpu_device*adev)Review
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0idr_init(&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter = 0; +mutex_init (&adev->vm_manager.lock_pstate); } /**(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.hQuoted 4 lines
index 520122b..f586b38 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm_manager { · line 333
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr; spinlock_t pasid_lock; + + /* counter of mapped memory through xgmi */ + uint32_t xgmi_map_counter; + struct mutex lock_pstate; }; #define amdgpu_vm_copy_pte(adev, ib, pe, src, count)((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.cdrivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info
Quoted 4 lines
index fcc4b05..3368347 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0@@ -200,12 +200,26 @@ struct amdgpu_hive_info*amdgpu_get_xgmi_hive(struct
amdgpu_device*adev, int loQuoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6
-1if (lock) mutex_lock(&tmp->hive_lock); - + tmp->pstate = -1; mutex_unlock(&xgmi_mutex); return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ + int ret = 0; + struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0); +drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lo
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9
-0+ if (!hive) + return 0; + + if (hive->pstate == pstate) + return 0; + /* Todo : sent the message to SMU for pstate change */ + return ret; +} + int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct
amdgpu_device*adev)Review
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0{ int ret = -EINVAL;(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.hQuoted 11 lines
index 24a3b03..3e9c91e 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0@@ -33,11 +33,21 @@ struct amdgpu_hive_info { struct kobject *kobj; struct device_attribute dev_attr; struct amdgpu_device *adev; + int pstate; /*0 -- low , 1 -- high , -1 unknown*/ };struct
amdgpu_hive_info*amdgpu_get_xgmi_hive(structamdgpu_device*adev, int lock);
Quoted 1 line
int amdgpu_xgmi_update_topology(struct
amdgpu_hive_info*hive,struct
amdgpu_device*adev);Quoted 12 lines
int
amdgpu_xgmi_add_device(struct amdgpu_device *adev); voidamdgpu_xgmi_remove_device(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +9
-0+int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate); + +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, + struct amdgpu_device *bo_adev) +{ + return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +}
Quoted 5 lines
Quoted 1 line
#endif
_______________________________________________
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): fa00ab91-3f6a-3bc9-b12d-bebdbfcea9c4-5C7GfCeVMHo@public.gmane.org
Can we simply failed the set placement call if we find the bo_va is existing and bo_va->is_xgmi flag is set ? The original call also failed when it detect it's shared and the placement is in VRAM.
Regards
shaoyun.liu
Quoted 231 lines · Felix
Quoted 2 lines · Shaoyun
I think in a real usage ( tensorflow ex), it's rarely only the system memory (no vram) will be mapped for peer access.
With that argument you could simplify your change and just power up XGMI as soon as a KFD process starts. Because that's effectively what happens with your change as it is now, if you don't check the memory type. Every KFD process maps the signal page (in system memory) to all GPUs. So you will always increment the
xgmi_map_counteven before the first VRAM BO is allocated, let alone mapped to multiple GPUs.Quoted 3 lines
Anyway, how about add
preferred_domaincheck for xgmi ? I think even user use ioctl to change the preferred_domain,bo_addshould still be called before the real mapping.
amdgpu_gem_op_ioctlwithAMDGPU_GEM_OP_SET_PLACEMENTdoesn't callbo_add. You'd have to add something inamdgpu_gem_op_ioctlto re-evaluate allbo_vasof the BO when its placement changes, update thebo_va->is_xgmiflag, and if necessary thexgmi_map_counter.Regards,
FelixQuoted 203 lines
Regards
Shaoyun.liu
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Kuehling, Felix <[email protected]>
*Sent:* March 25, 2019 6:28:32 PM
*To:* Liu, Shaoyun; [email protected] *Subject:* Re: [PATCH] drm/amdgpu: XGMI pstate switch initial support I don't see any check for the memory type. As far as I can tell you'll power up XGMI even for system memory mappings. See inline.Quoted 15 lines · Shaoyun
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-)Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void
Quoted 4 lines
index ec9562d..c4c61e9 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -2018,6 +2018,10 @@ static void
amdgpu_device_ip_late_init_func_handler(struct work_struct *work)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void · line 2027
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0r = amdgpu_device_enable_mgpu_fan_boost(); if (r) DRM_ERROR("enable mgpu fan boost failed (%d).\n", r); + + /*set to low pstate by default */ + amdgpu_xgmi_set_pstate(adev, 0); + } static void amdgpu_device_delay_enable_gfx_off(struct work_struct*work)
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.hReview
Quoted 13 lines
index 220a6a7..c430e82 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -72,6 +72,8 @@ struct amdgpu_bo_va { /* If the mappings are cleared or filled */ bool cleared; + + bool is_xgmi; }; struct amdgpu_bo {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.cdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
Quoted 12 lines
index 729da1c..a7247d5 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -34,6 +34,7 @@ #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /*** DOC: GPUVM @@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct · line 2076
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0INIT_LIST_HEAD(&bo_va->valids); INIT_LIST_HEAD(&bo_va->invalids); + if (bo && amdgpu_xgmi_same_hive(adev,
amdgpu_ttm_adev(bo->tbo.bdev))) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct · line 2077
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ bo_va->is_xgmi = true;You're setting this to true even for system memory BOs that don't involve XGMI mappings. That means you'll power up XGMI unnecessarily in many cases because KFD processes always have system memory mappings that are mapped to all GPUs (e.g. the signal page).
Regards,
Felixdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15
-0+mutex_lock (&adev->vm_manager.lock_pstate); + /* Power up XGMI if it can be potentially used */ + if (++adev->vm_manager.xgmi_map_counter == 1) + amdgpu_xgmi_set_pstate(adev, 1); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + return bo_va; }@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, } dma_fence_put(bo_va->last_pt_update); + + if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); + if (--adev->vm_manager.xgmi_map_counter == 0) + amdgpu_xgmi_set_pstate(adev, 0); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + kfree(bo_va); }@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct
amdgpu_device*adev)Review
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0idr_init(&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter = 0; +mutex_init (&adev->vm_manager.lock_pstate); } /**(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.hQuoted 4 lines
index 520122b..f586b38 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm_manager { · line 333
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr; spinlock_t pasid_lock; + + /* counter of mapped memory through xgmi */ + uint32_t xgmi_map_counter; + struct mutex lock_pstate; }; #define amdgpu_vm_copy_pte(adev, ib, pe, src, count)((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.cdrivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info
Quoted 4 lines
index fcc4b05..3368347 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0@@ -200,12 +200,26 @@ struct amdgpu_hive_info*amdgpu_get_xgmi_hive(struct
amdgpu_device*adev, int loQuoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6
-1if (lock) mutex_lock(&tmp->hive_lock); - + tmp->pstate = -1; mutex_unlock(&xgmi_mutex); return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ + int ret = 0; + struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0); +drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info · line 222
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9
-0+ if (!hive) + return 0; + + if (hive->pstate == pstate) + return 0; + /* Todo : sent the message to SMU for pstate change */ + return ret; +} + int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct
amdgpu_device*adev)Review
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0{ int ret = -EINVAL;(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.hdrivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 39
Quoted 11 lines
index 24a3b03..3e9c91e 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0@@ -33,11 +33,21 @@ struct amdgpu_hive_info { struct kobject *kobj; struct device_attribute dev_attr; struct amdgpu_device *adev; + int pstate; /*0 -- low , 1 -- high , -1 unknown*/ }; struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device*adev, int lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 40
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0
-0int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct
amdgpu_device*adev);Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +9
-0int amdgpu_xgmi_add_device(struct amdgpu_device *adev); void amdgpu_xgmi_remove_device(struct amdgpu_device *adev); +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate); + +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, + struct amdgpu_device *bo_adev) +{ + return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +}Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 53
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0
-0#endif_______________________________________________
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
A message that is not in the archive (sent off-list or not yet received): 75dc572a-bd53-c774-e818-87e68c808260-5C7GfCeVMHo@public.gmane.org
Am 26.03.19 um 16:43 schrieb Liu, Shaoyun:
Quoted 3 lines
Can we simply failed the set placement call if we find the
bo_vais existing andbo_va->is_xgmiflag is set ? The original call also failed when it detect it's shared and the placement is in VRAM.
Possible, alternative we could just move setting the flag again into amdgpu_vm_bo_update().
My concern was to not have the flag in the mapping structure, but setting/clearing it when the update is made is still possible.
Down side is that you then end up with multiple code paths for disabling XGMI.
Christian.
Quoted 238 lines
Regards
shaoyun.liu
Quoted 231 lines · Felix
Quoted 2 lines · Shaoyun
I think in a real usage ( tensorflow ex), it's rarely only the system memory (no vram) will be mapped for peer access.
With that argument you could simplify your change and just power up XGMI as soon as a KFD process starts. Because that's effectively what happens with your change as it is now, if you don't check the memory type. Every KFD process maps the signal page (in system memory) to all GPUs. So you will always increment the
xgmi_map_counteven before the first VRAM BO is allocated, let alone mapped to multiple GPUs.Quoted 3 lines
Anyway, how about add
preferred_domaincheck for xgmi ? I think even user use ioctl to change the preferred_domain,bo_addshould still be called before the real mapping.
amdgpu_gem_op_ioctlwithAMDGPU_GEM_OP_SET_PLACEMENTdoesn't callbo_add. You'd have to add something inamdgpu_gem_op_ioctlto re-evaluate allbo_vasof the BO when its placement changes, update thebo_va->is_xgmiflag, and if necessary thexgmi_map_counter.Regards,
FelixQuoted 208 lines
Regards
Shaoyun.liu
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Kuehling, Felix <[email protected]>
*Sent:* March 25, 2019 6:28:32 PM
*To:* Liu, Shaoyun; [email protected] *Subject:* Re: [PATCH] drm/amdgpu: XGMI pstate switch initial support I don't see any check for the memory type. As far as I can tell you'll power up XGMI even for system memory mappings. See inline.Quoted 15 lines · Shaoyun
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-)Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void
Quoted 4 lines
index ec9562d..c4c61e9 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -2018,6 +2018,10 @@ static void
amdgpu_device_ip_late_init_func_handler(struct work_struct *work)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void · line 2027
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0r = amdgpu_device_enable_mgpu_fan_boost(); if (r) DRM_ERROR("enable mgpu fan boost failed (%d).\n", r); + + /*set to low pstate by default */ + amdgpu_xgmi_set_pstate(adev, 0); + } static void amdgpu_device_delay_enable_gfx_off(struct work_struct*work)
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.hReview
Quoted 13 lines
index 220a6a7..c430e82 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -72,6 +72,8 @@ struct amdgpu_bo_va { /* If the mappings are cleared or filled */ bool cleared; + + bool is_xgmi; }; struct amdgpu_bo {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.cdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
Quoted 12 lines
index 729da1c..a7247d5 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -34,6 +34,7 @@ #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /*** DOC: GPUVM @@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct · line 2076
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0INIT_LIST_HEAD(&bo_va->valids); INIT_LIST_HEAD(&bo_va->invalids); + if (bo && amdgpu_xgmi_same_hive(adev,
amdgpu_ttm_adev(bo->tbo.bdev))) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct · line 2077
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ bo_va->is_xgmi = true;You're setting this to true even for system memory BOs that don't involve XGMI mappings. That means you'll power up XGMI unnecessarily in many cases because KFD processes always have system memory mappings that are mapped to all GPUs (e.g. the signal page).
Regards,
Felixdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15
-0+mutex_lock (&adev->vm_manager.lock_pstate); + /* Power up XGMI if it can be potentially used */ + if (++adev->vm_manager.xgmi_map_counter == 1) + amdgpu_xgmi_set_pstate(adev, 1); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + return bo_va; }@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, } dma_fence_put(bo_va->last_pt_update); + + if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); + if (--adev->vm_manager.xgmi_map_counter == 0) + amdgpu_xgmi_set_pstate(adev, 0); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + kfree(bo_va); }@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct
amdgpu_device*adev)Review
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0idr_init(&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter = 0; +mutex_init (&adev->vm_manager.lock_pstate); } /**(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.hQuoted 4 lines
index 520122b..f586b38 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm_manager { · line 333
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr; spinlock_t pasid_lock; + + /* counter of mapped memory through xgmi */ + uint32_t xgmi_map_counter; + struct mutex lock_pstate; }; #define amdgpu_vm_copy_pte(adev, ib, pe, src, count)((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.cdrivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info
Quoted 4 lines
index fcc4b05..3368347 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0@@ -200,12 +200,26 @@ struct amdgpu_hive_info*amdgpu_get_xgmi_hive(struct
amdgpu_device*adev, int loQuoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6
-1if (lock) mutex_lock(&tmp->hive_lock); - + tmp->pstate = -1; mutex_unlock(&xgmi_mutex); return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ + int ret = 0; + struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0); +drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info · line 222
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9
-0+ if (!hive) + return 0; + + if (hive->pstate == pstate) + return 0; + /* Todo : sent the message to SMU for pstate change */ + return ret; +} + int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct
amdgpu_device*adev)Review
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0{ int ret = -EINVAL;(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.hdrivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 39
Quoted 11 lines
index 24a3b03..3e9c91e 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0@@ -33,11 +33,21 @@ struct amdgpu_hive_info { struct kobject *kobj; struct device_attribute dev_attr; struct amdgpu_device *adev; + int pstate; /*0 -- low , 1 -- high , -1 unknown*/ }; struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device*adev, int lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 40
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0
-0int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct
amdgpu_device*adev);drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 53
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +9
-0int amdgpu_xgmi_add_device(struct amdgpu_device *adev); void amdgpu_xgmi_remove_device(struct amdgpu_device *adev); +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate); + +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, + struct amdgpu_device *bo_adev) +{ + return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +} #endif_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
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
The problem is that userspace could add it first and then change the domain.
Pretty unlikely thought,
Christian.
Am 26.03.19 um 14:15 schrieb Liu, Shaoyun:
Quoted 214 lines
I think in a real usage ( tensorflow ex), it's rarely only the system memory (no vram) will be mapped for peer access.
Anyway, how about addpreferred_domaincheck for xgmi ? I think even user use ioctl to change the preferred_domain,bo_addshould still be called before the real mapping.Regards
Shaoyun.liu
------------------------------------------------------------------------
*From:* amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Kuehling, Felix <[email protected]> *Sent:* March 25, 2019 6:28:32 PM
*To:* Liu, Shaoyun; [email protected]
*Subject:* Re: [PATCH] drm/amdgpu: XGMI pstate switch initial support
I don't see any check for the memory type. As far as I can tell you'll
power up XGMI even for system memory mappings. See inline.Quoted 13 lines · Shaoyun
Driver vote low to high pstate switch whenever there is an outstanding XGMI mapping request. Driver vote high to low pstate when all the outstanding XGMI mapping is terminated.
Change-Id I197501f853c47f844055c0e28c0ac00a1ff06607Signed-off-by shaoyunl <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 4 ++++drivers/gpu/drm/amd/amdgpu/amdgpu_object.h| 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 10 ++++++++++Review
Quoted 3 lines
6 files changed, 56 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void
Quoted 4 lines
index ec9562d..c4c61e9 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -2018,6 +2018,10 @@ static void
amdgpu_device_ip_late_init_func_handler(struct work_struct *work)Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0r = amdgpu_device_enable_mgpu_fan_boost(); if (r) DRM_ERROR("enable mgpu fan boost failed (%d).\n", r); + + /*set to low pstate by default */ + amdgpu_xgmi_set_pstate(adev, 0); + }static void amdgpu_device_delay_enable_gfx_off(struct
work_struct*work)
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.hReview
Quoted 13 lines
index 220a6a7..c430e82 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -72,6 +72,8 @@ struct amdgpu_bo_va { /* If the mappings are cleared or filled */ bool cleared; + + bool is_xgmi; }; struct amdgpu_bo {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.cdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
Quoted 12 lines
index 729da1c..a7247d5 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -34,6 +34,7 @@ #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" #include "amdgpu_gmc.h" +#include "amdgpu_xgmi.h" /*** DOC: GPUVM @@ -2072,6 +2073,15 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0INIT_LIST_HEAD(&bo_va->valids); INIT_LIST_HEAD(&bo_va->invalids); + if (bo && amdgpu_xgmi_same_hive(adev,
amdgpu_ttm_adev(bo->tbo.bdev))) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, · line 2077
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ bo_va->is_xgmi = true;You're setting this to true even for system memory BOs that don't involve XGMI mappings. That means you'll power up XGMI unnecessarily in many cases because KFD processes always have system memory mappings that are mapped to all GPUs (e.g. the signal page).
Regards,
Felixdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15
-0+mutex_lock (&adev->vm_manager.lock_pstate); + /* Power up XGMI if it can be potentially used */ + if (++adev->vm_manager.xgmi_map_counter == 1) + amdgpu_xgmi_set_pstate(adev, 1); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + return bo_va; }@@ -2490,6 +2500,14 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, } dma_fence_put(bo_va->last_pt_update); + + if (bo && bo_va->is_xgmi) { +mutex_lock (&adev->vm_manager.lock_pstate); + if (--adev->vm_manager.xgmi_map_counter == 0) + amdgpu_xgmi_set_pstate(adev, 0); +mutex_unlock (&adev->vm_manager.lock_pstate); + } + kfree(bo_va); }@@ -2997,6 +3015,9 @@ void amdgpu_vm_manager_init(struct
amdgpu_device*adev)Review
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0idr_init(&adev->vm_manager.pasid_idr);spin_lock_init (&adev->vm_manager.pasid_lock); + + adev->vm_manager.xgmi_map_counter = 0; +mutex_init (&adev->vm_manager.lock_pstate); } /**(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.hQuoted 4 lines
index 520122b..f586b38 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm_manager { · line 333
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -324,6 +324,10 @@ struct amdgpu_vm_manager {*/ struct idr pasid_idr; spinlock_t pasid_lock; + + /* counter of mapped memory through xgmi */ + uint32_t xgmi_map_counter; + struct mutex lock_pstate; }; #define amdgpu_vm_copy_pte(adev, ib, pe, src, count)((adev)->vm_manager.vm_pte_funcs->copy_pte((ib), (pe), (src), (count)))
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.cdrivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info
Quoted 4 lines
index fcc4b05..3368347 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0@@ -200,12 +200,26 @@ struct amdgpu_hive_info*amdgpu_get_xgmi_hive(struct
amdgpu_device*adev, int loQuoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6
-1if (lock) mutex_lock(&tmp->hive_lock); - + tmp->pstate = -1; mutex_unlock(&xgmi_mutex); return tmp; } +int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate) +{ + int ret = 0; + struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0); +drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lo
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9
-0+ if (!hive) + return 0; + + if (hive->pstate == pstate) + return 0; + /* Todo : sent the message to SMU for pstate change */ + return ret; +} + int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct
amdgpu_device*adev)Review
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0{ int ret = -EINVAL;(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.hQuoted 11 lines
index 24a3b03..3e9c91e 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0@@ -33,11 +33,21 @@ struct amdgpu_hive_info { struct kobject *kobj; struct device_attribute dev_attr; struct amdgpu_device *adev; + int pstate; /*0 -- low , 1 -- high , -1 unknown*/ };struct
amdgpu_hive_info*amdgpu_get_xgmi_hive(structamdgpu_device*adev, int lock);
Quoted 1 line
int amdgpu_xgmi_update_topology(struct
amdgpu_hive_info*hive,struct
amdgpu_device*adev);Quoted 12 lines
int
amdgpu_xgmi_add_device(struct amdgpu_device *adev); voidamdgpu_xgmi_remove_device(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +9
-0+int amdgpu_xgmi_set_pstate (struct amdgpu_device *adev,int pstate); + +static inline bool amdgpu_xgmi_same_hive (struct amdgpu_device *adev, + struct amdgpu_device *bo_adev) +{ + return (adev != bo_adev && + adev->gmc.xgmi.hive_id && + adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id); +}Quoted 1 line
#endif
_______________________________________________
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