[SWDEV-504146] Fix Device Name
Changes: - Fixed Device Name (market name) - Added new API rsmi_dev_market_name_get() - Updated tests - Updated amdgpu_drm.h to match latest mainline kernel - Fixed subsystem ID to only show hex value (not subsystem name) - rocm_smi_lib now has a recommended requirement for libdrm Change-Id: Ic438529e16c8c3dbbdd620da664918148c40c997
This commit is contained in:
committad av
Poag, Charis
förälder
4dbc2b6d57
incheckning
6a5e94c451
+60
-5
@@ -41,15 +41,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#include <libdrm/amdgpu.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <cassert>
|
||||
@@ -2338,6 +2339,60 @@ rsmi_dev_vendor_name_get(uint32_t dv_ind, char *name, size_t len) {
|
||||
CATCH
|
||||
}
|
||||
|
||||
rsmi_status_t rsmi_dev_market_name_get(uint32_t dv_ind, char *market_name, uint32_t len) {
|
||||
if (market_name == nullptr || len == 0) {
|
||||
return RSMI_STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
DEVICE_MUTEX
|
||||
GET_DEV_FROM_INDX
|
||||
dev->index();
|
||||
std::string render_file_name;
|
||||
|
||||
const std::string regex("renderD([0-9]+)");
|
||||
const std::string renderD_folder = "/sys/class/drm/card"
|
||||
+ std::to_string(dev->index()) + "/../";
|
||||
|
||||
// looking for /sys/class/drm/card0/../renderD*
|
||||
std::string render_name = amd::smi::find_file_in_folder(renderD_folder, regex);
|
||||
int gpu_fd = -1;
|
||||
std::string drm_path = "/dev/dri/" + render_name;
|
||||
if (render_name != "") {
|
||||
gpu_fd = open(drm_path.c_str(), O_RDWR | O_CLOEXEC);
|
||||
} else {
|
||||
market_name[0] = '\0';
|
||||
return RSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
amdgpu_device_handle device_handle = nullptr;
|
||||
uint32_t major_version, minor_version;
|
||||
int ret = amdgpu_device_initialize(gpu_fd, &major_version, &minor_version, &device_handle);
|
||||
if (ret != 0) {
|
||||
market_name[0] = '\0';
|
||||
close(gpu_fd);
|
||||
return RSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
|
||||
// Get the marketing name using libdrm's API
|
||||
const char *name = amdgpu_get_marketing_name(device_handle);
|
||||
if (name != nullptr) {
|
||||
// copy name to market name
|
||||
std::string temp_market_name(name);
|
||||
memset(market_name, '\0', len);
|
||||
uint32_t ln = static_cast<uint32_t>(temp_market_name.copy(market_name, len));
|
||||
market_name[std::min(len - 1, ln)] = '\0';
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
close(gpu_fd);
|
||||
if (len < (temp_market_name.size() + 1)) {
|
||||
return RSMI_STATUS_INSUFFICIENT_SIZE;
|
||||
}
|
||||
return RSMI_STATUS_SUCCESS;
|
||||
}
|
||||
amdgpu_device_deinitialize(device_handle);
|
||||
close(gpu_fd);
|
||||
return RSMI_STATUS_DRM_ERROR;
|
||||
}
|
||||
|
||||
|
||||
rsmi_status_t
|
||||
rsmi_dev_pci_bandwidth_get(uint32_t dv_ind, rsmi_pcie_bandwidth_t *b) {
|
||||
|
||||
@@ -1265,5 +1265,26 @@ int countDigit(uint64_t n) {
|
||||
return static_cast<int>(std::floor(log10(n) + 1));
|
||||
}
|
||||
|
||||
std::string find_file_in_folder(const std::string& folder,
|
||||
const std::string& regex) {
|
||||
std::string file_name;
|
||||
// TODO(amdsmi_dev): The closedir function has some non-standard attributes
|
||||
// that are being ignored here which is causing a warning to be thrown
|
||||
using dir_ptr = std::unique_ptr<DIR, decltype(&closedir)>;
|
||||
|
||||
struct dirent *dir = nullptr;
|
||||
std::regex file_regex(regex);
|
||||
auto drm_dir = dir_ptr(opendir(folder.c_str()), &closedir);
|
||||
if (drm_dir == nullptr) return file_name;
|
||||
std::cmatch m;
|
||||
while ((dir = readdir(drm_dir.get())) != NULL) {
|
||||
if (std::regex_search(dir->d_name, m, file_regex)) {
|
||||
file_name = dir->d_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return file_name;
|
||||
}
|
||||
|
||||
} // namespace smi
|
||||
} // namespace amd
|
||||
|
||||
Referens i nytt ärende
Block a user