fix: [SWDEV-442525] [rocm/amd_smi_lib]

Fixes gpu_process_list

Code changes related to the following:
  * amdsmi_get_gpu_process_list()
  * CLI
  * Examples
  * Unit tests
  * Changelog
  * Readme
  * rocm_smi_lib commit: 677433b367

Change-Id: I9210fbca7a5da92d0a8b472b72ca82597c8e4fb5
Signed-off-by: Oliveira, Daniel <daniel.oliveira@amd.com>
このコミットが含まれているのは:
Oliveira, Daniel
2024-03-14 05:53:26 -05:00
コミット 08e2e21bab
14個のファイルの変更380行の追加246行の削除
+29 -22
ファイルの表示
@@ -657,9 +657,9 @@ typedef struct {
uint32_t mm_activity;
uint32_t reserved[13];
} amdsmi_engine_usage_t;
typedef uint32_t amdsmi_process_handle_t;
typedef struct {
char name[AMDSMI_NORMAL_STRING_LENGTH];
amdsmi_process_handle_t pid;
@@ -679,6 +679,7 @@ typedef struct {
uint32_t reserved[4];
} amdsmi_proc_info_t;
//! Guaranteed maximum possible number of supported frequencies
#define AMDSMI_MAX_NUM_FREQUENCIES 33
@@ -4743,33 +4744,39 @@ amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_handle, amdsmi_vram_
* number of processes currently running,
* AMDSMI_STATUS_OUT_OF_RESOURCES will be returned.
*
* For cases where max_process is not zero (0), it specifies the list's size limit.
* That is, the maximum size this list will be able to hold. After the list is built
* internally, as a return status, we will have AMDSMI_STATUS_OUT_OF_RESOURCES when
* the original size limit is smaller than the actual list of processes running.
* Hence, the caller is aware the list size needs to be resized, or
* AMDSMI_STATUS_SUCCESS otherwise.
* Holding a copy of max_process before it is passed in will be helpful for monitoring
* the allocations done upon each call since the max_process will permanently be changed
* to reflect the actual number of processes running.
* Note: For the specific cases where the return status is AMDSMI_STATUS_NO_PERM only.
* The list of process and size are AMDSMI_STATUS_SUCCESS, however there are
* processes details not fully retrieved due to permissions.
*
*
* @param[out] list Reference to a user-provided buffer where the process
* list will be returned. This buffer must contain at least
* max_processes entries of type smi_process_handle. Must be allocated
* max_processes entries of type amd_proc_info_list_t. Must be allocated
* by user.
*
* @return ::amdsmi_status_t | ::AMDSMI_STATUS_SUCCESS on success, non-zero on fail
* @return ::amdsmi_status_t | ::AMDSMI_STATUS_SUCCESS on success,
* | ::AMDSMI_STATUS_NO_PERM on success, but not all details from process retrieved,
* | ::AMDSMI_STATUS_OUT_OF_RESOURCES, filled list buffer with data, but number of
* actual running processes is larger than the size provided.
*
*/
// Note: If the reserved size for processes is smaller than the number of
// actual processes running. The AMDSMI_STATUS_OUT_OF_RESOURCES is
// an indication the caller should handle the situation (resize).
// The max_processes is always changed to reflect the actual size of
// list of processes running, so the caller knows where it is at.
//
amdsmi_status_t
amdsmi_get_gpu_process_list(amdsmi_processor_handle processor_handle, uint32_t *max_processes, amdsmi_process_handle_t *list);
/**
* @brief Returns the process information of a given process.
* Engine usage show how much time the process spend using these engines in ns.
*
* @platform{gpu_bm_linux} @platform{guest_1vf} @platform{guest_mvf} @platform{guest_windows}
*
* @param[in] processor_handle Device which to query
*
* @param[in] process Handle of process to query.
*
* @param[out] info Reference to a process information structure where to return
* information. Must be allocated by user.
*
* @return ::amdsmi_status_t | ::AMDSMI_STATUS_SUCCESS on success, non-zero on fail
*/
amdsmi_status_t
amdsmi_get_gpu_process_info(amdsmi_processor_handle processor_handle, amdsmi_process_handle_t process, amdsmi_proc_info_t *info);
amdsmi_get_gpu_process_list(amdsmi_processor_handle processor_handle, uint32_t *max_processes, amdsmi_proc_info_t *list);
/** @} End processinfo */
+22
ファイルの表示
@@ -53,7 +53,20 @@
namespace amd {
namespace smi {
// PID, amdsmi_proc_info_t
using GPUComputeProcessList_t = std::map<amdsmi_process_handle_t, amdsmi_proc_info_t>;
using ComputeProcessListClassType_t = uint16_t;
enum class ComputeProcessListType_t : ComputeProcessListClassType_t
{
kAllProcesses,
kAllProcessesOnDevice,
};
class AMDSmiGPUDevice: public AMDSmiProcessor {
public:
AMDSmiGPUDevice(uint32_t gpu_id, uint32_t fd, std::string path, amdsmi_bdf_t bdf, AMDSmiDrm& drm):
AMDSmiProcessor(AMD_GPU), gpu_id_(gpu_id), fd_(fd), path_(path), bdf_(bdf), drm_(drm) {}
@@ -73,6 +86,10 @@ class AMDSmiGPUDevice: public AMDSmiProcessor {
amdsmi_bdf_t get_bdf();
bool check_if_drm_is_supported() { return drm_.check_if_drm_is_supported(); }
uint32_t get_vendor_id();
const GPUComputeProcessList_t& amdgpu_get_compute_process_list(ComputeProcessListType_t list_type = ComputeProcessListType_t::kAllProcessesOnDevice);
const GPUComputeProcessList_t& amdgpu_get_all_compute_process_list() {
return amdgpu_get_compute_process_list(ComputeProcessListType_t::kAllProcesses);
}
amdsmi_status_t amdgpu_query_info(unsigned info_id,
unsigned size, void *value) const;
@@ -83,6 +100,7 @@ class AMDSmiGPUDevice: public AMDSmiProcessor {
amdsmi_status_t amdgpu_query_vbios(void *info) const;
amdsmi_status_t amdgpu_query_driver_name(std::string& name) const;
amdsmi_status_t amdgpu_query_driver_date(std::string& date) const;
private:
uint32_t gpu_id_;
uint32_t fd_;
@@ -90,6 +108,10 @@ class AMDSmiGPUDevice: public AMDSmiProcessor {
amdsmi_bdf_t bdf_;
uint32_t vendor_id_;
AMDSmiDrm& drm_;
GPUComputeProcessList_t compute_process_list_;
int32_t get_compute_process_list_impl(GPUComputeProcessList_t& compute_process_list,
ComputeProcessListType_t list_type);
};