Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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

v2: fix build issues

Acked-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

+41
+9
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
··· 890 890 return kgd2kfd_start_sched(adev->kfd.dev, node_id); 891 891 } 892 892 893 + /* check if there are KFD queues active */ 894 + bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id) 895 + { 896 + if (!adev->kfd.init_complete) 897 + return false; 898 + 899 + return kgd2kfd_compute_active(adev->kfd.dev, node_id); 900 + } 901 + 893 902 /* Config CGTT_SQ_CLK_CTRL */ 894 903 int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id, 895 904 bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable)
+7
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
··· 268 268 int amdgpu_amdkfd_stop_sched(struct amdgpu_device *adev, uint32_t node_id); 269 269 int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id, 270 270 bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable); 271 + bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id); 271 272 272 273 273 274 /* Read user wptr from a specified user address space with page fault ··· 432 431 void kgd2kfd_unlock_kfd(void); 433 432 int kgd2kfd_start_sched(struct kfd_dev *kfd, uint32_t node_id); 434 433 int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id); 434 + bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id); 435 435 #else 436 436 static inline int kgd2kfd_init(void) 437 437 { ··· 512 510 static inline int kgd2kfd_stop_sched(struct kfd_dev *kfd, uint32_t node_id) 513 511 { 514 512 return 0; 513 + } 514 + 515 + static inline bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id) 516 + { 517 + return false; 515 518 } 516 519 #endif 517 520 #endif /* AMDGPU_AMDKFD_H_INCLUDED */
+25
drivers/gpu/drm/amd/amdkfd/kfd_device.c
··· 1392 1392 WARN_ONCE(count < 0, "Compute profile ref. count error"); 1393 1393 } 1394 1394 1395 + static bool kfd_compute_active(struct kfd_node *node) 1396 + { 1397 + if (atomic_read(&node->kfd->compute_profile)) 1398 + return true; 1399 + return false; 1400 + } 1401 + 1395 1402 void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, uint64_t throttle_bitmask) 1396 1403 { 1397 1404 /* ··· 1490 1483 1491 1484 node = kfd->nodes[node_id]; 1492 1485 return node->dqm->ops.halt(node->dqm); 1486 + } 1487 + 1488 + bool kgd2kfd_compute_active(struct kfd_dev *kfd, uint32_t node_id) 1489 + { 1490 + struct kfd_node *node; 1491 + 1492 + if (!kfd->init_complete) 1493 + return false; 1494 + 1495 + if (node_id >= kfd->num_nodes) { 1496 + dev_warn(kfd->adev->dev, "Invalid node ID: %u exceeds %u\n", 1497 + node_id, kfd->num_nodes - 1); 1498 + return false; 1499 + } 1500 + 1501 + node = kfd->nodes[node_id]; 1502 + 1503 + return kfd_compute_active(node); 1493 1504 } 1494 1505 1495 1506 #if defined(CONFIG_DEBUG_FS)