Skip to contentSkip to conversation

drm/amdkfd: add an interface to query whether is KFD is active

PATCH In review Alex Deucher 2 participants 3 messages Oct 28, 2024

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdkfd: add an interface to query whether is KFD is active

Add an interface to query whether KFD has any active queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  9 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  7 ++++++
 drivers/gpu/drm/amd/amdkfd/kfd_device.c    | 25 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  1 +
 4 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -0
index b545940e512b..82f1c6a19d79 100644
@@ -890,6 +890,15 @@ int amdgpu_amdkfd_start_sched(struct amdgpu_device *adev, uint32_t node_id)
 	return kgd2kfd_start_sched(adev->kfd.dev, node_id);
 }
 
+/* check if there are KFD queues active */
+bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id)
+{
+	if (!adev->kfd.init_complete)
+		return 0;
+
+	return kgd2kfd_compute_active(adev->kfd.dev, node_id);
+}
+
 /* Config CGTT_SQ_CLK_CTRL */
 int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,
 	bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +7 -0
index 7e0a22072536..f47f4555437b 100644
@@ -268,6 +268,7 @@ int amdgpu_amdkfd_start_sched(struct amdgpu_device *adev, uint32_t node_id);
 int amdgpu_amdkfd_stop_sched(struct amdgpu_device *adev, uint32_t node_id);
 int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,
 	bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable);
+bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id);
 
 
 /* Read user wptr from a specified user address space with page fault
@@ -431,6 +432,7 @@ int kgd2kfd_check_and_lock_kfd(void);
 void kgd2kfd_unlock_kfd(void);
 int kgd2kfd_start_sched(struct kfd_dev *kfd, uint32_t node_id);
 int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id);
+bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id);
 #else
 static inline int kgd2kfd_init(void)
 {
@@ -511,5 +513,10 @@ static inline int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id)
 {
 	return 0;
 }
+
+bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id)
+{
+	return false;
+}
 #endif
 #endif /* AMDGPU_AMDKFD_H_INCLUDED */
drivers/gpu/drm/amd/amdkfd/kfd_device.c +25 -0
index b1ce73c7a9ab..9d8bdead6e65 100644
@@ -1404,6 +1404,13 @@ void kfd_dec_compute_active(struct kfd_node *node)
 	WARN_ONCE(count < 0, "Compute profile ref. count error");
 }
 
+bool kfd_compute_active(struct kfd_node *node)
+{
+	if (atomic_read(&node->kfd->compute_profile))
+		return true;
+	return false;
+}
+
 void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, uint64_t throttle_bitmask)
 {
 	/*
@@ -1497,6 +1504,24 @@ int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id)
 	return node->dqm->ops.halt(node->dqm);
 }
 
+bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id)
+{
+	struct kfd_node *node;
+
+	if (!kfd->init_complete)
+		return false;
+
+	if (node_id >= kfd->num_nodes) {
+		dev_warn(kfd->adev->dev, "Invalid node ID: %u exceeds %u\n",
+			 node_id, kfd->num_nodes - 1);
+		return false;
+	}
+
+	node = kfd->nodes[node_id];
+
+	return kfd_compute_active(node);
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 /* This function will send a package to HIQ to hang the HWS
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
index 9e5ca0b93b2a..f9140fdb8132 100644
@@ -1518,6 +1518,7 @@ bool kfd_is_locked(void);
 /* Compute profile */
 void kfd_inc_compute_active(struct kfd_node *dev);
 void kfd_dec_compute_active(struct kfd_node *dev);
+bool kfd_compute_active(struct kfd_node *dev);
 
 /* Cgroup Support */
 /* Check with device cgroup if @kfd device is accessible */
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH 2/2 drm/amdgpu: fix fairness in enforce isolation handling

Make sure KFD gets a turn when serializing access to the GC IP. Currently non-KFD jobs can starve KFD if they submit often enough. This patch prevents that by stalling non-KFD if its time period has elapsed.

v2: fix units
v3: check enablement properly

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 53 ++++++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  2 +
 3 files changed, 54 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
index ab5524b7a259..2f381848c849 100644
@@ -119,7 +119,7 @@
 
 #define MAX_GPU_INSTANCE		64
 
-#define GFX_SLICE_PERIOD		msecs_to_jiffies(250)
+#define GFX_SLICE_PERIOD_MS		250
 
 struct amdgpu_gpu_instance {
 	struct amdgpu_device		*adev;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +51 -2

78 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
index f710178a21bc..af9dbd760fee 100644
@@ -472,6 +472,8 @@ struct amdgpu_gfx {
 	struct mutex                    kfd_sch_mutex;
 	u64				kfd_sch_req_count[MAX_XCP];
 	bool				kfd_sch_inactive[MAX_XCP];
+	unsigned long			enforce_isolation_jiffies[MAX_XCP];
+	unsigned long			enforce_isolation_time[MAX_XCP];
 };
 
 struct amdgpu_gfx_ras_reg_entry {
Signature · 1 line
2.47.0
Acked-by on v1 1/2
#2 lore raw
In reply to Alex Deucher

The series is:

Quoted 116 lines · Alex Deucher

Add an interface to query whether KFD has any active queues.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  9 ++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  7 ++++++
  drivers/gpu/drm/amd/amdkfd/kfd_device.c    | 25 ++++++++++++++++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  1 +
  4 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -0
index b545940e512b..82f1c6a19d79 100644
@@ -890,6 +890,15 @@ int amdgpu_amdkfd_start_sched(struct amdgpu_device *adev, uint32_t node_id)
  	return kgd2kfd_start_sched(adev->kfd.dev, node_id);
  }
 
+/* check if there are KFD queues active */
+bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id)
+{
+	if (!adev->kfd.init_complete)
+		return 0;
+
+	return kgd2kfd_compute_active(adev->kfd.dev, node_id);
+}
+
  /* Config CGTT_SQ_CLK_CTRL */
  int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,
  	bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +7 -0
index 7e0a22072536..f47f4555437b 100644
@@ -268,6 +268,7 @@ int amdgpu_amdkfd_start_sched(struct amdgpu_device *adev, uint32_t node_id);
  int amdgpu_amdkfd_stop_sched(struct amdgpu_device *adev, uint32_t node_id);
  int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,
  	bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable);
+bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id);
 
 
  /* Read user wptr from a specified user address space with page fault
@@ -431,6 +432,7 @@ int kgd2kfd_check_and_lock_kfd(void);
  void kgd2kfd_unlock_kfd(void);
  int kgd2kfd_start_sched(struct kfd_dev *kfd, uint32_t node_id);
  int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id);
+bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id);
  #else
  static inline int kgd2kfd_init(void)
  {
@@ -511,5 +513,10 @@ static inline int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id)
  {
  	return 0;
  }
+
+bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id)
+{
+	return false;
+}
  #endif
  #endif /* AMDGPU_AMDKFD_H_INCLUDED */
drivers/gpu/drm/amd/amdkfd/kfd_device.c +25 -0
index b1ce73c7a9ab..9d8bdead6e65 100644
@@ -1404,6 +1404,13 @@ void kfd_dec_compute_active(struct kfd_node *node)
  	WARN_ONCE(count < 0, "Compute profile ref. count error");
  }
 
+bool kfd_compute_active(struct kfd_node *node)
+{
+	if (atomic_read(&node->kfd->compute_profile))
+		return true;
+	return false;
+}
+
  void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, uint64_t throttle_bitmask)
  {
  	/*
@@ -1497,6 +1504,24 @@ int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id)
  	return node->dqm->ops.halt(node->dqm);
  }
 
+bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id)
+{
+	struct kfd_node *node;
+
+	if (!kfd->init_complete)
+		return false;
+
+	if (node_id >= kfd->num_nodes) {
+		dev_warn(kfd->adev->dev, "Invalid node ID: %u exceeds %u\n",
+			 node_id, kfd->num_nodes - 1);
+		return false;
+	}
+
+	node = kfd->nodes[node_id];
+
+	return kfd_compute_active(node);
+}
+
  #if defined(CONFIG_DEBUG_FS)
 
  /* This function will send a package to HIQ to hang the HWS
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
index 9e5ca0b93b2a..f9140fdb8132 100644
@@ -1518,6 +1518,7 @@ bool kfd_is_locked(void);
  /* Compute profile */
  void kfd_inc_compute_active(struct kfd_node *dev);
  void kfd_dec_compute_active(struct kfd_node *dev);
+bool kfd_compute_active(struct kfd_node *dev);
 
  /* Cgroup Support */
  /* Check with device cgroup if @kfd device is accessible */