Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Limit number of jobs per exec queue

Add a limit to the number of jobs that can be queued in a single
exec queue to avoid potential resource exhaustion.

A new field `job_cnt` is introduced in `struct xe_exec_queue` to
track the number of active DRM jobs, along with a maximum limit
`XE_MAX_JOB_COUNT_PER_EXEC_QUEUE` set to 1000.

If the job count exceeds this threshold, `xe_exec_ioctl()` now
returns `-EAGAIN` to signal that the caller should retry later.

A trace event is added to track when the limit is reached:
"xe_exec_queue_reach_max_job_count: dev=0000:03:00.0, job count
exceeded the maximum limit (1000) per exec queue. engine_class=0x3,
logical_mask=0x1, guc_id=2"

v3: add assert in xe_exec_queue_destroy that q->job_cnt is zero. (Matt)
v2 (Matt):
- add log to trace the limit is hit.
- Change max count from 0x1000 to 1000.
- Use atomic_t for job_cnt.

Suggested-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20251027202118.3339905-2-shuicheng.lin@intel.com

authored by

Shuicheng Lin and committed by
Matthew Brost
4a7fe36a 4504e780

+39
+7
drivers/gpu/drm/xe/xe_exec.c
··· 21 21 #include "xe_sched_job.h" 22 22 #include "xe_sync.h" 23 23 #include "xe_svm.h" 24 + #include "xe_trace.h" 24 25 #include "xe_vm.h" 25 26 26 27 /** ··· 152 151 153 152 if (XE_IOCTL_DBG(xe, q->ops->reset_status(q))) { 154 153 err = -ECANCELED; 154 + goto err_exec_queue; 155 + } 156 + 157 + if (atomic_read(&q->job_cnt) >= XE_MAX_JOB_COUNT_PER_EXEC_QUEUE) { 158 + trace_xe_exec_queue_reach_max_job_count(q, XE_MAX_JOB_COUNT_PER_EXEC_QUEUE); 159 + err = -EAGAIN; 155 160 goto err_exec_queue; 156 161 } 157 162
+2
drivers/gpu/drm/xe/xe_exec_queue.c
··· 377 377 struct xe_exec_queue *q = container_of(ref, struct xe_exec_queue, refcount); 378 378 struct xe_exec_queue *eq, *next; 379 379 380 + xe_assert(gt_to_xe(q->gt), atomic_read(&q->job_cnt) == 0); 381 + 380 382 if (xe_exec_queue_uses_pxp(q)) 381 383 xe_pxp_exec_queue_remove(gt_to_xe(q->gt)->pxp, q); 382 384
+5
drivers/gpu/drm/xe/xe_exec_queue_types.h
··· 162 162 const struct xe_ring_ops *ring_ops; 163 163 /** @entity: DRM sched entity for this exec queue (1 to 1 relationship) */ 164 164 struct drm_sched_entity *entity; 165 + 166 + #define XE_MAX_JOB_COUNT_PER_EXEC_QUEUE 1000 167 + /** @job_cnt: number of drm jobs in this exec queue */ 168 + atomic_t job_cnt; 169 + 165 170 /** 166 171 * @tlb_flush_seqno: The seqno of the last rebind tlb flush performed 167 172 * Protected by @vm's resv. Unused if @vm == NULL.
+2
drivers/gpu/drm/xe/xe_sched_job.c
··· 146 146 for (i = 0; i < width; ++i) 147 147 job->ptrs[i].batch_addr = batch_addr[i]; 148 148 149 + atomic_inc(&q->job_cnt); 149 150 xe_pm_runtime_get_noresume(job_to_xe(job)); 150 151 trace_xe_sched_job_create(job); 151 152 return job; ··· 178 177 dma_fence_put(job->fence); 179 178 drm_sched_job_cleanup(&job->drm); 180 179 job_free(job); 180 + atomic_dec(&q->job_cnt); 181 181 xe_exec_queue_put(q); 182 182 xe_pm_runtime_put(xe); 183 183 }
+23
drivers/gpu/drm/xe/xe_trace.h
··· 441 441 __entry->read_size, __entry->total_size) 442 442 ); 443 443 444 + TRACE_EVENT(xe_exec_queue_reach_max_job_count, 445 + TP_PROTO(struct xe_exec_queue *q, int max_cnt), 446 + TP_ARGS(q, max_cnt), 447 + 448 + TP_STRUCT__entry(__string(dev, __dev_name_eq(q)) 449 + __field(enum xe_engine_class, class) 450 + __field(u32, logical_mask) 451 + __field(u16, guc_id) 452 + __field(int, max_cnt) 453 + ), 454 + 455 + TP_fast_assign(__assign_str(dev); 456 + __entry->class = q->class; 457 + __entry->logical_mask = q->logical_mask; 458 + __entry->guc_id = q->guc->id; 459 + __entry->max_cnt = max_cnt; 460 + ), 461 + 462 + TP_printk("dev=%s, job count exceeded the maximum limit (%d) per exec queue. engine_class=0x%x, logical_mask=0x%x, guc_id=%d", 463 + __get_str(dev), __entry->max_cnt, 464 + __entry->class, __entry->logical_mask, __entry->guc_id) 465 + ); 466 + 444 467 #endif 445 468 446 469 /* This part must be outside protection */