Skip to contentSkip to conversation

drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

PATCH In review [email protected] 4 participants 7 messages Oct 18, 2024 – Nov 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

compute/gfx may have multiple rings on some hardware.
In some cases, userspace wants to run jobs on a specific ring for validation purposes. This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the gfx/compute ip.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c     | 142 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h     |   2 +
 3 files changed, 146 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -0
index 37d8657f0776..6e3f657cab9c 100644
@@ -2096,6 +2096,8 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 		amdgpu_debugfs_umsch_fwlog_init(adev, &adev->umsch_mm);
 
 	amdgpu_debugfs_jpeg_sched_mask_init(adev);
+	amdgpu_debugfs_gfx_sched_mask_init(adev);
+	amdgpu_debugfs_compute_sched_mask_init(adev);
 
 	amdgpu_ras_debugfs_create_all(adev);
 	amdgpu_rap_debugfs_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +142 -0

145 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
index f710178a21bc..9275c02c94c6 100644
@@ -582,6 +582,8 @@ void amdgpu_gfx_sysfs_isolation_shader_fini(struct amdgpu_device *adev);
 void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);
 void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);
 void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
 {
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 drm/amdgpu: add amdgpu_sdma_sched_mask debugfs

Userspace wants to run jobs on a specific sdma ring for verification purposes. This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the sdma ip.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c    | 71 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h    |  2 +-
 3 files changed, 73 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -0
index 6e3f657cab9c..c446bfccea59 100644
@@ -2098,6 +2098,7 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
 	amdgpu_debugfs_jpeg_sched_mask_init(adev);
 	amdgpu_debugfs_gfx_sched_mask_init(adev);
 	amdgpu_debugfs_compute_sched_mask_init(adev);
+	amdgpu_debugfs_sdma_sched_mask_init(adev);
 
 	amdgpu_ras_debugfs_create_all(adev);
 	amdgpu_rap_debugfs_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +71 -0

74 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1 -1
index 087ce0f6fa07..a37fcd9bb981 100644
@@ -175,5 +175,5 @@ int amdgpu_sdma_init_microcode(struct amdgpu_device *adev, u32 instance,
 void amdgpu_sdma_destroy_inst_ctx(struct amdgpu_device *adev,
         bool duplicate);
 int amdgpu_sdma_ras_sw_init(struct amdgpu_device *adev);
-
+void amdgpu_debugfs_sdma_sched_mask_init(struct amdgpu_device *adev);
 #endif
Signature · 1 line
2.25.1
#2 lore raw
In reply to [email protected]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping on this series?

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, October 18, 2024 10:31 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

compute/gfx may have multiple rings on some hardware.
In some cases, userspace wants to run jobs on a specific ring for validation purposes. This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the gfx/compute ip.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c     | 142 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h     |   2 +
 3 files changed, 146 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -0
index 37d8657f0776..6e3f657cab9c 100644
@@ -2096,6 +2096,8 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
                amdgpu_debugfs_umsch_fwlog_init(adev, &adev->umsch_mm);
 
        amdgpu_debugfs_jpeg_sched_mask_init(adev);
+       amdgpu_debugfs_gfx_sched_mask_init(adev);
+       amdgpu_debugfs_compute_sched_mask_init(adev);
 
        amdgpu_ras_debugfs_create_all(adev);
        amdgpu_rap_debugfs_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +137 -0

140 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
index f710178a21bc..9275c02c94c6 100644
@@ -582,6 +582,8 @@ void amdgpu_gfx_sysfs_isolation_shader_fini(struct amdgpu_device *adev);  void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work);  void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring);  void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device
+*adev);
 
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)  {
--

2.25.1

#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 72 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhang, Jesse(Jie)
Sent: Tuesday, October 22, 2024 11:12 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping on this series?

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, October 18, 2024 10:31 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

compute/gfx may have multiple rings on some hardware.
In some cases, userspace wants to run jobs on a specific ring for validation purposes.
This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the gfx/compute ip.

Deucher <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c     | 142 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h     |   2 +
 3 files changed, 146 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -0
index 37d8657f0776..6e3f657cab9c 100644
@@ -2096,6 +2096,8 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
                amdgpu_debugfs_umsch_fwlog_init(adev, &adev->umsch_mm);
 
        amdgpu_debugfs_jpeg_sched_mask_init(adev);
+       amdgpu_debugfs_gfx_sched_mask_init(adev);
+       amdgpu_debugfs_compute_sched_mask_init(adev);
 
        amdgpu_ras_debugfs_create_all(adev);
        amdgpu_rap_debugfs_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +7 -0
index b6acbe923b6b..29997c9f68b6 100644
@@ -1868,3 +1868,145 @@ void
 amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
        }
        mutex_unlock(&adev->enforce_isolation_mutex);
 }
