Skip to content

Commit f1574be

Browse files
luluu9Compute-Runtime-Automation
authored andcommitted
Use flag to opt-in for VM_BIND mode
Related-To: NEO-6640 Signed-off-by: Naklicki, Mateusz <[email protected]>
1 parent 944319b commit f1574be

File tree

11 files changed

+49
-20
lines changed

11 files changed

+49
-20
lines changed

level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ TEST(L0DebuggerLinux, givenVmBindAndPerContextVmEnabledInDrmWhenInitializingDebu
8282
executionEnvironment->initializeMemoryManager();
8383
auto osInterface = new OSInterface();
8484
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
85+
drmMock->callBaseIsVmBindAvailable = true;
8586
drmMock->bindAvailable = true;
8687
drmMock->setPerContextVMRequired(true);
8788

@@ -103,6 +104,7 @@ TEST(L0DebuggerLinux, givenVmBindNotAvailableInDrmWhenInitializingDebuggingInOsT
103104
executionEnvironment->initializeMemoryManager();
104105
auto osInterface = new OSInterface();
105106
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
107+
drmMock->callBaseIsVmBindAvailable = true;
106108
drmMock->bindAvailable = false;
107109
drmMock->setPerContextVMRequired(true);
108110

@@ -124,6 +126,7 @@ TEST(L0DebuggerLinux, givenPerContextVmNotEnabledWhenInitializingDebuggingInOsTh
124126
executionEnvironment->initializeMemoryManager();
125127
auto osInterface = new OSInterface();
126128
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
129+
drmMock->callBaseIsVmBindAvailable = true;
127130
drmMock->bindAvailable = true;
128131
drmMock->setPerContextVMRequired(false);
129132

opencl/test/unit_test/os_interface/linux/drm_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ TEST(DrmTest, GivenCompletionFenceDebugFlagWhenCreatingDrmObjectThenExpectCorrec
10471047
auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily);
10481048

10491049
DrmMock drmDefault{*executionEnvironment->rootDeviceEnvironments[0]};
1050+
drmDefault.callBaseIsVmBindAvailable = true;
10501051
if (hwHelper.isLinuxCompletionFenceSupported() && drmDefault.isVmBindAvailable()) {
10511052
EXPECT_TRUE(drmDefault.completionFenceSupport());
10521053
} else {
@@ -1056,10 +1057,12 @@ TEST(DrmTest, GivenCompletionFenceDebugFlagWhenCreatingDrmObjectThenExpectCorrec
10561057
DebugManager.flags.UseVmBind.set(1);
10571058
DebugManager.flags.EnableDrmCompletionFence.set(1);
10581059
DrmMock drmEnabled{*executionEnvironment->rootDeviceEnvironments[0]};
1060+
drmEnabled.callBaseIsVmBindAvailable = true;
10591061
EXPECT_TRUE(drmEnabled.completionFenceSupport());
10601062

10611063
DebugManager.flags.EnableDrmCompletionFence.set(0);
10621064
DrmMock drmDisabled{*executionEnvironment->rootDeviceEnvironments[0]};
1065+
drmDisabled.callBaseIsVmBindAvailable = true;
10631066
EXPECT_FALSE(drmDisabled.completionFenceSupport());
10641067
}
10651068

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,9 +1514,10 @@ int Drm::createDrmVirtualMemory(uint32_t &drmVmId) {
15141514
}
15151515

15161516
bool disableScratch = DebugManager.flags.DisableScratchPages.get();
1517-
bool enablePageFault = hasPageFaultSupport() && isVmBindAvailable();
1517+
bool useVmBind = isVmBindAvailable();
1518+
bool enablePageFault = hasPageFaultSupport() && useVmBind;
15181519

1519-
ctl.flags = ioctlHelper->getFlagsForVmCreate(disableScratch, enablePageFault);
1520+
ctl.flags = ioctlHelper->getFlagsForVmCreate(disableScratch, enablePageFault, useVmBind);
15201521

15211522
auto ret = SysCalls::ioctl(getFileDescriptor(), DRM_IOCTL_I915_GEM_VM_CREATE, &ctl);
15221523

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class IoctlHelper {
109109
virtual bool completionFenceExtensionSupported(const HardwareInfo &hwInfo, const bool isVmBindAvailable) = 0;
110110
virtual std::optional<int> getHasPageFaultParamId() = 0;
111111
virtual std::unique_ptr<uint8_t[]> createVmControlExtRegion(const std::optional<MemoryClassInstance> &regionInstanceClass) = 0;
112-
virtual uint32_t getFlagsForVmCreate(bool disableScratch, bool enablePageFault) = 0;
112+
virtual uint32_t getFlagsForVmCreate(bool disableScratch, bool enablePageFault, bool useVmBind) = 0;
113113
virtual uint32_t createContextWithAccessCounters(Drm *drm, drm_i915_gem_context_create_ext &gcc) = 0;
114114
virtual uint32_t createCooperativeContext(Drm *drm, drm_i915_gem_context_create_ext &gcc) = 0;
115115
virtual void fillVmBindExtSetPat(VmBindExtSetPatT &vmBindExtSetPat, uint64_t patIndex, uint64_t nextExtension) = 0;
@@ -160,7 +160,7 @@ class IoctlHelperUpstream : public IoctlHelper {
160160
bool completionFenceExtensionSupported(const HardwareInfo &hwInfo, const bool isVmBindAvailable) override;
161161
std::optional<int> getHasPageFaultParamId() override;
162162
std::unique_ptr<uint8_t[]> createVmControlExtRegion(const std::optional<MemoryClassInstance> &regionInstanceClass) override;
163-
uint32_t getFlagsForVmCreate(bool disableScratch, bool enablePageFault) override;
163+
uint32_t getFlagsForVmCreate(bool disableScratch, bool enablePageFault, bool useVmBind) override;
164164
uint32_t createContextWithAccessCounters(Drm *drm, drm_i915_gem_context_create_ext &gcc) override;
165165
uint32_t createCooperativeContext(Drm *drm, drm_i915_gem_context_create_ext &gcc) override;
166166
void fillVmBindExtSetPat(VmBindExtSetPatT &vmBindExtSetPat, uint64_t patIndex, uint64_t nextExtension) override;
@@ -224,7 +224,7 @@ class IoctlHelperPrelim20 : public IoctlHelper {
224224
bool completionFenceExtensionSupported(const HardwareInfo &hwInfo, const bool isVmBindAvailable) override;
225225
std::optional<int> getHasPageFaultParamId() override;
226226
std::unique_ptr<uint8_t[]> createVmControlExtRegion(const std::optional<MemoryClassInstance> &regionInstanceClass) override;
227-
uint32_t getFlagsForVmCreate(bool disableScratch, bool enablePageFault) override;
227+
uint32_t getFlagsForVmCreate(bool disableScratch, bool enablePageFault, bool useVmBind) override;
228228
uint32_t createContextWithAccessCounters(Drm *drm, drm_i915_gem_context_create_ext &gcc) override;
229229
uint32_t createCooperativeContext(Drm *drm, drm_i915_gem_context_create_ext &gcc) override;
230230
void fillVmBindExtSetPat(VmBindExtSetPatT &vmBindExtSetPat, uint64_t patIndex, uint64_t nextExtension) override;

shared/source/os_interface/linux/ioctl_helper_prelim.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ std::unique_ptr<uint8_t[]> IoctlHelperPrelim20::createVmControlExtRegion(const s
374374
return {};
375375
}
376376

377-
uint32_t IoctlHelperPrelim20::getFlagsForVmCreate(bool disableScratch, bool enablePageFault) {
377+
uint32_t IoctlHelperPrelim20::getFlagsForVmCreate(bool disableScratch, bool enablePageFault, bool useVmBind) {
378378
uint32_t flags = 0u;
379379
if (disableScratch) {
380380
flags |= PRELIM_I915_VM_CREATE_FLAGS_DISABLE_SCRATCH;
@@ -384,6 +384,10 @@ uint32_t IoctlHelperPrelim20::getFlagsForVmCreate(bool disableScratch, bool enab
384384
flags |= PRELIM_I915_VM_CREATE_FLAGS_ENABLE_PAGE_FAULT;
385385
}
386386

387+
if (useVmBind) {
388+
flags |= PRELIM_I915_VM_CREATE_FLAGS_USE_VM_BIND;
389+
}
390+
387391
return flags;
388392
}
389393

shared/source/os_interface/linux/ioctl_helper_upstream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ std::unique_ptr<uint8_t[]> IoctlHelperUpstream::createVmControlExtRegion(const s
183183
return {};
184184
}
185185

186-
uint32_t IoctlHelperUpstream::getFlagsForVmCreate(bool disableScratch, bool enablePageFault) {
186+
uint32_t IoctlHelperUpstream::getFlagsForVmCreate(bool disableScratch, bool enablePageFault, bool useVmBind) {
187187
return 0u;
188188
}
189189

shared/test/common/libult/linux/drm_mock.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ class DrmMock : public Drm {
147147
return 0;
148148
}
149149

150+
bool isVmBindAvailable() override {
151+
if (callBaseIsVmBindAvailable) {
152+
return Drm::isVmBindAvailable();
153+
}
154+
return bindAvailable;
155+
}
156+
150157
static const int mockFd = 33;
151158

152159
bool failRetTopology = false;
@@ -182,6 +189,7 @@ class DrmMock : public Drm {
182189
bool allowDebugAttach = false;
183190
bool allowDebugAttachCallBase = false;
184191
bool callBaseCreateDrmContext = true;
192+
bool callBaseIsVmBindAvailable = false;
185193

186194
bool capturedCooperativeContextRequest = false;
187195

@@ -289,6 +297,7 @@ class DrmMockResources : public DrmMock {
289297
public:
290298
DrmMockResources(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(mockFd, rootDeviceEnvironment) {
291299
setBindAvailable();
300+
callBaseIsVmBindAvailable = true;
292301
}
293302

294303
bool registerResourceClasses() override {

shared/test/common/libult/linux/drm_query_mock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DrmQueryMock : public DrmMock {
2525
DrmQueryMock(RootDeviceEnvironment &rootDeviceEnvironment, const HardwareInfo *inputHwInfo) : DrmMock(rootDeviceEnvironment) {
2626
rootDeviceEnvironment.setHwInfo(inputHwInfo);
2727
context.hwInfo = rootDeviceEnvironment.getHardwareInfo();
28+
callBaseIsVmBindAvailable = true;
2829

2930
setupIoctlHelper(IGFX_UNKNOWN);
3031

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ TEST(DrmBindTest, givenBindNotCompleteWhenWaitForBindThenWaitUserFenceIoctlIsCal
5757
TEST(DrmBindTest, whenCheckingVmBindAvailabilityThenIoctlHelperSupportIsUsed) {
5858
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
5959
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
60+
drm.callBaseIsVmBindAvailable = true;
6061

6162
EXPECT_EQ(drm.isVmBindAvailable(), drm.getIoctlHelper()->isVmBindAvailable(&drm));
6263
}

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ TEST_F(IoctlPrelimHelperTests, givenValidRegionInstanceClassWhenCreatingVmContro
101101
TEST_F(IoctlPrelimHelperTests, whenGettingFlagsForVmCreateThenProperValueIsReturned) {
102102
for (auto &disableScratch : ::testing::Bool()) {
103103
for (auto &enablePageFault : ::testing::Bool()) {
104-
auto flags = ioctlHelper.getFlagsForVmCreate(disableScratch, enablePageFault);
105-
if (disableScratch) {
106-
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_VM_CREATE_FLAGS_DISABLE_SCRATCH), (flags & PRELIM_I915_VM_CREATE_FLAGS_DISABLE_SCRATCH));
107-
}
108-
if (enablePageFault) {
109-
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_VM_CREATE_FLAGS_ENABLE_PAGE_FAULT), (flags & PRELIM_I915_VM_CREATE_FLAGS_ENABLE_PAGE_FAULT));
110-
}
111-
if (disableScratch || enablePageFault) {
112-
EXPECT_NE(0u, flags);
113-
} else {
114-
EXPECT_EQ(0u, flags);
104+
for (auto &useVmBind : ::testing::Bool()) {
105+
auto flags = ioctlHelper.getFlagsForVmCreate(disableScratch, enablePageFault, useVmBind);
106+
if (disableScratch) {
107+
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_VM_CREATE_FLAGS_DISABLE_SCRATCH), (flags & PRELIM_I915_VM_CREATE_FLAGS_DISABLE_SCRATCH));
108+
}
109+
if (enablePageFault) {
110+
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_VM_CREATE_FLAGS_ENABLE_PAGE_FAULT), (flags & PRELIM_I915_VM_CREATE_FLAGS_ENABLE_PAGE_FAULT));
111+
}
112+
if (useVmBind) {
113+
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_VM_CREATE_FLAGS_USE_VM_BIND), (flags & PRELIM_I915_VM_CREATE_FLAGS_USE_VM_BIND));
114+
}
115+
if (disableScratch || enablePageFault || useVmBind) {
116+
EXPECT_NE(0u, flags);
117+
} else {
118+
EXPECT_EQ(0u, flags);
119+
}
115120
}
116121
}
117122
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ TEST(IoctlHelperUpstreamTest, whenGettingFlagsForVmCreateThenZeroIsReturned) {
5252
IoctlHelperUpstream ioctlHelper{};
5353
for (auto &disableScratch : ::testing::Bool()) {
5454
for (auto &enablePageFault : ::testing::Bool()) {
55-
auto flags = ioctlHelper.getFlagsForVmCreate(disableScratch, enablePageFault);
56-
EXPECT_EQ(0u, flags);
55+
for (auto &useVmBind : ::testing::Bool()) {
56+
auto flags = ioctlHelper.getFlagsForVmCreate(disableScratch, enablePageFault, useVmBind);
57+
EXPECT_EQ(0u, flags);
58+
}
5759
}
5860
}
5961
}

0 commit comments

Comments
 (0)