feature: Set runalone mode for contexts with online debugging

Related-To: NEO-9139

Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2024-01-09 09:54:33 +00:00
committed by Compute-Runtime-Automation
parent 68b0d814a5
commit aa191b6f88
9 changed files with 137 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ struct LrcaHelper;
namespace NEO {
enum class AuxTranslationMode;
struct FeatureTable;
enum class DebuggingMode : uint32_t;
enum class PostSyncMode : uint32_t;
enum class CachePolicy : uint32_t;
enum class CacheRegion : uint16_t;
@@ -137,6 +138,7 @@ class GfxCoreHelper {
virtual size_t getTimestampPacketAllocatorAlignment() const = 0;
virtual size_t getSingleTimestampPacketSize() const = 0;
virtual void applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const = 0;
virtual bool isRunaloneModeRequired(DebuggingMode debuggingMode) const = 0;
virtual void applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const = 0;
virtual bool unTypedDataPortCacheFlushRequired() const = 0;
virtual bool isEngineTypeRemappingToHwSpecificRequired() const = 0;
@@ -357,6 +359,8 @@ class GfxCoreHelperHw : public GfxCoreHelper {
void applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const override;
bool isRunaloneModeRequired(DebuggingMode debuggingMode) const override;
void applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const override;
bool unTypedDataPortCacheFlushRequired() const override;

View File

@@ -584,6 +584,11 @@ size_t GfxCoreHelperHw<GfxFamily>::getPreemptionAllocationAlignment() const {
template <typename GfxFamily>
void GfxCoreHelperHw<GfxFamily>::applyAdditionalCompressionSettings(Gmm &gmm, bool isNotCompressed) const {}
template <typename GfxFamily>
bool GfxCoreHelperHw<GfxFamily>::isRunaloneModeRequired(DebuggingMode debuggingMode) const {
return false;
}
template <typename GfxFamily>
void GfxCoreHelperHw<GfxFamily>::applyRenderCompressionFlag(Gmm &gmm, uint32_t isCompressed) const {
gmm.resourceParams.Flags.Info.RenderCompressed = isCompressed;

View File

@@ -105,7 +105,7 @@ class Drm : public DriverModel {
int queryVmId(uint32_t drmContextId, uint32_t &vmId);
void setLowPriorityContextParam(uint32_t drmContextId);
unsigned int bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice);
MOCKABLE_VIRTUAL unsigned int bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice);
MOCKABLE_VIRTUAL int getErrno();
bool setQueueSliceCount(uint64_t sliceCount);

View File

@@ -17,6 +17,7 @@
#include "shared/source/helpers/common_types.h"
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/engine_control.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/register_offsets.h"
@@ -1209,6 +1210,17 @@ int IoctlHelperXe::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_
create.instances = castToUint64(engine.data());
create.num_placements = engine.size();
struct drm_xe_ext_set_property ext {};
auto &gfxCoreHelper = drm.getRootDeviceEnvironment().getHelper<GfxCoreHelper>();
if (gfxCoreHelper.isRunaloneModeRequired(drm.getRootDeviceEnvironment().executionEnvironment.getDebuggingMode())) {
ext.base.next_extension = 0;
ext.base.name = DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY;
ext.property = getRunaloneExtProperty();
ext.value = 1;
create.extensions = castToUint64(&ext);
}
int ret = IoctlHelper::ioctl(DrmIoctl::gemContextCreateExt, &create);
drmContextId = create.exec_queue_id;
xeLog("%s:%d (%d) vmid=0x%x ctx=0x%x r=0x%x\n", xeGetClassName(engine[0].engine_class),

View File

@@ -147,6 +147,7 @@ class IoctlHelperXe : public IoctlHelper {
void updateBindInfo(uint32_t handle, uint64_t userPtr, uint64_t size);
void *allocateDebugMetadata();
void *freeDebugMetadata(void *metadata);
int getRunaloneExtProperty();
struct UserFenceExtension {
static constexpr uint32_t tagValue = 0x123987;

View File

@@ -104,4 +104,8 @@ void IoctlHelperXe::addDebugMetadata(DrmResourceClass type, uint64_t *offset, ui
return;
}
int IoctlHelperXe::getRunaloneExtProperty() {
return DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE;
}
} // namespace NEO

View File

@@ -31,6 +31,7 @@ using namespace NEO;
struct MockIoctlHelperXeDebug : IoctlHelperXe {
using IoctlHelperXe::debugMetadata;
using IoctlHelperXe::freeDebugMetadata;
using IoctlHelperXe::getRunaloneExtProperty;
using IoctlHelperXe::IoctlHelperXe;
};
@@ -52,6 +53,10 @@ class DrmMockXeDebug : public DrmMockCustom {
bool baseErrno = false;
int errnoRetVal = 0;
unsigned int bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice) override {
return static_cast<unsigned int>(DrmParam::execDefault);
}
int ioctl(DrmIoctl request, void *arg) override {
int ret = -1;
ioctlCalled = true;
@@ -59,6 +64,25 @@ class DrmMockXeDebug : public DrmMockCustom {
return setIoctlAnswer;
}
switch (request) {
case DrmIoctl::query: {
struct drm_xe_device_query *deviceQuery = static_cast<struct drm_xe_device_query *>(arg);
switch (deviceQuery->query) {
case DRM_XE_DEVICE_QUERY_ENGINES:
if (deviceQuery->data) {
memcpy_s(reinterpret_cast<void *>(deviceQuery->data), deviceQuery->size, queryEngines, sizeof(queryEngines));
}
deviceQuery->size = sizeof(queryEngines);
break;
};
ret = 0;
} break;
case DrmIoctl::gemContextCreateExt: {
auto create = static_cast<struct drm_xe_exec_queue_create *>(arg);
if (create->extensions) {
receivedContextCreateSetParam = *reinterpret_cast<struct drm_xe_ext_set_property *>(create->extensions);
}
ret = 0;
} break;
case DrmIoctl::gemVmCreate: {
struct drm_xe_vm_create *v = static_cast<struct drm_xe_vm_create *>(arg);
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 {
return allowDebugAttach;
}
const drm_xe_engine_class_instance queryEngines[11] = {
{DRM_XE_ENGINE_CLASS_RENDER, 0, 0},
{DRM_XE_ENGINE_CLASS_COPY, 1, 0},
{DRM_XE_ENGINE_CLASS_COPY, 2, 0},
{DRM_XE_ENGINE_CLASS_COMPUTE, 3, 0},
{DRM_XE_ENGINE_CLASS_COMPUTE, 4, 0},
{DRM_XE_ENGINE_CLASS_COMPUTE, 5, 1},
{DRM_XE_ENGINE_CLASS_COMPUTE, 6, 1},
{DRM_XE_ENGINE_CLASS_COMPUTE, 7, 1},
{DRM_XE_ENGINE_CLASS_COMPUTE, 8, 1},
{DRM_XE_ENGINE_CLASS_VIDEO_DECODE, 9, 1},
{DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE, 10, 0}};
struct drm_xe_ext_set_property receivedContextCreateSetParam = {};
bool allowDebugAttachCallBase = false;
bool allowDebugAttach = false;
bool ioctlCalled = false;

View File

@@ -1562,6 +1562,12 @@ HWTEST2_F(GfxCoreHelperTest, givenParamsWhenCalculateNumThreadsPerThreadGroupThe
}
}
HWTEST2_F(GfxCoreHelperTest, givenDebugModeWhenCheckingIfRunaloneModeRequiredThenMethodReturnFalseValue, IsAtMostXeHpcCore) {
auto &gfxCoreHelper = getHelper<GfxCoreHelper>();
EXPECT_FALSE(gfxCoreHelper.isRunaloneModeRequired(DebuggingMode::offline));
EXPECT_FALSE(gfxCoreHelper.isRunaloneModeRequired(DebuggingMode::online));
}
HWTEST_F(GfxCoreHelperTest, givenFlagRemoveRestrictionsOnNumberOfThreadsInGpgpuThreadGroupWhenCalculateNumThreadsPerThreadGroupThenMethodReturnProperValue) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.RemoveRestrictionsOnNumberOfThreadsInGpgpuThreadGroup.set(1);

View File

@@ -5,13 +5,17 @@
*
*/
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/helpers/raii_gfx_core_helper.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/debug_mock_drm_xe.h"
#include "shared/test/common/mocks/linux/mock_os_time_linux.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/common/test_macros/test.h"
#include "uapi-eudebug/drm/xe_drm.h"
@@ -147,3 +151,65 @@ TEST(IoctlHelperXeTest, givenFreeDebugMetadataWhenVmCreateHasMultipleExtTypesThe
delete node2;
delete node3;
}
TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGetRunaloneExtPropertyThenCorrectValueReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->setDebuggingMode(DebuggingMode::offline);
DrmMockXeDebug drm{*executionEnvironment->rootDeviceEnvironments[0]};
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXeDebug>(drm);
EXPECT_EQ(xeIoctlHelper->getRunaloneExtProperty(), DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE);
}
using IoctlHelperXeTestFixture = ::testing::Test;
HWTEST_F(IoctlHelperXeTestFixture, GivenRunaloneModeRequiredReturnFalseWhenCreateDrmContextThenRunAloneContextIsNotRequested) {
DebugManagerStateRestore restorer;
struct MockGfxCoreHelperHw : NEO::GfxCoreHelperHw<FamilyType> {
bool isRunaloneModeRequired(DebuggingMode debuggingMode) const override {
return false;
}
};
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0];
auto raiiFactory = RAIIGfxCoreHelperFactory<MockGfxCoreHelperHw>(rootDeviceEnvironment);
rootDeviceEnvironment.osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique<DrmMockTime>(mockFd, rootDeviceEnvironment));
DrmMockXeDebug drm{*executionEnvironment->rootDeviceEnvironments[0]};
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXeDebug>(drm);
auto engineInfo = xeIoctlHelper->createEngineInfo(false);
ASSERT_NE(nullptr, engineInfo);
OsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
xeIoctlHelper->createDrmContext(drm, osContext, 0, 0);
auto ext = drm.receivedContextCreateSetParam;
EXPECT_NE(ext.property, static_cast<uint32_t>(DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE));
}
HWTEST_F(IoctlHelperXeTestFixture, GivenRunaloneModeRequiredReturnTrueWhenCreateDrmContextThenRunAloneContextIsRequested) {
DebugManagerStateRestore restorer;
struct MockGfxCoreHelperHw : NEO::GfxCoreHelperHw<FamilyType> {
bool isRunaloneModeRequired(DebuggingMode debuggingMode) const override {
return true;
}
};
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0];
auto raiiFactory = RAIIGfxCoreHelperFactory<MockGfxCoreHelperHw>(rootDeviceEnvironment);
rootDeviceEnvironment.osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique<DrmMockTime>(mockFd, rootDeviceEnvironment));
DrmMockXeDebug drm{*executionEnvironment->rootDeviceEnvironments[0]};
auto xeIoctlHelper = std::make_unique<MockIoctlHelperXeDebug>(drm);
auto engineInfo = xeIoctlHelper->createEngineInfo(false);
ASSERT_NE(nullptr, engineInfo);
OsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
xeIoctlHelper->createDrmContext(drm, osContext, 0, 0);
auto ext = drm.receivedContextCreateSetParam;
EXPECT_EQ(ext.base.name, static_cast<uint32_t>(DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY));
EXPECT_EQ(ext.base.next_extension, 0ULL);
EXPECT_EQ(ext.property, static_cast<uint32_t>(DRM_XE_EXEC_QUEUE_SET_PROPERTY_RUNALONE));
EXPECT_EQ(ext.value, 1ULL);
}