Skip to content

Commit df95450

Browse files
committed
feature: multi queue context creation using xe uAPI
Signed-off-by: Hoppe, Mateusz <[email protected]>
1 parent 5cf3eeb commit df95450

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

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

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,11 @@ void IoctlHelperXe::setContextProperties(const OsContextLinux &osContext, uint32
18991899

19001900
auto &ext = *reinterpret_cast<std::array<drm_xe_ext_set_property, maxContextSetProperties> *>(extProperties);
19011901

1902+
xeLog(" -> IoctlHelperXe::%s\n", __FUNCTION__);
1903+
19021904
if (osContext.isLowPriority()) {
1905+
UNRECOVERABLE_IF(extIndexInOut >= maxContextSetProperties);
1906+
xeLog(" -> low priority ctx, DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY value = 0\n");
19031907
ext[extIndexInOut].base.name = DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY;
19041908
ext[extIndexInOut].property = DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY;
19051909
ext[extIndexInOut].value = 0;
@@ -1908,20 +1912,60 @@ void IoctlHelperXe::setContextProperties(const OsContextLinux &osContext, uint32
19081912
}
19091913
extIndexInOut++;
19101914
}
1911-
}
19121915

1913-
bool IoctlHelperXe::isPrimaryContext(const OsContextLinux &osContext, uint32_t deviceIndex) {
1914-
return (nullptr == osContext.getPrimaryContext());
1916+
if (osContext.isPartOfContextGroup()) {
1917+
UNRECOVERABLE_IF(extIndexInOut >= maxContextSetProperties);
1918+
ext[extIndexInOut].base.name = DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY;
1919+
ext[extIndexInOut].property = DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP;
1920+
if (extIndexInOut > 0) {
1921+
ext[extIndexInOut - 1].base.next_extension = castToUint64(&ext[extIndexInOut]);
1922+
}
1923+
1924+
auto currentContextIndex = osContext.getDrmContextIds().size();
1925+
1926+
const bool isPrimary = isPrimaryContext(osContext, deviceIndex);
1927+
1928+
if (isPrimary) {
1929+
xeLog(" -> multi group create\n");
1930+
ext[extIndexInOut].value = getPrimaryContextProperties();
1931+
} else {
1932+
xeLog(" -> multi group secondary queue\n");
1933+
// For MultiTile, match currently created context index with the primary context index
1934+
ext[extIndexInOut].value = getPrimaryContextId(osContext, deviceIndex, currentContextIndex);
1935+
}
1936+
1937+
extIndexInOut++;
1938+
if (osContext.isRootDevice()) {
1939+
setContextPropertiesForRootDeviceContext(osContext, deviceIndex, extProperties, extIndexInOut);
1940+
}
1941+
1942+
uint32_t priorityValue = 0;
1943+
if (osContext.isHighPriority()) {
1944+
priorityValue = 2;
1945+
}
1946+
1947+
UNRECOVERABLE_IF(extIndexInOut >= maxContextSetProperties);
1948+
ext[extIndexInOut - 1].base.next_extension = castToUint64(&ext[extIndexInOut]);
1949+
ext[extIndexInOut].base.name = DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY;
1950+
ext[extIndexInOut].property = DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY;
1951+
ext[extIndexInOut].value = priorityValue;
1952+
xeLog(" -> DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY value = %d\n", ext[extIndexInOut].value);
1953+
extIndexInOut++;
1954+
}
19151955
}
19161956

19171957
uint32_t IoctlHelperXe::getPrimaryContextId(const OsContextLinux &osContext, uint32_t deviceIndex, size_t contextIndex) {
19181958
auto osContextLinuxPrimary = static_cast<const OsContextLinux *>(osContext.getPrimaryContext());
19191959
UNRECOVERABLE_IF(nullptr == osContextLinuxPrimary);
1960+
19201961
return osContextLinuxPrimary->getDrmContextIds()[contextIndex];
19211962
}
1922-
19231963
uint64_t IoctlHelperXe::getPrimaryContextProperties() const {
1924-
return 0;
1964+
return DRM_XE_MULTI_GROUP_CREATE;
1965+
}
1966+
1967+
bool IoctlHelperXe::isPrimaryContext(const OsContextLinux &osContext, uint32_t deviceIndex) {
1968+
return (nullptr == osContext.getPrimaryContext());
19251969
}
19261970

