2018-08-23 17:53:58 +02:00
|
|
|
/*
|
2021-01-25 20:43:48 +00:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
2018-08-23 17:53:58 +02:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/os_context_linux.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2021-04-01 14:12:51 +00:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2021-01-25 20:43:48 +00:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2021-03-12 10:46:18 +00:00
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
2021-03-31 13:06:23 +00:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2021-02-10 15:13:50 +00:00
|
|
|
#include "shared/source/helpers/hw_info.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_interface.h"
|
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2018-08-23 17:53:58 +02:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-11-08 13:05:46 +01:00
|
|
|
|
2019-03-13 15:00:07 +01:00
|
|
|
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield,
|
2021-03-08 18:50:32 +00:00
|
|
|
EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice) {
|
2018-11-08 13:05:46 +01:00
|
|
|
if (osInterface) {
|
2021-03-08 18:50:32 +00:00
|
|
|
return new OsContextLinux(*osInterface->get()->getDrm(), contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice);
|
2018-11-08 13:05:46 +01:00
|
|
|
}
|
2021-03-08 18:50:32 +00:00
|
|
|
return new OsContext(contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice);
|
2018-08-23 17:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:00:07 +01:00
|
|
|
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, DeviceBitfield deviceBitfield,
|
2021-03-08 18:50:32 +00:00
|
|
|
EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice)
|
|
|
|
|
: OsContext(contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice),
|
2020-03-03 23:33:31 +01:00
|
|
|
drm(drm) {
|
2021-02-10 15:13:50 +00:00
|
|
|
auto hwInfo = drm.getRootDeviceEnvironment().getHardwareInfo();
|
|
|
|
|
auto defaultEngineType = getChosenEngineType(*hwInfo);
|
|
|
|
|
|
2021-03-08 18:50:32 +00:00
|
|
|
if (engineType == defaultEngineType && !isLowPriority() && !isInternalEngine()) {
|
2021-02-10 15:13:50 +00:00
|
|
|
this->setDefaultContext(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool submitDirect = false;
|
|
|
|
|
this->isDirectSubmissionAvailable(*drm.getRootDeviceEnvironment().getHardwareInfo(), submitDirect);
|
|
|
|
|
|
2019-07-11 14:29:45 +02:00
|
|
|
for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) {
|
|
|
|
|
if (deviceBitfield.test(deviceIndex)) {
|
2020-07-07 09:34:31 +02:00
|
|
|
auto drmVmId = drm.getVirtualMemoryAddressSpace(deviceIndex);
|
2021-02-10 15:13:50 +00:00
|
|
|
auto drmContextId = drm.createDrmContext(drmVmId, this->isDirectSubmissionActive());
|
2020-02-10 08:05:32 -08:00
|
|
|
if (drm.areNonPersistentContextsSupported()) {
|
2019-12-24 12:20:23 +01:00
|
|
|
drm.setNonPersistentContext(drmContextId);
|
2019-12-18 19:38:22 +01:00
|
|
|
}
|
2021-01-25 20:43:48 +00:00
|
|
|
|
2021-03-08 18:50:32 +00:00
|
|
|
if (drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled() && !isInternalEngine()) {
|
2021-01-25 20:43:48 +00:00
|
|
|
drm.setContextDebugFlag(drmContextId);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 14:12:51 +00:00
|
|
|
auto lowPriorityDirectSubmissionBcs = this->isDirectSubmissionActive() && EngineHelpers::isBcs(engineType);
|
|
|
|
|
|
|
|
|
|
if (DebugManager.flags.DirectSubmissionLowPriorityBlitter.get() != -1) {
|
|
|
|
|
lowPriorityDirectSubmissionBcs = DebugManager.flags.DirectSubmissionLowPriorityBlitter.get();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 18:50:32 +00:00
|
|
|
if ((drm.isPreemptionSupported() && isLowPriority()) ||
|
2021-04-01 14:12:51 +00:00
|
|
|
lowPriorityDirectSubmissionBcs) {
|
2019-07-11 14:29:45 +02:00
|
|
|
drm.setLowPriorityContextParam(drmContextId);
|
|
|
|
|
}
|
2021-03-12 10:46:18 +00:00
|
|
|
|
2019-07-11 14:29:45 +02:00
|
|
|
this->engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, engineType);
|
|
|
|
|
this->drmContextIds.push_back(drmContextId);
|
2020-08-17 12:07:39 +02:00
|
|
|
|
|
|
|
|
if (drm.isPerContextVMRequired()) {
|
2020-08-31 07:04:58 +02:00
|
|
|
auto ret = drm.queryVmId(drmContextId, drmVmId);
|
|
|
|
|
DEBUG_BREAK_IF(drmVmId == 0);
|
|
|
|
|
DEBUG_BREAK_IF(ret != 0);
|
|
|
|
|
UNUSED_VARIABLE(ret);
|
2020-08-17 12:07:39 +02:00
|
|
|
this->drmVmIds.push_back(drmVmId);
|
|
|
|
|
}
|
2019-07-11 14:29:45 +02:00
|
|
|
}
|
2018-12-11 08:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-31 13:06:23 +00:00
|
|
|
bool OsContextLinux::isDirectSubmissionSupported(const HardwareInfo &hwInfo) const {
|
|
|
|
|
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
|
|
|
|
return this->getDrm().isVmBindAvailable() && hwHelper.isDirectSubmissionSupported();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-02 11:49:46 +02:00
|
|
|
Drm &OsContextLinux::getDrm() const {
|
|
|
|
|
return this->drm;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 15:27:21 +00:00
|
|
|
void OsContextLinux::waitForPagingFence() {
|
|
|
|
|
for (auto drmIterator = 0u; drmIterator < this->deviceBitfield.size(); drmIterator++) {
|
|
|
|
|
if (this->deviceBitfield.test(drmIterator)) {
|
|
|
|
|
drm.waitForBind(drmIterator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 11:17:17 +01:00
|
|
|
OsContextLinux::~OsContextLinux() {
|
2019-07-11 14:29:45 +02:00
|
|
|
for (auto drmContextId : drmContextIds) {
|
|
|
|
|
drm.destroyDrmContext(drmContextId);
|
|
|
|
|
}
|
2018-11-26 14:04:52 +01:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|