SWDEV-393084 - [AMDSMI] [Linux] [Guest] Added checking of return values of subfunctions in function amdsmi_get_power_cap_info and added handling errors
Signed-off-by: Marko Oblak <Marko.Oblak@amd.com>
Change-Id: I3bfcc6003d018add683d30efc9d038bdb6af072c
[ROCm/amdsmi commit: 9b476baf8e]
Tá an tiomantas seo le fáil i:
tiomanta ag
Cedomir Dimic
tuismitheoir
9ea55651b9
tiomantas
bdc4abb376
@@ -1069,13 +1069,15 @@ amdsmi_get_power_cap_info(amdsmi_device_handle device_handle,
|
||||
if (info == nullptr)
|
||||
return AMDSMI_STATUS_INVAL;
|
||||
|
||||
bool set_ret_success = false;
|
||||
amd::smi::AMDSmiGPUDevice* gpudevice = nullptr;
|
||||
amdsmi_status_t r = get_gpu_device_from_handle(device_handle, &gpudevice);
|
||||
if (r != AMDSMI_STATUS_SUCCESS)
|
||||
return r;
|
||||
|
||||
amdsmi_status_t status;
|
||||
|
||||
status = get_gpu_device_from_handle(device_handle, &gpudevice);
|
||||
if (status != AMDSMI_STATUS_SUCCESS)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
// Ignore errors to get as much as possible info.
|
||||
memset(info, 0, sizeof(amdsmi_power_cap_info_t));
|
||||
|
||||
@@ -1084,24 +1086,37 @@ amdsmi_get_power_cap_info(amdsmi_device_handle device_handle,
|
||||
int power_cap = 0;
|
||||
int dpm = 0;
|
||||
status = smi_amdgpu_get_power_cap(gpudevice, &power_cap);
|
||||
if ((status == AMDSMI_STATUS_SUCCESS) && !set_ret_success)
|
||||
set_ret_success = true;
|
||||
|
||||
info->power_cap = power_cap;
|
||||
status = smi_amdgpu_get_ranges(gpudevice, CLK_TYPE_GFX,
|
||||
NULL, NULL, &dpm);
|
||||
if ((status == AMDSMI_STATUS_SUCCESS) && !set_ret_success)
|
||||
set_ret_success = true;
|
||||
info->dpm_cap = dpm;
|
||||
}
|
||||
else {
|
||||
auto rsmi_status = rsmi_dev_power_cap_get(gpudevice->get_gpu_id(),
|
||||
status = rsmi_wrapper(rsmi_dev_power_cap_get, device_handle,
|
||||
sensor_ind, &(info->power_cap));
|
||||
if ((status == AMDSMI_STATUS_SUCCESS) && !set_ret_success)
|
||||
set_ret_success = true;
|
||||
}
|
||||
|
||||
// Get other information from rocm-smi
|
||||
auto rsmi_status = rsmi_dev_power_cap_default_get(gpudevice->get_gpu_id(),
|
||||
&(info->default_power_cap));
|
||||
rsmi_status = rsmi_dev_power_cap_range_get(gpudevice->get_gpu_id(),
|
||||
sensor_ind, &(info->max_power_cap), &(info->min_power_cap));
|
||||
status = rsmi_wrapper(rsmi_dev_power_cap_default_get, device_handle,
|
||||
&(info->default_power_cap));
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
if ((status == AMDSMI_STATUS_SUCCESS) && !set_ret_success)
|
||||
set_ret_success = true;
|
||||
|
||||
status = rsmi_wrapper(rsmi_dev_power_cap_range_get, device_handle, sensor_ind,
|
||||
&(info->max_power_cap), &(info->min_power_cap));
|
||||
|
||||
if ((status == AMDSMI_STATUS_SUCCESS) && !set_ret_success)
|
||||
set_ret_success = true;
|
||||
|
||||
return set_ret_success ? AMDSMI_STATUS_SUCCESS : AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
amdsmi_status_t
|
||||
|
||||
@@ -171,7 +171,6 @@ amdsmi_status_t smi_amdgpu_get_power_cap(amd::smi::AMDSmiGPUDevice* device, int
|
||||
fullpath += "/power1_cap_max";
|
||||
std::ifstream file(fullpath.c_str(), std::ifstream::in);
|
||||
if (!file.is_open()) {
|
||||
printf("Failed to open file: %s \n", fullpath.c_str());
|
||||
return AMDSMI_STATUS_API_FAILED;
|
||||
}
|
||||
|
||||
@@ -218,7 +217,6 @@ amdsmi_status_t smi_amdgpu_get_ranges(amd::smi::AMDSmiGPUDevice* device, amdsmi_
|
||||
std::ifstream ranges(fullpath.c_str());
|
||||
|
||||
if (ranges.fail()) {
|
||||
printf("Failed to open file: %s \n", fullpath.c_str());
|
||||
return AMDSMI_STATUS_API_FAILED;
|
||||
}
|
||||
|
||||
@@ -259,7 +257,6 @@ amdsmi_status_t smi_amdgpu_get_enabled_blocks(amd::smi::AMDSmiGPUDevice* device,
|
||||
std::string tmp_str;
|
||||
|
||||
if (f.fail()) {
|
||||
printf("Failed to open file: %s \n", fullpath.c_str());
|
||||
return AMDSMI_STATUS_API_FAILED;
|
||||
}
|
||||
|
||||
@@ -295,7 +292,6 @@ amdsmi_status_t smi_amdgpu_get_bad_page_info(amd::smi::AMDSmiGPUDevice* device,
|
||||
std::ifstream fs(fullpath.c_str());
|
||||
|
||||
if (fs.fail()) {
|
||||
printf("Failed to open file: %s \n", fullpath.c_str());
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@@ -365,7 +361,6 @@ amdsmi_status_t smi_amdgpu_get_ecc_error_count(amd::smi::AMDSmiGPUDevice* device
|
||||
std::ifstream f(fullpath.c_str());
|
||||
|
||||
if (f.fail()) {
|
||||
printf("Failed to open file: %s \n", fullpath.c_str());
|
||||
return AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
Tagairt in Eagrán Nua
Cuir bac ar úsáideoir