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

drm/i915/execlists: Set queue priority from secondary port

We can refine our current execlists->queue_priority if we inspect
ELSP[1] rather than the head of the unsubmitted queue. Currently, we use
the unsubmitted queue and say that if a subsequent request is more
important than the current queue, we will rerun the submission tasklet
to evaluate the need for preemption. However, we only want to preempt if
we need to jump ahead of a currently executing request in ELSP. The
second reason for running the submission tasklet is amalgamate requests
into the active context on ELSP[0] to avoid a stall when ELSP[0] drains.
(Though repeatedly amalgamating requests into the active context and
triggering many lite-restore is off question gain, the goal really is to
put a context into ELSP[1] to cover the interrupt.) So if instead of
looking at the head of the queue, we look at the context in ELSP[1] we
can answer both of the questions more accurately -- we don't need to
rerun the submission tasklet unless our new request is important enough
to feed into, at least, ELSP[1].

v2: Add some comments from the discussion with Tvrtko.
v3: More commentary to cross-reference queue_request()

References: f6322eddaff7 ("drm/i915/preemption: Allow preemption between submission ports")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Michel Thierry <michel.thierry@intel.com>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180411103929.27374-1-chris@chris-wilson.co.uk

+23 -1
+3
drivers/gpu/drm/i915/intel_engine_cs.c
··· 1687 1687 intel_engine_dump(engine, &p, NULL); 1688 1688 } 1689 1689 1690 + /* Must be reset upon idling, or we may miss the busy wakeup. */ 1691 + GEM_BUG_ON(engine->execlists.queue_priority != INT_MIN); 1692 + 1690 1693 if (engine->park) 1691 1694 engine->park(engine); 1692 1695
+20 -1
drivers/gpu/drm/i915/intel_lrc.c
··· 713 713 if (p->priority != I915_PRIORITY_NORMAL) 714 714 kmem_cache_free(engine->i915->priorities, p); 715 715 } 716 + 716 717 done: 717 - execlists->queue_priority = rb ? to_priolist(rb)->priority : INT_MIN; 718 + /* 719 + * Here be a bit of magic! Or sleight-of-hand, whichever you prefer. 720 + * 721 + * We choose queue_priority such that if we add a request of greater 722 + * priority than this, we kick the submission tasklet to decide on 723 + * the right order of submitting the requests to hardware. We must 724 + * also be prepared to reorder requests as they are in-flight on the 725 + * HW. We derive the queue_priority then as the first "hole" in 726 + * the HW submission ports and if there are no available slots, 727 + * the priority of the lowest executing request, i.e. last. 728 + * 729 + * When we do receive a higher priority request ready to run from the 730 + * user, see queue_request(), the queue_priority is bumped to that 731 + * request triggering preemption on the next dequeue (or subsequent 732 + * interrupt for secondary ports). 733 + */ 734 + execlists->queue_priority = 735 + port != execlists->port ? rq_prio(last) : INT_MIN; 736 + 718 737 execlists->first = rb; 719 738 if (submit) 720 739 port_assign(port, last);