Add returned status to MemoryOperationsHandler

Change-Id: Ic8685e3711cec03d8f83d371fa7152ee095a47a0
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2019-08-29 13:46:49 +02:00
committed by sys_ocldev
parent 77e22bd81b
commit 7827501b91
21 changed files with 130 additions and 107 deletions

View File

@ -12,16 +12,16 @@ namespace NEO {
DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() {
}
bool DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
return false;
MemoryOperationsStatus DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
return MemoryOperationsStatus::UNSUPPORTED;
}
bool DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
return false;
MemoryOperationsStatus DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
return MemoryOperationsStatus::UNSUPPORTED;
}
bool DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
return false;
MemoryOperationsStatus DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
return MemoryOperationsStatus::UNSUPPORTED;
}
} // namespace NEO

View File

@ -15,8 +15,8 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
DrmMemoryOperationsHandler();
~DrmMemoryOperationsHandler() override = default;
bool makeResident(GraphicsAllocation &gfxAllocation) override;
bool evict(GraphicsAllocation &gfxAllocation) override;
bool isResident(GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override;
};
} // namespace NEO

View File

@ -7,7 +7,6 @@
#pragma once
#include "core/command_stream/preemption_mode.h"
#include "core/memory_manager/eviction_status.h"
#include "core/utilities/spinlock.h"
#include "runtime/gmm_helper/gmm_lib.h"
#include "runtime/helpers/debug_helpers.h"

View File

@ -292,7 +292,7 @@ void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocatio
wddm->unlockResource(wddmAllocation.getDefaultHandle());
if (wddmAllocation.needsMakeResidentBeforeLock) {
auto evictionStatus = wddm->getTemporaryResourcesContainer()->evictResource(wddmAllocation.getDefaultHandle());
DEBUG_BREAK_IF(evictionStatus == EvictionStatus::FAILED);
DEBUG_BREAK_IF(evictionStatus == MemoryOperationsStatus::FAILED);
}
}
void WddmMemoryManager::freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) {

View File

@ -19,18 +19,17 @@ WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm
residentAllocations = std::make_unique<WddmResidentAllocationsContainer>(wddm);
}
bool WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
WddmAllocation &wddmAllocation = reinterpret_cast<WddmAllocation &>(gfxAllocation);
return residentAllocations->makeResidentResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles());
}
bool WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
MemoryOperationsStatus WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
WddmAllocation &wddmAllocation = reinterpret_cast<WddmAllocation &>(gfxAllocation);
auto result = residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles());
return result == EvictionStatus::SUCCESS;
return residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles());
}
bool WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
MemoryOperationsStatus WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
WddmAllocation &wddmAllocation = reinterpret_cast<WddmAllocation &>(gfxAllocation);
return residentAllocations->isAllocationResident(wddmAllocation.getDefaultHandle());
}

View File

