[SWDEV-512393] Fix for incorrect cpu set size input (#399)
Signed-off-by: Deepak Mewar <deepak.mewar@amd.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
91c9969b72
Коммит
9a49e454fd
@@ -61,7 +61,7 @@ class AMDSmiSystem {
|
||||
|
||||
amdsmi_status_t get_cpu_model_name(uint32_t socket_id, std::string *model_name);
|
||||
|
||||
std::map<uint32_t, uint32_t> get_sys_cpu_cores_per_socket() ;
|
||||
amdsmi_status_t get_sys_cpu_cores_per_socket(uint32_t *core_num) ;
|
||||
|
||||
amdsmi_status_t get_sys_num_of_cpu_sockets(uint32_t *sock_num);
|
||||
|
||||
|
||||
@@ -178,18 +178,4 @@ constexpr T translate_umax_or_assign_value(U source_value, V target_value)
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Iterates all entires in a directory .
|
||||
*
|
||||
* @details Given a directory in const std::string & base_path, and a callback function
|
||||
* entry_callback, this function will open the directory and iterate through all entires
|
||||
* in that directory. For each entry it will call the entry_callback function with the
|
||||
* path of that entry
|
||||
*
|
||||
* @param[in] base_path the path of the directory to iterate in
|
||||
*
|
||||
* @retval ::true if the iteration was successful
|
||||
* ::false if the iteration failed
|
||||
*/
|
||||
bool iterate_directory(const std::string &base_path, std::function<void(const std::string &)> entry_callback);
|
||||
#endif // AMD_SMI_INCLUDE_AMD_SMI_UTILS_H_
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <functional>
|
||||
#include <exception>
|
||||
|
||||
#include "amd_smi/amdsmi.h"
|
||||
#include "amd_smi/impl/fdinfo.h"
|
||||
@@ -5953,16 +5954,13 @@ amdsmi_status_t amdsmi_get_cpu_model_name(amdsmi_processor_handle processor_hand
|
||||
|
||||
amdsmi_status_t amdsmi_get_cpu_cores_per_socket(uint32_t sock_count, amdsmi_sock_info_t *sock_info)
|
||||
{
|
||||
std::map<uint32_t, uint32_t> socket_core_count = amd::smi::AMDSmiSystem::getInstance().get_sys_cpu_cores_per_socket();
|
||||
amdsmi_status_t status;
|
||||
uint32_t core_num;
|
||||
status = amd::smi::AMDSmiSystem::getInstance().get_sys_cpu_cores_per_socket(&core_num);
|
||||
if (status != AMDSMI_STATUS_SUCCESS)
|
||||
return status;
|
||||
|
||||
for (uint32_t i = 0; i < sock_count; ++i) {
|
||||
auto it = socket_core_count.find(sock_info[i].socket_id);
|
||||
if (it != socket_core_count.end()) {
|
||||
sock_info[i].cores_per_socket = it->second;
|
||||
} else {
|
||||
sock_info[i].cores_per_socket = 0;
|
||||
}
|
||||
}
|
||||
sock_info->cores_per_socket = core_num;
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -129,39 +129,60 @@ amdsmi_status_t AMDSmiSystem::get_cpu_model_name(uint32_t socket_id, std::string
|
||||
}
|
||||
|
||||
#endif
|
||||
std::map<uint32_t, uint32_t> AMDSmiSystem::get_sys_cpu_cores_per_socket() {
|
||||
|
||||
amdsmi_status_t AMDSmiSystem::get_sys_cpu_cores_per_socket(uint32_t *core_num) {
|
||||
std::map<uint32_t, uint32_t> socket_core_count;
|
||||
std::string base_path = "/sys/devices/system/cpu/";
|
||||
|
||||
iterate_directory(base_path, [&socket_core_count](const std::string &path) {
|
||||
std::string filename(basename(path.c_str()));
|
||||
if (filename.find("cpu") != std::string::npos) {
|
||||
std::string cpuPath = path;
|
||||
std::ifstream package_id_file(cpuPath + "/topology/physical_package_id");
|
||||
std::ifstream core_id_file(cpuPath + "/topology/core_id");
|
||||
DIR* dir = opendir(base_path.c_str());
|
||||
if (dir == nullptr) {
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
}
|
||||
|
||||
uint32_t physical_id, core_id;
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != nullptr) {
|
||||
std::string file_name = entry->d_name;
|
||||
if (file_name.find("cpu") == 0) {
|
||||
std::string cpu_path = base_path + file_name;
|
||||
std::ifstream package_id_file(cpu_path + "/topology/physical_package_id");
|
||||
std::ifstream core_id_file(cpu_path + "/topology/core_id");
|
||||
|
||||
if (package_id_file.is_open() && core_id_file.is_open()) {
|
||||
uint32_t physical_id, core_id;
|
||||
package_id_file >> physical_id;
|
||||
core_id_file >> core_id;
|
||||
|
||||
socket_core_count[physical_id]++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return socket_core_count;
|
||||
closedir(dir);
|
||||
|
||||
if (socket_core_count.find(physical_id) != socket_core_count.end()) {
|
||||
*core_num = socket_core_count[physical_id];
|
||||
} else {
|
||||
return AMDSMI_STATUS_NO_DATA;
|
||||
}
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdsmi_status_t AMDSmiSystem::get_sys_num_of_cpu_sockets(uint32_t *sock_num) {
|
||||
std::map<uint32_t, uint32_t> socket_count_map;
|
||||
std::string base_path = "/sys/devices/system/cpu/";
|
||||
|
||||
iterate_directory(base_path, [&socket_count_map](std::string path) {
|
||||
std::string filename(basename(path.c_str()));
|
||||
if (filename.find("cpu") != std::string::npos) {
|
||||
std::string cpu_path = path;
|
||||
std::ifstream package_id_file(cpu_path + "/topology/physical_package_id");
|
||||
DIR* dir = opendir(base_path.c_str());
|
||||
if (dir == nullptr) {
|
||||
return AMDSMI_STATUS_API_FAILED;
|
||||
}
|
||||
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != nullptr) {
|
||||
std::string file_name = entry->d_name;
|
||||
if (file_name.find("cpu") == 0) {
|
||||
std::string path = base_path + file_name;
|
||||
std::ifstream package_id_file(path + "/topology/physical_package_id");
|
||||
|
||||
if (package_id_file.is_open()) {
|
||||
uint32_t physical_id;
|
||||
@@ -170,7 +191,9 @@ amdsmi_status_t AMDSmiSystem::get_sys_num_of_cpu_sockets(uint32_t *sock_num) {
|
||||
socket_count_map[physical_id]++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
*sock_num = static_cast<uint32_t>(socket_count_map.size());
|
||||
|
||||
|
||||
@@ -1046,25 +1046,3 @@ void amdsmi_wait_for_user_input(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool iterate_directory(const std::string &base_path,
|
||||
std::function<void(const std::string &)> entry_callback) {
|
||||
|
||||
DIR *dir = opendir(base_path.c_str());
|
||||
if (!dir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct dirent *entry = nullptr;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
entry_callback(entry->d_name);
|
||||
}
|
||||
|
||||
if (errno != 0) {
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user