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