2018-08-23 23:53:58 +08:00
|
|
|
/*
|
2023-01-02 19:52:22 +08:00
|
|
|
* Copyright (C) 2018-2023 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-02-10 23:13:50 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2023-05-24 00:06:03 +08:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
2023-01-23 22:55:52 +08:00
|
|
|
#include "shared/source/os_interface/linux/ioctl_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2023-03-10 20:28:11 +08:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2023-03-31 19:41:17 +08:00
|
|
|
#include "shared/source/os_interface/sys_calls_common.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
|
|
|
|
2022-11-17 03:31:25 +08:00
|
|
|
OsContext *OsContextLinux::create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor) {
|
2018-11-08 20:05:46 +08:00
|
|
|
if (osInterface) {
|
2022-11-17 03:31:25 +08:00
|
|
|
return new OsContextLinux(*osInterface->getDriverModel()->as<Drm>(), rootDeviceIndex, contextId, engineDescriptor);
|
2018-11-08 20:05:46 +08:00
|
|
|
}
|
2022-11-17 03:31:25 +08:00
|
|
|
return new OsContext(rootDeviceIndex, contextId, engineDescriptor);
|
2018-08-23 23:53:58 +08:00
|
|
|
}
|
|
|
|
|
2022-11-17 03:31:25 +08:00
|
|
|
OsContextLinux::OsContextLinux(Drm &drm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
|
|
|
|
: OsContext(rootDeviceIndex, contextId, engineDescriptor),
|
2023-05-24 00:06:03 +08:00
|
|
|
drm(drm) {
|
|
|
|
pagingFence.fill(0u);
|
|
|
|
fenceVal.fill(0u);
|
|
|
|
}
|
2021-04-16 00:14:04 +08:00
|
|
|
|
2023-02-12 06:03:06 +08:00
|
|
|
bool 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);
|
2020-08-17 18:07:39 +08:00
|
|
|
|
|
|
|
if (drm.isPerContextVMRequired()) {
|
2023-03-17 19:50:23 +08:00
|
|
|
drmVmId = deviceIndex;
|
|
|
|
[[maybe_unused]] auto ret = drm.createDrmVirtualMemory(drmVmId);
|
2020-08-31 13:04:58 +08:00
|
|
|
DEBUG_BREAK_IF(drmVmId == 0);
|
|
|
|
DEBUG_BREAK_IF(ret != 0);
|
2023-03-17 19:50:23 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
}
|
2023-03-17 19:50:23 +08:00
|
|
|
|
|
|
|
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId, deviceIndex);
|
|
|
|
if (drmContextId < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->drmContextIds.push_back(drmContextId);
|
2019-07-11 20:29:45 +08:00
|
|
|
}
|
2018-12-11 15:21:56 +08:00
|
|
|
}
|
2023-02-12 06:03:06 +08:00
|
|
|
return true;
|
2018-12-11 15:21:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-31 21:06:23 +08:00
|
|
|
bool OsContextLinux::isDirectSubmissionSupported(const HardwareInfo &hwInfo) const {
|
2023-01-02 19:52:22 +08:00
|
|
|
auto &productHelper = this->getDrm().getRootDeviceEnvironment().getHelper<ProductHelper>();
|
|
|
|
|
|
|
|
return this->getDrm().isVmBindAvailable() && productHelper.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)) {
|
2023-05-24 00:06:03 +08:00
|
|
|
this->waitForBind(drmIterator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsContextLinux::waitForBind(uint32_t drmIterator) {
|
|
|
|
if (drm.isPerContextVMRequired()) {
|
|
|
|
if (pagingFence[drmIterator] >= fenceVal[drmIterator]) {
|
|
|
|
return;
|
2021-02-05 23:27:21 +08:00
|
|
|
}
|
2023-05-24 00:06:03 +08:00
|
|
|
auto lock = drm.lockBindFenceMutex();
|
|
|
|
auto fenceAddress = castToUint64(&this->pagingFence[drmIterator]);
|
|
|
|
auto fenceValue = this->fenceVal[drmIterator];
|
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
drm.waitUserFence(0u, fenceAddress, fenceValue, Drm::ValueWidth::U64, -1, drm.getIoctlHelper()->getWaitUserFenceSoftFlag());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
drm.waitForBind(drmIterator);
|
2021-02-05 23:27:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 10:13:00 +08:00
|
|
|
void OsContextLinux::reInitializeContext() {}
|
|
|
|
|
2023-03-31 19:41:17 +08:00
|
|
|
uint64_t OsContextLinux::getOfflineDumpContextId(uint32_t deviceIndex) const {
|
|
|
|
if (deviceIndex < drmContextIds.size()) {
|
|
|
|
const auto processId = SysCalls::getProcessId();
|
|
|
|
const auto drmContextId = drmContextIds[deviceIndex];
|
|
|
|
return static_cast<uint64_t>(processId) << 32 |
|
|
|
|
static_cast<uint64_t>(drmContextId);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|