[SWDEV-499029] Fix unable to change memory partition modes
Changes:
* [API] Removed checking board name, fixes for other MI ASICs
* [API] Fixed unable to restart AMD GPU, libdrm blocked
doing this operation
* [API] Added ability to unload/reload libdrm
from within AMD SMI APIs
* [CLI] Increased progress bar to change memory partition modes
to 140 seconds, since driver reload is variable per system
Change-Id: I52f227f2ab850c4a6332ff3ecdc899903b1080f1
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
This commit is contained in:
@@ -53,6 +53,8 @@
|
||||
#include "amd_smi/impl/amd_smi_processor.h"
|
||||
#include "rocm_smi/rocm_smi_logger.h"
|
||||
|
||||
// a global instance of std::mutex to protect data passed during threads
|
||||
std::mutex myMutex;
|
||||
static bool initialized_lib = false;
|
||||
|
||||
#define SIZE 10
|
||||
@@ -1426,8 +1428,63 @@ amdsmi_status_t
|
||||
amdsmi_set_gpu_memory_partition(amdsmi_processor_handle processor_handle,
|
||||
amdsmi_memory_partition_type_t memory_partition) {
|
||||
AMDSMI_CHECK_INIT();
|
||||
return rsmi_wrapper(rsmi_dev_memory_partition_set, processor_handle,
|
||||
std::ostringstream ss;
|
||||
std::lock_guard<std::mutex> g(myMutex);
|
||||
// open libdrm connections prevents the ability to unload driver
|
||||
amd::smi::AMDSmiSystem::getInstance().clean_up_drm();
|
||||
ss << __PRETTY_FUNCTION__ << " | \n"
|
||||
<< "***********************************\n"
|
||||
<< "* Cleaned up - clean_up_drm() *\n"
|
||||
<< "***********************************\n";
|
||||
LOG_INFO(ss);
|
||||
amdsmi_status_t ret = rsmi_wrapper(rsmi_dev_memory_partition_set, processor_handle,
|
||||
static_cast<rsmi_memory_partition_type_t>(memory_partition));
|
||||
if (ret == AMDSMI_STATUS_SUCCESS) {
|
||||
const uint32_t k256 = 256;
|
||||
char current_partition[k256];
|
||||
std::string current_partition_str = "UNKNOWN";
|
||||
std::string req_user_partition;
|
||||
amdsmi_status_t ret_get = rsmi_wrapper(rsmi_dev_memory_partition_get, processor_handle,
|
||||
current_partition, k256);
|
||||
if (ret_get == AMDSMI_STATUS_SUCCESS) {
|
||||
current_partition_str.clear();
|
||||
current_partition_str = current_partition;
|
||||
}
|
||||
switch (memory_partition) {
|
||||
case AMDSMI_MEMORY_PARTITION_NPS1:
|
||||
req_user_partition = "NPS1";
|
||||
break;
|
||||
case AMDSMI_MEMORY_PARTITION_NPS2:
|
||||
req_user_partition = "NPS2";
|
||||
break;
|
||||
case AMDSMI_MEMORY_PARTITION_NPS4:
|
||||
req_user_partition = "NPS4";
|
||||
break;
|
||||
case AMDSMI_MEMORY_PARTITION_NPS8:
|
||||
req_user_partition = "NPS8";
|
||||
break;
|
||||
default:
|
||||
req_user_partition = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
if (req_user_partition == current_partition_str) {
|
||||
amd::smi::AMDSmiSystem::getInstance().init_drm();
|
||||
ss << __PRETTY_FUNCTION__ << " | \n"
|
||||
<< "***********************************\n"
|
||||
<< "* Initialized libdrm - init_drm() *\n"
|
||||
<< "***********************************\n";
|
||||
LOG_INFO(ss);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(amdsmi_team): issue completely closing -> reopening libdrm on 1st try (workaround above)
|
||||
// amd::smi::AMDSmiSystem::getInstance().init_drm();
|
||||
// ss << __PRETTY_FUNCTION__ << " | \n"
|
||||
// << "***********************************\n"
|
||||
// << "* Initialized libdrm - init_drm() *\n"
|
||||
// << "***********************************\n";
|
||||
// LOG_INFO(ss);
|
||||
return ret;
|
||||
}
|
||||
|
||||
amdsmi_status_t
|
||||
|
||||
@@ -33,18 +33,24 @@ amdsmi_status_t AMDSmiLibraryLoader::load(const char* filename) {
|
||||
if (filename == nullptr) {
|
||||
return AMDSMI_STATUS_FAIL_LOAD_MODULE;
|
||||
}
|
||||
if (libHandler_) {
|
||||
if (libHandler_ || library_loaded_) {
|
||||
unload();
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(library_mutex_);
|
||||
libHandler_ = dlopen(filename, RTLD_LAZY);
|
||||
if (!libHandler_) {
|
||||
char* error = dlerror();
|
||||
std::cerr << "Fail to open " << filename <<": " << error
|
||||
<< std::endl;
|
||||
return AMDSMI_STATUS_FAIL_LOAD_MODULE;
|
||||
// check if already loaded, return success if it is
|
||||
// dlopen(filename, RTLD_NOLOAD) == null only IFF library is not loaded
|
||||
void* isLibOpen = dlopen(filename, RTLD_NOLOAD);
|
||||
if (isLibOpen == nullptr) {
|
||||
libHandler_ = dlopen(filename, RTLD_LAZY);
|
||||
if (!libHandler_) {
|
||||
char* error = dlerror();
|
||||
std::cerr << "Fail to open " << filename <<": " << error
|
||||
<< std::endl;
|
||||
return AMDSMI_STATUS_FAIL_LOAD_MODULE;
|
||||
}
|
||||
}
|
||||
library_loaded_ = true;
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -54,6 +60,7 @@ amdsmi_status_t AMDSmiLibraryLoader::unload() {
|
||||
if (libHandler_) {
|
||||
dlclose(libHandler_);
|
||||
libHandler_ = nullptr;
|
||||
library_loaded_ = false;
|
||||
}
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
مرجع در شماره جدید
Block a user