Skip to content

Commit

Permalink
fix: fallback path while creating drm context
Browse files Browse the repository at this point in the history
- if create VM ioctl fails, fallback to query VM from created context
- in fallback path context's VM will not have flags applied

Related-To: NEO-7813

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
  • Loading branch information
HoppeMateusz authored and Compute-Runtime-Automation committed Jul 9, 2024
1 parent 778645c commit c660784
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
13 changes: 11 additions & 2 deletions shared/source/os_interface/linux/os_context_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ bool OsContextLinux::initializeContext(bool allocateInterrupt) {
[[maybe_unused]] auto ret = drm.createDrmVirtualMemory(drmVmId);
DEBUG_BREAK_IF(drmVmId == 0);
DEBUG_BREAK_IF(ret != 0);

if (ret != 0) {
return false;
drmVmId = 0;
}

UNRECOVERABLE_IF(this->drmVmIds.size() <= deviceIndex);
this->drmVmIds[deviceIndex] = drmVmId;
}
Expand All @@ -73,6 +73,15 @@ bool OsContextLinux::initializeContext(bool allocateInterrupt) {
return false;
}

if (drm.isPerContextVMRequired() && this->drmVmIds[deviceIndex] == 0) {
drmVmId = 0;
[[maybe_unused]] auto ret = drm.queryVmId(drmContextId, drmVmId);
DEBUG_BREAK_IF(drmVmId == 0);
DEBUG_BREAK_IF(ret != 0);

this->drmVmIds[deviceIndex] = drmVmId;
}

this->drmContextIds.push_back(drmContextId);
}
}
Expand Down
3 changes: 2 additions & 1 deletion shared/test/common/mocks/linux/mock_os_context_linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand All @@ -12,6 +12,7 @@ namespace NEO {
class MockOsContextLinux : public OsContextLinux {
public:
using OsContextLinux::drmContextIds;
using OsContextLinux::drmVmIds;
using OsContextLinux::fenceVal;
using OsContextLinux::pagingFence;

Expand Down
14 changes: 10 additions & 4 deletions shared/test/unit_test/os_interface/linux/drm_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h"
#include "shared/test/common/mocks/linux/mock_ioctl_helper.h"
#include "shared/test/common/mocks/linux/mock_os_context_linux.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_product_helper.h"
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/unit_test/mocks/linux/mock_os_context_linux.h"

#include "gtest/gtest.h"

Expand Down Expand Up @@ -728,9 +728,11 @@ TEST(DrmTest, givenPerContextVMRequiredWhenCreatingOsContextsThenExplicitVmIsCre
EXPECT_EQ(0u, drmMock.receivedGemVmControl.vmId);
EXPECT_EQ(drmMock.latestCreatedVmId, drmVmIds[0]);
EXPECT_EQ(1, drmMock.createDrmVmCalled);

EXPECT_EQ(0, drmMock.ioctlCount.contextGetParam);
}

TEST(DrmTest, givenPerContextVMRequiredWhenVmIdCreationFailsThenContextInitializationReturnsFalse) {
TEST(DrmTest, givenPerContextVMRequiredWhenVmIdCreationFailsThenQueryVmIsCalled) {
MockExecutionEnvironment executionEnvironment{};
auto &rootEnv = *executionEnvironment.rootDeviceEnvironments[0];

Expand All @@ -739,12 +741,16 @@ TEST(DrmTest, givenPerContextVMRequiredWhenVmIdCreationFailsThenContextInitializ

drmMock.storedRetValForVmCreate = -1;

OsContextLinux osContext(drmMock, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
MockOsContextLinux osContext(drmMock, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
drmMock.createDrmVmCalled = 0;
auto vmId = static_cast<uint32_t>(drmMock.storedRetValForVmId);

auto status = osContext.ensureContextInitialized(false);
EXPECT_EQ(1, drmMock.createDrmVmCalled);
EXPECT_EQ(1, drmMock.ioctlCount.contextGetParam);
EXPECT_EQ(osContext.drmVmIds[0], vmId);

EXPECT_FALSE(status);
EXPECT_TRUE(status);
}

TEST(DrmTest, givenPerContextVMRequiredWhenCreatingOsContextForSubDeviceThenVmIdPerContextIsCreateddAndStoredAtSubDeviceIndex) {
Expand Down

0 comments on commit c660784

Please sign in to comment.