refactor: Unify getters to check platform support for KMD migration

Related-To: NEO-6465

Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir
2023-05-17 00:17:32 +00:00
committed by Compute-Runtime-Automation
parent d236bcbba9
commit ac9a96c07f
6 changed files with 62 additions and 15 deletions

View File

@@ -336,12 +336,9 @@ bool DrmAllocation::shouldAllocationPageFault(const Drm *drm) {
return DebugManager.flags.EnableImplicitMigrationOnFaultableHardware.get();
}
auto &productHelper = drm->getRootDeviceEnvironment().getHelper<ProductHelper>();
auto isKmdMigrationSupported = productHelper.isKmdMigrationSupported();
switch (this->allocationType) {
case AllocationType::UNIFIED_SHARED_MEMORY:
return (DebugManager.flags.UseKmdMigration.get() == -1) ? isKmdMigrationSupported : DebugManager.flags.UseKmdMigration.get();
return drm->hasKmdMigrationSupport();
case AllocationType::BUFFER:
return DebugManager.flags.UseKmdMigrationForBuffers.get() > 0;
default:

View File

@@ -245,14 +245,8 @@ bool DrmMemoryManager::hasPageFaultsEnabled(const Device &neoDevice) {
}
bool DrmMemoryManager::isKmdMigrationAvailable(uint32_t rootDeviceIndex) {
const auto &productHelper = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHelper<ProductHelper>();
auto useKmdMigration = productHelper.isKmdMigrationSupported();
if (DebugManager.flags.UseKmdMigration.get() != -1) {
useKmdMigration = DebugManager.flags.UseKmdMigration.get();
}
return useKmdMigration;
auto &drm = this->getDrm(rootDeviceIndex);
return drm.hasKmdMigrationSupport();
}
bool DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) {

View File

@@ -1132,6 +1132,17 @@ bool Drm::hasPageFaultSupport() const {
return pageFaultSupported;
}
bool Drm::hasKmdMigrationSupport() const {
const auto &productHelper = this->getRootDeviceEnvironment().getHelper<ProductHelper>();
auto kmdMigrationSupported = hasPageFaultSupport() && productHelper.isKmdMigrationSupported();
if (DebugManager.flags.UseKmdMigration.get() != -1) {
return !!DebugManager.flags.UseKmdMigration.get();
}
return kmdMigrationSupported;
}
unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice) {
auto engineInfo = this->engineInfo.get();

View File

@@ -169,6 +169,7 @@ class Drm : public DriverModel {
MOCKABLE_VIRTUAL void queryPageFaultSupport();
bool hasPageFaultSupport() const;
bool hasKmdMigrationSupport() const;
MOCKABLE_VIRTUAL uint32_t registerResource(DrmResourceClass classType, const void *data, size_t size);
MOCKABLE_VIRTUAL void unregisterResource(uint32_t handle);

View File

@@ -403,3 +403,39 @@ TEST(DrmQueryTest, givenEnableImplicitMigrationOnFaultableHardwareWhenShouldAllo
MockDrmAllocation allocation(0u, AllocationType::BUFFER, MemoryPool::MemoryNull);
EXPECT_TRUE(allocation.shouldAllocationPageFault(&drm));
}
TEST(DrmQueryTest, givenUseKmdMigrationSetWhenCallingHasKmdMigrationSupportThenReturnCorrectValue) {
DebugManagerStateRestore restorer;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->initializeMemoryManager();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
drm.pageFaultSupported = true;
for (auto useKmdMigration : {-1, 0, 1}) {
DebugManager.flags.UseKmdMigration.set(useKmdMigration);
if (useKmdMigration == -1) {
auto &productHelper = drm.getRootDeviceEnvironment().getHelper<ProductHelper>();
EXPECT_EQ(productHelper.isKmdMigrationSupported(), drm.hasKmdMigrationSupport());
} else {
EXPECT_EQ(useKmdMigration, drm.hasKmdMigrationSupport());
}
}
}
TEST(DrmQueryTest, givenKmdMigrationSupportedWhenShouldAllocationPageFaultIsCalledOnUnifiedSharedMemoryThenReturnTrue) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->initializeMemoryManager();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
drm.pageFaultSupported = true;
MockBufferObject bo(0u, &drm, 3, 0, 0, 1);
MockDrmAllocation allocation(0u, AllocationType::UNIFIED_SHARED_MEMORY, MemoryPool::LocalMemory);
allocation.bufferObjects[0] = &bo;
EXPECT_EQ(drm.hasKmdMigrationSupport(), allocation.shouldAllocationPageFault(&drm));
}

View File

@@ -123,7 +123,7 @@ TEST(DrmVmBindTest, givenUseKmdMigrationWhenCallingBindBoOnUnifiedSharedMemoryTh
EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag(), drm.context.receivedVmBind->flags);
}
TEST(DrmVmBindTest, givenDefaultDriverSettingsWhenCallingBindBoOnUnifiedSharedMemoryThenMarkAllocationShouldPageFaultWhenKmdMigrationIsSupported) {
TEST(DrmVmBindTest, givenDrmWithPageFaultSupportWhenCallingBindBoOnUnifiedSharedMemoryThenMarkAllocationShouldPageFaultWhenKmdMigrationIsSupported) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->initializeMemoryManager();
@@ -142,7 +142,15 @@ TEST(DrmVmBindTest, givenDefaultDriverSettingsWhenCallingBindBoOnUnifiedSharedMe
allocation.bindBO(&bo, &osContext, vmHandleId, nullptr, true);
auto &productHelper = drm.getRootDeviceEnvironment().getHelper<ProductHelper>();
auto isKmdMigrationSupported = productHelper.isKmdMigrationSupported();
auto kmdMigrationSupported = productHelper.isKmdMigrationSupported();
EXPECT_EQ(isKmdMigrationSupported, allocation.shouldAllocationPageFault(&drm));
if (kmdMigrationSupported) {
EXPECT_TRUE(allocation.shouldAllocationPageFault(&drm));
EXPECT_FALSE(bo.isExplicitResidencyRequired());
EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag(), drm.context.receivedVmBind->flags);
} else {
EXPECT_FALSE(allocation.shouldAllocationPageFault(&drm));
EXPECT_TRUE(bo.isExplicitResidencyRequired());
EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag() | DrmPrelimHelper::getMakeResidentVmBindFlag(), drm.context.receivedVmBind->flags);
}
}