Skip to content

Commit ca4af1d

Browse files
Add helpers for page fault support
Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent 7d109c4 commit ca4af1d

File tree

9 files changed

+59
-0
lines changed

9 files changed

+59
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,14 @@ TEST_F(DrmBufferObjectTest, given48bitAddressWhenSetThenAddressIsCanonized) {
532532
auto boAddress = bo.peekAddress();
533533
EXPECT_EQ(boAddress, expectedAddress);
534534
}
535+
536+
TEST_F(DrmBufferObjectTest, whenBoRequiresExplicitResidencyThenTheCorrespondingQueryReturnsCorrectValue) {
537+
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
538+
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
539+
MockBufferObject bo(&drm, 0, 0, 1);
540+
541+
for (auto required : {false, true}) {
542+
bo.requireExplicitResidency(required);
543+
EXPECT_EQ(required, bo.isExplicitResidencyRequired());
544+
}
545+
}

shared/source/os_interface/linux/drm_allocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void DrmAllocation::registerBOBindExtHandle(Drm *drm) {
138138
}
139139

140140
bo->requireImmediateBinding(true);
141+
bo->requireExplicitResidency(!shouldAllocationPageFault(drm));
141142
}
142143
}
143144
}

shared/source/os_interface/linux/drm_allocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class DrmAllocation : public GraphicsAllocation {
8888
void freeRegisteredBOBindExtHandles(Drm *drm);
8989
void linkWithRegisteredHandle(uint32_t handle);
9090
MOCKABLE_VIRTUAL void markForCapture();
91+
bool shouldAllocationPageFault(Drm *drm);
9192

9293
protected:
9394
BufferObjects bufferObjects{};

shared/source/os_interface/linux/drm_allocation_extended.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ bool DrmAllocation::setMemAdvise(Drm *drm, MemAdviseFlags flags) {
4242
return true;
4343
}
4444

45+
bool DrmAllocation::shouldAllocationPageFault(Drm *drm) {
46+
return false;
47+
}
48+
4549
} // namespace NEO

shared/source/os_interface/linux/drm_buffer_object.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ class BufferObject {
9191
requiresImmediateBinding = required;
9292
}
9393

94+
bool isExplicitResidencyRequired() {
95+
return requiresExplicitResidency;
96+
}
97+
void requireExplicitResidency(bool required) {
98+
requiresExplicitResidency = required;
99+
}
100+
94101
void setCacheRegion(CacheRegion regionIndex) { cacheRegion = regionIndex; }
95102
CacheRegion peekCacheRegion() const { return cacheRegion; }
96103

@@ -133,6 +140,7 @@ class BufferObject {
133140
uint32_t tiling_mode;
134141
bool allowCapture = false;
135142
bool requiresImmediateBinding = false;
143+
bool requiresExplicitResidency = false;
136144

137145
uint32_t getOsContextId(OsContext *osContext);
138146
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);

shared/source/os_interface/linux/drm_neo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class Drm : public DriverModel {
172172
MOCKABLE_VIRTUAL bool isVmBindAvailable();
173173
MOCKABLE_VIRTUAL bool registerResourceClasses();
174174

175+
void queryPageFaultSupport();
176+
bool hasPageFaultSupport();
177+
175178
MOCKABLE_VIRTUAL uint32_t registerResource(ResourceClass classType, const void *data, size_t size);
176179
MOCKABLE_VIRTUAL void unregisterResource(uint32_t handle);
177180
MOCKABLE_VIRTUAL uint32_t registerIsaCookie(uint32_t isaHandle);
@@ -323,6 +326,7 @@ class Drm : public DriverModel {
323326
bool bindAvailable = false;
324327
bool directSubmissionActive = false;
325328
bool contextDebugSupported = false;
329+
bool pageFaultSupported = false;
326330

327331
private:
328332
int getParamIoctl(int param, int *dstValue);

shared/source/os_interface/linux/drm_query_extended.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,11 @@ uint32_t Drm::createDrmContextExt(drm_i915_gem_context_create_ext &gcc, uint32_t
7171
void Drm::appendDrmContextFlags(drm_i915_gem_context_create_ext &gcc, bool isSpecialContextRequested) {
7272
}
7373

74+
void Drm::queryPageFaultSupport() {
75+
}
76+
77+
bool Drm::hasPageFaultSupport() {
78+
return false;
79+
}
80+
7481
} // namespace NEO

shared/test/common/os_interface/linux/drm_neo_create.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
5252
if (!drm->isPerContextVMRequired()) {
5353
drm->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
5454
}
55+
56+
drm->queryPageFaultSupport();
57+
5558
return drm;
5659
}
5760

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "shared/source/os_interface/os_interface.h"
1212
#include "shared/test/common/helpers/default_hw_info.h"
1313
#include "shared/test/common/libult/linux/drm_mock.h"
14+
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
1415

1516
#include "test.h"
1617

@@ -115,3 +116,22 @@ TEST(DrmQueryTest, givenIoctlParamWhenParseToStringThenProperStringIsReturned) {
115116
EXPECT_STREQ(IoctlHelper::getIoctlParamString(ioctlParamCodeString.first).c_str(), ioctlParamCodeString.second);
116117
}
117118
}
119+
120+
TEST(DrmQueryTest, WhenCallingQueryPageFaultSupportThenReturnFalse) {
121+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
122+
executionEnvironment->prepareRootDeviceEnvironments(1);
123+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
124+
125+
drm.queryPageFaultSupport();
126+
127+
EXPECT_FALSE(drm.hasPageFaultSupport());
128+
}
129+
130+
TEST(DrmQueryTest, givenDrmAllocationWhenShouldAllocationFaultIsCalledThenReturnFalse) {
131+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
132+
executionEnvironment->prepareRootDeviceEnvironments(1);
133+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
134+
135+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::MemoryNull);
136+
EXPECT_FALSE(allocation.shouldAllocationPageFault(&drm));
137+
}

0 commit comments

Comments
 (0)