Add ioctl helper function to check vm bind availability

Related-To: NEO-6591
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2022-02-15 09:33:27 +00:00 committed by Compute-Runtime-Automation
parent 964596e514
commit 12e2670b9a
14 changed files with 75 additions and 7 deletions

View File

@ -669,6 +669,7 @@ TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCr
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]);
drm->setupIoctlHelper(defaultHwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment);
@ -687,6 +688,7 @@ TEST(DrmMemoryManagerCreate, givenEnableHostPtrValidationSetToZeroWhenCreateDrmM
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]);
drm->setupIoctlHelper(defaultHwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment);

View File

@ -24,6 +24,7 @@ using namespace NEO;
TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFromMultipleThreadsThenSingleBoIsReused) {
class MockDrm : public Drm {
public:
using Drm::setupIoctlHelper;
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(fd, ""), rootDeviceEnvironment) {}
int ioctl(unsigned long request, void *arg) override {
@ -37,6 +38,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]);
mock->setupIoctlHelper(defaultHwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
@ -76,6 +78,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro
TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThenPrimeFdToHandleDoesNotRaceWithClose) {
class MockDrm : public Drm {
public:
using Drm::setupIoctlHelper;
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(fd, ""), rootDeviceEnvironment) {
primeFdHandle = 1;
closeHandle = 1;
@ -107,6 +110,7 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]);
mock->setupIoctlHelper(defaultHwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);

View File

@ -33,14 +33,14 @@ class DrmCommandStreamTest : public ::testing::Test {
DebugManager.flags.EnableForcePin.set(false);
mock = new ::testing::NiceMock<DrmMockImpl>(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
mock->setupIoctlHelper(hwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
mock->setupIoctlHelper(hwInfo->platform.eProductFamily);
osContext = std::make_unique<OsContextLinux>(*mock, 0u,
EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0],
PreemptionHelper::getDefaultPreemptionMode(*hwInfo)));

View File

@ -34,6 +34,7 @@ using namespace NEO;
class DrmMockForWorker : public Drm {
public:
using Drm::setupIoctlHelper;
std::mutex mutex;
std::atomic<int> gem_close_cnt;
std::atomic<int> gem_close_expected;
@ -68,6 +69,9 @@ class DrmGemCloseWorkerFixture {
void SetUp() {
this->drmMock = new DrmMockForWorker(*executionEnvironment.rootDeviceEnvironments[0]);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
drmMock->setupIoctlHelper(hwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drmMock));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drmMock, 0u);

View File

@ -67,6 +67,7 @@ class IoctlHelper {
virtual std::string getIoctlParamString(int param);
virtual IoctlHelper *clone() = 0;
virtual bool isVmBindAvailable(Drm *drm) = 0;
virtual uint32_t createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) = 0;
virtual std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo) = 0;
virtual CacheRegion closAlloc(Drm *drm) = 0;
@ -99,6 +100,7 @@ class IoctlHelperUpstream : public IoctlHelper {
public:
IoctlHelper *clone() override;
bool isVmBindAvailable(Drm *drm) override;
uint32_t createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) override;
std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo) override;
CacheRegion closAlloc(Drm *drm) override;
@ -146,6 +148,7 @@ class IoctlHelperPrelim20 : public IoctlHelper {
std::string getIoctlParamString(int param) override;
IoctlHelper *clone() override;
bool isVmBindAvailable(Drm *drm) override;
uint32_t createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) override;
std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo) override;
CacheRegion closAlloc(Drm *drm) override;

View File

