fix: skip always resident allocations during trim

Related-To: NEO-12461

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2024-08-27 12:51:42 +00:00
committed by Compute-Runtime-Automation
parent 85359331ce
commit c9457bb5eb
2 changed files with 59 additions and 0 deletions

View File

@@ -74,6 +74,11 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS
continue;
}
if (wddmAllocation->isAlwaysResident(osContextId)) {
allocationIter = allocations.erase(allocationIter);
continue;
}
if (wddmAllocation->fragmentsStorage.fragmentCount == 0) {
for (auto i = 0u; i < wddmAllocation->getNumGmms(); i++) {
handlesToEvict.push_back(wddmAllocation->getHandles()[i]);
@@ -134,6 +139,11 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes, std::unique_
continue;
}
if (wddmAllocation->isAlwaysResident(osContextId)) {
allocationIter = allocations.erase(allocationIter);
continue;
}
uint64_t sizeEvicted = 0;
if (lastFence > *monitoredFence.cpuAddress) {

View File

@@ -561,6 +561,55 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenEvictedAlloca
EXPECT_TRUE(allocation3.getResidencyData().resident[osContextId]);
}
TEST_F(WddmResidencyControllerWithGdiTest, givenAlwaysResidentAllocationWhenTrimResidencyToBudgetCalledThenDontEvict) {
gdi->setNonZeroNumBytesToTrimInEvict();
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmHelper());
allocation.getResidencyData().resident[osContextId] = true;
allocation.getResidencyData().updateCompletionData(0, osContextId);
*residencyController->getMonitoredFence().cpuAddress = 1;
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->evictResult.called = 0;
csr->getEvictionAllocations().push_back(&allocation);
allocation.updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContextId);
std::mutex mtx;
std::unique_lock<std::mutex> lock(mtx);
residencyController->trimResidencyToBudget(3 * 4096, lock);
EXPECT_TRUE(allocation.getResidencyData().resident[osContextId]);
}
TEST_F(WddmResidencyControllerWithGdiTest, givenAlwaysResidentAllocationWhenTrimResidencyCalledThenDontEvict) {
gdi->setNonZeroNumBytesToTrimInEvict();
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmHelper());
allocation.getResidencyData().resident[osContextId] = true;
allocation.getResidencyData().updateCompletionData(0, osContextId);
*residencyController->getMonitoredFence().cpuAddress = 1;
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->evictResult.called = 0;
csr->getEvictionAllocations().push_back(&allocation);
allocation.updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContextId);
D3DKMT_TRIMNOTIFICATION trimNotification = {0};
trimNotification.Flags.PeriodicTrim = 1;
trimNotification.NumBytesToTrim = 0;
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
EXPECT_TRUE(allocation.getResidencyData().resident[osContextId]);
}
TEST_F(WddmResidencyControllerWithGdiTest, GivenLastFenceIsGreaterThanMonitoredWhenTrimmingToBudgetThenWaitForCpu) {
gdi->setNonZeroNumBytesToTrimInEvict();