Skip to content

Commit 08f7e7b

Browse files
luluu9Compute-Runtime-Automation
authored andcommitted
fix: align NEO to new Xe KMD header
Align to the new PAT and cache coherency support There is an issue with coherency=non_coh, which is default option for some platforms. Add temporary W/A until this issue is resolved. xe_drm.h header is generated from the series "PAT and cache coherency support" from https://patchwork.freedesktop.org/series/123027/ Related-To: NEO-9421, NEO-8324 Signed-off-by: Naklicki, Mateusz <[email protected]>
1 parent 08dfb65 commit 08f7e7b

File tree

9 files changed

+244
-14
lines changed

9 files changed

+244
-14
lines changed

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, EnableInOrderRelaxedOrderingForEventsChaining, -
267267
DECLARE_DEBUG_VARIABLE(int32_t, InOrderAtomicSignallingEnabled, -1, "-1: default, 0: disabled, 1: Use atomic GPU operations in increment the counter. Otherwise use non-atomic commands like SDI.")
268268
DECLARE_DEBUG_VARIABLE(int32_t, InOrderDuplicatedCounterStorageEnabled, -1, "-1: default, 0: disabled, 1: Allocate additional host storage for signalling")
269269
DECLARE_DEBUG_VARIABLE(int32_t, SetProcessPowerThrottlingState, -1, "-1: default, 0: Disabled, 1: ECO, 2: HIGH. If set, will override process power throttling state on os context init. Windows only.")
270+
DECLARE_DEBUG_VARIABLE(int32_t, OverrideCpuCaching, -1, "-1: default, 1: DRM_XE_GEM_CPU_CACHING_WB, 2: DRM_XE_GEM_CPU_CACHING_WC")
270271

271272
/*LOGGING FLAGS*/
272273
DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level")

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,7 @@ int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleI
13151315
UNRECOVERABLE_IF(bo->peekPatIndex() == CommonConstants::unsupportedPatIndex);
13161316
ioctlHelper->fillVmBindExtSetPat(vmBindExtSetPat, bo->peekPatIndex(), castToUint64(extensions.get()));
13171317
vmBind.extensions = castToUint64(vmBindExtSetPat);
1318+
vmBind.patIndex = bo->peekPatIndex();
13181319
} else {
13191320
vmBind.extensions = castToUint64(extensions.get());
13201321
}

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct VmBindParams {
6161
uint64_t length;
6262
uint64_t flags;
6363
uint64_t extensions;
64+
uint64_t patIndex;
6465
};
6566

6667
struct UuidRegisterResult {

shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,15 @@ void IoctlHelperXe::setDefaultEngine() {
533533
}
534534
}
535535