@ -20,9 +20,9 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler {
WddmMemoryOperationsHandler(Wddm *wddm);
~WddmMemoryOperationsHandler() override = default;
bool makeResident(GraphicsAllocation &gfxAllocation) override;
bool evict(GraphicsAllocation &gfxAllocation) override;
bool isResident(GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override;
protected:
Wddm *wddm;

View File

@ -17,58 +17,58 @@ WddmResidentAllocationsContainer::~WddmResidentAllocationsContainer() {
evictAllResources();
}
bool WddmResidentAllocationsContainer::isAllocationResident(const D3DKMT_HANDLE &handle) {
MemoryOperationsStatus WddmResidentAllocationsContainer::isAllocationResident(const D3DKMT_HANDLE &handle) {
auto lock = acquireLock(resourcesLock);
auto position = std::find(resourceHandles.begin(), resourceHandles.end(), handle);
return position != resourceHandles.end();
return position != resourceHandles.end() ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::MEMORY_NOT_FOUND;
}
EvictionStatus WddmResidentAllocationsContainer::evictAllResources() {
MemoryOperationsStatus WddmResidentAllocationsContainer::evictAllResources() {
decltype(resourceHandles) resourcesToEvict;
auto lock = acquireLock(resourcesLock);
resourceHandles.swap(resourcesToEvict);
if (resourcesToEvict.empty()) {
return EvictionStatus::NOT_APPLIED;
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
}
uint64_t sizeToTrim = 0;
uint32_t evictedResources = static_cast<uint32_t>(resourcesToEvict.size());
bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim);
return success ? EvictionStatus::SUCCESS : EvictionStatus::FAILED;
return success ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED;
}
EvictionStatus WddmResidentAllocationsContainer::evictResource(const D3DKMT_HANDLE &handle) {
MemoryOperationsStatus WddmResidentAllocationsContainer::evictResource(const D3DKMT_HANDLE &handle) {
return evictResources(&handle, 1u);
}
EvictionStatus WddmResidentAllocationsContainer::evictResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
MemoryOperationsStatus WddmResidentAllocationsContainer::evictResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
auto lock = acquireLock(resourcesLock);
auto position = std::find(resourceHandles.begin(), resourceHandles.end(), handles[0]);
if (position == resourceHandles.end()) {
return EvictionStatus::NOT_APPLIED;
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
}
auto distance = static_cast<size_t>(std::distance(resourceHandles.begin(), position));
UNRECOVERABLE_IF(distance + count > resourceHandles.size());
resourceHandles.erase(position, position + count);
uint64_t sizeToTrim = 0;
if (!wddm->evict(handles, count, sizeToTrim)) {
return EvictionStatus::FAILED;
return MemoryOperationsStatus::FAILED;
}
return EvictionStatus::SUCCESS;
return MemoryOperationsStatus::SUCCESS;
}
bool WddmResidentAllocationsContainer::makeResidentResource(const D3DKMT_HANDLE &handle) {
MemoryOperationsStatus WddmResidentAllocationsContainer::makeResidentResource(const D3DKMT_HANDLE &handle) {
return makeResidentResources(&handle, 1u);
}
bool WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
MemoryOperationsStatus WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
bool madeResident = false;
while (!(madeResident = wddm->makeResident(handles, count, false, nullptr))) {
if (evictAllResources() == EvictionStatus::SUCCESS) {
if (evictAllResources() == MemoryOperationsStatus::SUCCESS) {
continue;
}
if (!wddm->makeResident(handles, count, false, nullptr)) {
DEBUG_BREAK_IF(true);
return false;
return MemoryOperationsStatus::OUT_OF_MEMORY;
};
break;
}
@ -79,7 +79,7 @@ bool WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE
}
lock.unlock();
wddm->waitOnPagingFenceFromCpu();
return madeResident;
return madeResident ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED;
}
void WddmResidentAllocationsContainer::removeResource(const D3DKMT_HANDLE &handle) {

View File

@ -6,7 +6,7 @@
*/
#pragma once
#include "core/memory_manager/eviction_status.h"
#include "core/memory_manager/memory_operations_status.h"
#include "core/utilities/spinlock.h"
#include "runtime/os_interface/windows/windows_defs.h"
@ -21,12 +21,12 @@ class WddmResidentAllocationsContainer {
WddmResidentAllocationsContainer(Wddm *wddm) : wddm(wddm) {}
virtual ~WddmResidentAllocationsContainer();
bool isAllocationResident(const D3DKMT_HANDLE &handle);
MOCKABLE_VIRTUAL EvictionStatus evictAllResources();
MOCKABLE_VIRTUAL EvictionStatus evictResource(const D3DKMT_HANDLE &handle);
EvictionStatus evictResources(const D3DKMT_HANDLE *handles, const uint32_t count);
MOCKABLE_VIRTUAL bool makeResidentResource(const D3DKMT_HANDLE &handle);
bool makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count);
MemoryOperationsStatus isAllocationResident(const D3DKMT_HANDLE &handle);
MOCKABLE_VIRTUAL MemoryOperationsStatus evictAllResources();
MOCKABLE_VIRTUAL MemoryOperationsStatus evictResource(const D3DKMT_HANDLE &handle);
MemoryOperationsStatus evictResources(const D3DKMT_HANDLE *handles, const uint32_t count);
MOCKABLE_VIRTUAL MemoryOperationsStatus makeResidentResource(const D3DKMT_HANDLE &handle);
MemoryOperationsStatus makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count);
MOCKABLE_VIRTUAL void removeResource(const D3DKMT_HANDLE &handle);
protected:

View File

@ -343,10 +343,10 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine
const bool trimmingDone = this->trimResidencyToBudget(bytesToTrim);
if (!trimmingDone) {
auto evictionStatus = wddm.getTemporaryResourcesContainer()->evictAllResources();
if (evictionStatus == EvictionStatus::SUCCESS) {
if (evictionStatus == MemoryOperationsStatus::SUCCESS) {
continue;
}
DEBUG_BREAK_IF(evictionStatus != EvictionStatus::NOT_APPLIED);
DEBUG_BREAK_IF(evictionStatus != MemoryOperationsStatus::MEMORY_NOT_FOUND);
result = wddm.makeResident(handlesForResidency.get(), totalHandlesCount, true, &bytesToTrim);
break;
}