Add DRM capability to create a virtual memory address space on Linux

Related-To: NEO-4821

Change-Id: Iefc17d6c0a3649791b9a9b15791a6d263399873d
Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek
2020-07-07 09:34:31 +02:00
committed by sys_ocldev
parent 4e1d96f7c3
commit 519e75e3d6
15 changed files with 152 additions and 29 deletions

View File

@@ -354,7 +354,7 @@ TEST_F(DrmTests, failOnContextCreate) {
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
EXPECT_NE(drm, nullptr);
failOnContextCreate = -1;
EXPECT_THROW(drm->createDrmContext(), std::exception);
EXPECT_THROW(drm->createDrmContext(1), std::exception);
EXPECT_FALSE(drm->isPreemptionSupported());
failOnContextCreate = 0;
}
@@ -365,7 +365,7 @@ TEST_F(DrmTests, failOnSetPriority) {
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
EXPECT_NE(drm, nullptr);
failOnSetPriority = -1;
auto drmContext = drm->createDrmContext();
auto drmContext = drm->createDrmContext(1);
EXPECT_THROW(drm->setLowPriorityContextParam(drmContext), std::exception);
EXPECT_FALSE(drm->isPreemptionSupported());
failOnSetPriority = 0;
@@ -404,7 +404,7 @@ TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenEx
TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCreated) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
auto drm = new DrmMockSuccess(*executionEnvironment.rootDeviceEnvironments[0]);
auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(drm);
@@ -417,6 +417,26 @@ TEST(OsInterfaceTests, givenOsInterfaceWhenEnableLocalMemoryIsSpecifiedThenItIsS
EXPECT_TRUE(OSInterface::osEnableLocalMemory);
}
TEST_F(DrmTests, whenDrmIsCreatedWithMultipleSubDevicesThenCreateMultipleVirtualMemoryAddressSpaces) {
DebugManagerStateRestore restore;
DebugManager.flags.CreateMultipleSubDevices.set(2);
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
EXPECT_NE(drm, nullptr);
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
for (auto id = 0u; id < numSubDevices; id++) {
EXPECT_EQ(id + 1, drm->getVirtualMemoryAddressSpace(id));
}
}
TEST_F(DrmTests, givenDrmIsCreatedWhenCreateVirtualMemoryFailsThenCallAbort) {
VariableBackup<decltype(failOnVirtualMemoryCreate)> backupFailOnVirtaualMemoryCreate(&failOnVirtualMemoryCreate);
failOnVirtualMemoryCreate = -1;
EXPECT_THROW(DrmWrap::createDrm(*rootDeviceEnvironment), std::exception);
}
int main(int argc, char **argv) {
bool useDefaultListener = false;

View File

@@ -22,6 +22,7 @@ int haveSoftPin = 1;
int havePreemption = I915_SCHEDULER_CAP_ENABLED |
I915_SCHEDULER_CAP_PRIORITY |
I915_SCHEDULER_CAP_PREEMPTION;
int vmId = 0;
int failOnDeviceId = 0;
int failOnEuTotal = 0;
int failOnSubsliceTotal = 0;
@@ -31,6 +32,7 @@ int failOnParamBoost = 0;
int failOnSetParamSseu = 0;
int failOnGetParamSseu = 0;
int failOnContextCreate = 0;
int failOnVirtualMemoryCreate = 0;
int failOnSetPriority = 0;
int failOnPreemption = 0;
int failOnDrmVersion = 0;
@@ -188,6 +190,20 @@ int drmContextDestroy(drm_i915_gem_context_destroy *destroy) {
return -1;
}
int drmVirtualMemoryCreate(drm_i915_gem_vm_control *control) {
assert(control);
control->vm_id = ++vmId;
return failOnVirtualMemoryCreate;
}
int drmVirtualMemoryDestroy(drm_i915_gem_vm_control *control) {
assert(control);
vmId--;
return (control->vm_id > 0) ? 0 : -1;
}
int drmVersion(drm_version_t *version) {
strcpy(version->name, providedDrmVersion);
@@ -241,6 +257,12 @@ int ioctl(int fd, unsigned long int request, ...) throw() {
case DRM_IOCTL_I915_GEM_CONTEXT_DESTROY:
res = drmContextDestroy(va_arg(vl, drm_i915_gem_context_destroy *));
break;
case DRM_IOCTL_I915_GEM_VM_CREATE:
res = drmVirtualMemoryCreate(va_arg(vl, drm_i915_gem_vm_control *));
break;
case DRM_IOCTL_I915_GEM_VM_DESTROY:
res = drmVirtualMemoryDestroy(va_arg(vl, drm_i915_gem_vm_control *));
break;
case DRM_IOCTL_VERSION:
res = drmVersion(va_arg(vl, drm_version_t *));
break;

View File

@@ -33,6 +33,7 @@ extern int fakeFd;
extern int haveDri; // index of dri to serve, -1 - none
extern int deviceId; // known DeviceID
extern int haveSoftPin;
extern int vmId;
extern int failOnDeviceId;
extern int failOnEuTotal;
extern int failOnSubsliceTotal;
@@ -40,6 +41,7 @@ extern int failOnRevisionId;
extern int failOnSoftPin;
extern int failOnParamBoost;
extern int failOnContextCreate;
extern int failOnVirtualMemoryCreate;
extern int failOnSetPriority;
extern int failOnPreemption;
extern int havePreemption;

View File

@@ -24,7 +24,7 @@ TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenProperFileDescriptorI
auto osInterface = new OSInterface();
rootDeviceEnvironment->osInterface.reset(osInterface);
auto drm = new DrmMock(*rootDeviceEnvironment);
auto drm = new DrmMock(fakeFd, *rootDeviceEnvironment);
osInterface->get()->setDrm(drm);
GMM_INIT_IN_ARGS gmmInputArgs = {};