The series is:
Acked-by: Srinivasan Shanmugam <[email protected]>

On 10/28/2024 8:22 PM, Alex Deucher wrote:
Add an interface to query whether KFD has any active queues.

Signed-off-by: Alex Deucher <[email protected]>
---
  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(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index b545940e512b..82f1c6a19d79 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index 7e0a22072536..f47f4555437b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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 */
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index b1ce73c7a9ab..9d8bdead6e65 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -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
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 9e5ca0b93b2a..f9140fdb8132 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -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 */

Reply via email to