Execution Queue
An Execution queue is an interface for the HW context of execution. The user creates an execution queue, submits the GPU jobs through those queues and in the end destroys them.
Execution queues can also be created by XeKMD itself for driver internal operations like object migration etc.
An execution queue is associated with a specified HW engine or a group of engines (belonging to the same tile and engine class) and any GPU job submitted on the queue will be run on one of these engines.
An execution queue is tied to an address space (VM). It holds a reference of the associated VM and the underlying Logical Ring Context/s (LRC/s) until the queue is destroyed.
The execution queue sits on top of the submission backend. It opaquely handles the GuC and Execlist backends whichever the platform uses, and the ring operations the different engine classes support.
Multi Queue Group #
Multi Queue Group is another mode of execution supported by the compute and blitter copy command streamers (CCS and BCS, respectively). It is an enhancement of the existing hardware architecture and leverages the same submission model. It enables support for efficient, parallel execution of multiple queues within a single shared context. The multi queue group functionality is only supported with GuC submission backend. All the queues of a group must use the same address space (VM).
The DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE execution queue property supports creating a multi queue group and adding queues to a queue group.
The XE_EXEC_QUEUE_CREATE ioctl call with above property with value field set to DRM_XE_MULTI_GROUP_CREATE, will create a new multi queue group with the queue being created as the primary queue (aka q0) of the group. To add secondary queues to the group, they need to be created with the above property with id of the primary queue as the value. The properties of the primary queue (like priority, time slice) applies to the whole group. So, these properties can't be set for secondary queues of a group.
The hardware does not support removing a queue from a multi-queue group. However, queues can be dynamically added to the group. A group can have up to 64 queues. To support this, XeKMD holds references to LRCs of the queues even after the queues are destroyed by the user until the whole group is destroyed. The secondary queues hold a reference to the primary queue thus preventing the group from being destroyed when user destroys the primary queue. Once the primary queue is destroyed, secondary queues can't be added to the queue group and new job submissions on existing secondary queues are not allowed.
The queues of a multi queue group can set their priority within the group through the DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY property. This multi queue priority can also be set dynamically through the XE_EXEC_QUEUE_SET_PROPERTY ioctl. This is the only other property supported by the secondary queues of a multi queue group, other than DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE.
When GuC reports an error on any of the queues of a multi queue group, the queue cleanup mechanism is invoked for all the queues of the group as hardware cannot make progress on the multi queue context.
Refer multi-queue-group-guc-interface for multi queue group GuC interface.
Multi Queue Group GuC interface #
The multi queue group coordination between KMD and GuC is through a software construct called Context Group Page (CGP). The CGP is a KMD managed 4KB page allocated in the global GTT.
CGP format:
+-----------+---------------------------+---------------------------------------------+
| DWORD | Name | Description |
+-----------+---------------------------+---------------------------------------------+
| 0 | Version | Bits [15:8]=Major ver, [7:0]=Minor ver |
+-----------+---------------------------+---------------------------------------------+
| 1..15 | RESERVED | MBZ |
+-----------+---------------------------+---------------------------------------------+
| 16 | KMD_QUEUE_UPDATE_MASK_DW0 | KMD queue mask for queues 31..0 |
+-----------+---------------------------+---------------------------------------------+
| 17 | KMD_QUEUE_UPDATE_MASK_DW1 | KMD queue mask for queues 63..32 |
+-----------+---------------------------+---------------------------------------------+
| 18..31 | RESERVED | MBZ |
+-----------+---------------------------+---------------------------------------------+
| 32 | Q0CD_DW0 | Queue 0 context LRC descriptor lower DWORD |
+-----------+---------------------------+---------------------------------------------+
| 33 | Q0ContextIndex | Context ID for Queue 0 |
+-----------+---------------------------+---------------------------------------------+
| 34 | Q1CD_DW0 | Queue 1 context LRC descriptor lower DWORD |
+-----------+---------------------------+---------------------------------------------+
| 35 | Q1ContextIndex | Context ID for Queue 1 |
+-----------+---------------------------+---------------------------------------------+
| ... |... | ... |
+-----------+---------------------------+---------------------------------------------+
| 158 | Q63CD_DW0 | Queue 63 context LRC descriptor lower DWORD |
+-----------+---------------------------+---------------------------------------------+
| 159 | Q63ContextIndex | Context ID for Queue 63 |
+-----------+---------------------------+---------------------------------------------+
| 160..1024 | RESERVED | MBZ |
+-----------+---------------------------+---------------------------------------------+
While registering Q0 with GuC, CGP is updated with Q0 entry and GuC is notified through XE_GUC_ACTION_REGISTER_CONTEXT_MULTI_QUEUE H2G message which specifies the CGP address. When the secondary queues are added to the group, the CGP is updated with entry for that queue and GuC is notified through the H2G interface XE_GUC_ACTION_MULTI_QUEUE_CONTEXT_CGP_SYNC. GuC responds to these H2G messages with a XE_GUC_ACTION_NOTIFY_MULTIQ_CONTEXT_CGP_SYNC_DONE G2H message. GuC also sends a XE_GUC_ACTION_NOTIFY_MULTI_QUEUE_CGP_CONTEXT_ERROR notification for any error in the CGP. Only one of these CGP update messages can be outstanding (waiting for GuC response) at any time. The bits in KMD_QUEUE_UPDATE_MASK_DW* fields indicate which queue entry is being updated in the CGP.
The primary queue (Q0) represents the multi queue group context in GuC and submission on any queue of the group must be through Q0 GuC interface only.
As it is not required to register secondary queues with GuC, the secondary queue context ids in the CGP are populated with Q0 context id.
Internal API #
enum xe_multi_queue_priority #
Multi Queue priority values
Constants
XE_MULTI_QUEUE_PRIORITY_LOW: Priority lowXE_MULTI_QUEUE_PRIORITY_NORMAL: Priority normalXE_MULTI_QUEUE_PRIORITY_HIGH: Priority high
Description
The priority values of the queues within the multi queue group.
struct xe_exec_queue_group #
Execution multi queue group
Definition
;
Members
primary: Primary queue of this groupcgp_bo: BO for the Context Group Pagexa: xarray to store LRCslist: List of all secondary queues in the grouplist_lock: Secondary queue list locksync_pending: CGP_SYNC_DONE g2h response pendingbanned: Group banned
Description
Contains multi queue group information.
struct xe_exec_queue #
Execution queue
Definition
;
Members
xef: Back pointer to xe file if this is user created exec queuegt: GT structure this exec queue can submit tohwe: A hardware of the same class. May (physical engine) or may not (virtual engine) be where jobs actual engine up running. Should never really be used for submissions.refcount: ref count of this exec queuevm: VM (address space) for this exec queueuser_vm: User VM (address space) for this exec queue (bind queues only)class: class of this exec queuelogical_mask: logical mask of where job submitted to exec queue can runname: name of this exec queuewidth: width (number BB submitted per exec) of this exec queuemsix_vec: MSI-X vector (for platforms that support it)fence_irq: fence IRQ used to signal job completionlast_fence: last fence for tlb invalidation, protected by vm->lock in write modeflags: flags for this exec queue, should statically setup aside from ban bit{unnamed_union}: anonymousmulti_gt_list: list head for VM bind engines if multi-GTmulti_gt_link: link for VM bind engines if multi-GT{unnamed_union}: anonymousexeclist: execlist backend specific state for exec queueguc: GuC backend specific state for exec queuemulti_queue: Multi queue informationmulti_queue.group: Queue group informationmulti_queue.link: Link into group's secondary queues listmulti_queue.priority: Queue priority within the multi-queue groupmulti_queue.pos: Position of queue within the multi-queue groupmulti_queue.valid: Queue belongs to a multi queue groupmulti_queue.is_primary: Is primary queue (Q0) of the groupsched_props: scheduling propertiessched_props.timeslice_us: timeslice period in micro-secondssched_props.preempt_timeout_us: preemption timeout in micro-secondssched_props.job_timeout_ms: job timeout in millisecondssched_props.priority: priority of this exec queuelr: long-running exec queue statelr.pfence: preemption fencelr.context: preemption fence contextlr.seqno: preemption fence seqnolr.link: link into VM's list of exec queuestlb_inval: TLB invalidations exec queue statetlb_inval.dep_scheduler: The TLB invalidation dependency schedulerpxp: PXP info trackingpxp.type: PXP session type used by this queuepxp.link: link into the list of PXP exec queuesufence_syncobj: User fence syncobjufence_timeline_value: User fence timeline valuereplay_state: GPU hang replay stateops: submission backend exec queue operationsring_ops: ring operations for this exec queueentity: DRM sched entity for this exec queue (1 to 1 relationship)job_cnt: number of drm jobs in this exec queuetlb_flush_seqno: The seqno of the last rebind tlb flush performed Protected by vm's resv. Unused if vm == NULL.hw_engine_group_link: link into exec queues in the same hw engine grouplrc: logical ring context for this exec queue
Description
Contains all state necessary for submissions. Can either be a user object or a kernel object.
struct xe_exec_queue_ops #
Submission backend exec queue operations
Definition
;
Members
init: Initialize exec queue for submission backendkill: Kill inflight submissions for backendfini: Undoes theinit()for submission backenddestroy: Destroy exec queue for submission backend. The backend function must callxe_exec_queue_fini()(which will in turn call thefini()backend function) to ensure the queue is properly cleaned up.set_priority: Set priority for exec queueset_timeslice: Set timeslice for exec queueset_preempt_timeout: Set preemption timeout for exec queueset_multi_queue_priority: Set multi queue prioritysuspend: Suspend exec queue from executing, allowed to be called multiple times in a row before resume with the caveat that suspend_wait returns before calling suspend again.suspend_wait: Wait for an exec queue to suspend executing, should be call after suspend. In dma-fencing path thus must return within a reasonable amount of time. -ETIME return shall indicate an error waiting for suspend resulting in associated VM getting killed. -EAGAIN return indicates the wait should be tried again, if the wait is within a work item, the work item should be requeued as deadlock avoidance mechanism.resume: Resume exec queue execution, exec queue must be in a suspended state and dma fence returned from most recent suspend call must be signalled when this function is called.reset_status: check exec queue reset status
xe_exec_queue_is_multi_queue() #
bool Whether an exec_queue is part of a queue group.
Parameters
struct xe_exec_queue *q: The exec_queue
Return
True if the exec_queue is part of a queue group, false otherwise.
xe_exec_queue_is_multi_queue_primary() #
bool Whether an exec_queue is primary queue of a multi queue group.
Parameters
struct xe_exec_queue *q: The exec_queue
Return
True if q is primary queue of a queue group, false otherwise.
xe_exec_queue_is_multi_queue_secondary() #
bool Whether an exec_queue is secondary queue of a multi queue group.
Parameters
struct xe_exec_queue *q: The exec_queue
Return
True if q is secondary queue of a queue group, false otherwise.
xe_exec_queue_multi_queue_primary() #
struct xe_exec_queue * Get multi queue group's primary queue
Parameters
struct xe_exec_queue *q: The exec_queue
Description
If q belongs to a multi queue group, then the primary queue of the group will be returned. Otherwise, q will be returned.
xe_exec_queue_idle_skip_suspend() #
bool Can exec queue skip suspend
Parameters
struct xe_exec_queue *q: The exec_queue
Description
If an exec queue is not parallel and is idle, the suspend steps can be skipped in the submission backend immediatley signaling the suspend fence. Parallel queues cannot skip this step due to limitations in the submission backend.
Return
True if exec queue is idle and can skip suspend steps, False otherwise
xe_exec_queue_create_bind() #
struct xe_exec_queue * Create bind exec queue.
Parameters
struct xe_device *xe: Xe device.struct xe_tile *tile: tile which bind exec queue belongs to.struct xe_vm *user_vm: The user VM which this exec queue belongs tou32 flags: exec queue creation flagsu64 extensions: exec queue creation extensions
Description
Normalize bind exec queue creation. Bind exec queue is tied to migration VM for access to physical memory required for page table programming. On a faulting devices the reserved copy engine instance must be used to avoid deadlocking (user binds cannot get stuck behind faults as kernel binds which resolve faults depend on user binds). On non-faulting devices any copy engine can be used.
Returns exec queue on success, ERR_PTR on failure
xe_exec_queue_lrc() #
struct xe_lrc * Get the LRC from exec queue.
Parameters
struct xe_exec_queue *q: The exec_queue.
Description
Retrieves the primary LRC for the exec queue. Note that this function returns only the first LRC instance, even when multiple parallel LRCs are configured.
Return
Pointer to LRC on success, error on failure
xe_exec_queue_is_lr() #
bool Whether an exec_queue is long-running
Parameters
struct xe_exec_queue *q: The exec_queue
Return
True if the exec_queue is long-running, false otherwise.
xe_exec_queue_is_idle() #
bool Whether an exec_queue is idle.
Parameters
struct xe_exec_queue *q: The exec_queue
Description
FIXME: Need to determine what to use as the short-lived timeline lock for the exec_queues, so that the return value of this function becomes more than just an advisory snapshot in time. The timeline lock must protect the seqno from racing submissions on the same exec_queue. Typically vm->resv, but user-created timeline locks use the migrate vm and never grabs the migrate vm->resv so we have a race there.
Return
True if the exec_queue is idle, false otherwise.
xe_exec_queue_update_run_ticks() #
void Update run time in ticks for this exec queue from hw
Parameters
struct xe_exec_queue *q: The exec queue
Description
Update the timestamp saved by HW for this exec queue and save run ticks calculated by using the delta from last update.
xe_exec_queue_kill() #
void permanently stop all execution from an exec queue
Parameters
struct xe_exec_queue *q: The exec queue
Description
This function permanently stops all activity on an exec queue. If the queue is actively executing on the HW, it will be kicked off the engine; any pending jobs are discarded and all future submissions are rejected. This function is safe to call multiple times.
xe_exec_queue_last_fence_put() #
void Drop ref to last fence
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind or exec for
xe_exec_queue_last_fence_put_unlocked() #
void Drop ref to last fence unlocked
Parameters
struct xe_exec_queue *q: The exec queue
Description
Only safe to be called from xe_exec_queue_destroy().
xe_exec_queue_last_fence_get() #
struct dma_fence * Get last fence
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind or exec for
Description
Get last fence, takes a ref
Return
last fence if not signaled, dma fence stub if signaled
xe_exec_queue_last_fence_get_for_resume() #
struct dma_fence * Get last fence
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind or exec for
Description
Get last fence, takes a ref. Only safe to be called in the context of resuming the hw engine group's long-running exec queue, when the group semaphore is held.
Return
last fence if not signaled, dma fence stub if signaled
xe_exec_queue_last_fence_set() #
void Set last fence
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind or exec forstruct dma_fence *fence: The fence
Description
Set the last fence for the engine. Increases reference count for fence, when closing engine xe_exec_queue_last_fence_put should be called.
xe_exec_queue_tlb_inval_last_fence_put() #
void Drop ref to last TLB invalidation fence
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind forunsigned int type: Either primary or media GT
xe_exec_queue_tlb_inval_last_fence_put_unlocked() #
void Drop ref to last TLB invalidation fence unlocked
Parameters
struct xe_exec_queue *q: The exec queueunsigned int type: Either primary or media GT
Description
Only safe to be called from xe_exec_queue_destroy().
xe_exec_queue_tlb_inval_last_fence_get() #
struct dma_fence * Get last fence for TLB invalidation
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind forunsigned int type: Either primary or media GT
Description
Get last fence, takes a ref
Return
last fence if not signaled, dma fence stub if signaled
xe_exec_queue_tlb_inval_last_fence_set() #
void Set last fence for TLB invalidation
Parameters
struct xe_exec_queue *q: The exec queuestruct xe_vm *vm: The VM the engine does a bind forstruct dma_fence *fence: The fenceunsigned int type: Either primary or media GT
Description
Set the last fence for the tlb invalidation type on the queue. Increases reference count for fence, when closing queue xe_exec_queue_tlb_inval_last_fence_put should be called.
xe_exec_queue_contexts_hwsp_rebase() #
int Re-compute GGTT references within all LRCs of a queue.
Parameters
struct xe_exec_queue *q: thexe_exec_queuestruct instance containing target LRCsvoid *scratch: scratch buffer to be used as temporary storage
Return
zero on success, negative error code on failure