Set allocation's lock state only in lockResource and unlockResource methods

Change-Id: I60f35801287166f5bdb0dfcd31ff0118c56ec22a
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-01-24 11:51:33 +01:00
committed by sys_ocldev
parent 09c62ca44c
commit f332bf369e
20 changed files with 161 additions and 149 deletions

View File

@@ -825,26 +825,26 @@ TEST_F(Wddm20Tests, givenAllocationThatDoesntNeedMakeResidentBeforeLockWhenLockT
EXPECT_FALSE(allocation.needsMakeResidentBeforeLock);
EXPECT_TRUE(wddm->temporaryResources.empty());
EXPECT_EQ(0u, wddm->makeResidentResult.called);
wddm->lockResource(&allocation);
wddm->lockResource(allocation);
EXPECT_TRUE(wddm->temporaryResources.empty());
EXPECT_EQ(0u, wddm->makeResidentResult.called);
wddm->unlockResource(&allocation);
wddm->unlockResource(allocation);
}
TEST_F(Wddm20Tests, givenAllocationThatNeedsMakeResidentBeforeLockWhenLockThenCallBlockingMakeResident) {
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
allocation.needsMakeResidentBeforeLock = true;
wddm->lockResource(&allocation);
wddm->lockResource(allocation);
EXPECT_EQ(1u, wddm->applyBlockingMakeResidentResult.called);
}
TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentThenAcquireUniqueLock) {
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
wddm->applyBlockingMakeResident(&allocation);
wddm->applyBlockingMakeResident(allocation);
EXPECT_EQ(1u, wddm->acquireLockResult.called);
EXPECT_EQ(reinterpret_cast<uint64_t>(&wddm->temporaryResourcesLock), wddm->acquireLockResult.uint64ParamPassed);
}
TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentThenCallMakeResidentAndStoreAllocation) {
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
wddm->applyBlockingMakeResident(&allocation);
wddm->applyBlockingMakeResident(allocation);
EXPECT_EQ(1u, wddm->makeResidentResult.called);
EXPECT_EQ(allocation.handle, wddm->temporaryResources.back());
}
@@ -852,7 +852,7 @@ TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentThenWaitForCurre
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
wddm->mockPagingFence = 0u;
wddm->currentPagingFenceValue = 3u;
wddm->applyBlockingMakeResident(&allocation);
wddm->applyBlockingMakeResident(allocation);
EXPECT_EQ(1u, wddm->makeResidentResult.called);
EXPECT_EQ(3u, wddm->mockPagingFence);
EXPECT_EQ(3u, wddm->getPagingFenceAddressResult.called);
@@ -861,7 +861,7 @@ TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentAndMakeResidentC
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
GmockWddm gmockWddm;
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillRepeatedly(::testing::Return(false));
gmockWddm.applyBlockingMakeResident(&allocation);
gmockWddm.applyBlockingMakeResident(allocation);
EXPECT_EQ(1u, gmockWddm.evictAllTemporaryResourcesResult.called);
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndTemporaryResourcesAreEvictedSuccessfullyThenCallMakeResidentOneMoreTime) {
@@ -870,7 +870,7 @@ TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndTemporaryResourcesAreEvicted
gmockWddm.temporaryResources.push_back(allocation.handle);
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true));
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(3).WillRepeatedly(::testing::Return(false));
gmockWddm.applyBlockingMakeResident(&allocation);
gmockWddm.applyBlockingMakeResident(allocation);
EXPECT_EQ(2u, gmockWddm.evictAllTemporaryResourcesResult.called);
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDontStoreTemporaryResource) {
@@ -881,7 +881,7 @@ TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDo
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true));
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(3).WillRepeatedly(::testing::Return(false));
EXPECT_EQ(1u, gmockWddm.temporaryResources.size());
gmockWddm.applyBlockingMakeResident(&allocation);
gmockWddm.applyBlockingMakeResident(allocation);
EXPECT_EQ(0u, gmockWddm.temporaryResources.size());
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvictThenStoreTemporaryResource) {
@@ -892,7 +892,7 @@ TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvict
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true));
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Return(false)).WillOnce(::testing::Return(true));
EXPECT_EQ(1u, gmockWddm.temporaryResources.size());
gmockWddm.applyBlockingMakeResident(&allocation);
gmockWddm.applyBlockingMakeResident(allocation);
EXPECT_EQ(1u, gmockWddm.temporaryResources.size());
EXPECT_EQ(0x2, gmockWddm.temporaryResources.back());
}
@@ -902,7 +902,7 @@ TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentPassesThenStoreT
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(0x1);
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true));
gmockWddm.applyBlockingMakeResident(&allocation);
gmockWddm.applyBlockingMakeResident(allocation);
EXPECT_EQ(2u, gmockWddm.temporaryResources.size());
EXPECT_EQ(0x2, gmockWddm.temporaryResources.back());
}
@@ -945,11 +945,13 @@ TEST_F(Wddm20Tests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesAndOne
EXPECT_EQ(EvictionStatus::FAILED, gmockWddm.evictAllTemporaryResourcesResult.status);
}
TEST_F(Wddm20Tests, givenNoTemporaryResourcesWhenEvictingTemporaryResourceThenEvictionIsNotApplied) {
wddm->evictTemporaryResource(nullptr);
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
wddm->evictTemporaryResource(allocation);
EXPECT_EQ(EvictionStatus::NOT_APPLIED, wddm->evictTemporaryResourceResult.status);
}
TEST_F(Wddm20Tests, whenEvictingTemporaryResourceThenAcquireTemporaryResourcesLock) {
wddm->evictTemporaryResource(nullptr);
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
wddm->evictTemporaryResource(allocation);
EXPECT_EQ(1u, wddm->acquireLockResult.called);
EXPECT_EQ(reinterpret_cast<uint64_t>(&wddm->temporaryResourcesLock), wddm->acquireLockResult.uint64ParamPassed);
}
@@ -958,7 +960,7 @@ TEST_F(Wddm20Tests, whenEvictingNonExistingTemporaryResourceThenEvictIsNotApplie
allocation.handle = 0x1;
wddm->temporaryResources.push_back(0x2);
EXPECT_FALSE(wddm->temporaryResources.empty());
wddm->evictTemporaryResource(&allocation);
wddm->evictTemporaryResource(allocation);
EXPECT_FALSE(wddm->temporaryResources.empty());
EXPECT_EQ(EvictionStatus::NOT_APPLIED, wddm->evictTemporaryResourceResult.status);
}
@@ -967,7 +969,7 @@ TEST_F(Wddm20Tests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) {
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(allocation.handle);
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false));
gmockWddm.evictTemporaryResource(&allocation);
gmockWddm.evictTemporaryResource(allocation);
EXPECT_TRUE(gmockWddm.temporaryResources.empty());
EXPECT_EQ(EvictionStatus::FAILED, gmockWddm.evictTemporaryResourceResult.status);
}
@@ -976,7 +978,7 @@ TEST_F(Wddm20Tests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSucces
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(allocation.handle);
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true));
gmockWddm.evictTemporaryResource(&allocation);
gmockWddm.evictTemporaryResource(allocation);
EXPECT_TRUE(gmockWddm.temporaryResources.empty());
EXPECT_EQ(EvictionStatus::SUCCESS, gmockWddm.evictTemporaryResourceResult.status);
}
@@ -987,7 +989,7 @@ TEST_F(Wddm20Tests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheLi
WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false};
allocation.handle = 0x2;
wddm->evictTemporaryResource(&allocation);
wddm->evictTemporaryResource(allocation);
EXPECT_EQ(2u, wddm->temporaryResources.size());
EXPECT_EQ(0x1, wddm->temporaryResources.front());

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Intel Corporation
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -60,7 +60,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListener
MockWddmAllocation allocation;
allocation.handle = ALLOCATION_HANDLE;
wddmWithKmDafMock->lockResource(&allocation);
wddmWithKmDafMock->lockResource(allocation);
EXPECT_EQ(wddmWithKmDafMock->getFeatureTable()->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAdapter);
@@ -74,7 +74,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafListen
MockWddmAllocation allocation;
allocation.handle = ALLOCATION_HANDLE;
wddmWithKmDafMock->unlockResource(&allocation);
wddmWithKmDafMock->unlockResource(allocation);
EXPECT_EQ(wddmWithKmDafMock->getFeatureTable()->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.hAdapter);

