Skip to content

Commit 9fa1c9d

Browse files
Extract create drm context logic to ioctl helper
Related-To: NEO-6999 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 14134be commit 9fa1c9d

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

shared/source/os_interface/linux/ioctl_helper.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
#include "shared/source/os_interface/linux/ioctl_helper.h"
99

1010
#include "shared/source/debug_settings/debug_settings_manager.h"
11+
#include "shared/source/execution_environment/execution_environment.h"
12+
#include "shared/source/execution_environment/root_device_environment.h"
13+
#include "shared/source/helpers/hw_info.h"
1114
#include "shared/source/helpers/ptr_math.h"
1215
#include "shared/source/os_interface/linux/drm_neo.h"
1316
#include "shared/source/os_interface/linux/drm_wrappers.h"
17+
#include "shared/source/os_interface/os_context.h"
1418

1519
#include "drm/i915_drm.h"
1620

@@ -78,4 +82,28 @@ void IoctlHelper::logExecBuffer(const ExecBuffer &execBuffer, std::stringstream
7882
<< " }\n";
7983
}
8084

85+
uint32_t IoctlHelper::createDrmContext(Drm &drm, const OsContext &osContext, uint32_t drmVmId) {
86+
87+
const auto numberOfCCS = drm.getRootDeviceEnvironment().getHardwareInfo()->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
88+
const bool debuggableContext = drm.isContextDebugSupported() && drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled() && !osContext.isInternalEngine();
89+
const bool debuggableContextCooperative = debuggableContext && numberOfCCS > 0;
90+
auto drmContextId = drm.createDrmContext(drmVmId, drm.isVmBindAvailable(), osContext.isCooperativeEngine() || debuggableContextCooperative);
91+
if (drm.areNonPersistentContextsSupported()) {
92+
drm.setNonPersistentContext(drmContextId);
93+
}
94+
95+
if (drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) {
96+
drm.setUnrecoverableContext(drmContextId);
97+
}
98+
99+
if (debuggableContext) {
100+
drm.setContextDebugFlag(drmContextId);
101+
}
102+
103+
if (drm.isPreemptionSupported() && osContext.isLowPriority()) {
104+
drm.setLowPriorityContextParam(drmContextId);
105+
}
106+
return drmContextId;
107+
}
108+
81109
} // namespace NEO

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace NEO {
2222
class Drm;
23+
class OsContext;
2324
class IoctlHelper;
2425
enum class CacheRegion : uint16_t;
2526
struct HardwareInfo;
@@ -116,6 +117,8 @@ class IoctlHelper {
116117
virtual bool isDebugAttachAvailable() = 0;
117118
virtual unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest) = 0;
118119

120+
uint32_t createDrmContext(Drm &drm, const OsContext &osContext, uint32_t drmVmId);
121+
119122
void fillExecObject(ExecObject &execObject, uint32_t handle, uint64_t gpuAddress, uint32_t drmContextId, bool bindInfo, bool isMarkedForCapture);
120123
void logExecObject(const ExecObject &execObject, std::stringstream &logger, size_t size);
121124

shared/source/os_interface/linux/os_context_linux.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,10 @@ void OsContextLinux::initializeContext() {
4545
this->drmVmIds.resize(deviceBitfield.size(), 0);
4646
}
4747

48-
const auto numberOfCCS = drm.getRootDeviceEnvironment().getHardwareInfo()->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
49-
const bool debuggableContext = drm.isContextDebugSupported() && drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled() && !isInternalEngine();
50-
const bool debuggableContextCooperative = debuggableContext && numberOfCCS > 0;
51-
5248
for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) {
5349
if (deviceBitfield.test(deviceIndex)) {
5450
auto drmVmId = drm.getVirtualMemoryAddressSpace(deviceIndex);
55-
auto drmContextId = drm.createDrmContext(drmVmId, drm.isVmBindAvailable(), isCooperativeEngine() || debuggableContextCooperative);
56-
if (drm.areNonPersistentContextsSupported()) {
57-
drm.setNonPersistentContext(drmContextId);
58-
}
59-
60-
if (drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) {
61-
drm.setUnrecoverableContext(drmContextId);
62-
}
63-
64-
if (debuggableContext) {
65-
drm.setContextDebugFlag(drmContextId);
66-
}
67-
68-
if (drm.isPreemptionSupported() && isLowPriority()) {
69-
drm.setLowPriorityContextParam(drmContextId);
70-
}
51+
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId);
7152

7253
this->engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, engineType, isEngineInstanced());
7354
this->drmContextIds.push_back(drmContextId);

0 commit comments

Comments
 (0)