+
+/*
+ * debugfs for to enable/disable gfx job submission to specific core.
+ */
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_debugfs_gfx_sched_mask_set(void *data, u64 val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void · line 1887

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+
+       mask = (1 << adev->gfx.num_gfx_rings) - 1;
+       if ((val & mask) == 0)
+               return -EINVAL;

Is this check used to prevent all the rings unscheduled?

Thanks,
Jiadong

Quoted 138 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +100 -0
+       for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
+               ring = &adev->gfx.gfx_ring[i];
+               if (val & (1 << i))
+                       ring->sched.ready = true;
+               else
+                       ring->sched.ready = false;
+       }
+       /* publish sched.ready flag update effective immediately across smp */
+       smp_rmb();
+       return 0;
+}
+
+static int amdgpu_debugfs_gfx_sched_mask_get(void *data, u64 *val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+       for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
+               ring = &adev->gfx.gfx_ring[i];
+               if (ring->sched.ready)
+                       mask |= 1 << i;
+       }
+
+       *val = mask;
+       return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gfx_sched_mask_fops,
+                        amdgpu_debugfs_gfx_sched_mask_get,
+                        amdgpu_debugfs_gfx_sched_mask_set, "%llx\n");
+
+#endif
+
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev) {
+#if defined(CONFIG_DEBUG_FS)
+       struct drm_minor *minor = adev_to_drm(adev)->primary;
+       struct dentry *root = minor->debugfs_root;
+       char name[32];
+
+       if (!(adev->gfx.num_gfx_rings > 1))
+               return;
+       sprintf(name, "amdgpu_gfx_sched_mask");
+       debugfs_create_file(name, 0600, root, adev,
+                           &amdgpu_debugfs_gfx_sched_mask_fops);
+#endif
+}
+
+/*
+ * debugfs for to enable/disable compute job submission to specific core.
+ */
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_debugfs_compute_sched_mask_set(void *data, u64 val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+
+       mask = (1 << adev->gfx.num_compute_rings) - 1;
+       if ((val & mask) == 0)
+               return -EINVAL;
+
+       for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
+               ring = &adev->gfx.compute_ring[i];
+               if (val & (1 << i))
+                       ring->sched.ready = true;
+               else
+                       ring->sched.ready = false;
+       }
+
+       /* publish sched.ready flag update effective immediately across smp */
+       smp_rmb();
+       return 0;
+}
+
+static int amdgpu_debugfs_compute_sched_mask_get(void *data, u64 *val)
+{
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+       for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
+               ring = &adev->gfx.compute_ring[i];
+               if (ring->sched.ready)
+                       mask |= 1 << i;
+       }
+
+       *val = mask;
+       return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_compute_sched_mask_fop

s,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +20 -0
+                        amdgpu_debugfs_compute_sched_mask_get,
+                        amdgpu_debugfs_compute_sched_mask_set,
+"%llx\n");
+
+#endif
+
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev)
+{ #if defined(CONFIG_DEBUG_FS)
+       struct drm_minor *minor = adev_to_drm(adev)->primary;
+       struct dentry *root = minor->debugfs_root;
+       char name[32];
+
+       if (!(adev->gfx.num_compute_rings > 1))
+               return;
+       sprintf(name, "amdgpu_compute_sched_mask");
+       debugfs_create_file(name, 0600, root, adev,
+                           &amdgpu_debugfs_compute_sched_mask_fops);
+#endif
+}
+
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f710178a21bc..9275c02c94c6 100644
@@ -582,6 +582,8 @@ void amdgpu_gfx_sysfs_isolation_shader_fini(struct

amdgpu_device *adev); void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work); void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring); void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device
+*adev);
 
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)  {
--

2.25.1

#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Jiadong,

-----Original Message-----
From: Zhu, Jiadong <[email protected]>
Sent: Wednesday, October 23, 2024 11:10 AM
To: Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 75 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhang,
Jesse(Jie)
Sent: Tuesday, October 22, 2024 11:12 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping on this series?

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, October 18, 2024 10:31 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

compute/gfx may have multiple rings on some hardware.
In some cases, userspace wants to run jobs on a specific ring for validation purposes.
This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the gfx/compute ip.

Deucher <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c     | 142 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h     |   2 +
 3 files changed, 146 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -0
index 37d8657f0776..6e3f657cab9c 100644
@@ -2096,6 +2096,8 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)
                amdgpu_debugfs_umsch_fwlog_init(adev,
 &adev->umsch_mm);
 
        amdgpu_debugfs_jpeg_sched_mask_init(adev);
