Skip to content

Commit aa191b6

Browse files
feature: Set runalone mode for contexts with online debugging
Related-To: NEO-9139 Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
1 parent 68b0d81 commit aa191b6

File tree

9 files changed

+137
-1
lines changed

9 files changed

+137
-1
lines changed

shared/source/helpers/gfx_core_helper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct LrcaHelper;
2626
namespace NEO {
2727
enum class AuxTranslationMode;
2828
struct FeatureTable;
29+
enum class DebuggingMode : uint32_t;
2930
enum class PostSyncMode : uint32_t;
3031
enum class CachePolicy : uint32_t;
3132
enum class CacheRegion : uint16_t;
@@ -137,6 +138,7 @@ class GfxCoreHelper {
137138
virtual size_t getTimestampPacketAllocatorAlignment() const = 0;
138139
virtual size_t getSingleTimestampPacketSize() const = 0;
139140
virtual void applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const = 0;
141+
virtual bool isRunaloneModeRequired(DebuggingMode debuggingMode) const = 0;
140142
virtual void applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const = 0;
141143
virtual bool unTypedDataPortCacheFlushRequired() const = 0;
142144
virtual bool isEngineTypeRemappingToHwSpecificRequired() const = 0;
@@ -357,6 +359,8 @@ class GfxCoreHelperHw : public GfxCoreHelper {
357359

358360
void applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const override;
359361

362+
bool isRunaloneModeRequired(DebuggingMode debuggingMode) const override;
363+
360364
void applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const override;
361365

362366
bool unTypedDataPortCacheFlushRequired() const override;

shared/source/helpers/gfx_core_helper_base.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ size_t GfxCoreHelperHw<GfxFamily>::getPreemptionAllocationAlignment() const {
584584
template <typename GfxFamily>
585585
void GfxCoreHelperHw<GfxFamily>::applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const {}
586586

587+
template <typename GfxFamily>
588+
bool GfxCoreHelperHw<GfxFamily>::isRunaloneModeRequired(DebuggingMode debuggingMode) const {
589+
return false;
590+
}
591+
587592
template <typename GfxFamily>
588593
void GfxCoreHelperHw<GfxFamily>::applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const {
589594
gmm.resourceParams.Flags.Info.RenderCompressed = isCompressed;

shared/source/os_interface/linux/drm_neo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Drm : public DriverModel {
105105
int queryVmId(uint32_t drmContextId, uint32_t &vmId);
106106
void setLowPriorityContextParam(uint32_t drmContextId);
107107

108-
unsigned int bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice);
108+
MOCKABLE_VIRTUAL unsigned int bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice);
109109

110110
MOCKABLE_VIRTUAL int getErrno();
111111
bool setQueueSliceCount(uint64_t sliceCount);

shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "shared/source/helpers/common_types.h"
1818
#include "shared/source/helpers/constants.h"
1919
#include "shared/source/helpers/engine_control.h"
20+
#include "shared/source/helpers/gfx_core_helper.h"
2021
#include "shared/source/helpers/hw_info.h"
2122
#include "shared/source/helpers/ptr_math.h"
2223
#include "shared/source/helpers/register_offsets.h"
@@ -1209,6 +1210,17 @@ int IoctlHelperXe::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_
12091210
create.instances = castToUint64(engine.data());
12101211
create.num_placements = engine.size();
12111212

1213+
struct drm_xe_ext_set_property ext {};
1214+
auto &gfxCoreHelper = drm.getRootDeviceEnvironment().getHelper<GfxCoreHelper>();
1215+
if (gfxCoreHelper.isRunaloneModeRequired(drm.getRootDeviceEnvironment().executionEnvironment.getDebuggingMode())) {
1216+
ext.base.next_extension = 0;
1217+
ext.base.name = DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY;
1218+
ext.property = getRunaloneExtProperty();
1219+
ext.value = 1;
1220+
1221+
create.extensions = castToUint64(&ext);
1222+
}
1223+
12121224
int ret = IoctlHelper::ioctl(DrmIoctl::gemContextCreateExt, &create);
12131225
drmContextId = create.exec_queue_id;
12141226
xeLog("%s:%d (%d) vmid=0x%x ctx=0x%x r=0x%x\n", xeGetClassName(engine[0].engine_class),

shared/source/os_interface/linux/xe/ioctl_helper_xe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class IoctlHelperXe : public IoctlHelper {
147147
void updateBindInfo(uint32_t handle, uint64_t userPtr, uint64_t size);
148148
void *allocateDebugMetadata();
149149
void *freeDebugMetadata(void *metadata);
150+
int getRunaloneExtProperty();
150151

151152
struct UserFenceExtension {
152153
static constexpr uint32_t tagValue = 0x123987;

shared/source/os_interface/linux/xe/ioctl_helper_xe_debugger.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,8 @@ void IoctlHelperXe::addDebugMetadata(DrmResourceClass type, uint64_t *offset, ui
104104
return;
105105
}
106106

107+
int IoctlHelperXe::getRunaloneExtProperty() {
108+
return DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE;
109+
}
110+
107111
} // namespace NEO

shared/test/common/mocks/linux/debug_mock_drm_xe.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using namespace NEO;
3131
struct MockIoctlHelperXeDebug : IoctlHelperXe {
3232
using IoctlHelperXe::debugMetadata;
3333
using IoctlHelperXe::freeDebugMetadata;
34+
using IoctlHelperXe::getRunaloneExtProperty;
3435
using IoctlHelperXe::IoctlHelperXe;
3536
};
3637

@@ -52,13 +53,36 @@ class DrmMockXeDebug : public DrmMockCustom {
5253
bool baseErrno = false;
5354
int errnoRetVal = 0;
5455

56+
unsigned int bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice) override {
57+
return static_cast<unsigned int>(DrmParam::execDefault);
58+
}
59+
5560
int ioctl(DrmIoctl request, void *arg) override {
5661
int ret = -1;
5762
ioctlCalled = true;
5863
if (forceIoctlAnswer) {
5964
return setIoctlAnswer;
6065
}
6166
switch (request) {
67+
case DrmIoctl::query: {
68+
struct drm_xe_device_query *deviceQuery = static_cast<struct drm_xe_device_query *>(arg);
69+
switch (deviceQuery->query) {
70+
case DRM_XE_DEVICE_QUERY_ENGINES:
71+
if (deviceQuery->data) {
72+
memcpy_s(reinterpret_cast<void *>(deviceQuery->data), deviceQuery->size, queryEngines, sizeof(queryEngines));
73+
}
74+
deviceQuery->size = sizeof(queryEngines);
75+
break;
76+
};
77+
ret = 0;
78+
} break;
79+
case DrmIoctl::gemContextCreateExt: {
80+
auto create = static_cast<struct drm_xe_exec_queue_create *>(arg);
81+
if (create->extensions) {
82+
receivedContextCreateSetParam = *reinterpret_cast<struct drm_xe_ext_set_property *>(create->extensions);
83+
}
84+
ret = 0;
85+
} break;
6286
case DrmIoctl::gemVmCreate: {
6387
struct drm_xe_vm_create *v = static_cast<struct drm_xe_vm_create *>(arg);
6488
drm_xe_ext_vm_set_debug_metadata *metadata = reinterpret_cast<drm_xe_ext_vm_set_debug_metadata *>(v->extensions);
@@ -112,6 +136,20 @@ class DrmMockXeDebug : public DrmMockCustom {
112136
return allowDebugAttach;
113137
}
114138

139+
const drm_xe_engine_class_instance queryEngines[11] = {
140+
{DRM_XE_ENGINE_CLASS_RENDER, 0, 0},
141+
{DRM_XE_ENGINE_CLASS_COPY, 1, 0},
142+
{DRM_XE_ENGINE_CLASS_COPY, 2, 0},
143+
{DRM_XE_ENGINE_CLASS_COMPUTE, 3, 0},
144+
{DRM_XE_ENGINE_CLASS_COMPUTE, 4, 0},
145+
{DRM_XE_ENGINE_CLASS_COMPUTE, 5, 1},
146+
{DRM_XE_ENGINE_CLASS_COMPUTE, 6, 1},
147+
{DRM_XE_ENGINE_CLASS_COMPUTE, 7, 1},
148+
{DRM_XE_ENGINE_CLASS_COMPUTE, 8, 1},
149+
{DRM_XE_ENGINE_CLASS_VIDEO_DECODE, 9, 1},
150+
{DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE, 10, 0}};
151+
152+
struct drm_xe_ext_set_property receivedContextCreateSetParam = {};
115153
bool allowDebugAttachCallBase = false;
116154
bool allowDebugAttach = false;
117155
bool ioctlCalled = false;

shared/test/unit_test/helpers/gfx_core_helper_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,12 @@ HWTEST2_F(GfxCoreHelperTest, givenParamsWhenCalculateNumThreadsPerThreadGroupThe
15621562
}
15631563
}
15641564

1565+
HWTEST2_F(GfxCoreHelperTest, givenDebugModeWhenCheckingIfRunaloneModeRequiredThenMethodReturnFalseValue, IsAtMostXeHpcCore) {
1566+
auto &gfxCoreHelper = getHelper<GfxCoreHelper>();
1567+
EXPECT_FALSE(gfxCoreHelper.isRunaloneModeRequired(DebuggingMode::offline));
1568+
EXPECT_FALSE(gfxCoreHelper.isRunaloneModeRequired(DebuggingMode::online));
1569+
}
1570+
15651571
HWTEST_F(GfxCoreHelperTest, givenFlagRemoveRestrictionsOnNumberOfThreadsInGpgpuThreadGroupWhenCalculateNumThreadsPerThreadGroupThenMethodReturnProperValue) {
15661572
DebugManagerStateRestore dbgRestore;
15671573
debugManager.flags.RemoveRestrictionsOnNumberOfThreadsInGpgpuThreadGroup.set(1);

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
*
66
*/
77

8+
#include "shared/source/os_interface/linux/os_context_linux.h"
89
#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h"
910
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1011
#include "shared/test/common/helpers/default_hw_info.h"
12+
#include "shared/test/common/helpers/engine_descriptor_helper.h"
13+
#include "shared/test/common/helpers/raii_gfx_core_helper.h"
1114
#include "shared/test/common/libult/linux/drm_mock.h"
1215
#include "shared/test/common/mocks/linux/debug_mock_drm_xe.h"
1316
#include "shared/test/common/mocks/linux/mock_os_time_linux.h"
1417
#include "shared/test/common/mocks/mock_execution_environment.h"
18+
#include "shared/test/common/test_macros/hw_test.h"
1519
#include "shared/test/common/test_macros/test.h"
1620

1721
#include "uapi-eudebug/drm/xe_drm.h"
@@ -147,3 +151,65 @@ TEST(IoctlHelperXeTest, givenFreeDebugMetadataWhenVmCreateHasMultipleExtTypesThe
147151
delete node2;
148152
delete node3;
149153
}
154+
155+
TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGetRunaloneExtPropertyThenCorrectValueReturned) {
156+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
157+
executionEnvironment->setDebuggingMode(DebuggingMode::offline);
158+
DrmMockXeDebug drm{*executionEnvironment->rootDeviceEnvironments[0]};
159+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXeDebug>(drm);
160+
EXPECT_EQ(xeIoctlHelper->getRunaloneExtProperty(), DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE);
161+
}
162+
163+
using IoctlHelperXeTestFixture = ::testing::Test;
164+
HWTEST_F(IoctlHelperXeTestFixture, GivenRunaloneModeRequiredReturnFalseWhenCreateDrmContextThenRunAloneContextIsNotRequested) {
165+
DebugManagerStateRestore restorer;
166+
struct MockGfxCoreHelperHw : NEO::GfxCoreHelperHw<FamilyType> {
167+
bool isRunaloneModeRequired(DebuggingMode debuggingMode) const override {
168+
return false;
169+
}
170+
};
171+
172+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
173+
auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0];
174+
auto raiiFactory = RAIIGfxCoreHelperFactory<MockGfxCoreHelperHw>(rootDeviceEnvironment);
175+
rootDeviceEnvironment.osInterface = std::make_unique<OSInterface>();
176+
rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique<DrmMockTime>(mockFd, rootDeviceEnvironment));
177+
DrmMockXeDebug drm{*executionEnvironment->rootDeviceEnvironments[0]};
178+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXeDebug>(drm);
179+
auto engineInfo = xeIoctlHelper->createEngineInfo(false);
180+
ASSERT_NE(nullptr, engineInfo);
181+
182+
OsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
183+
xeIoctlHelper->createDrmContext(drm, osContext, 0, 0);
184+
185+
auto ext = drm.receivedContextCreateSetParam;
186+
EXPECT_NE(ext.property, static_cast<uint32_t>(DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE));
187+
}
188+
189+
HWTEST_F(IoctlHelperXeTestFixture, GivenRunaloneModeRequiredReturnTrueWhenCreateDrmContextThenRunAloneContextIsRequested) {
190+
DebugManagerStateRestore restorer;
191+
struct MockGfxCoreHelperHw : NEO::GfxCoreHelperHw<FamilyType> {
192+
bool isRunaloneModeRequired(DebuggingMode debuggingMode) const override {
193+
return true;
194+
}
195+
};
196+
197+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
198+
auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0];
199+
auto raiiFactory = RAIIGfxCoreHelperFactory<MockGfxCoreHelperHw>(rootDeviceEnvironment);
200+
rootDeviceEnvironment.osInterface = std::make_unique<OSInterface>();
201+
rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique<DrmMockTime>(mockFd, rootDeviceEnvironment));
202+
DrmMockXeDebug drm{*executionEnvironment->rootDeviceEnvironments[0]};
203+
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXeDebug>(drm);
204+
auto engineInfo = xeIoctlHelper->createEngineInfo(false);
205+
ASSERT_NE(nullptr, engineInfo);
206+
207+
OsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
208+
xeIoctlHelper->createDrmContext(drm, osContext, 0, 0);
209+
210+
auto ext = drm.receivedContextCreateSetParam;
211+
EXPECT_EQ(ext.base.name, static_cast<uint32_t>(DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY));
212+
EXPECT_EQ(ext.base.next_extension, 0ULL);
213+
EXPECT_EQ(ext.property, static_cast<uint32_t>(DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE));
214+
EXPECT_EQ(ext.value, 1ULL);
215+
}

0 commit comments

Comments
 (0)