Add new wddm eviction parameter

Related-To: NEO-7179

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz 2022-07-18 13:25:50 +00:00 committed by Compute-Runtime-Automation
parent a12c138c16
commit d19cab1fb3
10 changed files with 50 additions and 18 deletions

View File

@ -520,7 +520,7 @@ TEST_F(Wddm20Tests, WhenMakingResidentAndEvictingThenReturnIsCorrect) {
EXPECT_TRUE(error);
uint64_t sizeToTrim;
error = wddm->evict(&allocation.getHandles()[0], allocation.getNumGmms(), sizeToTrim);
error = wddm->evict(&allocation.getHandles()[0], allocation.getNumGmms(), sizeToTrim, true);
EXPECT_TRUE(error);
auto monitoredFence = osContext->getResidencyController().getMonitoredFence();
@ -814,7 +814,7 @@ TEST_F(Wddm20Tests, GivenMultipleHandlesWhenMakingResidentThenBytesToTrimIsCorre
EXPECT_EQ(gdi->getMakeResidentArg().NumBytesToTrim, bytesToTrim);
}
TEST_F(Wddm20Tests, WhenMakingNonResidentThenEvictIsCalled) {
TEST_F(Wddm20Tests, WhenMakingNonResidentAndEvictNotNeededThenEvictIsCalledWithProperFlagSet) {
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
gdi->getEvictArg().AllocationList = nullptr;
@ -825,12 +825,33 @@ TEST_F(Wddm20Tests, WhenMakingNonResidentThenEvictIsCalled) {
wddm->callBaseEvict = true;
uint64_t sizeToTrim = 10;
wddm->evict(&handle, 1, sizeToTrim);
wddm->evict(&handle, 1, sizeToTrim, false);
EXPECT_EQ(1u, gdi->getEvictArg().NumAllocations);
EXPECT_EQ(&handle, gdi->getEvictArg().AllocationList);
EXPECT_EQ(wddm->getDeviceHandle(), gdi->getEvictArg().hDevice);
EXPECT_EQ(0u, gdi->getEvictArg().NumBytesToTrim);
EXPECT_EQ(1u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
}
TEST_F(Wddm20Tests, WhenMakingNonResidentAndEvictNeededThenEvictIsCalledWithProperFlagSet) {
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
gdi->getEvictArg().AllocationList = nullptr;
gdi->getEvictArg().Flags.Value = 0;
gdi->getEvictArg().hDevice = 0;
gdi->getEvictArg().NumAllocations = 0;
gdi->getEvictArg().NumBytesToTrim = 20;
wddm->callBaseEvict = true;
uint64_t sizeToTrim = 10;
wddm->evict(&handle, 1, sizeToTrim, true);
EXPECT_EQ(1u, gdi->getEvictArg().NumAllocations);
EXPECT_EQ(&handle, gdi->getEvictArg().AllocationList);
EXPECT_EQ(wddm->getDeviceHandle(), gdi->getEvictArg().hDevice);
EXPECT_EQ(0u, gdi->getEvictArg().NumBytesToTrim);
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
}
TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedToDestroyAllocation) {
@ -1072,11 +1093,13 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndTemporaryR
allocation.handle = 0x3;
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentStatus = false;
mockWddm.callBaseEvict = true;
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(allocation.handle);
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
EXPECT_EQ(2u, mockTemporaryResources->evictAllResourcesResult.called);
EXPECT_EQ(1u, mockWddm.evictResult.called);
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
EXPECT_EQ(3u, mockWddm.makeResidentResult.called);
}

View File

@ -128,7 +128,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenEvictIsCalledThenKmDafListenerNotifyE
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmHelper());
uint64_t sizeToTrim;
wddmWithKmDafMock->evict(&allocation.handle, 1, sizeToTrim);
wddmWithKmDafMock->evict(&allocation.handle, 1, sizeToTrim, true);
EXPECT_EQ(wddmWithKmDafMock->featureTable->flags.ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyEvictParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyEvictParametrization.hAdapter);

View File

@ -516,6 +516,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe
residencyController->getMonitoredFence().currentFenceValue = 20;
wddm->evictResult.called = 0;
wddm->callBaseEvict = true;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -524,6 +525,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe
// 2 allocations evicted
EXPECT_EQ(2u, wddm->evictResult.called);
EXPECT_EQ(1u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
// removed from trim candidate list
EXPECT_EQ(0u, residencyController->peekTrimCandidateList().size());
// marked nonresident
@ -601,6 +603,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation
residencyController->getMonitoredFence().currentFenceValue = 20;
wddm->evictResult.called = 0;
wddm->callBaseEvict = true;
residencyController->addToTrimCandidateList(allocationTriple);
@ -608,6 +611,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation
// 2 fragments evicted with one call
EXPECT_EQ(1u, wddm->evictResult.called);
EXPECT_EQ(1u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
// marked nonresident
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]);
@ -672,6 +676,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->evictResult.called = 0;
wddm->callBaseEvict = true;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -680,6 +685,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca
residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, wddm->evictResult.called);
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
EXPECT_EQ(1u, residencyController->peekTrimCandidatesCount());
residencyController->compactTrimCandidateList();
@ -853,11 +859,11 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, WhenTrimmingToBudgetT
residencyController->getMonitoredFence().currentFenceValue = 2;
wddm->evictResult.called = 0;
wddm->callBaseEvict = true;
residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, wddm->evictResult.called);
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]);
EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident[osContextId]);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]);