+       amdgpu_debugfs_gfx_sched_mask_init(adev);
+       amdgpu_debugfs_compute_sched_mask_init(adev);
 
        amdgpu_ras_debugfs_create_all(adev);
        amdgpu_rap_debugfs_init(adev); diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index b6acbe923b6b..29997c9f68b6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +7 -0
@@ -1868,3 +1868,145 @@ void
 amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
        }
        mutex_unlock(&adev->enforce_isolation_mutex);
 }
+
+/*
+ * debugfs for to enable/disable gfx job submission to specific core.
+ */
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_debugfs_gfx_sched_mask_set(void *data, u64 val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void · line 1887

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+
+       mask = (1 << adev->gfx.num_gfx_rings) - 1;
+       if ((val & mask) == 0)
+               return -EINVAL;

Is this check used to prevent all the rings unscheduled? Yes, we must keep a ring available.

Regards
Jesse

Thanks,
Jiadong

Quoted 141 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +100 -0
+       for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
+               ring = &adev->gfx.gfx_ring[i];
+               if (val & (1 << i))
+                       ring->sched.ready = true;
+               else
+                       ring->sched.ready = false;
+       }
+       /* publish sched.ready flag update effective immediately across smp */
+       smp_rmb();
+       return 0;
+}
+
+static int amdgpu_debugfs_gfx_sched_mask_get(void *data, u64 *val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+       for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
+               ring = &adev->gfx.gfx_ring[i];
+               if (ring->sched.ready)
+                       mask |= 1 << i;
+       }
+
+       *val = mask;
+       return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gfx_sched_mask_fops,
+                        amdgpu_debugfs_gfx_sched_mask_get,
+                        amdgpu_debugfs_gfx_sched_mask_set, "%llx\n");
+
+#endif
+
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev) {
+#if defined(CONFIG_DEBUG_FS)
+       struct drm_minor *minor = adev_to_drm(adev)->primary;
+       struct dentry *root = minor->debugfs_root;
+       char name[32];
+
+       if (!(adev->gfx.num_gfx_rings > 1))
+               return;
+       sprintf(name, "amdgpu_gfx_sched_mask");
+       debugfs_create_file(name, 0600, root, adev,
+                           &amdgpu_debugfs_gfx_sched_mask_fops);
+#endif
+}
+
+/*
+ * debugfs for to enable/disable compute job submission to specific core.
+ */
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_debugfs_compute_sched_mask_set(void *data, u64 val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+
+       mask = (1 << adev->gfx.num_compute_rings) - 1;
+       if ((val & mask) == 0)
+               return -EINVAL;
+
+       for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
+               ring = &adev->gfx.compute_ring[i];
+               if (val & (1 << i))
+                       ring->sched.ready = true;
+               else
+                       ring->sched.ready = false;
+       }
+
+       /* publish sched.ready flag update effective immediately across smp */
+       smp_rmb();
+       return 0;
+}
+
+static int amdgpu_debugfs_compute_sched_mask_get(void *data, u64
+*val) {
+       struct amdgpu_device *adev = (struct amdgpu_device *)data;
+       u32 i;
+       u64 mask = 0;
+       struct amdgpu_ring *ring;
+
+       if (!adev)
+               return -ENODEV;
+       for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
+               ring = &adev->gfx.compute_ring[i];
+               if (ring->sched.ready)
+                       mask |= 1 << i;
+       }
+
+       *val = mask;
+       return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_compute_sched_mask_fop

