Move MonitoredFence to WddmResidencyController

Change-Id: Iac99e7d730fda26d13feed56d5e4c50adf115e51
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2018-10-22 15:59:26 +02:00
committed by sys_ocldev
parent 620708e510
commit f374696f1d
12 changed files with 79 additions and 77 deletions

View File

@@ -30,14 +30,6 @@ OsContextWin::~OsContextImpl() {
wddm.destroyContext(context);
}
void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) {
monitoredFence.lastSubmittedFence = 0;
monitoredFence.currentFenceValue = 1;
monitoredFence.fenceHandle = handle;
monitoredFence.cpuAddress = cpuAddress;
monitoredFence.gpuAddress = gpuAddress;
}
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId) : contextId(contextId) {
if (osInterface) {
osContextImpl = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), contextId);

View File

@@ -8,8 +8,6 @@
#pragma once
#include "runtime/os_interface/os_context.h"
#include "runtime/os_interface/windows/wddm_residency_controller.h"
#include "runtime/os_interface/windows/windows_wrapper.h"
#include "runtime/os_interface/windows/windows_defs.h"
#include <d3dkmthk.h>
namespace OCLRT {
@@ -33,8 +31,6 @@ class OsContext::OsContextImpl {
bool isInitialized() const {
return initialized;
}
MonitoredFence &getMonitoredFence() { return monitoredFence; }
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
Wddm *getWddm() const { return &wddm; }
WddmResidencyController &getResidencyController() { return residencyController; }
@@ -43,7 +39,6 @@ class OsContext::OsContextImpl {
D3DKMT_HANDLE context = 0;
D3DKMT_HANDLE hwQueueHandle = 0;
Wddm &wddm;
MonitoredFence monitoredFence = {};
WddmResidencyController residencyController;
};
} // namespace OCLRT

View File

@@ -711,12 +711,12 @@ bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsCo
if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU(osContext.getContext())) {
return false;
}
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.getMonitoredFence().currentFenceValue);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.getResidencyController().getMonitoredFence().currentFenceValue);
status = wddmInterface->submit(commandBuffer, size, commandHeader, osContext);
if (status) {
osContext.getMonitoredFence().lastSubmittedFence = osContext.getMonitoredFence().currentFenceValue;
osContext.getMonitoredFence().currentFenceValue++;
osContext.getResidencyController().getMonitoredFence().lastSubmittedFence = osContext.getResidencyController().getMonitoredFence().currentFenceValue;
osContext.getResidencyController().getMonitoredFence().currentFenceValue++;
}
getDeviceState();
UNRECOVERABLE_IF(!status);
@@ -742,9 +742,10 @@ void Wddm::getDeviceState() {
}
void Wddm::handleCompletion(OsContextWin &osContext) {
if (osContext.getMonitoredFence().cpuAddress) {
auto *currentTag = osContext.getMonitoredFence().cpuAddress;
while (*currentTag < osContext.getMonitoredFence().currentFenceValue - 1)
auto &monitoredFence = osContext.getResidencyController().getMonitoredFence();
if (monitoredFence.cpuAddress) {
auto *currentTag = monitoredFence.cpuAddress;
while (*currentTag < monitoredFence.currentFenceValue - 1)
;
}
}
@@ -770,10 +771,10 @@ bool Wddm::waitOnGPU(D3DKMT_HANDLE context) {
bool Wddm::waitFromCpu(uint64_t lastFenceValue, OsContextWin &osContext) {
NTSTATUS status = STATUS_SUCCESS;
if (lastFenceValue > *osContext.getMonitoredFence().cpuAddress) {
if (lastFenceValue > *osContext.getResidencyController().getMonitoredFence().cpuAddress) {
D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU waitFromCpu = {0};
waitFromCpu.ObjectCount = 1;
waitFromCpu.ObjectHandleArray = &osContext.getMonitoredFence().fenceHandle;
waitFromCpu.ObjectHandleArray = &osContext.getResidencyController().getMonitoredFence().fenceHandle;
waitFromCpu.FenceValueArray = &lastFenceValue;
waitFromCpu.hDevice = device;
waitFromCpu.hAsyncEvent = NULL;

View File

@@ -29,9 +29,9 @@ bool WddmInterface::createMonitoredFence(OsContextWin &osContext) {
DEBUG_BREAK_IF(STATUS_SUCCESS != Status);
osContext.resetMonitoredFenceParams(CreateSynchronizationObject.hSyncObject,
reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress),
CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress);
osContext.getResidencyController().resetMonitoredFenceParams(CreateSynchronizationObject.hSyncObject,
reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress),
CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress);
return Status == STATUS_SUCCESS;
}
@@ -44,7 +44,7 @@ bool WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *commandH
D3DKMT_SUBMITCOMMAND SubmitCommand = {0};
NTSTATUS status = STATUS_SUCCESS;
auto monitoredFence = osContext.getMonitoredFence();
auto monitoredFence = osContext.getResidencyController().getMonitoredFence();
SubmitCommand.Commands = commandBuffer;
SubmitCommand.CommandLength = static_cast<UINT>(size);
SubmitCommand.BroadcastContextCount = 1;
@@ -99,7 +99,7 @@ const bool WddmInterface23::hwQueuesSupported() {
}
bool WddmInterface23::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) {
auto monitoredFence = osContext.getMonitoredFence();
auto monitoredFence = osContext.getResidencyController().getMonitoredFence();
D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {};
submitCommand.hHwQueue = osContext.getHwQueue();

View File

@@ -116,7 +116,7 @@ FlushStamp WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContext.get());
return osContext.get()->getMonitoredFence().lastSubmittedFence;
return osContext.get()->getResidencyController().getMonitoredFence().lastSubmittedFence;
}
template <typename GfxFamily>

View File

@@ -483,7 +483,7 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer &all
osContext.get()->getResidencyController().acquireLock();
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.get()->getMonitoredFence().currentFenceValue);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", osContext.get()->getResidencyController().getMonitoredFence().currentFenceValue);
for (uint32_t i = 0; i < residencyCount; i++) {
WddmAllocation *allocation = reinterpret_cast<WddmAllocation *>(allocationsForResidency[i]);
@@ -538,7 +538,7 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer &all
for (uint32_t i = 0; i < residencyCount; i++) {
WddmAllocation *allocation = reinterpret_cast<WddmAllocation *>(allocationsForResidency[i]);
// Update fence value not to early destroy / evict allocation
auto currentFence = osContext.get()->getMonitoredFence().currentFenceValue;
auto currentFence = osContext.get()->getResidencyController().getMonitoredFence().currentFenceValue;
allocation->getResidencyData().updateCompletionData(currentFence, osContext.getContextId());
allocation->getResidencyData().resident = true;
@@ -636,7 +636,7 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6
}
if (flags.PeriodicTrim || flags.RestartPeriodicTrim) {
const auto newPeriodicTrimFenceValue = *osContext.get()->getMonitoredFence().cpuAddress;
const auto newPeriodicTrimFenceValue = *osContext.get()->getResidencyController().getMonitoredFence().cpuAddress;
osContext.get()->getResidencyController().setLastTrimFenceValue(newPeriodicTrimFenceValue);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "updated lastPeriodicTrimFenceValue =", newPeriodicTrimFenceValue);
}
@@ -660,7 +660,7 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) {
}
lastFence = wddmAllocation->getResidencyData().getFenceValueForContextId(0);
auto &monitoredFence = osContext.get()->getMonitoredFence();
auto &monitoredFence = osContext.get()->getResidencyController().getMonitoredFence();
if (lastFence <= monitoredFence.lastSubmittedFence) {
uint32_t fragmentsToEvict = 0;

View File

@@ -163,4 +163,12 @@ void WddmResidencyController::compactTrimCandidateList() {
checkTrimCandidateCount();
}
void WddmResidencyController::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) {
monitoredFence.lastSubmittedFence = 0;
monitoredFence.currentFenceValue = 1;
monitoredFence.fenceHandle = handle;
monitoredFence.cpuAddress = cpuAddress;
monitoredFence.gpuAddress = gpuAddress;
}
} // namespace OCLRT

View File

@@ -8,6 +8,8 @@
#pragma once
#include "runtime/memory_manager/residency_container.h"
#include "runtime/os_interface/windows/windows_wrapper.h"
#include "runtime/os_interface/windows/windows_defs.h"
#include <atomic>
@@ -40,6 +42,9 @@ class WddmResidencyController {
const ResidencyContainer &peekTrimCandidateList() const { return trimCandidateList; }
uint32_t peekTrimCandidatesCount() const { return trimCandidatesCount; }
MonitoredFence &getMonitoredFence() { return monitoredFence; }
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
protected:
uint32_t osContextId;
std::atomic<bool> lock = false;
@@ -47,5 +52,6 @@ class WddmResidencyController {
uint64_t lastTrimFenceValue = 0u;
ResidencyContainer trimCandidateList;
uint32_t trimCandidatesCount = 0;
MonitoredFence monitoredFence = {};
};
} // namespace OCLRT