Merge "Return the driver loading status" into amd-dev

This commit is contained in:
Maisam Arif
2023-09-19 13:01:28 -04:00
committato da Gerrit Code Review
4 ha cambiato i file con 54 aggiunte e 0 eliminazioni
+1
Vedi File
@@ -178,6 +178,7 @@ typedef enum {
AMDSMI_STATUS_NOT_FOUND = 31, //!< Device Not found
AMDSMI_STATUS_NOT_INIT = 32, //!< Device not initialized
AMDSMI_STATUS_NO_SLOT = 33, //!< No more free slot
AMDSMI_STATUS_DRIVER_NOT_LOADED = 34, //!< Processor driver not loaded
// Data and size errors
AMDSMI_STATUS_NO_DATA = 40, //!< No data was found for a given input
AMDSMI_STATUS_INSUFFICIENT_SIZE = 41, //!< Not enough resources were available for the operation
+21
Vedi File
@@ -150,6 +150,20 @@ typedef enum {
RSMI_INIT_FLAG_RESRV_TEST1 = 0x800000000000000, //!< Reserved for test
} rsmi_init_flags_t;
/**
* @brief Driver loading status
*
* The driver loading status from initState sysfs
*/
typedef enum {
RSMI_DRIVER_NOT_FOUND = 0, //!< Cannot find the driver
RSMI_DRIVER_MODULE_STATE_LIVE, //!< Driver loaded and live
RSMI_DRIVER_MODULE_STATE_LOADING, //!< Driver is loading(coming)
RSMI_DRIVER_MODULE_STATE_UNLOADING, //!< Driver is unloading(going)
RSMI_DRIVER_MODULE_STATE_UNKNOWN, //!< Driver state unknown
} rsmi_driver_state_t;
/**
* @brief PowerPlay performance levels
*/
@@ -1038,6 +1052,13 @@ rsmi_status_t rsmi_init(uint64_t init_flags);
*/
rsmi_status_t rsmi_shut_down(void);
/**
* @brief Get driver loading status
*
* @details The status could be not found, live, loading, unloading.
*/
rsmi_status_t rsmi_driver_status(rsmi_driver_state_t* state);
/** @} */ // end of InitShut
/*****************************************************************************/
+27
Vedi File
@@ -508,6 +508,33 @@ rsmi_shut_down(void) {
CATCH
}
rsmi_status_t rsmi_driver_status(rsmi_driver_state_t* state) {
TRY
if (state == nullptr) {
return RSMI_STATUS_INVALID_ARGS;
}
// live, coming, going
static const char *kDevInitStateID = "/sys/module/amdgpu/initstate";
std::ifstream infile(kDevInitStateID);
if (!infile) {
*state = RSMI_DRIVER_NOT_FOUND;
return RSMI_STATUS_SUCCESS;
}
std::string stat_str;
infile >> stat_str;
*state = RSMI_DRIVER_MODULE_STATE_UNKNOWN;
if (stat_str == "live") *state = RSMI_DRIVER_MODULE_STATE_LIVE;
if (stat_str == "coming") *state = RSMI_DRIVER_MODULE_STATE_LOADING;
if (stat_str == "going") *state = RSMI_DRIVER_MODULE_STATE_UNLOADING;
return RSMI_STATUS_SUCCESS;
CATCH
}
rsmi_status_t
rsmi_num_monitor_devices(uint32_t *num_devices) {
TRY
+5
Vedi File
@@ -208,8 +208,13 @@ amdsmi_status_t AMDSmiSystem::get_cpu_model(uint32_t cpu_model) {
amdsmi_status_t AMDSmiSystem::populate_amd_gpu_devices() {
// init rsmi
rsmi_driver_state_t state;
rsmi_status_t ret = rsmi_init(0);
if (ret != RSMI_STATUS_SUCCESS) {
if (rsmi_driver_status(&state) == RSMI_STATUS_SUCCESS &&
state != RSMI_DRIVER_MODULE_STATE_LIVE) {
return AMDSMI_STATUS_DRIVER_NOT_LOADED;
}
return amd::smi::rsmi_to_amdsmi_status(ret);
}