[SWDEV-488303] Adjusted process vram_mem data source (#411)
* [SWDEV-488303] Adjusted process vram_mem data source * Standardized sscanf format strings --------- Signed-off-by: Maisam Arif <Maisam.Arif@amd.com> Co-authored-by: gabrpham_amdeng <Gabriel.Pham@amd.com>
This commit is contained in:
gecommit door
GitHub
bovenliggende
876f3976e0
commit
42441c78ea
@@ -100,6 +100,35 @@ uint32_t AMDSmiGPUDevice::get_drm_render_minor() {
|
||||
return this->drm_render_minor_;
|
||||
}
|
||||
|
||||
uint64_t AMDSmiGPUDevice::get_kfd_gpu_id() {
|
||||
std::ostringstream ss;
|
||||
// Should never return not_supported, but just in case
|
||||
rsmi_status_t ret = rsmi_status_t::RSMI_STATUS_NOT_SUPPORTED;
|
||||
uint32_t gpu_index = this->get_gpu_id();
|
||||
rsmi_device_identifiers_t identifiers = rsmi_device_identifiers_t{};
|
||||
ret = rsmi_dev_device_identifiers_get(gpu_index, &identifiers);
|
||||
if (ret != rsmi_status_t::RSMI_STATUS_SUCCESS) {
|
||||
this->kfd_gpu_id_ = std::numeric_limits<uint64_t>::max();
|
||||
} else {
|
||||
this->kfd_gpu_id_ = identifiers.kfd_gpu_id;
|
||||
}
|
||||
|
||||
ss << __PRETTY_FUNCTION__
|
||||
<< " | rsmi_dev_identifiers_get status: " << getRSMIStatusString(ret, false) << "\n"
|
||||
<< " | gpu_id_: " << gpu_id_ << "\n"
|
||||
<< " | identifiers.card_index: " << identifiers.card_index << "\n"
|
||||
<< " | identifiers.drm_render_minor: " << identifiers.drm_render_minor << "\n"
|
||||
<< " | identifiers.bdfid: " << std::hex << "0x" << identifiers.bdfid << "\n"
|
||||
<< " | identifiers.kfd_gpu_id: " << std::dec << identifiers.kfd_gpu_id << "\n"
|
||||
<< " | identifiers.partition_id: " << identifiers.partition_id << "\n"
|
||||
<< " | identifiers.smi_device_id: " << identifiers.smi_device_id << "\n"
|
||||
<< " | returning kfd_gpu_id_: "
|
||||
<< this->kfd_gpu_id_ << std::endl;
|
||||
// std::cout << ss.str();
|
||||
LOG_DEBUG(ss);
|
||||
return this->kfd_gpu_id_;
|
||||
}
|
||||
|
||||
uint32_t AMDSmiGPUDevice::get_gpu_fd() const {
|
||||
return fd_;
|
||||
}
|
||||
@@ -159,7 +188,6 @@ pthread_mutex_t* AMDSmiGPUDevice::get_mutex() {
|
||||
return amd::smi::GetMutex(gpu_id_);
|
||||
}
|
||||
|
||||
|
||||
int32_t AMDSmiGPUDevice::get_compute_process_list_impl(GPUComputeProcessList_t& compute_process_list,
|
||||
ComputeProcessListType_t list_type)
|
||||
{
|
||||
@@ -231,6 +259,41 @@ int32_t AMDSmiGPUDevice::get_compute_process_list_impl(GPUComputeProcessList_t&
|
||||
// Copy the cu occupancy from rsmi_process_info_t to amdsmi_proc_info_t
|
||||
asmi_proc_info.cu_occupancy = rsmi_proc_info.cu_occupancy;
|
||||
|
||||
// Safely handle KFD file access
|
||||
uint64_t kfd_gpu_id = get_kfd_gpu_id();
|
||||
std::string kfd_path = "/sys/class/kfd/kfd/proc/" +
|
||||
std::to_string(rsmi_proc_info.process_id) +
|
||||
"/vram_" + std::to_string(kfd_gpu_id);
|
||||
|
||||
// Check if the file exists before attempting to open it
|
||||
if (access(kfd_path.c_str(), R_OK) == 0) {
|
||||
std::ifstream kfd_file(kfd_path.c_str());
|
||||
if (kfd_file.is_open()) {
|
||||
std::string line;
|
||||
if (std::getline(kfd_file, line)) {
|
||||
try {
|
||||
uint64_t vram_bytes = std::stoull(line);
|
||||
asmi_proc_info.mem = vram_bytes; // Already in bytes
|
||||
asmi_proc_info.memory_usage.vram_mem = vram_bytes; // Already in bytes
|
||||
} catch (const std::exception& e) {
|
||||
// Handle conversion error gracefully
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << " | Failed to parse VRAM value from KFD: " << e.what();
|
||||
LOG_DEBUG(ss);
|
||||
}
|
||||
}
|
||||
kfd_file.close();
|
||||
} else {
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << " | Failed to open KFD file: " << kfd_path;
|
||||
LOG_DEBUG(ss);
|
||||
}
|
||||
} else {
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << " | KFD file not accessible: " << kfd_path;
|
||||
LOG_DEBUG(ss);
|
||||
}
|
||||
|
||||
return status_code;
|
||||
};
|
||||
|
||||
|
||||
@@ -166,26 +166,26 @@ amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid,
|
||||
if (it == pasids.end()) pasids.push_back(pasid);
|
||||
} else if (line.find("drm-memory-gtt:") != std::string::npos) {
|
||||
unsigned long mem;
|
||||
if (sscanf(line.c_str(), "drm-memory-gtt: %lu", &mem) != 1) continue;
|
||||
if (sscanf(line.c_str(), "drm-memory-gtt: %" PRIu32, &mem) != 1) continue;
|
||||
info.mem += mem * 1000;
|
||||
info.memory_usage.gtt_mem += mem * 1000;
|
||||
} else if (line.find("drm-memory-cpu:") != std::string::npos) {
|
||||
unsigned long mem;
|
||||
if (sscanf(line.c_str(), "drm-memory-cpu: %lu", &mem) != 1) continue;
|
||||
if (sscanf(line.c_str(), "drm-memory-cpu: %" PRIu32, &mem) != 1) continue;
|
||||
info.mem += mem * 1000;
|
||||
info.memory_usage.cpu_mem += mem * 1000;
|
||||
} else if (line.find("drm-memory-vram:") != std::string::npos) {
|
||||
unsigned long mem;
|
||||
if (sscanf(line.c_str(), "drm-memory-vram: %lu", &mem) != 1) continue;\
|
||||
if (sscanf(line.c_str(), "drm-memory-vram: %" PRIu32, &mem) != 1) continue;
|
||||
info.mem += mem * 1000;
|
||||
info.memory_usage.vram_mem += mem * 1000;
|
||||
} else if (line.find("drm-engine-gfx") != std::string::npos) {
|
||||
uint64_t engine_gfx;
|
||||
if (sscanf(line.c_str(), "drm-engine-gfx: %lu", &engine_gfx) != 1) continue;
|
||||
if (sscanf(line.c_str(), "drm-engine-gfx: %" PRIu32, &engine_gfx) != 1) continue;
|
||||
info.engine_usage.gfx = engine_gfx;
|
||||
} else if (line.find("drm-engine-enc") != std::string::npos) {
|
||||
uint64_t engine_enc;
|
||||
if (sscanf(line.c_str(), "drm-engine-enc: %lu", &engine_enc) != 1) continue;
|
||||
if (sscanf(line.c_str(), "drm-engine-enc: %" PRIu32, &engine_enc) != 1) continue;
|
||||
info.engine_usage.enc = engine_enc;
|
||||
}
|
||||
}
|
||||
|
||||
Verwijs in nieuw issue
Block a user