diff --git a/core/os_interface/linux/drm_neo.cpp b/core/os_interface/linux/drm_neo.cpp index 8c8f98622d..caf69b2259 100644 --- a/core/os_interface/linux/drm_neo.cpp +++ b/core/os_interface/linux/drm_neo.cpp @@ -212,16 +212,10 @@ bool Drm::setQueueSliceCount(uint64_t sliceCount) { return false; } -void Drm::checkNonPersistentContextsSupport() { +void Drm::checkContextPersistenceChangeSupport() { drm_i915_gem_context_param contextParam = {}; contextParam.param = I915_CONTEXT_PARAM_PERSISTENCE; - - auto retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &contextParam); - if (retVal == 0 && contextParam.value == 1) { - nonPersistentContextsSupported = true; - } else { - nonPersistentContextsSupported = false; - } + contextPersistenceChangeSupported = (ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &contextParam) == 0); } void Drm::setNonPersistentContext(uint32_t drmContextId) { @@ -229,7 +223,12 @@ void Drm::setNonPersistentContext(uint32_t drmContextId) { contextParam.ctx_id = drmContextId; contextParam.param = I915_CONTEXT_PARAM_PERSISTENCE; - ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam); + auto retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam); + if (retVal == ENODEV) { + contextPersistenceChangeSupported = false; + } else { + UNRECOVERABLE_IF(retVal != 0); + } } uint32_t Drm::createDrmContext() { diff --git a/core/os_interface/linux/drm_neo.h b/core/os_interface/linux/drm_neo.h index 67f9c06ffd..59e501c46c 100644 --- a/core/os_interface/linux/drm_neo.h +++ b/core/os_interface/linux/drm_neo.h @@ -83,8 +83,8 @@ class Drm { bool queryMemoryInfo(); int setupHardwareInfo(DeviceDescriptor *, bool); - bool areNonPersistentContextsSupported() const { return nonPersistentContextsSupported; } - void checkNonPersistentContextsSupport(); + bool isContextPersistenceChangeSupported() const { return contextPersistenceChangeSupported; } + void checkContextPersistenceChangeSupport(); void setNonPersistentContext(uint32_t drmContextId); MemoryInfo *getMemoryInfo() const { @@ -99,8 +99,8 @@ class Drm { bool sliceCountChangeSupported = false; drm_i915_gem_context_param_sseu sseu{}; bool preemptionSupported = false; - bool nonPersistentContextsSupported = false; std::unique_ptr hwDeviceId; + bool contextPersistenceChangeSupported = false; int deviceId = 0; int revisionId = 0; GTTYPE eGtType = GTTYPE_UNDEFINED; diff --git a/core/os_interface/linux/hw_info_config.cpp b/core/os_interface/linux/hw_info_config.cpp index 8740790d60..f94a844922 100644 --- a/core/os_interface/linux/hw_info_config.cpp +++ b/core/os_interface/linux/hw_info_config.cpp @@ -161,7 +161,7 @@ int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *ou outHwInfo->capabilityTable.ftrRenderCompressedBuffers = false; outHwInfo->capabilityTable.ftrRenderCompressedImages = false; drm->checkQueueSliceSupport(); - drm->checkNonPersistentContextsSupport(); + drm->checkContextPersistenceChangeSupport(); drm->checkPreemptionSupport(); bool preemption = drm->isPreemptionSupported(); PreemptionHelper::adjustDefaultPreemptionMode(outHwInfo->capabilityTable, diff --git a/core/os_interface/linux/os_context_linux.cpp b/core/os_interface/linux/os_context_linux.cpp index 66f5875399..312a62e161 100644 --- a/core/os_interface/linux/os_context_linux.cpp +++ b/core/os_interface/linux/os_context_linux.cpp @@ -27,7 +27,7 @@ OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, DeviceBitfield devi for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) { if (deviceBitfield.test(deviceIndex)) { auto drmContextId = drm.createDrmContext(); - if (drm.areNonPersistentContextsSupported()) { + if (drm.isContextPersistenceChangeSupported()) { drm.setNonPersistentContext(drmContextId); } if (drm.isPreemptionSupported() && lowPriority) { diff --git a/unit_tests/os_interface/linux/drm_mock.cpp b/unit_tests/os_interface/linux/drm_mock.cpp index 45430b5a1c..253addd25e 100644 --- a/unit_tests/os_interface/linux/drm_mock.cpp +++ b/unit_tests/os_interface/linux/drm_mock.cpp @@ -88,7 +88,7 @@ int DrmMock::ioctl(unsigned long request, void *arg) { return this->StoredRetValForSetSSEU; } if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PERSISTENCE) { - return this->StoredRetValForPersistant; + return this->StoredRetValForPersistent; } } @@ -106,8 +106,7 @@ int DrmMock::ioctl(unsigned long request, void *arg) { return this->StoredRetValForGetSSEU; } if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PERSISTENCE) { - static_cast(arg)->value = this->StoredPersistentContextsSupport; - return this->StoredRetValForPersistant; + return this->StoredRetValForPersistent; } } diff --git a/unit_tests/os_interface/linux/drm_mock.h b/unit_tests/os_interface/linux/drm_mock.h index b7d804684a..0fa787ef83 100644 --- a/unit_tests/os_interface/linux/drm_mock.h +++ b/unit_tests/os_interface/linux/drm_mock.h @@ -24,10 +24,10 @@ using namespace NEO; class DrmMock : public Drm { public: using Drm::checkQueueSliceSupport; + using Drm::contextPersistenceChangeSupported; using Drm::engineInfo; using Drm::getQueueSliceCount; using Drm::memoryInfo; - using Drm::nonPersistentContextsSupported; using Drm::preemptionSupported; using Drm::query; using Drm::sliceCountChangeSupported; @@ -90,7 +90,6 @@ class DrmMock : public Drm { int StoredDeviceRevID = 1; int StoredHasPooledEU = 1; int StoredMinEUinPool = 1; - int StoredPersistentContextsSupport = 1; int StoredRetVal = 0; int StoredRetValForGetGttSize = 0; int StoredRetValForGetSSEU = 0; @@ -101,7 +100,7 @@ class DrmMock : public Drm { int StoredRetValForDeviceRevID = 0; int StoredRetValForPooledEU = 0; int StoredRetValForMinEUinPool = 0; - int StoredRetValForPersistant = 0; + int StoredRetValForPersistent = 0; int StoredPreemptionSupport = I915_SCHEDULER_CAP_ENABLED | I915_SCHEDULER_CAP_PRIORITY | diff --git a/unit_tests/os_interface/linux/drm_tests.cpp b/unit_tests/os_interface/linux/drm_tests.cpp index f9de0c730a..b00263344e 100644 --- a/unit_tests/os_interface/linux/drm_tests.cpp +++ b/unit_tests/os_interface/linux/drm_tests.cpp @@ -197,7 +197,7 @@ TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) EXPECT_EQ(0u, drmMock.receivedContextParamRequestCount); } -TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextIsCreatedThenReceivedContextParamRequestCountReturnsCorrectValue) { +TEST(DrmTest, givenDrmAndNegativeCheckContextPersistenceChangeSupportWhenOsContextIsCreatedThenReceivedContextParamRequestCountReturnsCorrectValue) { DrmMock drmMock; uint32_t drmContextId1 = 123; @@ -205,15 +205,15 @@ TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextI auto expectedCount = 0u; { - drmMock.StoredRetValForPersistant = -1; - drmMock.checkNonPersistentContextsSupport(); + drmMock.StoredRetValForPersistent = -1; + drmMock.checkContextPersistenceChangeSupport(); ++expectedCount; OsContextLinux osContext(drmMock, 0u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount); } { - drmMock.StoredRetValForPersistant = 0; - drmMock.checkNonPersistentContextsSupport(); + drmMock.StoredRetValForPersistent = 0; + drmMock.checkContextPersistenceChangeSupport(); ++expectedCount; OsContextLinux osContext(drmMock, 0u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); ++expectedCount; @@ -221,6 +221,29 @@ TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextI } } +TEST(DrmTest, givenUnsupportedPlatformWhenOsContextIsCreatedAndThenIsContextPersistenceChangeSupportedReturnsFalse) { + + DrmMock drmMock; + uint32_t drmContextId1 = 123; + drmMock.StoredCtxId = drmContextId1; + auto expectedCount = 0u; + auto unsupportedPlatformErrorCode = ENODEV; + + drmMock.StoredRetValForPersistent = 0; + drmMock.checkContextPersistenceChangeSupport(); + ++expectedCount; + + { + EXPECT_TRUE(drmMock.isContextPersistenceChangeSupported()); + drmMock.StoredRetValForPersistent = unsupportedPlatformErrorCode; + OsContextLinux osContext(drmMock, 0u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + ++expectedCount; + EXPECT_FALSE(drmMock.isContextPersistenceChangeSupported()); + } + + EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount); +} + TEST(DrmTest, givenDrmPreemptionEnabledAndLowPriorityEngineWhenCreatingOsContextThenCallSetContextPriorityIoctl) { DrmMock drmMock; drmMock.StoredCtxId = 123; @@ -354,14 +377,14 @@ TEST(DrmTest, givenPlatformWhereGetSseuRetFailureWhenCallSetQueueSliceCountThenS EXPECT_NE(drm->getSliceMask(newSliceCount), drm->storedParamSseu); } -TEST(DrmTest, whenCheckNonPeristentSupportIsCalledThenAreNonPersistentContextsSupportedReturnsCorrectValues) { +TEST(DrmTest, whenCheckContextPersistenceChangeSupportIsCalledThenIsContextPersistenceChangeSupportedReturnsCorrectValues) { std::unique_ptr drm = std::make_unique(); - drm->StoredRetValForPersistant = -1; - drm->checkNonPersistentContextsSupport(); - EXPECT_FALSE(drm->areNonPersistentContextsSupported()); - drm->StoredRetValForPersistant = 0; - drm->checkNonPersistentContextsSupport(); - EXPECT_TRUE(drm->areNonPersistentContextsSupported()); + drm->StoredRetValForPersistent = -1; + drm->checkContextPersistenceChangeSupport(); + EXPECT_FALSE(drm->isContextPersistenceChangeSupported()); + drm->StoredRetValForPersistent = 0; + drm->checkContextPersistenceChangeSupport(); + EXPECT_TRUE(drm->isContextPersistenceChangeSupported()); } TEST(DrmTest, givenPlatformWhereSetSseuRetFailureWhenCallSetQueueSliceCountThenReturnFalse) { diff --git a/unit_tests/os_interface/linux/hw_info_config_linux_tests.cpp b/unit_tests/os_interface/linux/hw_info_config_linux_tests.cpp index 7cea68df7c..92c5d32406 100644 --- a/unit_tests/os_interface/linux/hw_info_config_linux_tests.cpp +++ b/unit_tests/os_interface/linux/hw_info_config_linux_tests.cpp @@ -267,17 +267,17 @@ TEST_F(HwInfoConfigTestLinuxDummy, dummyNegativeUnknownDeviceId) { EXPECT_EQ(-1, ret); } -TEST_F(HwInfoConfigTestLinuxDummy, whenConfigureHwInfoIsCalledThenAreNonPersistentContextsSupportedReturnsTrue) { +TEST_F(HwInfoConfigTestLinuxDummy, whenConfigureHwInfoIsCalledThenIsContextPersistenceChangeSupportedReturnsTrue) { int ret = hwConfig.configureHwInfo(&pInHwInfo, &outHwInfo, osInterface); EXPECT_EQ(0, ret); - EXPECT_TRUE(drm->areNonPersistentContextsSupported()); + EXPECT_TRUE(drm->isContextPersistenceChangeSupported()); } -TEST_F(HwInfoConfigTestLinuxDummy, whenConfigureHwInfoIsCalledAndPersitentContextIsUnsupportedThenAreNonPersistentContextsSupportedReturnsFalse) { - drm->StoredPersistentContextsSupport = 0; +TEST_F(HwInfoConfigTestLinuxDummy, whenConfigureHwInfoIsCalledAndPersitentContextIsUnsupportedThenIsContextPersistenceChangeSupportedReturnsFalse) { + drm->StoredRetValForPersistent = -1; int ret = hwConfig.configureHwInfo(&pInHwInfo, &outHwInfo, osInterface); EXPECT_EQ(0, ret); - EXPECT_FALSE(drm->areNonPersistentContextsSupported()); + EXPECT_FALSE(drm->isContextPersistenceChangeSupported()); } TEST_F(HwInfoConfigTestLinuxDummy, dummyConfigPreemptionDrmEnabledMidThreadOn) {