2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-12-30 14:40:24 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-19 20:54:29 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
|
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
|
|
|
|
#include "shared/source/gmm_helper/page_table_mngr.h"
|
|
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
|
#include "shared/source/helpers/flush_stamp.h"
|
2020-05-15 13:52:11 +02:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/preamble.h"
|
|
|
|
|
#include "shared/source/memory_manager/residency.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/drm_allocation.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/drm_buffer_object.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
2020-05-08 10:04:06 +02:00
|
|
|
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/os_context_linux.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/os_interface.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/os_interface/linux/drm_command_stream.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-10-29 08:01:53 +01:00
|
|
|
DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex, gemCloseWorkerMode mode)
|
|
|
|
|
: BaseClass(executionEnvironment, rootDeviceIndex), gemCloseWorkerOperationMode(mode) {
|
2018-09-17 15:42:15 +02:00
|
|
|
|
2020-05-15 13:52:11 +02:00
|
|
|
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get();
|
|
|
|
|
|
|
|
|
|
this->drm = rootDeviceEnvironment->osInterface->get()->getDrm();
|
2018-08-30 09:27:47 +02:00
|
|
|
residency.reserve(512);
|
|
|
|
|
execObjectsStorage.reserve(512);
|
2020-05-15 13:52:11 +02:00
|
|
|
|
|
|
|
|
auto hwInfo = rootDeviceEnvironment->getHardwareInfo();
|
|
|
|
|
auto localMemoryEnabled = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo);
|
|
|
|
|
|
|
|
|
|
this->dispatchMode = localMemoryEnabled ? DispatchMode::BatchedDispatch : DispatchMode::ImmediateDispatch;
|
|
|
|
|
|
|
|
|
|
if (DebugManager.flags.CsrDispatchMode.get()) {
|
|
|
|
|
this->dispatchMode = static_cast<DispatchMode>(DebugManager.flags.CsrDispatchMode.get());
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-11-24 14:50:41 +01:00
|
|
|
bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
2020-04-30 13:24:34 +02:00
|
|
|
this->printDeviceIndex();
|
2017-12-21 00:45:38 +01:00
|
|
|
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
|
|
|
|
|
DEBUG_BREAK_IF(!alloc);
|
|
|
|
|
|
|
|
|
|
BufferObject *bb = alloc->getBO();
|
2019-09-23 16:30:31 +02:00
|
|
|
if (bb == nullptr) {
|
2019-11-24 14:50:41 +01:00
|
|
|
return false;
|
2019-09-23 16:30:31 +02:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-08-21 03:50:47 -07:00
|
|
|
if (this->lastSentSliceCount != batchBuffer.sliceCount) {
|
|
|
|
|
if (drm->setQueueSliceCount(batchBuffer.sliceCount)) {
|
|
|
|
|
this->lastSentSliceCount = batchBuffer.sliceCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 10:04:06 +02:00
|
|
|
auto memoryOperationsInterface = this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get();
|
|
|
|
|
static_cast<DrmMemoryOperationsHandler *>(memoryOperationsInterface)->mergeWithResidencyContainer(allocationsForResidency);
|
|
|
|
|
|
2019-11-24 14:50:41 +01:00
|
|
|
this->flushStamp->setStamp(bb->peekHandle());
|
2019-09-23 16:30:31 +02:00
|
|
|
this->flushInternal(batchBuffer, allocationsForResidency);
|
2018-05-11 09:57:59 +02:00
|
|
|
|
2019-10-30 20:05:41 +01:00
|
|
|
if (this->gemCloseWorkerOperationMode == gemCloseWorkerMode::gemCloseWorkerActive) {
|
2019-09-23 16:30:31 +02:00
|
|
|
bb->reference();
|
|
|
|
|
this->getMemoryManager()->peekGemCloseWorker()->push(bb);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-24 14:50:41 +01:00
|
|
|
return true;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-23 16:30:31 +02:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::exec(const BatchBuffer &batchBuffer, uint32_t drmContextId) {
|
|
|
|
|
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
|
|
|
|
|
DEBUG_BREAK_IF(!alloc);
|
|
|
|
|
BufferObject *bb = alloc->getBO();
|
|
|
|
|
DEBUG_BREAK_IF(!bb);
|
|
|
|
|
|
2020-05-21 12:21:13 +02:00
|
|
|
auto execFlags = static_cast<OsContextLinux *>(osContext)->getEngineFlag() | I915_EXEC_NO_RELOC;
|
|
|
|
|
if (DebugManager.flags.UseAsyncDrmExec.get() != -1) {
|
|
|
|
|
execFlags |= (EXEC_OBJECT_ASYNC * DebugManager.flags.UseAsyncDrmExec.get());
|
|
|
|
|
}
|
2019-09-23 16:30:31 +02:00
|
|
|
|
|
|
|
|
// Residency hold all allocation except command buffer, hence + 1
|
|
|
|
|
auto requiredSize = this->residency.size() + 1;
|
|
|
|
|
if (requiredSize > this->execObjectsStorage.size()) {
|
|
|
|
|
this->execObjectsStorage.resize(requiredSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int err = bb->exec(static_cast<uint32_t>(alignUp(batchBuffer.usedSize - batchBuffer.startOffset, 8)),
|
2020-05-21 12:21:13 +02:00
|
|
|
batchBuffer.startOffset, execFlags,
|
2019-09-23 16:30:31 +02:00
|
|
|
batchBuffer.requiresCoherency,
|
|
|
|
|
drmContextId,
|
2020-05-06 03:37:15 -07:00
|
|
|
this->residency.data(), this->residency.size(),
|
2019-09-23 16:30:31 +02:00
|
|
|
this->execObjectsStorage.data());
|
|
|
|
|
UNRECOVERABLE_IF(err != 0);
|
|
|
|
|
|
|
|
|
|
this->residency.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::makeResident(BufferObject *bo) {
|
2018-11-08 18:30:13 +01:00
|
|
|
if (bo) {
|
2020-05-06 03:37:15 -07:00
|
|
|
if (bo->peekIsReusableAllocation()) {
|
|
|
|
|
for (auto bufferObject : this->residency) {
|
|
|
|
|
if (bufferObject == bo) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
residency.push_back(bo);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2020-02-03 17:50:53 +01:00
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::processResidency(const ResidencyContainer &inputAllocationsForResidency, uint32_t handleId) {
|
2018-09-14 10:39:21 +02:00
|
|
|
for (auto &alloc : inputAllocationsForResidency) {
|
2019-07-29 16:11:51 +02:00
|
|
|
auto drmAlloc = static_cast<const DrmAllocation *>(alloc);
|
2017-12-21 00:45:38 +01:00
|
|
|
if (drmAlloc->fragmentsStorage.fragmentCount) {
|
2018-06-08 14:40:21 +02:00
|
|
|
for (unsigned int f = 0; f < drmAlloc->fragmentsStorage.fragmentCount; f++) {
|
2018-11-28 11:01:41 +01:00
|
|
|
const auto osContextId = osContext->getContextId();
|
|
|
|
|
if (!drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId]) {
|
2018-11-08 18:30:13 +01:00
|
|
|
makeResident(drmAlloc->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo);
|
2018-11-28 11:01:41 +01:00
|
|
|
drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId] = true;
|
2018-11-08 18:30:13 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2020-02-03 17:50:53 +01:00
|
|
|
makeResidentBufferObjects(drmAlloc, handleId);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void DrmCommandStreamReceiver<GfxFamily>::makeNonResident(GraphicsAllocation &gfxAllocation) {
|
|
|
|
|
// Vector is moved to command buffer inside flush.
|
|
|
|
|
// If flush wasn't called we need to make all objects non-resident.
|
|
|
|
|
// If makeNonResident is called before flush, vector will be cleared.
|
2018-12-03 10:05:36 +01:00
|
|
|
if (gfxAllocation.isResident(this->osContext->getContextId())) {
|
2017-12-21 00:45:38 +01:00
|
|
|
if (this->residency.size() != 0) {
|
|
|
|
|
this->residency.clear();
|
|
|
|
|
}
|
2019-07-29 16:11:51 +02:00
|
|
|
for (auto fragmentId = 0u; fragmentId < gfxAllocation.fragmentsStorage.fragmentCount; fragmentId++) {
|
|
|
|
|
gfxAllocation.fragmentsStorage.fragmentStorageData[fragmentId].residency->resident[osContext->getContextId()] = false;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-01-07 09:29:49 +01:00
|
|
|
gfxAllocation.releaseResidencyInOsContext(this->osContext->getContextId());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-07-29 16:11:51 +02:00
|
|
|
DrmMemoryManager *DrmCommandStreamReceiver<GfxFamily>::getMemoryManager() const {
|
|
|
|
|
return static_cast<DrmMemoryManager *>(CommandStreamReceiver::getMemoryManager());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-06 18:14:30 +01:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
GmmPageTableMngr *DrmCommandStreamReceiver<GfxFamily>::createPageTableManager() {
|
2020-02-24 18:04:30 +01:00
|
|
|
GmmPageTableMngr *gmmPageTableMngr = GmmPageTableMngr::create(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->getGmmClientContext(), TT_TYPE::AUXTT, nullptr);
|
2019-11-06 18:14:30 +01:00
|
|
|
gmmPageTableMngr->setCsrHandle(this);
|
|
|
|
|
this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->pageTableManager.reset(gmmPageTableMngr);
|
|
|
|
|
return gmmPageTableMngr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template <typename GfxFamily>
|
2018-11-26 14:04:52 +01:00
|
|
|
bool DrmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStamp) {
|
2017-12-21 00:45:38 +01:00
|
|
|
drm_i915_gem_wait wait = {};
|
2018-02-02 10:33:31 +01:00
|
|
|
wait.bo_handle = static_cast<uint32_t>(flushStamp);
|
2017-12-21 00:45:38 +01:00
|
|
|
wait.timeout_ns = -1;
|
|
|
|
|
|
|
|
|
|
drm->ioctl(DRM_IOCTL_I915_GEM_WAIT, &wait);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|