@ -71,6 +71,18 @@ IoctlHelper *IoctlHelperPrelim20::clone() {
return new IoctlHelperPrelim20{};
}
bool IoctlHelperPrelim20::isVmBindAvailable(Drm *drm) {
int vmBindSupported = 0;
drm_i915_getparam_t getParam = {};
getParam.param = PRELIM_I915_PARAM_HAS_VM_BIND;
getParam.value = &vmBindSupported;
int retVal = IoctlHelper::ioctl(drm, DRM_IOCTL_I915_GETPARAM, &getParam);
if (retVal) {
return false;
}
return vmBindSupported;
}
uint32_t IoctlHelperPrelim20::createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) {
uint32_t regionsSize = static_cast<uint32_t>(memClassInstances.size());
std::vector<prelim_drm_i915_gem_memory_class_instance> regions(regionsSize);

View File

@ -17,6 +17,10 @@ IoctlHelper *IoctlHelperUpstream::clone() {
return new IoctlHelperUpstream{};
}
bool IoctlHelperUpstream::isVmBindAvailable(Drm *drm) {
return false;
}
uint32_t IoctlHelperUpstream::createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) {
uint32_t regionsSize = static_cast<uint32_t>(memClassInstances.size());
std::vector<drm_i915_gem_memory_class_instance> regions(regionsSize);

View File

@ -53,6 +53,10 @@ int DrmMockPrelimContext::handlePrelimRequest(unsigned long request, void *arg)
if (gp->param == PRELIM_I915_PARAM_HAS_PAGE_FAULT) {
*gp->value = hasPageFaultQueryValue;
return hasPageFaultQueryReturn;
} else if (gp->param == PRELIM_I915_PARAM_HAS_VM_BIND) {
vmBindQueryCalled++;
*gp->value = vmBindQueryValue;
return vmBindQueryReturn;
}
} break;
case PRELIM_DRM_IOCTL_I915_GEM_CLOS_RESERVE: {

View File

@ -22,6 +22,10 @@ struct DrmMockPrelimContext {
uint16_t maxNumWays{32};
uint32_t allocNumWays{0};
size_t vmBindQueryCalled{0};
int vmBindQueryValue{0};
int vmBindQueryReturn{0};
int hasPageFaultQueryValue{0};
int hasPageFaultQueryReturn{0};

View File

@ -201,8 +201,8 @@ DrmMockCustom::DrmMockCustom(RootDeviceEnvironment &rootDeviceEnvironment)
ioctl_expected.contextCreate = static_cast<int>(NEO::HwHelper::get(NEO::defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*NEO::defaultHwInfo).size());
ioctl_expected.contextDestroy = ioctl_expected.contextCreate.load();
createVirtualMemoryAddressSpace(NEO::HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
isVmBindAvailable();
setupIoctlHelper(rootDeviceEnvironment.getHardwareInfo()->platform.eProductFamily);
isVmBindAvailable();
reset();
}

View File

@ -38,6 +38,7 @@ class DrmMockImpl : public Drm {
class DrmMockSuccess : public Drm {
public:
using Drm::setupIoctlHelper;
DrmMockSuccess(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(fd, mockPciPath), rootDeviceEnvironment) {}
int ioctl(unsigned long request, void *arg) override { return 0; };

View File

@ -35,14 +35,15 @@ class DrmCommandStreamTestL0 : public ::testing::Test {
//make sure this is disabled, we don't want to test this now
DebugManager.flags.EnableForcePin.set(false);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
mock = new ::testing::NiceMock<DrmMockImpl>(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
mock->setupIoctlHelper(hwInfo->platform.eProductFamily);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
osContext = std::make_unique<OsContextLinux>(*mock, 0u,
EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0],
@ -98,4 +99,4 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTestL0, givenL0ApiConfigWhenCreatingDrmCsrThe
VariableBackup<ApiSpecificConfig::ApiType> backup(&apiTypeForUlts, ApiSpecificConfig::L0);
MockDrmCsrL0<FamilyType> csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode);
}
}

View File

@ -5,12 +5,13 @@
*
*/
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/libult/linux/drm_query_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/test_macros/test.h"
using namespace NEO;
@ -50,6 +51,28 @@ class IoctlHelperPrelimFixture : public ::testing::Test {
std::unique_ptr<DrmPrelimMock> drm;
};
TEST(IoctlHelperPrelimTest, whenGettingVmBindAvailabilityThenProperValueIsReturnedBasedOnIoctlResult) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
IoctlHelperPrelim20 ioctlHelper{};
for (auto &ioctlValue : {0, EINVAL}) {
drm.context.vmBindQueryReturn = ioctlValue;
for (auto &hasVmBind : ::testing::Bool()) {
drm.context.vmBindQueryValue = hasVmBind;
drm.context.vmBindQueryCalled = 0u;
if (ioctlValue == 0) {
EXPECT_EQ(hasVmBind, ioctlHelper.isVmBindAvailable(&drm));
} else {
EXPECT_FALSE(ioctlHelper.isVmBindAvailable(&drm));
}
EXPECT_EQ(1u, drm.context.vmBindQueryCalled);
}
}
}
TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtThenReturnSuccess) {
auto ioctlHelper = drm->getIoctlHelper();
uint32_t handle = 0;

View File

@ -5,7 +5,6 @@
*
*/
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
@ -17,6 +16,13 @@ using namespace NEO;
extern std::map<unsigned long, const char *> ioctlCodeStringMap;
extern std::map<int, const char *> ioctlParamCodeStringMap;
TEST(IoctlHelperUpstreamTest, whenGettingVmBindAvailabilityThenFalseIsReturned) {
IoctlHelperUpstream ioctlHelper{};
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_FALSE(ioctlHelper.isVmBindAvailable(drm.get()));
}
TEST(IoctlHelperUpstreamTest, givenIoctlWhenParseToStringThenProperStringIsReturned) {
IoctlHelperUpstream ioctlHelper{};
for (auto ioctlCodeString : ioctlCodeStringMap) {