View File

@@ -1480,14 +1480,14 @@ TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhen
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingLockedAllocationThatDoesntNeedMakeResidentBeforeLockThenDontEvictAllocationFromWddmTemporaryResources) {
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
allocation->setLocked(true);
memoryManager->lockResource(allocation);
EXPECT_FALSE(allocation->needsMakeResidentBeforeLock);
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(0u, wddm->evictTemporaryResourceResult.called);
}
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatDoesntNeedMakeResidentBeforeLockThenDontEvictAllocationFromWddmTemporaryResources) {
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
allocation->setLocked(false);
EXPECT_FALSE(allocation->isLocked());
EXPECT_FALSE(allocation->needsMakeResidentBeforeLock);
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(0u, wddm->evictTemporaryResourceResult.called);
@@ -1495,14 +1495,14 @@ TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatDoesntN
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingLockedAllocationThatNeedsMakeResidentBeforeLockThenEvictAllocationFromWddmTemporaryResources) {
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
allocation->needsMakeResidentBeforeLock = true;
allocation->setLocked(true);
memoryManager->lockResource(allocation);
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(1u, wddm->evictTemporaryResourceResult.called);
}
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatNeedsMakeResidentBeforeLockThenDontEvictAllocationFromWddmTemporaryResources) {
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
allocation->needsMakeResidentBeforeLock = true;
allocation->setLocked(false);
EXPECT_FALSE(allocation->isLocked());
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(0u, wddm->evictTemporaryResourceResult.called);
}