s,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +20 -0
+                        amdgpu_debugfs_compute_sched_mask_get,
+                        amdgpu_debugfs_compute_sched_mask_set,
+"%llx\n");
+
+#endif
+
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device
+*adev) { #if defined(CONFIG_DEBUG_FS)
+       struct drm_minor *minor = adev_to_drm(adev)->primary;
+       struct dentry *root = minor->debugfs_root;
+       char name[32];
+
+       if (!(adev->gfx.num_compute_rings > 1))
+               return;
+       sprintf(name, "amdgpu_compute_sched_mask");
+       debugfs_create_file(name, 0600, root, adev,
+                           &amdgpu_debugfs_compute_sched_mask_fops);
+#endif
+}
+
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f710178a21bc..9275c02c94c6 100644
@@ -582,6 +582,8 @@ void amdgpu_gfx_sysfs_isolation_shader_fini(struct

amdgpu_device *adev); void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work); void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring); void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device
+*adev);
 
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)  {
--

2.25.1

Reviewed-by on v1 1/2
#5 lore raw
In reply to [email protected]

[Public]

Hi Jesse,

Quoted 104 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of [email protected]
Sent: Friday, October 18, 2024 10:31 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs

compute/gfx may have multiple rings on some hardware.
In some cases, userspace wants to run jobs on a specific ring for validation purposes.
This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the gfx/compute ip.

Deucher <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c     | 142
++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h     |   2 +
 3 files changed, 146 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -0
index 37d8657f0776..6e3f657cab9c 100644
@@ -2096,6 +2096,8 @@ int amdgpu_debugfs_init(struct amdgpu_device
 *adev)
              amdgpu_debugfs_umsch_fwlog_init(adev, &adev->umsch_mm);
 
      amdgpu_debugfs_jpeg_sched_mask_init(adev);
+     amdgpu_debugfs_gfx_sched_mask_init(adev);
+     amdgpu_debugfs_compute_sched_mask_init(adev);
 
      amdgpu_ras_debugfs_create_all(adev);
      amdgpu_rap_debugfs_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +53 -0
index b6acbe923b6b..29997c9f68b6 100644
@@ -1868,3 +1868,145 @@ void
 amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring)
      }
      mutex_unlock(&adev->enforce_isolation_mutex);
 }
+
+/*
+ * debugfs for to enable/disable gfx job submission to specific core.
+ */
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_debugfs_gfx_sched_mask_set(void *data, u64 val) {
+     struct amdgpu_device *adev = (struct amdgpu_device *)data;
+     u32 i;
+     u64 mask = 0;
+     struct amdgpu_ring *ring;
+
+     if (!adev)
+             return -ENODEV;
+
+     mask = (1 << adev->gfx.num_gfx_rings) - 1;
+     if ((val & mask) == 0)
+             return -EINVAL;
+
+     for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
+             ring = &adev->gfx.gfx_ring[i];
+             if (val & (1 << i))
+                     ring->sched.ready = true;
+             else
+                     ring->sched.ready = false;
+     }
+     /* publish sched.ready flag update effective immediately across smp */
+     smp_rmb();
+     return 0;
+}
+
+static int amdgpu_debugfs_gfx_sched_mask_get(void *data, u64 *val) {
+     struct amdgpu_device *adev = (struct amdgpu_device *)data;
+     u32 i;
+     u64 mask = 0;
+     struct amdgpu_ring *ring;
+
+     if (!adev)
+             return -ENODEV;
+     for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
+             ring = &adev->gfx.gfx_ring[i];
+             if (ring->sched.ready)
+                     mask |= 1 << i;
+     }
+
+     *val = mask;
+     return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gfx_sched_mask_fops,
+                      amdgpu_debugfs_gfx_sched_mask_get,
+                      amdgpu_debugfs_gfx_sched_mask_set, "%llx\n");
+
+#endif

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void · line 1936

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev) {
+#if defined(CONFIG_DEBUG_FS)
+     struct drm_minor *minor = adev_to_drm(adev)->primary;
+     struct dentry *root = minor->debugfs_root;
+     char name[32];
+
+     if (!(adev->gfx.num_gfx_rings > 1))
+             return;
+     sprintf(name, "amdgpu_gfx_sched_mask");

I recommend using the literal string 'amdgpu_gfx_sched_mask' as the argument for debugfs_create_file instead of a variable name. The same applies to the other instances.

With or without this change,
This series are,

Best Regards,
Tim

Quoted 93 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +55 -0
+     debugfs_create_file(name, 0600, root, adev,
+                         &amdgpu_debugfs_gfx_sched_mask_fops);
+#endif
+}
+
+/*
+ * debugfs for to enable/disable compute job submission to specific core.
+ */
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_debugfs_compute_sched_mask_set(void *data, u64 val) {
+     struct amdgpu_device *adev = (struct amdgpu_device *)data;
+     u32 i;
+     u64 mask = 0;
+     struct amdgpu_ring *ring;
+
+     if (!adev)
+             return -ENODEV;
+
+     mask = (1 << adev->gfx.num_compute_rings) - 1;
+     if ((val & mask) == 0)
+             return -EINVAL;
+
+     for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
+             ring = &adev->gfx.compute_ring[i];
+             if (val & (1 << i))
+                     ring->sched.ready = true;
+             else
+                     ring->sched.ready = false;
+     }
+
+     /* publish sched.ready flag update effective immediately across smp */
+     smp_rmb();
+     return 0;
+}
+
+static int amdgpu_debugfs_compute_sched_mask_get(void *data, u64 *val)
+{
+     struct amdgpu_device *adev = (struct amdgpu_device *)data;
+     u32 i;
+     u64 mask = 0;
+     struct amdgpu_ring *ring;
+
+     if (!adev)
+             return -ENODEV;
+     for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
+             ring = &adev->gfx.compute_ring[i];
+             if (ring->sched.ready)
+                     mask |= 1 << i;
+     }
+
+     *val = mask;
+     return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_compute_sched_mask_fops

