Deferred deletion of allocations in main thread

Add a clearQueueTillFirstFailure interface to DeferredDeleter, which
iterates the queue from the front and delete the allocations in the
queue till a failure. It is called by defer deletion of allocations
occupied by mutliple contexts to unlock the execution in main thread

Related-To: NEO-7532

Signed-off-by: HeFan2017 <fan.f.he@intel.com>
This commit is contained in:
HeFan2017
2022-12-12 10:57:02 +00:00
committed by Compute-Runtime-Automation
parent a572f6ce95
commit c268e30189
13 changed files with 159 additions and 23 deletions

View File

@@ -2204,7 +2204,7 @@ HWTEST_F(GraphicsAllocationTests, givenAllocationUsedByManyOsContextsWhenCheckin
auto memoryManager = new MockMemoryManager(false, false, *executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
auto multiContextDestructor = new MockDeferredDeleter();
multiContextDestructor->expectDrainBlockingValue(false);
multiContextDestructor->expectClearQueueTillFirstFailure();
memoryManager->multiContextResourceDestructor.reset(multiContextDestructor);
auto device = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(executionEnvironment, 0u));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -30,7 +30,7 @@ struct ClearQueueTest : public ::testing::Test,
static void threadMethod(MockDeferredDeleter *deleter) {
while (!startClear)
;
deleter->clearQueue();
deleter->clearQueue(false);
threadStopped++;
}
MockDeferrableDeletion *createDeletion() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -224,3 +224,20 @@ TEST_F(DeferredDeleterTest, givenDeferredDeleterWhenNonBlockingDrainIsCalledThen
EXPECT_EQ(0, deleter->areElementsReleasedCalled);
EXPECT_EQ(1, deleter->drainCalled);
}
TEST_F(DeferredDeleterTest, GivenAsyncThreadStartedThenCallClearQueueTillFirstFailure) {
deleter->DeferredDeleter::addClient();
waitForAsyncThread();
auto deletion = createDeletion();
deleter->DeferredDeleter::deferDeletion(deletion);
deleter->clearQueueTillFirstFailure();
EXPECT_TRUE(deleter->isThreadRunning());
EXPECT_TRUE(deleter->isWorking());
EXPECT_EQ(0, deleter->clearCalledWithBreakTillFailure);
deleter->allowEarlyStopThread();
deleter->DeferredDeleter::removeClient();
EXPECT_TRUE(deleter->isQueueEmpty());
}