Moving getPciPath out of os interface

Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
This commit is contained in:
Jaroslaw Chodor
2021-05-20 00:36:24 +02:00
committed by Compute-Runtime-Automation
parent 2b3b47b495
commit 8ca347f836
7 changed files with 64 additions and 31 deletions

View File

@@ -57,6 +57,8 @@ set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/pci_path.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pci_path.h
${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/print.cpp
${CMAKE_CURRENT_SOURCE_DIR}/settings_reader_create.cpp

View File

@@ -19,6 +19,7 @@
#include "shared/source/os_interface/linux/hw_device_id.h"
#include "shared/source/os_interface/linux/os_inc.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/source/os_interface/linux/pci_path.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/source/os_interface/linux/system_info.h"
#include "shared/source/os_interface/os_environment.h"
@@ -399,7 +400,7 @@ std::vector<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices(ExecutionE
std::string path = std::string(pathPrefix) + std::to_string(i + startNum);
int fileDescriptor = SysCalls::open(path.c_str(), O_RDWR);
auto pciPath = OSInterface::OSInterfaceImpl::getPciPath(fileDescriptor);
auto pciPath = NEO::getPciPath(fileDescriptor);
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.value_or("00:02.0").c_str());
if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) {

View File

@@ -15,8 +15,6 @@
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include <optional>
#include <string_view>
#include <sys/stat.h>
#include <system_error>
#include <unistd.h>
@@ -78,29 +76,4 @@ bool RootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDevi
return true;
}
std::optional<std::string> OSInterface::OSInterfaceImpl::getPciPath(int deviceFd) {
char path[256] = {0};
size_t pathlen = 256;
if (SysCalls::getDevicePath(deviceFd, path, pathlen)) {
return std::nullopt;
}
if (SysCalls::access(path, F_OK)) {
return std::nullopt;
}
int readLinkSize = 0;
char devicePath[256] = {0};
readLinkSize = SysCalls::readlink(path, devicePath, pathlen);
if (readLinkSize == -1) {
return std::nullopt;
}
std::string_view devicePathView(devicePath, static_cast<size_t>(readLinkSize));
devicePathView = devicePathView.substr(devicePathView.find("/drm/render") - 7u, 7u);
return std::string(devicePathView);
}
} // namespace NEO

View File

@@ -27,8 +27,6 @@ class OSInterface::OSInterfaceImpl {
bool isDebugAttachAvailable() const;
static std::optional<std::string> getPciPath(int deviceFd);
protected:
std::unique_ptr<Drm> drm;
};

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/pci_path.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include <string_view>
#include <unistd.h>
namespace NEO {
std::optional<std::string> getPciPath(int deviceFd) {
char path[256] = {0};
size_t pathlen = 256;
if (SysCalls::getDevicePath(deviceFd, path, pathlen)) {
return std::nullopt;
}
if (SysCalls::access(path, F_OK)) {
return std::nullopt;
}
int readLinkSize = 0;
char devicePath[256] = {0};
readLinkSize = SysCalls::readlink(path, devicePath, pathlen);
if (readLinkSize == -1) {
return std::nullopt;
}
std::string_view devicePathView(devicePath, static_cast<size_t>(readLinkSize));
devicePathView = devicePathView.substr(devicePathView.find("/drm/render") - 7u, 7u);
return std::string(devicePathView);
}
} // namespace NEO

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <optional>
#include <string>
namespace NEO {
std::optional<std::string> getPciPath(int deviceFd);
}