536+
uint16_t IoctlHelperXe::getCpuCachingMode() {
537+
uint16_t cpuCachingMode = DRM_XE_GEM_CPU_CACHING_WC;
538+
if (debugManager.flags.OverrideCpuCaching.get() != -1) {
539+
cpuCachingMode = debugManager.flags.OverrideCpuCaching.get();
540+
}
541+
542+
return cpuCachingMode;
543+
}
544+
536545
int IoctlHelperXe::createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional<uint32_t> vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks) {
537546
struct drm_xe_gem_create create = {};
538547
uint32_t regionsSize = static_cast<uint32_t>(memClassInstances.size());
@@ -553,6 +562,7 @@ int IoctlHelperXe::createGemExt(const MemRegionsVec &memClassInstances, size_t a
553562
memoryInstances.set(memoryClassInstance.memoryInstance);
554563
}
555564
create.flags = static_cast<uint32_t>(memoryInstances.to_ulong());
565+
create.cpu_caching = this->getCpuCachingMode();
556566

557567
auto ret = IoctlHelper::ioctl(DrmIoctl::gemCreate, &create);
558568
handle = create.handle;
@@ -586,6 +596,7 @@ uint32_t IoctlHelperXe::createGem(uint64_t size, uint32_t memoryBanks) {
586596
memoryInstances.set(regionClassAndInstance.memoryInstance);
587597
}
588598
create.flags = static_cast<uint32_t>(memoryInstances.to_ulong());
599+
create.cpu_caching = this->getCpuCachingMode();
589600
[[maybe_unused]] auto ret = ioctl(DrmIoctl::gemCreate, &create);
590601
DEBUG_BREAK_IF(ret != 0);
591602
updateBindInfo(create.handle, 0u, create.size);
@@ -1254,6 +1265,7 @@ int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) {
12541265
bind.bind.addr = gmmHelper->decanonize(vmBindParams.start);
12551266
bind.bind.flags = DRM_XE_VM_BIND_FLAG_ASYNC;
12561267
bind.bind.obj_offset = vmBindParams.offset;
1268+
bind.bind.pat_index = vmBindParams.patIndex;
12571269

12581270
if (isBind) {
12591271
bind.bind.op = DRM_XE_VM_BIND_OP_MAP;

shared/source/os_interface/linux/xe/ioctl_helper_xe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class IoctlHelperXe : public IoctlHelper {
119119
void fillBindInfoForIpcHandle(uint32_t handle, size_t size) override;
120120
bool getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd) override;
121121
bool isImmediateVmBindRequired() const override;
122+
uint16_t getCpuCachingMode();
122123

123124
private:
124125
template <typename... XeLogArgs>

shared/test/common/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,4 +572,5 @@ EnableDeviceStateVerificationAfterFailedSubmission = -1
572572
InOrderAtomicSignallingEnabled = -1
573573
SetProcessPowerThrottlingState = -1
574574
InOrderDuplicatedCounterStorageEnabled = -1
575+
OverrideCpuCaching = -1
575576
# Please don't edit below this line

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ TEST(IoctlHelperXeTest, whenChangingBufferBindingThenWaitIsNeededAlways) {
4545

4646
TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsThenDummyValueIsReturned) {
4747
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
48-
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
48+
DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]};
4949
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXe>(drm);
5050
ASSERT_NE(nullptr, xeIoctlHelper);
5151

@@ -62,11 +62,12 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsThen
6262
EXPECT_TRUE(xeIoctlHelper->bindInfo.empty());
6363
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, {}, -1, false, numOfChunks));
6464
EXPECT_FALSE(xeIoctlHelper->bindInfo.empty());
65+
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
6566
}
6667

6768
TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsAndVmIdThenDummyValueIsReturned) {
6869
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
69-
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
70+
DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]};
7071
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXe>(drm);
7172
ASSERT_NE(nullptr, xeIoctlHelper);
7273

@@ -84,6 +85,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsAndV
8485
EXPECT_TRUE(xeIoctlHelper->bindInfo.empty());
8586
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, test.vmId, -1, false, numOfChunks));
8687
EXPECT_FALSE(xeIoctlHelper->bindInfo.empty());
88+
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
8789
}
8890

