From 380e2dcc350dd8690fdf6dd49355deea6cd29502 Mon Sep 17 00:00:00 2001 From: Kamil Diedrich Date: Thu, 20 Oct 2022 11:51:13 +0200 Subject: [PATCH] [WSL2] Avoid gdi calls while process exit Related-To: NEO-7380 Signed-off-by: Kamil Diedrich --- .../device/device_drm_or_wddm/test_device.cpp | 2 +- opencl/source/platform/platform.cpp | 2 + .../execution_environment_tests.cpp | 45 ++++++++++++++++--- .../root_device_environment.cpp | 2 +- shared/source/os_interface/os_interface.h | 2 +- .../skip_resource_cleanup_drm_or_wddm.cpp | 2 +- .../wddm/skip_resource_cleanup_wddm.cpp | 2 +- .../source/os_interface/windows/wddm/wddm.h | 2 +- .../os_interface/windows/wddm_fixture.h | 2 +- .../os_interface/linux/drm_tests.cpp | 2 +- ..._device_address_space_drm_or_wddm_test.cpp | 4 +- .../windows/os_context_win_tests.cpp | 2 +- .../os_interface/windows/wddm_tests.cpp | 2 +- 13 files changed, 53 insertions(+), 18 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/device/device_drm_or_wddm/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/device_drm_or_wddm/test_device.cpp index fd8b11ae42..a271862bd9 100644 --- a/level_zero/core/test/unit_tests/sources/device/device_drm_or_wddm/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/device_drm_or_wddm/test_device.cpp @@ -48,7 +48,7 @@ class MockDriverModelWDDMLUID : public NEO::Wddm { return true; } - bool isDriverAvaliable() override { + bool isDriverAvailable() override { return false; } diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 08ca3c907d..440da3028c 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -44,6 +44,8 @@ Platform::Platform(ExecutionEnvironment &executionEnvironmentIn) : executionEnvi } Platform::~Platform() { + executionEnvironment.prepareForCleanup(); + for (auto clDevice : this->clDevices) { clDevice->getDevice().getRootDeviceEnvironmentRef().debugger.reset(nullptr); clDevice->decRefInternal(); diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index f7768a00cd..6975e0ac43 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -271,15 +271,15 @@ TEST(ExecutionEnvironment, givenMultipleRootDevicesWhenTheyAreCreatedThenReuseMe EXPECT_EQ(memoryManager, device2->getMemoryManager()); } -uint64_t isDriverAvaliableCounter = 0u; +uint64_t isDriverAvailableCounter = 0u; class DriverModelMock : public DriverModel { public: DriverModelMock(DriverModelType driverModelType) : DriverModel(driverModelType) { } - bool isDriverAvaliable() override { - isDriverAvaliableCounter++; + bool isDriverAvailable() override { + isDriverAvailableCounter++; return true; } void setGmmInputArgs(void *args) override { @@ -305,8 +305,39 @@ class DriverModelMock : public DriverModel { } }; -TEST(ExecutionEnvironment, givenRootDeviceWhenPrepareForCleanupThenIsDriverAvaliableIsCalled) { - VariableBackup varBackup = &isDriverAvaliableCounter; +class DefaultDriverModelMock : public DriverModel { + public: + DefaultDriverModelMock(DriverModelType driverModelType) : DriverModel(driverModelType) { + } + + bool isDriverAvailable() override { + return true; + } + void setGmmInputArgs(void *args) override { + } + + uint32_t getDeviceHandle() const override { + return 0; + } + + PhysicalDevicePciBusInfo getPciBusInfo() const override { + return {}; + } + PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override { + return {}; + } + + bool skipResourceCleanup() const { + return skipResourceCleanupVar; + } + + bool isGpuHangDetected(OsContext &osContext) override { + return false; + } +}; + +TEST(ExecutionEnvironment, givenRootDeviceWhenPrepareForCleanupThenIsDriverAvailableIsCalled) { + VariableBackup varBackup = &isDriverAvailableCounter; ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); std::unique_ptr osInterface = std::make_unique(); @@ -317,7 +348,9 @@ TEST(ExecutionEnvironment, givenRootDeviceWhenPrepareForCleanupThenIsDriverAvali executionEnvironment->prepareForCleanup(); - EXPECT_EQ(1u, isDriverAvaliableCounter); + EXPECT_EQ(1u, isDriverAvailableCounter); + + executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique(DriverModelType::UNKNOWN)); } TEST(ExecutionEnvironment, givenUnproperSetCsrFlagValueWhenInitializingMemoryManagerThenCreateDefaultMemoryManager) { diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index f68e4207e0..47f8552cd9 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -87,7 +87,7 @@ GmmClientContext *RootDeviceEnvironment::getGmmClientContext() const { void RootDeviceEnvironment::prepareForCleanup() const { if (osInterface && osInterface->getDriverModel()) { - osInterface->getDriverModel()->isDriverAvaliable(); + osInterface->getDriverModel()->isDriverAvailable(); } } diff --git a/shared/source/os_interface/os_interface.h b/shared/source/os_interface/os_interface.h index c1d371dbc2..ce3d34caec 100644 --- a/shared/source/os_interface/os_interface.h +++ b/shared/source/os_interface/os_interface.h @@ -85,7 +85,7 @@ class DriverModel : public NonCopyableClass { return std::numeric_limits::max(); } - virtual bool isDriverAvaliable() { + virtual bool isDriverAvailable() { return true; } diff --git a/shared/source/os_interface/windows/wddm/skip_resource_cleanup_drm_or_wddm.cpp b/shared/source/os_interface/windows/wddm/skip_resource_cleanup_drm_or_wddm.cpp index 36ee7c6a04..589297be3c 100644 --- a/shared/source/os_interface/windows/wddm/skip_resource_cleanup_drm_or_wddm.cpp +++ b/shared/source/os_interface/windows/wddm/skip_resource_cleanup_drm_or_wddm.cpp @@ -30,7 +30,7 @@ NTSTATUS closeAdapterNoOp(const D3DKMT_CLOSEADAPTER *closeAdapter) { return STATUS_SUCCESS; } -bool Wddm::isDriverAvaliable() { +bool Wddm::isDriverAvailable() { D3DKMT_GETDEVICESTATE deviceState = {}; deviceState.hDevice = device; deviceState.StateType = D3DKMT_DEVICESTATE_PRESENT; diff --git a/shared/source/os_interface/windows/wddm/skip_resource_cleanup_wddm.cpp b/shared/source/os_interface/windows/wddm/skip_resource_cleanup_wddm.cpp index 3765feddac..944db4112e 100644 --- a/shared/source/os_interface/windows/wddm/skip_resource_cleanup_wddm.cpp +++ b/shared/source/os_interface/windows/wddm/skip_resource_cleanup_wddm.cpp @@ -9,7 +9,7 @@ namespace NEO { -bool Wddm::isDriverAvaliable() { +bool Wddm::isDriverAvailable() { return true; } diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 8d54aef0b8..050b83d9ef 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -199,7 +199,7 @@ class Wddm : public DriverModel { PhysicalDevicePciBusInfo getPciBusInfo() const override; size_t getMaxMemAllocSize() const override; - bool isDriverAvaliable() override; + bool isDriverAvailable() override; static std::vector> discoverDevices(ExecutionEnvironment &executionEnvironment); diff --git a/shared/test/common/os_interface/windows/wddm_fixture.h b/shared/test/common/os_interface/windows/wddm_fixture.h index 0f1bfe9996..8c3eb5373c 100644 --- a/shared/test/common/os_interface/windows/wddm_fixture.h +++ b/shared/test/common/os_interface/windows/wddm_fixture.h @@ -132,7 +132,7 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture, public MockExecutionEnv struct NoCleanupWddmMock : WddmMock { using WddmMock::WddmMock; - bool isDriverAvaliable() override { + bool isDriverAvailable() override { return false; } diff --git a/shared/test/unit_test/os_interface/linux/drm_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_tests.cpp index 87fb7d05b9..5e084b4f2c 100644 --- a/shared/test/unit_test/os_interface/linux/drm_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_tests.cpp @@ -1141,7 +1141,7 @@ TEST(DrmQueryTest, GivenRpsMaxFreqFileDoesntExistWhenFrequencyIsQueriedThenFallb TEST(DrmTest, whenCheckedIfResourcesCleanupCanBeSkippedThenReturnsFalse) { auto executionEnvironment = std::make_unique(); DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]); - EXPECT_TRUE(pDrm->isDriverAvaliable()); + EXPECT_TRUE(pDrm->isDriverAvailable()); EXPECT_FALSE(pDrm->skipResourceCleanup()); delete pDrm; } diff --git a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp index abf7bcb6a1..b6d8ab77a7 100644 --- a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp +++ b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp @@ -643,14 +643,14 @@ TEST_F(WddmLinuxTest, givenRequestFor32bitAllocationWithoutPreexistingHostPtrWhe TEST_F(WddmLinuxTest, whenCheckedIfResourcesCleanupCanBeSkippedAndDeviceIsAliveThenReturnsFalse) { osEnvironment->gdi->getDeviceState = getDeviceStateMock; gdiMockConfig.getDeviceStateClb.returnValue = STATUS_SUCCESS; - EXPECT_TRUE(this->wddm->isDriverAvaliable()); + EXPECT_TRUE(this->wddm->isDriverAvailable()); EXPECT_EQ(1, gdiMockConfig.getDeviceStateClb.callCount); } TEST_F(WddmLinuxTest, whenCheckedIfResourcesCleanupCanBeSkippedAndDeviceIsLostThenReturnsTrue) { osEnvironment->gdi->getDeviceState = getDeviceStateMock; gdiMockConfig.getDeviceStateClb.returnValue = -1; - EXPECT_FALSE(this->wddm->isDriverAvaliable()); + EXPECT_FALSE(this->wddm->isDriverAvailable()); EXPECT_EQ(0, this->wddm->getGdi()->destroyAllocation2(nullptr)); EXPECT_EQ(0, this->wddm->getGdi()->waitForSynchronizationObjectFromCpu(nullptr)); EXPECT_EQ(0, this->wddm->getGdi()->destroyPagingQueue(nullptr)); diff --git a/shared/test/unit_test/os_interface/windows/os_context_win_tests.cpp b/shared/test/unit_test/os_interface/windows/os_context_win_tests.cpp index f1c89c8eb7..51af8c308f 100644 --- a/shared/test/unit_test/os_interface/windows/os_context_win_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/os_context_win_tests.cpp @@ -83,7 +83,7 @@ struct OsContextWinTestNoCleanup : public WddmTestWithMockGdiDllNoCleanup { TEST_F(OsContextWinTestNoCleanup, givenReinitializeContextWhenContextIsInitThenContextIsNotDestroyed) { osContext = std::make_unique(*osInterface->getDriverModel()->as(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engineTypeUsage, preemptionMode)); - EXPECT_FALSE(this->wddm->isDriverAvaliable()); + EXPECT_FALSE(this->wddm->isDriverAvailable()); EXPECT_TRUE(this->wddm->skipResourceCleanup()); EXPECT_NO_THROW(osContext->reInitializeContext()); EXPECT_NO_THROW(osContext->ensureContextInitialized()); diff --git a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp index b351cdc34f..0c6da87bf9 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp @@ -75,7 +75,7 @@ TEST_F(WddmTests, givenWddmWhenPassesIncorrectHandleToVerifyNTHandleThenReturnFa TEST_F(WddmTests, whenCheckedIfResourcesCleanupCanBeSkippedThenReturnsFalse) { init(); EXPECT_FALSE(wddm->skipResourceCleanup()); - EXPECT_TRUE(wddm->isDriverAvaliable()); + EXPECT_TRUE(wddm->isDriverAvailable()); } TEST_F(WddmTests, whenCheckedIfDebugAttachAvailableThenReturnsFalse) {