Skip to content

Commit ac9a96c

Browse files
refactor: Unify getters to check platform support for KMD migration
Related-To: NEO-6465 Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent d236bcb commit ac9a96c

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

shared/source/os_interface/linux/drm_allocation.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,9 @@ bool DrmAllocation::shouldAllocationPageFault(const Drm *drm) {
336336
return DebugManager.flags.EnableImplicitMigrationOnFaultableHardware.get();
337337
}
338338

339-
auto &productHelper = drm->getRootDeviceEnvironment().getHelper<ProductHelper>();
340-
auto isKmdMigrationSupported = productHelper.isKmdMigrationSupported();
341-
342339
switch (this->allocationType) {
343340
case AllocationType::UNIFIED_SHARED_MEMORY:
344-
return (DebugManager.flags.UseKmdMigration.get() == -1) ? isKmdMigrationSupported : DebugManager.flags.UseKmdMigration.get();
341+
return drm->hasKmdMigrationSupport();
345342
case AllocationType::BUFFER:
346343
return DebugManager.flags.UseKmdMigrationForBuffers.get() > 0;
347344
default:

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,8 @@ bool DrmMemoryManager::hasPageFaultsEnabled(const Device &neoDevice) {
245245
}
246246

247247
bool DrmMemoryManager::isKmdMigrationAvailable(uint32_t rootDeviceIndex) {
248-
const auto &productHelper = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHelper<ProductHelper>();
249-
auto useKmdMigration = productHelper.isKmdMigrationSupported();
250-
251-
if (DebugManager.flags.UseKmdMigration.get() != -1) {
252-
useKmdMigration = DebugManager.flags.UseKmdMigration.get();
253-
}
254-
255-
return useKmdMigration;
248+
auto &drm = this->getDrm(rootDeviceIndex);
249+
return drm.hasKmdMigrationSupport();
256250
}
257251

258252
bool DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) {

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,17 @@ bool Drm::hasPageFaultSupport() const {
11321132
return pageFaultSupported;
11331133
}
11341134

1135+
bool Drm::hasKmdMigrationSupport() const {
1136+
const auto &productHelper = this->getRootDeviceEnvironment().getHelper<ProductHelper>();
1137+
auto kmdMigrationSupported = hasPageFaultSupport() && productHelper.isKmdMigrationSupported();
1138+
1139+
if (DebugManager.flags.UseKmdMigration.get() != -1) {
1140+
return !!DebugManager.flags.UseKmdMigration.get();
1141+
}
1142+
1143+
return kmdMigrationSupported;
1144+
}
1145+
11351146
unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice) {
11361147
auto engineInfo = this->engineInfo.get();
11371148

shared/source/os_interface/linux/drm_neo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class Drm : public DriverModel {
169169

170170
MOCKABLE_VIRTUAL void queryPageFaultSupport();
171171
bool hasPageFaultSupport() const;
172+
bool hasKmdMigrationSupport() const;
172173

173174
MOCKABLE_VIRTUAL uint32_t registerResource(DrmResourceClass classType, const void *data, size_t size);
174175
MOCKABLE_VIRTUAL void unregisterResource(uint32_t handle);

shared/test/unit_test/os_interface/linux/drm_query_topology_prelim_tests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,39 @@ TEST(DrmQueryTest, givenEnableImplicitMigrationOnFaultableHardwareWhenShouldAllo
403403
MockDrmAllocation allocation(0u, AllocationType::BUFFER, MemoryPool::MemoryNull);
404404
EXPECT_TRUE(allocation.shouldAllocationPageFault(&drm));
405405
}
406+
407+
TEST(DrmQueryTest, givenUseKmdMigrationSetWhenCallingHasKmdMigrationSupportThenReturnCorrectValue) {
408+
DebugManagerStateRestore restorer;
409+
410+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
411+
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
412+
executionEnvironment->initializeMemoryManager();
413+
414+
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
415+
drm.pageFaultSupported = true;
416+
417+
for (auto useKmdMigration : {-1, 0, 1}) {
418+
DebugManager.flags.UseKmdMigration.set(useKmdMigration);
419+
if (useKmdMigration == -1) {
420+
auto &productHelper = drm.getRootDeviceEnvironment().getHelper<ProductHelper>();
421+
EXPECT_EQ(productHelper.isKmdMigrationSupported(), drm.hasKmdMigrationSupport());
422+
} else {
423+
EXPECT_EQ(useKmdMigration, drm.hasKmdMigrationSupport());
424+
}
425+
}
426+
}
427+
428+
TEST(DrmQueryTest, givenKmdMigrationSupportedWhenShouldAllocationPageFaultIsCalledOnUnifiedSharedMemoryThenReturnTrue) {
429+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
430+
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
431+
executionEnvironment->initializeMemoryManager();
432+
433+
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
434+
drm.pageFaultSupported = true;
435+
436+
MockBufferObject bo(0u, &drm, 3, 0, 0, 1);
437+
MockDrmAllocation allocation(0u, AllocationType::UNIFIED_SHARED_MEMORY, MemoryPool::LocalMemory);
438+
allocation.bufferObjects[0] = &bo;
439+
440+
EXPECT_EQ(drm.hasKmdMigrationSupport(), allocation.shouldAllocationPageFault(&drm));
441+
}

shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ TEST(DrmVmBindTest, givenUseKmdMigrationWhenCallingBindBoOnUnifiedSharedMemoryTh
123123
EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag(), drm.context.receivedVmBind->flags);
124124
}
125125

126-
TEST(DrmVmBindTest, givenDefaultDriverSettingsWhenCallingBindBoOnUnifiedSharedMemoryThenMarkAllocationShouldPageFaultWhenKmdMigrationIsSupported) {
126+
TEST(DrmVmBindTest, givenDrmWithPageFaultSupportWhenCallingBindBoOnUnifiedSharedMemoryThenMarkAllocationShouldPageFaultWhenKmdMigrationIsSupported) {
127127
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
128128
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
129129
executionEnvironment->initializeMemoryManager();
@@ -142,7 +142,15 @@ TEST(DrmVmBindTest, givenDefaultDriverSettingsWhenCallingBindBoOnUnifiedSharedMe
142142
allocation.bindBO(&bo, &osContext, vmHandleId, nullptr, true);
143143

144144
auto &productHelper = drm.getRootDeviceEnvironment().getHelper<ProductHelper>();
145-
auto isKmdMigrationSupported = productHelper.isKmdMigrationSupported();
146-
147-
EXPECT_EQ(isKmdMigrationSupported, allocation.shouldAllocationPageFault(&drm));
145+
auto kmdMigrationSupported = productHelper.isKmdMigrationSupported();
146+
147+
if (kmdMigrationSupported) {
148+
EXPECT_TRUE(allocation.shouldAllocationPageFault(&drm));
149+
EXPECT_FALSE(bo.isExplicitResidencyRequired());
150+
EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag(), drm.context.receivedVmBind->flags);
151+
} else {
152+
EXPECT_FALSE(allocation.shouldAllocationPageFault(&drm));
153+
EXPECT_TRUE(bo.isExplicitResidencyRequired());
154+
EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag() | DrmPrelimHelper::getMakeResidentVmBindFlag(), drm.context.receivedVmBind->flags);
155+
}
148156
}

0 commit comments

Comments
 (0)