Skip to content

Commit 2b6fc61

Browse files
Revert "Coherency patch cleanup"
This reverts commit 8d7e175. Change-Id: Ia5e2d3dd6f622859320e57e659c677c53b775d2a
1 parent 8d7e175 commit 2b6fc61

File tree

11 files changed

+164
-8
lines changed

11 files changed

+164
-8
lines changed

runtime/os_interface/linux/drm_buffer_object.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
156156
execbuf.batch_len = alignUp(used, 8);
157157
execbuf.flags = flags;
158158

159+
if (drm->peekCoherencyDisablePatchActive() && !requiresCoherency) {
160+
execbuf.flags |= I915_PRIVATE_EXEC_FORCE_NON_COHERENT;
161+
}
159162
if (lowPriority) {
160163
execbuf.rsvd1 = this->drm->lowPriorityContextId & I915_EXEC_CONTEXT_ID_MASK;
161164
}
@@ -190,6 +193,10 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos) {
190193
execbuf.buffer_count = boIndex + 1;
191194
execbuf.batch_len = alignUp(static_cast<uint32_t>(sizeof(uint32_t)), 8);
192195

196+
if (drm->peekCoherencyDisablePatchActive()) {
197+
execbuf.flags = execbuf.flags | I915_PRIVATE_EXEC_FORCE_NON_COHERENT;
198+
}
199+
193200
int err = 0;
194201
int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
195202
if (ret != 0) {

runtime/os_interface/linux/drm_neo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ int Drm::getMaxGpuFrequency(int &maxGpuFrequency) {
115115
return 0;
116116
}
117117

118+
void Drm::obtainCoherencyDisablePatchActive() {
119+
int value = 0;
120+
auto ret = getParamIoctl(I915_PRIVATE_PARAM_HAS_EXEC_FORCE_NON_COHERENT, &value);
121+
coherencyDisablePatchActive = (ret == 0) && (value != 0);
122+
}
123+
118124
std::string Drm::getSysFsPciPath(int deviceID) {
119125
std::string nullPath;
120126
std::string sysFsPciDirectory = Os::sysFsPciPath;

runtime/os_interface/linux/drm_neo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
struct GT_SYSTEM_INFO;
3434

3535
namespace OCLRT {
36+
37+
#define I915_PRIVATE_PARAM_HAS_EXEC_FORCE_NON_COHERENT (-1)
38+
#define I915_PRIVATE_EXEC_FORCE_NON_COHERENT (1 << 31)
39+
3640
#define I915_CONTEXT_PRIVATE_PARAM_BOOST 0x80000000
3741

3842
class DeviceFactory;
@@ -70,6 +74,8 @@ class Drm {
7074
bool is48BitAddressRangeSupported();
7175
MOCKABLE_VIRTUAL bool hasPreemption();
7276
bool setLowPriority();
77+
bool peekCoherencyDisablePatchActive() { return coherencyDisablePatchActive; }
78+
virtual void obtainCoherencyDisablePatchActive();
7379
int getFileDescriptor() const { return fd; }
7480
bool contextCreate();
7581
void contextDestroy();
@@ -83,6 +89,7 @@ class Drm {
8389
int deviceId;
8490
int revisionId;
8591
GTTYPE eGtType;
92+
bool coherencyDisablePatchActive = false;
8693
Drm(int fd) : lowPriorityContextId(0), fd(fd), deviceId(0), revisionId(0), eGtType(GTTYPE_UNDEFINED) {}
8794
virtual ~Drm();
8895

runtime/os_interface/linux/drm_null_device.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (c) 2017, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -54,6 +54,8 @@ class DrmNullDevice : public Drm {
5454
}
5555
}
5656

57+
void obtainCoherencyDisablePatchActive() override { coherencyDisablePatchActive = true; }
58+
5759
protected:
5860
DrmNullDevice(int fd) : Drm(fd), gpuTimestamp(0){};
5961

runtime/os_interface/linux/hw_info_config.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *ou
131131
}
132132
pSysInfo->SubSliceCount = static_cast<uint32_t>(subSliceCount);
133133

134+
drm->obtainCoherencyDisablePatchActive();
134135
pSkuTable->ftrSVM = drm->is48BitAddressRangeSupported();
135136

136137
int maxGpuFreq = 0;
@@ -163,8 +164,10 @@ int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *ou
163164
outHwInfo->capabilityTable.maxRenderFrequency = maxGpuFreq;
164165
outHwInfo->capabilityTable.ftrSvm = pSkuTable->ftrSVM;
165166

167+
bool platformCoherency = false;
166168
HwHelper &hwHelper = HwHelper::get(pPlatform->eRenderCoreFamily);
167-
outHwInfo->capabilityTable.ftrSupportsCoherency = false;
169+
hwHelper.setCapabilityCoherencyFlag(const_cast<const HardwareInfo *>(outHwInfo), platformCoherency);
170+
outHwInfo->capabilityTable.ftrSupportsCoherency = (platformCoherency && drm->peekCoherencyDisablePatchActive());
168171

169172
outHwInfo->capabilityTable.defaultEngineType = DebugManager.flags.NodeOrdinal.get() == -1
170173
? outHwInfo->capabilityTable.defaultEngineType

unit_tests/linux/drm_null_device_tests.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (c) 2017, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -76,6 +76,13 @@ TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallGetDeviceIdTHENreturnProper
7676
EXPECT_EQ(0x1916, deviceId);
7777
}
7878

79+
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENpeekAndObtainCoherencyDisablePatchActiveTHENreturnNullDeviceValues) {
80+
EXPECT_EQ(drmNullDevice->peekCoherencyDisablePatchActive(), false);
81+
82+
drmNullDevice->obtainCoherencyDisablePatchActive();
83+
EXPECT_EQ(drmNullDevice->peekCoherencyDisablePatchActive(), true);
84+
}
85+
7986
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallIoctlTHENalwaysSuccess) {
8087
EXPECT_EQ(drmNullDevice->ioctl(0, nullptr), 0);
8188
}

unit_tests/os_interface/linux/device_command_stream_fixture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class DrmMockCustom : public Drm {
8080

8181
IoctlResExt(int32_t no, int32_t res) : no(no), res(res) {}
8282
};
83+
void overideCoherencyPatchActive(bool newCoherencyPatchActiveValue) { coherencyDisablePatchActive = newCoherencyPatchActiveValue; }
8384

8485
class Ioctls {
8586
public:

unit_tests/os_interface/linux/drm_buffer_object_tests.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ TEST_F(DrmBufferObjectTest, exec) {
8686
EXPECT_EQ(0u, mock->execBuffer.flags);
8787
}
8888

89+
TEST_F(DrmBufferObjectTest, givenDrmWithCoherencyPatchActiveWhenExecIsCalledThenFlagsContainNonCoherentFlag) {
90+
mock->ioctl_expected.total = 1;
91+
mock->ioctl_res = 0;
92+
mock->overideCoherencyPatchActive(true);
93+
94+
auto ret = bo->exec(0, 0, 0);
95+
EXPECT_EQ(mock->ioctl_res, ret);
96+
uint64_t expectedFlag = I915_PRIVATE_EXEC_FORCE_NON_COHERENT;
97+
uint64_t currentFlag = mock->execBuffer.flags;
98+
EXPECT_EQ(expectedFlag, currentFlag);
99+
}
100+
101+
TEST_F(DrmBufferObjectTest, givenDrmWithCoherencyPatchActiveWhenExecIsCalledWithCoherencyRequestThenFlagsDontContainNonCoherentFlag) {
102+
mock->ioctl_expected.total = 1;
103+
mock->ioctl_res = 0;
104+
mock->overideCoherencyPatchActive(true);
105+
106+
auto ret = bo->exec(0, 0, 0, true);
107+
EXPECT_EQ(mock->ioctl_res, ret);
108+
uint64_t expectedFlag = 0;
109+
uint64_t currentFlag = mock->execBuffer.flags;
110+
EXPECT_EQ(expectedFlag, currentFlag);
111+
}
112+
89113
TEST_F(DrmBufferObjectTest, exec_ioctlFailed) {
90114
mock->ioctl_expected.total = 1;
91115
mock->ioctl_res = -1;
@@ -128,6 +152,48 @@ TEST_F(DrmBufferObjectTest, testExecObjectFlags) {
128152
EXPECT_FALSE(execObject.flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS);
129153
}
130154

155+
TEST_F(DrmBufferObjectTest, onPinBBhasOnlyBbEndAndForceNonCoherent) {
156+
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
157+
mock->ioctl_expected.total = 1;
158+
mock->ioctl_res = 0;
159+
160+
mock->overideCoherencyPatchActive(true);
161+
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(this->mock));
162+
ASSERT_NE(nullptr, boToPin.get());
163+
164+
bo->setAddress(buff.get());
165+
BufferObject *boArray[1] = {boToPin.get()};
166+
auto ret = bo->pin(boArray, 1);
167+
EXPECT_EQ(mock->ioctl_res, ret);
168+
uint32_t bb_end = 0x05000000;
169+
EXPECT_EQ(buff[0], bb_end);
170+
EXPECT_GT(mock->execBuffer.batch_len, 0u);
171+
uint32_t flag = I915_PRIVATE_EXEC_FORCE_NON_COHERENT;
172+
EXPECT_TRUE((mock->execBuffer.flags & flag) == flag);
173+
bo->setAddress(nullptr);
174+
}
175+
176+
TEST_F(DrmBufferObjectTest, onPinBBhasOnlyBbEndAndNoForceNonCoherent) {
177+
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
178+
mock->ioctl_expected.total = 1;
179+
mock->ioctl_res = 0;
180+
181+
mock->overideCoherencyPatchActive(false);
182+
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(this->mock));
183+
ASSERT_NE(nullptr, boToPin.get());
184+
185+
bo->setAddress(buff.get());
186+
BufferObject *boArray[1] = {boToPin.get()};
187+
auto ret = bo->pin(boArray, 1);
188+
EXPECT_EQ(mock->ioctl_res, ret);
189+
uint32_t bb_end = 0x05000000;
190+
EXPECT_EQ(buff[0], bb_end);
191+
EXPECT_GT(mock->execBuffer.batch_len, 0u);
192+
uint32_t flag = I915_PRIVATE_EXEC_FORCE_NON_COHERENT;
193+
EXPECT_TRUE((mock->execBuffer.flags & flag) == 0);
194+
bo->setAddress(nullptr);
195+
}
196+
131197
TEST_F(DrmBufferObjectTest, onPinIoctlFailed) {
132198
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
133199

unit_tests/os_interface/linux/drm_mock.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (c) 2017, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -119,6 +119,10 @@ class Drm2 : public Drm {
119119
return this->StoredRetVal;
120120
}
121121
#endif
122+
if (gp->param == I915_PRIVATE_PARAM_HAS_EXEC_FORCE_NON_COHERENT) {
123+
*((int *)(gp->value)) = this->StoredDisableCoherencyPatchActive;
124+
return this->StoredRetVal;
125+
}
122126
if (gp->param == I915_PARAM_HAS_ALIASING_PPGTT) {
123127
*((int *)(gp->value)) = this->StoredPPGTT;
124128
return this->StoredRetVal;
@@ -180,6 +184,8 @@ class Drm2 : public Drm {
180184
return 0;
181185
}
182186

187+
void overideCoherencyPatchActive(bool newCoherencyPatchActiveValue) { coherencyDisablePatchActive = newCoherencyPatchActiveValue; }
188+
183189
void setSysFsDefaultGpuPath(const char *path) {
184190
sysFsDefaultGpuPathToRestore = sysFsDefaultGpuPath;
185191
sysFsDefaultGpuPath = path;
@@ -238,6 +244,7 @@ class Drm2 : public Drm {
238244
int StoredRetValForDeviceRevID = 0;
239245
int StoredRetValForPooledEU = 0;
240246
int StoredRetValForMinEUinPool = 0;
247+
int StoredDisableCoherencyPatchActive = 1;
241248
int StoredPPGTT = 3;
242249
int StoredPreemptionSupport = 1;
243250
int StoredMockPreemptionSupport = 0;

unit_tests/os_interface/linux/drm_tests.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,46 @@ TEST(DrmTest, GetRevisionID) {
131131
delete pDrm;
132132
}
133133

134+
TEST(DrmTest, GivenMockDrmWhenAskedForCoherencyStatusThenProperBitIsSet) {
135+
Drm2 *pDrm = new Drm2;
136+
EXPECT_NE(nullptr, pDrm);
137+
138+
EXPECT_FALSE(pDrm->peekCoherencyDisablePatchActive());
139+
140+
pDrm->obtainCoherencyDisablePatchActive();
141+
142+
EXPECT_TRUE(pDrm->peekCoherencyDisablePatchActive());
143+
delete pDrm;
144+
}
145+
146+
TEST(DrmTest, GivenMockDrmWhenAskedForCoherencyStatusThatPassThenDisabledIsReturned) {
147+
Drm2 *pDrm = new Drm2;
148+
pDrm->StoredDisableCoherencyPatchActive = 0;
149+
EXPECT_NE(nullptr, pDrm);
150+
151+
EXPECT_FALSE(pDrm->peekCoherencyDisablePatchActive());
152+
153+
pDrm->obtainCoherencyDisablePatchActive();
154+
155+
EXPECT_FALSE(pDrm->peekCoherencyDisablePatchActive());
156+
pDrm->StoredDisableCoherencyPatchActive = 1;
157+
delete pDrm;
158+
}
159+
160+
TEST(DrmTest, GivenMockDrmWhenAskedForCoherencyStatusThatFailsThenFalseIsReturned) {
161+
Drm2 *pDrm = new Drm2;
162+
pDrm->StoredRetVal = -1;
163+
EXPECT_NE(nullptr, pDrm);
164+
165+
EXPECT_FALSE(pDrm->peekCoherencyDisablePatchActive());
166+
167+
pDrm->obtainCoherencyDisablePatchActive();
168+
169+
EXPECT_FALSE(pDrm->peekCoherencyDisablePatchActive());
170+
pDrm->StoredRetVal = 0;
171+
delete pDrm;
172+
}
173+
134174
TEST(DrmTest, GivenMockDrmWhenAskedFor48BitAddressCorrectValueReturned) {
135175
Drm2 *pDrm = new Drm2;
136176
pDrm->StoredPPGTT = 3;

0 commit comments

Comments
 (0)