8991
TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndNoLocalMemoryThenProperValuesSet) {
@@ -107,6 +109,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndNoLocalMemoryThenP
107109

108110
EXPECT_EQ(size, drm.createParamsSize);
109111
EXPECT_EQ(1u, drm.createParamsFlags);
112+
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
110113

111114
// dummy mock handle
112115
EXPECT_EQ(handle, drm.createParamsHandle);
@@ -134,6 +137,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateWhenMemoryBanksZeroTh
134137

135138
EXPECT_EQ(size, drm.createParamsSize);
136139
EXPECT_EQ(1u, drm.createParamsFlags);
140+
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
137141

138142
// dummy mock handle
139143
EXPECT_EQ(handle, drm.createParamsHandle);
@@ -161,6 +165,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndLocalMemoryThenPro
161165

162166
EXPECT_EQ(size, drm.createParamsSize);
163167
EXPECT_EQ(6u, drm.createParamsFlags);
168+
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
164169

165170
// dummy mock handle
166171
EXPECT_EQ(handle, drm.createParamsHandle);
@@ -583,6 +588,7 @@ TEST(IoctlHelperXeTest, whenCallingIoctlThenProperValueIsReturned) {
583588
test.handle = 0;
584589
test.flags = 1;
585590
test.size = 123;
591+
test.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;
586592
ret = mockXeIoctlHelper->ioctl(DrmIoctl::gemCreate, &test);
587593
EXPECT_EQ(0, ret);
588594
}
@@ -1649,3 +1655,51 @@ TEST(IoctlHelperXeTest, givenXeIoctlHelperWhenInitializeGetGpuTimeFunctionIsCall
16491655
xeIoctlHelper->initializeGetGpuTimeFunction();
16501656
EXPECT_EQ(xeIoctlHelper->getGpuTime, nullptr);
16511657
}
1658+
1659+
TEST(IoctlHelperXeTest, givenIoctlHelperXeAndDebugOverrideEnabledWhenGetCpuCachingModeCalledThenOverriddenValueIsReturned) {
1660+
DebugManagerStateRestore restorer;
1661+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
1662+
DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]};
1663+
1664+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXe>(drm);
1665+
drm.memoryInfo.reset(xeIoctlHelper->createMemoryInfo().release());
1666+
ASSERT_NE(nullptr, xeIoctlHelper);
1667+
1668+
debugManager.flags.OverrideCpuCaching.set(DRM_XE_GEM_CPU_CACHING_WB);
1669+
EXPECT_EQ(xeIoctlHelper->getCpuCachingMode(), DRM_XE_GEM_CPU_CACHING_WB);
1670+
1671+
debugManager.flags.OverrideCpuCaching.set(DRM_XE_GEM_CPU_CACHING_WC);
1672+
EXPECT_EQ(xeIoctlHelper->getCpuCachingMode(), DRM_XE_GEM_CPU_CACHING_WC);
1673+
}
1674+
1675+
TEST(IoctlHelperXeTest, whenCallingVmBindThenPatIndexIsSet) {
1676+
DebugManagerStateRestore restorer;
1677+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
1678+
DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]};
1679+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXe>(drm);
1680+
1681+
uint64_t fenceAddress = 0x4321;
1682+
uint64_t fenceValue = 0x789;
1683+
uint64_t expectedPatIndex = 0xba;
1684+
1685+
BindInfo mockBindInfo{};
1686+
mockBindInfo.handle = 0x1234;
1687+
xeIoctlHelper->bindInfo.push_back(mockBindInfo);
1688+
1689+
VmBindExtUserFenceT vmBindExtUserFence{};
1690+
1691+
xeIoctlHelper->fillVmBindExtUserFence(vmBindExtUserFence, fenceAddress, fenceValue, 0u);
1692+
1693+
VmBindParams vmBindParams{};
1694+
vmBindParams.handle = mockBindInfo.handle;
1695+
vmBindParams.extensions = castToUint64(&vmBindExtUserFence);
1696+
vmBindParams.patIndex = expectedPatIndex;
1697+
1698+
drm.vmBindInputs.clear();
1699+
drm.syncInputs.clear();
1700+
drm.waitUserFenceInputs.clear();
1701+
ASSERT_EQ(0, xeIoctlHelper->vmBind(vmBindParams));
1702+
ASSERT_EQ(1u, drm.vmBindInputs.size());
1703+
1704+
EXPECT_EQ(drm.vmBindInputs[0].bind.pat_index, expectedPatIndex);
1705+
}

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class DrmMockXe : public DrmMockCustom {
150150
this->createParamsSize = createParams->size;
151151
this->createParamsFlags = createParams->flags;
152152
this->createParamsHandle = createParams->handle = testValueGemCreate;
153-
if (0 == this->createParamsSize || 0 == this->createParamsFlags) {
153+
this->createParamsCpuCaching = createParams->cpu_caching;
154+
if (0 == this->createParamsSize || 0 == this->createParamsFlags || 0 == this->createParamsCpuCaching) {
154155
return EINVAL;
155156
}
156157
ret = 0;
@@ -268,5 +269,6 @@ class DrmMockXe : public DrmMockCustom {
268269
StackVec<drm_xe_sync, 1> syncInputs;
269270
int waitUserFenceReturn = 0;
270271
uint32_t createParamsFlags = 0u;
272+
uint16_t createParamsCpuCaching = 0u;
271273
bool ioctlCalled = false;
272274
};

0 commit comments

Comments
 (0)