<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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:11pt;color:#0078D7;margin:5pt;" 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);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Hi Das,</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">It seems more reasonable
 to put spin lock in ring structure, so that KIQ ring can be treated like other normal ring.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
</div>
<div><span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">and do we have other
 paths to call kiq ring except for kernel initialization? it seems the kfd and kgd will use kiq in one thread..</span></div>
<div><br>
</div>
<div><span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">thanks.</span></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);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Best Regards,</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 12pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Kevin</span></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Nirmoy Das <nirmoy.das@amd.com><br>
<b>Sent:</b> Saturday, March 13, 2021 1:08 AM<br>
<b>To:</b> Koenig, Christian <Christian.Koenig@amd.com><br>
<b>Cc:</b> Das, Nirmoy <Nirmoy.Das@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> [PATCH 1/1] drm/amdgpu: wrap kiq ring ops with kiq spinlock</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">KIQ ring is being operated by kfd as well as amdgpu.<br>
KFD is using kiq lock, we should the same from amdgpu side<br>
as well.<br>
<br>
Signed-off-by: Nirmoy Das <nirmoy.das@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 15 +++++++++++----<br>
 1 file changed, 11 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
index 1915b9b95106..892dc6b269fb 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
@@ -462,20 +462,25 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev)<br>
 {<br>
         struct amdgpu_kiq *kiq = &adev->gfx.kiq;<br>
         struct amdgpu_ring *kiq_ring = &kiq->ring;<br>
-       int i;<br>
+       int i, r;<br>
 <br>
         if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)<br>
                 return -EINVAL;<br>
 <br>
+       spin_lock(&adev->gfx.kiq.ring_lock);<br>
         if (amdgpu_ring_alloc(kiq_ring, kiq->pmf->unmap_queues_size *<br>
-                                       adev->gfx.num_compute_rings))<br>
+                                       adev->gfx.num_compute_rings)) {<br>
+               spin_unlock(&adev->gfx.kiq.ring_lock);<br>
                 return -ENOMEM;<br>
+       }<br>
 <br>
         for (i = 0; i < adev->gfx.num_compute_rings; i++)<br>
                 kiq->pmf->kiq_unmap_queues(kiq_ring, &adev->gfx.compute_ring[i],<br>
                                            RESET_QUEUES, 0, 0);<br>
+       r = amdgpu_ring_test_helper(kiq_ring);<br>
+       spin_unlock(&adev->gfx.kiq.ring_lock);<br>
 <br>
-       return amdgpu_ring_test_helper(kiq_ring);<br>
+       return r;<br>
 }<br>
 <br>
 int amdgpu_queue_mask_bit_to_set_resource_bit(struct amdgpu_device *adev,<br>
@@ -518,12 +523,13 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev)<br>
 <br>
         DRM_INFO("kiq ring mec %d pipe %d q %d\n", kiq_ring->me, kiq_ring->pipe,<br>
                                                         kiq_ring->queue);<br>
-<br>
+       spin_lock(&adev->gfx.kiq.ring_lock);<br>
         r = amdgpu_ring_alloc(kiq_ring, kiq->pmf->map_queues_size *<br>
                                         adev->gfx.num_compute_rings +<br>
                                         kiq->pmf->set_resources_size);<br>
         if (r) {<br>
                 DRM_ERROR("Failed to lock KIQ (%d).\n", r);<br>
+               spin_unlock(&adev->gfx.kiq.ring_lock);<br>
                 return r;<br>
         }<br>
 <br>
@@ -532,6 +538,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev)<br>
                 kiq->pmf->kiq_map_queues(kiq_ring, &adev->gfx.compute_ring[i]);<br>
 <br>
         r = amdgpu_ring_test_helper(kiq_ring);<br>
+       spin_unlock(&adev->gfx.kiq.ring_lock);<br>
         if (r)<br>
                 DRM_ERROR("KCQ enable failed\n");<br>
 <br>
-- <br>
2.30.1<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&amp;data=04%7C01%7CKevin1.Wang%40amd.com%7C0a90c6383d634a5226a108d8e5797c08%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637511657234189238%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=sfa27Sz8wcIyHJqaE9f8aXQMeUxbyynpAONZHUYoogY%3D&amp;reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CKevin1.Wang%40amd.com%7C0a90c6383d634a5226a108d8e5797c08%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637511657234189238%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=sfa27Sz8wcIyHJqaE9f8aXQMeUxbyynpAONZHUYoogY%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>