19271971
unsigned int IoctlHelperXe::getIoctlRequestValue(DrmIoctl ioctlRequest) const {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ HWTEST_F(IoctlHelperXeTestFixture, GivenDebuggingEnabledWhenCreateDrmContextFrom
183183
EXPECT_EQ(ext.property, static_cast<uint32_t>(EuDebugParam::execQueueSetPropertyEuDebug));
184184
EXPECT_EQ(ext.value, static_cast<uint32_t>(EuDebugParam::execQueueSetPropertyValueEnable));
185185

186-
EXPECT_EQ(ext.base.next_extension, 0ULL);
186+
EXPECT_NE(ext.base.next_extension, 0ULL);
187187

188188
osContext2.setPrimaryContext(&osContext);
189189
drm->receivedContextCreateSetParam = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch: https://patchwork.freedesktop.org/series/156865/

third_party/uapi/drm-next/xe/xe_drm.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ extern "C" {
106106
#define DRM_XE_OBSERVATION 0x0b
107107
#define DRM_XE_MADVISE 0x0c
108108
#define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d
109+
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY 0x0e
109110

110111
/* Must be kept compact -- no holes */
111112

@@ -123,6 +124,7 @@ extern "C" {
123124
#define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param)
124125
#define DRM_IOCTL_XE_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_MADVISE, struct drm_xe_madvise)
125126
#define DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_QUERY_MEM_RANGE_ATTRS, struct drm_xe_vm_query_mem_range_attr)
127+
#define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)
126128

127129
/**
128130
* DOC: Xe IOCTL Extensions
@@ -1252,6 +1254,18 @@ struct drm_xe_vm_bind {
12521254
* Given that going into a power-saving state kills PXP HWDRM sessions,
12531255
* runtime PM will be blocked while queues of this type are alive.
12541256
* All PXP queues will be killed if a PXP invalidation event occurs.
1257+
* - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP - Create a multi-queue group
1258+
* or add secondary queues to a multi-queue group.
1259+
* If the extension's 'value' field has %DRM_XE_MULTI_GROUP_CREATE flag set,
1260+
* then a new multi-queue group is created with this queue as the primary queue
1261+
* (Q0). Otherwise, the queue gets added to the multi-queue group whose primary
1262+
* queue id is specified in the 'value' field.
1263+
* If the extension's 'value' field has %DRM_XE_MULTI_GROUP_KEEP_ACTIVE flag
1264+
* set, then the multi-queue group is kept active after the primary queue is
1265+
* destroyed.
1266+
*
1267+
* - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY - Set the queue
1268+
* priority within the multi-queue group.
12551269
*
12561270
* The example below shows how to use @drm_xe_exec_queue_create to create
12571271
* a simple exec_queue (no parallel submission) of class
@@ -1292,6 +1306,10 @@ struct drm_xe_exec_queue_create {
12921306
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0
12931307
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1
12941308
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE 2
1309+
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP 3
1310+
#define DRM_XE_MULTI_GROUP_CREATE (1ull << 63)
1311+
#define DRM_XE_MULTI_GROUP_KEEP_ACTIVE (1ull << 62)
1312+
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY 4
12951313
/** @extensions: Pointer to the first extension struct, if any */
12961314
__u64 extensions;
12971315

@@ -2273,6 +2291,28 @@ struct drm_xe_vm_query_mem_range_attr {
22732291

22742292
};
22752293

2294+
/**
2295+
* struct drm_xe_exec_queue_set_property - exec queue set property
2296+
*
2297+
* Sets execution queue properties dynamically.
2298+
*/
2299+
struct drm_xe_exec_queue_set_property {
2300+
/** @extensions: Pointer to the first extension struct, if any */
2301+
__u64 extensions;
2302+
2303+
/** @exec_queue_id: Exec queue ID */
2304+
__u32 exec_queue_id;
2305+
2306+
/** @property: property to set */
2307+
__u32 property;
2308+
2309+
/** @value: property value */
2310+
__u64 value;
2311+
2312+
/** @reserved: Reserved */
2313+
__u64 reserved[2];
2314+
};
2315+
22762316
#if defined(__cplusplus)
22772317
}
22782318
#endif

0 commit comments

Comments
 (0)