,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +6 -0
+                      amdgpu_debugfs_compute_sched_mask_get,
+                      amdgpu_debugfs_compute_sched_mask_set, "%llx\n");
+
+#endif
+
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +13 -0
+{ #if defined(CONFIG_DEBUG_FS)
+     struct drm_minor *minor = adev_to_drm(adev)->primary;
+     struct dentry *root = minor->debugfs_root;
+     char name[32];
+
+     if (!(adev->gfx.num_compute_rings > 1))
+             return;
+     sprintf(name, "amdgpu_compute_sched_mask");
+     debugfs_create_file(name, 0600, root, adev,
+                         &amdgpu_debugfs_compute_sched_mask_fops);
+#endif
+}
+
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f710178a21bc..9275c02c94c6 100644
@@ -582,6 +582,8 @@ void amdgpu_gfx_sysfs_isolation_shader_fini(struct

amdgpu_device *adev); void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work); void amdgpu_gfx_enforce_isolation_ring_begin_use(struct amdgpu_ring *ring); void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
+void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device
+*adev);
 
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)  {
--

2.25.1

#6 lore raw
In reply to [email protected]

Op 18-10-2024 om 04:30 schreef jesse.zhang at amd.com ([email protected]):

Quoted 20 lines

compute/gfx may have multiple rings on some hardware.
In some cases, userspace wants to run jobs on a specific ring for validation purposes. This debugfs entry helps to disable or enable submitting jobs to a specific ring. This entry is populated only if there are at least two or more cores in the gfx/compute ip.

Signed-off-by Jesse Zhang <jesse.zhang at amd.com>
Suggested-by Alex Deucher <alexander.deucher at amd.com>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c     | 142 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h     |   2 +
  3 files changed, 146 insertions(+)

[...]

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +5 -0
+
+void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev)
+{
+#if defined(CONFIG_DEBUG_FS)
+	struct drm_minor *minor = adev_to_drm(adev)->primary;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_enforce_isolation_ring_end_use(struct amdgpu_ring *ring) · line 2011

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+	struct dentry *root = minor->debugfs_root;
+	char name[32];
+
+	if (!(adev->gfx.num_compute_rings > 1))
+		return;
+	sprintf(name, "amdgpu_compute_sched_mask");
+	debugfs_create_file(name, 0600, root, adev,
+			    &amdgpu_debugfs_compute_sched_mask_fops);
+#endif
+}

Hi Jesse,

Can you please eliminate name[32]? There is absolutely no need to copy the filename in a buffer. Also, using sprintf this way is weird too.

Just do
    debugfs_create_file("amdgpu_compute_sched_mask", 0600, root, adev, ...

The same for amdgpu_debugfs_gfx_sched_mask_init() of course.

Signature · 1 line
Kees