Store vector of trim candidate list positions in WddmAllocation

Change-Id: I2fb247238802fc1ccd98e42d7714063f5231249f
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2018-10-09 17:03:07 +02:00
committed by sys_ocldev
parent 9f895c1ecc
commit 44dd4c9145
9 changed files with 100 additions and 59 deletions

View File

@@ -12,7 +12,7 @@
namespace OCLRT {
OsContextWin::OsContextImpl(Wddm &wddm) : wddm(wddm) {
OsContextWin::OsContextImpl(Wddm &wddm, uint32_t osContextId) : wddm(wddm), residencyController(osContextId) {
UNRECOVERABLE_IF(!wddm.isInitialized());
auto wddmInterface = wddm.getWddmInterface();
if (!wddm.createContext(context)) {
@@ -40,7 +40,7 @@ void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cp
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId) : contextId(contextId) {
if (osInterface) {
osContextImpl = std::make_unique<OsContextWin>(*osInterface->get()->getWddm());
osContextImpl = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), contextId);
}
}
OsContext::~OsContext() = default;

View File

@@ -19,7 +19,7 @@ using OsContextWin = OsContext::OsContextImpl;
class OsContext::OsContextImpl {
public:
OsContextImpl() = delete;
OsContextImpl(Wddm &wddm);
OsContextImpl(Wddm &wddm, uint32_t osContextId);
~OsContextImpl();
D3DKMT_HANDLE getContext() const {
return context;

View File

@@ -35,8 +35,8 @@ class WddmAllocation : public GraphicsAllocation {
handle(0),
gpuPtr(0),
alignedCpuPtr(alignedCpuPtr),
alignedSize(alignedSize) {
trimListPosition = trimListUnusedPosition;
alignedSize(alignedSize),
trimCandidateListPositions(osContextsCount, trimListUnusedPosition) {
reservedAddressSpace = reservedAddr;
this->memoryPool = pool;
}
@@ -46,8 +46,8 @@ class WddmAllocation : public GraphicsAllocation {
handle(0),
gpuPtr(0),
alignedCpuPtr(nullptr),
alignedSize(sizeIn) {
trimListPosition = trimListUnusedPosition;
alignedSize(sizeIn),
trimCandidateListPositions(osContextsCount, trimListUnusedPosition) {
reservedAddressSpace = nullptr;
this->memoryPool = pool;
}
@@ -73,12 +73,15 @@ class WddmAllocation : public GraphicsAllocation {
return residency;
}
void setTrimCandidateListPosition(size_t position) {
trimListPosition = position;
void setTrimCandidateListPosition(uint32_t osContextId, size_t position) {
trimCandidateListPositions[osContextId] = position;
}
size_t getTrimCandidateListPosition() {
return trimListPosition;
size_t getTrimCandidateListPosition(uint32_t osContextId) const {
if (osContextId < trimCandidateListPositions.size()) {
return trimCandidateListPositions[osContextId];
}
return trimListUnusedPosition;
}
void *getReservedAddress() const {
@@ -93,7 +96,7 @@ class WddmAllocation : public GraphicsAllocation {
void *alignedCpuPtr;
size_t alignedSize;
ResidencyData residency;
size_t trimListPosition;
std::vector<size_t> trimCandidateListPositions;
void *reservedAddressSpace;
};
} // namespace OCLRT

View File

@@ -313,9 +313,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
if (osContext) {
auto &residencyController = osContext->get()->getResidencyController();
residencyController.acquireLock();
if (input->getTrimCandidateListPosition() != trimListUnusedPosition) {
residencyController.removeFromTrimCandidateList(gfxAllocation, true);
}
residencyController.removeFromTrimCandidateListIfUsed(input, true);
residencyController.releaseLock();
}
}
@@ -492,7 +490,7 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer &all
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation =", allocation, mainResidency ? "resident" : "not resident");
if (allocation->getTrimCandidateListPosition() != trimListUnusedPosition) {
if (allocation->getTrimCandidateListPosition(osContext.getContextId()) != trimListUnusedPosition) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation =", allocation, "on trimCandidateList");
osContext.get()->getResidencyController().removeFromTrimCandidateList(allocation, false);

View File

@@ -5,14 +5,14 @@
*
*/
#include "wddm_residency_controller.h"
#include "runtime/os_interface/windows/wddm_residency_controller.h"
#include "runtime/os_interface/windows/wddm_allocation.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/utilities/spinlock.h"
namespace OCLRT {
WddmResidencyController::WddmResidencyController() : lock(false), lastTrimFenceValue(0u) {}
WddmResidencyController::WddmResidencyController(uint32_t osContextId) : osContextId(osContextId) {}
void WddmResidencyController::acquireLock() {
bool previousLockValue = false;
@@ -53,10 +53,10 @@ void WddmResidencyController::addToTrimCandidateList(GraphicsAllocation *allocat
DEBUG_BREAK_IF(trimCandidatesCount > trimCandidateList.size());
if (wddmAllocation->getTrimCandidateListPosition() == trimListUnusedPosition) {
if (wddmAllocation->getTrimCandidateListPosition(this->osContextId) == trimListUnusedPosition) {
trimCandidatesCount++;
trimCandidateList.push_back(allocation);
wddmAllocation->setTrimCandidateListPosition(position);
wddmAllocation->setTrimCandidateListPosition(this->osContextId, position);
}
checkTrimCandidateCount();
@@ -64,7 +64,7 @@ void WddmResidencyController::addToTrimCandidateList(GraphicsAllocation *allocat
void WddmResidencyController::removeFromTrimCandidateList(GraphicsAllocation *allocation, bool compactList) {
WddmAllocation *wddmAllocation = (WddmAllocation *)allocation;
size_t position = wddmAllocation->getTrimCandidateListPosition();
size_t position = wddmAllocation->getTrimCandidateListPosition(this->osContextId);
DEBUG_BREAK_IF(!(trimCandidatesCount > (trimCandidatesCount - 1)));
DEBUG_BREAK_IF(trimCandidatesCount > trimCandidateList.size());
@@ -93,7 +93,7 @@ void WddmResidencyController::removeFromTrimCandidateList(GraphicsAllocation *al
trimCandidateList.resize(sizeRemaining);
}
}
wddmAllocation->setTrimCandidateListPosition(trimListUnusedPosition);
wddmAllocation->setTrimCandidateListPosition(this->osContextId, trimListUnusedPosition);
if (compactList && checkTrimCandidateListCompaction()) {
compactTrimCandidateList();
@@ -102,6 +102,12 @@ void WddmResidencyController::removeFromTrimCandidateList(GraphicsAllocation *al
checkTrimCandidateCount();
}
void WddmResidencyController::removeFromTrimCandidateListIfUsed(WddmAllocation *allocation, bool compactList) {
if (allocation->getTrimCandidateListPosition(this->osContextId) != trimListUnusedPosition) {
this->removeFromTrimCandidateList(allocation, true);
}
}
void WddmResidencyController::checkTrimCandidateCount() {
if (DebugManager.flags.ResidencyDebugEnable.get()) {
uint32_t sum = 0;
@@ -142,7 +148,7 @@ void WddmResidencyController::compactTrimCandidateList() {
if (trimCandidateList[i] != nullptr && freePosition < i) {
trimCandidateList[freePosition] = trimCandidateList[i];
trimCandidateList[i] = nullptr;
((WddmAllocation *)trimCandidateList[freePosition])->setTrimCandidateListPosition(freePosition);
static_cast<WddmAllocation *>(trimCandidateList[freePosition])->setTrimCandidateListPosition(this->osContextId, freePosition);
freePosition++;
// Last element was moved, erase elements from freePosition

View File

@@ -18,7 +18,7 @@ class WddmAllocation;
class WddmResidencyController {
public:
WddmResidencyController();
WddmResidencyController(uint32_t osContextId);
void acquireLock();
void releaseLock();
@@ -29,6 +29,7 @@ class WddmResidencyController {
WddmAllocation *getTrimCandidateHead();
void addToTrimCandidateList(GraphicsAllocation *allocation);
void removeFromTrimCandidateList(GraphicsAllocation *allocation, bool compactList);
void removeFromTrimCandidateListIfUsed(WddmAllocation *allocation, bool compactList);
void checkTrimCandidateCount();
bool checkTrimCandidateListCompaction();
@@ -40,9 +41,10 @@ class WddmResidencyController {
uint32_t peekTrimCandidatesCount() const { return trimCandidatesCount; }
protected:
std::atomic<bool> lock;
uint32_t osContextId;
std::atomic<bool> lock = false;
std::atomic_flag trimCallbackLock = ATOMIC_FLAG_INIT;
uint64_t lastTrimFenceValue;
uint64_t lastTrimFenceValue = 0u;
ResidencyContainer trimCandidateList;
uint32_t trimCandidatesCount = 0;
};