View File

@ -75,8 +75,10 @@ TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenMakingResiden
}
TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocationWhenEvictingResidentAllocationThenEvictCalled) {
wddm->callBaseEvict = true;
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, *wddmAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
}

View File

@ -70,7 +70,7 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS
if (wddmAllocation->fragmentsStorage.fragmentCount == 0) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict allocation: default handle =", wddmAllocation->getDefaultHandle(), "lastFence =", wddmAllocation->getResidencyData().getFenceValueForContextId(osContextId));
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim);
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim, false);
}
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
@ -84,7 +84,7 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS
}
}
if (fragmentsToEvict != 0) {
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim);
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim, false);
}
wddmAllocation->getResidencyData().resident[osContextId] = false;
@ -129,7 +129,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) {
}
if (wddmAllocation->fragmentsStorage.fragmentCount == 0) {
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim);
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim, true);
sizeEvicted = wddmAllocation->getAlignedSize();
} else {
auto &fragmentStorageData = wddmAllocation->fragmentsStorage.fragmentStorageData;
@ -140,7 +140,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) {
}
if (fragmentsToEvict != 0) {
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim);
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim, true);
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
if (fragmentStorageData[allocationId].residency->getFenceValueForContextId(osContextId) <= monitoredFence.lastSubmittedFence) {

View File

@ -359,13 +359,14 @@ std::vector<std::unique_ptr<HwDeviceId>> Wddm::discoverDevices(ExecutionEnvironm
return hwDeviceIds;
}
bool Wddm::evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim) {
bool Wddm::evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim, bool evictNeeded) {
NTSTATUS status = STATUS_SUCCESS;
D3DKMT_EVICT evict = {};
evict.AllocationList = handleList;
evict.hDevice = device;
evict.NumAllocations = numOfHandles;
evict.NumBytesToTrim = 0;
evict.Flags.EvictOnlyIfNecessary = evictNeeded ? 0 : 1;
status = getGdi()->evict(&evict);

View File

@ -70,7 +70,7 @@ class Wddm : public DriverModel {
static Wddm *createWddm(std::unique_ptr<HwDeviceIdWddm> &&hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
bool init();
MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim);
MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim, bool evictNeeded);
MOCKABLE_VIRTUAL bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize);
MOCKABLE_VIRTUAL bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr);
bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -36,7 +36,7 @@ MemoryOperationsStatus WddmResidentAllocationsContainer::evictAllResourcesNoLock
}
uint64_t sizeToTrim = 0;
uint32_t evictedResources = static_cast<uint32_t>(resourcesToEvict.size());
bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim);
bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim, true);
return success ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED;
}
@ -54,7 +54,7 @@ MemoryOperationsStatus WddmResidentAllocationsContainer::evictResources(const D3
UNRECOVERABLE_IF(distance + count > resourceHandles.size());
resourceHandles.erase(position, position + count);
uint64_t sizeToTrim = 0;
if (!wddm->evict(handles, count, sizeToTrim)) {
if (!wddm->evict(handles, count, sizeToTrim, true)) {
return MemoryOperationsStatus::FAILED;
}
return MemoryOperationsStatus::SUCCESS;

View File

@ -59,10 +59,10 @@ bool WddmMock::makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool c
}
return makeResidentStatus;
}
bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) {
bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim, bool evictNeeded) {
evictResult.called++;
if (callBaseEvict) {
evictStatus = Wddm::evict(handles, num, sizeToTrim);
evictStatus = Wddm::evict(handles, num, sizeToTrim, evictNeeded);
}
return evictStatus;
}

View File

@ -124,7 +124,7 @@ class WddmMock : public Wddm {
void resetGdi(Gdi *gdi);
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override;
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override;
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim, bool evictNeeded) override;
NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) override;
WddmMockHelpers::MakeResidentCall makeResidentResult;