Skip to content

Commit f68b8a2

Browse files
luluu9Compute-Runtime-Automation
authored andcommitted
fix: align NEO to new Xe KMD header
Align to the new PAT and cache coherency support 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 2146cd0 commit f68b8a2

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
@@ -265,6 +265,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, EnableInOrderRelaxedOrderingForEventsChaining, -
265265
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.")
266266
DECLARE_DEBUG_VARIABLE(int32_t, InOrderDuplicatedCounterStorageEnabled, -1, "-1: default, 0: disabled, 1: Allocate additional host storage for signalling")
267267
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.")
268+
DECLARE_DEBUG_VARIABLE(int32_t, OverrideCpuCaching, -1, "-1: default, 1: DRM_XE_GEM_CPU_CACHING_WB, 2: DRM_XE_GEM_CPU_CACHING_WC")
268269

269270
/*LOGGING FLAGS*/
270271
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
@@ -118,6 +118,7 @@ class IoctlHelperXe : public IoctlHelper {
118118
void fillBindInfoForIpcHandle(uint32_t handle, size_t size) override;
119119
bool getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd) override;
120120
bool isImmediateVmBindRequired() const override;
121+
uint16_t getCpuCachingMode();
121122

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

shared/test/common/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,5 @@ EnableDeviceStateVerificationAfterFailedSubmission = -1
569569
InOrderAtomicSignallingEnabled = -1
570570
SetProcessPowerThrottlingState = -1
571571
InOrderDuplicatedCounterStorageEnabled = -1
572+
OverrideCpuCaching = -1
572573
# 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);
@@ -587,6 +592,7 @@ TEST(IoctlHelperXeTest, whenCallingIoctlThenProperValueIsReturned) {
587592
test.handle = 0;
588593
test.flags = 1;
589594
test.size = 123;
595+
test.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;
590596
ret = mockXeIoctlHelper->ioctl(DrmIoctl::gemCreate, &test);
591597
EXPECT_EQ(0, ret);
592598
}
@@ -1653,3 +1659,51 @@ TEST(IoctlHelperXeTest, givenXeIoctlHelperWhenInitializeGetGpuTimeFunctionIsCall
16531659
xeIoctlHelper->initializeGetGpuTimeFunction();
16541660
EXPECT_EQ(xeIoctlHelper->getGpuTime, nullptr);
16551661
}
1662+
1663+
TEST(IoctlHelperXeTest, givenIoctlHelperXeAndDebugOverrideEnabledWhenGetCpuCachingModeCalledThenOverriddenValueIsReturned) {
1664+
DebugManagerStateRestore restorer;
1665+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
1666+
DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]};
1667+
1668+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXe>(drm);
1669+
drm.memoryInfo.reset(xeIoctlHelper->createMemoryInfo().release());
1670+
ASSERT_NE(nullptr, xeIoctlHelper);
1671+
1672+
debugManager.flags.OverrideCpuCaching.set(DRM_XE_GEM_CPU_CACHING_WB);
1673+
EXPECT_EQ(xeIoctlHelper->getCpuCachingMode(), DRM_XE_GEM_CPU_CACHING_WB);
1674+
1675+
debugManager.flags.OverrideCpuCaching.set(DRM_XE_GEM_CPU_CACHING_WC);
1676+
EXPECT_EQ(xeIoctlHelper->getCpuCachingMode(), DRM_XE_GEM_CPU_CACHING_WC);
1677+
}
1678+
1679+
TEST(IoctlHelperXeTest, whenCallingVmBindThenPatIndexIsSet) {
1680+
DebugManagerStateRestore restorer;
1681+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
1682+
DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]};
1683+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXe>(drm);
1684+
1685+
uint64_t fenceAddress = 0x4321;
1686+
uint64_t fenceValue = 0x789;
1687+
uint64_t expectedPatIndex = 0xba;
1688+
1689+
BindInfo mockBindInfo{};
1690+
mockBindInfo.handle = 0x1234;
1691+
xeIoctlHelper->bindInfo.push_back(mockBindInfo);
1692+
1693+
VmBindExtUserFenceT vmBindExtUserFence{};
1694+
1695+
xeIoctlHelper->fillVmBindExtUserFence(vmBindExtUserFence, fenceAddress, fenceValue, 0u);
1696+
1697+
VmBindParams vmBindParams{};
1698+
vmBindParams.handle = mockBindInfo.handle;
1699+
vmBindParams.extensions = castToUint64(&vmBindExtUserFence);
1700+
vmBindParams.patIndex = expectedPatIndex;
1701+
1702+
drm.vmBindInputs.clear();
1703+
drm.syncInputs.clear();
1704+
drm.waitUserFenceInputs.clear();
1705+
ASSERT_EQ(0, xeIoctlHelper->vmBind(vmBindParams));
1706+
ASSERT_EQ(1u, drm.vmBindInputs.size());
1707+
1708+
EXPECT_EQ(drm.vmBindInputs[0].bind.pat_index, expectedPatIndex);
1709+
}

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
@@ -151,7 +151,8 @@ class DrmMockXe : public DrmMockCustom {
151151
this->createParamsSize = createParams->size;
152152
this->createParamsFlags = createParams->flags;
153153
this->createParamsHandle = createParams->handle = testValueGemCreate;
154-
if (0 == this->createParamsSize || 0 == this->createParamsFlags) {
154+
this->createParamsCpuCaching = createParams->cpu_caching;
155+
if (0 == this->createParamsSize || 0 == this->createParamsFlags || 0 == this->createParamsCpuCaching) {
155156
return EINVAL;
156157
}
157158
ret = 0;
@@ -269,5 +270,6 @@ class DrmMockXe : public DrmMockCustom {
269270
StackVec<drm_xe_sync, 1> syncInputs;
270271
int waitUserFenceReturn = 0;
271272
uint32_t createParamsFlags = 0u;
273+
uint16_t createParamsCpuCaching = 0u;
272274
bool ioctlCalled = false;
273275
};

0 commit comments

Comments
 (0)