<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">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Liu, Shaoyun <Shaoyun.Liu@amd.com><br>
<b>Sent:</b> Wednesday, March 6, 2019 11:03 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> RE: [PATCH] drm/amdgpu: XGMI pstate switch initial support</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Ping<br>
<br>
-----Original Message-----<br>
From: Liu, Shaoyun <Shaoyun.Liu@amd.com> <br>
Sent: Tuesday, March 5, 2019 11:25 AM<br>
To: amd-gfx@lists.freedesktop.org<br>
Cc: Liu, Shaoyun <Shaoyun.Liu@amd.com><br>
Subject: [PATCH] drm/amdgpu: XGMI pstate switch initial support<br>
<br>
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.<br>
<br>
Change-Id: I499fb1c389077632fe9cfce4b6dc9a33deff6875<br>
Signed-off-by: shaoyunl <shaoyun.liu@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  4 ++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  3 +++  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 29 ++++++++++++++++++++++++++++-<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   | 15 +++++++++++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 ++<br>
 6 files changed, 53 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
index f0dada9..c3c8392 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
@@ -930,6 +930,10 @@ struct amdgpu_device {<br>
 <br>
         int asic_reset_res;<br>
         struct work_struct              xgmi_reset_work;<br>
+<br>
+       /* counter of mapped memory through xgmi */<br>
+       atomic_t                        xgmi_map_counter;<br>
+<br>
 };<br>
 <br>
 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
index 00def57..f28abb3 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -2008,6 +2008,9 @@ static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work)<br>
         r = amdgpu_device_enable_mgpu_fan_boost();<br>
         if (r)<br>
                 DRM_ERROR("enable mgpu fan boost failed (%d).\n", r);<br>
+<br>
+       /*set to low pstate by default */<br>
+       amdgpu_xgmi_set_pstate(adev, 0);<br>
 }<br>
 <br>
 static void amdgpu_device_delay_enable_gfx_off(struct work_struct *work) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
index 220a6a7..6f176bb 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
@@ -54,6 +54,7 @@ struct amdgpu_bo_va_mapping {<br>
         uint64_t                        __subtree_last;<br>
         uint64_t                        offset;<br>
         uint64_t                        flags;<br>
+       bool                            is_xgmi;<br>
 };<br>
 <br>
 /* User space allocated BO in a VM */<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
index c0f315b..5765761 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
@@ -34,6 +34,7 @@<br>
 #include "amdgpu_trace.h"<br>
 #include "amdgpu_amdkfd.h"<br>
 #include "amdgpu_gmc.h"<br>
+#include "amdgpu_xgmi.h"<br>
 <br>
 /**<br>
  * DOC: GPUVM<br>
@@ -2013,8 +2014,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,<br>
         struct ttm_mem_reg *mem;<br>
         struct drm_mm_node *nodes;<br>
         struct dma_fence *exclusive, **last_update;<br>
-       uint64_t flags;<br>
         struct amdgpu_device *bo_adev = adev;<br>
+       bool is_xgmi = false;<br>
+       uint64_t flags;<br>
         int r;<br>
 <br>
         if (clear || !bo) {<br>
@@ -2036,6 +2038,10 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,<br>
         if (bo) {<br>
                 flags = amdgpu_ttm_tt_pte_flags(adev, bo->tbo.ttm, mem);<br>
                 bo_adev = amdgpu_ttm_adev(bo->tbo.bdev);<br>
+               if (adev != bo_adev &&<br>
+                   adev->gmc.xgmi.hive_id &&<br>
+                   adev->gmc.xgmi.hive_id == bo_adev->gmc.xgmi.hive_id)<br>
+                       is_xgmi = true;<br>
         } else {<br>
                 flags = 0x0;<br>
         }<br>
@@ -2054,6 +2060,19 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,<br>
         }<br>
 <br>
         list_for_each_entry(mapping, &bo_va->invalids, list) {<br>
+               if (mapping->is_xgmi != is_xgmi) {<br>
+                       if (is_xgmi) {<br>
+                               /* Adding an XGMI mapping to the PT */<br>
+                               if (atomic_inc_return(&adev->xgmi_map_counter) == 1)<br>
+                                       amdgpu_xgmi_set_pstate(adev, 1);<br>
+                       } else {<br>
+                               /* Removing an XGMI mapping from the PT */<br>
+                               if (atomic_dec_return(&adev->xgmi_map_counter) == 0)<br>
+                                       amdgpu_xgmi_set_pstate(adev, 0);<br>
+                       }<br>
+                       mapping->is_xgmi = is_xgmi;<br>
+               }<br>
+<br>
                 r = amdgpu_vm_bo_split_mapping(adev, exclusive, pages_addr, vm,<br>
                                                mapping, flags, bo_adev, nodes,<br>
                                                last_update);<br>
@@ -2271,6 +2290,13 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,<br>
                 r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,<br>
                                                 mapping->start, mapping->last,<br>
                                                 init_pte_value, 0, &f);<br>
+<br>
+               if (mapping->is_xgmi) {<br>
+                       /* Removing an XGMI mapping from the PT */<br>
+                       if (atomic_dec_return(&adev->xgmi_map_counter) == 0)<br>
+                               amdgpu_xgmi_set_pstate(adev, 0);<br>
+               }<br>
+<br>
                 amdgpu_vm_free_mapping(adev, vm, mapping, f);<br>
                 if (r) {<br>
                         dma_fence_put(f);<br>
@@ -2467,6 +2493,7 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,<br>
         mapping->last = eaddr;<br>
         mapping->offset = offset;<br>
         mapping->flags = flags;<br>
+       mapping->is_xgmi = false;<br>
 <br>
         amdgpu_vm_bo_insert_map(adev, bo_va, mapping);<br>
 <br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c<br>
index 407dd16c..cb403cf 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c<br>
@@ -72,6 +72,7 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lo<br>
         mutex_init(&tmp->reset_lock);<br>
         if (lock)<br>
                 mutex_lock(&tmp->hive_lock);<br>
+       tmp->pstate = -1;<br>
 <br>
         mutex_unlock(&xgmi_mutex);<br>
 <br>
@@ -182,3 +183,17 @@ void amdgpu_xgmi_remove_device(struct amdgpu_device *adev)<br>
                 mutex_unlock(&hive->hive_lock);<br>
         }<br>
 }<br>
+<br>
+int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate) {<br>
+       int ret = 0;<br>
+       struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0);<br>
+<br>
+       if (!hive)<br>
+               return 0;<br>
+<br>
+       if (hive->pstate == pstate)<br>
+               return 0;<br>
+       /* Todo : sent the message to SMU for pstate change */<br>
+       return ret;<br>
+}<br>
\ No newline at end of file<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h<br>
index 14bc606..6859702 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h<br>
@@ -31,11 +31,13 @@ struct amdgpu_hive_info {<br>
         int number_devices;<br>
         struct mutex hive_lock,<br>
                      reset_lock;<br>
+       int pstate; /*0 -- low , 1 -- high , -1 unknown*/<br>
 };<br>
 <br>
 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);<br>
+int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate);<br>
 <br>
 #endif<br>
--<br>
2.7.4<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></div>
</span></font></div>
</body>
</html>