Skip to content

Commit a555f28

Browse files
Don't unregister trim callback during process shutdown.
Resolves: NEO-4668 Signed-off-by: Piotr Zdunowski <[email protected]>
1 parent d80afd6 commit a555f28

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

opencl/test/unit_test/mocks/mock_wddm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class WddmMock : public Wddm {
118118
return Wddm::verifySharedHandle(osHandle);
119119
}
120120

121+
bool isShutdownInProgress() override {
122+
return shutdownStatus;
123+
};
124+
121125
void resetGdi(Gdi *gdi);
122126

123127
WddmMockHelpers::MakeResidentCall makeResidentResult;
@@ -158,6 +162,7 @@ class WddmMock : public Wddm {
158162
bool makeResidentStatus = true;
159163
bool callBaseMakeResident = true;
160164
bool callBaseCreatePagingLogger = true;
165+
bool shutdownStatus = false;
161166
};
162167

163168
struct GmockWddm : WddmMock {

opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -262,6 +262,16 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenWddmResidencyControllerWhenItIsD
262262
EXPECT_EQ(trimCallbackHandle, gdi->getUnregisterTrimNotificationArg().Handle);
263263
}
264264

265+
TEST_F(WddmResidencyControllerWithGdiTest, givenWddmResidencyControllerWhenItIsDestructedDuringProcessShutdownThenDontUnregisterTrimCallback) {
266+
wddm->shutdownStatus = true;
267+
268+
std::memset(&gdi->getUnregisterTrimNotificationArg(), 0, sizeof(D3DKMT_UNREGISTERTRIMNOTIFICATION));
269+
mockOsContextWin.reset();
270+
271+
EXPECT_EQ(nullptr, gdi->getUnregisterTrimNotificationArg().Callback);
272+
EXPECT_EQ(nullptr, gdi->getUnregisterTrimNotificationArg().Handle);
273+
}
274+
265275
TEST_F(WddmResidencyControllerTest, givenUsedAllocationWhenCallingRemoveFromTrimCandidateListIfUsedThenRemoveIt) {
266276
MockWddmAllocation allocation;
267277
residencyController->addToTrimCandidateList(&allocation);

shared/source/os_interface/windows/wddm/wddm.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,20 @@ VOID *Wddm::registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, Wd
959959
}
960960
return nullptr;
961961
}
962+
bool Wddm::isShutdownInProgress() {
963+
auto handle = GetModuleHandleA("ntdll.dll");
964+
965+
if (!handle) {
966+
return true;
967+
}
968+
969+
auto RtlDllShutdownInProgress = reinterpret_cast<BOOLEAN(WINAPI *)()>(GetProcAddress(handle, "RtlDllShutdownInProgress"));
970+
return RtlDllShutdownInProgress();
971+
}
962972

963973
void Wddm::unregisterTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, VOID *trimCallbackHandle) {
964974
DEBUG_BREAK_IF(callback == nullptr);
965-
if (trimCallbackHandle == nullptr) {
975+
if (trimCallbackHandle == nullptr || isShutdownInProgress()) {
966976
return;
967977
}
968978
D3DKMT_UNREGISTERTRIMNOTIFICATION unregisterTrimNotification;

shared/source/os_interface/windows/wddm/wddm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class Wddm {
9090
MOCKABLE_VIRTUAL void *virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned long type);
9191
MOCKABLE_VIRTUAL int virtualFree(void *ptr, size_t size, unsigned long flags);
9292

93+
MOCKABLE_VIRTUAL bool isShutdownInProgress();
94+
9395
bool configureDeviceAddressSpace();
9496

9597
GT_SYSTEM_INFO *getGtSysInfo() const {

0 commit comments

Comments
 (0)