Move bind/unbind buffer objects methods to drm_neo.cpp

use ioctl helper to handle binding properly

Related-To: NEO-6591
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-02-15 17:28:38 +00:00
committed by Compute-Runtime-Automation
parent 74cdd60255
commit 4a24195e99
6 changed files with 165 additions and 8 deletions

View File

@@ -190,6 +190,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, LimitEngineCountForVirtualCcs, -1, "-1: default,
DECLARE_DEBUG_VARIABLE(int32_t, CreateContextWithAccessCounters, -1, "-1: default, 0: ignore, 1: create context with Access Counter programming")
DECLARE_DEBUG_VARIABLE(int32_t, AccessCountersTrigger, -1, "-1: default - disabled, 0: disabled, >= 0: triggering thresholds")
DECLARE_DEBUG_VARIABLE(int32_t, AccessCountersGranularity, -1, "-1: default - ACG_2MB, >= 0: granularites - 0: ACG_128K, 1: ACG_2M, 2: ACG_16M, 3: ACG_16M")
DECLARE_DEBUG_VARIABLE(int32_t, OverridePatIndex, -1, "-1: default, >=0: PatIndex to override")
/*LOGGING FLAGS*/
DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level")
DECLARE_DEBUG_VARIABLE(bool, PrintOsContextInitializations, false, "print initialized OsContexts to standard output")

View File

@@ -11,6 +11,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/cache_info_impl.h
${CMAKE_CURRENT_SOURCE_DIR}/clos_cache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/clos_cache.h
${CMAKE_CURRENT_SOURCE_DIR}/clos_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream.inl
${CMAKE_CURRENT_SOURCE_DIR}/device_time_drm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_time_drm.h

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/os_interface/linux/cache_info.h"
namespace NEO {
namespace ClosHelper {
/*
PAT Index CLOS MemType
SHARED
0 0 UC (00)
1 0 WC (01)
2 0 WT (10)
3 0 WB (11)
RESERVED 1
4 1 WT (10)
5 1 WB (11)
RESERVED 2
6 2 WT (10)
7 2 WB (11)
*/
constexpr uint64_t getPatIndex(CacheRegion closIndex, CachePolicy memType) {
UNRECOVERABLE_IF((closIndex > CacheRegion::Default) && (memType < CachePolicy::WriteThrough));
return (static_cast<uint32_t>(memType) + (static_cast<uint16_t>(closIndex) * 2));
}
} // namespace ClosHelper
} // namespace NEO

View File

@@ -17,9 +17,11 @@
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/linux/cache_info_impl.h"
#include "shared/source/os_interface/linux/clos_helper.h"
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
#include "shared/source/os_interface/linux/drm_gem_close_worker.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
#include "shared/source/os_interface/linux/hw_device_id.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
@@ -1191,4 +1193,127 @@ bool Drm::isVmBindAvailable() {
return bindAvailable;
}
int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleId, BufferObject *bo, bool bind) {
auto vmId = drm->getVirtualMemoryAddressSpace(vmHandleId);
auto ioctlHelper = drm->getIoctlHelper();
uint64_t flags = 0u;
if (drm->isPerContextVMRequired()) {
auto osContextLinux = static_cast<const OsContextLinux *>(osContext);
UNRECOVERABLE_IF(osContextLinux->getDrmVmIds().size() <= vmHandleId);
vmId = osContextLinux->getDrmVmIds()[vmHandleId];
}
std::unique_ptr<uint8_t[]> extensions;
if (bind) {
bool allowUUIDsForDebug = !osContext->isInternalEngine() && !EngineHelpers::isBcs(osContext->getEngineType());
if (bo->getBindExtHandles().size() > 0 && allowUUIDsForDebug) {
extensions = ioctlHelper->prepareVmBindExt(bo->getBindExtHandles());
}
bool bindCapture = bo->isMarkedForCapture();
bool bindImmediate = bo->isImmediateBindingRequired();
bool bindMakeResident = false;
if (drm->useVMBindImmediate()) {
bindMakeResident = bo->isExplicitResidencyRequired();
bindImmediate = true;
}
flags |= ioctlHelper->getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident);
}
auto bindAddresses = bo->getColourAddresses();
auto bindIterations = bindAddresses.size();
if (bindIterations == 0) {
bindIterations = 1;
}
int ret = 0;
for (size_t i = 0; i < bindIterations; i++) {
VmBindParams vmBind{};
vmBind.vmId = static_cast<uint32_t>(vmId);
vmBind.flags = flags;
vmBind.handle = bo->peekHandle();
vmBind.length = bo->peekSize();
vmBind.offset = 0;
vmBind.start = bo->peekAddress();
if (bo->getColourWithBind()) {
vmBind.length = bo->getColourChunk();
vmBind.offset = bo->getColourChunk() * i;
vmBind.start = bindAddresses[i];
}
auto hwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily);
bool closEnabled = (hwHelper.getNumCacheRegions() > 0);
if (DebugManager.flags.ClosEnabled.get() != -1) {
closEnabled = !!DebugManager.flags.ClosEnabled.get();
}
auto vmBindExtSetPat = ioctlHelper->createVmBindExtSetPat();
if (closEnabled) {
uint64_t patIndex = ClosHelper::getPatIndex(bo->peekCacheRegion(), bo->peekCachePolicy());
if (DebugManager.flags.OverridePatIndex.get() != -1) {
patIndex = static_cast<uint64_t>(DebugManager.flags.OverridePatIndex.get());
}
ioctlHelper->fillVmBindExtSetPat(vmBindExtSetPat, patIndex, castToUint64(extensions.get()));
vmBind.extensions = castToUint64(vmBindExtSetPat.get());
} else {
vmBind.extensions = castToUint64(extensions.get());
}
if (bind) {
std::unique_lock<std::mutex> lock;
auto vmBindExtSyncFence = ioctlHelper->createVmBindExtSyncFence();
if (drm->useVMBindImmediate()) {
lock = drm->lockBindFenceMutex();
if (!drm->hasPageFaultSupport() || bo->isExplicitResidencyRequired()) {
auto nextExtension = vmBind.extensions;
auto address = castToUint64(drm->getFenceAddr(vmHandleId));
auto value = drm->getNextFenceVal(vmHandleId);
ioctlHelper->fillVmBindExtSyncFence(vmBindExtSyncFence, address, value, nextExtension);
vmBind.extensions = castToUint64(vmBindExtSyncFence.get());
}
}
ret = ioctlHelper->vmBind(drm, vmBind);
if (ret) {
break;
}
drm->setNewResourceBoundToVM(vmHandleId);
} else {
vmBind.handle = 0u;
ret = ioctlHelper->vmUnbind(drm, vmBind);
if (ret) {
break;
}
}
}
return ret;
}
int Drm::bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) {
auto ret = changeBufferObjectBinding(this, osContext, vmHandleId, bo, true);
if (ret != 0) {
static_cast<DrmMemoryOperationsHandlerBind *>(this->rootDeviceEnvironment.memoryOperationsInterface.get())->evictUnusedAllocations(false, false);
ret = changeBufferObjectBinding(this, osContext, vmHandleId, bo, true);
}
return ret;
}
int Drm::unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) {
return changeBufferObjectBinding(this, osContext, vmHandleId, bo, false);
}
} // namespace NEO

View File

@@ -28,12 +28,4 @@ bool Drm::isDebugAttachAvailable() {
return false;
}
int Drm::bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) {
return 0;
}
int Drm::unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) {
return 0;
}
} // namespace NEO