drm/amdgpu: wrap kiq ring ops with kiq spinlock
Subsystems (2)
PATCH 1/1 drm/amdgpu: wrap kiq ring ops with kiq spinlock
KIQ ring is being operated by kfd as well as amdgpu. KFD is using kiq lock, we should the same from amdgpu side as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +11 -4
@@ -462,20 +462,25 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev) {struct amdgpu_kiq *kiq = &adev->gfx.kiq;struct amdgpu_ring *kiq_ring = &kiq->ring; -int i; +int i, r;if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; +spin_lock (&adev->gfx.kiq.ring_lock);if (amdgpu_ring_alloc (kiq_ring, kiq->pmf->unmap_queues_size * - adev->gfx.num_compute_rings)) + adev->gfx.num_compute_rings)) { +spin_unlock (&adev->gfx.kiq.ring_lock);return -ENOMEM ; + }for (i =0 ; i < adev->gfx.num_compute_rings; i++) kiq->pmf->kiq_unmap_queues (kiq_ring, &adev->gfx.compute_ring[i],RESET_QUEUES ,0 ,0 ); + r =amdgpu_ring_test_helper (kiq_ring); +spin_unlock (&adev->gfx.kiq.ring_lock); -return amdgpu_ring_test_helper (kiq_ring); +return r; } int amdgpu_queue_mask_bit_to_set_resource_bit(struct amdgpu_device *adev,
@@ -518,12 +523,13 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev)DRM_INFO ("kiq ring mec %d pipe %d q %d\n" , kiq_ring->me, kiq_ring->pipe, kiq_ring->queue); - +spin_lock (&adev->gfx.kiq.ring_lock); r =amdgpu_ring_alloc (kiq_ring, kiq->pmf->map_queues_size * adev->gfx.num_compute_rings + kiq->pmf->set_resources_size);if (r) {DRM_ERROR ("Failed to lock KIQ (%d).\n" , r); +spin_unlock (&adev->gfx.kiq.ring_lock);return r; }
@@ -532,6 +538,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev) kiq->pmf->kiq_map_queues (kiq_ring, &adev->gfx.compute_ring[i]); r =amdgpu_ring_test_helper (kiq_ring); +spin_unlock (&adev->gfx.kiq.ring_lock);if (r)DRM_ERROR ("KCQ enable failed\n" );
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 12.03.21 um 18:08 schrieb Nirmoy Das:
Quoted 5 lines
KIQ ring is being operated by kfd as well as amdgpu. KFD is using kiq lock, we should the same from amdgpu side as well.
Signed-off-by Nirmoy Das <[email protected]>
Quoted 53 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10
-4@@ -462,20 +462,25 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev) {struct amdgpu_kiq *kiq = &adev->gfx.kiq;struct amdgpu_ring *kiq_ring = &kiq->ring; -int i; +int i, r;if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; +spin_lock (&adev->gfx.kiq.ring_lock);if (amdgpu_ring_alloc (kiq_ring, kiq->pmf->unmap_queues_size * - adev->gfx.num_compute_rings)) + adev->gfx.num_compute_rings)) { +spin_unlock (&adev->gfx.kiq.ring_lock);return -ENOMEM ; + }for (i =0 ; i < adev->gfx.num_compute_rings; i++) kiq->pmf->kiq_unmap_queues (kiq_ring, &adev->gfx.compute_ring[i],RESET_QUEUES ,0 ,0 ); + r =amdgpu_ring_test_helper (kiq_ring); +spin_unlock (&adev->gfx.kiq.ring_lock); -return amdgpu_ring_test_helper (kiq_ring); +return r; } int amdgpu_queue_mask_bit_to_set_resource_bit(struct amdgpu_device *adev,@@ -518,12 +523,13 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev)DRM_INFO ("kiq ring mec %d pipe %d q %d\n" , kiq_ring->me, kiq_ring->pipe, kiq_ring->queue); - +spin_lock (&adev->gfx.kiq.ring_lock); r =amdgpu_ring_alloc (kiq_ring, kiq->pmf->map_queues_size * adev->gfx.num_compute_rings + kiq->pmf->set_resources_size);if (r) {DRM_ERROR ("Failed to lock KIQ (%d).\n" , r); +spin_unlock (&adev->gfx.kiq.ring_lock);return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev) · line 544
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-0@@ -532,6 +538,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev) kiq->pmf->kiq_map_queues (kiq_ring, &adev->gfx.compute_ring[i]); r =amdgpu_ring_test_helper (kiq_ring); +spin_unlock (&adev->gfx.kiq.ring_lock);if (r)DRM_ERROR ("KCQ enable failed\n" );
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Hi Das,
It seems more reasonable to put spin lock in ring structure, so that KIQ ring can be treated like other normal ring. 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..
thanks.
Best Regards,
Kevin
________________________________
From: amd-gfx <[email protected]> on behalf of Nirmoy Das <[email protected]>
Sent: Saturday, March 13, 2021 1:08 AM
To: Koenig, Christian <[email protected]>
Cc: Das, Nirmoy <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH 1/1] drm/amdgpu: wrap kiq ring ops with kiq spinlock
KIQ ring is being operated by kfd as well as amdgpu. KFD is using kiq lock, we should the same from amdgpu side as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +11 -4
@@ -462,20 +462,25 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev) {struct amdgpu_kiq *kiq = &adev->gfx.kiq;struct amdgpu_ring *kiq_ring = &kiq->ring; -int i; +int i, r;if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; +spin_lock (&adev->gfx.kiq.ring_lock);if (amdgpu_ring_alloc (kiq_ring, kiq->pmf->unmap_queues_size * - adev->gfx.num_compute_rings)) + adev->gfx.num_compute_rings)) { +spin_unlock (&adev->gfx.kiq.ring_lock);return -ENOMEM ; + }for (i =0 ; i < adev->gfx.num_compute_rings; i++) kiq->pmf->kiq_unmap_queues (kiq_ring, &adev->gfx.compute_ring[i],RESET_QUEUES ,0 ,0 ); + r =amdgpu_ring_test_helper (kiq_ring); +spin_unlock (&adev->gfx.kiq.ring_lock); -return amdgpu_ring_test_helper (kiq_ring); +return r; } int amdgpu_queue_mask_bit_to_set_resource_bit(struct amdgpu_device *adev,
@@ -518,12 +523,13 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev)DRM_INFO ("kiq ring mec %d pipe %d q %d\n" , kiq_ring->me, kiq_ring->pipe, kiq_ring->queue); - +spin_lock (&adev->gfx.kiq.ring_lock); r =amdgpu_ring_alloc (kiq_ring, kiq->pmf->map_queues_size * adev->gfx.num_compute_rings + kiq->pmf->set_resources_size);if (r) {DRM_ERROR ("Failed to lock KIQ (%d).\n" , r); +spin_unlock (&adev->gfx.kiq.ring_lock);return r; }
@@ -532,6 +538,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev) kiq->pmf->kiq_map_queues (kiq_ring, &adev->gfx.compute_ring[i]); r =amdgpu_ring_test_helper (kiq_ring); +spin_unlock (&adev->gfx.kiq.ring_lock);if (r)DRM_ERROR ("KCQ enable failed\n" );
--
2.30.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7CKevin1.Wang%40amd.com%7C0a90c6383d634a5226a108d8e5797c08%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637511657234189238%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=sfa27Sz8wcIyHJqaE9f8aXQMeUxbyynpAONZHUYoogY%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 7 lines · Kevin(Yang)
[AMD Official Use Only - Internal Distribution Only]
Hi Das,
It seems more reasonable to put spin lock in ring structure, so that KIQ ring can be treated like other normal ring.
We don't use locks for other rings though.
Quoted 1 line
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..
This patch is for consistency. It is not fixing any issue/bug.
Nirmoy
Quoted 85 lines
thanks.
Best Regards,
Kevin
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Nirmoy Das <[email protected]> *Sent:* Saturday, March 13, 2021 1:08 AM
*To:* Koenig, Christian <[email protected]>
*Cc:* Das, Nirmoy <[email protected]>; [email protected] <[email protected]> *Subject:* [PATCH 1/1] drm/amdgpu: wrap kiq ring ops with kiq spinlock
KIQ ring is being operated by kfd as well as amdgpu.
KFD is using kiq lock, we should the same from amdgpu side
as well.Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 15 +++++++++++----1 file changed, 11 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2
-1@@ -462,20 +462,25 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev) { struct amdgpu_kiq *kiq = &adev->gfx.kiq; struct amdgpu_ring *kiq_ring = &kiq->ring; - int i; + int i, r; if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues) return -EINVAL; + spin_lock(&adev->gfx.kiq.ring_lock);if (amdgpu_ring_alloc(kiq_ring,
kiq->pmf->unmap_queues_size*
-adev->gfx.num_compute_rings))
+adev->gfx.num_compute_rings)) {
+spin_unlock(&adev->gfx.kiq.ring_lock);
return-ENOMEM;
+ }for (i = 0; i <
adev->gfx.num_compute_rings; i++)kiq->pmf->kiq_unmap_queues(kiq_ring, &adev->gfx.compute_ring[i], RESET_QUEUES, 0, 0);
+ r =amdgpu_ring_test_helper(kiq_ring);
+spin_unlock(&adev->gfx.kiq.ring_lock);- return
amdgpu_ring_test_helper(kiq_ring);
+ return r;
}int amdgpu_queue_mask_bit_to_set_resource_bit(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-1@@ -518,12 +523,13 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev) DRM_INFO("kiq ring mec %d pipe %d q %d\n", kiq_ring->me, kiq_ring->pipe, kiq_ring->queue); - + spin_lock(&adev->gfx.kiq.ring_lock);r =
amdgpu_ring_alloc(kiq_ring, kiq->pmf->map_queues_size * adev->gfx.num_compute_rings + kiq->pmf->set_resources_size);
if (r) {
DRM_ERROR("Failed to lock KIQ (%d).\n", r);
+spin_unlock(&adev->gfx.kiq.ring_lock);
return r;
}drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-0@@ -532,6 +538,7 @@ int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev) kiq->pmf->kiq_map_queues (kiq_ring, &adev->gfx.compute_ring[i]); r = amdgpu_ring_test_helper(kiq_ring); + spin_unlock(&adev->gfx.kiq.ring_lock); if (r) DRM_ERROR("KCQ enable failed\n");Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7CKevin1.Wang%40amd.com%7C0a90c6383d634a5226a108d8e5797c08%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637511657234189238%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=sfa27Sz8wcIyHJqaE9f8aXQMeUxbyynpAONZHUYoogY%3D&reserved=0 <https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7CKevin1.Wang%40amd.com%7C0a90c6383d634a5226a108d8e5797c08%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637511657234189238%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=sfa27Sz8wcIyHJqaE9f8aXQMeUxbyynpAONZHUYoogY%3D&reserved=0>
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx