Return error when failing on submission

Signed-off-by: Raiyan Latif <raiyan.latif@intel.com>
This commit is contained in:
Raiyan Latif
2022-01-07 14:53:31 +00:00
committed by Compute-Runtime-Automation
parent 38f9df26dd
commit 394c0e90e1
45 changed files with 668 additions and 128 deletions

View File

@ -68,27 +68,36 @@ bool DrmAllocation::setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regi
return true;
}
void DrmAllocation::makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
int DrmAllocation::makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
if (this->fragmentsStorage.fragmentCount) {
for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) {
if (!this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContext->getContextId()]) {
bindBO(static_cast<OsHandleLinux *>(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage)->bo, osContext, vmHandleId, bufferObjects, bind);
int retVal = bindBO(static_cast<OsHandleLinux *>(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage)->bo, osContext, vmHandleId, bufferObjects, bind);
if (retVal) {
return retVal;
}
this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContext->getContextId()] = true;
}
}
} else {
bindBOs(osContext, vmHandleId, bufferObjects, bind);
int retVal = bindBOs(osContext, vmHandleId, bufferObjects, bind);
if (retVal) {
return retVal;
}
}
return 0;
}
void DrmAllocation::bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
int DrmAllocation::bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
auto retVal = 0;
if (bo) {
bo->requireExplicitResidency(bo->peekDrm()->hasPageFaultSupport() && !shouldAllocationPageFault(bo->peekDrm()));
if (bufferObjects) {
if (bo->peekIsReusableAllocation()) {
for (auto bufferObject : *bufferObjects) {
if (bufferObject == bo) {
return;
return 0;
}
}
}
@ -96,15 +105,14 @@ void DrmAllocation::bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHa
bufferObjects->push_back(bo);
} else {
auto retVal = 0;
if (bind) {
retVal = bo->bind(osContext, vmHandleId);
} else {
retVal = bo->unbind(osContext, vmHandleId);
}
UNRECOVERABLE_IF(retVal);
}
}
return retVal;
}
void DrmAllocation::registerBOBindExtHandle(Drm *drm) {

View File

@ -91,9 +91,9 @@ class DrmAllocation : public GraphicsAllocation {
size_t getMmapSize() { return this->mmapSize; }
void setMmapSize(size_t size) { this->mmapSize = size; }
void makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
void bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
void bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
MOCKABLE_VIRTUAL int makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
MOCKABLE_VIRTUAL int bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
MOCKABLE_VIRTUAL int bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm);
void freeRegisteredBOBindExtHandles(Drm *drm);
void linkWithRegisteredHandle(uint32_t handle);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -13,9 +13,9 @@
namespace NEO {
void DrmAllocation::bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
int DrmAllocation::bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
auto bo = this->getBO();
bindBO(bo, osContext, vmHandleId, bufferObjects, bind);
return bindBO(bo, osContext, vmHandleId, bufferObjects, bind);
}
bool DrmAllocation::setCacheRegion(Drm *drm, CacheRegion regionIndex) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -44,7 +44,7 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
const DeviceBitfield deviceBitfield,
gemCloseWorkerMode mode = gemCloseWorkerMode::gemCloseWorkerActive);
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
SubmissionStatus flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
MOCKABLE_VIRTUAL void processResidency(const ResidencyContainer &allocationsForResidency, uint32_t handleId) override;
void makeNonResident(GraphicsAllocation &gfxAllocation) override;
bool waitForFlushStamp(FlushStamp &flushStampToWait) override;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -77,14 +77,14 @@ DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(ExecutionEnvironme
}
template <typename GfxFamily>
bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
SubmissionStatus DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
this->printDeviceIndex();
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
DEBUG_BREAK_IF(!alloc);
BufferObject *bb = alloc->getBO();
if (bb == nullptr) {
return false;
return SubmissionStatus::OUT_OF_MEMORY;
}
if (this->lastSentSliceCount != batchBuffer.sliceCount) {
@ -102,19 +102,39 @@ bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Reside
this->printBOsForSubmit(allocationsForResidency, *batchBuffer.commandBufferAllocation);
memoryOperationsInterface->mergeWithResidencyContainer(this->osContext, allocationsForResidency);
MemoryOperationsStatus retVal = memoryOperationsInterface->mergeWithResidencyContainer(this->osContext, allocationsForResidency);
if (retVal != MemoryOperationsStatus::SUCCESS) {
if (retVal == MemoryOperationsStatus::OUT_OF_MEMORY) {
return SubmissionStatus::OUT_OF_MEMORY;
}
return SubmissionStatus::FAILED;
}
if (this->drm->isVmBindAvailable()) {
memoryOperationsInterface->makeResidentWithinOsContext(this->osContext, ArrayRef<GraphicsAllocation *>(&batchBuffer.commandBufferAllocation, 1), true);
retVal = memoryOperationsInterface->makeResidentWithinOsContext(this->osContext, ArrayRef<GraphicsAllocation *>(&batchBuffer.commandBufferAllocation, 1), true);
if (retVal != MemoryOperationsStatus::SUCCESS) {
if (retVal == MemoryOperationsStatus::OUT_OF_MEMORY) {
return SubmissionStatus::OUT_OF_MEMORY;
}
return SubmissionStatus::FAILED;
}
}
if (this->directSubmission.get()) {
this->startControllingDirectSubmissions();
return this->directSubmission->dispatchCommandBuffer(batchBuffer, *this->flushStamp.get());
bool ret = this->directSubmission->dispatchCommandBuffer(batchBuffer, *this->flushStamp.get());
if (ret == false) {
return SubmissionStatus::FAILED;
}
return SubmissionStatus::SUCCESS;
}
if (this->blitterDirectSubmission.get()) {
this->startControllingDirectSubmissions();
return this->blitterDirectSubmission->dispatchCommandBuffer(batchBuffer, *this->flushStamp.get());
bool ret = this->blitterDirectSubmission->dispatchCommandBuffer(batchBuffer, *this->flushStamp.get());
if (ret == false) {
return SubmissionStatus::FAILED;
}
return SubmissionStatus::SUCCESS;
}
if (isUserFenceWaitActive()) {
@ -130,10 +150,10 @@ bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Reside
}
if (ret) {
return false;
return SubmissionStatus::FAILED;
}
return true;
return SubmissionStatus::SUCCESS;
}
template <typename GfxFamily>

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -20,7 +20,7 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
DrmMemoryOperationsHandler() = default;
~DrmMemoryOperationsHandler() override = default;
virtual void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0;
virtual MemoryOperationsStatus mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0;
virtual std::unique_lock<std::mutex> lockHandlerIfUsed() = 0;
virtual void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) = 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -40,7 +40,10 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsConte
auto drmAllocation = static_cast<DrmAllocation *>(*gfxAllocation);
for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) {
if (osContext->getDeviceBitfield().test(drmIterator)) {
drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true);
int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true);
if (result) {
return MemoryOperationsStatus::OUT_OF_MEMORY;
}
}
}
if (!evictable) {
@ -64,18 +67,26 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evict(Device *device, Gra
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) {
std::lock_guard<std::mutex> lock(mutex);
evictImpl(osContext, gfxAllocation, osContext->getDeviceBitfield());
int retVal = evictImpl(osContext, gfxAllocation, osContext->getDeviceBitfield());
if (retVal) {
return MemoryOperationsStatus::FAILED;
}
return MemoryOperationsStatus::SUCCESS;
}
void DrmMemoryOperationsHandlerBind::evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield) {
int DrmMemoryOperationsHandlerBind::evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield) {
auto drmAllocation = static_cast<DrmAllocation *>(&gfxAllocation);
for (auto drmIterator = 0u; drmIterator < deviceBitfield.size(); drmIterator++) {
if (deviceBitfield.test(drmIterator)) {
drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, false);
int retVal = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, false);
if (retVal) {
return retVal;
}
}
}
drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectNotResident, osContext->getContextId());
return 0;
}
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::isResident(Device *device, GraphicsAllocation &gfxAllocation) {
@ -92,8 +103,11 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::isResident(Device *device
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
}
void DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) {
this->makeResidentWithinOsContext(osContext, ArrayRef<GraphicsAllocation *>(residencyContainer), true);
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) {
MemoryOperationsStatus retVal = this->makeResidentWithinOsContext(osContext, ArrayRef<GraphicsAllocation *>(residencyContainer), true);
if (retVal != MemoryOperationsStatus::SUCCESS) {
return retVal;
}
auto clearContainer = true;
@ -104,6 +118,7 @@ void DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osCo
if (clearContainer) {
residencyContainer.clear();
}
return MemoryOperationsStatus::SUCCESS;
}
std::unique_lock<std::mutex> DrmMemoryOperationsHandlerBind::lockHandlerIfUsed() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -22,13 +22,13 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler {
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override;
void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
MemoryOperationsStatus mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;
protected:
void evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield);
MOCKABLE_VIRTUAL int evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield);
void evictUnusedAllocationsImpl(std::vector<GraphicsAllocation *> &allocationsForEviction, bool waitForCompletion);
RootDeviceEnvironment &rootDeviceEnvironment;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -47,13 +47,14 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::isResident(Device *dev
return MemoryOperationsStatus::SUCCESS;
}
void DrmMemoryOperationsHandlerDefault::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) {
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) {
for (auto gfxAllocation = this->residency.begin(); gfxAllocation != this->residency.end(); gfxAllocation++) {
auto ret = std::find(residencyContainer.begin(), residencyContainer.end(), *gfxAllocation);
if (ret == residencyContainer.end()) {
residencyContainer.push_back(*gfxAllocation);
}
}
return MemoryOperationsStatus::SUCCESS;
}
std::unique_lock<std::mutex> DrmMemoryOperationsHandlerDefault::lockHandlerIfUsed() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -23,7 +23,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler {
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override;
void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
MemoryOperationsStatus mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -7,6 +7,7 @@
#pragma once
#include "shared/source/command_stream/device_command_stream.h"
#include "shared/source/command_stream/submission_status.h"
struct COMMAND_BUFFER_HEADER_REC;
@ -24,7 +25,7 @@ class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily>
WddmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex, const DeviceBitfield deviceBitfield);
virtual ~WddmCommandStreamReceiver();
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
SubmissionStatus flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
void processResidency(const ResidencyContainer &allocationsForResidency, uint32_t handleId) override;
void processEviction() override;
bool waitForFlushStamp(FlushStamp &flushStampToWait) override;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -66,7 +66,7 @@ WddmCommandStreamReceiver<GfxFamily>::~WddmCommandStreamReceiver() {
}
template <typename GfxFamily>
bool WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
SubmissionStatus WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
this->printDeviceIndex();
auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
@ -75,10 +75,18 @@ bool WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Resid
perfLogResidencyVariadicLog(wddm->getResidencyLogger(), "Wddm CSR processing residency set: %zu\n", allocationsForResidency.size());
this->processResidency(allocationsForResidency, 0u);
if (this->directSubmission.get()) {
return this->directSubmission->dispatchCommandBuffer(batchBuffer, *(this->flushStamp.get()));
bool ret = this->directSubmission->dispatchCommandBuffer(batchBuffer, *(this->flushStamp.get()));
if (ret == false) {
return SubmissionStatus::FAILED;
}
return SubmissionStatus::SUCCESS;
}
if (this->blitterDirectSubmission.get()) {
return this->blitterDirectSubmission->dispatchCommandBuffer(batchBuffer, *(this->flushStamp.get()));
bool ret = this->blitterDirectSubmission->dispatchCommandBuffer(batchBuffer, *(this->flushStamp.get()));
if (ret == false) {
return SubmissionStatus::FAILED;
}
return SubmissionStatus::SUCCESS;
}
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandBufferHeader);
@ -110,7 +118,11 @@ bool WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, Resid
auto status = wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, submitArgs);
this->flushStamp->setStamp(submitArgs.monitorFence->lastSubmittedFence);
return status;
if (status == false) {
return SubmissionStatus::FAILED;
}
return SubmissionStatus::SUCCESS;
}
template <typename GfxFamily>